@staix/agent-hub 0.37.0 → 0.39.0
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/CHANGELOG.md +55 -0
- package/README.md +17 -7
- package/docs/adding-an-ai-tool.md +6 -4
- package/docs/agent-notes/README.md +16 -0
- package/docs/agent-notes/adapters.md +4 -2
- package/docs/agent-notes/budget.md +8 -0
- package/docs/agent-notes/daemon.md +15 -8
- package/docs/agent-notes/local-worker.md +1 -1
- package/docs/agent-notes/security-review.md +55 -0
- package/docs/agent-notes/tasks.md +15 -4
- package/docs/agent-notes/tests.md +3 -2
- package/docs/design/adapters.md +51 -0
- package/docs/design/agent-hub-architecture.md +29 -1
- package/docs/design/guidance-probes.md +365 -0
- package/docs/design/task-board.md +151 -5
- package/docs/dogfood.md +22 -7
- package/docs/events.md +3 -3
- package/docs/memory.md +5 -5
- package/docs/operations.md +189 -32
- package/docs/profiles.md +101 -9
- package/docs/quickstart.md +38 -4
- package/docs/research.md +6 -3
- package/docs/roles.md +52 -0
- package/docs/sdlc.md +187 -1
- package/docs/security.md +56 -13
- package/docs/text-projection.md +1 -0
- package/docs/verification/2026-11-11-0.38.0.md +41 -0
- package/docs/verification/2026-11-11-guidance-probe-t3-1226.md +85 -0
- package/docs/verification/2026-11-11-guidance-probe-t4-1226.md +65 -0
- package/docs/verification/2026-11-13-claude-implementer-2.1.323.md +59 -0
- package/docs/verification/2026-11-13-codex-01672-reviewer-isolation.md +69 -0
- package/docs/verification/2026-11-14-0.39.0.md +51 -0
- package/docs/verified.json +48 -25
- package/package.json +3 -3
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +1989 -474
- package/plugins/agent-hub/server.js +2056 -512
- package/src/adapters/acp-model-policy.ts +1 -1
- package/src/adapters/acp-session-model.ts +35 -0
- package/src/adapters/acp.ts +14 -0
- package/src/adapters/agy/definition.ts +1 -1
- package/src/adapters/agy/hooks.ts +7 -0
- package/src/adapters/claude-channel.ts +3 -2
- package/src/adapters/claude-implementer.ts +8 -0
- package/src/adapters/claude-print-child.ts +26 -2
- package/src/adapters/claude-print.ts +4 -0
- package/src/adapters/codex-appserver.ts +90 -16
- package/src/adapters/codex-review-isolation.ts +2 -0
- package/src/adapters/compat.ts +4 -4
- package/src/adapters/conformance/fakes/acp-server.ts +11 -2
- package/src/adapters/conformance/fakes/app-server.ts +5 -1
- package/src/adapters/conformance/fakes/pi-rpc.ts +1 -1
- package/src/adapters/definitions/builtin-metadata.ts +6 -6
- package/src/adapters/definitions/native-cli-jcode-mcp.ts +18 -3
- package/src/adapters/definitions/native-quota.ts +122 -0
- package/src/adapters/definitions/native-recovery.ts +3 -0
- package/src/adapters/definitions/qwen.ts +1 -1
- package/src/adapters/kimi-review.ts +23 -0
- package/src/adapters/kimi-wire-usage.ts +39 -16
- package/src/adapters/local-probe.ts +65 -6
- package/src/adapters/local-worker.ts +6 -3
- package/src/adapters/pi-state-model.ts +12 -0
- package/src/adapters/pi.ts +22 -0
- package/src/adapters/print-result-model.ts +24 -0
- package/src/adapters/registry-types.ts +10 -1
- package/src/adapters/registry.ts +19 -2
- package/src/adapters/reviewer-print.ts +130 -15
- package/src/adapters/role-eligibility.ts +99 -0
- package/src/adapters/same-directory.ts +16 -0
- package/src/cli/agy-mcp.ts +18 -7
- package/src/cli/console-state.ts +3 -1
- package/src/cli/free-text.ts +20 -0
- package/src/cli/handoff-args.ts +1 -1
- package/src/cli/help.ts +61 -6
- package/src/cli/identity.ts +10 -4
- package/src/cli/init-prompt.ts +31 -2
- package/src/cli/init-roles.ts +156 -0
- package/src/cli/init-settings.ts +24 -2
- package/src/cli/init.ts +141 -17
- package/src/cli/main.ts +216 -56
- package/src/cli/model.ts +1 -1
- package/src/cli/output.ts +64 -5
- package/src/cli/preview.ts +1 -1
- package/src/cli/recovery-launch.ts +114 -0
- package/src/cli/recovery-package.ts +14 -7
- package/src/cli/recovery-version-preflight.ts +104 -0
- package/src/cli/role-doctor.ts +39 -0
- package/src/cli/sdlc-output.ts +66 -1
- package/src/cli/study-output.ts +54 -0
- package/src/cli/study.ts +14 -1
- package/src/cli/terminal-recovery.ts +14 -0
- package/src/cli/upgrade-presentation.ts +4 -0
- package/src/cli/upgrade-restore-state.ts +12 -3
- package/src/cli/upgrade-runtime.ts +41 -3
- package/src/cli/upgrade.ts +8 -4
- package/src/hub/advisor-survey.ts +139 -0
- package/src/hub/audit-source.ts +66 -0
- package/src/hub/board.ts +479 -14
- package/src/hub/budget.ts +54 -4
- package/src/hub/bus.ts +2 -2
- package/src/hub/conductor.ts +14 -8
- package/src/hub/config-apply.ts +2 -1
- package/src/hub/config-edit-host.ts +77 -5
- package/src/hub/considered-findings.ts +47 -0
- package/src/hub/control-client.ts +1 -1
- package/src/hub/daemon.ts +373 -66
- package/src/hub/deliverable-files.ts +17 -1
- package/src/hub/dogfood-profile.ts +3 -2
- package/src/hub/envelope.ts +6 -1
- package/src/hub/events.ts +23 -2
- package/src/hub/folder-trigger.ts +11 -4
- package/src/hub/guidance-probe-store.ts +345 -14
- package/src/hub/guidance-probes.ts +338 -4
- package/src/hub/hub-tools.ts +88 -16
- package/src/hub/kimi-usage.ts +34 -2
- package/src/hub/lifecycle-schema.ts +3 -3
- package/src/hub/manager.ts +24 -1
- package/src/hub/memory-profile.ts +9 -1
- package/src/hub/memory-sync-state.ts +1 -0
- package/src/hub/model-overrides.ts +2 -1
- package/src/hub/no-writes.ts +2 -0
- package/src/hub/operational-authority.ts +8 -2
- package/src/hub/operational-view.ts +5 -1
- package/src/hub/peers.ts +2 -0
- package/src/hub/person-command.ts +25 -0
- package/src/hub/plan-conformance.ts +20 -2
- package/src/hub/quota-account.ts +34 -0
- package/src/hub/recovery-policy.ts +18 -4
- package/src/hub/research-evidence.ts +51 -3
- package/src/hub/research.ts +77 -13
- package/src/hub/restart.ts +14 -0
- package/src/hub/review-budget.ts +88 -0
- package/src/hub/review-findings.ts +93 -12
- package/src/hub/reviewer-pool-config.ts +6 -2
- package/src/hub/reviewer-pool.ts +39 -6
- package/src/hub/routing.ts +7 -3
- package/src/hub/sdlc-merge.ts +1 -1
- package/src/hub/sdlc-queue.ts +14 -4
- package/src/hub/sdlc-release.ts +1 -1
- package/src/hub/sdlc.ts +10 -6
- package/src/hub/security-audit.ts +178 -0
- package/src/hub/security-pass.ts +115 -0
- package/src/hub/settings.ts +11 -5
- package/src/hub/source-read.ts +80 -2
- package/src/hub/sources.ts +57 -9
- package/src/hub/startup-event-seeds.ts +5 -3
- package/src/hub/startup-timing.ts +1 -0
- package/src/hub/supervision.ts +3 -2
- package/src/hub/synthesis-readiness.ts +279 -0
- package/src/hub/tasks.ts +1131 -72
- package/src/hub/text-projection.ts +11 -1
- package/src/local/probe-types.ts +2 -0
- package/src/local/probe-workspace.ts +191 -2
- package/src/memory/capture.ts +2 -1
- package/src/ui/guidance-panel.ts +34 -2
- package/src/ui/guidance-view.ts +33 -0
- package/src/ui/index.html +3 -0
- package/src/ui/office-model.ts +11 -3
- package/src/ui/office-space.ts +50 -30
- package/src/ui/plugin.ts +31 -14
- package/templates/AGENTS.block.md +14 -14
- package/templates/profiles/general.json +1 -1
- package/templates/profiles/research.json +1 -1
- package/templates/profiles/writing.json +1 -1
|
@@ -10,7 +10,8 @@ import { profile, sandboxAvailable } from "../local/sandbox.ts";
|
|
|
10
10
|
export type ProjectionConfig = Record<string, string[]>;
|
|
11
11
|
const EMPTY_ROOT = "/var/empty";
|
|
12
12
|
export const MAX_PROJECTION_INPUT = 16 * 1024 * 1024;
|
|
13
|
-
const
|
|
13
|
+
export const MAX_PROJECTION_TEXT = 256 * 1024;
|
|
14
|
+
const MAX_INPUT = MAX_PROJECTION_INPUT, MAX_TEXT = MAX_PROJECTION_TEXT;
|
|
14
15
|
/** Only machine-local config chooses programs; no implicit shell or command-string parsing. */
|
|
15
16
|
export function projectionConfig(raw: unknown): ProjectionConfig {
|
|
16
17
|
if (raw === undefined) return {};
|
|
@@ -67,6 +68,15 @@ export class TextProjections {
|
|
|
67
68
|
}
|
|
68
69
|
get enabled(): boolean { return Object.keys(this.options.config).length > 0; }
|
|
69
70
|
handles(file: string): boolean { return !!this.options.config[extname(file).toLowerCase()]; }
|
|
71
|
+
/** Current configured converter identity, without reading a source or running conversion. */
|
|
72
|
+
fingerprint(file: string): string | undefined {
|
|
73
|
+
const argv = this.options.config[extname(file).toLowerCase()];
|
|
74
|
+
if (!argv) return undefined;
|
|
75
|
+
try {
|
|
76
|
+
const commandHash = commandFingerprint(this.options.cwd, argv);
|
|
77
|
+
return this.options.projectRoot === undefined ? commandHash : hash(commandHash + "\nproject-root:" + realPath(this.options.projectRoot));
|
|
78
|
+
} catch { return undefined; }
|
|
79
|
+
}
|
|
70
80
|
project(file: string): ProjectedText | undefined {
|
|
71
81
|
const ext = extname(file).toLowerCase(), argv = this.options.config[ext];
|
|
72
82
|
if (!argv) return undefined;
|
package/src/local/probe-types.ts
CHANGED
|
@@ -79,6 +79,8 @@ export interface ProbeLocalAdapterOptions {
|
|
|
79
79
|
current(): void;
|
|
80
80
|
/** Private minted-resource ownership notification, never an ordinary observer or authority source. */
|
|
81
81
|
workspaceOwned?: (workspace: ProbeWorkspace) => void;
|
|
82
|
+
/** Host-owned directory (outside every workspace) where a session's declared output is retained. Without it nothing is retained, only hashed. */
|
|
83
|
+
retentionRoot?: string;
|
|
82
84
|
fixture?: ProbeLocalFixturePorts;
|
|
83
85
|
}
|
|
84
86
|
export interface ProbeLocalAdapter {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { chmodSync, constants, closeSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, opendirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { chmodSync, constants, closeSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, opendirSync, readSync, rmSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { dirname, isAbsolute, join } from "node:path";
|
|
5
5
|
import { executionText, EXECUTION_REFERENCE_LIMITS } from "../hub/execution-reference.ts";
|
|
6
6
|
import { hubGitSync } from "../hub/git.ts";
|
|
7
|
-
import { guidanceProbeCanonical, GUIDANCE_PROBE_LIMITS, type ProbeDataPolicyV1, type
|
|
7
|
+
import { guidanceProbeCanonical, GUIDANCE_PROBE_LIMITS, PROBE_OUTPUT_LIMITS, probeOutputName, type ProbeDataPolicyV1, type ProbeExcludedReason, type ProbeOutputEntry, type ProbeOutputExcluded,
|
|
8
|
+
type ProbeOutputManifestV1, type ProbeRetainedRecord, type ProbeSlot, type ProbeTree } from "../hub/guidance-probes.ts";
|
|
8
9
|
import { foldSegment } from "../hub/permission-mode.ts";
|
|
9
10
|
import { realPath } from "../hub/project.ts";
|
|
10
11
|
import { isDenied } from "./deny.ts";
|
|
@@ -235,3 +236,191 @@ export async function reserveProbeWorkspaceStorage(workspace: ProbeWorkspace, by
|
|
|
235
236
|
await state.reserveStorage(bytes); state.current();
|
|
236
237
|
probeWorkspaceCurrent(workspace);
|
|
237
238
|
}
|
|
239
|
+
|
|
240
|
+
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
241
|
+
// T3 (#1226): output collection and owned cleanup. Contract: docs/design/guidance-probes.md "T3 receipts, reconcile and cleanup contract".
|
|
242
|
+
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
243
|
+
|
|
244
|
+
/** What `collectProbeOutput` read: the manifest, the exact bytes it hashed (kept for retention, never re-read from a path), and the measured scratch. */
|
|
245
|
+
export interface ProbeCollected {
|
|
246
|
+
manifest: ProbeOutputManifestV1;
|
|
247
|
+
/** The bytes hashed for each manifest entry, read once through the opened file. Retention copies these and never re-reads the workspace. Bounded by 64 files of 1 MiB. */
|
|
248
|
+
contents: ReadonlyMap<string, Buffer>;
|
|
249
|
+
scratchBytes: number;
|
|
250
|
+
/** True when scratch was not fully measured (a tree deeper than the walk limit): its size is unknown, so it must be treated as over the cap. */
|
|
251
|
+
scratchUnmeasured: boolean;
|
|
252
|
+
}
|
|
253
|
+
/** The deepest directory level read under output or scratch. Anything deeper is excluded (output) or makes scratch unmeasured, never silently skipped. */
|
|
254
|
+
export const PROBE_WALK_DEPTH = 8;
|
|
255
|
+
/**
|
|
256
|
+
* The most directory entries read in ONE walk (output, then scratch separately). The walk is synchronous on the daemon's event loop, so a confined child that
|
|
257
|
+
* leaves a million empty files (well under every byte cap) must not stall the control socket and every peer. Reaching it is a limit, never a silent stop:
|
|
258
|
+
* output is excluded whole (`over_walk_cap`, nothing hashed or retained from a walk that did not finish) and scratch becomes unmeasured, which is over the cap.
|
|
259
|
+
*/
|
|
260
|
+
export const PROBE_WALK_ENTRIES = 4096;
|
|
261
|
+
/** Test seam only: a hook that runs between a file's lstat and its open, to swap the file the way a racing process would. */
|
|
262
|
+
export interface ProbeCollectSeam { beforeOpen?(file: string): void; walkEntries?: number }
|
|
263
|
+
class WalkCapReached extends Error {}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Collect a finished session's declared output into a manifest: every regular, link-count-1 file under the output root is read through its opened descriptor
|
|
267
|
+
* and hashed, and the identity is re-checked after the read. Anything else (a symlink, a hardlink, a device, a directory entry the policy does not
|
|
268
|
+
* declare, a file past the per-file cap, a file that changed while read, a tree deeper than the walk limit) is recorded as an exclusion and is NOT hashed.
|
|
269
|
+
* Bytes past `maxBytes` are not read. Files are opened O_NONBLOCK|O_NOFOLLOW and must still be regular files once open, so a file swapped for a FIFO
|
|
270
|
+
* or a device after its lstat can neither block this call nor be read. Call it only after the confinement stop has reported quiescence: until then a
|
|
271
|
+
* child may still be writing. Reads only; it deletes nothing and follows no link.
|
|
272
|
+
*/
|
|
273
|
+
export function collectProbeOutput(workspace: ProbeWorkspace, maxBytes: number, seam: ProbeCollectSeam = {}): ProbeCollected {
|
|
274
|
+
probeWorkspacePhysical(workspace);
|
|
275
|
+
const entries: ProbeOutputEntry[] = [], excluded: ProbeOutputExcluded[] = [], contents = new Map<string, Buffer>();
|
|
276
|
+
let total = 0, visited = 0;
|
|
277
|
+
const walkCap = seam.walkEntries ?? PROBE_WALK_ENTRIES;
|
|
278
|
+
const declared = workspace.allowedWrites.filter(path => path === workspace.output || path.startsWith(workspace.output + "/"));
|
|
279
|
+
const within = (file: string): boolean => declared.some(path => file === path || file.startsWith(path + "/"));
|
|
280
|
+
// An exclusion is itself a receipt field, so its name must pass the same check as any other: a name that is too long or carries a control or format
|
|
281
|
+
// character is recorded under a stable digest label with the `invalid_name` reason, never dropped and never written raw.
|
|
282
|
+
const exclude = (relative: string, reason: ProbeExcludedReason): void => {
|
|
283
|
+
if (excluded.length >= PROBE_OUTPUT_LIMITS.entries) return;
|
|
284
|
+
if (!probeOutputName(relative)) { excluded.push({ relative: `invalid-name-${digest(relative).slice(0, 32)}`, reason: "invalid_name" }); return; }
|
|
285
|
+
excluded.push({ relative, reason });
|
|
286
|
+
};
|
|
287
|
+
const walk = (directory: string, depth: number): void => {
|
|
288
|
+
if (depth > PROBE_WALK_DEPTH) { exclude(directory.slice(workspace.root.length + 1), "over_depth"); return; }
|
|
289
|
+
const handle = opendirSync(directory);
|
|
290
|
+
try {
|
|
291
|
+
for (let item = handle.readSync(); item; item = handle.readSync()) {
|
|
292
|
+
if (++visited > walkCap) throw new WalkCapReached();
|
|
293
|
+
const file = join(directory, item.name), relative = file.slice(workspace.root.length + 1);
|
|
294
|
+
const before = lstatSync(file, { throwIfNoEntry: false });
|
|
295
|
+
if (!before) continue;
|
|
296
|
+
if (before.isSymbolicLink()) { exclude(relative, "not_regular"); continue; }
|
|
297
|
+
if (before.isDirectory()) { walk(file, depth + 1); continue; }
|
|
298
|
+
if (!before.isFile()) { exclude(relative, "not_regular"); continue; }
|
|
299
|
+
if (before.nlink !== 1) { exclude(relative, "linked"); continue; }
|
|
300
|
+
// A name the receipt could not carry (past the name bound, or with a control or format character) is never hashed or retained: it is an exclusion.
|
|
301
|
+
if (!probeOutputName(relative)) { exclude(relative, "invalid_name"); continue; }
|
|
302
|
+
if (!within(file)) { exclude(relative, "outside_declared_writes"); continue; }
|
|
303
|
+
if (before.size > PROBE_OUTPUT_LIMITS.fileBytes) { exclude(relative, "over_file_cap"); continue; }
|
|
304
|
+
if (entries.length >= PROBE_OUTPUT_LIMITS.entries) { exclude(relative, "over_entry_cap"); continue; }
|
|
305
|
+
if (total + before.size > maxBytes) { exclude(relative, "over_total_cap"); continue; }
|
|
306
|
+
seam.beforeOpen?.(file);
|
|
307
|
+
let fd: number;
|
|
308
|
+
try { fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK); }
|
|
309
|
+
catch { exclude(relative, "changed_while_read"); continue; }
|
|
310
|
+
let bytes: Buffer;
|
|
311
|
+
try {
|
|
312
|
+
const opened = fstatSync(fd);
|
|
313
|
+
if (!opened.isFile() || opened.dev !== before.dev || opened.ino !== before.ino || opened.nlink !== 1) { exclude(relative, "changed_while_read"); continue; }
|
|
314
|
+
bytes = Buffer.alloc(Math.min(opened.size, PROBE_OUTPUT_LIMITS.fileBytes));
|
|
315
|
+
let read = 0; while (read < bytes.length) { const n = readSync(fd, bytes, read, bytes.length - read, read); if (n === 0) break; read += n; }
|
|
316
|
+
const after = fstatSync(fd);
|
|
317
|
+
if (read !== opened.size || after.size !== opened.size || after.ino !== opened.ino || after.mtimeMs !== opened.mtimeMs) { exclude(relative, "changed_while_read"); continue; }
|
|
318
|
+
} finally { closeSync(fd); }
|
|
319
|
+
entries.push({ relative, sha256: digest(bytes), bytes: bytes.length }); contents.set(relative, bytes); total += bytes.length;
|
|
320
|
+
}
|
|
321
|
+
} finally { handle.closeSync(); }
|
|
322
|
+
};
|
|
323
|
+
try { walk(workspace.output, 0); }
|
|
324
|
+
catch (error) {
|
|
325
|
+
if (!(error instanceof WalkCapReached)) throw error;
|
|
326
|
+
// The walk did not finish, so nothing it read is a complete answer: discard it and exclude the whole output with the reason that forbids a success.
|
|
327
|
+
entries.length = 0; excluded.length = 0; contents.clear(); total = 0;
|
|
328
|
+
exclude(workspace.output.slice(workspace.root.length + 1), "over_walk_cap");
|
|
329
|
+
}
|
|
330
|
+
let scratch = 0, scratchUnmeasured = false;
|
|
331
|
+
const measure = (directory: string, depth: number): void => {
|
|
332
|
+
if (depth > PROBE_WALK_DEPTH) { scratchUnmeasured = true; return; }
|
|
333
|
+
const handle = opendirSync(directory);
|
|
334
|
+
try {
|
|
335
|
+
for (let item = handle.readSync(); item; item = handle.readSync()) {
|
|
336
|
+
if (++visited > walkCap) throw new WalkCapReached();
|
|
337
|
+
const file = join(directory, item.name), stat = lstatSync(file, { throwIfNoEntry: false });
|
|
338
|
+
if (!stat) continue;
|
|
339
|
+
if (stat.isDirectory()) measure(file, depth + 1); else if (stat.isFile()) scratch += stat.size;
|
|
340
|
+
}
|
|
341
|
+
} finally { handle.closeSync(); }
|
|
342
|
+
};
|
|
343
|
+
visited = 0;
|
|
344
|
+
try { measure(workspace.scratch, 0); }
|
|
345
|
+
catch (error) { if (!(error instanceof WalkCapReached)) throw error; scratchUnmeasured = true; }
|
|
346
|
+
entries.sort((a, b) => a.relative < b.relative ? -1 : a.relative > b.relative ? 1 : 0);
|
|
347
|
+
return { manifest: { v: 1, entries, excluded, totalBytes: total }, contents, scratchBytes: scratch, scratchUnmeasured };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** A retained output directory the host itself created, with the identity it recorded at creation. Prune acts on nothing else. */
|
|
351
|
+
export type ProbeRetained = ProbeRetainedRecord;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Copy the collected output into a fresh host-owned retention directory (mode 0700, O_EXCL files, link count 1) and return what was created. The retention
|
|
355
|
+
* directory is outside the workspace so the workspace can be released at once; what is retained is exactly the manifest's entries, nothing else.
|
|
356
|
+
*/
|
|
357
|
+
export function retainProbeOutput(workspace: ProbeWorkspace, collected: Pick<ProbeCollected, "manifest" | "contents">, root: string): ProbeRetained {
|
|
358
|
+
probeWorkspacePhysical(workspace);
|
|
359
|
+
const { manifest, contents } = collected;
|
|
360
|
+
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
361
|
+
const directory = realPath(mkdtempSync(join(root, "retained-")));
|
|
362
|
+
const identity = directoryIdentity(directory);
|
|
363
|
+
chmodSync(directory, 0o700);
|
|
364
|
+
const files: { relative: string; dev: number; ino: number; bytes: number; ctimeNs: string }[] = [];
|
|
365
|
+
try {
|
|
366
|
+
for (const entry of manifest.entries) {
|
|
367
|
+
// The bytes already read and hashed through the opened descriptor. The workspace path is never read again: a swap to a symlink, a FIFO or /dev/zero
|
|
368
|
+
// after collection can neither hang this call nor change what is retained.
|
|
369
|
+
const bytes = contents.get(entry.relative);
|
|
370
|
+
if (!bytes || bytes.length !== entry.bytes || digest(bytes) !== entry.sha256) refused();
|
|
371
|
+
// The manifest already holds only workspace-relative names; refuse anything that could leave the retention directory before joining.
|
|
372
|
+
if (!probeRelativePath(entry.relative)) refused();
|
|
373
|
+
const dest = join(directory, entry.relative);
|
|
374
|
+
mkdirSync(dirname(dest), { recursive: true, mode: 0o700 });
|
|
375
|
+
const fd = openSync(dest, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o400);
|
|
376
|
+
try { writeFileSync(fd, bytes); const created = fstatSync(fd, { bigint: true }); files.push({ relative: entry.relative, dev: Number(created.dev), ino: Number(created.ino), bytes: bytes.length, ctimeNs: created.ctimeNs.toString() }); }
|
|
377
|
+
finally { closeSync(fd); }
|
|
378
|
+
}
|
|
379
|
+
} catch (error) {
|
|
380
|
+
// Remove only what this call created, by identity, never a replaced name.
|
|
381
|
+
removeRetained({ directory, dev: identity.dev, ino: identity.ino, files }, true);
|
|
382
|
+
throw error;
|
|
383
|
+
}
|
|
384
|
+
return Object.freeze({ directory, dev: identity.dev, ino: identity.ino, files: Object.freeze(files.map(item => Object.freeze(item))) });
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** What a prune would remove from one retained directory, and why anything is kept. Read-only. */
|
|
388
|
+
export function previewRetained(retained: ProbeRetained): { remove: { relative: string; bytes: number }[]; keep: { relative: string; reason: string }[] } {
|
|
389
|
+
const remove: { relative: string; bytes: number }[] = [], keep: { relative: string; reason: string }[] = [];
|
|
390
|
+
const root = lstatSync(retained.directory, { throwIfNoEntry: false });
|
|
391
|
+
if (!root || !root.isDirectory() || root.isSymbolicLink() || root.dev !== retained.dev || root.ino !== retained.ino) {
|
|
392
|
+
return { remove, keep: [{ relative: ".", reason: "directory_replaced_or_missing" }] };
|
|
393
|
+
}
|
|
394
|
+
for (const file of retained.files) {
|
|
395
|
+
const stat = lstatSync(join(retained.directory, file.relative), { throwIfNoEntry: false, bigint: true });
|
|
396
|
+
if (!stat) continue;
|
|
397
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1n || Number(stat.dev) !== file.dev || Number(stat.ino) !== file.ino || stat.ctimeNs.toString() !== file.ctimeNs) keep.push({ relative: file.relative, reason: "identity_changed" });
|
|
398
|
+
else remove.push({ relative: file.relative, bytes: Number(stat.size) });
|
|
399
|
+
}
|
|
400
|
+
return { remove, keep };
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Remove only the files and directories this host created, each verified by captured device and inode at the moment of removal. A name that is a
|
|
405
|
+
* replacement, a symlink, a hardlink or a bystander is left exactly where it is. Never recurses through a name it did not create and never follows a link.
|
|
406
|
+
* Returns what it removed and what it kept; a retained name makes the directory itself stay.
|
|
407
|
+
*/
|
|
408
|
+
export function removeRetained(retained: ProbeRetained, partial = false): { removed: string[]; kept: { relative: string; reason: string }[] } {
|
|
409
|
+
const removed: string[] = [], kept: { relative: string; reason: string }[] = [];
|
|
410
|
+
const root = lstatSync(retained.directory, { throwIfNoEntry: false });
|
|
411
|
+
if (!root || !root.isDirectory() || root.isSymbolicLink() || root.dev !== retained.dev || root.ino !== retained.ino) {
|
|
412
|
+
return { removed, kept: [{ relative: ".", reason: "directory_replaced_or_missing" }] };
|
|
413
|
+
}
|
|
414
|
+
const parents = new Set<string>();
|
|
415
|
+
for (const file of retained.files) {
|
|
416
|
+
const path = join(retained.directory, file.relative), stat = lstatSync(path, { throwIfNoEntry: false, bigint: true });
|
|
417
|
+
if (!stat) continue;
|
|
418
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1n || Number(stat.dev) !== file.dev || Number(stat.ino) !== file.ino || stat.ctimeNs.toString() !== file.ctimeNs) { kept.push({ relative: file.relative, reason: "identity_changed" }); continue; }
|
|
419
|
+
unlinkSync(path); removed.push(file.relative);
|
|
420
|
+
for (let parent = dirname(path); parent !== retained.directory && parent.startsWith(retained.directory + "/"); parent = dirname(parent)) parents.add(parent);
|
|
421
|
+
}
|
|
422
|
+
// Directories this call may have created: removed only if now empty, deepest first; a non-empty one holds a bystander and stays.
|
|
423
|
+
for (const parent of [...parents].sort((a, b) => b.length - a.length)) { try { rmdirSync(parent); } catch { kept.push({ relative: parent.slice(retained.directory.length + 1), reason: "not_empty" }); } }
|
|
424
|
+
if (kept.length === 0 || partial) { try { rmdirSync(retained.directory); } catch { kept.push({ relative: ".", reason: "not_empty" }); } }
|
|
425
|
+
return { removed, kept };
|
|
426
|
+
}
|
package/src/memory/capture.ts
CHANGED
|
@@ -40,7 +40,8 @@ export class Capture {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
observe(call: { tool: string; args: string; output: string; id: string; paths: string[]; sourceId?: string }): void {
|
|
43
|
-
if (
|
|
43
|
+
if (call.tool.replace(/^mcp__[^ ]+__/, "") === "hub_survey_report") return;
|
|
44
|
+
if (!this.sessionId || GUIDANCE_TOOL_NAMES.has(call.tool.replace(/^mcp__[^ ]+__/, "")) || call.tool.replace(/^mcp__[^ ]+__/, "") === "hub_audit_report" || LINEAGE_TOOL_NAMES.has(call.tool.replace(/^mcp__[^ ]+__/, "")) || reviewCaptureExcluded(call.tool, call.args) || ((MEMORY_READ_TOOLS.has(call.tool.replace(/^mcp__[^ ]+__/, "")) || BOUNDED_TASK_TOOLS.has(call.tool.replace(/^mcp__[^ ]+__/, "")) || CAPABILITY_TOOLS.has(call.tool.replace(/^mcp__[^ ]+__/, "")) || STUDY_TOOLS.has(call.tool.replace(/^mcp__[^ ]+__/, "")) || HANDOFF_TOOLS.has(call.tool.replace(/^mcp__[^ ]+__/, ""))) || call.tool.replace(/^mcp__[^ ]+__/, "") === "hub_memory_correct") || call.tool.replace(/^mcp__[^ ]+__/, "") === "hub_source_read" || call.tool.replace(/^mcp__[^ ]+__/, "") === "hub_set_title" || call.tool.replace(/^mcp__[^ ]+__/, "") === "hub_evidence_read" || call.tool.replace(/^mcp__[^ ]+__/, "") === "hub_evidence_record" || this.opts.skip?.includes(call.tool)) return;
|
|
44
45
|
// #1053: a question and its answer are the person's and the peer's words: never memory evidence, whatever the call's paths say.
|
|
45
46
|
if (QUESTION_TOOLS.has(call.tool.replace(/^mcp__[^ ]+__/, ""))) return;
|
|
46
47
|
// Anything that names a denylisted path is kept out of memory entirely, input and output alike.
|
package/src/ui/guidance-panel.ts
CHANGED
|
@@ -14,6 +14,15 @@ export default (host) => {
|
|
|
14
14
|
const title = node('h2', 'Guidance');
|
|
15
15
|
const introduction = node('p', 'Inspect task-bound declarations and editable-section diffs. Source evidence is a declaration; actual handoff, testing and model consumption are unknown.');
|
|
16
16
|
const instructions = node('p', 'Create or withdraw with the authorized ahub guidance CLI or MCP tools. This panel only reads declarations.');
|
|
17
|
+
const probeForm = node('form', undefined, 'ahub-guidance-probe');
|
|
18
|
+
const probeId = node('input'); probeId.type = 'text'; probeId.autocomplete = 'off'; probeId.required = true;
|
|
19
|
+
probeId.pattern = '[a-f0-9]{64}'; probeId.maxLength = 64; probeId.spellcheck = false;
|
|
20
|
+
const probeLabel = node('label'); probeLabel.append(node('span', 'Probe ID (64 hex)'), probeId);
|
|
21
|
+
const probeButton = node('button', 'Read probe status'); probeButton.type = 'submit';
|
|
22
|
+
probeForm.append(probeLabel, probeButton);
|
|
23
|
+
const probeNote = node('p', 'Probe status is fixture evidence only: it reads the sealed receipts and the outcome denominator and claims no live model or worker trial.');
|
|
24
|
+
const probeOutput = node('pre', undefined, 'ahub-guidance-output');
|
|
25
|
+
probeOutput.tabIndex = 0; probeOutput.setAttribute('aria-label', 'Guidance probe status');
|
|
17
26
|
const scopeForm = node('form', undefined, 'ahub-guidance-scope');
|
|
18
27
|
const field = (label, control) => {
|
|
19
28
|
const wrapper = node('label');
|
|
@@ -39,20 +48,21 @@ export default (host) => {
|
|
|
39
48
|
const next = node('button', 'Next page'); next.type = 'button'; next.hidden = true;
|
|
40
49
|
const output = node('pre', undefined, 'ahub-guidance-output');
|
|
41
50
|
output.tabIndex = 0; output.setAttribute('aria-label', 'Guidance public details');
|
|
42
|
-
root.append(title, introduction, instructions, scopeForm, notice, recordList, next, output);
|
|
51
|
+
root.append(title, introduction, instructions, scopeForm, notice, recordList, next, output, probeForm, probeNote, probeOutput);
|
|
43
52
|
host.mount.append(root);
|
|
44
53
|
let generation = 0, disposed = false, visible = false, projects = [], cursor, busy = false;
|
|
45
54
|
const state = (message) => { notice.textContent = message; };
|
|
46
55
|
const update = () => {
|
|
47
56
|
listButton.disabled = busy;
|
|
48
57
|
projectsButton.disabled = busy;
|
|
58
|
+
probeButton.disabled = busy;
|
|
49
59
|
next.disabled = busy;
|
|
50
60
|
for (const button of recordList.querySelectorAll('button')) button.disabled = busy;
|
|
51
61
|
root.setAttribute('aria-busy', busy ? 'true' : 'false');
|
|
52
62
|
};
|
|
53
63
|
const invalidate = () => {
|
|
54
64
|
generation++; busy = false; cursor = undefined;
|
|
55
|
-
recordList.replaceChildren(); output.textContent = ''; next.hidden = true;
|
|
65
|
+
recordList.replaceChildren(); output.textContent = ''; probeOutput.textContent = ''; next.hidden = true;
|
|
56
66
|
update();
|
|
57
67
|
};
|
|
58
68
|
const scope = () => {
|
|
@@ -120,12 +130,33 @@ export default (host) => {
|
|
|
120
130
|
} catch { if (active(token)) failure(); }
|
|
121
131
|
finally { if (active(token)) { busy = false; update(); } }
|
|
122
132
|
}
|
|
133
|
+
async function readProbe() {
|
|
134
|
+
const selected = projects.find(row => row.id === project.value);
|
|
135
|
+
if (!selected || typeof selected.instanceId !== 'string' || !selected.instanceId || !/^[a-f0-9]{64}$/.test(probeId.value)) {
|
|
136
|
+
state('Select a running project and enter the exact 64-character probe id.'); return;
|
|
137
|
+
}
|
|
138
|
+
const id = probeId.value, token = ++generation;
|
|
139
|
+
busy = true; probeOutput.textContent = ''; update(); state('Reading probe status...');
|
|
140
|
+
try {
|
|
141
|
+
const result = await host.snapshot({ panel: 'guidance', op: 'probe', projectId: selected.id, instanceId: selected.instanceId, id });
|
|
142
|
+
if (!active(token)) return;
|
|
143
|
+
// The text shown is the provider's own lines for exactly the probe that was asked for; anything else is a refusal, never partial text.
|
|
144
|
+
if (!result || result.ok !== true || result.probe?.status?.id !== id || !Array.isArray(result.lines) || result.lines.some(line => typeof line !== 'string')) {
|
|
145
|
+
state(typeof result?.error === 'string' && result.ok === false ? result.error : 'Probe status unavailable. Refresh the probe id or check access and guidance_probe_receipts support.'); return;
|
|
146
|
+
}
|
|
147
|
+
probeOutput.textContent = result.lines.join('\n');
|
|
148
|
+
state('Probe status read. Fixture evidence only; every unknown stays unknown.');
|
|
149
|
+
} catch { if (active(token)) state('Probe status unavailable. Refresh the probe id or check access and guidance_probe_receipts support.'); }
|
|
150
|
+
finally { if (active(token)) { busy = false; update(); } }
|
|
151
|
+
}
|
|
123
152
|
scopeForm.addEventListener('submit', event => { event.preventDefault(); track(read('list')); });
|
|
153
|
+
probeForm.addEventListener('submit', event => { event.preventDefault(); track(readProbe()); });
|
|
124
154
|
projectsButton.addEventListener('click', () => track(refreshProjects()));
|
|
125
155
|
next.addEventListener('click', () => { if (cursor) track(read('list', undefined, cursor)); });
|
|
126
156
|
for (const input of [project, task, epoch]) input.addEventListener('input', () => {
|
|
127
157
|
invalidate(); state('Task scope changed. List declarations to read the selected scope.');
|
|
128
158
|
});
|
|
159
|
+
probeId.addEventListener('input', () => { generation++; busy = false; probeOutput.textContent = ''; update(); state('Probe id changed. Read probe status to refresh.'); });
|
|
129
160
|
return {
|
|
130
161
|
show(_panel, params) {
|
|
131
162
|
if (disposed) return;
|
|
@@ -151,6 +182,7 @@ export default (host) => {
|
|
|
151
182
|
.ahub-guidance-record code{overflow-wrap:anywhere;flex:1 1 30ch}.ahub-guidance-record span{font-size:.875em}
|
|
152
183
|
.ahub-guidance-output{white-space:pre-wrap;overflow-wrap:anywhere;font-size:.875em;line-height:1.55;font-variant-numeric:tabular-nums;padding:16px;border:1px solid currentColor;border-radius:10px;max-height:65vh;overflow:auto}
|
|
153
184
|
.ahub-guidance-output:empty{display:none}.ahub-guidance [hidden]{display:none!important}
|
|
185
|
+
.ahub-guidance-probe{display:flex;flex-wrap:wrap;gap:12px;align-items:end;margin:20px 0}.ahub-guidance-probe input{width:68ch;max-width:100%;font-family:ui-monospace,monospace}
|
|
154
186
|
@media(max-width:600px){.ahub-guidance{padding:12px}.ahub-guidance-scope>label{width:100%}.ahub-guidance input{width:100%}}`;
|
|
155
187
|
return { js, css };
|
|
156
188
|
}
|
package/src/ui/guidance-view.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GuidanceDiffResult, GuidancePageResult, GuidanceWriteReceipt } from "../hub/guidance-variants.ts";
|
|
2
|
+
import type { ProbeReceiptExport } from "../hub/guidance-probes.ts";
|
|
2
3
|
import { sanitize } from "../hub/envelope.ts";
|
|
3
4
|
|
|
4
5
|
/** Shared public projection only. These lines neither reconstruct private role bytes nor attest to a handoff. */
|
|
@@ -41,3 +42,35 @@ export function guidanceReceiptLines(receipt: GuidanceWriteReceipt): string[] {
|
|
|
41
42
|
"Experiment label (untrusted advisory text):", `> ${experiment}`,
|
|
42
43
|
"Actual handoff, testing and model consumption are unknown."];
|
|
43
44
|
}
|
|
45
|
+
|
|
46
|
+
/** Wire text is advisory and untrusted: no control or format character survives, and a model-written name is never shown raw. */
|
|
47
|
+
const plain = (raw: string): string => sanitize(raw).replace(/[\p{Cc}\p{Cf}]/gu, "");
|
|
48
|
+
const known = (value: number | null): string => value === null ? "unknown" : String(value);
|
|
49
|
+
/**
|
|
50
|
+
* T4 (#1226): the producer's probe status, one text for the plugin panel and the CLI. It states what the host observed and nothing more: a fixture run says
|
|
51
|
+
* `fixture`, a missing measurement says `unknown` and never zero, and every state that is not a success stays visible, so a failed, cancelled or unavailable
|
|
52
|
+
* arm cannot disappear from the denominator. A live trial is never claimed here: no production runner exists, and evidence is at most `fixture`.
|
|
53
|
+
*/
|
|
54
|
+
export function guidanceProbeStatusLines(exported: ProbeReceiptExport): string[] {
|
|
55
|
+
const status = exported.status, counts = exported.counts;
|
|
56
|
+
const lines = [`Guidance probe ${status.id}`, `Task #${status.taskId}; revision ${status.revision}; state ${status.state}; evidence ${status.evidence}.`,
|
|
57
|
+
`Experiment label (untrusted advisory text): ${plain(status.experimentId)}`,
|
|
58
|
+
`Comparable: ${exported.comparable ? "yes" : "no"}${exported.reasons.length ? ` (${exported.reasons.join(", ")})` : ""}.`,
|
|
59
|
+
`Outcomes (every reserved slot counts): ${counts.succeeded} succeeded, ${counts.failed} failed, ${counts.cancelled} cancelled, ${counts.timed_out} timed out, ${counts.unavailable} unavailable, ${counts.unknown} unknown; not started ${counts.planned}; not needed ${counts.not_needed}.`,
|
|
60
|
+
`Attempts: ${status.counters.workerAttempts} worker, ${status.counters.editorAttempts} editor; model calls ${status.counters.modelCalls}; tool calls ${status.counters.toolCalls}.`,
|
|
61
|
+
`Token usage: ${status.counters.usageUnknown || status.counters.modelCalls === 0 ? "unknown" : status.counters.tokensObservedKnown}.`,
|
|
62
|
+
`Cancel requested: ${status.cancelRequested ? "yes" : "no"}.`,
|
|
63
|
+
"Fixture evidence only: no live model or worker trial, sampling control, provider behaviour or model quality is claimed."];
|
|
64
|
+
for (const slot of exported.slots) {
|
|
65
|
+
const receipt = slot.receipt;
|
|
66
|
+
lines.push(`Slot ${plain(slot.slotId)}: ${slot.stage}/${slot.role}/${slot.arm}; session ${slot.state}; retained output ${slot.retention}.`);
|
|
67
|
+
if (receipt) {
|
|
68
|
+
lines.push(` Receipt ${receipt.state}; requested ${plain(receipt.requestedModel)}; served ${receipt.servedModel === null ? "unobserved" : plain(receipt.servedModel)}.`,
|
|
69
|
+
` Elapsed ${receipt.elapsedMs} ms; model calls ${receipt.usage.modelCalls} (${receipt.usage.modelUsageKnown} with known usage); tool calls ${receipt.usage.toolCalls}; tokens ${known(receipt.usage.tokensObserved)}.`,
|
|
70
|
+
` Output: ${receipt.output.entries.length} file${receipt.output.entries.length === 1 ? "" : "s"}, ${receipt.output.totalBytes} bytes; ${receipt.output.excluded.length} excluded.`,
|
|
71
|
+
` Limits: ${receipt.limits.join(", ") || "none"}.`, ` Receipt digest ${receipt.digest}`);
|
|
72
|
+
} else if (slot.withheld) lines.push(` Receipt withheld by the privacy screen; digest ${slot.receiptDigest}.`);
|
|
73
|
+
else lines.push(" No receipt: this slot has no sealed observation, so its outcome is unknown or not started.");
|
|
74
|
+
}
|
|
75
|
+
return lines;
|
|
76
|
+
}
|
package/src/ui/index.html
CHANGED
|
@@ -855,6 +855,9 @@ function settingRow(row, raise) {
|
|
|
855
855
|
select.value = current[index] || ''; actions.append(select); return select;
|
|
856
856
|
});
|
|
857
857
|
read = () => choices.map(select => select.value).filter(Boolean);
|
|
858
|
+
} else if (row.type === 'number-or-off') {
|
|
859
|
+
const input=el('input');input.type='text';input.id=id;input.name=row.key;input.value=fileValue===null ? '' : String(fileValue);input.placeholder='0..1 or off; empty inherits';input.autocomplete='off';input.autocapitalize='none';input.setAttribute('autocorrect','off');input.spellcheck=false;
|
|
860
|
+
read=()=>{const value=input.value.trim();return value==='' ? null : value==='off' ? 'off' : Number.isFinite(Number(value)) ? Number(value) : value;};actions.append(input);
|
|
858
861
|
} else if (row.type === 'integer' || row.type === 'number') {
|
|
859
862
|
const input=el('input');input.type='number';input.id=id;input.step=row.type === 'number' ? 'any' : '1';input.min=String(row.min ?? 0);input.max=String(row.max ?? Number.MAX_SAFE_INTEGER);const current=fileValue;input.value=current===null ? '' : String(current);input.placeholder='Empty inherits';
|
|
860
863
|
read=()=>input.value==='' ? null : Number(input.value);actions.append(input);
|
package/src/ui/office-model.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { OFFICE_PEER_ORDER } from "../adapters/registry.ts";
|
|
|
3
3
|
/**
|
|
4
4
|
* Pure office scene model for the dashboard (#264, phase 1: the static Flat view).
|
|
5
5
|
* Self-contained so `src/hub/ui.ts` injects it into the page by toString(), exactly like
|
|
6
|
-
* task-progress.ts. Inputs are allowlisted: peer states, queue counts and modes;
|
|
7
|
-
* classes, states, owners, reviewers, deps and public titles; approval counts by peer; budget
|
|
6
|
+
* task-progress.ts. Inputs are allowlisted: peer states, queue counts and modes; a peer's configured roles and the open
|
|
7
|
+
* turn's start; task ids, classes, states, owners, reviewers, deps and public titles; approval counts by peer; budget
|
|
8
8
|
* pause readings. env.body, task detail, approval titles, paths and symbols never enter;
|
|
9
9
|
* test/office-model.test.ts pins that with a marker fixture.
|
|
10
10
|
*/
|
|
@@ -121,6 +121,10 @@ export interface OfficeDesk {
|
|
|
121
121
|
approvals: number;
|
|
122
122
|
tray: { queued: number; important: number; heldBy: string; needsReview: number };
|
|
123
123
|
mode: string;
|
|
124
|
+
/** The project's configured `roles` for this peer (#1375), as configured; absent when it has none. */
|
|
125
|
+
roles?: readonly string[];
|
|
126
|
+
/** The open turn's start, in epoch ms (#1375): the one state-change time the model knows. Absent without a reported turn. */
|
|
127
|
+
turnSince?: number;
|
|
124
128
|
/** "#id class" of the turn's attributed task (phase 3, exact), else of the peer's single in_progress task; empty when unknown. Never guessed. */
|
|
125
129
|
bubble: string;
|
|
126
130
|
/** The peer is paused with a turn still open: "finishing a turn" under the Break sign. */
|
|
@@ -351,6 +355,7 @@ export function officeModel(snapshot: OfficeSnapshotInput, previous: OfficeScene
|
|
|
351
355
|
// The open turn's attributed task names the bubble exactly (phase 3); without it the
|
|
352
356
|
// single-in_progress-task heuristic applies, and otherwise there is no bubble. Never guessed.
|
|
353
357
|
const turn = peer.turn && typeof peer.turn === "object" ? peer.turn : undefined;
|
|
358
|
+
const turnSince = turn && typeof turn.since === "number" && Number.isFinite(turn.since) ? turn.since : undefined;
|
|
354
359
|
const turnTask = turn && typeof turn.task === "number" && Number.isSafeInteger(turn.task) ? turn.task : undefined;
|
|
355
360
|
const bubble = turnTask !== undefined ? `#${turnTask} ${classById.get(turnTask) ?? "task"}`
|
|
356
361
|
: !Object.hasOwn(peer, "turn") && current.length === 1 ? `#${current[0]!.id} ${text(current[0]!.class) || "task"}` : "";
|
|
@@ -363,7 +368,9 @@ export function officeModel(snapshot: OfficeSnapshotInput, previous: OfficeScene
|
|
|
363
368
|
if (finishing) parts.push("finishing a turn");
|
|
364
369
|
if (condition !== "waiting" && count > 0) parts.push(`${count} approval${count === 1 ? "" : "s"} waiting`);
|
|
365
370
|
if (!attached) parts.push("disconnected, work retained");
|
|
366
|
-
const
|
|
371
|
+
const flowRoles = snapshot.status?.roleInfo?.[id]?.flowRoles;
|
|
372
|
+
const roles = Array.isArray(flowRoles) ? flowRoles.filter((role): role is string => typeof role === "string") : [];
|
|
373
|
+
const planner = roles.includes("planner");
|
|
367
374
|
if (planner) parts.push(`planner, ${unplanned} unplanned backlog cards`);
|
|
368
375
|
// An over-full desk shows two chips and a "+N more" line in the third slot.
|
|
369
376
|
const shown = work.length > DESK_CARDS ? work.slice(0, DESK_CARDS - 1) : work;
|
|
@@ -373,6 +380,7 @@ export function officeModel(snapshot: OfficeSnapshotInput, previous: OfficeScene
|
|
|
373
380
|
dimmed: condition === "offline", attached, approvals: count,
|
|
374
381
|
tray: { queued: num(peer.queued), important: num(peer.queuedImportant), heldBy: text(peer.heldBy), needsReview: num(peer.needsReview) },
|
|
375
382
|
mode: text(peer.permissionMode), bubble, breakNote, breakResetsAt,
|
|
383
|
+
...(roles.length ? { roles } : {}), ...(turnSince !== undefined ? { turnSince } : {}),
|
|
376
384
|
finishing,
|
|
377
385
|
cards: shown.map((task, index) => card(task, x + 0.8, y + 8.5 + index * 2.5, DESK_W - 1.6, 2)),
|
|
378
386
|
extraCards: work.length - shown.length,
|
package/src/ui/office-space.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* officeModel() -> acon SpaceScene (#1012 Part 2). Pure: no DOM, no I/O, no clock beyond the model's own.
|
|
2
|
+
* officeModel() -> acon SpaceScene (#1012 Part 2, #1375). Pure: no DOM, no I/O, no clock beyond the model's own.
|
|
3
3
|
*
|
|
4
|
-
* Reads only the scene officeModel built, which is allowlisted by #264 (peer states, queue counts
|
|
5
|
-
* classes, states, owners and public titles; approval counts; link and arc ids). No envelope body, task
|
|
6
|
-
* approval title, path or symbol can reach it, and test/acon-plugin.test.ts pins that with the #264 marker fixture.
|
|
4
|
+
* Reads only the scene officeModel built, which is allowlisted by #264 (peer states, queue counts, modes and configured
|
|
5
|
+
* roles; task ids, classes, states, owners and public titles; approval counts; link and arc ids). No envelope body, task
|
|
6
|
+
* detail, approval title, path or symbol can reach it, and test/acon-plugin.test.ts pins that with the #264 marker fixture.
|
|
7
|
+
*
|
|
8
|
+
* The scene type is acon's own, imported type-only from its pinned contract entry rather than hand-copied, so a field or
|
|
9
|
+
* cap drift fails typecheck here instead of at a person's console.
|
|
7
10
|
*/
|
|
11
|
+
import type { SpaceScene, Tone } from "@staix/agent-console/contract";
|
|
8
12
|
import type { OfficeScene } from "./office-model.ts";
|
|
9
13
|
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
marks?: { kind: "approval" | "inbox" | "paused" | "mode"; text: string }[]; link: Link }[];
|
|
18
|
-
zones: { id: string; title: string; kind?: ZoneKind; count: number }[];
|
|
19
|
-
cards: { id: string; title: string; zone: string; owner?: string; tone?: Tone; link: Link }[];
|
|
20
|
-
links?: { kind: LinkKind; from: string; to: string; label?: string; at?: string }[];
|
|
21
|
-
}
|
|
14
|
+
export type { SpaceScene };
|
|
15
|
+
|
|
16
|
+
type ActorState = SpaceScene["actors"][number]["state"];
|
|
17
|
+
type ZoneKind = NonNullable<SpaceScene["zones"][number]["kind"]>;
|
|
18
|
+
type LinkKind = NonNullable<SpaceScene["links"]>[number]["kind"];
|
|
19
|
+
type Link = SpaceScene["actors"][number]["link"];
|
|
20
|
+
type Group = NonNullable<SpaceScene["groups"]>[number];
|
|
22
21
|
|
|
23
22
|
const ZONES: Record<string, { kind: ZoneKind; title: string }> = {
|
|
24
23
|
backlog: { kind: "queue", title: "Backlog" },
|
|
@@ -28,6 +27,10 @@ const ZONES: Record<string, { kind: ZoneKind; title: string }> = {
|
|
|
28
27
|
const clip = (text: string, max = 200) => text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
29
28
|
const ID = /[^A-Za-z0-9._:-]/g;
|
|
30
29
|
const safeId = (text: string) => text.replace(ID, "_").slice(0, 128);
|
|
30
|
+
const ROLE_LIMIT = 4, ROLE_TEXT_LIMIT = 32;
|
|
31
|
+
/** acon's role bounds: at most 4 public role names of at most 32 characters, in the configured order. */
|
|
32
|
+
const rolesOf = (configured: readonly string[] | undefined): string[] =>
|
|
33
|
+
(configured ?? []).filter((role) => typeof role === "string" && role.trim().length > 0 && role.length <= ROLE_TEXT_LIMIT).slice(0, ROLE_LIMIT);
|
|
31
34
|
|
|
32
35
|
/** officeModel desk condition -> SpaceScene actor state (the shell picks pet rows by state). */
|
|
33
36
|
function actorState(condition: string, attached: boolean, approvals: number, needsReview: number): ActorState {
|
|
@@ -40,12 +43,13 @@ function actorState(condition: string, attached: boolean, approvals: number, nee
|
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
/**
|
|
43
|
-
* Maps one project's office scene. `project.id` prefixes every id so scenes from several projects never collide
|
|
44
|
-
*
|
|
46
|
+
* Maps one project's office scene. `project.id` prefixes every id so scenes from several projects never collide, and it
|
|
47
|
+
* names the scene's group too (#1375): every actor, zone and card carries that `group`, and actor names stay bare because
|
|
48
|
+
* the console shows the group itself. `project.label` titles the group when the caller has a human name for the project.
|
|
45
49
|
*/
|
|
46
50
|
export function officeSpace(model: OfficeScene, project: { id: string; label?: string }, now?: number): SpaceScene {
|
|
47
51
|
const pre = (id: string | number) => safeId(`${project.id}:${id}`);
|
|
48
|
-
const
|
|
52
|
+
const group: Group = { id: safeId(project.id), title: clip((project.label ?? project.id).trim(), 200) || safeId(project.id) };
|
|
49
53
|
// Links name the owning project so a multi-project console opens the right one (the panel's show() selects it).
|
|
50
54
|
const board: Link = { panel: "board", params: { project: project.id } }, agents: Link = { panel: "agents", params: { project: project.id } };
|
|
51
55
|
const actors: SpaceScene["actors"] = model.desks.map((desk) => {
|
|
@@ -58,10 +62,14 @@ export function officeSpace(model: OfficeScene, project: { id: string; label?: s
|
|
|
58
62
|
// The card is only the bubble's attributed task ("#id ..."): a peer reviewing #2 while owning #1 shows #2, an empty bubble shows none.
|
|
59
63
|
const attributed = /^#(\d+) /.exec(desk.bubble)?.[1];
|
|
60
64
|
const card = attributed ? { id: Number(attributed) } : undefined;
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
// `since` is only what the model holds: the open turn's start, so it is present while the actor is working and absent
|
|
66
|
+
// for every other state, which has no change time here. Roles are the project's configured ones, bounded by acon.
|
|
67
|
+
const roles = rolesOf(desk.roles);
|
|
68
|
+
const since = desk.condition === "busy" && desk.turnSince !== undefined ? new Date(desk.turnSince).toISOString() : undefined;
|
|
69
|
+
return { id: pre(desk.id), name: clip(desk.id, 64), state: actorState(desk.condition, desk.attached, desk.approvals, desk.tray.needsReview), group: group.id,
|
|
70
|
+
...(card ? { card: pre(card.id) } : {}), ...(roles.length ? { roles } : {}), ...(since ? { since } : {}), ...(marks.length ? { marks } : {}), link: agents };
|
|
63
71
|
});
|
|
64
|
-
const zones: SpaceScene["zones"] = model.rooms.map((room) => ({ id: pre(room.id), title: ZONES[room.id]?.title ?? clip(room.label, 60), ...(ZONES[room.id] ? { kind: ZONES[room.id]!.kind } : {}), count: Math.max(0, room.count) }));
|
|
72
|
+
const zones: SpaceScene["zones"] = model.rooms.map((room) => ({ id: pre(room.id), title: ZONES[room.id]?.title ?? clip(room.label, 60), ...(ZONES[room.id] ? { kind: ZONES[room.id]!.kind } : {}), count: Math.max(0, room.count), group: group.id }));
|
|
65
73
|
const zoneOf = (placement: string | undefined): string | undefined => {
|
|
66
74
|
if (!placement) return undefined;
|
|
67
75
|
if (placement.startsWith("room:")) return pre(placement.slice(5));
|
|
@@ -78,7 +86,7 @@ export function officeSpace(model: OfficeScene, project: { id: string; label?: s
|
|
|
78
86
|
if (!zone) continue;
|
|
79
87
|
const tone: Tone = card.rework ? "err" : card.waiting ? "warn" : card.state === "approved" ? "ok" : "neutral";
|
|
80
88
|
// label is "#id public title"; the public view already stubs a private task as [pii].
|
|
81
|
-
cards.push({ id: pre(card.id), title: clip(card.label), zone, ...(card.owner ? { owner: pre(card.owner) } : {}), tone, link: board });
|
|
89
|
+
cards.push({ id: pre(card.id), title: clip(card.label), zone, ...(card.owner ? { owner: pre(card.owner) } : {}), tone, group: group.id, link: board });
|
|
82
90
|
}
|
|
83
91
|
const desks = new Set(model.desks.map((d) => d.id));
|
|
84
92
|
const links: NonNullable<SpaceScene["links"]> = [];
|
|
@@ -100,20 +108,32 @@ export function officeSpace(model: OfficeScene, project: { id: string; label?: s
|
|
|
100
108
|
// An attributed task that is not on the floor (not placed) has no card to point at.
|
|
101
109
|
const placedCards = new Set(cards.map((c) => c.id));
|
|
102
110
|
for (const actor of actors) if (actor.card && !placedCards.has(actor.card)) delete actor.card;
|
|
103
|
-
return { actors, zones, cards, links };
|
|
111
|
+
return { groups: [group], actors, zones, cards, links };
|
|
104
112
|
}
|
|
105
113
|
|
|
106
|
-
/** acon's
|
|
107
|
-
export const SPACE_CAPS = { actors:
|
|
114
|
+
/** acon's caps: `actors`, `cards` and `links` are its SPACE_CAPS, `groups` its item bound; over them a scene fails conformance. */
|
|
115
|
+
export const SPACE_CAPS = { actors: 96, groups: 200, cards: 200, links: 128 } as const;
|
|
108
116
|
|
|
109
|
-
/** Joins per-project scenes within acon's caps. */
|
|
117
|
+
/** Joins per-project scenes within acon's caps, keeping every reference inside what was kept. */
|
|
110
118
|
export function mergeSpaces(scenes: SpaceScene[]): SpaceScene {
|
|
119
|
+
// Declare groups first: a record's `group` must reference one of them, so a scene past the group bound loses the reference
|
|
120
|
+
// (pruned like `owner` and `card` below, never left as a dangling id) instead of the whole scene failing conformance; one
|
|
121
|
+
// group per project, so only 200+ running projects reach that.
|
|
122
|
+
const groups: Group[] = [], declared = new Set<string>();
|
|
123
|
+
for (const group of scenes.flatMap((s) => s.groups ?? [])) {
|
|
124
|
+
if (groups.length >= SPACE_CAPS.groups) break;
|
|
125
|
+
if (declared.has(group.id)) continue;
|
|
126
|
+
declared.add(group.id);
|
|
127
|
+
groups.push({ id: group.id, title: group.title });
|
|
128
|
+
}
|
|
129
|
+
const grouped = <T extends { group?: string }>(row: T): T => row.group === undefined || declared.has(row.group) ? row : (({ group: _group, ...rest }) => rest as T)(row);
|
|
111
130
|
// Cap actors and cards first, then keep only references inside what was kept, so links to cut actors never crowd out visible ones.
|
|
112
|
-
const actors = scenes.flatMap((s) => s.actors).slice(0, SPACE_CAPS.actors);
|
|
131
|
+
const actors = scenes.flatMap((s) => s.actors).slice(0, SPACE_CAPS.actors).map(grouped);
|
|
113
132
|
const actorIds = new Set(actors.map((a) => a.id));
|
|
114
|
-
const cards = scenes.flatMap((s) => s.cards).slice(0, SPACE_CAPS.cards).map((c) => c.owner && !actorIds.has(c.owner) ? (({ owner: _owner, ...rest }) => rest)(c) : c);
|
|
133
|
+
const cards = scenes.flatMap((s) => s.cards).slice(0, SPACE_CAPS.cards).map((c) => c.owner && !actorIds.has(c.owner) ? (({ owner: _owner, ...rest }) => rest)(c) : c).map(grouped);
|
|
115
134
|
const cardIds = new Set(cards.map((c) => c.id));
|
|
116
135
|
const kept = actors.map((a) => a.card && !cardIds.has(a.card) ? (({ card: _card, ...rest }) => rest)(a) : a);
|
|
136
|
+
const zones = scenes.flatMap((s) => s.zones).map(grouped);
|
|
117
137
|
const links = scenes.flatMap((s) => s.links ?? []).filter((l) => actorIds.has(l.from) && actorIds.has(l.to));
|
|
118
|
-
return { actors: kept, zones
|
|
138
|
+
return { groups, actors: kept, zones, cards, links: links.slice(Math.max(0, links.length - SPACE_CAPS.links)) };
|
|
119
139
|
}
|