@timurproko/a1 0.1.1-dev.5 → 0.1.1-dev.7

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 (151) hide show
  1. package/README.md +32 -9
  2. package/bin/a1-guardian.js +22 -0
  3. package/bin/a1-ui.js +7 -4
  4. package/dist/native/darwin-arm64/a1-process-guardian +0 -0
  5. package/dist/native/darwin-arm64/manifest.json +20 -0
  6. package/dist/native/linux-x64/a1-process-guardian +0 -0
  7. package/dist/native/linux-x64/manifest.json +20 -0
  8. package/dist/native/win32-x64/a1-process-guardian.exe +0 -0
  9. package/dist/native/win32-x64/manifest.json +20 -0
  10. package/dist/src/composition/index.d.ts +26 -0
  11. package/dist/src/composition/index.js +88 -2
  12. package/dist/src/features/launch/runtime-selection.d.ts +2 -1
  13. package/dist/src/features/launch/runtime-selection.js +2 -2
  14. package/dist/src/features/owned-ui/index.d.ts +1 -0
  15. package/dist/src/features/owned-ui/index.js +1 -0
  16. package/dist/src/features/owned-ui/run.d.ts +6 -0
  17. package/dist/src/features/owned-ui/run.js +3 -1
  18. package/dist/src/features/owned-ui/settings-app.d.ts +22 -0
  19. package/dist/src/features/owned-ui/settings-app.js +631 -0
  20. package/dist/src/foundation/agent-engine-contracts/domain.d.ts +26 -0
  21. package/dist/src/foundation/launch-guardian/index.d.ts +1 -0
  22. package/dist/src/foundation/launch-guardian/index.js +1 -0
  23. package/dist/src/foundation/launch-guardian/main.d.ts +31 -0
  24. package/dist/src/foundation/launch-guardian/main.js +165 -0
  25. package/dist/src/foundation/lifecycle/commands.d.ts +40 -0
  26. package/dist/src/foundation/lifecycle/commands.js +1 -0
  27. package/dist/src/foundation/lifecycle/index.d.ts +2 -0
  28. package/dist/src/foundation/lifecycle/index.js +2 -0
  29. package/dist/src/foundation/lifecycle/launch-instance.d.ts +46 -0
  30. package/dist/src/foundation/lifecycle/launch-instance.js +134 -0
  31. package/dist/src/foundation/lifecycle/model.d.ts +6 -42
  32. package/dist/src/foundation/owned-ui-settings/declarations.d.ts +13 -0
  33. package/dist/src/foundation/owned-ui-settings/declarations.js +39 -0
  34. package/dist/src/foundation/owned-ui-settings/index.d.ts +6 -0
  35. package/dist/src/foundation/owned-ui-settings/index.js +6 -0
  36. package/dist/src/foundation/owned-ui-settings/migrations.d.ts +13 -0
  37. package/dist/src/foundation/owned-ui-settings/migrations.js +28 -0
  38. package/dist/src/foundation/owned-ui-settings/resolution.d.ts +45 -0
  39. package/dist/src/foundation/owned-ui-settings/resolution.js +147 -0
  40. package/dist/src/foundation/owned-ui-settings/sections.d.ts +70 -0
  41. package/dist/src/foundation/owned-ui-settings/sections.js +93 -0
  42. package/dist/src/foundation/owned-ui-settings/session.d.ts +44 -0
  43. package/dist/src/foundation/owned-ui-settings/session.js +145 -0
  44. package/dist/src/foundation/owned-ui-settings/store.d.ts +28 -0
  45. package/dist/src/foundation/owned-ui-settings/store.js +90 -0
  46. package/dist/src/foundation/pi-component-adapter/index.d.ts +1 -0
  47. package/dist/src/foundation/pi-component-adapter/index.js +1 -0
  48. package/dist/src/foundation/pi-component-adapter/shell-selectors-dialogs.d.ts +9 -1
  49. package/dist/src/foundation/pi-component-adapter/shell-selectors-dialogs.js +10 -8
  50. package/dist/src/foundation/pi-engine-adapter/adapter.d.ts +12 -3
  51. package/dist/src/foundation/pi-engine-adapter/adapter.js +73 -7
  52. package/dist/src/foundation/pi-engine-adapter/pi-settings-metadata.json +374 -0
  53. package/dist/src/foundation/pi-engine-adapter/public-main-entry.js +10 -1
  54. package/dist/src/foundation/pi-engine-adapter/settings-integration.d.ts +42 -2
  55. package/dist/src/foundation/pi-engine-adapter/settings-integration.js +185 -24
  56. package/dist/src/foundation/pi-engine-adapter/workflows.d.ts +9 -0
  57. package/dist/src/foundation/pi-owned-ui-integration/index.d.ts +1 -0
  58. package/dist/src/foundation/pi-owned-ui-integration/index.js +1 -0
  59. package/dist/src/foundation/pi-owned-ui-integration/route-host.d.ts +29 -0
  60. package/dist/src/foundation/pi-owned-ui-integration/route-host.js +1 -0
  61. package/dist/src/foundation/pi-owned-ui-integration/session-shell.d.ts +6 -0
  62. package/dist/src/foundation/pi-owned-ui-integration/session-shell.js +71 -1
  63. package/dist/src/foundation/pi-tui-runtime-adapter/adapter.d.ts +6 -0
  64. package/dist/src/foundation/pi-tui-runtime-adapter/adapter.js +9 -0
  65. package/dist/src/foundation/process-containment/artifact.d.ts +1 -0
  66. package/dist/src/foundation/process-containment/artifact.js +34 -0
  67. package/dist/src/foundation/process-containment/contracts.d.ts +31 -0
  68. package/dist/src/foundation/process-containment/contracts.js +35 -0
  69. package/dist/src/foundation/process-containment/index.d.ts +5 -0
  70. package/dist/src/foundation/process-containment/index.js +5 -0
  71. package/dist/src/foundation/process-containment/linux-process-inspector.d.ts +6 -0
  72. package/dist/src/foundation/process-containment/linux-process-inspector.js +26 -0
  73. package/dist/src/foundation/process-containment/native-guardian-containment.d.ts +16 -0
  74. package/dist/src/foundation/process-containment/native-guardian-containment.js +139 -0
  75. package/dist/src/foundation/process-containment/windows-process-inspector.d.ts +17 -0
  76. package/dist/src/foundation/process-containment/windows-process-inspector.js +53 -0
  77. package/dist/src/foundation/protocol/client.d.ts +2 -1
  78. package/dist/src/foundation/protocol/client.js +3 -0
  79. package/dist/src/foundation/protocol/messages.d.ts +5 -5
  80. package/dist/src/foundation/protocol/messages.js +1 -1
  81. package/dist/src/foundation/release/bootstrap.js +29 -10
  82. package/dist/src/foundation/release/cohort-selection.js +3 -3
  83. package/dist/src/foundation/release/cohort-state.d.ts +3 -2
  84. package/dist/src/foundation/release/process-cleanup.d.ts +1 -1
  85. package/dist/src/foundation/release/process-cleanup.js +2 -2
  86. package/dist/src/foundation/release/update.js +2 -2
  87. package/dist/src/foundation/storage/control-store.d.ts +8 -7
  88. package/dist/src/foundation/storage/control-store.js +105 -55
  89. package/dist/src/foundation/supervision/server.d.ts +4 -2
  90. package/dist/src/foundation/supervision/server.js +254 -87
  91. package/dist/src/foundation/transparent-terminal/command-resolution.js +6 -3
  92. package/dist/src/foundation/transparent-terminal/foreground-broker.d.ts +5 -13
  93. package/dist/src/foundation/transparent-terminal/foreground-broker.js +11 -68
  94. package/dist/src/foundation/transparent-terminal/main.js +1 -8
  95. package/dist/src/foundation/ui-apps/contracts.d.ts +42 -0
  96. package/dist/src/foundation/ui-apps/contracts.js +12 -0
  97. package/dist/src/foundation/ui-apps/host.d.ts +42 -0
  98. package/dist/src/foundation/ui-apps/host.js +152 -0
  99. package/dist/src/foundation/ui-apps/index.d.ts +3 -0
  100. package/dist/src/foundation/ui-apps/index.js +3 -0
  101. package/dist/src/foundation/ui-apps/registry.d.ts +11 -0
  102. package/dist/src/foundation/ui-apps/registry.js +32 -0
  103. package/dist/src/foundation/ui-components/dialog-panel.d.ts +36 -0
  104. package/dist/src/foundation/ui-components/dialog-panel.js +47 -0
  105. package/dist/src/foundation/ui-components/frame.d.ts +21 -0
  106. package/dist/src/foundation/ui-components/frame.js +54 -0
  107. package/dist/src/foundation/ui-components/index.d.ts +18 -0
  108. package/dist/src/foundation/ui-components/index.js +18 -0
  109. package/dist/src/foundation/ui-components/label.d.ts +8 -0
  110. package/dist/src/foundation/ui-components/label.js +36 -0
  111. package/dist/src/foundation/ui-components/line-input.d.ts +74 -0
  112. package/dist/src/foundation/ui-components/line-input.js +245 -0
  113. package/dist/src/foundation/ui-components/list-block.d.ts +66 -0
  114. package/dist/src/foundation/ui-components/list-block.js +176 -0
  115. package/dist/src/foundation/ui-components/list-view.d.ts +66 -0
  116. package/dist/src/foundation/ui-components/list-view.js +76 -0
  117. package/dist/src/foundation/ui-components/mouse.d.ts +15 -0
  118. package/dist/src/foundation/ui-components/mouse.js +46 -0
  119. package/dist/src/foundation/ui-components/pane.d.ts +33 -0
  120. package/dist/src/foundation/ui-components/pane.js +7 -0
  121. package/dist/src/foundation/ui-components/revision.d.ts +35 -0
  122. package/dist/src/foundation/ui-components/revision.js +79 -0
  123. package/dist/src/foundation/ui-components/scrollbar.d.ts +62 -0
  124. package/dist/src/foundation/ui-components/scrollbar.js +102 -0
  125. package/dist/src/foundation/ui-components/shortcuts.d.ts +57 -0
  126. package/dist/src/foundation/ui-components/shortcuts.js +81 -0
  127. package/dist/src/foundation/ui-components/spans.d.ts +7 -0
  128. package/dist/src/foundation/ui-components/spans.js +59 -0
  129. package/dist/src/foundation/ui-components/status-line.d.ts +16 -0
  130. package/dist/src/foundation/ui-components/status-line.js +14 -0
  131. package/dist/src/foundation/ui-components/stepper.d.ts +24 -0
  132. package/dist/src/foundation/ui-components/stepper.js +33 -0
  133. package/dist/src/foundation/ui-components/surface.d.ts +20 -0
  134. package/dist/src/foundation/ui-components/surface.js +38 -0
  135. package/dist/src/foundation/ui-components/text.d.ts +24 -0
  136. package/dist/src/foundation/ui-components/text.js +123 -0
  137. package/dist/src/foundation/ui-components/theme.d.ts +17 -0
  138. package/dist/src/foundation/ui-components/theme.js +12 -0
  139. package/dist/src/foundation/ui-components/value-menu.d.ts +41 -0
  140. package/dist/src/foundation/ui-components/value-menu.js +33 -0
  141. package/dist/src/product-identity.d.ts +2 -2
  142. package/dist/src/product-identity.js +2 -1
  143. package/dist/src/product-identity.json +3 -0
  144. package/docs/architecture/boundaries.md +31 -13
  145. package/docs/architecture/process-guardian-provenance.md +26 -0
  146. package/docs/architecture/toolchain.md +6 -0
  147. package/docs/architecture/ui-reference-provenance.md +50 -0
  148. package/docs/ci-release-runbook.md +38 -42
  149. package/docs/features/launch-profiles.md +7 -1
  150. package/docs/manual-launch-instance-acceptance.md +66 -0
  151. package/package.json +11 -12
@@ -0,0 +1,35 @@
1
+ export async function closeVerifiedContainment(containment, inspector, rootIdentity, reason, deadlineMs = 1_500) {
2
+ if (!await ownershipMatches(containment, inspector, rootIdentity)) {
3
+ return ownershipMismatch("refusing graceful cleanup because launch-instance ownership changed");
4
+ }
5
+ await containment.stop(false);
6
+ if (await containment.waitForEmpty(deadlineMs)) {
7
+ return { outcome: { kind: "stopped", reason }, graceful: true, forced: false };
8
+ }
9
+ if (!await ownershipMatches(containment, inspector, rootIdentity)) {
10
+ return ownershipMismatch("refusing forced cleanup because launch-instance ownership changed");
11
+ }
12
+ await containment.stop(true);
13
+ if (await containment.waitForEmpty(deadlineMs)) {
14
+ return { outcome: { kind: "stopped", reason }, graceful: false, forced: true };
15
+ }
16
+ return {
17
+ outcome: {
18
+ kind: "cleanup-error",
19
+ message: "launch-instance process tree did not exit within the bounded cleanup deadline",
20
+ code: "CONTAINMENT_CLEANUP_TIMEOUT",
21
+ },
22
+ graceful: false,
23
+ forced: true,
24
+ };
25
+ }
26
+ async function ownershipMatches(containment, inspector, rootIdentity) {
27
+ return await inspector.matches(rootIdentity) && await containment.contains(rootIdentity);
28
+ }
29
+ function ownershipMismatch(message) {
30
+ return {
31
+ outcome: { kind: "cleanup-error", message, code: "PROCESS_IDENTITY_MISMATCH" },
32
+ graceful: false,
33
+ forced: false,
34
+ };
35
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./artifact.js";
2
+ export * from "./contracts.js";
3
+ export * from "./linux-process-inspector.js";
4
+ export * from "./native-guardian-containment.js";
5
+ export * from "./windows-process-inspector.js";
@@ -0,0 +1,5 @@
1
+ export * from "./artifact.js";
2
+ export * from "./contracts.js";
3
+ export * from "./linux-process-inspector.js";
4
+ export * from "./native-guardian-containment.js";
5
+ export * from "./windows-process-inspector.js";
@@ -0,0 +1,6 @@
1
+ import type { NativeProcessIdentity } from "../lifecycle/index.js";
2
+ import type { NativeProcessInspector } from "./contracts.js";
3
+ export declare class LinuxNativeProcessInspector implements NativeProcessInspector {
4
+ observe(pid: number): Promise<NativeProcessIdentity | null>;
5
+ matches(identity: NativeProcessIdentity): Promise<boolean>;
6
+ }
@@ -0,0 +1,26 @@
1
+ import { readFile } from "node:fs/promises";
2
+ export class LinuxNativeProcessInspector {
3
+ async observe(pid) {
4
+ if (!Number.isSafeInteger(pid) || pid <= 0)
5
+ throw new TypeError("inspected PID must be a positive safe integer");
6
+ let stat;
7
+ try {
8
+ stat = await readFile(`/proc/${pid}/stat`, "utf8");
9
+ }
10
+ catch (error) {
11
+ if (error instanceof Error && "code" in error && error.code === "ENOENT")
12
+ return null;
13
+ throw error;
14
+ }
15
+ const commandEnd = stat.lastIndexOf(")");
16
+ const fields = commandEnd >= 0 ? stat.slice(commandEnd + 1).trim().split(/\s+/) : [];
17
+ const startTicks = fields[19];
18
+ if (!startTicks || !/^\d+$/.test(startTicks))
19
+ throw new Error("process stat has no valid start-time field");
20
+ return { pid, startIdentity: `linux-proc-start:${startTicks}` };
21
+ }
22
+ async matches(identity) {
23
+ const observed = await this.observe(identity.pid);
24
+ return observed !== null && observed.startIdentity === identity.startIdentity;
25
+ }
26
+ }
@@ -0,0 +1,16 @@
1
+ import type { NativeProcessIdentity, ProcessContainmentIdentity } from "../lifecycle/index.js";
2
+ import type { ContainedProcessHandle, ContainedSpawnOptions, ProcessContainment } from "./contracts.js";
3
+ export declare class NativeGuardianContainment implements ProcessContainment {
4
+ #private;
5
+ readonly instanceId: string;
6
+ readonly helperPath: string;
7
+ readonly statusPath: string;
8
+ constructor(instanceId: string, helperPath: string, statusPath: string);
9
+ get identity(): ProcessContainmentIdentity;
10
+ spawn(executable: string, arguments_: readonly string[], options: ContainedSpawnOptions): Promise<ContainedProcessHandle>;
11
+ contains(identity: NativeProcessIdentity): Promise<boolean>;
12
+ stop(force: boolean): Promise<void>;
13
+ waitForEmpty(timeoutMs: number): Promise<boolean>;
14
+ close(): Promise<void>;
15
+ }
16
+ export declare function resolveProcessGuardianPath(releaseRoot: string, environment?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, architecture?: string): string;
@@ -0,0 +1,139 @@
1
+ import { spawn } from "node:child_process";
2
+ import { mkdir, readFile, rm } from "node:fs/promises";
3
+ import { dirname, resolve } from "node:path";
4
+ import { PRODUCT_IDENTITY } from "../../product-identity.js";
5
+ export class NativeGuardianContainment {
6
+ instanceId;
7
+ helperPath;
8
+ statusPath;
9
+ #identity;
10
+ #helper = null;
11
+ #rootIdentity = null;
12
+ #outcome = null;
13
+ constructor(instanceId, helperPath, statusPath) {
14
+ this.instanceId = instanceId;
15
+ this.helperPath = helperPath;
16
+ this.statusPath = statusPath;
17
+ this.#identity = { provider: "native-guardian-pending", token: instanceId };
18
+ }
19
+ get identity() {
20
+ return this.#identity;
21
+ }
22
+ async spawn(executable, arguments_, options) {
23
+ if (this.#helper)
24
+ throw new Error("process containment already has a root runtime");
25
+ await mkdir(dirname(this.statusPath), { recursive: true, mode: 0o700 });
26
+ await rm(this.statusPath, { force: true });
27
+ const helper = spawn(this.helperPath, [
28
+ "--parent-pid", String(process.pid),
29
+ "--instance", this.instanceId,
30
+ "--status-file", this.statusPath,
31
+ "--", executable, ...arguments_,
32
+ ], {
33
+ cwd: options.cwd,
34
+ env: { ...options.environment, ...(options.terminalType ? { TERM: options.terminalType } : {}) },
35
+ shell: false,
36
+ stdio: "inherit",
37
+ windowsHide: false,
38
+ });
39
+ this.#helper = helper;
40
+ this.#outcome = helperOutcome(helper);
41
+ const status = await waitForReadyStatus(this.statusPath, this.#outcome, 5_000);
42
+ this.#rootIdentity = { pid: status.pid, startIdentity: status.startIdentity };
43
+ this.#identity = { provider: status.containmentProvider, token: status.containmentToken };
44
+ return { identity: this.#rootIdentity, outcome: this.#outcome };
45
+ }
46
+ async contains(identity) {
47
+ return this.#rootIdentity !== null
48
+ && identity.pid === this.#rootIdentity.pid
49
+ && identity.startIdentity === this.#rootIdentity.startIdentity;
50
+ }
51
+ async stop(force) {
52
+ const root = this.#rootIdentity;
53
+ if (!root)
54
+ return;
55
+ try {
56
+ process.kill(root.pid, force ? "SIGKILL" : "SIGTERM");
57
+ }
58
+ catch { }
59
+ }
60
+ async waitForEmpty(timeoutMs) {
61
+ if (!this.#helper || this.#helper.exitCode !== null || this.#helper.signalCode !== null)
62
+ return true;
63
+ return await new Promise(resolvePromise => {
64
+ const timer = setTimeout(() => finish(false), timeoutMs);
65
+ timer.unref();
66
+ const finish = (empty) => {
67
+ clearTimeout(timer);
68
+ this.#helper?.off("close", onClose);
69
+ resolvePromise(empty);
70
+ };
71
+ const onClose = () => finish(true);
72
+ this.#helper?.once("close", onClose);
73
+ });
74
+ }
75
+ async close() {
76
+ const helper = this.#helper;
77
+ if (helper && helper.exitCode === null && helper.signalCode === null)
78
+ helper.kill("SIGKILL");
79
+ await this.waitForEmpty(1_500);
80
+ await rm(this.statusPath, { force: true });
81
+ }
82
+ }
83
+ export function resolveProcessGuardianPath(releaseRoot, environment = process.env, platform = process.platform, architecture = process.arch) {
84
+ const override = environment[PRODUCT_IDENTITY.environment.processGuardianPath]?.trim();
85
+ if (override)
86
+ return resolve(override);
87
+ const executable = platform === "win32"
88
+ ? `${PRODUCT_IDENTITY.artifacts.processGuardianExecutable}.exe`
89
+ : PRODUCT_IDENTITY.artifacts.processGuardianExecutable;
90
+ return resolve(releaseRoot, "dist", "native", `${platform}-${architecture}`, executable);
91
+ }
92
+ function helperOutcome(helper) {
93
+ return new Promise(resolvePromise => {
94
+ let settled = false;
95
+ const settle = (outcome) => {
96
+ if (settled)
97
+ return;
98
+ settled = true;
99
+ resolvePromise(outcome);
100
+ };
101
+ helper.once("error", error => settle({ kind: "guardian-error", message: error.message, code: errorCode(error) }));
102
+ helper.once("close", (code, signal) => {
103
+ if (signal)
104
+ settle({ kind: "signaled", signal });
105
+ else
106
+ settle({ kind: "exited", exitCode: code ?? 1 });
107
+ });
108
+ });
109
+ }
110
+ async function waitForReadyStatus(path, outcome, timeoutMs) {
111
+ const deadline = Date.now() + timeoutMs;
112
+ let terminalOutcome = null;
113
+ void outcome.then(value => { terminalOutcome = value; });
114
+ while (Date.now() < deadline) {
115
+ try {
116
+ const value = JSON.parse(await readFile(path, "utf8"));
117
+ if (isReadyStatus(value))
118
+ return value;
119
+ throw new Error("process guardian published invalid ready status");
120
+ }
121
+ catch (error) {
122
+ if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
123
+ throw error;
124
+ }
125
+ if (terminalOutcome)
126
+ throw new Error(`process guardian exited before readiness: ${JSON.stringify(terminalOutcome)}`);
127
+ await new Promise(resolvePromise => setTimeout(resolvePromise, 20));
128
+ }
129
+ throw new Error(`process guardian did not publish readiness within ${timeoutMs}ms`);
130
+ }
131
+ function isReadyStatus(value) {
132
+ return Number.isSafeInteger(value.pid) && Number(value.pid) > 0
133
+ && typeof value.startIdentity === "string" && value.startIdentity.length > 0
134
+ && typeof value.containmentProvider === "string" && value.containmentProvider.length > 0
135
+ && typeof value.containmentToken === "string" && value.containmentToken.length > 0;
136
+ }
137
+ function errorCode(error) {
138
+ return "code" in error && typeof error.code === "string" ? error.code : null;
139
+ }
@@ -0,0 +1,17 @@
1
+ import type { NativeProcessIdentity } from "../lifecycle/index.js";
2
+ import type { NativeProcessInspector } from "./contracts.js";
3
+ export interface InspectorCommandResult {
4
+ readonly exitCode: number;
5
+ readonly stdout: string;
6
+ readonly stderr: string;
7
+ }
8
+ export interface InspectorCommandRunner {
9
+ run(executable: string, arguments_: readonly string[]): Promise<InspectorCommandResult>;
10
+ }
11
+ export declare class WindowsNativeProcessInspector implements NativeProcessInspector {
12
+ readonly helperPath: string;
13
+ private readonly runner;
14
+ constructor(helperPath: string, runner?: InspectorCommandRunner);
15
+ observe(pid: number): Promise<NativeProcessIdentity | null>;
16
+ matches(identity: NativeProcessIdentity): Promise<boolean>;
17
+ }
@@ -0,0 +1,53 @@
1
+ import { execFile } from "node:child_process";
2
+ export class WindowsNativeProcessInspector {
3
+ helperPath;
4
+ runner;
5
+ constructor(helperPath, runner = defaultRunner) {
6
+ this.helperPath = helperPath;
7
+ this.runner = runner;
8
+ if (!helperPath || helperPath.includes("\0"))
9
+ throw new TypeError("process guardian helper path is invalid");
10
+ }
11
+ async observe(pid) {
12
+ if (!Number.isSafeInteger(pid) || pid <= 0)
13
+ throw new TypeError("inspected PID must be a positive safe integer");
14
+ const result = await this.runner.run(this.helperPath, ["--inspect-pid", String(pid)]);
15
+ if (result.exitCode === 3)
16
+ return null;
17
+ if (result.exitCode !== 0) {
18
+ const detail = result.stderr.trim() || `helper exited ${result.exitCode}`;
19
+ throw Object.assign(new Error(`cannot inspect native process identity: ${detail}`), { code: "PROCESS_INSPECTION_FAILED" });
20
+ }
21
+ let value;
22
+ try {
23
+ value = JSON.parse(result.stdout);
24
+ }
25
+ catch {
26
+ throw Object.assign(new Error("process guardian returned malformed identity data"), { code: "PROCESS_INSPECTION_INVALID" });
27
+ }
28
+ if (!isIdentity(value) || value.pid !== pid || !value.startIdentity.startsWith("windows-filetime:")) {
29
+ throw Object.assign(new Error("process guardian returned mismatched identity data"), { code: "PROCESS_INSPECTION_INVALID" });
30
+ }
31
+ return value;
32
+ }
33
+ async matches(identity) {
34
+ const observed = await this.observe(identity.pid);
35
+ return observed !== null && observed.startIdentity === identity.startIdentity;
36
+ }
37
+ }
38
+ const defaultRunner = {
39
+ async run(executable, arguments_) {
40
+ return await new Promise(resolvePromise => {
41
+ execFile(executable, [...arguments_], { windowsHide: true, timeout: 2_000, maxBuffer: 8 * 1_024 }, (error, stdout, stderr) => {
42
+ const exitCode = error && "code" in error && typeof error.code === "number" ? error.code : error ? 1 : 0;
43
+ resolvePromise({ exitCode, stdout, stderr });
44
+ });
45
+ });
46
+ },
47
+ };
48
+ function isIdentity(value) {
49
+ return typeof value === "object" && value !== null
50
+ && "pid" in value && Number.isSafeInteger(value.pid) && Number(value.pid) > 0
51
+ && "startIdentity" in value && typeof value.startIdentity === "string"
52
+ && value.startIdentity.length > 0 && value.startIdentity.length <= 512 && !value.startIdentity.includes("\0");
53
+ }
@@ -1,7 +1,8 @@
1
1
  import { EventEmitter } from "node:events";
2
- import type { CommandResult, SupervisorCommand, SupervisorSnapshot } from "../lifecycle/index.js";
2
+ import type { CommandResult, LaunchInstanceStopIntent, SupervisorCommand, SupervisorSnapshot } from "../lifecycle/index.js";
3
3
  interface ClientEvents {
4
4
  snapshot: [SupervisorSnapshot];
5
+ stopIntent: [LaunchInstanceStopIntent];
5
6
  disconnect: [];
6
7
  }
7
8
  export declare class SupervisorClient extends EventEmitter<ClientEvents> {
@@ -91,6 +91,9 @@ export class SupervisorClient extends EventEmitter {
91
91
  pending.resolve(message.result);
92
92
  }
93
93
  }
94
+ else if (message.type === "stop-launch-instance" && message.instanceId && message.requestId && message.reason) {
95
+ this.emit("stopIntent", message);
96
+ }
94
97
  else if (message.type === "protocol-error") {
95
98
  fail(new Error(message.message ?? "protocol error"));
96
99
  }
@@ -1,7 +1,7 @@
1
- import type { CommandResult, SupervisorCommand, SupervisorSnapshot } from "../lifecycle/index.js";
1
+ import type { CommandResult, LaunchInstanceStopIntent, SupervisorCommand, SupervisorSnapshot } from "../lifecycle/index.js";
2
2
  export declare const CONTROL_ENVELOPE: string;
3
3
  export declare const CONTROL_ENVELOPE_REVISION: 1;
4
- export declare const REQUIRED_CONTROL_FEATURES: readonly ["handshake.features.v1", "snapshot.revision.v1", "commands.request-identity.v1", "generation.lifecycle.v1", "terminal.foreground-lease.v1"];
4
+ export declare const REQUIRED_CONTROL_FEATURES: readonly ["handshake.features.v1", "snapshot.revision.v1", "commands.request-identity.v1", "generation.lifecycle.v1", "launch.instance-lifecycle.v1"];
5
5
  export declare const OPTIONAL_CONTROL_FEATURES: readonly ["messages.unknown-additive-ignore.v1", "snapshot.resynchronize.v1"];
6
6
  export type ControlFeature = string;
7
7
  export declare const GENERATED_CONTRACT_DIGEST: string;
@@ -41,12 +41,12 @@ export type ServerMessage = {
41
41
  readonly type: "release-ownership-result";
42
42
  readonly released: boolean;
43
43
  readonly reason: string;
44
- readonly liveGenerationIds: readonly string[];
44
+ readonly liveInstanceIds: readonly string[];
45
45
  } | {
46
46
  readonly type: "release-update-result";
47
47
  readonly accepted: boolean;
48
48
  readonly reason: string;
49
- readonly liveGenerationIds: readonly string[];
49
+ readonly liveInstanceIds: readonly string[];
50
50
  } | ({
51
51
  readonly type: "server-hello";
52
52
  readonly supervisorId: string;
@@ -60,7 +60,7 @@ export type ServerMessage = {
60
60
  } | {
61
61
  readonly type: "command-result";
62
62
  readonly result: CommandResult;
63
- } | {
63
+ } | LaunchInstanceStopIntent | {
64
64
  readonly type: "protocol-error";
65
65
  readonly code: string;
66
66
  readonly message: string;
@@ -7,7 +7,7 @@ export const REQUIRED_CONTROL_FEATURES = [
7
7
  "snapshot.revision.v1",
8
8
  "commands.request-identity.v1",
9
9
  "generation.lifecycle.v1",
10
- "terminal.foreground-lease.v1",
10
+ "launch.instance-lifecycle.v1",
11
11
  ];
12
12
  export const OPTIONAL_CONTROL_FEATURES = [
13
13
  "messages.unknown-additive-ignore.v1",
@@ -55,7 +55,7 @@ export async function runBootstrap(options) {
55
55
  probe = endpoint ? await probeOwnership(endpoint) : "dead";
56
56
  let decision = selectCohortLaunch(candidate, state, endpoint, probe);
57
57
  if (decision.action === "blocked") {
58
- await stateStore.blockPending(decision.reason, endpoint?.ownership.liveGenerationIds ?? []);
58
+ await stateStore.blockPending(decision.reason, endpoint?.ownership.liveInstanceIds ?? []);
59
59
  output.write(`${PRODUCT_TEXT.diagnostic(`startup is blocked to preserve uncertain live ownership: ${decision.reason}`)}\n`);
60
60
  return 1;
61
61
  }
@@ -73,7 +73,7 @@ export async function runBootstrap(options) {
73
73
  if (decision.action === "launch-retained-ui") {
74
74
  const retained = await verifyMaterializedRelease(decision.releaseRoot, undefined, resolve(paths.dataDir, "releases"));
75
75
  if (decision.recordPending && endpoint) {
76
- await stateStore.blockPending("candidate activation deferred by live non-resumable generations", endpoint.ownership.nonResumableGenerationIds);
76
+ await stateStore.blockPending("candidate activation deferred by live non-resumable instances", endpoint.ownership.nonResumableInstanceIds);
77
77
  }
78
78
  const code = await launchUi(retained, environment);
79
79
  if (decision.recordPending)
@@ -85,12 +85,12 @@ export async function runBootstrap(options) {
85
85
  await stateStore.approve(candidate.releaseId, diagnosticsPath);
86
86
  const released = await requestIdleOwnershipRelease(endpoint, candidate.releaseId, 2_000);
87
87
  if (!released) {
88
- await stateStore.blockPending("idle supervisor did not verify ownership release", endpoint.ownership.liveGenerationIds);
88
+ await stateStore.blockPending("idle supervisor did not verify ownership release", endpoint.ownership.liveInstanceIds);
89
89
  output.write(`${PRODUCT_TEXT.diagnostic("could not verify idle cohort ownership release; the retained release remains selected.")}\n`);
90
90
  return 1;
91
91
  }
92
92
  if (!await releaseVerifiedIdleOwner(endpoint, paths.dataDir)) {
93
- await stateStore.blockPending("idle supervisor acknowledged release but did not terminate", endpoint.ownership.liveGenerationIds);
93
+ await stateStore.blockPending("idle supervisor acknowledged release but did not terminate", endpoint.ownership.liveInstanceIds);
94
94
  output.write(`${PRODUCT_TEXT.diagnostic("could not complete bounded idle cohort shutdown; the candidate remains pending.")}\n`);
95
95
  return 1;
96
96
  }
@@ -152,7 +152,7 @@ export async function startSupervisor(release, environment) {
152
152
  child.unref();
153
153
  }
154
154
  async function launchUi(release, environment) {
155
- const entry = await resolveReleaseEntryPoint(release, "bin/a1-ui.js");
155
+ const entry = await resolveReleaseEntryPoint(release, "bin/a1-guardian.js");
156
156
  return await new Promise((resolvePromise, rejectPromise) => {
157
157
  const child = spawn(process.execPath, [entry], {
158
158
  env: releaseEnvironment(environment, release),
@@ -184,13 +184,29 @@ export async function waitForVerifiedEndpoint(path, release, timeoutMs) {
184
184
  export async function readEndpointMetadata(path) {
185
185
  try {
186
186
  const value = JSON.parse(await readFile(path, "utf8"));
187
+ const ownership = value.ownership;
188
+ const liveInstanceIds = Array.isArray(ownership?.liveInstanceIds)
189
+ ? ownership.liveInstanceIds
190
+ : Array.isArray(ownership?.liveGenerationIds) ? ownership.liveGenerationIds : null;
191
+ const nonResumableInstanceIds = Array.isArray(ownership?.nonResumableInstanceIds)
192
+ ? ownership.nonResumableInstanceIds
193
+ : Array.isArray(ownership?.nonResumableGenerationIds) ? ownership.nonResumableGenerationIds : null;
194
+ const uncertainInstanceIds = Array.isArray(ownership?.uncertainInstanceIds) ? ownership.uncertainInstanceIds : [];
187
195
  if (!value || value.schema !== PRODUCT_IDENTITY.protocol.supervisorSchema || typeof value.supervisorId !== "string" || typeof value.endpoint !== "string" || !Number.isSafeInteger(value.pid)
188
196
  || typeof value.pidStartIdentity !== "string" || typeof value.bootNonce !== "string" || typeof value.releaseId !== "string"
189
- || typeof value.releaseRoot !== "string" || typeof value.contentDigest !== "string" || !value.ownership
190
- || !Array.isArray(value.ownership.liveGenerationIds) || !Array.isArray(value.ownership.nonResumableGenerationIds)) {
197
+ || typeof value.releaseRoot !== "string" || typeof value.contentDigest !== "string" || !ownership
198
+ || !isStringArray(liveInstanceIds) || !isStringArray(nonResumableInstanceIds) || !isStringArray(uncertainInstanceIds)) {
191
199
  return null;
192
200
  }
193
- return value;
201
+ return {
202
+ ...value,
203
+ ownership: {
204
+ ...ownership,
205
+ liveInstanceIds,
206
+ nonResumableInstanceIds,
207
+ uncertainInstanceIds,
208
+ },
209
+ };
194
210
  }
195
211
  catch {
196
212
  return null;
@@ -243,11 +259,11 @@ async function activatePendingAfterBlockerExit(candidate, stateStore, paths, env
243
259
  let endpoint = null;
244
260
  while (Date.now() < deadline) {
245
261
  endpoint = await readEndpointMetadata(paths.endpointMetadataPath);
246
- if (!endpoint || endpoint.ownership.liveGenerationIds.length === 0)
262
+ if (!endpoint || endpoint.ownership.liveInstanceIds.length === 0)
247
263
  break;
248
264
  await new Promise(resolvePromise => setTimeout(resolvePromise, 40));
249
265
  }
250
- if (!endpoint || endpoint.ownership.liveGenerationIds.length > 0 || await probeOwnership(endpoint) !== "live-verified")
266
+ if (!endpoint || endpoint.ownership.liveInstanceIds.length > 0 || await probeOwnership(endpoint) !== "live-verified")
251
267
  return;
252
268
  const diagnosticsPath = await certifyMaterializedRelease(candidate, paths.dataDir);
253
269
  await stateStore.approve(candidate.releaseId, diagnosticsPath);
@@ -300,6 +316,9 @@ async function requestIdleOwnershipRelease(metadata, candidateReleaseId, timeout
300
316
  setTimeout(() => finish(false), timeoutMs).unref();
301
317
  });
302
318
  }
319
+ function isStringArray(value) {
320
+ return Array.isArray(value) && value.every(item => typeof item === "string" && item.length > 0);
321
+ }
303
322
  export async function waitForProcessExit(pid, timeoutMs) {
304
323
  const deadline = Date.now() + timeoutMs;
305
324
  while (Date.now() < deadline) {
@@ -10,7 +10,7 @@ export function selectCohortLaunch(candidate, state, endpoint, probe) {
10
10
  pid: endpoint.pid,
11
11
  };
12
12
  }
13
- if (endpoint.releaseId !== candidate.releaseId && endpoint.ownership.liveGenerationIds.length === 0) {
13
+ if (endpoint.releaseId !== candidate.releaseId && endpoint.ownership.liveInstanceIds.length === 0) {
14
14
  return {
15
15
  action: "replace-idle-cohort",
16
16
  releaseId: candidate.releaseId,
@@ -30,12 +30,12 @@ export function selectCohortLaunch(candidate, state, endpoint, probe) {
30
30
  };
31
31
  }
32
32
  if (endpoint && probe === "unresponsive") {
33
- if (endpoint.ownership.liveGenerationIds.length > 0 || endpoint.ownership.nonResumableGenerationIds.length > 0) {
33
+ if (endpoint.ownership.liveInstanceIds.length > 0 || endpoint.ownership.nonResumableInstanceIds.length > 0) {
34
34
  return {
35
35
  action: "blocked",
36
36
  releaseId: endpoint.releaseId,
37
37
  releaseRoot: endpoint.releaseRoot,
38
- reason: "ownership of live generations is uncertain; preserving the unresponsive supervisor",
38
+ reason: "ownership of live launch instances is uncertain; preserving the unresponsive supervisor",
39
39
  pid: endpoint.pid,
40
40
  };
41
41
  }
@@ -32,8 +32,9 @@ export interface CohortState {
32
32
  }
33
33
  export interface EndpointOwnership {
34
34
  readonly state: "idle" | "busy" | "draining" | "released" | "blocked";
35
- readonly liveGenerationIds: readonly string[];
36
- readonly nonResumableGenerationIds: readonly string[];
35
+ readonly liveInstanceIds: readonly string[];
36
+ readonly nonResumableInstanceIds: readonly string[];
37
+ readonly uncertainInstanceIds: readonly string[];
37
38
  }
38
39
  export interface SupervisorEndpointMetadata {
39
40
  readonly schema: string;
@@ -9,6 +9,6 @@ export declare function processIsAlive(pid: number): boolean;
9
9
  export declare function cleanupProvenIdleOwner(metadata: SupervisorEndpointMetadata, graceMs?: number): Promise<CleanupDiagnostics>;
10
10
  export declare function cleanupVerifiedOwner(metadata: SupervisorEndpointMetadata, options?: {
11
11
  readonly graceMs?: number;
12
- readonly allowLiveGenerations?: boolean;
12
+ readonly allowLiveInstances?: boolean;
13
13
  readonly reason?: "stale-idle-owner" | "explicit-update" | "legacy-mutable-install";
14
14
  }): Promise<CleanupDiagnostics>;
@@ -11,11 +11,11 @@ export function processIsAlive(pid) {
11
11
  }
12
12
  }
13
13
  export async function cleanupProvenIdleOwner(metadata, graceMs = 1_500) {
14
- return await cleanupVerifiedOwner(metadata, { graceMs, allowLiveGenerations: false });
14
+ return await cleanupVerifiedOwner(metadata, { graceMs, allowLiveInstances: false });
15
15
  }
16
16
  export async function cleanupVerifiedOwner(metadata, options = {}) {
17
17
  const graceMs = options.graceMs ?? 1_500;
18
- if (!options.allowLiveGenerations && (metadata.ownership.liveGenerationIds.length > 0 || metadata.ownership.nonResumableGenerationIds.length > 0)) {
18
+ if (!options.allowLiveInstances && (metadata.ownership.liveInstanceIds.length > 0 || metadata.ownership.nonResumableInstanceIds.length > 0)) {
19
19
  throw new Error("refusing to terminate an owner with recorded live generations");
20
20
  }
21
21
  const started = Date.now();
@@ -71,7 +71,7 @@ export function createUpdateLifecycleCoordinator(environment = process.env, file
71
71
  // Explicit update consent permits bounded cleanup of an authenticated
72
72
  // older owner that predates the update-shutdown message.
73
73
  const cleanup = await cleanupVerifiedOwner(endpoint, {
74
- allowLiveGenerations: true,
74
+ allowLiveInstances: true,
75
75
  reason: legacyMutableInstall ? "legacy-mutable-install" : "explicit-update",
76
76
  });
77
77
  if (!cleanup.terminated)
@@ -80,7 +80,7 @@ export function createUpdateLifecycleCoordinator(environment = process.env, file
80
80
  else if (identity.accepted) {
81
81
  await waitForProcessExit(endpoint.pid, 3_000).catch(async () => {
82
82
  const cleanup = await cleanupVerifiedOwner(endpoint, {
83
- allowLiveGenerations: true,
83
+ allowLiveInstances: true,
84
84
  reason: legacyMutableInstall ? "legacy-mutable-install" : "explicit-update",
85
85
  });
86
86
  if (!cleanup.terminated)
@@ -1,6 +1,6 @@
1
1
  import { DatabaseSync } from "node:sqlite";
2
2
  import type { ManagedAgentDescriptor, PaneId, AgentRecoveryAuthority, RecoveryReferenceId, TerminalSessionLaunch, TerminalTopologySnapshot } from "../workspace-contracts/index.js";
3
- import type { ForegroundTerminalLease, ForegroundTerminalLeaseId, GenerationId, NativeProcessIdentity, TransparentTerminalLifecycleOutcome } from "../lifecycle/index.js";
3
+ import type { LaunchInstance, LaunchInstanceId, LaunchInstanceOutcome, NativeProcessIdentity, ProcessContainmentIdentity } from "../lifecycle/index.js";
4
4
  export declare const DEFAULT_WORKSPACE_ID = "workspace-default";
5
5
  export interface WorkspaceAgentPresentation {
6
6
  readonly unreadActivity: number;
@@ -21,12 +21,13 @@ export declare class ControlStore {
21
21
  constructor(path: string, bootNonce?: string | null);
22
22
  migrate(): void;
23
23
  reconcilePriorBootGenerations(bootNonce: string): number;
24
- acquireForegroundTerminalLease(lease: ForegroundTerminalLease): void;
25
- activateForegroundTerminalLease(leaseId: ForegroundTerminalLeaseId, generationId: GenerationId, processIdentity: NativeProcessIdentity, heartbeatAt: string): boolean;
26
- heartbeatForegroundTerminalLease(leaseId: ForegroundTerminalLeaseId, processIdentity: NativeProcessIdentity, heartbeatAt: string): boolean;
27
- releaseForegroundTerminalLease(leaseId: ForegroundTerminalLeaseId, processIdentity: NativeProcessIdentity | null, outcome: TransparentTerminalLifecycleOutcome, releasedAt: string): boolean;
28
- loadLiveForegroundTerminalLease(): ForegroundTerminalLease | null;
29
- reconcilePriorBootForegroundTerminalLeases(bootNonce: string, reconciledAt?: string): number;
24
+ createLaunchInstance(instance: LaunchInstance): void;
25
+ activateLaunchInstance(instanceId: LaunchInstanceId, ownerClientId: string, rootIdentity: NativeProcessIdentity, containmentIdentity: ProcessContainmentIdentity, activatedAt: string): boolean;
26
+ beginLaunchInstanceStop(instanceId: LaunchInstanceId, ownerClientId: string, stoppingAt: string): boolean;
27
+ completeLaunchInstance(instanceId: LaunchInstanceId, ownerClientId: string, terminalState: "completed" | "interrupted", outcome: LaunchInstanceOutcome, completedAt: string): boolean;
28
+ loadActiveLaunchInstances(): LaunchInstance[];
29
+ loadLaunchInstance(instanceId: LaunchInstanceId): LaunchInstance | null;
30
+ reconcilePriorBootLaunchInstances(bootNonce: string, reconciledAt?: string): number;
30
31
  persistWorkspaceAgent(agent: ManagedAgentDescriptor, updatedAt?: string): void;
31
32
  persistWorkspaceAgentRecord(record: StoredWorkspaceAgent, updatedAt?: string): void;
32
33
  replaceWorkspaceAgentRecords(records: readonly StoredWorkspaceAgent[], selectedAgentId: string | null, revision: number, updatedAt?: string): void;