@1agh/maude 2.0.3 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/apps/hub/src/project-transactions/kernel.mjs +10 -1
- package/apps/studio/access/filters.ts +12 -5
- package/apps/studio/access/known-canvases.ts +24 -1
- package/apps/studio/access/refused-inputs.ts +89 -0
- package/apps/studio/access/request.ts +0 -1
- package/apps/studio/acp/adapter-stderr.ts +43 -13
- package/apps/studio/acp/background-tasks.ts +155 -0
- package/apps/studio/acp/bridge.ts +44 -5
- package/apps/studio/acp/connected-fact.ts +15 -4
- package/apps/studio/acp/index.ts +14 -5
- package/apps/studio/actions/agents.ts +10 -0
- package/apps/studio/actions/defs/app.ts +12 -0
- package/apps/studio/actions/defs/view.ts +12 -0
- package/apps/studio/actions.manifest.json +25 -1
- package/apps/studio/actions.parity.json +13 -1
- package/apps/studio/annotations/ui/element-node.tsx +139 -54
- package/apps/studio/annotations/ui/lod.tsx +1 -1
- package/apps/studio/annotations/ui/text-style.ts +1 -1
- package/apps/studio/annotations-layer.tsx +0 -12
- package/apps/studio/api.ts +73 -24
- package/apps/studio/artboard-live-gate.tsx +267 -0
- package/apps/studio/artboard-live.ts +336 -0
- package/apps/studio/artboard-webgl.ts +668 -0
- package/apps/studio/bin/_agent-browser-bin.mjs +8 -0
- package/apps/studio/bin/_agent-browser-safe.mjs +2 -1
- package/apps/studio/bin/_canvas-reasons.mjs +34 -0
- package/apps/studio/bin/_ds-check-live.mjs +37 -0
- package/apps/studio/bin/_ds-check.mjs +4 -1
- package/apps/studio/bin/_ds-prove-judge.mjs +167 -0
- package/apps/studio/bin/_ds-prove-playwright.mjs +183 -105
- package/apps/studio/bin/_import-asset.mjs +2 -1
- package/apps/studio/bin/_perf-probe.mjs +2 -1
- package/apps/studio/bin/_png-playwright.mjs +10 -1
- package/apps/studio/bin/_pw-launch.mjs +14 -0
- package/apps/studio/bin/_studio-verb.mjs +24 -3
- package/apps/studio/bin/_thumb-blank.mjs +70 -0
- package/apps/studio/bin/_thumb-cover.mjs +35 -0
- package/apps/studio/bin/_thumbs-playwright.mjs +93 -13
- package/apps/studio/bin/ds-check.sh +5 -1
- package/apps/studio/bin/perf.sh +11 -1
- package/apps/studio/bin/server-up.sh +7 -2
- package/apps/studio/bin/smoke.sh +19 -0
- package/apps/studio/boot-progress.ts +31 -0
- package/apps/studio/canvas-build-sandbox.ts +275 -42
- package/apps/studio/canvas-build-worker.ts +10 -0
- package/apps/studio/canvas-create.ts +24 -0
- package/apps/studio/canvas-lib.tsx +131 -12
- package/apps/studio/canvas-module-cache.ts +93 -0
- package/apps/studio/canvas-source/errors.ts +39 -0
- package/apps/studio/canvas-source/waiting.ts +290 -0
- package/apps/studio/client/actions/shell-key-handlers.js +5 -0
- package/apps/studio/client/app.jsx +19 -9
- package/apps/studio/client/canvas-url.js +13 -0
- package/apps/studio/client/github.js +23 -3
- package/apps/studio/client/home/HomeAccounts.jsx +262 -0
- package/apps/studio/client/home/Shelves.jsx +4 -3
- package/apps/studio/client/home/home-accounts-model.js +121 -0
- package/apps/studio/client/home/home-api.js +36 -19
- package/apps/studio/client/home/home-app.jsx +141 -40
- package/apps/studio/client/home/home-model.js +172 -6
- package/apps/studio/client/home/home.css +169 -5
- package/apps/studio/client/home/shell-mode.js +8 -1
- package/apps/studio/client/hooks/use-git-actions.jsx +2 -1
- package/apps/studio/client/hooks/use-project-data.jsx +2 -0
- package/apps/studio/client/hooks/use-shell-core.jsx +3 -0
- package/apps/studio/client/hooks/use-tabs.jsx +64 -35
- package/apps/studio/client/index-loader.ts +23 -3
- package/apps/studio/client/panels/ChatPanel.jsx +49 -57
- package/apps/studio/client/panels/CreateProject.jsx +19 -5
- package/apps/studio/client/panels/DiffView.jsx +314 -248
- package/apps/studio/client/panels/TeamProjects.jsx +119 -69
- package/apps/studio/client/panels/acp-runtime.js +25 -0
- package/apps/studio/client/panels/caps-cache.js +46 -0
- package/apps/studio/client/panels/chat-finish.js +66 -0
- package/apps/studio/client/shell/frame-cap.js +53 -0
- package/apps/studio/client/shell/viewport.jsx +45 -8
- package/apps/studio/client/styles/_index.css +2 -0
- package/apps/studio/client/tree/tree.jsx +48 -21
- package/apps/studio/client/v2/access/access-client.js +2 -0
- package/apps/studio/client/v2/access/access-host.jsx +12 -1
- package/apps/studio/client/v2/access/trashed-banner.jsx +6 -3
- package/apps/studio/client/v2/ai/Advanced.jsx +12 -0
- package/apps/studio/client/v2/ai/BackgroundStrip.jsx +120 -0
- package/apps/studio/client/v2/ai/Composer.jsx +27 -10
- package/apps/studio/client/v2/ai/StoppedDivider.jsx +2 -1
- package/apps/studio/client/v2/ai/ai-run.css +87 -3
- package/apps/studio/client/v2/ai/background-model.js +113 -0
- package/apps/studio/client/v2/ai/needs-you-store.js +2 -1
- package/apps/studio/client/v2/ai/run-api.js +7 -3
- package/apps/studio/client/v2/ai/runs-store.js +2 -1
- package/apps/studio/client/v2/annotations/vote-store.js +11 -5
- package/apps/studio/client/v2/assets/asset-state-lane.js +6 -3
- package/apps/studio/client/v2/assets/assets-bus.js +10 -8
- package/apps/studio/client/v2/assets/browse-view.jsx +2 -0
- package/apps/studio/client/v2/assets/ds-library-view.jsx +47 -0
- package/apps/studio/client/v2/assets/spotlight-model.js +75 -0
- package/apps/studio/client/v2/assets/spotlight.css +153 -0
- package/apps/studio/client/v2/assets/spotlight.jsx +199 -0
- package/apps/studio/client/v2/assets/tile-menu.jsx +3 -1
- package/apps/studio/client/v2/assets/tile.jsx +3 -0
- package/apps/studio/client/v2/assets/use-assets.js +2 -1
- package/apps/studio/client/v2/canvases/canvases-panel.jsx +13 -2
- package/apps/studio/client/v2/canvases/covers.js +11 -5
- package/apps/studio/client/v2/canvases/folder-ask.js +139 -0
- package/apps/studio/client/v2/canvases/folder-dialogs.jsx +150 -0
- package/apps/studio/client/v2/canvases/trash-canvas.js +10 -2
- package/apps/studio/client/v2/canvases/trash-queue.js +152 -0
- package/apps/studio/client/v2/canvases/use-canvas-index.js +42 -18
- package/apps/studio/client/v2/canvases/use-pins.js +2 -1
- package/apps/studio/client/v2/code/canvas-error-card.jsx +70 -5
- package/apps/studio/client/v2/code/canvas-imports-card.jsx +15 -14
- package/apps/studio/client/v2/code/canvas-imports-words.js +44 -0
- package/apps/studio/client/v2/code/canvas-waiting-card.jsx +128 -0
- package/apps/studio/client/v2/code/canvas-waiting.js +164 -0
- package/apps/studio/client/v2/code/code-bus.js +5 -0
- package/apps/studio/client/v2/code/code.css +67 -0
- package/apps/studio/client/v2/code/use-canvas-source.js +19 -4
- package/apps/studio/client/v2/create/NameDialog.jsx +4 -2
- package/apps/studio/client/v2/create/name-dialog.css +10 -0
- package/apps/studio/client/v2/ds/advanced-host.jsx +11 -23
- package/apps/studio/client/v2/ds/ds-refresh.js +161 -0
- package/apps/studio/client/v2/ds/library-host.jsx +45 -45
- package/apps/studio/client/v2/ds/make-host.jsx +13 -12
- package/apps/studio/client/v2/ds/off-system-host.jsx +18 -16
- package/apps/studio/client/v2/ds/review-host.jsx +7 -1
- package/apps/studio/client/v2/ds/truth-host.jsx +15 -14
- package/apps/studio/client/v2/ds/upgrade-host.jsx +26 -10
- package/apps/studio/client/v2/empty/arriving.jsx +29 -12
- package/apps/studio/client/v2/empty/empty-host.jsx +8 -2
- package/apps/studio/client/v2/empty/not-local.jsx +31 -1
- package/apps/studio/client/v2/empty/use-empty-canvas.js +10 -1
- package/apps/studio/client/v2/export/last-finished.js +2 -1
- package/apps/studio/client/v2/history/branch-actions.js +13 -9
- package/apps/studio/client/v2/history/git-advanced.jsx +8 -1
- package/apps/studio/client/v2/history/git-model.js +21 -5
- package/apps/studio/client/v2/history/git-parts.jsx +76 -43
- package/apps/studio/client/v2/history/history.css +6 -0
- package/apps/studio/client/v2/left-panel/assets-panel.jsx +87 -10
- package/apps/studio/client/v2/left-panel/use-trash.js +2 -1
- package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +100 -33
- package/apps/studio/client/v2/onboarding/HubSheet.jsx +51 -83
- package/apps/studio/client/v2/onboarding/onboarding-model.js +10 -6
- package/apps/studio/client/v2/presence/faces.jsx +42 -14
- package/apps/studio/client/v2/present/order-notes-artboards.js +2 -1
- package/apps/studio/client/v2/search/search-recent.js +3 -1
- package/apps/studio/client/v2/search/search-remote.js +6 -4
- package/apps/studio/client/v2/settings/connections-model.js +1 -1
- package/apps/studio/client/v2/shell/account-card.jsx +10 -4
- package/apps/studio/client/v2/shell/canvas-crash-guard.js +137 -0
- package/apps/studio/client/v2/shell/github-signin-host.jsx +42 -0
- package/apps/studio/client/v2/shell/menu-runner.js +12 -0
- package/apps/studio/client/v2/shell/occlusion-insets.js +14 -2
- package/apps/studio/client/v2/shell/project-account-card.jsx +203 -0
- package/apps/studio/client/v2/shell/project-account-model.js +182 -0
- package/apps/studio/client/v2/shell/recovery-store.js +2 -1
- package/apps/studio/client/v2/shell/served-routes.js +120 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +139 -11
- package/apps/studio/client/v2/shell/share-cluster.css +58 -0
- package/apps/studio/client/v2/shell/share-cluster.jsx +26 -7
- package/apps/studio/client/v2/shell/shell-activity.js +19 -0
- package/apps/studio/client/v2/shell/team-switch.js +94 -0
- package/apps/studio/client/v2/shell/too-heavy-card.jsx +38 -0
- package/apps/studio/client/v2/shell/use-account.js +8 -1
- package/apps/studio/client/v2/shell/use-occluded-insets.js +3 -0
- package/apps/studio/client/v2/sync-states/conflict-card.jsx +7 -2
- package/apps/studio/client/v2/undo/use-undo-projection.jsx +3 -1
- package/apps/studio/cloud/endpoints.ts +23 -1
- package/apps/studio/collab/persistence.ts +9 -1
- package/apps/studio/collab/registry.ts +32 -0
- package/apps/studio/collab/room.ts +8 -0
- package/apps/studio/config-reload-wire.ts +53 -0
- package/apps/studio/dist/client.bundle.js +1098 -1102
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds/board/specimen.tsx +12 -1
- package/apps/studio/ds/canvas-cli.ts +58 -2
- package/apps/studio/ds/check.ts +26 -1
- package/apps/studio/ds/cli.ts +7 -3
- package/apps/studio/ds/convert.ts +34 -6
- package/apps/studio/ds/ds-verb.ts +13 -0
- package/apps/studio/ds/post-build.ts +38 -0
- package/apps/studio/ds/upgrade-apply.ts +27 -5
- package/apps/studio/ds/upgrade-cli.ts +22 -2
- package/apps/studio/ds/upgrade-prove.ts +198 -15
- package/apps/studio/ds/upgrade-stage.ts +4 -1
- package/apps/studio/editing/minimap-context.tsx +3 -3
- package/apps/studio/editing/page-activity.ts +251 -0
- package/apps/studio/editing/rotate-handle.tsx +9 -5
- package/apps/studio/editing/sticky-name.tsx +4 -4
- package/apps/studio/history/restore-artboard-action.ts +40 -0
- package/apps/studio/history/trash.ts +6 -0
- package/apps/studio/home/accounts.ts +87 -0
- package/apps/studio/home/hub.ts +77 -175
- package/apps/studio/home/index-reader.ts +24 -2
- package/apps/studio/home/routes.ts +66 -8
- package/apps/studio/http.ts +131 -68
- package/apps/studio/index-flight.ts +40 -0
- package/apps/studio/managed-projects.ts +52 -24
- package/apps/studio/migrate/hub.ts +7 -1
- package/apps/studio/routes/canvas-source.ts +44 -2
- package/apps/studio/routes/ds-convert.ts +18 -0
- package/apps/studio/routes/history.ts +28 -5
- package/apps/studio/routes/hub-signin.ts +115 -0
- package/apps/studio/routes/index.ts +4 -0
- package/apps/studio/routes/table.ts +7 -0
- package/apps/studio/routes/trash.ts +19 -1
- package/apps/studio/server.ts +19 -10
- package/apps/studio/sync/accepted-cold-start.ts +54 -16
- package/apps/studio/sync/accepted-link.ts +9 -4
- package/apps/studio/sync/asset-push.ts +146 -23
- package/apps/studio/sync/asset-state.ts +3 -2
- package/apps/studio/sync/code-module-consent.ts +74 -0
- package/apps/studio/sync/file-ledger.ts +35 -0
- package/apps/studio/sync/file-membership.ts +28 -3
- package/apps/studio/sync/file-plane.ts +483 -86
- package/apps/studio/sync/file-pull.ts +304 -33
- package/apps/studio/sync/hub-browser-signin.ts +377 -0
- package/apps/studio/sync/hub-link.ts +1 -2
- package/apps/studio/sync/hub-text-undo.ts +30 -10
- package/apps/studio/sync/index.ts +381 -161
- package/apps/studio/sync/journal-client.ts +94 -5
- package/apps/studio/sync/pending-deletes.ts +100 -0
- package/apps/studio/sync/projection.ts +121 -14
- package/apps/studio/sync/pull-pacer.ts +160 -0
- package/apps/studio/sync/pull-priority.ts +119 -0
- package/apps/studio/sync/seed-progress.ts +58 -3
- package/apps/studio/sync/status.ts +3 -1
- package/apps/studio/sync/transaction-client.ts +71 -6
- package/apps/studio/sync/workspace-signin.ts +6 -256
- package/apps/studio/sync/writer-registry.ts +5 -1
- package/apps/studio/thumbs/service.ts +12 -2
- package/apps/studio/thumbs/validate.ts +7 -0
- package/apps/studio/ui-prefs-migrate.ts +4 -0
- package/apps/studio/video-comp.tsx +23 -0
- package/apps/studio/video-links-overlay.tsx +3 -2
- package/apps/studio/whats-new.json +126 -0
- package/cli/lib/bash-guard.mjs +13 -1
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/design-hook.mjs +20 -0
- package/cli/lib/studio-locate.mjs +35 -10
- package/cli/lib/workspace-plan.mjs +14 -0
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
A personal marketplace of Claude Code and Codex plugins. Two plugins today, plus a `maude` CLI for scaffolding and running the bundled dev tooling.
|
|
4
4
|
|
|
5
|
-
<!--
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
<!-- The 1-minute intro film is a release asset of the `intro-v2` release (not a v* tag, so no
|
|
6
|
+
release workflow fires). Upload: cp scripts/video/final/out/intro2/Intro2-audio.mp4 /tmp/intro.mp4 &&
|
|
7
|
+
gh release create intro-v2 /tmp/intro.mp4 --title "Intro film" --notes "Maude 2 intro film" -->
|
|
8
|
+
<video src="https://github.com/1aGh/maude/releases/download/intro-v2/intro.mp4" controls muted playsinline poster="https://maude.sh/intro-poster.jpg" width="800"></video>
|
|
8
9
|
|
|
9
10
|
> **📚 Full docs: https://maude.sh** (or browse the source under [`site/content/docs/`](./site/content/docs/) until the public URL lands).
|
|
10
11
|
> Contributing? See [CONTRIBUTING.md](./CONTRIBUTING.md). Security? See [SECURITY.md](./SECURITY.md).
|
|
@@ -120,7 +121,7 @@ Solo mode (the default) is fully local — no accounts, no telemetry, no network
|
|
|
120
121
|
|
|
121
122
|
User-facing docs live in two places — the README points you the right way:
|
|
122
123
|
|
|
123
|
-
- **Reference** (every command, every config key, recipes for Next.js / Expo / monorepo) → [`site/content/docs/`](./site/content/docs/) (served at https://maude.sh
|
|
124
|
+
- **Reference** (every command, every config key, recipes for Next.js / Expo / monorepo) → [`site/content/docs/`](./site/content/docs/) (served at https://maude.sh — see [DDR-005](.ai/archive/decisions/DDR-005-docs-site-stack-and-hosting.md)).
|
|
124
125
|
- **kgai knowledge-graph backend** (opt-in shared decision memory across repos) → [`docs/kgai-onboarding.md`](./docs/kgai-onboarding.md) (per user) + [`docs/kgai-company-setup.md`](./docs/kgai-company-setup.md) (one-time admin). Off by default — absent `kg`, every command runs its classic `.ai/` path.
|
|
125
126
|
- **Quickstart** + **contributor info** → this README.
|
|
126
127
|
|
|
@@ -133,7 +134,7 @@ The repo is a **pnpm workspace monorepo** with one published npm package (`@1agh
|
|
|
133
134
|
| Workspace | Purpose |
|
|
134
135
|
| --------- | ------- |
|
|
135
136
|
| `.` (root) | The single npm publisher — CLI, dev-server entry, plugin templates that ship to npm. |
|
|
136
|
-
| `site/` | Docs site — Fumadocs + Next.js,
|
|
137
|
+
| `site/` | Docs site — Fumadocs + Next.js, served by Cloudflare Workers ([DDR-005](.ai/archive/decisions/DDR-005-docs-site-stack-and-hosting.md)). |
|
|
137
138
|
| `apps/studio/` | Zero-dep Node dev server + browser client. Bundled output (`dist/`) is the only thing in the npm tarball. |
|
|
138
139
|
| `apps/hub/` | Reserved for the v1.1 federated hub (Phase 9). |
|
|
139
140
|
|
|
@@ -1650,7 +1650,16 @@ export function createKernel({
|
|
|
1650
1650
|
const st = work.docs.get(doc);
|
|
1651
1651
|
if (!st) continue;
|
|
1652
1652
|
const lanes = {};
|
|
1653
|
-
|
|
1653
|
+
// A REVIVED document (an undone delete, a Trash restore) publishes every
|
|
1654
|
+
// lane it holds, not only the ones this action touched: the delete
|
|
1655
|
+
// dropped the live document (`deleteDocument`), so the replica it comes
|
|
1656
|
+
// back into is empty. Publishing nothing left the hub's copy empty, and
|
|
1657
|
+
// it only looked restored on a peer that still held the deleted doc —
|
|
1658
|
+
// the stale lineage that doubles a re-created canvas (fix/205).
|
|
1659
|
+
const names = new Set(c.lanes);
|
|
1660
|
+
if (c.revived)
|
|
1661
|
+
for (const [lane, h] of Object.entries(st.lanes ?? {})) if (h?.hash) names.add(lane);
|
|
1662
|
+
for (const lane of names) lanes[lane] = await work.laneContent(st, lane);
|
|
1654
1663
|
changes.push({
|
|
1655
1664
|
doc,
|
|
1656
1665
|
path: st.path,
|
|
@@ -597,7 +597,8 @@ const sources = new WeakMap<object, ProjectVisibility>();
|
|
|
597
597
|
* write gate (http.ts) and the read filters (api.ts) compute the same closure once.
|
|
598
598
|
*
|
|
599
599
|
* gate-b-c4j — judged with the studio's EFFECTIVE config (`ctx.cfg`, read per call: a config
|
|
600
|
-
* reload swaps it)
|
|
600
|
+
* reload swaps it) when `<designRoot>/config.json` does not exist (a custom designRoot); 2.0.5 —
|
|
601
|
+
* otherwise with that file, the one the board build reads (`config` below).
|
|
601
602
|
*/
|
|
602
603
|
export function projectVisibility(
|
|
603
604
|
ctx: Pick<Context, 'paths' | 'bus'> & { cfg?: Context['cfg'] }
|
|
@@ -625,6 +626,8 @@ export function projectVisibility(
|
|
|
625
626
|
await listMaterializable();
|
|
626
627
|
};
|
|
627
628
|
// p8-c4b — plus the canvases the authority knows of (a stored grant), re-read per call.
|
|
629
|
+
// 2.0.5 — `closureConfigFor` reads the design systems from `<designRoot>/config.json` when it exists
|
|
630
|
+
// (the file the board build reads), so the closure and the build cannot disagree.
|
|
628
631
|
const config = () =>
|
|
629
632
|
closureConfigFor(ctx) ?? projectClosureConfig(reader, knownCanvasesFor(undefined));
|
|
630
633
|
const closureOf = (access: Access): Closure | null =>
|
|
@@ -677,6 +680,8 @@ interface IndexDataShape {
|
|
|
677
680
|
dsRevGaps?: Record<string, string | null>;
|
|
678
681
|
// gate-b-c4j — a canvas → the other canvases it imports (its frame is refused; api.ts buildIndexData)
|
|
679
682
|
canvasImportsCanvases?: Record<string, string[]>;
|
|
683
|
+
// 2.0.5 (#205) — a canvas → the design-root files its built module was refused for (access/refused-inputs.ts)
|
|
684
|
+
canvasRefusedInputs?: Record<string, string[]>;
|
|
680
685
|
}
|
|
681
686
|
|
|
682
687
|
/** Repo-relative `.design/ui/x/y.tsx` → every ancestor dir (`.design/ui`, `.design/ui/x`). */
|
|
@@ -733,14 +738,16 @@ export function filterIndexData<T extends IndexDataShape>(
|
|
|
733
738
|
// sees. gate-b-c4k — an entry whose every name is hidden is dropped: it would tell the reader that
|
|
734
739
|
// A imports SOME canvas it cannot see (a probe oracle: plant an import, watch the card). Its frame
|
|
735
740
|
// is still refused; the shell shows the generic card there.
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
Object.entries(
|
|
741
|
+
const namesSeen = (m: Record<string, string[]>) =>
|
|
742
|
+
Object.fromEntries(
|
|
743
|
+
Object.entries(m)
|
|
739
744
|
.filter(([k]) => seen(k))
|
|
740
745
|
.map(([k, v]) => [k, v.filter((c) => vis.sees(c))] as const)
|
|
741
746
|
.filter(([, v]) => v.length > 0)
|
|
742
747
|
);
|
|
743
|
-
|
|
748
|
+
if (data.canvasImportsCanvases) out.canvasImportsCanvases = namesSeen(data.canvasImportsCanvases);
|
|
749
|
+
// 2.0.5 (#205) — the refused files by the same rule: only names this reader sees, no all-hidden entry
|
|
750
|
+
if (data.canvasRefusedInputs) out.canvasRefusedInputs = namesSeen(data.canvasRefusedInputs);
|
|
744
751
|
// S10.4 — the revision fields name systems and revisions: a session sees the ones it renders with.
|
|
745
752
|
if (data.dsConverted) {
|
|
746
753
|
const byName = <V>(m: Record<string, V> | undefined) =>
|
|
@@ -77,6 +77,29 @@ export function knownCanvasesFor(
|
|
|
77
77
|
*/
|
|
78
78
|
export function closureConfigFor(ctx: {
|
|
79
79
|
cfg?: { linkedHub?: { url?: string } | null } | null;
|
|
80
|
+
paths?: { designRoot?: string };
|
|
80
81
|
}): ClosureConfig | undefined {
|
|
81
|
-
|
|
82
|
+
// 2.0.5 (decision maude/v2-205-closure-config-is-the-build-config) — the design systems come from
|
|
83
|
+
// `<designRoot>/config.json` whenever it parses: the file the board build itself reads
|
|
84
|
+
// (ds-resolver `canvasSystemFor`) and the hub's file plane judges with. `ctx.cfg` reloads only on a
|
|
85
|
+
// watcher `fs:json`, which a cell child never gets (the journal heal emits `fs:any`), so after a
|
|
86
|
+
// synced config change the closure judged a DS board with another system list than its build
|
|
87
|
+
// used and the board failed closed (design.studyfi.com, 2.0.4). `ctx.cfg` stays the answer for a
|
|
88
|
+
// custom designRoot, which has no `<designRoot>/config.json` (gate-b-c4j). The linked hub (for the
|
|
89
|
+
// known canvases) is boot-pinned in `ctx.cfg` either way.
|
|
90
|
+
const own = designRootConfig(ctx.paths?.designRoot);
|
|
91
|
+
const known = () => knownCanvasesFor(ctx.cfg ?? undefined);
|
|
92
|
+
if (own) return closureConfigOf(own, known());
|
|
93
|
+
return ctx.cfg ? closureConfigOf(ctx.cfg, known()) : undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** `<designRoot>/config.json` as an object, or null (absent, unreadable, not an object). */
|
|
97
|
+
function designRootConfig(designRoot: string | undefined): Record<string, unknown> | null {
|
|
98
|
+
if (!designRoot) return null;
|
|
99
|
+
try {
|
|
100
|
+
const v = JSON.parse(readFileSync(`${designRoot}/config.json`, 'utf8'));
|
|
101
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? (v as Record<string, unknown>) : null;
|
|
102
|
+
} catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
82
105
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// access/refused-inputs.ts — 2.0.5 (#205): why a canvas's built module was refused, for the person who can fix it.
|
|
2
|
+
//
|
|
3
|
+
// The inputs gate (access/frame.ts `inputsRefusal`, http.ts `canvasInputsGate`) refuses a built canvas module
|
|
4
|
+
// when it inlined a design-root file the frame's closure does not admit — typically a file that belongs to
|
|
5
|
+
// another canvas. The canvas origin answers the bare not-in-scope 403 and must keep doing so: canvas code reads
|
|
6
|
+
// that body. So the refusal's reason is kept HERE, on the server, per canvas, and reported only on the main
|
|
7
|
+
// origin (`/_index-data` `canvasRefusedInputs`, filtered per reader like `canvasImportsCanvases` — a name the
|
|
8
|
+
// reader cannot see is left out, and an entry with no visible name is dropped).
|
|
9
|
+
//
|
|
10
|
+
// Bounded: at most MAX_CANVASES canvases (oldest dropped first) × MAX_NAMES names each. A later build of the
|
|
11
|
+
// same canvas that passes the gate forgets its entry.
|
|
12
|
+
|
|
13
|
+
import { relative, resolve, sep } from 'node:path';
|
|
14
|
+
import { isUnderOrEqualPath } from './frame.ts';
|
|
15
|
+
|
|
16
|
+
export const MAX_CANVASES = 200;
|
|
17
|
+
export const MAX_NAMES = 20;
|
|
18
|
+
|
|
19
|
+
/** The design-root files (design-root-relative, `/`-separated) among `inputs` that `sees` does not admit. */
|
|
20
|
+
export function refusedDesignInputs(
|
|
21
|
+
inputs: readonly string[],
|
|
22
|
+
roots: readonly string[],
|
|
23
|
+
sees: (rel: string) => boolean
|
|
24
|
+
): string[] {
|
|
25
|
+
const out = new Set<string>();
|
|
26
|
+
for (const abs of inputs) {
|
|
27
|
+
for (const root of roots) {
|
|
28
|
+
if (!isUnderOrEqualPath(abs, root)) continue;
|
|
29
|
+
const rel = relative(root, abs).split(sep).join('/');
|
|
30
|
+
if (rel && !sees(rel)) out.add(rel);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return [...out].sort().slice(0, MAX_NAMES);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** `entry` (absolute) → its design-root-relative name, or null outside every root. */
|
|
38
|
+
export function entryRel(entry: string, roots: readonly string[]): string | null {
|
|
39
|
+
for (const root of roots) {
|
|
40
|
+
const rel = relative(root, resolve(entry)).split(sep).join('/');
|
|
41
|
+
if (rel && !rel.startsWith('..')) return rel;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface RefusedInputs {
|
|
47
|
+
/** Keep `names` as the reason `canvas` was refused. @returns whether the entry changed */
|
|
48
|
+
record(canvas: string, names: readonly string[]): boolean;
|
|
49
|
+
/** The gate passed for `canvas`: forget its reason. @returns whether there was one */
|
|
50
|
+
clear(canvas: string): boolean;
|
|
51
|
+
/** canvas (design-root-relative) → the files it was refused for. */
|
|
52
|
+
report(): Map<string, string[]>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function createRefusedInputs(max = MAX_CANVASES): RefusedInputs {
|
|
56
|
+
const byCanvas = new Map<string, string[]>();
|
|
57
|
+
return {
|
|
58
|
+
record(canvas, names) {
|
|
59
|
+
const list = [...new Set(names)].sort().slice(0, MAX_NAMES);
|
|
60
|
+
const was = byCanvas.get(canvas);
|
|
61
|
+
if (was && was.length === list.length && was.every((n, i) => n === list[i])) return false;
|
|
62
|
+
byCanvas.delete(canvas); // re-insert: the newest is last
|
|
63
|
+
byCanvas.set(canvas, list);
|
|
64
|
+
while (byCanvas.size > max) {
|
|
65
|
+
const oldest = byCanvas.keys().next().value;
|
|
66
|
+
if (oldest === undefined) break;
|
|
67
|
+
byCanvas.delete(oldest);
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
},
|
|
71
|
+
clear(canvas) {
|
|
72
|
+
return byCanvas.delete(canvas);
|
|
73
|
+
},
|
|
74
|
+
report() {
|
|
75
|
+
return new Map([...byCanvas].map(([k, v]) => [k, [...v]]));
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// One store per server context (the http layer records, the index reports).
|
|
81
|
+
const stores = new WeakMap<object, RefusedInputs>();
|
|
82
|
+
export function refusedInputsFor(ctx: object): RefusedInputs {
|
|
83
|
+
let s = stores.get(ctx);
|
|
84
|
+
if (!s) {
|
|
85
|
+
s = createRefusedInputs();
|
|
86
|
+
stores.set(ctx, s);
|
|
87
|
+
}
|
|
88
|
+
return s;
|
|
89
|
+
}
|
|
@@ -55,7 +55,6 @@ export const SESSION_WRITES: ReadonlySet<string> = new Set([
|
|
|
55
55
|
'/_api/report-fallback',
|
|
56
56
|
'/_api/hub/link', // link/unlink ≈ session management (cell allows /auth/logout)
|
|
57
57
|
'/_api/cloud/detach', // unlink — the same session-management class as hub/link
|
|
58
|
-
'/_api/workspace/sign-in', // signing in is how the role is (re)learned
|
|
59
58
|
'/_api/workspace/disclosure',
|
|
60
59
|
'/_api/cloud/signin/start', // account session, not project state
|
|
61
60
|
'/_api/cloud/signin/poll',
|
|
@@ -1,22 +1,52 @@
|
|
|
1
1
|
// What the studio relays from the ACP adapter's stderr into its own log (the
|
|
2
2
|
// person's Diagnostics view). The adapter (@agentclientprotocol/claude-agent-acp)
|
|
3
|
-
// calls `unreachable()` for an SDK
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
3
|
+
// calls `unreachable()` for an SDK message it has no case for and logs
|
|
4
|
+
// `Unexpected case: <json>`. Two of those are known and not surprises:
|
|
5
|
+
//
|
|
6
|
+
// · `subtype: "background_tasks_changed"` — the live set of background tasks
|
|
7
|
+
// (subagents, background commands). Not noise any more (issue #177): it is
|
|
8
|
+
// the one place that snapshot reaches us, so it goes to `onBackground` (see
|
|
9
|
+
// background-tasks.ts) instead of the log.
|
|
10
|
+
// · `type: "command_lifecycle"` — queued / started / completed of the host's
|
|
11
|
+
// own prompts in Claude Code's input queue. Dropped quietly.
|
|
12
|
+
//
|
|
13
|
+
// We handle these here and not by bumping the adapter (the lockfiles are
|
|
14
|
+
// release-sensitive); every OTHER `Unexpected case` still shows, so a real
|
|
15
|
+
// protocol surprise is not hidden.
|
|
9
16
|
|
|
10
|
-
|
|
17
|
+
import {
|
|
18
|
+
type BackgroundSnapshot,
|
|
19
|
+
isCommandLifecycleLine,
|
|
20
|
+
parseBackgroundLine,
|
|
21
|
+
} from './background-tasks.ts';
|
|
22
|
+
|
|
23
|
+
const BACKGROUND_LINE = /Unexpected case:.*"subtype"\s*:\s*"background_tasks_changed"/;
|
|
11
24
|
|
|
12
25
|
export function isKnownAdapterNoise(line: string): boolean {
|
|
13
|
-
return
|
|
26
|
+
return BACKGROUND_LINE.test(line) || isCommandLifecycleLine(line);
|
|
14
27
|
}
|
|
15
28
|
|
|
16
|
-
/**
|
|
17
|
-
export function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
/** One whole stderr line: a background snapshot goes to `onBackground`, noise is dropped, the rest to `sink`. */
|
|
30
|
+
export function relayAdapterLine(
|
|
31
|
+
raw: string,
|
|
32
|
+
sink: (line: string) => void,
|
|
33
|
+
onBackground?: (snap: BackgroundSnapshot) => void
|
|
34
|
+
): void {
|
|
35
|
+
const line = raw.trimEnd();
|
|
36
|
+
if (!line) return;
|
|
37
|
+
const snap = parseBackgroundLine(line);
|
|
38
|
+
if (snap) {
|
|
39
|
+
onBackground?.(snap);
|
|
40
|
+
return;
|
|
21
41
|
}
|
|
42
|
+
if (!isKnownAdapterNoise(line)) sink(line);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Split one stderr chunk into lines and hand each non-empty, non-noise line to `sink`. */
|
|
46
|
+
export function relayAdapterStderr(
|
|
47
|
+
chunk: string,
|
|
48
|
+
sink: (line: string) => void,
|
|
49
|
+
onBackground?: (snap: BackgroundSnapshot) => void
|
|
50
|
+
): void {
|
|
51
|
+
for (const raw of chunk.split('\n')) relayAdapterLine(raw, sink, onBackground);
|
|
22
52
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// acp/background-tasks.ts — issue #177: what the AI chat knows about work running in the background.
|
|
2
|
+
//
|
|
3
|
+
// Claude Code reports its live background work (subagents launched with the Agent tool, a Bash call
|
|
4
|
+
// with `run_in_background`, a Monitor) as one LEVEL signal: the SDK system message
|
|
5
|
+
// `background_tasks_changed`, whose `tasks` array is "every live background task after the change"
|
|
6
|
+
// (replace semantics; emitted on start, completion, kill, a foreground agent being backgrounded).
|
|
7
|
+
// The edge events (`task_started` / `task_progress` / `task_updated` / `task_notification`) never reach
|
|
8
|
+
// us: the pinned adapter (claude-agent-acp 0.57.0) swallows them. It has no case for
|
|
9
|
+
// `background_tasks_changed` either, so it calls `unreachable()`, which logs the WHOLE message to its
|
|
10
|
+
// stderr as `Unexpected case: <json>` — that stderr line is the one place the snapshot survives, so the
|
|
11
|
+
// bridge reads it there (decision maude/v2-204-background-from-adapter-stderr).
|
|
12
|
+
//
|
|
13
|
+
// `command_lifecycle` (queued / started / completed) is the lifecycle of the host's OWN prompts in
|
|
14
|
+
// Claude Code's input queue, not background work: it is dropped quietly.
|
|
15
|
+
//
|
|
16
|
+
// What leaves this module is a short, render-ready list: an id, a kind (agent / command / other), a
|
|
17
|
+
// one-line label and the time this bridge first saw the task. The label is model-authored text — it is
|
|
18
|
+
// cut to one line and capped here, and rendered as text by the client, never as markup.
|
|
19
|
+
|
|
20
|
+
/** One live background task, as the chat shows it. */
|
|
21
|
+
export interface BackgroundTask {
|
|
22
|
+
id: string;
|
|
23
|
+
kind: 'agent' | 'command' | 'other';
|
|
24
|
+
label: string;
|
|
25
|
+
/** Epoch ms this bridge first saw the task in a snapshot (drives the elapsed time). */
|
|
26
|
+
since: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A parsed `background_tasks_changed` message: the session it is for and its raw tasks. */
|
|
30
|
+
export interface BackgroundSnapshot {
|
|
31
|
+
sessionId: string | null;
|
|
32
|
+
tasks: RawTask[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface RawTask {
|
|
36
|
+
task_id?: unknown;
|
|
37
|
+
task_type?: unknown;
|
|
38
|
+
description?: unknown;
|
|
39
|
+
subagent_type?: unknown;
|
|
40
|
+
ambient?: unknown;
|
|
41
|
+
awaited?: unknown;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** At most this many rows reach the client (a runaway list must not flood the chat). */
|
|
45
|
+
export const MAX_TASKS = 50;
|
|
46
|
+
const LABEL_MAX = 80;
|
|
47
|
+
const ID_RE = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
48
|
+
const PREFIX = 'Unexpected case: ';
|
|
49
|
+
|
|
50
|
+
/** The JSON body of an adapter `Unexpected case:` line (any leading timestamp tolerated), or null. */
|
|
51
|
+
function unexpectedBody(line: string): unknown {
|
|
52
|
+
const at = line.indexOf(PREFIX);
|
|
53
|
+
if (at < 0) return null;
|
|
54
|
+
const body = line.slice(at + PREFIX.length).trim();
|
|
55
|
+
if (!body.startsWith('{')) return null;
|
|
56
|
+
try {
|
|
57
|
+
return JSON.parse(body);
|
|
58
|
+
} catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The background snapshot an adapter stderr line carries, or null when it carries none. */
|
|
64
|
+
export function parseBackgroundLine(line: string): BackgroundSnapshot | null {
|
|
65
|
+
if (!line.includes('background_tasks_changed')) return null;
|
|
66
|
+
const msg = unexpectedBody(line) as Record<string, unknown> | null;
|
|
67
|
+
if (msg?.type !== 'system' || msg.subtype !== 'background_tasks_changed') return null;
|
|
68
|
+
if (!Array.isArray(msg.tasks)) return null;
|
|
69
|
+
return {
|
|
70
|
+
sessionId: typeof msg.session_id === 'string' ? msg.session_id : null,
|
|
71
|
+
tasks: msg.tasks.filter((t): t is RawTask => !!t && typeof t === 'object'),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** True for the adapter's `command_lifecycle` line — the host's own prompt queue, not background work. */
|
|
76
|
+
export function isCommandLifecycleLine(line: string): boolean {
|
|
77
|
+
if (!line.includes('command_lifecycle')) return false;
|
|
78
|
+
const msg = unexpectedBody(line) as Record<string, unknown> | null;
|
|
79
|
+
return !!msg && msg.type === 'command_lifecycle';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** One line of model text: control and bidi characters out, whitespace collapsed, capped. */
|
|
83
|
+
export function oneLine(s: unknown, max = LABEL_MAX): string {
|
|
84
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: stripping control characters is the point
|
|
85
|
+
const t = String(s ?? '').replace(/[\u0000-\u001f\u007f-\u009f---]/g, ' ');
|
|
86
|
+
const one = t.replace(/\s+/g, ' ').trim();
|
|
87
|
+
return one.length <= max ? one : `${one.slice(0, max - 1).trimEnd()}…`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function kindOf(taskType: unknown): BackgroundTask['kind'] {
|
|
91
|
+
if (taskType === 'local_agent' || taskType === 'remote_agent') return 'agent';
|
|
92
|
+
if (taskType === 'local_bash') return 'command';
|
|
93
|
+
return 'other';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Fold a snapshot into the live list. Replace semantics: a task missing from the snapshot has
|
|
98
|
+
* ended. `prev` keeps a task's `since` across snapshots. Ambient tasks (housekeeping, live-update
|
|
99
|
+
* watchers — "hosts should exclude them from activity indicators") and awaited runs (a foreground
|
|
100
|
+
* call is waiting on them, so they are not background) are left out.
|
|
101
|
+
*/
|
|
102
|
+
export function foldSnapshot(
|
|
103
|
+
prev: readonly BackgroundTask[],
|
|
104
|
+
snap: BackgroundSnapshot,
|
|
105
|
+
now: number = Date.now()
|
|
106
|
+
): BackgroundTask[] {
|
|
107
|
+
const before = new Map(prev.map((t) => [t.id, t]));
|
|
108
|
+
const out: BackgroundTask[] = [];
|
|
109
|
+
const seen = new Set<string>();
|
|
110
|
+
for (const raw of snap.tasks) {
|
|
111
|
+
if (out.length >= MAX_TASKS) break;
|
|
112
|
+
if (raw.ambient === true || raw.awaited === true) continue;
|
|
113
|
+
const id = typeof raw.task_id === 'string' && ID_RE.test(raw.task_id) ? raw.task_id : null;
|
|
114
|
+
if (!id || seen.has(id)) continue;
|
|
115
|
+
seen.add(id);
|
|
116
|
+
const kind = kindOf(raw.task_type);
|
|
117
|
+
const label =
|
|
118
|
+
oneLine(raw.description) ||
|
|
119
|
+
(kind === 'agent' ? oneLine(raw.subagent_type) : '') ||
|
|
120
|
+
(kind === 'agent' ? 'Agent' : kind === 'command' ? 'Command' : 'Task');
|
|
121
|
+
out.push({ id, kind, label, since: before.get(id)?.since ?? now });
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Same list, same order, same fields — so an unchanged snapshot sends no frame. */
|
|
127
|
+
export function sameTasks(a: readonly BackgroundTask[], b: readonly BackgroundTask[]): boolean {
|
|
128
|
+
if (a.length !== b.length) return false;
|
|
129
|
+
return a.every((t, i) => {
|
|
130
|
+
const o = b[i];
|
|
131
|
+
return o && o.id === t.id && o.kind === t.kind && o.label === t.label && o.since === t.since;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Split a stderr stream into whole lines. A chunk can end mid-line (a long snapshot is one long
|
|
137
|
+
* line), so the tail is carried into the next chunk; `flush()` hands back what is left at the end.
|
|
138
|
+
*/
|
|
139
|
+
export function createLineSplitter(onLine: (line: string) => void) {
|
|
140
|
+
let carry = '';
|
|
141
|
+
return {
|
|
142
|
+
push(chunk: string): void {
|
|
143
|
+
const text = carry + chunk;
|
|
144
|
+
const parts = text.split('\n');
|
|
145
|
+
carry = parts.pop() ?? '';
|
|
146
|
+
// A line longer than 1 MB is never a snapshot we want; do not hold it forever.
|
|
147
|
+
if (carry.length > 1_000_000) carry = '';
|
|
148
|
+
for (const p of parts) onLine(p);
|
|
149
|
+
},
|
|
150
|
+
flush(): void {
|
|
151
|
+
if (carry) onLine(carry);
|
|
152
|
+
carry = '';
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -34,7 +34,7 @@ import { autoAllowRules } from '../actions/verbs.ts';
|
|
|
34
34
|
import { HANDOFF_RUN_VERBS } from '../handoff/write-scopes.ts';
|
|
35
35
|
import { DEV_SERVER_ROOT } from '../paths.ts';
|
|
36
36
|
import { readUiPrefs } from '../ui-prefs.ts';
|
|
37
|
-
import {
|
|
37
|
+
import { relayAdapterLine } from './adapter-stderr.ts';
|
|
38
38
|
import {
|
|
39
39
|
type AudienceLeak,
|
|
40
40
|
audienceLeak,
|
|
@@ -48,6 +48,12 @@ import {
|
|
|
48
48
|
withoutWriterRules,
|
|
49
49
|
writerVerbCall,
|
|
50
50
|
} from './audience.ts';
|
|
51
|
+
import {
|
|
52
|
+
type BackgroundTask,
|
|
53
|
+
createLineSplitter,
|
|
54
|
+
foldSnapshot,
|
|
55
|
+
sameTasks,
|
|
56
|
+
} from './background-tasks.ts';
|
|
51
57
|
import { chatSpawnEnv, scrubAgentEnv, teamsSpawnEnv } from './env.ts';
|
|
52
58
|
import {
|
|
53
59
|
type AiMay,
|
|
@@ -247,6 +253,12 @@ export interface AcpBridgeOptions {
|
|
|
247
253
|
* a message part.
|
|
248
254
|
*/
|
|
249
255
|
onUsage?: (usage: BridgeUsage) => void;
|
|
256
|
+
/**
|
|
257
|
+
* Issue #177 — the live set of background tasks (subagents, background commands), replaced
|
|
258
|
+
* whenever it changes; `[]` once the last one ends or the adapter goes away. Read from the
|
|
259
|
+
* adapter's stderr (background-tasks.ts). Chrome, not turn content: never transcripted.
|
|
260
|
+
*/
|
|
261
|
+
onBackground?: (tasks: BackgroundTask[]) => void;
|
|
250
262
|
/** Override for `PERMISSION_TIMEOUT_MS` (tests only — production always gets the real default). */
|
|
251
263
|
permissionTimeoutMs?: number;
|
|
252
264
|
/**
|
|
@@ -856,6 +868,10 @@ export class AcpBridge {
|
|
|
856
868
|
// running establishSession() and stomping the single shared `replaying` flag.
|
|
857
869
|
private sessionPromises = new Map<string, Promise<string>>();
|
|
858
870
|
private currentSession: string | null = null; // the in-flight prompt's session
|
|
871
|
+
// Issue #177 — the live background tasks, and which adapter process reported them (a respawned
|
|
872
|
+
// adapter's old stderr ending must not wipe the new one's list).
|
|
873
|
+
private background: BackgroundTask[] = [];
|
|
874
|
+
private backgroundProc: Spawned | null = null;
|
|
859
875
|
// issue-82 — every prompt() call currently racing a forced-cancellation
|
|
860
876
|
// (see `prompt()`), so cancel()/stop() can force ANY of them to settle
|
|
861
877
|
// when the adapter doesn't cooperate, instead of leaving one hanging
|
|
@@ -1089,6 +1105,11 @@ export class AcpBridge {
|
|
|
1089
1105
|
return this.pendingPermissions.size + this.pendingElicitations.size;
|
|
1090
1106
|
}
|
|
1091
1107
|
|
|
1108
|
+
/** Issue #177 — the background tasks running now (subagents, background commands). */
|
|
1109
|
+
get backgroundTasks(): BackgroundTask[] {
|
|
1110
|
+
return this.background;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1092
1113
|
/** The session id of the most recent prompt (for the `connected` frame). */
|
|
1093
1114
|
get sessionId(): string | null {
|
|
1094
1115
|
return this.currentSession;
|
|
@@ -1503,7 +1524,7 @@ export class AcpBridge {
|
|
|
1503
1524
|
stderr: 'pipe',
|
|
1504
1525
|
});
|
|
1505
1526
|
this.proc = proc;
|
|
1506
|
-
void this.drainStderr(proc
|
|
1527
|
+
void this.drainStderr(proc);
|
|
1507
1528
|
|
|
1508
1529
|
// Bun's `proc.stdin` is a FileSink, not a WritableStream — wrap it so
|
|
1509
1530
|
// ndJsonStream can pipe encoded ACP frames into the child's stdin.
|
|
@@ -2524,15 +2545,33 @@ export class AcpBridge {
|
|
|
2524
2545
|
}
|
|
2525
2546
|
}
|
|
2526
2547
|
|
|
2527
|
-
private async drainStderr(
|
|
2548
|
+
private async drainStderr(proc: Spawned): Promise<void> {
|
|
2549
|
+
const log = (line: string) => console.error('[acp-adapter]', line);
|
|
2550
|
+
const lines = createLineSplitter((line) =>
|
|
2551
|
+
relayAdapterLine(line, log, (snap) => this.setBackground(proc, snap))
|
|
2552
|
+
);
|
|
2528
2553
|
try {
|
|
2529
2554
|
const decoder = new TextDecoder();
|
|
2530
|
-
for await (const chunk of stderr) {
|
|
2531
|
-
|
|
2555
|
+
for await (const chunk of proc.stderr as ReadableStream<Uint8Array>) {
|
|
2556
|
+
lines.push(decoder.decode(chunk, { stream: true }));
|
|
2532
2557
|
}
|
|
2533
2558
|
} catch {
|
|
2534
2559
|
/* stream closed on teardown */
|
|
2535
2560
|
}
|
|
2561
|
+
lines.flush();
|
|
2562
|
+
// The adapter is gone (stopped, crashed, respawned): nothing it ran is still running for us.
|
|
2563
|
+
if (this.backgroundProc === proc) this.setBackground(proc, null);
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
/** Issue #177 — fold one adapter snapshot (null: that adapter ended) into the live list. */
|
|
2567
|
+
private setBackground(proc: Spawned, snap: Parameters<typeof foldSnapshot>[1] | null): void {
|
|
2568
|
+
const next = snap
|
|
2569
|
+
? foldSnapshot(this.backgroundProc === proc ? this.background : [], snap)
|
|
2570
|
+
: [];
|
|
2571
|
+
this.backgroundProc = next.length ? proc : null;
|
|
2572
|
+
if (sameTasks(next, this.background)) return;
|
|
2573
|
+
this.background = next;
|
|
2574
|
+
this.opts.onBackground?.(next);
|
|
2536
2575
|
}
|
|
2537
2576
|
|
|
2538
2577
|
/** Append one transcript line. `claimedSeq` is passed by the update path,
|
|
@@ -54,9 +54,14 @@ export function createConnectedFact(deps: ConnectedFactDeps) {
|
|
|
54
54
|
function ensure(): Promise<boolean> {
|
|
55
55
|
if (fresh()) return Promise.resolve(value === true);
|
|
56
56
|
if (inflight) return inflight;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
// 2.0.4 (J): never chain on the probe's own return. In the cloud build (cell, self-hosted hub image)
|
|
58
|
+
// `acp/probe.ts` is the inert, deliberately NON-thenable stub (`cloud-build.ts`), so `probe().then` threw
|
|
59
|
+
// synchronously — out of `read()`, out of the outbox gates, and every drain pass failed. The executor
|
|
60
|
+
// adopts a promise, wraps a plain value and turns a synchronous throw into a rejection.
|
|
61
|
+
inflight = new Promise<{ available?: unknown } | null | undefined>((resolve) =>
|
|
62
|
+
resolve(deps.probe())
|
|
63
|
+
)
|
|
64
|
+
.then((r) => set(r?.available === true))
|
|
60
65
|
.catch(() => set(false))
|
|
61
66
|
.finally(() => {
|
|
62
67
|
inflight = null;
|
|
@@ -71,7 +76,13 @@ export function createConnectedFact(deps: ConnectedFactDeps) {
|
|
|
71
76
|
/** The last answer (the sync fallback before the first one); a stale answer starts a refresh. */
|
|
72
77
|
read(): boolean {
|
|
73
78
|
if (!fresh()) void ensure();
|
|
74
|
-
|
|
79
|
+
if (value !== null) return value;
|
|
80
|
+
// strictly `true`: the cloud stub's `.available` is a truthy proxy, and a gate fact is a boolean
|
|
81
|
+
try {
|
|
82
|
+
return deps.sync() === true;
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
75
86
|
},
|
|
76
87
|
/** An answer somebody else already got (the status route, the preflight). */
|
|
77
88
|
note(available: boolean): void {
|
package/apps/studio/acp/index.ts
CHANGED
|
@@ -766,13 +766,19 @@ export function createAcp(ctx: Context, aiActivity?: AiActivity, options: AcpOpt
|
|
|
766
766
|
* must not kill a running turn — but a genuinely abandoned one is torn down
|
|
767
767
|
* on the first TTL. Re-attaching cancels the timer (see `attach`).
|
|
768
768
|
*/
|
|
769
|
+
/** A turn in flight, or background work the turn left running (issue #177). */
|
|
770
|
+
function isBusy(entry: BridgeEntry): boolean {
|
|
771
|
+
return entry.turnActive || entry.bridge.backgroundTasks.length > 0;
|
|
772
|
+
}
|
|
773
|
+
|
|
769
774
|
function armReap(entry: BridgeEntry): void {
|
|
770
775
|
if (entry.reapTimer) clearTimeout(entry.reapTimer);
|
|
771
776
|
entry.reapTimer = setTimeout(() => {
|
|
772
777
|
entry.reapTimer = null;
|
|
773
778
|
if (entry.sinks.size > 0) return; // re-attached in the meantime
|
|
774
779
|
const detachedFor = Date.now() - entry.detachedSince;
|
|
775
|
-
|
|
780
|
+
// Issue #177 — background work (a subagent, a background command) outlives the turn: keep it too.
|
|
781
|
+
if (isBusy(entry) && detachedFor < MAX_DETACHED_LIFETIME_MS) {
|
|
776
782
|
armReap(entry);
|
|
777
783
|
return;
|
|
778
784
|
}
|
|
@@ -788,9 +794,7 @@ export function createAcp(ctx: Context, aiActivity?: AiActivity, options: AcpOpt
|
|
|
788
794
|
for (;;) {
|
|
789
795
|
const detached = [...bridges.values()].filter((e) => e.sinks.size === 0);
|
|
790
796
|
if (detached.length <= max) return;
|
|
791
|
-
detached.sort(
|
|
792
|
-
(a, b) => Number(a.turnActive) - Number(b.turnActive) || a.lastActive - b.lastActive
|
|
793
|
-
);
|
|
797
|
+
detached.sort((a, b) => Number(isBusy(a)) - Number(isBusy(b)) || a.lastActive - b.lastActive);
|
|
794
798
|
reap(detached[0]);
|
|
795
799
|
}
|
|
796
800
|
}
|
|
@@ -963,6 +967,8 @@ export function createAcp(ctx: Context, aiActivity?: AiActivity, options: AcpOpt
|
|
|
963
967
|
},
|
|
964
968
|
onCaps: (modes, configOptions) => broadcast(entry, { t: 'caps', modes, configOptions }),
|
|
965
969
|
onSessionInfo: (info) => broadcast(entry, { t: 'session-info', ...info }),
|
|
970
|
+
// Issue #177 — the live background tasks (chrome, like caps: replayed on attach, never transcripted).
|
|
971
|
+
onBackground: (tasks) => broadcast(entry, { t: 'background', tasks }),
|
|
966
972
|
onUsage: (usage) => {
|
|
967
973
|
latestUsage = usage;
|
|
968
974
|
noteRateLimit(usage.rateLimit); // S5.6 — the outbox's `ai-allowance` gate fact
|
|
@@ -1405,7 +1411,8 @@ export function createAcp(ctx: Context, aiActivity?: AiActivity, options: AcpOpt
|
|
|
1405
1411
|
registerActivityProbe(() =>
|
|
1406
1412
|
[...bridges.values()].map((e) => ({
|
|
1407
1413
|
chatId: e.chatId,
|
|
1408
|
-
|
|
1414
|
+
// Issue #177 — background work counts as running: the tab must not rest mid-run.
|
|
1415
|
+
state: e.bridge.awaitingInputCount > 0 ? 'awaiting-input' : isBusy(e) ? 'running' : 'idle',
|
|
1409
1416
|
}))
|
|
1410
1417
|
);
|
|
1411
1418
|
|
|
@@ -1504,6 +1511,8 @@ export function createAcp(ctx: Context, aiActivity?: AiActivity, options: AcpOpt
|
|
|
1504
1511
|
// the busy state) rather than a finished one. Without this a reload
|
|
1505
1512
|
// mid-turn would look idle while the agent kept working.
|
|
1506
1513
|
send(ws, { t: 'attached', chat: safeChat, running: entry.turnActive });
|
|
1514
|
+
// Issue #177 — what is still running in the background (a reload must not hide it).
|
|
1515
|
+
send(ws, { t: 'background', tasks: entry.bridge.backgroundTasks });
|
|
1507
1516
|
entry.sentRuns.clear(); // a re-attached client gets the chat's live runs again
|
|
1508
1517
|
pushRunFrames(entry);
|
|
1509
1518
|
} else if (frame.t === 'prompt' && typeof frame.text === 'string') {
|