diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6efba22..78412fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,9 @@ on: branches: [main] pull_request: +permissions: + contents: read + jobs: check: runs-on: ${{ matrix.os }} @@ -14,8 +17,10 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + persist-credentials: false + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: 22 cache: npm diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 94ecf98..3030440 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,8 +6,11 @@ # uploads its installers to that draft, and once all three have, the release is published and becomes "latest", which is # what the download links in the README point at. # -# Signing is optional. With no secrets the installers are unsigned: macOS asks you to open the app with a right-click the -# first time, and Windows SmartScreen asks you to confirm. Add these repository secrets to sign (and notarize) them: +# The Mac app is signed and notarized, and a release without the certificate fails rather than ship one that isn't: a +# missing secret used to be a warning nobody reads, and the unsigned app went out as the release. To build unsigned on +# purpose (a fork, a try-out), run the workflow by hand with "unsigned" ticked, or set the repository variable +# ALLOW_UNSIGNED to true. Windows has no certificate yet, so its installer is unsigned and says so in a warning +# (SmartScreen asks people to confirm). The repository secrets: # MAC_CSC_LINK, MAC_CSC_KEY_PASSWORD a Developer ID Application certificate (.p12, base64) and its password # APPLE_API_KEY, APPLE_API_KEY_ID, APPLE_API_ISSUER an App Store Connect API key (.p8, whole or base64) for notarizing # WIN_CSC_LINK, WIN_CSC_KEY_PASSWORD a Windows code-signing certificate (.pfx, base64) and its password @@ -18,14 +21,23 @@ on: tags: ["v*"] # Builds every platform without releasing anything, to check the build. workflow_dispatch: + inputs: + unsigned: + description: Build the Mac app unsigned when there is no certificate + type: boolean + default: false +# Reading is all a build needs. Only the jobs that make, fill and publish the release may write to it: the build runs +# every dependency's install script, and with a token that could write it could rewrite the release people update from. permissions: - contents: write + contents: read jobs: prepare: if: ${{ startsWith(github.ref, 'refs/tags/') }} runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Make the draft release env: @@ -46,8 +58,12 @@ jobs: os: [macos-15, windows-latest, ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + # Third-party actions are named by commit, not by a tag that can be moved. The token isn't left on the disk for + # what npm ci runs to find. + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + persist-credentials: false + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: 22 cache: npm @@ -64,6 +80,7 @@ jobs: APPLE_ISSUER: ${{ secrets.APPLE_API_ISSUER }} WIN_CERT: ${{ secrets.WIN_CSC_LINK }} WIN_CERT_PASSWORD: ${{ secrets.WIN_CSC_KEY_PASSWORD }} + UNSIGNED_OK: ${{ inputs.unsigned == true || vars.ALLOW_UNSIGNED == 'true' }} run: | args=(--publish never) if [ "$RUNNER_OS" = "macOS" ]; then @@ -82,13 +99,20 @@ jobs: export APPLE_API_KEY="$RUNNER_TEMP/AuthKey.p8" export APPLE_API_KEY_ID="$(printf %s "$APPLE_KEY_ID" | tr -d '[:space:]')" export APPLE_API_ISSUER="$(printf %s "$APPLE_ISSUER" | tr -d '[:space:]')" - else + elif [ "$UNSIGNED_OK" = "true" ]; then export CSC_IDENTITY_AUTO_DISCOVERY=false args+=(-c.mac.notarize=false) - echo "::warning::No Developer ID certificate and notarization key: building an unsigned Mac app." + echo "::warning::No Developer ID certificate and notarization key: building an unsigned Mac app, as asked." + else + echo "::error::No Developer ID certificate (MAC_CSC_LINK) or notarization key (APPLE_API_KEY): the Mac app would ship unsigned. Add the secrets, or run by hand with \"unsigned\" ticked (or set the repository variable ALLOW_UNSIGNED=true) to build it unsigned on purpose." + exit 1 + fi + elif [ "$RUNNER_OS" = "Windows" ]; then + if [ -n "$WIN_CERT" ]; then + export WIN_CSC_LINK="$WIN_CERT" WIN_CSC_KEY_PASSWORD="$WIN_CERT_PASSWORD" + else + echo "::warning::No Windows certificate (WIN_CSC_LINK): building an unsigned Windows installer." fi - elif [ "$RUNNER_OS" = "Windows" ] && [ -n "$WIN_CERT" ]; then - export WIN_CSC_LINK="$WIN_CERT" WIN_CSC_KEY_PASSWORD="$WIN_CERT_PASSWORD" fi # Stapling the notarization ticket asks Apple's servers, which drop the connection now and then ("The network # connection was lost", error 68: v0.2.11 and v0.2.12 both failed on it once). The build is tried up to three times. @@ -122,9 +146,39 @@ jobs: curl -sf http://127.0.0.1:4599/api/info > /dev/null || { echo "::error::The AppImage didn't start."; exit 1; } if grep -q "Cannot find module" "$RUNNER_TEMP/app.log"; then echo "::error::The AppImage is missing a module."; exit 1; fi - # Only what people download (and electron-builder's checksums beside them), never the unpacked app folders. - - name: Attach the installers to the draft + # Only what people download (and electron-builder's checksums beside them), never the unpacked app folders. Handed + # to the attach job below: this one, which ran npm ci, has no token that can write to the release. + - name: Hand the installers on if: ${{ startsWith(github.ref, 'refs/tags/') }} + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + with: + name: installers-${{ runner.os }} + path: | + release/*.dmg + release/*.zip + release/*.exe + release/*.AppImage + release/*.blockmap + release/latest*.yml + if-no-files-found: error + # Already packed, and only needed until the next job has them. + compression-level: 0 + retention-days: 1 + + # The one job that writes the installers to the draft. Whatever was built is attached, as before, when a platform failed. + attach: + needs: build + if: ${{ always() && startsWith(github.ref, 'refs/tags/') }} + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 + with: + pattern: installers-* + path: release + merge-multiple: true + - name: Attach the installers to the draft shell: bash env: GH_TOKEN: ${{ github.token }} @@ -135,13 +189,15 @@ jobs: files=(release/*.dmg release/*.zip release/*.exe release/*.AppImage release/*.blockmap release/latest*.yml) [ ${#files[@]} -gt 0 ] || { echo "::error::No installers were built."; exit 1; } gh release upload "$TAG" "${files[@]}" --repo "$GITHUB_REPOSITORY" --clobber - echo "### Friday $TAG ($RUNNER_OS)" >> "$GITHUB_STEP_SUMMARY" + echo "### Friday $TAG" >> "$GITHUB_STEP_SUMMARY" for f in "${files[@]}"; do echo "- ${f##*/}" >> "$GITHUB_STEP_SUMMARY"; done publish: - needs: build + needs: [build, attach] if: ${{ startsWith(github.ref, 'refs/tags/') }} runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Publish the release env: @@ -160,7 +216,8 @@ jobs: steps: - name: Submit the new version to winget if: ${{ env.WINGET_TOKEN != '' }} - uses: vedantmgoyal9/winget-releaser@v2 + # By commit (the v2 tag as of 2026-11-27), not the tag: it is handed a token that can write to GitHub as its owner. + uses: vedantmgoyal9/winget-releaser@b7370d4d152efdce803a26cc6ca9eee58cb2ad54 # v2 with: identifier: FridayWork.Friday installers-regex: 'Friday-Setup\.exe$' diff --git a/build/entitlements.mac.plist b/build/entitlements.mac.plist index 7c3faea..788d1fb 100644 --- a/build/entitlements.mac.plist +++ b/build/entitlements.mac.plist @@ -6,6 +6,11 @@ The JIT and unsigned-memory pairs are Electron's own: V8 compiles as it runs. Library validation is off so the terminal's module and your coding tools, signed by other people, can load and run. The microphone is for voice input, the network for Friday's own server on 127.0.0.1 and the previews of what you build. + + Not allow-dyld-environment-variables: nothing here sets a DYLD_ variable, and with it any process on the computer could + start Friday with a library of its own loaded inside it, under Friday's name and its microphone and screen permissions + (security audit 2026-11-27, desktop M5). Library validation stays off: the editor's own Node loads extensions' native + modules, which are signed by other people. --> @@ -13,8 +18,6 @@ com.apple.security.cs.allow-unsigned-executable-memory - com.apple.security.cs.allow-dyld-environment-variables - com.apple.security.cs.disable-library-validation com.apple.security.device.audio-input diff --git a/e2e/fixtures/fake-gh.mjs b/e2e/fixtures/fake-gh.mjs index e87e6fb..ed14b6a 100644 --- a/e2e/fixtures/fake-gh.mjs +++ b/e2e/fixtures/fake-gh.mjs @@ -13,7 +13,10 @@ if (process.env.FAKE_GH_DIR) { if (dir) appendFileSync(path.join(dir, "calls.log"), `${args.join(" ")}\n`); const read = (name) => (dir && existsSync(path.join(dir, name)) ? readFileSync(path.join(dir, name), "utf8") : null); - if (args[0] === "pr" && args[1] === "view") { + // An automation watching a repository (automations.ts gh.watch): who's signed in, and the open issues in issues.json. + if (args[0] === "api" && args[1] === "user") process.stdout.write("ada\n"); + else if (args[0] === "issue" && args[1] === "list") process.stdout.write(read("issues.json") ?? "[]"); + else if (args[0] === "pr" && args[1] === "view") { const pr = read("pr.json"); if (pr === null) { process.stderr.write('no pull requests found for branch "refunds"\n'); diff --git a/package-lock.json b/package-lock.json index 79f8f04..74d0235 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "streamdown": "2.6.0", "tailwind-merge": "^3.6.0", "tsx": "^4.23.13", - "undici": "7.29.1", + "undici": "7.30.2", "ws": "^8.21.3" }, "bin": { @@ -65,9 +65,9 @@ } }, "node_modules/@ai-sdk/gateway": { - "version": "4.0.156", - "resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-4.0.156.tgz", - "integrity": "sha512-Nv1ILpLYNDlIV/beyo6Uc6jZcwTDzLMiSqer4PUEmIHqyOceLHf58lv1bfntAJ0xZxaBa9BtYDOv3/Msu0mQrQ==", + "version": "4.0.157", + "resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-4.0.157.tgz", + "integrity": "sha512-2JL4w9I8pSoIONA9LJDdga+L57ousY2PxJrf+Qx2w4AEjYGynYjUTXNDLFvtmgYx9nfKx+8hQug8Z0YBeP+3yg==", "license": "Apache-2.0", "dependencies": { "@ai-sdk/provider": "4.0.39", @@ -283,9 +283,9 @@ } }, "node_modules/@codemirror/lang-markdown": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/@codemirror/lang-markdown/-/lang-markdown-6.5.2.tgz", - "integrity": "sha512-AwBOdkWYuA//WcM0xO5PfHPUcmz/O2i5o0Nsg1U69SII/loCJlFI1Romd9xp2HYb1kYJRGZotyqRghuHH5n8Kw==", + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/@codemirror/lang-markdown/-/lang-markdown-6.5.3.tgz", + "integrity": "sha512-gNfFYi5jS6JkWD5kLW3cXB3g2uMYec9wzjYurMLDHeB0P2Ppc/Qe8UtDv7EBR5BzPQbkaW3/50+7qLtS//1Pqw==", "license": "MIT", "dependencies": { "@codemirror/autocomplete": "^6.7.1", @@ -508,9 +508,9 @@ "license": "MIT" }, "node_modules/@codemirror/view": { - "version": "6.44.1", - "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.44.1.tgz", - "integrity": "sha512-tRpGVUboI0Tehkhk4y0loEuU6O+y9EvXWFTM9gTRSriu+OIHaP9cEbyYUZ3wIRx/1F/BKRPSTF3ihiRiDA84ZQ==", + "version": "6.44.2", + "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.44.2.tgz", + "integrity": "sha512-7yxTh7+iCbxIV9QCJAVlkYjWV/TCHD0zmLIaIR3NOb47YpCWwVUuFUnHwkRC3z+8cXNgeJzrCy4QtlR3fVt5kg==", "license": "MIT", "dependencies": { "@codemirror/state": "^6.7.0", @@ -4540,12 +4540,12 @@ } }, "node_modules/ai": { - "version": "7.0.183", - "resolved": "https://registry.npmjs.org/ai/-/ai-7.0.183.tgz", - "integrity": "sha512-rrPZNiuOKr8L6j9acxrWpE/lKWgR+rYNHDYr9bOvfMLM8RlsX75WMJsMw4LBPZkX6tdjFL8fiLXhTKN29wkkYQ==", + "version": "7.0.184", + "resolved": "https://registry.npmjs.org/ai/-/ai-7.0.184.tgz", + "integrity": "sha512-IiRPrPtvbc6xhkDCsj3xsTXrCvQWYZdHs+KXKQmvAMcQ/x62qFVD2lQE9EkZkUPxhWTzf1n70B2SUPS9qHR6lA==", "license": "Apache-2.0", "dependencies": { - "@ai-sdk/gateway": "4.0.156", + "@ai-sdk/gateway": "4.0.157", "@ai-sdk/provider": "4.0.39", "@ai-sdk/provider-utils": "5.0.85" }, @@ -5320,9 +5320,9 @@ "peer": true }, "node_modules/cross-spawn": { - "version": "7.0.6", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", - "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.1.0.tgz", + "integrity": "sha512-/PHUIV1x/hZLpJN8KmyV2aYkT8pll4RjQ59TmhwkL/9B4HdOtlBQ2pos6iB2cfVRzpGHk3HXlRa8sdVYrPjIYw==", "dev": true, "license": "MIT", "dependencies": { @@ -7561,9 +7561,9 @@ } }, "node_modules/lucide-react": { - "version": "1.81.0", - "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-1.81.0.tgz", - "integrity": "sha512-U+CisvFQ84m+xUJAKKA4q+mykGB1LAmu196hOblQbuNYJgD43iHwpmfYuqcFYHXJu2oqRih5JoH3f5LxwsUegg==", + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-1.83.0.tgz", + "integrity": "sha512-bYosQeQphbbNtdWT4DvY1/wlen2CcsZEQI/pMykcQ8twiu+T7m7cY7s8hOTJiMEAs3nUxCkeCxTe4ohczS5jhA==", "license": "ISC", "peerDependencies": { "@types/react": "*", @@ -7903,9 +7903,9 @@ } }, "node_modules/mdast-util-to-markdown": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/mdast-util-to-markdown/-/mdast-util-to-markdown-2.2.4.tgz", - "integrity": "sha512-aCsogoZ2Oz1EItAlC12A+/uGuzp+CWlDU0xZ3o5jbJaepLsOu2tlxpvHslnX5dRhspD1gxNVkBtYG0yMiIpXoQ==", + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/mdast-util-to-markdown/-/mdast-util-to-markdown-2.2.5.tgz", + "integrity": "sha512-mxOMQQ8NgisvTarkSUqZwi6GmzNo490V932DpEK/0+OETIeVJBzq4QuMt45fqqcsF5EYMlJENjSSAZxh89VJsg==", "license": "MIT", "dependencies": { "@types/mdast": "^4.0.0", @@ -10147,9 +10147,9 @@ } }, "node_modules/tar": { - "version": "7.5.23", - "resolved": "https://registry.npmjs.org/tar/-/tar-7.5.23.tgz", - "integrity": "sha512-lkukzdoGngZHJZXxW4S/E4Fp9ghTDlyZXrQGRNoJ/LXvDKcXUTq2sg5yQe74po7Voea6n/IN09+wE/QvJMiifA==", + "version": "7.5.24", + "resolved": "https://registry.npmjs.org/tar/-/tar-7.5.24.tgz", + "integrity": "sha512-to/OxuCk5DeVONcjjODT7aeoRq5NIPPlfPc0tNML+wLlnf6u5BcJz97Uukv3pT3jzorkFhUevylkAiBr+ZmV2w==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { @@ -10435,9 +10435,9 @@ } }, "node_modules/undici": { - "version": "7.29.1", - "resolved": "https://registry.npmjs.org/undici/-/undici-7.29.1.tgz", - "integrity": "sha512-RYONW2MeafgYlkVOKYKkA/Ag7BmXqgIWCa8t1m0JcxrQg9pI9lEqRhAOruOBCbAohOa/gkCF+iPi9hrgvTzu6Q==", + "version": "7.30.2", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.30.2.tgz", + "integrity": "sha512-mLyPQnHwUxaM/rideoK/+KL8DaAJLRl4aBCfmX444aCSLnIaomqPLtNRe2jdCYcsk5wZzXrDIQC8ZeYNRAYyIA==", "license": "MIT", "engines": { "node": ">=20.18.1" @@ -10758,9 +10758,9 @@ "license": "ISC" }, "node_modules/ws": { - "version": "8.23.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.23.0.tgz", - "integrity": "sha512-wCkmX8QMOrKjgO8HW2WyDbTSGeqkocxgDzS9iR79rEAexty6/2qzilx3Ag8Tqf9ykop3irLKle0MtVn5qjVnoQ==", + "version": "8.23.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.23.1.tgz", + "integrity": "sha512-1rzWDSN0NOi3tpwgHsQExjWRoKUGtjCkJ2gZRaaRtzhYLboMytOI9pj9PU7yCgY37auqdd4OyLofZDbkeuZmPA==", "license": "MIT", "engines": { "node": ">=10.0.0" diff --git a/package.json b/package.json index 3beb2be..1a2181c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "friday-work", - "version": "0.4.4", + "version": "0.4.5", "description": "One app for all your coding agents: Claude Code, Codex, Cursor and more, side by side or splitting a job, on your own computer. No account, nothing hosted.", "license": "MIT", "homepage": "https://www.tryfridaywork.com", @@ -65,7 +65,7 @@ "shiki": "^4.4.3", "streamdown": "2.6.0", "tailwind-merge": "^3.6.0", - "undici": "7.29.1", + "undici": "7.30.2", "ws": "^8.21.3", "tsx": "^4.23.13" }, @@ -107,6 +107,13 @@ "filter": [ "**/*" ] + }, + { + "from": "build/host-package", + "to": "host-package", + "filter": [ + "friday.tgz" + ] } ], "directories": { diff --git a/public/index.html b/public/index.html index 6634593..400ed45 100644 --- a/public/index.html +++ b/public/index.html @@ -17,6 +17,13 @@ // Frosted glass (prefs.ts applyGlass): on before the first paint, so the window never flashes solid first. if (localStorage.getItem("mpa.glass") === "1") document.documentElement.classList.add("glass"), window.fridayDesktop && window.fridayDesktop.glassNative && document.documentElement.classList.add("glass-native"); } catch (e) {} + // The fonts and KaTeX's stylesheet below are fetched beside the page (rel="preload") and become stylesheets once they + // arrive. Done from here, not an onload="" on each: the page's policy runs no inline handlers (page-csp.ts). A load + // doesn't bubble, so it is heard on its way down. + document.addEventListener("load", function (e) { + var l = e.target; + if (l && l.tagName === "LINK" && l.rel === "preload" && l.getAttribute("as") === "style") l.rel = "stylesheet"; + }, true); ${panZoom(big)}${SIZER}`; } - // A page: the agent's own, with Friday's policy first in its head (a policy can only be narrowed by another, never widened). + // A page: the agent's own, with Friday's policy first in it, straight after the doctype (a policy can only be narrowed by + // another, never widened). First in the page, not first in its : a script written above the head ran before the + // policy was read, and a
was taken for the head, where a policy in the body counts for nothing (audit M2). const doc = /]/i.test(code) ? code : `${code}`; - const withHead = /]*>/i.test(doc) ? doc.replace(/]*>/i, (h) => `${h}${base}`) : doc.replace(/]*>/i, (h) => `${h}${base}`); - return /<\/body>/i.test(withHead) ? withHead.replace(/<\/body>/i, `${SIZER}`) : `${withHead}${SIZER}`; + const doctype = /^\s*]*>/i.exec(doc)?.[0] ?? ""; + const rest = doc.slice(doctype.length); + // Friday's kit goes after it, wherever the page's own head is: a parser gathers what comes before the body into the head. + const page = `${doctype}${policy}${base}${rest}`; + return /<\/body>/i.test(page) ? page.replace(/<\/body>/i, `${SIZER}`) : `${page}${SIZER}`; } /** The height a block is drawn from, before it says its own: a page is usually taller than a diagram. */ @@ -290,7 +297,10 @@ function LiveFrame({ kind, code, tall, exporter }: { kind: LiveKind; code: strin f.title = KINDS[kind].label; // Scripts, and nothing else: no origin of its own, no forms, no popups, no navigating the app. f.setAttribute("sandbox", "allow-scripts"); - f.srcdoc = doc; + // Friday's frame page (page-csp.ts), which carries the policy an agent's page is held to as a header and writes the page + // it is handed in its name. Not srcdoc: that takes the policy of the app around it, under which no script of the agent's runs. + f.name = doc; + f.src = "/api/frame"; at.append(f); } // The same scheme as the page around it, or the browser paints the frame's own opaque canvas behind it. @@ -467,6 +477,11 @@ export function LiveImage(props: React.ImgHTMLAttributes & { / // is said to be missing, and then with a way to ask again (Arun, 2026-10-28: "iron everything and ensure we are good"). const [tries, setTries] = useState(0); const [gone, setGone] = useState(false); + // One from the web waits to be asked for, as in a document (WorkPanels DocImage): an answer can be steered by what the agent + // read, and a picture fetched the moment it is drawn tells whoever wrote its address who is watching, and whatever the + // address was made to carry (audit M1, 2026-11-27). Friday's own, a data: or blob: one and one from the folder show at once. + const [asked, setAsked] = useState(false); + const far = typeof rest.src === "string" && /^https?:/i.test(rest.src) && !rest.src.startsWith(`${location.origin}/`) ? rest.src : ""; const own = src ?? (typeof rest.src === "string" && rest.src.startsWith("/api/") ? rest.src : null); if (own) (rest as { src?: string }).src = tries ? `${own}${own.includes("?") ? "&" : "?"}try=${tries}` : own; // Named in passing, and not there: the name stands alone, with nothing said about a picture nobody asked to see. @@ -474,6 +489,16 @@ export function LiveImage(props: React.ImgHTMLAttributes & { / if (gone && quiet) onMissing?.(); }, [gone, quiet]); // eslint-disable-line react-hooks/exhaustive-deps if (gone && quiet) return null; + if (far && !asked) + return ( + + {/* The host it would be asked of: what follows an "@", never the name put before one. */} + {props.alt || "A picture"} from {far.split("/")[2]!.replace(/.*@/, "")}.{" "} + + + ); if (gone) return ( diff --git a/src/client/MachinesMap.tsx b/src/client/MachinesMap.tsx index 3130ef2..20a808b 100644 --- a/src/client/MachinesMap.tsx +++ b/src/client/MachinesMap.tsx @@ -4,6 +4,7 @@ import { busyness, rankComputers, toolName, type MachineFacts, type PlaceCandida import { EngineMark } from "./BrandMarks.js"; import { Icon } from "./icons.js"; import { lastSeen, type State } from "./Computers.js"; +import { hostLine, openHost, type HostView } from "./hosts.js"; import "./machines-map.css"; /** @@ -48,14 +49,17 @@ interface Node { tools: { tool: string; name: string; loggedIn?: boolean | null }[]; facts: MachineFacts | null; problem?: string; + /** A machine that runs on its own (a host, opened here over SSH), not one lending its tools to this one. */ + host?: HostView; } type Pos = Record; -function nodesOf(state: State): Node[] { +function nodesOf(state: State, hosts: HostView[]): Node[] { const here: Node = { id: "here", name: state.here?.name || "This computer", here: true, connected: true, platform: state.here?.platform, tools: state.here?.tools ?? [], facts: state.here?.facts ?? null }; return [ here, ...state.computers.map((c) => ({ id: c.id, name: c.name, here: false, connected: c.connected, platform: c.platform, seen: c.seen, address: c.address, tools: c.tools, facts: c.facts ?? null, problem: c.problem })), + ...hosts.map((h): Node => ({ id: `host-${h.id}`, name: h.label, here: false, connected: h.link === "up", seen: h.lastSeen, tools: [], facts: null, host: h })), ]; } @@ -95,10 +99,11 @@ const readJson = (key: string, fallback: T): T => { } }; -export function MachinesMap({ state, onAdd }: { state: State; onAdd?: () => void }) { - const nodes = nodesOf(state); - const ranked = rankComputers(nodes.map((n): PlaceCandidate => ({ id: n.id, name: n.name, connected: n.connected, tools: n.tools, facts: n.facts }))); - const best = ranked[0]?.ok && nodes.length > 1 ? ranked[0] : null; +export function MachinesMap({ state, hosts = [], onAdd }: { state: State; /** The machines that run on their own, drawn with a line that says SSH. */ hosts?: HostView[]; onAdd?: () => void }) { + const nodes = nodesOf(state, hosts); + // Placement picks among the computers sessions here can run on: a host runs its own. + const ranked = rankComputers(nodes.filter((n) => !n.host).map((n): PlaceCandidate => ({ id: n.id, name: n.name, connected: n.connected, tools: n.tools, facts: n.facts }))); + const best = ranked[0]?.ok && ranked.length > 1 ? ranked[0] : null; const wrap = useRef(null); const [size, setSize] = useState({ w: 0, h: readJson(HEIGHT_KEY, 240) }); const [moved, setMoved] = useState(() => readJson(POS_KEY, {})); @@ -205,7 +210,7 @@ export function MachinesMap({ state, onAdd }: { state: State; onAdd?: () => void const my = (y0 + y1) / 2; d = `M${x0},${y0} C${x0},${my} ${x1},${my} ${x1},${y1}`; } - return { id: n.id, d, x: (x0 + x1) / 2, y: (y0 + y1) / 2, on: n.connected, busy: !!n.facts?.agents, label: routeOf(n.address, n.connected) }; + return { id: n.id, d, x: (x0 + x1) / 2, y: (y0 + y1) / 2, on: n.connected, busy: n.host ? !!n.host.running : !!n.facts?.agents, label: n.host ? (n.connected ? "SSH" : "Not connected") : routeOf(n.address, n.connected), ssh: !!n.host }; }); return ( @@ -236,7 +241,7 @@ export function MachinesMap({ state, onAdd }: { state: State; onAdd?: () => void >
+ {n.name} + {[`${h.ssh} over SSH`, h.os?.split(" ")[0] === "Darwin" ? "macOS" : h.os?.split(" ")[0], h.version ? `Friday ${h.version}` : ""].filter(Boolean).join(" · ")} +
+
+ {h.link === "up" ? "Runs on its own: its sessions keep going when this computer sleeps. " : `${hostLine(h)}. `} + +
+ + ); + } const f = n.facts; const signed = n.tools.filter((t) => t.loggedIn === true); const busy = busyness(f); diff --git a/src/client/ManagerWindow.tsx b/src/client/ManagerWindow.tsx index 9403b79..6a36732 100644 --- a/src/client/ManagerWindow.tsx +++ b/src/client/ManagerWindow.tsx @@ -2,22 +2,32 @@ * The Captain's window, its settings and the New Captain sheet: loaded the first time one opens, so the sidebar's Captains don't * weigh on the first screen (2026-11-25: the first load went 2 KB over its budget with the simple window). */ -import { useEffect, useRef, useState, type ReactNode } from "react"; +import { createPortal } from "react-dom"; +import { Suspense, lazy, useEffect, useRef, useState, type ReactNode, type RefObject } from "react"; +import { Badge } from "./components/affect/badge.js"; +import { Button } from "./components/affect/button.js"; +import { Popover } from "./components/affect/popover.js"; +import { SegmentedControl } from "./components/affect/segmented-control.js"; import { Dialog, DialogContent, DialogTitle, DialogDescription } from "@/components/ui/dialog"; -import type { ChatLine, Manager, ManagerAct, ManagerLevel, ManagerTask } from "../managers.js"; +import type { ChatLine, Manager, ManagerAct, ManagerLevel, ManagerTask, ReadyItem } from "../managers.js"; import { ENGINE_MODEL_INFO, ENGINE_NAMES, type EngineTool } from "../types.js"; +import { MISSION_ROUNDS } from "../missions.js"; +import { runClock } from "../step-words.js"; import { AgentModelPicker, wordOf } from "./AgentModelPicker.js"; import { EngineMark } from "./BrandMarks.js"; import { useEngineModelInfo } from "./EngineModelPill.js"; import { useMachine } from "./local.js"; -import { Icon } from "./icons.js"; +import { Icon, type IconName } from "./icons.js"; import type { Identity } from "./storage.js"; import { MenuButton, Picker, Switch, useConfirm } from "./ui.js"; import { md } from "./markdown.js"; +import { LiveClock, elapsed } from "./presence.js"; import { Shine } from "./shine.js"; import { ArrowUpIcon } from "lucide-react"; import { PromptInput, PromptInputBody, PromptInputFooter, PromptInputSubmit, PromptInputTextarea } from "@/components/ai-elements/prompt-input"; -import { clockOf, forYouOf, managerFor, readyFacts, ManagerFace, type ManagedProject, type ManagerView, type ManagersApi } from "./Managers.js"; +import { askShort, clockOf, forYouOf, managerFor, progressOf, readyFacts, ManagerFace, ProgressRing, StatusChip, type LiveView, type ManagedProject, type ManagerView, type ManagersApi } from "./Managers.js"; +import { BlobFace } from "./teammate-face.js"; +import { api } from "./api.js"; /** One of Run's options as a small on/off chip: a switch to a screen reader, its words always showing. */ function RunChip({ on, onChange, label, children }: { on: boolean; onChange: (v: boolean) => void; label: string; children: ReactNode }) { @@ -28,20 +38,25 @@ function RunChip({ on, onChange, label, children }: { on: boolean; onChange: (v: ); } +/** A status icon whose shape says the state without its colour (managers.css .mgr-si); here, not in Managers.tsx, which loads first. */ +type StatusTone = "working" | "needs" | "done" | "failed" | "idle" | "queued"; +const StatusIcon = ({ s }: { s: StatusTone }) => ; + /** - * What it did while you were away (managers.ts awayReport, here because that file reaches for node modules): what it decided, what's - * ready, what still waits on you. Null when there's no Away or nothing happened in it. + * What it did while you were away (managers.ts awayReport, here because that file reaches for node modules): what it decided for + * you, what's ready, what still waits on you and what failed its check. Null when there's no Away or nothing happened in it. */ -function awayOf(m: ManagerView, now = Date.now()): { decided: ManagerAct[]; ready: number; waiting: number; held: number } | null { +function awayOf(m: ManagerView, now = Date.now()): { since: number; end: number; decided: ManagerAct[]; ready: ReadyItem[]; waiting: ManagerAct[]; failed: ManagerAct[]; stuck: { sid: string; title: string; since: number }[] } | null { const a = m.away; if (!a) return null; const end = a.back ?? now; const inside = (at: number) => at >= a.since && at <= end; const decided = m.log.filter((x) => x.kind === "assumed" && inside(x.at)); - const ready = (m.ready ?? []).filter((r) => inside(r.at)).length; - const waiting = forYouOf(m, now).filter((x) => inside(x.at)).length; - const held = m.log.filter((x) => (x.kind === "skipped" || x.kind === "sent-back") && inside(x.at) && !/^Just looked/.test(x.text)).length; - return decided.length || ready || waiting || held ? { decided, ready, waiting, held } : null; + const ready = (m.ready ?? []).filter((r) => inside(r.at)); + const waiting = forYouOf(m, now).filter((x) => inside(x.at)); + const failed = m.log.filter((x) => x.kind === "sent-back" && inside(x.at)); + const stuck = (m.threads ?? []).filter((t) => t.state === "needs" && inside(t.since) && !waiting.some((q) => q.sid === t.sid)); + return decided.length || ready.length || waiting.length || failed.length || stuck.length ? { since: a.since, end, decided, ready, waiting, failed, stuck } : null; } /** @@ -50,39 +65,46 @@ function awayOf(m: ManagerView, now = Date.now()): { decided: ManagerAct[]; read * check-ins and its guard at the foot. Settings, from the gear: how much it does, what it runs on, its limits, its mascot, what it * knows, and Remove. Nothing you change once a week sits between you and what's happening. */ -export function ManagerPanel({ m, p, api: a, onClose, onSettings }: { m: ManagerView; p: ManagedProject | undefined; api: ManagersApi; onClose: () => void; /** Its settings, in a modal of their own (2026-11-25: "make it a modal instead"). */ onSettings: () => void }) { - return ( -
-
- -
-
- {m.project.name} -
- {captainState(m)} +export function ManagerPanel({ m, p, api: a, onClose, onSettings, headIn }: { m: ManagerView; p: ManagedProject | undefined; api: ManagersApi; onClose: () => void; /** On the Captain's page: its header drawn in the window's band (CaptainPage.tsx), with no close. */ headIn?: HTMLElement | null; /** Its settings, in a modal of their own (2026-11-25: "make it a modal instead"). */ onSettings: () => void }) { + const header = ( +
+ +
+
+ {m.project.name}
- {/* A new conversation, and the ones before it. */} - {m.on && ( - [ - { label: "New conversation", icon: "plus" as const, disabled: !(m.chat ?? []).length, onSelect: () => void a.newChat(m.id) }, - ...((m.pastChats ?? []).length ? [{ heading: "Earlier" }, ...(m.pastChats ?? []).map((c) => ({ label: c.title, sub: sameDay(c.at, Date.now()) ? clockOf(c.at) : new Date(c.at).toLocaleDateString([], { month: "short", day: "numeric" }), onSelect: () => void a.openChat(m.id, c.at), action: { icon: "trash" as const, label: `Delete "${c.title}"`, onSelect: () => void a.deleteChat(m.id, c.at) } }))] : []), - ]} - /> - )} - + + + +
+ {/* A new conversation, and the ones before it. */} + {m.on && ( + [ + { label: "New conversation", icon: "plus" as const, disabled: !(m.chat ?? []).length, onSelect: () => void a.newChat(m.id) }, + ...((m.pastChats ?? []).length ? [{ heading: "Earlier" }, ...(m.pastChats ?? []).map((c) => ({ label: c.title, sub: sameDay(c.at, Date.now()) ? clockOf(c.at) : new Date(c.at).toLocaleDateString([], { month: "short", day: "numeric" }), onSelect: () => void a.openChat(m.id, c.at), action: { icon: "trash" as const, label: `Delete "${c.title}"`, onSelect: () => void a.deleteChat(m.id, c.at) } }))] : []), + ]} + /> + )} + + {!headIn && ( -
+ )} +
+ ); + return ( +
+ {headIn ? createPortal(header, headIn) : header} {/* No How it works page (2026-11-25: "get rid of this page"): the settings' level cards say it. */}
@@ -111,15 +133,24 @@ function PanelNow({ m, a, onClose }: { m: ManagerView; a: ManagersApi; onClose: const asks = forYouOf(m); const ready = m.on ? (m.ready ?? []) : []; const open = (sid?: string) => sid && (dispatchEvent(new CustomEvent("friday:open-session", { detail: { sid } })), onClose()); - const away = m.away?.back && !m.away.seen ? awayOf(m) : null; + // Back from Away: the card until Got it, then a one-line divider for as long as this window is open; Show brings the card back. + const [awayDone, setAwayDone] = useState(false); + const [awayShown, setAwayShown] = useState(false); + const back = m.away?.back ? awayOf(m) : null; + const away = back && (!m.away!.seen || awayShown) ? back : null; const awayOn = !!m.away && !m.away.back && m.away.until > Date.now(); const [msg, setMsg] = useState(""); const [sending, setSending] = useState(false); + const [filter, setFilter] = useState<"all" | "needs" | "working">("all"); + const [page, setPage] = useState(0); const run = m.level === "run"; // Its conversation, less a day's digest line (the greeting says how things stand, live). const chat = (m.chat ?? []).filter((c) => !(c.who === "captain" && /^Today in .*:/i.test(c.text.trim()))); const thinking = (m.chat ?? []).at(-1)?.who === "you"; const scroller = useRef(null); + const finishAllRef = useRef(""); + const msgRef = useRef(""); + msgRef.current = msg; // Each thread as it stands now, ready and waiting-on-you from its own record. const readySids = new Set(ready.map((r) => r.sid)); const askSids = new Set(asks.map((x) => x.sid).filter(Boolean)); @@ -137,17 +168,29 @@ function PanelNow({ m, a, onClose }: { m: ManagerView; a: ManagersApi; onClose: ...tasks.map((t) => ({ at: t.at, key: `t${t.id}`, task: t })), ].sort((x, y) => x.at - y.at); useEffect(() => { - // The conversation's end once there is one; before, the top, where what needs you is pinned. + // Its foot, always: the latest answer and what waits on you sit just over the box, as a chat's do (Arun, 2026-11-27: "make + // sure the answer stuff is pinned to the bottom of the chat and not at the top"). const el = scroller.current; - if (el) el.scrollTop = items.length || thinking ? el.scrollHeight : 0; - }, [items.length, thinking, m.id]); - const say = (t: string) => { + if (el) requestAnimationFrame(() => (el.scrollTop = el.scrollHeight)); + }, [items.length, thinking, m.id, asks.length]); + const say = (t: string, opts?: SayOpts): Promise => { const text = t.trim(); - if (!text || sending) return; + if (!text || sending) return Promise.resolve(false); setSending(true); - void a.say(m.id, text).then((ok) => (setSending(false), ok && setMsg(""))); + return a.say(m.id, text, opts).then((ok) => (setSending(false), ok && setMsg(""), ok)); }; + // (Before the early return below: hooks run in the same order on and off.) ⌘↵ with nothing in the box finishes the idle threads, as the Finish button's key says. + useEffect(() => { + const k = (e: KeyboardEvent) => { + if (!(e.key === "Enter" && (e.metaKey || e.ctrlKey)) || !run || !finishAllRef.current || msgRef.current.trim()) return; + e.preventDefault(); + void say(finishAllRef.current); + }; + addEventListener("keydown", k); + return () => removeEventListener("keydown", k); + }); + if (!m.on) finishAllRef.current = ""; if (!m.on) return (
@@ -158,36 +201,57 @@ function PanelNow({ m, a, onClose }: { m: ManagerView; a: ManagersApi; onClose:
); - // The first thing it says, from how its threads stand now (no tokens): the count that matters most first, then the next step. - const parts = [ready.length && `${ready.length} ready to ship`, waiting.length && `${waiting.length} waiting on you`, working.length && `${working.length} working`, idle.length && `${idle.length} sitting idle`].filter(Boolean) as string[]; - const lead = parts.length === 1 ? parts[0]!.replace(/^(\d+) /, (_, n) => `${n} thread${n === "1" ? "" : "s"} `) : (parts[0] ?? ""); - const rest = parts.slice(1); + // The first thing it says, from how its threads stand now (no tokens): what's left unfinished and the next step. The counts of + // what's ready and what needs you are the header's chips now, so the line no longer repeats them. const unfinished = idle[0] ?? waiting[0]; const greeting = !threads.length ? `No threads in ${m.project.name} yet.` : null; const quoted = (t: { title: string }) => `"${t.title}"`; + finishAllRef.current = !chat.length && !thinking ? (idle.length > 1 ? `Finish the idle threads: ${idle.slice(0, 6).map((t) => `"${t.title}"`).join(", ")}` : idle[0] ? `Finish "${idle[0].title}"` : "") : ""; const finishAll = idle.length > 1 ? `Finish the idle threads: ${idle.slice(0, 6).map(quoted).join(", ")}` : unfinished ? `Finish ${quoted(unfinished)}` : ""; // The threads, what needs you first: waiting on you, ready, working, then idle; newest change first within each. const RANK = { needs: 0, ready: 1, working: 2, idle: 3, stopped: 3 } as const; - const rows = [...threads].sort((x, y) => RANK[x.state] - RANK[y.state] || y.since - x.since); + const all = [...threads].sort((x, y) => RANK[x.state] - RANK[y.state] || y.since - x.since); + // The list as filtered (Arun, 2026-11-27: the threads filter, All / Needs you / Working, back above the list). + const rows = filter === "all" ? all : all.filter((t) => t.state === (filter === "needs" ? "needs" : "working")); + const ask = asks[Math.min(page, asks.length - 1)]; // Your last ask, for ↑ in an empty box. const lastSaid = [...(m.chat ?? [])].reverse().find((c) => c.who === "you")?.text ?? ""; const focusBox = () => requestAnimationFrame(() => document.querySelector(".mgr-one-foot .mgr-composer-ta")?.focus()); const quick = run ? ["What's left to do?", "Run the tests", "Review today's changes"] : ["What's left to do?", "What changed today?", "Anything risky?"]; + // Each row's second line and its steps, from the Captain's own record of the thread: its question, its checked work, else the + // last things it did with it (newest last). + const readyBySid = new Map(ready.map((r) => [r.sid, r])); + const askBySid = new Map(asks.filter((x) => x.sid).map((x) => [x.sid!, x])); + const stepsOf = (sid: string, title: string) => + m.log.filter((x) => x.sid === sid && x.kind !== "for-you" && x.kind !== "woke").slice(0, 4).reverse().map((x) => stepText(x.text, title)); + const answer = () => { + const el = scroller.current?.querySelector(".mgr-dc input"); + el?.scrollIntoView({ block: "nearest", behavior: "smooth" }); + el?.focus(); + }; return (
{/* What needs you, pinned: its questions, then work ready to ship, then a risky or overlapping change. */} - {(asks.length > 0 || ready.length > 0 || notices.length > 0 || away || awayOn) && ( + {(asks.length > 0 || ready.length > 0 || notices.length > 0 || away || awayOn || (back && awayDone)) && (
{away && ( -
- - While you were away: {away.decided.length} decided{away.ready ? `, ${away.ready} ready` : ""} - {away.decided.length > 0 && {away.decided.slice(0, 2).map((x) => x.text.replace(/^Decided:\s*/i, "")).join(" · ")}} + (m.threads ?? []).find((t) => t.sid === sid)?.title} + open={open} + onAnswer={answer} + onGotIt={() => (setAwayDone(true), setAwayShown(false), void (m.away!.seen || a.awaySeen(m.id)))} + /> + )} + {back && !away && awayDone && ( +
+ + While you were away{awayFor(back) ? ` · ${awayFor(back)}` : ""} · {back.waiting.length + back.stuck.length + back.failed.length + back.decided.length + back.ready.length} things -
)} @@ -196,23 +260,42 @@ function PanelNow({ m, a, onClose }: { m: ManagerView; a: ManagersApi; onClose: Away until {clockOf(m.away!.until)}
)} - {asks.slice(0, 3).map((x) => ( - a.answer(m.id, x.at, t)} onDismiss={() => void a.answer(m.id, x.at, null)} /> - ))} - {ready.slice(0, 3).map((r) => ( -
- - {r.title} - {readyFacts(r)} - - - -
- ))} + {ask && ( + t.sid === ask.sid)?.title} + pos={Math.min(page, asks.length - 1)} + of={asks.length} + onPage={(d) => setPage((p) => Math.max(0, Math.min(asks.length - 1, Math.min(p, asks.length - 1) + d)))} + onAnswer={(t) => a.answer(m.id, ask.at, t)} + onDismiss={() => void a.answer(m.id, ask.at, null)} + /> + )} + {ready.slice(0, 3).map((r) => { + const c = checkOf(r); + return ( +
+ + + {r.title} + + + {c.note && ` · ${c.note}`} + + + {c.word} + {/* Put away, on hover only: at rest the card is the mock's, its chip and Review. */} + + {/* The primary button ends the row. */} + +
+ ); + })} {notices.slice(0, 2).map((n) => ( - )} - {run && unfinished && ( - - )} - {ready.length > 0 && ( - - )} + {greeting ? ( +

{greeting}

+ ) : ( + unfinished && ( +
+

+ {idle.length ? `${idle.length} idle` : `${waiting.length} waiting on you`} + {idle.length ? " stopped part way." : ""} +

+ {!run && ( + + )} + {run && ( + + )} +
+ ) + )} + {all.length > 0 && ( +
+ Threads + t.state === "needs").length }, + { value: "working", label: "Working", count: all.filter((t) => t.state === "working").length }, + ]} + />
)} {rows.length > 0 && (
    - {rows.map((t) => ( -
  • - - {run && (t.state === "idle" || t.state === "stopped") && ( - - )} -
  • - ))} + {rows.map((t) => { + const finish = run && (t.state === "idle" || t.state === "stopped"); + const steps = stepsOf(t.sid, t.title); + const tool = t.tool ? (ENGINE_NAMES[t.tool] ?? t.tool) : ""; + const st = stepOf(t); + const q = askBySid.get(t.sid)?.text; + const line = + t.state === "needs" ? (q ? askLine(q) : "Waiting on you") + : t.state === "ready" && readyBySid.get(t.sid) ? + : t.state === "working" ? [st?.text ?? steps.at(-1) ?? tool, st?.of ? `step ${st.n} of ${st.of}` : ""].filter(Boolean).join(" · ") + : (steps.at(-1) ?? (t.state === "stopped" ? "Stopped part way" : "Idle")); + return ( + open(t.sid)} + go={ + finish ? ( + + ) : t.state === "needs" && askBySid.has(t.sid) ? ( + + ) : t.state === "ready" ? ( + + ) : null + } + /> + ); + })}
)}
@@ -292,7 +407,15 @@ function PanelNow({ m, a, onClose }: { m: ManagerView; a: ManagersApi; onClose:
) ) : x.goal ? ( - void a.giveUp(m.id, x.goal!.id)} onReview={() => scroller.current?.scrollTo({ top: 0, behavior: "smooth" })} /> + void (x.goal!.mission ? a.stopMission(m.id, x.goal!.id) : a.giveUp(m.id, x.goal!.id))} + onPause={(p) => void a.pauseMission(m.id, x.goal!.id, p)} + onReview={() => scroller.current?.scrollTo({ top: 0, behavior: "smooth" })} + /> ) : (
@@ -313,32 +436,38 @@ function PanelNow({ m, a, onClose }: { m: ManagerView; a: ManagersApi; onClose:
{!chat.length && !thinking && !msg && ( -
+
{quick.map((q) => ( ))}
)} -
- say(msg)} className="prompt"> - - setMsg(e.currentTarget.value)} - onKeyDown={(e) => { - if (e.key === "ArrowUp" && !msg && lastSaid) (e.preventDefault(), setMsg(lastSaid)); - else if (e.key === "Escape" && msg) (e.preventDefault(), e.stopPropagation(), setMsg("")); - }} placeholder={run ? `What should get done in ${m.project.name}?` : `Ask about ${m.project.name}…`} disabled={sending} /> - - -
- - {sending ? undefined : } - -
-
-
-
+ {run ? ( + say(msg, opts)} /> + ) : ( +
+ void say(msg)} className="prompt"> + + setMsg(e.currentTarget.value)} + onKeyDown={(e) => { + if (e.key === "ArrowUp" && !msg && lastSaid) (e.preventDefault(), setMsg(lastSaid)); + else if (e.key === "Escape" && msg) (e.preventDefault(), e.stopPropagation(), setMsg("")); + }} placeholder={`Ask about ${m.project.name}…`} disabled={sending} /> + + + +
+ + {sending ? undefined : } + +
+
+
+
+ )} {a.error &&

{a.error}

}
@@ -362,15 +491,27 @@ function CopyButton({ text }: { text: string }) { } -/** How the Captain stands, in a few words beside its name: what needs you, else what's working, else what it watches. */ -function captainState(m: ManagerView): string { - if (!m.on) return "Off"; - const forYou = forYouOf(m).length + (m.ready?.length ?? 0); - if (forYou) return `${forYou} for you`; +/** + * How the Captain stands, beside its name: what's for you as chips that say what they are ("1 ready", "1 needs you", not "2 for + * you"), else what's working, else what it watches. + */ +function CaptainState({ m }: { m: ManagerView }) { + if (!m.on) return <>Off; + const asks = forYouOf(m); + const askSids = new Set(asks.map((x) => x.sid)); + const needs = asks.length + (m.threads ?? []).filter((t) => t.state === "needs" && !askSids.has(t.sid)).length; + const ready = m.ready?.length ?? 0; const working = (m.threads ?? []).filter((t) => t.state === "working").length; - if (working) return `${working} working`; const n = (m.threads ?? []).length; - return n ? `Watching ${n} thread${n === 1 ? "" : "s"}` : "Watching"; + if (ready || needs) + return ( + <> + {ready > 0 && {ready} ready} + {needs > 0 && {needs} needs you} + + ); + if (working) return {working} working; + return <>{n ? `Watching ${n} thread${n === 1 ? "" : "s"}` : "Watching"}; } /** @@ -406,17 +547,37 @@ export function CaptainSettings({ m, a, open, onClose, onBack }: { m: ManagerVie
On - Watches {m.project.name}'s threads + {m.autonomy ? `Plans and runs work in ${m.project.name}` : `Watches ${m.project.name}'s threads`} set({ on })} label={m.on ? "Turn the Captain off" : "Turn the Captain on"} />
-
- - Start work by itself - {m.level === "run" ? "Starts, checks and finishes what you ask" : "Off: it only tells you"} - - set({ level: v ? "run" : "help" })} label="Start work by itself" /> -
+ {/* A Captain v2 goes as far as its autonomy says (its chat's picker sets it too); the level is the older flow's. */} + {m.autonomy ? ( +
+ + On its own + {AUTONOMY_PICK.find((x) => x.value === m.autonomy)?.hint} + + set({ autonomy })} /> +
+ ) : ( +
+ + Start work by itself + {m.level === "run" ? "Starts, checks and finishes what you ask" : "Off: it only tells you"} + + set({ level: v ? "run" : "help" })} label="Start work by itself" /> +
+ )} + {m.autonomy && ( +
+ + When a goal is done + {SHIP_PICK.find((x) => x.value === (m.ship ?? "folder"))?.hint} + + set({ ship })} /> +
+ )}
Runs on @@ -424,35 +585,49 @@ export function CaptainSettings({ m, a, open, onClose, onBack }: { m: ManagerVie set(v)} />
- More -
- New threads - set({ threadTool: v })} /> -
+ + More settings + + + {/* Threads, splitting, the queue and tidying are the older flow's; a Captain v2's agents are its own (Checks work still holds). */} + {!m.autonomy && ( +
+ New threads + set({ threadTool: v })} /> +
+ )}
- On its own + {m.autonomy ? "Checks" : "On its own"}
- set({ startThreads: v })} label="Start new threads by itself"> - Starts threads - - set({ startQueued: v })} label="Start the next queued task"> - Starts queued - + {!m.autonomy && ( + <> + set({ startThreads: v })} label="Start new threads by itself"> + Starts threads + + set({ startQueued: v })} label="Start the next queued task"> + Starts queued + + + )} set({ checkWork: v })} label="Check finished work and send failures back"> Checks work - set({ splitWork: v })} label="Split big tasks into parts"> - Splits big tasks - - set({ tidyIdle: v })} label="Stop idle threads' tools and clear finished parts"> - Tidies idle - + {!m.autonomy && ( + <> + set({ splitWork: v })} label="Split big tasks into parts"> + Splits big tasks + + set({ tidyIdle: v })} label="Stop idle threads' tools and clear finished parts"> + Tidies idle + + + )}
Limits
- ({ value: n, label: `${n} check-ins a day` }))} onChange={(n) => set({ dailyWakes: n })} /> + ({ value: n, label: m.autonomy ? turnsWord(n) : `${n} check-ins a day` }))} onChange={(n) => set({ dailyWakes: n })} /> ({ value: q.value, label: q.label }))} onChange={(v) => set({ quiet: QUIET.find((q) => q.value === v)?.q ?? null })} />
@@ -472,9 +647,9 @@ export function CaptainSettings({ m, a, open, onClose, onBack }: { m: ManagerVie
{a.error &&

{a.error}

}
- + - Never approves PRs, merges, deploys or money + {m.autonomy ? guardOf(m.ship) : "Never approves PRs, merges, deploys or money"} + ); + }; + const firstLive = g.threads.find((t) => byId.get(t.sid)?.state === "working")?.sid ?? g.threads[0]?.sid; return ( -
+
- {pill} - + {ms && ( + + + Mission + + )} + {chip.word} + + {ms && (live ? : done ? {runClock(ended - g.at)} : null)} + {pieces.length > 0 && !done && ( + + )} + {(!ms || live) && ( + [ + ...(live ? [{ label: ms!.paused ? "Carry on" : "Pause", icon: (ms!.paused ? "play" : "pause") as IconName, onSelect: () => onPause(!ms!.paused) }] : []), + ...(firstLive ? [{ label: "Open threads", icon: "external" as IconName, onSelect: () => open(firstLive) }] : []), + { label: ms ? "Stop the mission" : "Give up", icon: "x" as IconName, danger: true, onSelect: onGiveUp }, + ]} + /> + )} +
{g.title} -
- {pieces.length ? pieces.map((x) => ) : } -
- {pieces.length !== 1 &&
{summary}
} - {pieces.length > 0 && ( + {ms && ( +

+ + + Done when + {" "} + {ms.done} +

+ )} + {!pieces.length &&

Planning the threads…

} + {pieces.length > 0 && !done && crew && ( + + open(sid)} /> + + )} + {pieces.length > 0 && !done && !crew && (
- {pieces.map((x) => ( - - ))} + {after.length > 0 && ms &&
Now · {ms.parallel} at once
} + {now.map(row)} + {after.length > 0 &&
After
} + {after.map(row)} +
+ )} + {(judged || note) && ( +
+ {judged && ( +
+ Done? + + {rounds.map((r, i) => ( + + {r === "yes" ? : r === "no" ? : null} + + ))} + + {/* The judge's answer on the squares' line, the reason under it (the mock's judge block). */} + {done ? Yes : g.status === "checking" ? Judging : up to {MISSION_ROUNDS} rounds} +
+ )} + {note &&

{note}

}
)} - {g.status === "ready" && ( -
- + {!folded && ( +
    + {pieces.map((x) => { + const d = x.sid ? /(\d+) files? \+(\d+) [−-](\d+)/.exec(readyBy.get(x.sid)?.facts ?? "") : null; + return ( +
  1. + + {sentence(x.text)} + {d && ( + + +{d[2]} −{d[3]} + + )} +
  2. + ); + })} +
+ )} +
+ )} + {(ms || g.status === "ready") && ( +
+ {ms && ms.budgetUsd > 0 ? ( +
+
+ {done ? "Spent" : "Budget"} + + ${ms.spent.toFixed(2)} of ${ms.budgetUsd} + +
+
= ms.budgetUsd ? " bad" : ms.spent >= ms.budgetUsd * 0.8 ? " warn" : ""}`}> + +
+
+ ) : ms && ms.spent >= 0.01 ? ( + Spent ${ms.spent.toFixed(2)} + ) : null} + {ms && {done && !ms.prs ? "Ready for you to merge" : `${ms.prs ? "Opens PRs" : "No PRs"} · never merges`}} + {live && g.status !== "ready" && ( + <> + + {firstLive && ( + + )} + + )} + {g.status === "ready" && ( + + )} + {done && review && ( + <> + + + + )}
)}
@@ -556,35 +921,494 @@ function GoalCard({ g, m, open, onGiveUp, onReview }: { g: Goal; m: ManagerView; } -/** One of its questions for you: what it asks, a line to answer it (passed on by the Captain to its thread), or put it away. */ -function ForYou({ text, onAnswer, onDismiss }: { text: string; onAnswer: (t: string) => Promise; onDismiss: () => void }) { - const [reply, setReply] = useState(""); - const [sending, setSending] = useState(false); +type MissionDraft = { parallel: number; setParallel: (n: number) => void; budget: number; setBudget: (n: number) => void; prs: boolean; setPrs: (v: boolean) => void; /** About what its threads spend an hour, when the record has it. */ rate?: number | undefined }; +const BUDGETS = [0, 5, 10, 25, 50, 100]; + +/** + * Its settings as snug rounded-square menus, each with its icon, the chosen value in ink (2026-11-27 polish): threads at once as a + * 1 to 4 control inside its menu, a budget whose menu says what happens at the line, and pull requests on or off. + */ +function MissionPills({ d }: { d: MissionDraft }) { + return ( + <> + [ + { heading: "Threads at once" }, + { + node: ( + d.setParallel(Number(v))} options={[1, 2, 3, 4].map((n) => ({ value: String(n), label: String(n) }))} className="mgr-seg-kit" /> + ), + height: 40, + }, + { node:

Each thread works in its own copy of the project.

, height: 34 }, + ]} + > + + {d.parallel} at once + +
+ [ + { heading: "Pause at" }, + ...BUDGETS.map((usd) => ({ label: usd ? `$${usd}` : "No budget", checked: d.budget === usd, onSelect: () => d.setBudget(usd), ...(usd && d.rate ? { hint: hoursFor(usd, d.rate) } : {}) })), + { node:

At the line it pauses and asks you.

, height: 34 }, + ]} + > + + {d.budget ? ( + <> + ${d.budget} budget + + ) : ( + "No budget" + )} + +
+ + + ); +} + +/** The mock's three glyphs, which the app's icon set doesn't have: stacked layers (threads at once), a coin (budget), info. */ +const TARGET = "M8 14A6 6 0 1 0 8 2a6 6 0 0 0 0 12zM8 11a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM8 8.6a.6.6 0 1 0 0-1.2.6.6 0 0 0 0 1.2z"; +const LAYERS = "M8 2.5 14 5.5 8 8.5 2 5.5zM2 8.2l6 3 6-3M2 10.9l6 3 6-3"; +const COIN = "M8 14A6 6 0 1 0 8 2a6 6 0 0 0 0 12zM9.8 6.2C9.5 5.6 8.8 5.2 8 5.2c-1 0-1.8.6-1.8 1.4 0 1.9 3.6 1 3.6 2.9 0 .8-.8 1.4-1.8 1.4-.9 0-1.6-.4-1.9-1.1M8 4.2v1M8 10.9v1"; +const INFO = "M8 14A6 6 0 1 0 8 2a6 6 0 0 0 0 12zM8 7.3v3.6M8 5.2v.01"; +const Glyph = ({ d, size = 13 }: { d: string; size?: number }) => ( + + + +); + +/** About how long a budget lasts at its rate: "about 2 hours". */ +const hoursFor = (usd: number, rate: number) => { + const h = Math.max(1, Math.round(usd / rate)); + return `about ${h} hour${h === 1 ? "" : "s"}`; +}; + +/** What it will do with work, in one short line that follows the settings. */ +const missionSentence = (d: MissionDraft) => + `${d.parallel === 1 ? "One thread" : `${d.parallel} threads at once`}, each in its own copy. Checked, then judged done.${d.prs ? " Opens pull requests." : ""}${d.budget ? ` Pauses at $${d.budget}.` : ""} Never merges.`; + +export type SayOpts = { done?: string; parallel?: number; budgetUsd?: number; prs?: boolean }; + +/** + * A Run Captain's box: one way in (Arun, 2026-11-27: "Yeah also let's look at one way in"). What you write is what you want; work + * becomes a mission it owns until done is true (missions.ts), a question is answered. "Done when" is yours to say or leave: left + * empty, the Captain says its own and the card shows it. Its settings are the box's pills, and the line under "Done when" says what + * it will do, once you've said what done means. Enter sends; Shift+Enter is a new line; ↑ in an empty box brings back your last. + */ +function RunBox({ project, rate, msg, setMsg, lastSaid, sending, onSend }: { project: string; rate?: number | undefined; msg: string; setMsg: (v: string) => void; lastSaid: string; sending: boolean; onSend: (opts: SayOpts) => Promise }) { + const [done, setDone] = useState(""); + const [parallel, setParallel] = useState(2); + const [budget, setBudget] = useState(0); + const [prs, setPrs] = useState(false); + const d: MissionDraft = { parallel, setParallel, budget, setBudget, prs, setPrs, rate }; + const send = () => { + if (!msg.trim() || sending) return; + void onSend({ ...(done.trim() ? { done: done.trim() } : {}), parallel, ...(budget ? { budgetUsd: budget } : {}), ...(prs ? { prs } : {}) }).then((ok) => ok && setDone("")); + }; + return ( +
{ + e.preventDefault(); + send(); + }} + > +