@timurproko/a1 0.2.7-dev.792 → 0.2.7-dev.801

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.
Files changed (120) hide show
  1. package/dist/app/session-shell/clipboard-diagnostics.js +1 -1
  2. package/dist/app/session-shell/response-copy-helper.js +21 -6
  3. package/dist/app/session-shell/response-copy-protocol.d.ts +1 -1
  4. package/dist/app/session-shell/response-copy-transport.d.ts +3 -6
  5. package/dist/app/session-shell/response-copy-transport.js +60 -17
  6. package/dist/app/session-shell/session-shell-root.d.ts +2 -0
  7. package/dist/app/session-shell/session-shell-root.js +6 -1
  8. package/dist/app/session-shell/session-shell.d.ts +1 -0
  9. package/dist/app/session-shell/session-shell.js +22 -19
  10. package/dist/app/session-shell/shell-host.js +11 -0
  11. package/dist/cli/tabs.js +1 -1
  12. package/dist/composition/owned-ui.d.ts +1 -0
  13. package/dist/composition/owned-ui.js +16 -3
  14. package/dist/features/resident-tab/shortcut-declarations.d.ts +1 -1
  15. package/dist/features/resident-tab/shortcut-declarations.js +1 -0
  16. package/dist/foundation/launch-guardian/exit-watcher.d.ts +14 -0
  17. package/dist/foundation/launch-guardian/exit-watcher.js +94 -0
  18. package/dist/foundation/launch-guardian/main.d.ts +2 -1
  19. package/dist/foundation/launch-guardian/main.js +58 -6
  20. package/dist/foundation/process-containment/{native-guardian-containment.d.ts → addon-containment.d.ts} +7 -5
  21. package/dist/foundation/process-containment/addon-containment.js +139 -0
  22. package/dist/foundation/process-containment/addon-process-inspector.d.ts +11 -0
  23. package/dist/foundation/process-containment/addon-process-inspector.js +36 -0
  24. package/dist/foundation/process-containment/addon.d.ts +42 -0
  25. package/dist/foundation/process-containment/addon.js +57 -0
  26. package/dist/foundation/process-containment/artifact.d.ts +1 -1
  27. package/dist/foundation/process-containment/artifact.js +6 -5
  28. package/dist/foundation/process-containment/contracts.d.ts +2 -0
  29. package/dist/foundation/process-containment/index.d.ts +4 -4
  30. package/dist/foundation/process-containment/index.js +3 -3
  31. package/dist/foundation/process-containment/native-process-inspector.d.ts +2 -1
  32. package/dist/foundation/process-containment/native-process-inspector.js +10 -10
  33. package/dist/foundation/release/bootstrap.js +53 -16
  34. package/dist/foundation/release/index.d.ts +1 -1
  35. package/dist/foundation/release/index.js +1 -1
  36. package/dist/foundation/release/release-store.d.ts +12 -0
  37. package/dist/foundation/release/release-store.js +124 -2
  38. package/dist/foundation/resident-tabs/bounded-host-command.d.ts +3 -1
  39. package/dist/foundation/resident-tabs/bounded-host-command.js +6 -2
  40. package/dist/foundation/resident-tabs/bridge-client.d.ts +2 -0
  41. package/dist/foundation/resident-tabs/bridge-client.js +13 -0
  42. package/dist/foundation/resident-tabs/doctor.d.ts +0 -1
  43. package/dist/foundation/resident-tabs/doctor.js +4 -4
  44. package/dist/foundation/resident-tabs/ensure-terminal-host.d.ts +7 -2
  45. package/dist/foundation/resident-tabs/ensure-terminal-host.js +15 -11
  46. package/dist/foundation/resident-tabs/fixture-control.d.ts +7 -0
  47. package/dist/foundation/resident-tabs/fixture-control.js +35 -0
  48. package/dist/foundation/resident-tabs/host-entry.d.ts +1 -0
  49. package/dist/foundation/resident-tabs/host-entry.js +17 -0
  50. package/dist/foundation/resident-tabs/index.d.ts +2 -2
  51. package/dist/foundation/resident-tabs/index.js +1 -1
  52. package/dist/foundation/resident-tabs/maintenance.d.ts +5 -4
  53. package/dist/foundation/resident-tabs/maintenance.js +32 -17
  54. package/dist/foundation/resident-tabs/progress-observation.d.ts +7 -0
  55. package/dist/foundation/resident-tabs/progress-observation.js +119 -0
  56. package/dist/foundation/resident-tabs/release-holds.d.ts +3 -2
  57. package/dist/foundation/resident-tabs/release-holds.js +16 -7
  58. package/dist/foundation/resident-tabs/settings.d.ts +0 -1
  59. package/dist/foundation/resident-tabs/settings.js +1 -7
  60. package/dist/foundation/resident-tabs/terminal-host-artifact.d.ts +11 -15
  61. package/dist/foundation/resident-tabs/terminal-host-artifact.js +57 -32
  62. package/dist/foundation/session-writer-lock/index.d.ts +1 -3
  63. package/dist/foundation/session-writer-lock/index.js +8 -6
  64. package/dist/integrations/pi/components/shell-editor-autocomplete.js +2 -1
  65. package/dist/integrations/pi/components/shell-shared-facade.d.ts +2 -0
  66. package/dist/integrations/pi/engine/session-runtime.js +5 -2
  67. package/dist/integrations/pi/tui-runtime/damage-aware-terminal.d.ts +11 -0
  68. package/dist/integrations/pi/tui-runtime/damage-aware-terminal.js +30 -1
  69. package/dist/native/darwin-arm64/manifest.json +8 -6
  70. package/dist/native/darwin-arm64/process-guardian.node +0 -0
  71. package/dist/native/darwin-arm64/terminal-host-THIRD-PARTY-NOTICES.txt +1 -1
  72. package/dist/native/darwin-arm64/terminal-host.manifest.json +14 -13
  73. package/dist/native/darwin-arm64/terminal-host.node +0 -0
  74. package/dist/native/darwin-x64/manifest.json +9 -7
  75. package/dist/native/darwin-x64/process-guardian.node +0 -0
  76. package/dist/native/darwin-x64/terminal-host-THIRD-PARTY-NOTICES.txt +1 -1
  77. package/dist/native/darwin-x64/terminal-host.manifest.json +15 -14
  78. package/dist/native/darwin-x64/terminal-host.node +0 -0
  79. package/dist/native/linux-x64/manifest.json +8 -6
  80. package/dist/native/linux-x64/process-guardian.node +0 -0
  81. package/dist/native/linux-x64/terminal-host-THIRD-PARTY-NOTICES.txt +1 -1
  82. package/dist/native/linux-x64/terminal-host.manifest.json +14 -13
  83. package/dist/native/linux-x64/terminal-host.node +0 -0
  84. package/dist/native/win32-x64/manifest.json +8 -6
  85. package/dist/native/win32-x64/process-guardian.node +0 -0
  86. package/dist/native/win32-x64/terminal-host-THIRD-PARTY-NOTICES.txt +1 -1
  87. package/dist/native/win32-x64/terminal-host.manifest.json +14 -13
  88. package/dist/native/win32-x64/terminal-host.node +0 -0
  89. package/dist/product-identity.d.ts +3 -3
  90. package/dist/product-identity.js +3 -3
  91. package/dist/product-identity.json +9 -2
  92. package/dist/runtime-payload-inventory.json +1 -0
  93. package/dist/ui/settings/declarations.d.ts +0 -12
  94. package/dist/ui/settings/declarations.js +0 -10
  95. package/docs/architecture/boundaries.md +10 -9
  96. package/docs/architecture/process-guardian-provenance.md +17 -11
  97. package/docs/architecture/resident-tabs.md +46 -40
  98. package/docs/architecture/terminal-host-provenance.md +5 -3
  99. package/docs/architecture/toolchain.md +8 -6
  100. package/docs/ci-release-runbook.md +1 -1
  101. package/docs/openspec-archive-automation.md +23 -9
  102. package/docs/validation.md +6 -2
  103. package/package.json +6 -3
  104. package/dist/foundation/process-containment/darwin-process-inspector.d.ts +0 -5
  105. package/dist/foundation/process-containment/darwin-process-inspector.js +0 -7
  106. package/dist/foundation/process-containment/native-guardian-containment.js +0 -152
  107. package/dist/foundation/process-containment/windows-process-inspector.d.ts +0 -19
  108. package/dist/foundation/process-containment/windows-process-inspector.js +0 -56
  109. package/dist/native/darwin-arm64/a1_session_lock.node +0 -0
  110. package/dist/native/darwin-arm64/process-guardian +0 -0
  111. package/dist/native/darwin-arm64/terminal-host +0 -0
  112. package/dist/native/darwin-x64/a1_session_lock.node +0 -0
  113. package/dist/native/darwin-x64/process-guardian +0 -0
  114. package/dist/native/darwin-x64/terminal-host +0 -0
  115. package/dist/native/linux-x64/a1_session_lock.node +0 -0
  116. package/dist/native/linux-x64/process-guardian +0 -0
  117. package/dist/native/linux-x64/terminal-host +0 -0
  118. package/dist/native/win32-x64/a1_session_lock.node +0 -0
  119. package/dist/native/win32-x64/process-guardian.exe +0 -0
  120. package/dist/native/win32-x64/terminal-host.exe +0 -0
@@ -1,4 +1,4 @@
1
- export { ensureTerminalHost, resolveTerminalHostPath } from "./ensure-terminal-host.js";
1
+ export { ensureTerminalHost, resolveTerminalHostEntryPath, resolveTerminalHostPath } from "./ensure-terminal-host.js";
2
2
  export { readResidentTabLaunchSettings } from "./settings.js";
3
3
  export { selectResidentHost } from "./routing.js";
4
4
  export { readResidentReleaseHolds } from "./release-holds.js";
@@ -1,3 +1,4 @@
1
+ import { type TerminalHostCommand } from "./ensure-terminal-host.js";
1
2
  export type MaintenanceAction = "list" | "stop" | "stop-all" | "host-status" | "host-stop";
2
3
  export type MaintenanceHostState = "none" | "running" | "stopped" | "unresponsive" | "incompatible" | "refused" | "unverifiable" | "unavailable";
3
4
  /** The versioned `a1 tabs` report: `a1-tabs-maintenance-v1`, as printed by the terminal host. */
@@ -26,16 +27,16 @@ export interface MaintenanceOptions {
26
27
  readonly platform?: NodeJS.Platform;
27
28
  readonly architecture?: string;
28
29
  readonly timeoutMs?: number;
29
- readonly verify?: (executable: string, platform: NodeJS.Platform, architecture: string) => Promise<unknown>;
30
- readonly run?: (executable: string, arguments_: readonly string[], timeoutMs: number) => Promise<{
30
+ readonly verify?: (addon: string, platform: NodeJS.Platform, architecture: string) => Promise<unknown>;
31
+ readonly run?: (command: TerminalHostCommand, arguments_: readonly string[], timeoutMs: number) => Promise<{
31
32
  readonly code: number;
32
33
  readonly stdout: string;
33
34
  }>;
34
35
  }
35
36
  /**
36
37
  * Runs one maintenance form through a verified terminal host. When the running host speaks
37
- * another protocol generation, it retries once with the binary from the release that host
38
- * recorded, after verifying that release's manifest; it never runs an unverified binary.
38
+ * another protocol generation, it retries once with the addon from the release that host
39
+ * recorded, after verifying that release's manifest; it never loads an unverified addon.
39
40
  */
40
41
  export declare function runTerminalHostMaintenance(options: MaintenanceOptions): Promise<MaintenanceReport>;
41
42
  /** The largest maintenance report accepted from the terminal host. */
@@ -2,37 +2,38 @@ import { constants } from "node:fs";
2
2
  import { access } from "node:fs/promises";
3
3
  import { PRODUCT_IDENTITY } from "../../product-identity.js";
4
4
  import { runBoundedHostCommand } from "./bounded-host-command.js";
5
- import { resolveTerminalHostPath } from "./ensure-terminal-host.js";
5
+ import { resolveTerminalHostEntryPath, resolveTerminalHostPath } from "./ensure-terminal-host.js";
6
6
  import { verifyTerminalHostArtifact } from "./terminal-host-artifact.js";
7
7
  const INCOMPATIBLE_EXIT = 4;
8
8
  /**
9
9
  * Runs one maintenance form through a verified terminal host. When the running host speaks
10
- * another protocol generation, it retries once with the binary from the release that host
11
- * recorded, after verifying that release's manifest; it never runs an unverified binary.
10
+ * another protocol generation, it retries once with the addon from the release that host
11
+ * recorded, after verifying that release's manifest; it never loads an unverified addon.
12
12
  */
13
13
  export async function runTerminalHostMaintenance(options) {
14
14
  const platform = options.platform ?? process.platform;
15
15
  const architecture = options.architecture ?? process.arch;
16
- const executable = await firstVerifiedHost(options, options.releaseRoots, platform, architecture);
17
- if (executable === undefined)
16
+ const command = await firstVerifiedHost(options, options.releaseRoots, platform, architecture);
17
+ if (command === undefined)
18
18
  return unavailable(options.action, "no verified terminal host is installed");
19
- const report = await invoke(options, executable);
19
+ const report = await invoke(options, command);
20
20
  if (report.exitCode !== INCOMPATIBLE_EXIT || typeof report.releaseRoot !== "string")
21
21
  return report;
22
22
  const cohort = await firstVerifiedHost({ ...options, environment: {} }, [report.releaseRoot], platform, architecture);
23
- if (cohort === undefined || cohort === executable) {
23
+ if (cohort === undefined || cohort.entry === command.entry) {
24
24
  return { ...report, message: "the running tabs use another version whose terminal host cannot be verified" };
25
25
  }
26
- return await invoke(options, cohort);
26
+ return await invoke({ ...options, environment: installedEnvironment(options.environment) }, cohort);
27
27
  }
28
28
  function arguments_(options) {
29
29
  const command = options.action === "stop" ? ["stop", options.tabId ?? ""] : [options.action];
30
30
  return ["tabs", ...command, "--profile", options.profileRoot, "--data-dir", options.dataDir, "--runtime-dir", options.runtimeDir];
31
31
  }
32
- async function invoke(options, executable) {
32
+ async function invoke(options, command) {
33
33
  const timeoutMs = options.timeoutMs ?? 120_000;
34
34
  try {
35
- const result = await (options.run ?? runHost)(executable, arguments_(options), timeoutMs);
35
+ const run = options.run ?? ((host, argumentsValue, limit) => runHost(host, argumentsValue, limit, options.environment));
36
+ const result = await run(command, arguments_(options), timeoutMs);
36
37
  const line = result.stdout.trim().split(/\r?\n/u).at(-1) ?? "";
37
38
  const parsed = JSON.parse(line);
38
39
  if (parsed.schema !== "a1-tabs-maintenance-v1" || typeof parsed.host !== "string")
@@ -48,19 +49,22 @@ async function firstVerifiedHost(options, roots, platform, architecture) {
48
49
  ? options.environment[PRODUCT_IDENTITY.environment.terminalHostPath]?.trim()
49
50
  : undefined;
50
51
  if (override) {
52
+ const entry = roots[0] === undefined ? undefined : resolveTerminalHostEntryPath(roots[0]);
53
+ if (entry === undefined)
54
+ return undefined;
51
55
  try {
52
- await access(override, constants.R_OK | (platform === "win32" ? 0 : constants.X_OK));
53
- return override;
56
+ await Promise.all([access(override, constants.R_OK), access(entry, constants.R_OK)]);
57
+ return { executable: process.execPath, entry };
54
58
  }
55
59
  catch {
56
60
  return undefined;
57
61
  }
58
62
  }
59
63
  for (const root of roots) {
60
- const candidate = resolveTerminalHostPath(root, {}, platform, architecture);
64
+ const addon = resolveTerminalHostPath(root, {}, platform, architecture);
61
65
  try {
62
- await (options.verify ?? verifyTerminalHostArtifact)(candidate, platform, architecture);
63
- return candidate;
66
+ await (options.verify ?? verifyTerminalHostArtifact)(addon, platform, architecture);
67
+ return { executable: process.execPath, entry: resolveTerminalHostEntryPath(root) };
64
68
  }
65
69
  catch {
66
70
  // Rationale: an older retained release may predate the packaged host; try the next one.
@@ -68,11 +72,22 @@ async function firstVerifiedHost(options, roots, platform, architecture) {
68
72
  }
69
73
  return undefined;
70
74
  }
75
+ function installedEnvironment(environment) {
76
+ const sanitized = { ...environment };
77
+ delete sanitized[PRODUCT_IDENTITY.environment.developmentInstanceId];
78
+ delete sanitized[PRODUCT_IDENTITY.environment.terminalHostPath];
79
+ return sanitized;
80
+ }
71
81
  function unavailable(action, message) {
72
82
  return { schema: "a1-tabs-maintenance-v1", command: action, host: "unavailable", message, exitCode: 3 };
73
83
  }
74
84
  /** The largest maintenance report accepted from the terminal host. */
75
85
  export const MAX_MAINTENANCE_REPORT_BYTES = 4 * 1024 * 1024;
76
- async function runHost(executable, arguments_, timeoutMs) {
77
- return await runBoundedHostCommand(executable, arguments_, { maxStdoutBytes: MAX_MAINTENANCE_REPORT_BYTES, timeoutMs, label: "terminal host maintenance" });
86
+ async function runHost(command, arguments_, timeoutMs, environment) {
87
+ return await runBoundedHostCommand(command, arguments_, {
88
+ environment,
89
+ maxStdoutBytes: MAX_MAINTENANCE_REPORT_BYTES,
90
+ timeoutMs,
91
+ label: "terminal host maintenance",
92
+ });
78
93
  }
@@ -0,0 +1,7 @@
1
+ export interface ResidentProgressObserverPort {
2
+ readonly tabId: string;
3
+ engineDelivery(event: unknown): void;
4
+ childRenderWrite(bytes: number, fragments: number, transaction: "synchronized-output" | "ordinary", frameId?: number, renderCause?: string): void;
5
+ }
6
+ /** Returns the opt-in payload-free observer for a resident child, or null on ordinary launches. */
7
+ export declare function residentProgressObserver(environment?: NodeJS.ProcessEnv): ResidentProgressObserverPort | null;
@@ -0,0 +1,119 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { appendFile, mkdir } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { performance } from "node:perf_hooks";
5
+ import { PRODUCT_IDENTITY } from "../../product-identity.js";
6
+ const OBSERVATION_DIRECTORY_ENV = PRODUCT_IDENTITY.environment.residentProgressObservationDir;
7
+ const OBSERVATION_RUN_ENV = PRODUCT_IDENTITY.environment.residentProgressRunId;
8
+ const MAX_PENDING_BYTES = 256 * 1024;
9
+ class ResidentProgressObserver {
10
+ #directory;
11
+ #runId;
12
+ #tabId;
13
+ #incarnation;
14
+ #processInstance;
15
+ #path;
16
+ #sequence = 0;
17
+ #engineSequence = 0;
18
+ #pendingBytes = 0;
19
+ #lost = 0;
20
+ #writing = Promise.resolve();
21
+ #failed = false;
22
+ get tabId() { return this.#tabId; }
23
+ constructor(directory, runId, tabId, incarnation) {
24
+ this.#directory = directory;
25
+ this.#runId = runId;
26
+ this.#tabId = tabId;
27
+ this.#incarnation = incarnation;
28
+ this.#processInstance = `${process.pid}-${randomUUID()}`;
29
+ this.#path = join(directory, `child-${this.#processInstance}.jsonl`);
30
+ }
31
+ engineDelivery(event) {
32
+ this.#engineSequence += 1;
33
+ this.#observe("engine-delivery", {
34
+ eventSequence: this.#engineSequence,
35
+ eventKind: eventKind(event),
36
+ count: 1,
37
+ });
38
+ }
39
+ childRenderWrite(bytes, fragments, transaction, frameId, renderCause) {
40
+ this.#observe("child-render-write", {
41
+ eventSequence: this.#engineSequence,
42
+ bytes,
43
+ count: 1,
44
+ fragmentCount: fragments,
45
+ transactionKind: transaction,
46
+ ...(frameId === undefined ? {} : { frameId }),
47
+ ...(renderCause === undefined ? {} : { renderCause }),
48
+ });
49
+ }
50
+ #observe(stage, fields) {
51
+ if (this.#failed)
52
+ return;
53
+ const lostBefore = this.#lost;
54
+ const record = {
55
+ schema: "a1-resident-progress-observation-v1",
56
+ runId: this.#runId,
57
+ role: "child",
58
+ stage,
59
+ pid: process.pid,
60
+ processInstance: this.#processInstance,
61
+ timestampUnixUs: Math.round((performance.timeOrigin + performance.now()) * 1_000),
62
+ // Rationale: timeOrigin is calibrated to the Unix epoch; retain a conservative cross-process error.
63
+ clockErrorUs: 1_000,
64
+ sequence: ++this.#sequence,
65
+ tabId: this.#tabId,
66
+ incarnation: this.#incarnation,
67
+ lostBefore,
68
+ ...fields,
69
+ };
70
+ const line = `${JSON.stringify(record)}\n`;
71
+ const length = Buffer.byteLength(line);
72
+ if (this.#pendingBytes + length > MAX_PENDING_BYTES) {
73
+ this.#lost = lostBefore + 1;
74
+ return;
75
+ }
76
+ this.#lost = 0;
77
+ this.#pendingBytes += length;
78
+ this.#writing = this.#writing.then(async () => {
79
+ await mkdir(this.#directory, { recursive: true });
80
+ await appendFile(this.#path, line, "utf8");
81
+ }).catch(() => {
82
+ this.#failed = true;
83
+ }).finally(() => {
84
+ this.#pendingBytes -= length;
85
+ });
86
+ }
87
+ }
88
+ let observer;
89
+ /** Returns the opt-in payload-free observer for a resident child, or null on ordinary launches. */
90
+ export function residentProgressObserver(environment = process.env) {
91
+ if (environment === process.env && observer !== undefined)
92
+ return observer;
93
+ const directory = environment[OBSERVATION_DIRECTORY_ENV];
94
+ const runId = environment[OBSERVATION_RUN_ENV];
95
+ const tabId = environment[PRODUCT_IDENTITY.environment.residentProgressTabId];
96
+ const incarnation = Number(environment[PRODUCT_IDENTITY.environment.residentProgressTabIncarnation]);
97
+ const value = directory && runId && runId.length <= 128 && tabId && Number.isSafeInteger(incarnation) && incarnation >= 0
98
+ ? new ResidentProgressObserver(directory, runId, tabId, incarnation)
99
+ : null;
100
+ if (environment === process.env) {
101
+ observer = value;
102
+ // Security: test evidence paths and tab identity are not child/tool configuration. Retain them only in
103
+ // this observer instance so extensions and spawned tools cannot append to the fixture trace.
104
+ for (const name of [
105
+ OBSERVATION_DIRECTORY_ENV,
106
+ OBSERVATION_RUN_ENV,
107
+ PRODUCT_IDENTITY.environment.residentProgressTabId,
108
+ PRODUCT_IDENTITY.environment.residentProgressTabIncarnation,
109
+ ])
110
+ delete process.env[name];
111
+ }
112
+ return value;
113
+ }
114
+ function eventKind(event) {
115
+ if (typeof event !== "object" || event === null)
116
+ return "unknown";
117
+ const value = event.type;
118
+ return typeof value === "string" && /^[a-z][a-z0-9_-]{0,63}$/iu.test(value) ? value : "unknown";
119
+ }
@@ -1,3 +1,4 @@
1
+ import { type TerminalHostCommand } from "./ensure-terminal-host.js";
1
2
  export interface ResidentReleaseHoldReport {
2
3
  /** False when any resident record or identity could not be verified; callers then keep every release. */
3
4
  readonly complete: boolean;
@@ -11,8 +12,8 @@ export interface ResidentReleaseHoldOptions {
11
12
  readonly platform?: NodeJS.Platform;
12
13
  readonly architecture?: string;
13
14
  readonly timeoutMs?: number;
14
- readonly verify?: (executable: string, platform: NodeJS.Platform, architecture: string) => Promise<unknown>;
15
- readonly run?: (executable: string, arguments_: readonly string[], timeoutMs: number) => Promise<{
15
+ readonly verify?: (addon: string, platform: NodeJS.Platform, architecture: string) => Promise<unknown>;
16
+ readonly run?: (command: TerminalHostCommand, arguments_: readonly string[], timeoutMs: number) => Promise<{
16
17
  readonly code: number;
17
18
  readonly stdout: string;
18
19
  }>;
@@ -1,7 +1,8 @@
1
1
  import { readdir, stat } from "node:fs/promises";
2
2
  import { resolve } from "node:path";
3
+ import { PRODUCT_IDENTITY } from "../../product-identity.js";
3
4
  import { runBoundedHostCommand } from "./bounded-host-command.js";
4
- import { resolveTerminalHostPath } from "./ensure-terminal-host.js";
5
+ import { resolveTerminalHostEntryPath, resolveTerminalHostPath } from "./ensure-terminal-host.js";
5
6
  import { verifyTerminalHostArtifact } from "./terminal-host-artifact.js";
6
7
  const COMPLETE_EMPTY = Object.freeze({ complete: true, releaseRoots: Object.freeze([]), uncertain: Object.freeze([]) });
7
8
  /**
@@ -15,22 +16,22 @@ export async function readResidentReleaseHolds(options) {
15
16
  const platform = options.platform ?? process.platform;
16
17
  const architecture = options.architecture ?? process.arch;
17
18
  const verify = options.verify ?? verifyTerminalHostArtifact;
18
- let executable;
19
+ let command;
19
20
  for (const root of options.releaseRoots) {
20
21
  const candidate = resolveTerminalHostPath(root, {}, platform, architecture);
21
22
  try {
22
23
  await verify(candidate, platform, architecture);
23
- executable = candidate;
24
+ command = { executable: process.execPath, entry: resolveTerminalHostEntryPath(root) };
24
25
  break;
25
26
  }
26
27
  catch {
27
28
  // Rationale: an older release may predate the packaged host; another retained release may still carry it.
28
29
  }
29
30
  }
30
- if (!executable)
31
+ if (!command)
31
32
  return incomplete("no verified terminal host is installed to inspect resident records");
32
33
  try {
33
- const result = await (options.run ?? runHost)(executable, ["release-holds", "--data-dir", options.dataDir], options.timeoutMs ?? 5_000);
34
+ const result = await (options.run ?? runHost)(command, ["release-holds", "--data-dir", options.dataDir], options.timeoutMs ?? 5_000);
34
35
  const report = JSON.parse(result.stdout.trim().split(/\r?\n/u).at(-1) ?? "");
35
36
  if (result.code !== 0 || report.schema !== "a1-resident-release-holds-v1" || typeof report.complete !== "boolean"
36
37
  || !isStringArray(report.releaseRoots) || !isStringArray(report.uncertain)) {
@@ -72,6 +73,14 @@ function isStringArray(value) {
72
73
  }
73
74
  /** The largest release-hold report accepted from the terminal host. */
74
75
  export const MAX_RELEASE_HOLD_REPORT_BYTES = 1024 * 1024;
75
- async function runHost(executable, arguments_, timeoutMs) {
76
- return await runBoundedHostCommand(executable, arguments_, { maxStdoutBytes: MAX_RELEASE_HOLD_REPORT_BYTES, timeoutMs, label: "terminal host release-hold inspection" });
76
+ async function runHost(command, arguments_, timeoutMs) {
77
+ const environment = { ...process.env };
78
+ delete environment[PRODUCT_IDENTITY.environment.developmentInstanceId];
79
+ delete environment[PRODUCT_IDENTITY.environment.terminalHostPath];
80
+ return await runBoundedHostCommand(command, arguments_, {
81
+ environment,
82
+ maxStdoutBytes: MAX_RELEASE_HOLD_REPORT_BYTES,
83
+ timeoutMs,
84
+ label: "terminal host release-hold inspection",
85
+ });
77
86
  }
@@ -3,7 +3,6 @@ export declare const RESIDENT_TABS_MAX_CONCURRENT_STARTS_CAP = 8;
3
3
  export declare const RESIDENT_TABS_PREWARM_COUNT = 1;
4
4
  export declare const RESIDENT_TABS_PREWARM_CAP = 1;
5
5
  export interface ResidentTabLaunchSettings {
6
- readonly tabsMax: number;
7
6
  readonly tabsAutoName: boolean;
8
7
  readonly maxConcurrentStarts: number;
9
8
  readonly prewarmCount: number;
@@ -7,7 +7,6 @@ export const RESIDENT_TABS_MAX_CONCURRENT_STARTS_CAP = 8;
7
7
  export const RESIDENT_TABS_PREWARM_COUNT = 1;
8
8
  export const RESIDENT_TABS_PREWARM_CAP = 1;
9
9
  const DEFAULTS = Object.freeze({
10
- tabsMax: 10,
11
10
  tabsAutoName: true,
12
11
  maxConcurrentStarts: RESIDENT_TABS_MAX_CONCURRENT_STARTS,
13
12
  prewarmCount: RESIDENT_TABS_PREWARM_COUNT,
@@ -46,17 +45,12 @@ export async function readResidentTabLaunchSettings(profileDir, namespace = "a1"
46
45
  }
47
46
  function resolveLaunchValues(document, migrations) {
48
47
  const resolution = resolveOwnedUiSettings({
49
- declarations: [
50
- OWNED_SETTING_DECLARATIONS.tabsMax,
51
- OWNED_SETTING_DECLARATIONS.tabsAutoName,
52
- ],
48
+ declarations: [OWNED_SETTING_DECLARATIONS.tabsAutoName],
53
49
  migrations,
54
50
  document,
55
51
  currentVersion: OWNED_UI_SETTINGS_VERSION,
56
52
  });
57
- const tabsMax = document.values?.["tabsMax"] ?? settingValue(resolution, "tabsMax");
58
53
  return {
59
- tabsMax: typeof tabsMax === "number" && Number.isFinite(tabsMax) ? Math.max(1, Math.min(50, Math.trunc(tabsMax))) : DEFAULTS.tabsMax,
60
54
  tabsAutoName: settingValue(resolution, "tabsAutoName") === true,
61
55
  maxConcurrentStarts: RESIDENT_TABS_MAX_CONCURRENT_STARTS,
62
56
  prewarmCount: RESIDENT_TABS_PREWARM_COUNT,
@@ -1,18 +1,14 @@
1
1
  export declare const TERMINAL_HOST_MANIFEST_FILENAME = "terminal-host.manifest.json";
2
- export declare const TERMINAL_HOST_GENERATION = 1;
3
- export type TerminalHostArtifactCode = "TERMINAL_HOST_ARTIFACT_MISSING" | "TERMINAL_HOST_ARTIFACT_INCOMPATIBLE" | "TERMINAL_HOST_ARTIFACT_UNSUPPORTED" | "TERMINAL_HOST_ARTIFACT_TAMPERED";
4
- export interface VerifiedTerminalHostArtifact {
5
- readonly executable: string;
6
- readonly sessionLock: string;
7
- readonly generation: number;
8
- }
2
+ export type TerminalHostArtifactErrorCode = "TERMINAL_HOST_ARTIFACT_MISSING" | "TERMINAL_HOST_ARTIFACT_TAMPERED" | "TERMINAL_HOST_ARTIFACT_INCOMPATIBLE" | "TERMINAL_HOST_ARTIFACT_UNSUPPORTED";
9
3
  export declare class TerminalHostArtifactError extends Error {
10
- readonly code: TerminalHostArtifactCode;
11
- constructor(message: string, code: TerminalHostArtifactCode);
4
+ readonly code: TerminalHostArtifactErrorCode;
5
+ readonly manifestPath: string;
6
+ constructor(code: TerminalHostArtifactErrorCode, manifestPath: string, message: string);
7
+ }
8
+ export interface VerifiedTerminalHostArtifact {
9
+ readonly addon: string;
10
+ readonly entry: string;
11
+ readonly generation: 1;
12
12
  }
13
- /**
14
- * Verifies a release's terminal host and its session-writer lock against their manifest before
15
- * anything executes or loads them: schema, generation, platform, architecture, file names, sizes,
16
- * and SHA-256 digests.
17
- */
18
- export declare function verifyTerminalHostArtifact(executable: string, platform?: NodeJS.Platform, architecture?: string, generation?: number): Promise<VerifiedTerminalHostArtifact>;
13
+ /** Verifies every runtime file certified by the terminal-host v2 manifest before Node loads it. */
14
+ export declare function verifyTerminalHostArtifact(addonPath: string, platform?: NodeJS.Platform, architecture?: string): Promise<VerifiedTerminalHostArtifact>;
@@ -1,53 +1,78 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { readFile, stat } from "node:fs/promises";
3
3
  import { basename, dirname, resolve } from "node:path";
4
+ import { PRODUCT_IDENTITY } from "../../product-identity.js";
4
5
  export const TERMINAL_HOST_MANIFEST_FILENAME = "terminal-host.manifest.json";
5
- export const TERMINAL_HOST_GENERATION = 1;
6
+ const SCHEMA = "a1-terminal-host-artifact-v2";
7
+ const GENERATION = 1;
8
+ const NODE_API = 9;
9
+ const NOTICES_NAME = "terminal-host-THIRD-PARTY-NOTICES.txt";
6
10
  export class TerminalHostArtifactError extends Error {
7
11
  code;
8
- constructor(message, code) {
12
+ manifestPath;
13
+ constructor(code, manifestPath, message) {
9
14
  super(message);
10
15
  this.name = "TerminalHostArtifactError";
11
16
  this.code = code;
17
+ this.manifestPath = manifestPath;
12
18
  }
13
19
  }
14
- /**
15
- * Verifies a release's terminal host and its session-writer lock against their manifest before
16
- * anything executes or loads them: schema, generation, platform, architecture, file names, sizes,
17
- * and SHA-256 digests.
18
- */
19
- export async function verifyTerminalHostArtifact(executable, platform = process.platform, architecture = process.arch, generation = TERMINAL_HOST_GENERATION) {
20
- const directory = dirname(executable);
20
+ /** Verifies every runtime file certified by the terminal-host v2 manifest before Node loads it. */
21
+ export async function verifyTerminalHostArtifact(addonPath, platform = process.platform, architecture = process.arch) {
22
+ const directory = dirname(addonPath);
23
+ const releaseRoot = resolve(directory, "../../..");
24
+ const manifestPath = resolve(directory, TERMINAL_HOST_MANIFEST_FILENAME);
21
25
  let manifest;
22
26
  try {
23
- manifest = JSON.parse(await readFile(resolve(directory, TERMINAL_HOST_MANIFEST_FILENAME), "utf8"));
27
+ const parsed = JSON.parse(await readFile(manifestPath, "utf8"));
28
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
29
+ throw new TypeError("terminal host manifest is not an object");
30
+ manifest = parsed;
24
31
  }
25
32
  catch (error) {
26
- throw new TerminalHostArtifactError(`terminal host manifest is missing or malformed: ${errorMessage(error)}`, "TERMINAL_HOST_ARTIFACT_MISSING");
33
+ const code = error instanceof Error && "code" in error && error.code === "ENOENT"
34
+ ? "TERMINAL_HOST_ARTIFACT_MISSING"
35
+ : "TERMINAL_HOST_ARTIFACT_INCOMPATIBLE";
36
+ throw new TerminalHostArtifactError(code, manifestPath, "terminal host manifest is missing or invalid");
27
37
  }
28
- if (manifest.schema !== "a1-terminal-host-artifact-v1" || manifest.protocolVersion !== 1 || manifest.generation !== generation
29
- || manifest.platform !== platform || manifest.architecture !== architecture
30
- || manifest.artifact?.filename !== basename(executable) || typeof manifest.sessionLock?.filename !== "string"
31
- || basename(manifest.sessionLock.filename) !== manifest.sessionLock.filename) {
32
- throw new TerminalHostArtifactError("terminal host manifest is incompatible with this platform or generation", "TERMINAL_HOST_ARTIFACT_INCOMPATIBLE");
38
+ if (manifest.capability === "unsupported") {
39
+ throw new TerminalHostArtifactError("TERMINAL_HOST_ARTIFACT_UNSUPPORTED", manifestPath, "terminal host is unsupported on this platform");
33
40
  }
34
- if (manifest.capability !== "supported") {
35
- throw new TerminalHostArtifactError(`resident tabs are not supported on ${platform}-${architecture}`, "TERMINAL_HOST_ARTIFACT_UNSUPPORTED");
41
+ if (manifest.schema !== SCHEMA || manifest.kind !== "node-addon" || manifest.nodeApi !== NODE_API
42
+ || manifest.protocolVersion !== 1 || manifest.generation !== GENERATION
43
+ || manifest.platform !== platform || manifest.architecture !== architecture || manifest.capability !== "supported"
44
+ || !validRecord(manifest.artifact) || !validRecord(manifest.entry) || !validRecord(manifest.notices)
45
+ || manifest.artifact.filename !== `${PRODUCT_IDENTITY.artifacts.terminalHostAddon}.node`
46
+ || manifest.entry.filename !== `dist/foundation/resident-tabs/${PRODUCT_IDENTITY.artifacts.terminalHostEntry}.js`
47
+ || manifest.notices.filename !== NOTICES_NAME
48
+ || basename(addonPath) !== manifest.artifact.filename) {
49
+ throw new TerminalHostArtifactError("TERMINAL_HOST_ARTIFACT_INCOMPATIBLE", manifestPath, "terminal host manifest is incompatible");
36
50
  }
37
- const sessionLock = resolve(directory, manifest.sessionLock.filename);
38
- await verifyFile(executable, manifest.artifact, "terminal host");
39
- await verifyFile(sessionLock, manifest.sessionLock, "session-writer lock");
40
- return { executable, sessionLock, generation: manifest.generation };
51
+ const entry = resolve(releaseRoot, manifest.entry.filename);
52
+ await verifyFile(addonPath, manifest.artifact, manifestPath);
53
+ await verifyFile(entry, manifest.entry, manifestPath);
54
+ await verifyFile(resolve(directory, manifest.notices.filename), manifest.notices, manifestPath);
55
+ return { addon: addonPath, entry, generation: 1 };
41
56
  }
42
- async function verifyFile(path, expected, label) {
43
- const [bytes, metadata] = await Promise.all([readFile(path), stat(path)]).catch((error) => {
44
- throw new TerminalHostArtifactError(`${label} artifact is unavailable: ${errorMessage(error)}`, "TERMINAL_HOST_ARTIFACT_MISSING");
45
- });
46
- const digest = createHash("sha256").update(bytes).digest("hex");
47
- if (metadata.size !== expected.size || digest !== expected.sha256) {
48
- throw new TerminalHostArtifactError(`${label} artifact integrity verification failed`, "TERMINAL_HOST_ARTIFACT_TAMPERED");
49
- }
57
+ function validRecord(value) {
58
+ return typeof value === "object" && value !== null
59
+ && typeof value.filename === "string"
60
+ && /^[a-f0-9]{64}$/u.test(value.sha256)
61
+ && Number.isSafeInteger(value.size) && value.size >= 0;
50
62
  }
51
- function errorMessage(error) {
52
- return error instanceof Error ? error.message : String(error);
63
+ async function verifyFile(path, record, manifestPath) {
64
+ let bytes;
65
+ let metadata;
66
+ try {
67
+ [bytes, metadata] = await Promise.all([readFile(path), stat(path)]);
68
+ }
69
+ catch (error) {
70
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
71
+ throw new TerminalHostArtifactError("TERMINAL_HOST_ARTIFACT_MISSING", manifestPath, `certified terminal host file is missing: ${record.filename}`);
72
+ }
73
+ throw error;
74
+ }
75
+ if (!metadata.isFile() || bytes.byteLength !== record.size || createHash("sha256").update(bytes).digest("hex") !== record.sha256) {
76
+ throw new TerminalHostArtifactError("TERMINAL_HOST_ARTIFACT_TAMPERED", manifestPath, `certified terminal host file failed verification: ${record.filename}`);
77
+ }
53
78
  }
@@ -19,9 +19,7 @@ export interface SessionWriterHandle {
19
19
  bind(createdPath?: string): void;
20
20
  release(): void;
21
21
  }
22
- /** Development-only override naming a native lock addon to load first. */
23
- export declare const SESSION_LOCK_OVERRIDE_ENVIRONMENT = "A1_SESSION_LOCK_PATH";
24
- /** Security: a release that carries its own lock never loads an addon chosen by the environment or cwd. */
22
+ /** Security: a release that carries its own terminal-host addon never loads one chosen by cwd. */
25
23
  export declare function nativeCandidates(moduleUrl?: string, env?: NodeJS.ProcessEnv, cwd?: string, exists?: typeof existsSync): string[];
26
24
  export declare function acquireExisting(path: string): SessionWriterHandle;
27
25
  export declare function reserveNew(parent: string, name: string): SessionWriterHandle;
@@ -18,15 +18,17 @@ export class SessionWriterConflict extends Error {
18
18
  }
19
19
  let backendOverride;
20
20
  let cachedBackend;
21
- /** Development-only override naming a native lock addon to load first. */
22
- export const SESSION_LOCK_OVERRIDE_ENVIRONMENT = "A1_SESSION_LOCK_PATH";
23
- /** Security: a release that carries its own lock never loads an addon chosen by the environment or cwd. */
21
+ /** Security: a release that carries its own terminal-host addon never loads one chosen by cwd. */
24
22
  export function nativeCandidates(moduleUrl = import.meta.url, env = process.env, cwd = process.cwd(), exists = existsSync) {
25
- const addon = "a1_session_lock.node";
23
+ const addon = `${PRODUCT_IDENTITY.artifacts.terminalHostAddon}.node`;
26
24
  // Invariant: this module sits at dist/foundation/session-writer-lock/ inside the release root.
27
25
  const own = resolve(fileURLToPath(new URL("../../../", moduleUrl)), "dist", "native", `${process.platform}-${process.arch}`, addon);
28
- const override = env[PRODUCT_IDENTITY.environment.developmentInstanceId] ? env[SESSION_LOCK_OVERRIDE_ENVIRONMENT]?.trim() || undefined : undefined;
29
- const local = exists(own) ? [own] : [resolve(cwd, "dist", "native", `${process.platform}-${process.arch}`, addon), resolve(cwd, ".artifacts", "terminal-host", addon)];
26
+ const override = env[PRODUCT_IDENTITY.environment.developmentInstanceId]
27
+ ? env[PRODUCT_IDENTITY.environment.terminalHostPath]?.trim() || undefined
28
+ : undefined;
29
+ const local = exists(own)
30
+ ? [own]
31
+ : [resolve(cwd, "dist", "native", `${process.platform}-${process.arch}`, addon), resolve(cwd, ".artifacts", "terminal-host", addon)];
30
32
  return override ? [override, ...local] : local;
31
33
  }
32
34
  function loadNativeBackend() {
@@ -143,7 +143,8 @@ export function createPiShellEditor(options) {
143
143
  tui.requestRender();
144
144
  };
145
145
  let autocompleteProvider;
146
- const builtInCatalog = options.keybindingProfile === "a1" ? OWNED_BUILTIN_SLASH_COMMANDS : PINNED_PI_BUILTIN_SLASH_COMMANDS;
146
+ const builtInCatalog = (options.keybindingProfile === "a1" ? OWNED_BUILTIN_SLASH_COMMANDS : PINNED_PI_BUILTIN_SLASH_COMMANDS)
147
+ .filter(command => !options.hideSettingsCommand || command.name !== "settings");
147
148
  const setAutocompleteCommands = (installed) => {
148
149
  // Invariant: collapse is a bare-A1 presentation; the comparison profile installs the pinned list.
149
150
  const collapsed = options.keybindingProfile === "a1" && options.skillsPresentation?.() === "collapse"
@@ -164,6 +164,8 @@ export interface PiShellEditorOptions {
164
164
  readonly historyEditor?: HistoryEditorConstructor;
165
165
  /** Bare A1 adds ergonomic aliases while comparison profiles retain Pi defaults. */
166
166
  readonly keybindingProfile?: "pi" | "a1";
167
+ /** Resident Agents expose Settings through the global tab instead of a slash command. */
168
+ readonly hideSettingsCommand?: boolean;
167
169
  /** The process's shared keybindings; its profile must match `keybindingProfile`. */
168
170
  readonly keybindings?: PiKeybindingsHost;
169
171
  readonly getColumns: () => number;
@@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
2
2
  import { existsSync } from "node:fs";
3
3
  import { promisify } from "node:util";
4
4
  import { PRODUCT_IDENTITY } from "../../../product-identity.js";
5
+ import { residentProgressObserver } from "../../../foundation/resident-tabs/progress-observation.js";
5
6
  import { observeCompactionProgress } from "./compaction-progress.js";
6
7
  import { createPiRuntimeIntegration } from "./runtime-integration.js";
7
8
  import { PiSessionCommandIntegration } from "./session-integration.js";
@@ -369,8 +370,10 @@ export class PiEngineRuntime {
369
370
  return;
370
371
  const generation = this.#sessionGeneration;
371
372
  this.#unsubscribe = session.subscribe(event => {
372
- if (generation === this.#sessionGeneration && !this.#ports.disposed())
373
- this.#ports.event(event);
373
+ if (generation !== this.#sessionGeneration || this.#ports.disposed())
374
+ return;
375
+ residentProgressObserver()?.engineDelivery(event);
376
+ this.#ports.event(event);
374
377
  });
375
378
  }
376
379
  /**
@@ -52,6 +52,17 @@ export interface DamageAwareTerminalOptions {
52
52
  };
53
53
  readonly onResize?: () => void;
54
54
  readonly onHyperlinkCleanupRequired?: () => void;
55
+ /** Exact-artifact fault controls evaluated before physical writes; absent in ordinary sessions. */
56
+ readonly allowWrite?: () => boolean;
57
+ readonly writeChunks?: (data: string) => readonly string[];
58
+ /** Optional payload-free observation after a terminal write returns. */
59
+ readonly onWrite?: (metadata: {
60
+ readonly bytes: number;
61
+ readonly fragments: number;
62
+ readonly transaction: "synchronized-output" | "ordinary";
63
+ readonly frameId?: number;
64
+ readonly cause?: string;
65
+ }) => void;
55
66
  }
56
67
  /**
57
68
  * A fail-closed adapter for one pinned Pi fullscreen write grammar. Semantic