@staix/agent-hub 0.52.0 → 0.54.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 +37 -0
- package/README.md +4 -3
- package/docs/addons/open-code-review.md +3 -6
- package/docs/agent-notes/README.md +1 -1
- package/docs/agent-notes/adapters.md +5 -4
- package/docs/agent-notes/budget.md +2 -2
- package/docs/agent-notes/bus.md +1 -0
- package/docs/agent-notes/daemon.md +6 -5
- package/docs/agent-notes/models.md +1 -1
- package/docs/agent-notes/tasks.md +3 -3
- package/docs/agent-notes/tests.md +4 -4
- package/docs/contracts/companion-cli-v2.json +90 -0
- package/docs/contracts/companion-cli-v3.json +348 -0
- package/docs/design/adapters.md +1 -1
- package/docs/design/agent-hub-architecture.md +8 -5
- package/docs/design/bus.md +1 -1
- package/docs/design/cli-output-inventory.md +4 -2
- package/docs/design/execution-reference.md +1 -1
- package/docs/design/guidance-experiments.md +1 -0
- package/docs/design/guidance-probes.md +1 -0
- package/docs/design/model-routes.md +20 -5
- package/docs/design/roadmap.md +6 -4
- package/docs/design/task-board.md +21 -2
- package/docs/dogfood.md +13 -6
- package/docs/events.md +1 -1
- package/docs/memory.md +2 -2
- package/docs/operations.md +158 -50
- package/docs/quickstart.md +14 -2
- package/docs/security.md +17 -9
- package/docs/specs/2026-09-19-agent-hub-design.md +5 -3
- package/docs/specs/2026-09-19-multi-project-design.md +1 -1
- package/docs/specs/2026-09-20-upgrade-recovery-design.md +24 -0
- package/docs/specs/2026-12-04-arev-adoption-design.md +84 -0
- package/docs/specs/mcp-endpoint.md +15 -4
- package/docs/specs/relay-contract.md +38 -0
- package/docs/verification/2026-12-04-host-shared-receipts.md +43 -0
- package/docs/verification/2026-12-05-0.53.0.md +101 -0
- package/docs/verification/2026-12-05-agy-1.5.24.md +55 -0
- package/docs/verification/2026-12-05-claude-implementer-2.1.337.md +43 -0
- package/docs/verification/2026-12-06-0.54.0.md +76 -0
- package/docs/verification/2026-12-06-codex-0174-reviewer-isolation.md +43 -0
- package/docs/verification/2026-12-06-codex-0174-reviewer-tool-call.md +34 -0
- package/docs/verification/2026-12-06-compat-codex-capabilities-0.174.0.md +25 -0
- package/docs/verification/2026-12-06-compat-pi-1.8.0.md +23 -0
- package/docs/verified.json +38 -29
- package/package.json +9 -3
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/.mcp.json +1 -1
- package/plugins/agent-hub/compat.json +9 -5
- package/plugins/agent-hub/kimi-hook.js +892 -874
- package/plugins/agent-hub/relay-launcher.js +24 -0
- package/plugins/agent-hub/server.js +27271 -25146
- package/src/adapters/acp-session-model.ts +1 -1
- package/src/adapters/acp.ts +5 -4
- package/src/adapters/agy/definition.ts +1 -1
- package/src/adapters/agy/hooks.ts +1 -1
- package/src/adapters/channel-peer.ts +3 -1
- package/src/adapters/claude-channel-evidence.ts +26 -1
- package/src/adapters/claude-channel.ts +27 -30
- package/src/adapters/claude-connection-policy.ts +62 -0
- package/src/adapters/claude-relay.ts +255 -0
- package/src/adapters/codex-review-isolation.ts +1 -2
- package/src/adapters/compat.ts +28 -18
- package/src/adapters/definitions/native-cli-preview-pi.ts +2 -1
- package/src/adapters/definitions/native-config-defaults.ts +1 -1
- package/src/adapters/definitions/native-context.ts +1 -2
- package/src/adapters/definitions/native-factories.ts +4 -1
- package/src/adapters/definitions/native-quota.ts +1 -1
- package/src/adapters/definitions/native-recovery.ts +3 -1
- package/src/adapters/external-modules.ts +2 -2
- package/src/adapters/kimi-review.ts +1 -1
- package/src/adapters/kimi-tui-facts.ts +1 -1
- package/src/adapters/local-worker.ts +3 -3
- package/src/adapters/native-capabilities.ts +1 -1
- package/src/adapters/pi.ts +26 -7
- package/src/adapters/registry-types.ts +2 -0
- package/src/adapters/relay-launcher.ts +27 -0
- package/src/adapters/reviewer-mcp.ts +1 -1
- package/src/cli/agents.ts +20 -8
- package/src/cli/agy-mcp.ts +1 -1
- package/src/cli/claude-profile-hook.ts +1 -1
- package/src/cli/command-table.ts +1 -0
- package/src/cli/commands/agents.ts +18 -1
- package/src/cli/commands/doctor.ts +18 -4
- package/src/cli/commands/launch-line.ts +32 -0
- package/src/cli/commands/status.ts +14 -3
- package/src/cli/help.ts +7 -4
- package/src/cli/identity.ts +1 -1
- package/src/cli/init-roles.ts +1 -1
- package/src/cli/init-settings.ts +1 -1
- package/src/cli/launch-line-plan.ts +82 -0
- package/src/cli/launch-line-project.ts +13 -0
- package/src/cli/main.ts +10 -9
- package/src/cli/pi-steps-warning.ts +14 -0
- package/src/cli/recovery-package.ts +60 -6
- package/src/cli/reset.ts +1 -1
- package/src/cli/shell-quote.ts +1 -3
- package/src/cli/upgrade-interactive.ts +7 -2
- package/src/cli/upgrade-keep-plan.ts +47 -0
- package/src/cli/upgrade-restore-state.ts +1 -1
- package/src/cli/upgrade-runtime.ts +119 -18
- package/src/cli/upgrade.ts +17 -2
- package/src/hub/accounts.ts +8 -4
- package/src/hub/action-class.ts +1 -3
- package/src/hub/adec-triage.ts +105 -0
- package/src/hub/autonomy.ts +1 -1
- package/src/hub/board.ts +3 -27
- package/src/hub/bus.ts +39 -6
- package/src/hub/capabilities.ts +1 -1
- package/src/hub/channel-project-base.ts +46 -0
- package/src/hub/channel-project.ts +21 -46
- package/src/hub/config-apply.ts +1 -1
- package/src/hub/config-edit.ts +1 -1
- package/src/hub/config-tier.ts +1 -1
- package/src/hub/config.ts +2 -2
- package/src/hub/confirmation-matrix.ts +1 -1
- package/src/hub/control/board-messages.ts +415 -0
- package/src/hub/control/dashboard-messages.ts +221 -0
- package/src/hub/control/delivery-messages.ts +356 -0
- package/src/hub/control/dispatch.ts +114 -0
- package/src/hub/control/hub-tool-helpers.ts +243 -0
- package/src/hub/control/hub-tools.ts +147 -0
- package/src/hub/control/native-messages.ts +665 -0
- package/src/hub/control/operations-messages.ts +269 -0
- package/src/hub/control/peer-messages.ts +126 -0
- package/src/hub/control/recovery-messages.ts +391 -0
- package/src/hub/control/recovery-operation.ts +480 -0
- package/src/hub/control/scope.ts +460 -0
- package/src/hub/control/sdlc-messages.ts +373 -0
- package/src/hub/control/task-ops-more.ts +245 -0
- package/src/hub/control/task-ops.ts +553 -0
- package/src/hub/control/ui-actions.ts +241 -0
- package/src/hub/control-write-trace.ts +1 -4
- package/src/hub/daemon.ts +485 -4324
- package/src/hub/delivery-hints.ts +2 -0
- package/src/hub/delivery-journal.ts +17 -6
- package/src/hub/events.ts +2 -1
- package/src/hub/execution-reference.ts +1 -1
- package/src/hub/host.ts +41 -9
- package/src/hub/hub-tools.ts +3 -4
- package/src/hub/invocations.ts +1 -1
- package/src/hub/lifecycle.ts +4 -3
- package/src/hub/mcp-endpoint-serve.ts +4 -3
- package/src/hub/mcp-endpoint.ts +15 -6
- package/src/hub/memory-profile-check.ts +1 -1
- package/src/hub/no-writes.ts +1 -1
- package/src/hub/peers.ts +2 -0
- package/src/hub/pi-exit-policy.ts +27 -0
- package/src/hub/progress.ts +1 -1
- package/src/hub/project-runtime-state.ts +17 -4
- package/src/hub/project-runtime.ts +3 -1
- package/src/hub/protocol-window.ts +1 -1
- package/src/hub/recovery-continuity.ts +3 -3
- package/src/hub/recovery-kept-roster.ts +50 -0
- package/src/hub/review-anchor.ts +13 -181
- package/src/hub/review-brief.ts +78 -28
- package/src/hub/review-findings.ts +15 -193
- package/src/hub/review-ledger.ts +162 -0
- package/src/hub/review-material.ts +3 -3
- package/src/hub/reviewer-pool.ts +4 -2
- package/src/hub/roadmap-issue-states.ts +65 -14
- package/src/hub/roadmap-sync.ts +39 -14
- package/src/hub/routing.ts +9 -0
- package/src/hub/runtime-capture-prune.ts +8 -2
- package/src/hub/runtime-package-assets.ts +3 -0
- package/src/hub/sdlc-release-policy.ts +1 -2
- package/src/hub/settings.ts +1 -1
- package/src/hub/spec-ack-tool.ts +4 -0
- package/src/hub/spec-report-history.ts +36 -0
- package/src/hub/specs.ts +1 -4
- package/src/hub/supervision.ts +33 -6
- package/src/hub/tasks-audit.ts +390 -0
- package/src/hub/tasks-backlog.ts +522 -0
- package/src/hub/tasks-handoff.ts +208 -0
- package/src/hub/tasks-release.ts +257 -0
- package/src/hub/tasks-roadmap.ts +17 -3
- package/src/hub/tasks-specs.ts +672 -0
- package/src/hub/tasks-types.ts +334 -0
- package/src/hub/tasks.ts +286 -1961
- package/src/hub/upgrade-session-contract.ts +11 -0
- package/src/local/probe-sandbox.ts +1 -2
- package/src/local/probe-workspace.ts +1 -1
- package/src/models/route/config.ts +4 -4
- package/src/models/route/decision.ts +18 -10
- package/src/models/route/observation-signals.ts +1 -2
- package/src/models/route/runtime.ts +8 -5
- package/src/npm-artifact.ts +76 -0
- package/src/omniroute/client.ts +6 -0
- package/src/pi/extension.ts +5 -2
- package/src/pi/install.ts +77 -0
- package/src/pi/pin.ts +49 -0
- package/src/primitives.ts +14 -0
- package/src/version.ts +2 -0
- package/templates/adec/README.md +10 -6
- package/templates/config.json +1 -1
- package/templates/specs.block.md +1 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { KINDS, sanitize, type Kind } from "./envelope.ts";
|
|
2
2
|
|
|
3
|
+
/** #1946: the reason an ACP session stop leaves on a row (src/adapters/acp.ts). It is the one needs_review reason that holds only its own row; the producer and the bus both use this constant. */
|
|
4
|
+
export const ACP_STOPPED_BEFORE_SETTLEMENT = "ACP session stopped before settlement";
|
|
3
5
|
export const HELD_DELIVERY_PAGE = 32;
|
|
4
6
|
export const MAX_HELD_HINT_ROWS = 32;
|
|
5
7
|
export const DELIVERY_RETRY_WARNING = sanitize("Hub redelivery warning: An earlier attempt of this delivery is uncertain; check for its effects before acting.");
|
|
@@ -55,6 +55,8 @@ export interface JournalDelivery {
|
|
|
55
55
|
out: Envelope[];
|
|
56
56
|
reason?: string;
|
|
57
57
|
failureCause?: DeliveryFailureCause;
|
|
58
|
+
/** #1946: a host-owned mark (only the ACP adapter's own unrequested stop sets it): this needs_review row holds only itself. Never derived from reason text. */
|
|
59
|
+
holdsSelf?: true;
|
|
58
60
|
attempt?: number;
|
|
59
61
|
previousId?: string;
|
|
60
62
|
}
|
|
@@ -320,6 +322,7 @@ function validateDelivery(value: unknown, name = "delivery"): JournalDelivery {
|
|
|
320
322
|
);
|
|
321
323
|
if (d.reason !== undefined) text(d.reason, `${name}.reason`, 1_000_000);
|
|
322
324
|
const failureCause = checkedFailureCause(d.failureCause);
|
|
325
|
+
if (d.holdsSelf !== undefined && d.holdsSelf !== true) fail(`${name}.holdsSelf is invalid`);
|
|
323
326
|
if (d.attempt !== undefined) integer(d.attempt, `${name}.attempt`, 0, 100);
|
|
324
327
|
if (d.previousId !== undefined) text(d.previousId, `${name}.previousId`, 256);
|
|
325
328
|
return {
|
|
@@ -333,6 +336,7 @@ function validateDelivery(value: unknown, name = "delivery"): JournalDelivery {
|
|
|
333
336
|
out,
|
|
334
337
|
...(d.reason === undefined ? {} : { reason: d.reason as string }),
|
|
335
338
|
...(failureCause === undefined ? {} : { failureCause }),
|
|
339
|
+
...(d.holdsSelf === true ? { holdsSelf: true as const } : {}),
|
|
336
340
|
...(d.attempt === undefined ? {} : { attempt: d.attempt as number }),
|
|
337
341
|
...(d.previousId === undefined
|
|
338
342
|
? {}
|
|
@@ -497,6 +501,7 @@ export class DeliveryJournal {
|
|
|
497
501
|
);
|
|
498
502
|
const deliveryColumns = this.db.query("PRAGMA table_info(deliveries)").all() as { name: string }[];
|
|
499
503
|
if (!deliveryColumns.some(column => column.name === "failure_cause")) this.db.run("ALTER TABLE deliveries ADD COLUMN failure_cause TEXT");
|
|
504
|
+
if (!deliveryColumns.some(column => column.name === "holds_self")) this.db.run("ALTER TABLE deliveries ADD COLUMN holds_self INTEGER");
|
|
500
505
|
this.db.run("CREATE TABLE IF NOT EXISTS review_input_sessions (project_id TEXT NOT NULL, peer TEXT NOT NULL, session_hash TEXT NOT NULL, input_hash TEXT, PRIMARY KEY(project_id,peer,session_hash))");
|
|
501
506
|
this.db.run("CREATE TABLE IF NOT EXISTS review_input_incomplete_peers (project_id TEXT NOT NULL, peer TEXT NOT NULL, PRIMARY KEY(project_id,peer))");
|
|
502
507
|
this.db.run("CREATE TABLE IF NOT EXISTS review_input_incomplete_sessions (project_id TEXT NOT NULL, peer TEXT NOT NULL, session_hash TEXT NOT NULL, PRIMARY KEY(project_id,peer,session_hash))");
|
|
@@ -1249,7 +1254,7 @@ export class DeliveryJournal {
|
|
|
1249
1254
|
for (const d of deliveries)
|
|
1250
1255
|
this.db
|
|
1251
1256
|
.query(
|
|
1252
|
-
"INSERT INTO deliveries (id, project_id, peer, state, revision, created_at, updated_at, originals, out_json, reason, attempt, previous_id, failure_cause) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
1257
|
+
"INSERT INTO deliveries (id, project_id, peer, state, revision, created_at, updated_at, originals, out_json, reason, attempt, previous_id, failure_cause, holds_self) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
1253
1258
|
)
|
|
1254
1259
|
.run(
|
|
1255
1260
|
d.id,
|
|
@@ -1265,6 +1270,7 @@ export class DeliveryJournal {
|
|
|
1265
1270
|
d.attempt ?? null,
|
|
1266
1271
|
d.previousId ?? null,
|
|
1267
1272
|
checkedFailureCause(d.failureCause) ?? null,
|
|
1273
|
+
d.holdsSelf === true ? 1 : null,
|
|
1268
1274
|
);
|
|
1269
1275
|
this.refreshReviewInputCoverage(true);
|
|
1270
1276
|
this.harden();
|
|
@@ -1316,7 +1322,7 @@ export class DeliveryJournal {
|
|
|
1316
1322
|
this.writeQueueMetadata(bus, revision, trackQueuePressure);
|
|
1317
1323
|
this.db
|
|
1318
1324
|
.query(
|
|
1319
|
-
"INSERT INTO deliveries (id, project_id, peer, state, revision, created_at, updated_at, originals, out_json, reason, attempt, previous_id, failure_cause) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
1325
|
+
"INSERT INTO deliveries (id, project_id, peer, state, revision, created_at, updated_at, originals, out_json, reason, attempt, previous_id, failure_cause, holds_self) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
1320
1326
|
)
|
|
1321
1327
|
.run(
|
|
1322
1328
|
delivery.id,
|
|
@@ -1332,6 +1338,7 @@ export class DeliveryJournal {
|
|
|
1332
1338
|
delivery.attempt ?? null,
|
|
1333
1339
|
delivery.previousId ?? null,
|
|
1334
1340
|
checkedFailureCause(delivery.failureCause) ?? null,
|
|
1341
|
+
delivery.holdsSelf === true ? 1 : null,
|
|
1335
1342
|
);
|
|
1336
1343
|
this.harden();
|
|
1337
1344
|
return { ...delivery, revision, updatedAt: now };
|
|
@@ -1354,7 +1361,7 @@ export class DeliveryJournal {
|
|
|
1354
1361
|
const updatedAt = input.updatedAt ?? Date.now();
|
|
1355
1362
|
this.db
|
|
1356
1363
|
.query(
|
|
1357
|
-
"INSERT INTO deliveries (id, project_id, peer, state, revision, created_at, updated_at, originals, out_json, reason, attempt, previous_id, failure_cause) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
1364
|
+
"INSERT INTO deliveries (id, project_id, peer, state, revision, created_at, updated_at, originals, out_json, reason, attempt, previous_id, failure_cause, holds_self) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
1358
1365
|
)
|
|
1359
1366
|
.run(
|
|
1360
1367
|
input.id,
|
|
@@ -1370,6 +1377,7 @@ export class DeliveryJournal {
|
|
|
1370
1377
|
input.attempt ?? null,
|
|
1371
1378
|
input.previousId ?? null,
|
|
1372
1379
|
checkedFailureCause(input.failureCause) ?? null,
|
|
1380
|
+
input.holdsSelf === true ? 1 : null,
|
|
1373
1381
|
);
|
|
1374
1382
|
this.pruneTerminal(input.state, input.id);
|
|
1375
1383
|
return { ...input, revision, updatedAt };
|
|
@@ -1442,6 +1450,7 @@ export class DeliveryJournal {
|
|
|
1442
1450
|
reason?: string,
|
|
1443
1451
|
expectedRevision?: number,
|
|
1444
1452
|
failureCause?: DeliveryFailureCause,
|
|
1453
|
+
holdsSelf?: boolean,
|
|
1445
1454
|
): JournalDelivery {
|
|
1446
1455
|
this.ensureOpen();
|
|
1447
1456
|
if (!STATES.has(state)) throw new Error("invalid delivery state");
|
|
@@ -1456,9 +1465,9 @@ export class DeliveryJournal {
|
|
|
1456
1465
|
const revision = this.bump();
|
|
1457
1466
|
this.db
|
|
1458
1467
|
.query(
|
|
1459
|
-
"UPDATE deliveries SET state = ?, revision = ?, updated_at = ?, reason = ?, failure_cause = ? WHERE id = ? AND project_id = ?",
|
|
1468
|
+
"UPDATE deliveries SET state = ?, revision = ?, updated_at = ?, reason = ?, failure_cause = ?, holds_self = ? WHERE id = ? AND project_id = ?",
|
|
1460
1469
|
)
|
|
1461
|
-
.run(state, revision, Date.now(), reason ?? null, failureCause ?? old.failureCause ?? null, id, this.projectId);
|
|
1470
|
+
.run(state, revision, Date.now(), reason ?? null, failureCause ?? old.failureCause ?? null, holdsSelf === undefined ? (old.holdsSelf ? 1 : null) : holdsSelf ? 1 : null, id, this.projectId);
|
|
1462
1471
|
this.refreshReviewInputCoverage(true);
|
|
1463
1472
|
this.pruneTerminal(state, id);
|
|
1464
1473
|
return this.get(id)!;
|
|
@@ -1859,7 +1868,7 @@ export class DeliveryJournal {
|
|
|
1859
1868
|
for (const row of snapshot.deliveries)
|
|
1860
1869
|
this.db
|
|
1861
1870
|
.query(
|
|
1862
|
-
"INSERT INTO deliveries (id, project_id, peer, state, revision, created_at, updated_at, originals, out_json, reason, attempt, previous_id, failure_cause) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
1871
|
+
"INSERT INTO deliveries (id, project_id, peer, state, revision, created_at, updated_at, originals, out_json, reason, attempt, previous_id, failure_cause, holds_self) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
1863
1872
|
)
|
|
1864
1873
|
.run(
|
|
1865
1874
|
row.id,
|
|
@@ -1875,6 +1884,7 @@ export class DeliveryJournal {
|
|
|
1875
1884
|
row.attempt ?? null,
|
|
1876
1885
|
row.previousId ?? null,
|
|
1877
1886
|
checkedFailureCause(row.failureCause) ?? null,
|
|
1887
|
+
row.holdsSelf === true ? 1 : null,
|
|
1878
1888
|
);
|
|
1879
1889
|
for (const raw of reviewInputProvenance.holds) {
|
|
1880
1890
|
const hold = reviewInputHold(raw, "snapshot review input");
|
|
@@ -1917,6 +1927,7 @@ function parseDelivery(row: Record<string, unknown>): JournalDelivery {
|
|
|
1917
1927
|
out: JSON.parse(String(row.out_json)),
|
|
1918
1928
|
...(row.reason == null ? {} : { reason: String(row.reason) }),
|
|
1919
1929
|
...(row.failure_cause == null ? {} : { failureCause: row.failure_cause }),
|
|
1930
|
+
...(row.holds_self === 1 ? { holdsSelf: true } : {}),
|
|
1920
1931
|
...(row.attempt == null ? {} : { attempt: Number(row.attempt) }),
|
|
1921
1932
|
...(row.previous_id == null ? {} : { previousId: String(row.previous_id) }),
|
|
1922
1933
|
});
|
package/src/hub/events.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { appendFileSync, closeSync, existsSync, fstatSync, openSync, readFileSyn
|
|
|
2
2
|
import type { TaskAttribution } from "./attribution.ts";
|
|
3
3
|
import { segmentsOf, streamEnd } from "./log-rotation.ts";
|
|
4
4
|
import type { PeerId } from "./envelope.ts";
|
|
5
|
+
import type { DecisionTrace } from "../models/route/decision.ts";
|
|
5
6
|
import type { StageSwitchTrace as SwitchTrace } from "../models/route/stage-fallback.ts";
|
|
6
7
|
import type { ScreenRecord } from "./inference.ts";
|
|
7
8
|
import { safeModelLabel } from "../omniroute/usage.ts";
|
|
@@ -76,7 +77,7 @@ export type HubEvent =
|
|
|
76
77
|
| { type: "quiet"; id: string; from: string; peers: string[] }
|
|
77
78
|
| { type: "fact"; peer: string; id: string; files: number; plans: number; unknown: number; named: number; bytes: number; via: "hook" | "steer" | "done"; ms?: number; hookMs?: number; rttMs?: number; accepted?: boolean; unanswered?: boolean; probe?: boolean; coverage?: boolean }
|
|
78
79
|
| { type: "fact_ack"; peer: string; id: string; via: string; ms: number }
|
|
79
|
-
| ({ type: "route"; peer: string; route: string; tier: string; source: "override" | "dimensions" | "hold" | "classifier" | "default" | "load" | "cooldown" | "pin" | "decision"; score: number; ms: number; decisionTarget?: "judge";
|
|
80
|
+
| ({ type: "route"; peer: string; route: string; tier: string; source: "override" | "dimensions" | "hold" | "classifier" | "default" | "load" | "cooldown" | "pin" | "decision"; score: number; ms: number; decisionTarget?: "judge"; stateless?: boolean; decision?: string; turn?: string; task?: number; pii?: boolean; severity?: number; spinning?: number; exploring?: number; production?: number } & Partial<SwitchTrace> & Partial<DecisionTrace>)
|
|
80
81
|
| { type: "cooldown"; peer: string; alias: string; event: "start" | "end"; failures: number; ms?: number }
|
|
81
82
|
| { type: "route_outcome"; peer: string; decision: string; turnId: string; turn: "completed" | "failed"; task?: number; pii: boolean; latched: boolean; next?: { severity: number; tests: "pass" | "fail" | "none"; repeat: boolean }; advisor?: "approve" | "redo" | "failed" }
|
|
82
83
|
| { type: "advisor"; peer: string; route: string; trigger: string; verdict: "approve" | "redo" | "failed"; discardedChars: number }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { types } from "node:util";
|
|
2
2
|
/** ExecutionReferenceV1 is an opaque address, never authority or a resolver instruction. */
|
|
3
|
-
export const EXECUTION_PRODUCERS = ["ahub", "ares", "amem", "vmem", "atex"] as const;
|
|
3
|
+
export const EXECUTION_PRODUCERS = ["ahub", "ares", "amem", "vmem", "atex", "arev"] as const;
|
|
4
4
|
export interface ExecutionReferenceV1 {
|
|
5
5
|
v: 1;
|
|
6
6
|
tool: typeof EXECUTION_PRODUCERS[number];
|
package/src/hub/host.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WebSocketHandler } from "bun";
|
|
1
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
4
|
import { chmodSync, existsSync, mkdirSync, rmSync } from "node:fs";
|
|
@@ -12,7 +13,21 @@ import { processSignature } from "../pi/process-signature.ts";
|
|
|
12
13
|
/** What a launched project gives the host: the daemon's stop and its end, and the registry claim to give back. */
|
|
13
14
|
export interface HostedDaemon { stop(): Promise<void>; stopped: Promise<unknown> }
|
|
14
15
|
export interface Launched { daemon: HostedDaemon; release(): void }
|
|
15
|
-
export
|
|
16
|
+
export interface HostLaunchOptions {
|
|
17
|
+
unattended: boolean;
|
|
18
|
+
hostId: string;
|
|
19
|
+
runControlWebSocket(callback: () => void): void;
|
|
20
|
+
}
|
|
21
|
+
export type Launch = (project: Project, options: HostLaunchOptions) => Promise<Launched>;
|
|
22
|
+
|
|
23
|
+
export function hostedControlWebSocket<T>(handler: WebSocketHandler<T>, run?: HostLaunchOptions["runControlWebSocket"]): WebSocketHandler<T> {
|
|
24
|
+
if (!run) return handler;
|
|
25
|
+
return {
|
|
26
|
+
...handler,
|
|
27
|
+
message(socket, data) { run(() => handler.message(socket, data)); },
|
|
28
|
+
close(socket, code, reason) { run(() => handler.close?.(socket, code, reason)); },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
16
31
|
|
|
17
32
|
export interface HostOptions {
|
|
18
33
|
launch: Launch;
|
|
@@ -59,7 +74,23 @@ export class Host {
|
|
|
59
74
|
if (this.projects.has(project.id) || this.pending.has(project.id)) throw new Error("project already runs in this host");
|
|
60
75
|
this.pending.add(project.id); // reserve the id across the await
|
|
61
76
|
let launched: Launched;
|
|
62
|
-
|
|
77
|
+
let controlFailure: { error: unknown } | undefined;
|
|
78
|
+
const stopForControlFailure = (error: unknown) => {
|
|
79
|
+
const running = this.projects.get(project.id);
|
|
80
|
+
if (running && running.launched === launched) {
|
|
81
|
+
void this.stopFailedProject(project.id, error, "uncaught exception").catch(() => {});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const runControlWebSocket = (callback: () => void) => this.within(project.id, () => {
|
|
85
|
+
try { callback(); }
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (controlFailure) return;
|
|
88
|
+
// Bun may lose the async context when a WebSocket throw escapes into the process hook.
|
|
89
|
+
controlFailure = { error };
|
|
90
|
+
stopForControlFailure(error);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
try { launched = await this.within(project.id, () => this.options.launch(project, { unattended, hostId: this.id, runControlWebSocket })); }
|
|
63
94
|
catch (error) { this.pending.delete(project.id); this.maybeFinish(); throw error; }
|
|
64
95
|
finally { this.pending.delete(project.id); }
|
|
65
96
|
this.everAdded = true;
|
|
@@ -69,6 +100,7 @@ export class Host {
|
|
|
69
100
|
this.maybeFinish();
|
|
70
101
|
});
|
|
71
102
|
this.projects.set(project.id, { project, launched, ended });
|
|
103
|
+
if (controlFailure) stopForControlFailure(controlFailure.error);
|
|
72
104
|
}
|
|
73
105
|
|
|
74
106
|
/** Stop one project, leaving the others serving. Removes its listener, timers and children through the daemon's own stop. */
|
|
@@ -106,16 +138,16 @@ export class Host {
|
|
|
106
138
|
if (this.everAdded && this.projects.size === 0 && this.pending.size === 0 && !this.closing) { this.uninstall(); this.finish(); }
|
|
107
139
|
}
|
|
108
140
|
|
|
141
|
+
private async stopFailedProject(id: string, error: unknown, kind: string): Promise<void> {
|
|
142
|
+
this.log(`${kind} in project ${id}; stopping that project only: ${error instanceof Error ? error.message : String(error)}`);
|
|
143
|
+
await this.stopProject(id);
|
|
144
|
+
}
|
|
145
|
+
|
|
109
146
|
/** An uncaught error: stops the project it belongs to, or, with no attribution, the host. */
|
|
110
147
|
async handleUncaught(error: unknown, kind = "uncaught exception"): Promise<void> {
|
|
111
|
-
const text = error instanceof Error ? error.message : String(error);
|
|
112
148
|
const id = this.currentProject();
|
|
113
|
-
if (id !== undefined && this.projects.has(id))
|
|
114
|
-
|
|
115
|
-
await this.stopProject(id);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
this.log(`${kind} outside any project; stopping the host: ${text}`);
|
|
149
|
+
if (id !== undefined && this.projects.has(id)) return this.stopFailedProject(id, error, kind);
|
|
150
|
+
this.log(`${kind} outside any project; stopping the host: ${error instanceof Error ? error.message : String(error)}`);
|
|
119
151
|
await this.stopAll();
|
|
120
152
|
}
|
|
121
153
|
|
package/src/hub/hub-tools.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { specAck, specAckDescription, specAckFields } from "./spec-ack-tool.ts";
|
|
1
2
|
import { defaultPeerRoles } from "../adapters/definitions/native-adapter-policy.ts";
|
|
2
3
|
import { EXECUTION_REFERENCE_LIMITS } from "./execution-reference.ts";
|
|
3
4
|
import { CHECKPOINT_FIELDS, CHECKPOINT_FIELDS_SENTENCE, CHECKPOINT_FIELD_MAX_LINES, CHECKPOINT_FIELD_MAX_LINE_CHARS, CHECKPOINT_HEADINGS } from "./checkpoint-fields.ts";
|
|
@@ -11,10 +12,8 @@ import { catalogSection, type CatalogRole } from "./roles.ts";
|
|
|
11
12
|
import { CONDUCTOR_START_PEERS, conductorStartText } from "../adapters/declaration-data.ts";
|
|
12
13
|
// The hub's task tools, defined once: the MCP server (Claude plugin, Kimi, Codex) and the local worker both read this.
|
|
13
14
|
import { NOTE_KINDS } from "./envelope.ts";
|
|
14
|
-
|
|
15
|
-
/** Restricted to the fixed current-child tools server, never an ordinary peer tool. */
|
|
16
15
|
/** The fixed MCP surface of a current owned implementer child; independent of broader project roles. */
|
|
17
|
-
export const IMPLEMENTER_HUB_TOOL_NAMES: readonly string[] = Object.freeze(["hub_task_accept", "hub_task_decline", "hub_task_done", "hub_task_wait", "hub_checkpoint", "hub_send", "hub_task_show", "hub_task_propose", "hub_remember", "hub_visual", "hub_visual_show", "hub_inbox", "hub_permission_request", "hub_study_show", "hub_experiment_show", "hub_experiment_record", "hub_study_handoff", "hub_specs", "hub_delivery_resolve", "hub_evidence_record", "hub_evidence_read", "hub_lineage_show", "hub_lineage_link", "hub_guidance_create", "hub_guidance_list", "hub_guidance_show", "hub_guidance_withdraw"]);
|
|
16
|
+
export const IMPLEMENTER_HUB_TOOL_NAMES: readonly string[] = Object.freeze(["hub_task_accept", "hub_task_decline", "hub_task_done", "hub_spec_ack", "hub_task_wait", "hub_checkpoint", "hub_send", "hub_task_show", "hub_task_propose", "hub_remember", "hub_visual", "hub_visual_show", "hub_inbox", "hub_permission_request", "hub_study_show", "hub_experiment_show", "hub_experiment_record", "hub_study_handoff", "hub_specs", "hub_delivery_resolve", "hub_evidence_record", "hub_evidence_read", "hub_lineage_show", "hub_lineage_link", "hub_guidance_create", "hub_guidance_list", "hub_guidance_show", "hub_guidance_withdraw"]);
|
|
18
17
|
|
|
19
18
|
export const IMPLEMENTER_PERMISSION_TOOL = {
|
|
20
19
|
name: "hub_permission_request",
|
|
@@ -52,7 +51,6 @@ const refs = {
|
|
|
52
51
|
additionalProperties: false,
|
|
53
52
|
} as const;
|
|
54
53
|
const list = (description: string) => ({ type: "array", items: str, description }) as const;
|
|
55
|
-
const specAck = { type: "array", maxItems: 20, items: { type: "object", properties: { id: { type: "string", minLength: 1, maxLength: 160 }, reason: { type: "string", minLength: 1, maxLength: 1000 } }, required: ["id", "reason"], additionalProperties: false } } as const;
|
|
56
54
|
/** #509a: files a task delivered. The hub hashes them itself; there is no hash field, and one is refused. */
|
|
57
55
|
const deliverablesSchema = {
|
|
58
56
|
type: "array", minItems: 1, maxItems: 16,
|
|
@@ -305,6 +303,7 @@ export const TASK_TOOLS: HubTool[] = [
|
|
|
305
303
|
tool("hub_task_accept", "Take a task that was assigned to you, with your plan for it. Set refs.repo for work in another repository; acceptance may correct only that repository metadata.", { id, plan: acceptPlan, refs: { ...refs, properties: { repo: refs.properties.repo } } }, ["id"]),
|
|
306
304
|
tool("hub_task_cancel", "Cancel proposed/backlog work you proposed as its configured planner, including work an owner accepted and then declined while it has no execution, branch, commit or PR evidence; work with any such evidence is person-only. The configured conductor may also cancel a task another project handed this one that nobody has accepted. Keeps history and does not stop a native turn or delete files.", { id, reason: str, superseded_by: str, revision: { type: "integer", minimum: 0 } }, ["id", "reason"]),
|
|
307
305
|
tool("hub_task_decline", "Pass on a task assigned to you; the hub offers it to the next peer. A plain decline is a lasting refusal: you are never offered this task again. Pass capacity: true whenever the reason is load: you are busy, at your WIP cap or running a job. You are then skipped until you next report idle, and the task goes back to its planner or the next peer. Leave capacity off only for \"I should never own this\".", { id, reason: str, capacity: { type: "boolean" } }, ["id"]),
|
|
306
|
+
tool("hub_spec_ack", specAckDescription, specAckFields, ["id", "head", "spec_ack"]),
|
|
308
307
|
tool("hub_task_done", "Mark your task finished. It goes to its reviewer with your summary and refs; no duplicate hub_send chat is needed. When re-filing work after review, set refs.commit to the new full SHA; summary text does not change the review head. If a covering spec is unchanged, update it or provide spec_ack with a public reason for each unchanged spec. When the project configures a check for its class, the hub runs it first and the result comes as a task message: a failed check keeps the task with you.", { id, summary: { type: "string", description: "what changed, why, and the check you ran with its result" }, refs, deliverables: deliverablesSchema, spec_ack: specAck, resolved: { type: "array", maxItems: 64, uniqueItems: true, items: str, description: "Sent person comment ids addressed by this admitted completion; this is an owner claim, not check or verdict proof" } }, ["id", "summary"]),
|
|
309
308
|
tool("hub_sdlc_record", "Record artifact ids or claimed local checks on your task. This grants no authority or external-check evidence. Only its owner/reviewer or the person may record; only its reviewer/person may name a reviewed head or phase checklist. Phase evidence refs are content hashes, not external verification.", { id, receipt: { type: "object", properties: { deliverables: deliverablesSchema, stage: { type: "string", enum: ["spec", "plan", "implement", "review", "verify", "merge", "release"] }, repo: str, issue: id, pr: id, localHead: str, localResult: { type: "string", enum: ["passed", "failed", "unknown"] }, reviewedHead: str, phase: { type: "object", properties: { id: str, head: str, tasks: { type: "array", maxItems: 64, items: { type: "object", properties: { id, after: { type: "array", maxItems: 16, items: id } }, required: ["id", "after"], additionalProperties: false } }, criteria: { type: "array", maxItems: 32, items: { type: "object", properties: { id: str, required: { type: "boolean" }, result: { type: "string", enum: ["verified", "failed", "unverified"] }, refs: { type: "array", maxItems: 8, items: str } }, required: ["id", "required", "result", "refs"], additionalProperties: false } } }, required: ["id", "tasks", "criteria"], additionalProperties: false } }, additionalProperties: false } }, ["id", "receipt"]),
|
|
310
309
|
tool("hub_task_list", "The task board, newest updated first, 50 compact rows (id, state, owner, reviewer, title) per call. The reply is {tasks, total, next?}: pass next as cursor for the following page. Use ids for full rows of specific tasks, or detail: true for full rows of a page. PII tasks show as [pii].", { state: { type: "string", enum: ["proposed", "in_progress", "in_review", "approved", "changes_requested", "cancelled"] }, ready: { type: "boolean", description: "only proposed tasks with nothing left to wait for" }, limit: { type: "integer", minimum: 1, maximum: 200, description: "rows per page, default 50" }, cursor: { type: "string", description: "the next value from the previous reply, unchanged" }, ids: { type: "array", minItems: 1, maxItems: 200, items: { type: "integer", minimum: 1 }, description: "full rows for exactly these task numbers; no paging" }, detail: { type: "boolean", description: "full rows instead of compact rows" } }),
|
package/src/hub/invocations.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { openHubDatabase } from "./db-schema.ts";
|
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { MAX_HOP, sanitize } from "./envelope.ts";
|
|
8
8
|
import type { FlatSchema, ShareState, SideEffect } from "./capabilities.ts";
|
|
9
|
+
import { isRecord as object } from "../primitives.ts";
|
|
9
10
|
|
|
10
11
|
export const OUTCOMES = ["queued", "delivered", "completed", "refused", "failed", "expired", "timeout", "needs_review", "withheld"] as const;
|
|
11
12
|
export type InvocationOutcome = (typeof OUTCOMES)[number];
|
|
@@ -24,7 +25,6 @@ export const MAX_OPEN_PER_TARGET = 8;
|
|
|
24
25
|
|
|
25
26
|
const NATIVE_INPUT: FlatSchema = { type: "object", properties: { input: { type: "string" } }, additionalProperties: false };
|
|
26
27
|
const CONTROL = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f\u2028\u2029\u202a-\u202e\u2066-\u2069]/;
|
|
27
|
-
const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
|
|
28
28
|
|
|
29
29
|
export type ArgsCheck = { ok: true; args: Record<string, string | number | boolean> } | { ok: false; reason: string };
|
|
30
30
|
/**
|
package/src/hub/lifecycle.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HostLaunchOptions } from "./host.ts";
|
|
1
2
|
import { waitForStartupReadiness, type StartupOwner } from "./startup-readiness.ts";
|
|
2
3
|
import { rotateTextLogAtStart } from "./log-rotation.ts";
|
|
3
4
|
import { resolveProjectRuntime, recordProjectRuntime, confirmProjectRuntime, readProjectRuntimeForCaller, projectRuntimeRefusal, type ProjectRuntimeSelection } from "./project-runtime.ts";
|
|
@@ -152,7 +153,7 @@ export async function runProjectDaemon(project: Project, unattended = false): Pr
|
|
|
152
153
|
for (let attempt = 0; attempt < 100; attempt++) {
|
|
153
154
|
if (await available(base)) {
|
|
154
155
|
try {
|
|
155
|
-
daemon = await startDaemon({ cwd: project.root, stateDir: project.stateDir, projectId: project.id, instanceId, mcpHome: hubHome(),
|
|
156
|
+
daemon = await startDaemon({ cwd: project.root, stateDir: project.stateDir, projectId: project.id, instanceId, mcpHome: hubHome(), mcpServe: true,
|
|
156
157
|
controlPort: base + CONTROL, codexAppPort: base + CODEX_APP, codexProxyPort: base + CODEX_PROXY,
|
|
157
158
|
unattended, onShutdownStart, agentDrift: true,
|
|
158
159
|
// #269: the real terminal providers belong to the running product; a daemon built without them opens nothing.
|
|
@@ -182,7 +183,7 @@ export async function runProjectDaemon(project: Project, unattended = false): Pr
|
|
|
182
183
|
* #1779 T3a: the daemon half of `runProjectDaemon`, for a host process that owns the signals and the forced exit.
|
|
183
184
|
* ponytail: it mirrors `runProjectDaemon`'s claim, runtime check and port loop so the default one-process path stays byte-identical; fold the two once shared mode is the default (T5).
|
|
184
185
|
*/
|
|
185
|
-
export async function launchHostedProject(project: Project, opts:
|
|
186
|
+
export async function launchHostedProject(project: Project, opts: HostLaunchOptions & { env: NodeJS.ProcessEnv }): Promise<{ daemon: Awaited<ReturnType<typeof import("./daemon.ts").startDaemon>>; release(): void }> {
|
|
186
187
|
assertLifecycleAvailable(project.root);
|
|
187
188
|
assertHubDbCompatible(join(project.stateDir, "hub.db"));
|
|
188
189
|
const registry = new Registry();
|
|
@@ -210,7 +211,7 @@ export async function launchHostedProject(project: Project, opts: { unattended:
|
|
|
210
211
|
for (let attempt = 0; attempt < 100; attempt++) {
|
|
211
212
|
if (await available(base)) {
|
|
212
213
|
try {
|
|
213
|
-
daemon = await startDaemon({ cwd: project.root, stateDir: project.stateDir, projectId: project.id, instanceId, mcpHome: hubHome(), context, hostId: opts.hostId,
|
|
214
|
+
daemon = await startDaemon({ cwd: project.root, stateDir: project.stateDir, projectId: project.id, instanceId, mcpHome: hubHome(), mcpServe: true, context, hostId: opts.hostId, runControlWebSocket: opts.runControlWebSocket,
|
|
214
215
|
controlPort: base + CONTROL, codexAppPort: base + CODEX_APP, codexProxyPort: base + CODEX_PROXY,
|
|
215
216
|
unattended: opts.unattended, agentDrift: true,
|
|
216
217
|
terminal: (template) => terminalOpener({ template, cwd: project.root, stateDir: project.stateDir }) });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { claudeHeldReason } from "../adapters/claude-connection-policy.ts";
|
|
1
2
|
// #1780 T2a-2c: the JSON-RPC 2.0 half of the MCP endpoint. One session per connection: `initialize` and `tools/list` come from the shared core (`mcp-bridge-core.ts`), `tools/call` from the bridge's own
|
|
2
3
|
// translation (`mcp-tool-call.ts`), over a ControlClient the daemon opened for the session. Nothing here reads the hello's home or any path; the daemon derives roles, profile and catalog itself.
|
|
3
4
|
import { hubToolCall, withPendingHint, text, type McpToolCallState } from "./mcp-tool-call.ts";
|
|
@@ -28,6 +29,7 @@ interface ServeMcpSessionInput {
|
|
|
28
29
|
buffer: string[];
|
|
29
30
|
/** The tool definitions the host was last given by a session of this peer (#490). A new session of the same peer that finds a different list asks the host to list again. Owned by the daemon, like the buffer. */
|
|
30
31
|
listed?: { key?: string };
|
|
32
|
+
reannounceOnAttach?: boolean;
|
|
31
33
|
log(line: string): void;
|
|
32
34
|
}
|
|
33
35
|
const INBOX_CAP = 200;
|
|
@@ -99,8 +101,7 @@ export function serveMcpSession(input: ServeMcpSessionInput): McpSessionServer {
|
|
|
99
101
|
get invalidPermissionAttempts() { return invalidPermissionAttempts; }, set invalidPermissionAttempts(value) { invalidPermissionAttempts = value; },
|
|
100
102
|
inbox: input.buffer,
|
|
101
103
|
get pendingQueued() { return pendingQueued; }, set pendingQueued(value) { pendingQueued = value; },
|
|
102
|
-
|
|
103
|
-
HELD: `another session is attached to the hub as "${peer}"`, NO_PROJECT: "agent-hub has no hub to join", NO_SESSION_SUPPORT: "the hub predates session identities", UNIDENTIFIED: "agent-hub tools refused: no peer identity",
|
|
104
|
+
HELD: `${claudeHeldReason(peer)}; a person can hand it over with ahub peer takeover ${peer}`, NO_PROJECT: "agent-hub has no hub to join", NO_SESSION_SUPPORT: "the hub predates session identities", UNIDENTIFIED: "agent-hub tools refused: no peer identity",
|
|
104
105
|
};
|
|
105
106
|
|
|
106
107
|
const handleRequest = async (id: unknown, method: string, params: any): Promise<string> => {
|
|
@@ -141,7 +142,7 @@ export function serveMcpSession(input: ServeMcpSessionInput): McpSessionServer {
|
|
|
141
142
|
return;
|
|
142
143
|
}
|
|
143
144
|
};
|
|
144
|
-
if (listed.key !== undefined) void reannounce().catch(() => {});
|
|
145
|
+
if (input.reannounceOnAttach !== false && listed.key !== undefined) void reannounce().catch(() => {});
|
|
145
146
|
|
|
146
147
|
return {
|
|
147
148
|
handle(line) {
|
package/src/hub/mcp-endpoint.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { timingSafeEqual, randomUUID } from "node:crypto";
|
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { execFile } from "node:child_process";
|
|
8
8
|
import { isClaudeSessionUuid } from "./claude-state.ts";
|
|
9
|
+
import type { ClaudeChannelEvidence } from "../adapters/claude-channel-evidence.ts";
|
|
9
10
|
|
|
10
11
|
type McpMode = "channel" | "tools";
|
|
11
12
|
/** What the hub keeps of one relay session: never the home path, only the account label it maps to. */
|
|
@@ -23,7 +24,8 @@ interface McpEndpointOptions {
|
|
|
23
24
|
/** #1780 T2a: set only by a daemon that holds its project's fixed control port, which one daemon per project can bind; it alone lets a stale socket file be replaced. */
|
|
24
25
|
exclusiveOwner?: boolean;
|
|
25
26
|
/** #1780 T2a-2c: serves the session's JSON-RPC. Without it every request after the hello gets -32601 "not served yet". Returning undefined closes the connection (the serve step wrote its own reason). */
|
|
26
|
-
serve?: (session: McpSession, hello: McpHello, write: (line: string) => boolean, close: () => void) => Promise<McpSessionServer | undefined>;
|
|
27
|
+
serve?: (session: McpSession, hello: McpHello, write: (line: string) => boolean, close: () => void, evidence: ClaudeChannelEvidence) => Promise<McpSessionServer | undefined>;
|
|
28
|
+
channelEvidence?: (hello: McpHello) => ClaudeChannelEvidence | Promise<ClaudeChannelEvidence>;
|
|
27
29
|
onSession?: (session: McpSession, socket: Socket) => void; onClose?: (session: McpSession) => void;
|
|
28
30
|
}
|
|
29
31
|
type McpEndpointResult = { ok: true; endpoint: McpEndpoint } | { ok: false; refusal: string };
|
|
@@ -32,9 +34,9 @@ const HELLO_BYTES = 8192, LINE_BYTES = 1024 * 1024, HELLO_MS = 5000, PEER = /^[a
|
|
|
32
34
|
|
|
33
35
|
/** The hello's optional fields mirror what the bridge sends on its control connect; roles, profile and catalog are never taken from it. */
|
|
34
36
|
export type McpHello = { v: 1; mode: McpMode; peer: string; pid: number; ppid: number; cwd: string; home?: string; token: string;
|
|
35
|
-
session?: string; claudeSessionId?: string; launchId?: string; projectRoot?: string; permissionTool?: boolean; deliveryOnly?: boolean };
|
|
37
|
+
session?: string; claudeSessionId?: string; launchId?: string; projectRoot?: string; permissionTool?: boolean; deliveryOnly?: boolean; relay?: boolean; channelRequested?: boolean; standby?: boolean; reconnect?: boolean; projectId?: string; instanceId?: string };
|
|
36
38
|
type Hello = McpHello;
|
|
37
|
-
const HELLO_KEYS = new Set(["v", "mode", "peer", "pid", "ppid", "cwd", "home", "token", "session", "claudeSessionId", "launchId", "projectRoot", "permissionTool", "deliveryOnly"]);
|
|
39
|
+
const HELLO_KEYS = new Set(["v", "mode", "peer", "pid", "ppid", "cwd", "home", "token", "session", "claudeSessionId", "launchId", "projectRoot", "permissionTool", "deliveryOnly", "relay", "channelRequested", "standby", "reconnect", "projectId", "instanceId"]);
|
|
38
40
|
|
|
39
41
|
/** One hello line, parsed. Anything unexpected is a refusal; the caller closes the connection without a reply. */
|
|
40
42
|
function validateHello(line: string, token: string): Hello | undefined {
|
|
@@ -49,11 +51,15 @@ function validateHello(line: string, token: string): Hello | undefined {
|
|
|
49
51
|
if (typeof hello.cwd !== "string" || hello.cwd.length === 0 || hello.cwd.length > 4096) return undefined;
|
|
50
52
|
if (hello.home !== undefined && (typeof hello.home !== "string" || hello.home.length > 4096)) return undefined;
|
|
51
53
|
// The same limits the control path applies: a session label, a Claude session uuid, a launch id of at most 128 characters, a project root of at most 4096.
|
|
52
|
-
if (hello.session !== undefined && (typeof hello.session !== "string" || hello.session.length
|
|
54
|
+
if (hello.session !== undefined && (typeof hello.session !== "string" || hello.session.length > 64)) return undefined;
|
|
53
55
|
if (hello.claudeSessionId !== undefined && !isClaudeSessionUuid(hello.claudeSessionId)) return undefined;
|
|
54
56
|
if (hello.launchId !== undefined && (typeof hello.launchId !== "string" || hello.launchId.length === 0 || hello.launchId.length > 128)) return undefined;
|
|
55
57
|
if (hello.projectRoot !== undefined && (typeof hello.projectRoot !== "string" || hello.projectRoot.length === 0 || hello.projectRoot.length > 4096)) return undefined;
|
|
56
|
-
for (const key of ["
|
|
58
|
+
for (const key of ["projectId", "instanceId"] as const) {
|
|
59
|
+
const value = hello[key];
|
|
60
|
+
if (value !== undefined && (typeof value !== "string" || !value || value.length > 128 || /[\p{Cc}\p{Cf}]/u.test(value))) return undefined;
|
|
61
|
+
}
|
|
62
|
+
for (const key of ["permissionTool", "deliveryOnly", "relay", "channelRequested", "standby", "reconnect"] as const) if (hello[key] !== undefined && typeof hello[key] !== "boolean") return undefined;
|
|
57
63
|
if (typeof hello.token !== "string") return undefined;
|
|
58
64
|
const given = Buffer.from(hello.token), expected = Buffer.from(token);
|
|
59
65
|
if (given.length !== expected.length || !timingSafeEqual(given, expected)) return undefined;
|
|
@@ -152,13 +158,16 @@ export async function startMcpEndpoint(options: McpEndpointOptions): Promise<Mcp
|
|
|
152
158
|
const owner = await uidOf(hello.pid);
|
|
153
159
|
if (closed || socket.destroyed) return;
|
|
154
160
|
if (uid !== undefined && owner !== uid) return close();
|
|
161
|
+
const evidence = options.serve && hello.mode === "channel" && hello.session === undefined && hello.channelRequested !== false
|
|
162
|
+
? await options.channelEvidence?.(hello) ?? "unknown" : "unknown";
|
|
163
|
+
if (closed || socket.destroyed) return;
|
|
155
164
|
clearTimeout(timer);
|
|
156
165
|
const label = options.accountLabel(hello.home, hello.peer);
|
|
157
166
|
session = { id: randomUUID(), peer: hello.peer, mode: hello.mode, pid: hello.pid, ppid: hello.ppid, ...(label ? { accountLabel: label } : {}), connectedAt: Date.now() };
|
|
158
167
|
sessions.set(session.id, session);
|
|
159
168
|
options.onSession?.(session, socket);
|
|
160
169
|
if (options.serve) {
|
|
161
|
-
served = await options.serve(session, hello, text => { if (closed || socket.destroyed) return false; socket.write(`${text}\n`); return true; },
|
|
170
|
+
served = await options.serve(session, hello, text => { if (closed || socket.destroyed) return false; socket.write(`${text}\n`); return true; }, () => { closed = true; socket.end(); }, evidence);
|
|
162
171
|
// The serve step wrote its own reason; end the connection after it so the line is flushed.
|
|
163
172
|
if (!served) { closed = true; socket.end(); return; }
|
|
164
173
|
// The connection may have closed while the session was admitted: the close handler ran before `served` existed.
|
|
@@ -6,6 +6,7 @@ import { canonicalPath, hubHome, realPath } from "./project.ts";
|
|
|
6
6
|
import { processLiveness, type Liveness } from "../pi/process-signature.ts";
|
|
7
7
|
import type { Project } from "./registry.ts";
|
|
8
8
|
import { MEMORY_SPLIT_INCOMPLETE, shardProfileForProject, type UnboundMemoryProfileReceipt } from "./memory-profile.ts";
|
|
9
|
+
import { isRecord as object } from "../primitives.ts";
|
|
9
10
|
|
|
10
11
|
export interface ExpectedMemoryProfile {
|
|
11
12
|
home: string;
|
|
@@ -49,7 +50,6 @@ export interface MemoryProfileCheck {
|
|
|
49
50
|
daemons: CheckedMemoryDaemon[];
|
|
50
51
|
reason?: string;
|
|
51
52
|
}
|
|
52
|
-
const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
|
|
53
53
|
const revision = (value: unknown): value is string => value === "absent" || typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
54
54
|
const generationCapable = (version: string): boolean => {
|
|
55
55
|
const parts = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/.exec(version);
|
package/src/hub/no-writes.ts
CHANGED
|
@@ -37,7 +37,7 @@ export class NoWriteTurns {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
const OWNER_TOOL_EFFECTS = new Set(["hub_task_propose", "hub_task_decline", "hub_task_done", "hub_task_cancel", "hub_task_assign", "hub_task_escalate", "hub_review", "hub_checkpoint", "hub_remember", "hub_memory_correct", "hub_check_start", "hub_check_cancel", "hub_sdlc_record", "hub_plan_review", "hub_backlog_plan", "hub_backlog_pull", "hub_backlog_undo", "hub_backlog_split", "hub_backlog_return_untouched", "hub_release_new", "hub_release_configure", "hub_release_assign", "hub_release_cut", "hub_study_handoff", "hub_experiment_record", "hub_evidence_record"]);
|
|
40
|
+
const OWNER_TOOL_EFFECTS = new Set(["hub_task_propose", "hub_task_decline", "hub_task_done", "hub_spec_ack", "hub_task_cancel", "hub_task_assign", "hub_task_escalate", "hub_review", "hub_checkpoint", "hub_remember", "hub_memory_correct", "hub_check_start", "hub_check_cancel", "hub_sdlc_record", "hub_plan_review", "hub_backlog_plan", "hub_backlog_pull", "hub_backlog_undo", "hub_backlog_split", "hub_backlog_return_untouched", "hub_release_new", "hub_release_configure", "hub_release_assign", "hub_release_cut", "hub_study_handoff", "hub_experiment_record", "hub_evidence_record"]);
|
|
41
41
|
OWNER_TOOL_EFFECTS.add("hub_survey_report");
|
|
42
42
|
OWNER_TOOL_EFFECTS.add("hub_roadmap_edit");
|
|
43
43
|
OWNER_TOOL_EFFECTS.add("hub_roadmap_triage");
|
package/src/hub/peers.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface DeliveryReceipt {
|
|
|
13
13
|
reason?: string;
|
|
14
14
|
/** Public-safe transport cause only, never native error text. */
|
|
15
15
|
failureCause?: DeliveryFailureCause;
|
|
16
|
+
/** #1946: only the in-process ACP adapter's own unrequested stop sets this; the control receipt path never copies it from a caller. */
|
|
17
|
+
holdsSelf?: true;
|
|
16
18
|
/** A provider refused before acceptance for quota; requeue without spending poison retries while paused. */
|
|
17
19
|
quota?: true;
|
|
18
20
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PiExit } from "../adapters/pi.ts";
|
|
2
|
+
|
|
3
|
+
/** #1967 T1: one label per unexpected Pi exit, so the log and the restart rule name the same cause. Never carries task text. */
|
|
4
|
+
export function piExitReason(exit: Pick<PiExit, "cause" | "code" | "signal" | "modelProvider">): string {
|
|
5
|
+
if (exit.signal) return `signal:${exit.signal}`;
|
|
6
|
+
if (exit.cause === "session_shutdown" && exit.modelProvider) return `model_select:${exit.modelProvider}`;
|
|
7
|
+
if (exit.cause === "session_shutdown" && exit.code === null) return "session_shutdown";
|
|
8
|
+
if (exit.code !== null) return `code:${exit.code}`;
|
|
9
|
+
return exit.cause;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** A killed or self-shutdown owner has no clean exit code to explain it; the owner may restart once (#1967). A plain exit code keeps the earlier inspect-first rule. */
|
|
13
|
+
export const piRestartableReason = (reason: string): boolean => reason.startsWith("signal:") || reason === "session_shutdown" || reason.startsWith("model_select:");
|
|
14
|
+
|
|
15
|
+
const PI_SAME_CAUSE_WINDOW_MS = 10 * 60_000;
|
|
16
|
+
|
|
17
|
+
/** Per peer: an owner restarts once after an unexpected exit, and not again while the same cause repeats inside the window. */
|
|
18
|
+
export class PiRestartLedger {
|
|
19
|
+
// Keyed by peer and cause, so a different cause never erases the window of an earlier one.
|
|
20
|
+
private readonly last = new Map<string, number>();
|
|
21
|
+
private key(peer: string, reason: string): string { return JSON.stringify([peer, reason]); }
|
|
22
|
+
allow(peer: string, reason: string, now: number): boolean {
|
|
23
|
+
const previous = this.last.get(this.key(peer, reason));
|
|
24
|
+
return !(previous !== undefined && now - previous < PI_SAME_CAUSE_WINDOW_MS);
|
|
25
|
+
}
|
|
26
|
+
record(peer: string, reason: string, now: number): void { this.last.set(this.key(peer, reason), now); }
|
|
27
|
+
}
|
package/src/hub/progress.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { asRecord as record } from "../primitives.ts";
|
|
1
2
|
import { EscalationControl } from "../models/route/escalation-control.ts";
|
|
2
3
|
import type { EscalationCategory, EscalationReply } from "../models/route/judge-replies.ts";
|
|
3
4
|
import { diagnoseStageResult } from "../models/route/stage-diagnostics.ts";
|
|
@@ -207,7 +208,6 @@ export class ProgressObserver {
|
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
function key(peer: string, task: number): string { return `${peer}\0${task}`; }
|
|
210
|
-
function record(value: unknown): Record<string, unknown> | undefined { return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined; }
|
|
211
211
|
function boundedObservation(item: NativeToolObservation): NativeToolObservation {
|
|
212
212
|
return {
|
|
213
213
|
name: item.name.slice(0, 80),
|
|
@@ -6,8 +6,19 @@ import { configRepositoryPresent } from "./config-trust.ts";
|
|
|
6
6
|
import { childEnv } from "./child-process.ts";
|
|
7
7
|
import { hubGitSync } from "./git.ts";
|
|
8
8
|
|
|
9
|
+
export type SessionContract = Readonly<{ claude: number; codex: number }>;
|
|
10
|
+
|
|
11
|
+
export function parseSessionContract(value: unknown): SessionContract | undefined {
|
|
12
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
13
|
+
const row = value as Record<string, unknown>;
|
|
14
|
+
const { claude, codex } = row;
|
|
15
|
+
if (Object.keys(row).length !== 2 || typeof claude !== "number" || !Number.isSafeInteger(claude) || claude <= 0
|
|
16
|
+
|| typeof codex !== "number" || !Number.isSafeInteger(codex) || codex <= 0) return;
|
|
17
|
+
return value as SessionContract;
|
|
18
|
+
}
|
|
19
|
+
|
|
9
20
|
export type RuntimeProject = Pick<Project, "id" | "root" | "stateDir">;
|
|
10
|
-
export interface ProjectRuntimeSelection { version: string; root: string; digest: string; kind: "restart" | "upgrade" }
|
|
21
|
+
export interface ProjectRuntimeSelection { version: string; root: string; digest: string; kind: "restart" | "upgrade"; sessionContract?: SessionContract }
|
|
11
22
|
export interface ProjectRuntimeIdentity extends ProjectRuntimeSelection {
|
|
12
23
|
schema: 1; projectId: string; projectRoot: string; stateDir: string; instanceId: string | null;
|
|
13
24
|
}
|
|
@@ -23,13 +34,15 @@ const invalid = (): Error => new Error("project runtime record is invalid; inspe
|
|
|
23
34
|
export function parseProjectRuntime(project: RuntimeProject, input: unknown): ProjectRuntimeIdentity {
|
|
24
35
|
if (!input || typeof input !== "object" || Array.isArray(input)) throw invalid();
|
|
25
36
|
const row = input as Record<string, unknown>;
|
|
26
|
-
|
|
37
|
+
const sessionContract = parseSessionContract(row.sessionContract);
|
|
38
|
+
if (Object.keys(row).filter(key => key !== "sessionContract").sort().join(",") !== "digest,instanceId,kind,projectId,projectRoot,root,schema,stateDir,version"
|
|
39
|
+
|| (Object.hasOwn(row, "sessionContract") && !sessionContract)
|
|
27
40
|
|| row.schema !== 1 || row.projectId !== project.id || row.projectRoot !== project.root || row.stateDir !== project.stateDir
|
|
28
41
|
|| !version(row.version) || !pathText(row.root) || typeof row.digest !== "string" || row.digest.length !== 64 || !/^[a-f0-9]{64}$/.test(row.digest)
|
|
29
42
|
|| row.kind !== "restart" && row.kind !== "upgrade"
|
|
30
43
|
|| row.instanceId !== null && (typeof row.instanceId !== "string" || /^[a-zA-Z0-9-]{1,128}$/.exec(row.instanceId)?.[0] !== row.instanceId)) throw invalid();
|
|
31
44
|
return { schema: 1, projectId: project.id, projectRoot: project.root, stateDir: project.stateDir,
|
|
32
|
-
version: row.version, root: row.root, digest: row.digest, kind: row.kind, instanceId: row.instanceId as string | null };
|
|
45
|
+
version: row.version, root: row.root, digest: row.digest, kind: row.kind, instanceId: row.instanceId as string | null, ...(sessionContract ? { sessionContract } : {}) };
|
|
33
46
|
}
|
|
34
47
|
|
|
35
48
|
const ACCESS = Symbol("project runtime access");
|
|
@@ -147,7 +160,7 @@ export function readProjectRuntimeReference(project: RuntimeProject): ProjectRun
|
|
|
147
160
|
/** Caller holds the shared runtime-capture lock until publication and its launch/reference effects finish. */
|
|
148
161
|
function writeRuntimeState(project: RuntimeProject, runtime: ProjectRuntimeSelection, instanceId: string | null): ProjectRuntimeIdentity {
|
|
149
162
|
const record = parseProjectRuntime(project, { schema: 1, projectId: project.id, projectRoot: project.root, stateDir: project.stateDir,
|
|
150
|
-
version: runtime.version, root: runtime.root, digest: runtime.digest, kind: runtime.kind, instanceId });
|
|
163
|
+
version: runtime.version, root: runtime.root, digest: runtime.digest, kind: runtime.kind, instanceId, ...(runtime.sessionContract ? { sessionContract: runtime.sessionContract } : {}) });
|
|
151
164
|
assertExecutableRuntimeRoot(record.root);
|
|
152
165
|
readProjectRuntimeReference(project); // refuse to overwrite an unknown binding or an unsafe file
|
|
153
166
|
const body = JSON.stringify(record);
|
|
@@ -2,6 +2,7 @@ import { resolve } from "node:path";
|
|
|
2
2
|
import { stageCurrentRuntime, verifyRecoveryTarget, newerVersion, exactVersion } from "../cli/recovery-package.ts";
|
|
3
3
|
import { hubHome, realPath } from "./project.ts";
|
|
4
4
|
import { Registry, type Project } from "./registry.ts";
|
|
5
|
+
import { readSessionContract } from "./upgrade-session-contract.ts";
|
|
5
6
|
import { processLiveness } from "../pi/process-signature.ts";
|
|
6
7
|
import { assertExecutableRuntimeRoot, createProjectRuntimeAccess, readProjectRuntime, writeProjectRuntimeState, type ProjectRuntimeAccess, type ProjectRuntimeIdentity, type ProjectRuntimeSelection } from "./project-runtime-state.ts";
|
|
7
8
|
export { readProjectRuntime } from "./project-runtime-state.ts";
|
|
@@ -44,7 +45,8 @@ export function recordProjectRuntime(project: Project, runtime: ProjectRuntimeSe
|
|
|
44
45
|
|| instanceId === null && current.instanceId && processLiveness(current.pid, current.pidSignature) !== "gone")
|
|
45
46
|
throw new Error("project runtime owner changed; refresh before starting");
|
|
46
47
|
verifyProjectRuntime(runtime);
|
|
47
|
-
|
|
48
|
+
const sessionContract = readSessionContract(runtime.root);
|
|
49
|
+
writeProjectRuntimeState(project, { ...runtime, sessionContract }, instanceId, admitted);
|
|
48
50
|
});
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -43,7 +43,7 @@ export const BRIDGE_PROTOCOL_RELEASES = [
|
|
|
43
43
|
[14, "v0.12.16", "2026-10-09", "v0.12.16", "2026-10-09"],
|
|
44
44
|
[15, "v0.12.17", "2026-10-09", "v0.12.19", "2026-10-09"],
|
|
45
45
|
[16, "v0.12.20", "2026-10-09", "v0.25.0", "2026-11-01"],
|
|
46
|
-
[17, "v0.26.0", "2026-11-01", "v0.
|
|
46
|
+
[17, "v0.26.0", "2026-11-01", "v0.54.0", "2026-12-06"],
|
|
47
47
|
] as const;
|
|
48
48
|
|
|
49
49
|
export function bridgeWindowSettings(raw: unknown): BridgeWindowSettings {
|