@anhlp/alp-daemon 0.0.1-beta.4 → 0.0.1-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD-PARTY-NOTICES.txt +26 -1
- package/dist/alpd.js +10768 -2592
- package/dist/attachments.d.ts +25 -49
- package/dist/attachments.js +45 -8
- package/dist/build-manifest.json +14 -1
- package/dist/conversation.js +18 -2
- package/dist/disk.d.ts +67 -0
- package/dist/disk.js +152 -0
- package/dist/files.d.ts +141 -2
- package/dist/files.js +377 -68
- package/dist/git.d.ts +8 -2
- package/dist/git.js +111 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/main.js +57 -12
- package/dist/native-terminal.d.ts +45 -0
- package/dist/native-terminal.js +198 -0
- package/dist/operations.d.ts +12 -2
- package/dist/operations.js +22 -11
- package/dist/registry.js +1 -1
- package/dist/scheduler.js +8 -2
- package/dist/schedules.d.ts +2 -1
- package/dist/schedules.js +6 -4
- package/dist/server.d.ts +4 -2
- package/dist/server.js +171 -43
- package/dist/store.d.ts +3 -1
- package/dist/store.js +4 -3
- package/dist/terminal-native/README.md +201 -0
- package/dist/terminal-native/prebuilt/darwin-arm64/manifest.json +11 -0
- package/dist/terminal-native/prebuilt/darwin-arm64/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/darwin-x64/manifest.json +11 -0
- package/dist/terminal-native/prebuilt/darwin-x64/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-arm64-musl/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-x64-glibc/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-x64-musl/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-x64-musl/terminal-owner +0 -0
- package/dist/terminal-native/terminal-owner.c +389 -0
- package/dist/terminal-screen.d.ts +24 -0
- package/dist/terminal-screen.js +99 -0
- package/dist/terminals.d.ts +43 -7
- package/dist/terminals.js +222 -139
- package/dist/windows-terminal.d.ts +29 -0
- package/dist/windows-terminal.js +122 -0
- package/dist/worktrees.d.ts +25 -1
- package/dist/worktrees.js +74 -2
- package/native/README.md +201 -0
- package/native/prebuilt/darwin-arm64/manifest.json +11 -0
- package/native/prebuilt/darwin-arm64/terminal-owner +0 -0
- package/native/prebuilt/darwin-x64/manifest.json +11 -0
- package/native/prebuilt/darwin-x64/terminal-owner +0 -0
- package/native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
- package/native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
- package/native/prebuilt/linux-arm64-musl/manifest.json +10 -0
- package/native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
- package/native/prebuilt/linux-x64-glibc/manifest.json +10 -0
- package/native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
- package/native/prebuilt/linux-x64-musl/manifest.json +10 -0
- package/native/prebuilt/linux-x64-musl/terminal-owner +0 -0
- package/native/terminal-owner.c +389 -0
- package/package.json +11 -7
- package/src/attachments.ts +46 -8
- package/src/conversation.ts +22 -2
- package/src/disk.ts +175 -0
- package/src/files.ts +505 -80
- package/src/git.ts +113 -18
- package/src/index.ts +1 -0
- package/src/main.ts +53 -13
- package/src/native-terminal.ts +122 -0
- package/src/operations.ts +28 -12
- package/src/registry.ts +1 -1
- package/src/scheduler.ts +13 -3
- package/src/schedules.ts +5 -2
- package/src/server.ts +164 -36
- package/src/store.ts +2 -1
- package/src/terminal-screen.ts +74 -0
- package/src/terminals.ts +205 -155
- package/src/windows-terminal.ts +123 -0
- package/src/worktrees.ts +97 -2
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// packages/daemon/src/windows-terminal.ts
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
function packagedNodePty() {
|
|
6
|
+
const assets = globalThis[Symbol.for("alp.packaged")]?.assetDir?.();
|
|
7
|
+
const entry = assets ? path.join(assets, "node-pty", "lib", "index.js") : void 0;
|
|
8
|
+
return entry && existsSync(entry) ? entry : void 0;
|
|
9
|
+
}
|
|
10
|
+
var loaded;
|
|
11
|
+
function loadNodePty() {
|
|
12
|
+
if (loaded === void 0) {
|
|
13
|
+
try {
|
|
14
|
+
loaded = createRequire(import.meta.url)(packagedNodePty() ?? "node-pty");
|
|
15
|
+
} catch {
|
|
16
|
+
loaded = null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return loaded ?? void 0;
|
|
20
|
+
}
|
|
21
|
+
function windowsTerminalCapability() {
|
|
22
|
+
return loadNodePty() ? { available: true, protection: "none" } : { available: false, reason: "node_pty_unavailable" };
|
|
23
|
+
}
|
|
24
|
+
function windowsShell(env = process.env) {
|
|
25
|
+
const candidate = env.ComSpec ?? env.COMSPEC;
|
|
26
|
+
return candidate && /^[a-zA-Z]:[\\/]/.test(candidate) ? candidate : "cmd.exe";
|
|
27
|
+
}
|
|
28
|
+
var windowsPtySpawn = (file, args, options) => {
|
|
29
|
+
if (options.signal?.aborted) throw new Error("Terminal startup cancelled");
|
|
30
|
+
const pty = loadNodePty();
|
|
31
|
+
if (!pty) throw new Error("node-pty is unavailable on this host");
|
|
32
|
+
const spawnOptions = { name: options.name, cols: options.cols, rows: options.rows, cwd: options.cwd, env: options.env, useConpty: true, ...packagedNodePty() ? { useConptyDll: true } : {} };
|
|
33
|
+
const child = typeof process.versions.bun === "string" ? spawnUnderBun(pty, file, args, spawnOptions) : pty.spawn(file, args, spawnOptions);
|
|
34
|
+
let killed = false;
|
|
35
|
+
return {
|
|
36
|
+
pid: child.pid,
|
|
37
|
+
write(data) {
|
|
38
|
+
if (!killed) child.write(data);
|
|
39
|
+
},
|
|
40
|
+
resize(cols, rows) {
|
|
41
|
+
if (!killed) try {
|
|
42
|
+
child.resize(cols, rows);
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
// Best-effort: node-pty ends the ConPTY session and its shell; descendants are not guaranteed.
|
|
47
|
+
kill() {
|
|
48
|
+
if (killed) return;
|
|
49
|
+
killed = true;
|
|
50
|
+
try {
|
|
51
|
+
child.kill();
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
onData: (listener) => child.onData(listener),
|
|
56
|
+
onExit: (listener) => child.onExit(({ exitCode, signal }) => listener({ exitCode, signal }))
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
function spawnUnderBun(pty, file, args, options) {
|
|
60
|
+
const load = createRequire(import.meta.url);
|
|
61
|
+
const fs = load("node:fs");
|
|
62
|
+
const net = load("node:net");
|
|
63
|
+
const Socket = net.Socket;
|
|
64
|
+
function InputSocket(...rest) {
|
|
65
|
+
const [opts] = rest;
|
|
66
|
+
if (opts && typeof opts.fd === "number" && opts.writable === true && opts.readable === false) return fdWriter(fs, opts.fd);
|
|
67
|
+
return new Socket(...rest);
|
|
68
|
+
}
|
|
69
|
+
InputSocket.prototype = Socket.prototype;
|
|
70
|
+
net.Socket = InputSocket;
|
|
71
|
+
try {
|
|
72
|
+
return pty.spawn(file, args, options);
|
|
73
|
+
} finally {
|
|
74
|
+
net.Socket = Socket;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function fdWriter(fs, fd) {
|
|
78
|
+
let queue = Promise.resolve();
|
|
79
|
+
let closed = false;
|
|
80
|
+
let failed = false;
|
|
81
|
+
const writer = {
|
|
82
|
+
readable: false,
|
|
83
|
+
writable: true,
|
|
84
|
+
setEncoding() {
|
|
85
|
+
return writer;
|
|
86
|
+
},
|
|
87
|
+
write(data) {
|
|
88
|
+
if (closed || failed) return false;
|
|
89
|
+
const bytes = typeof data === "string" ? Buffer.from(data, "utf8") : Buffer.from(data);
|
|
90
|
+
queue = queue.then(() => new Promise((resolve) => {
|
|
91
|
+
const rest = (offset) => {
|
|
92
|
+
if (closed || failed || offset >= bytes.length) return resolve();
|
|
93
|
+
fs.write(fd, bytes, offset, bytes.length - offset, null, (error, written) => {
|
|
94
|
+
if (error) {
|
|
95
|
+
failed = true;
|
|
96
|
+
writer.writable = false;
|
|
97
|
+
return resolve();
|
|
98
|
+
}
|
|
99
|
+
rest(offset + written);
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
rest(0);
|
|
103
|
+
}));
|
|
104
|
+
return true;
|
|
105
|
+
},
|
|
106
|
+
destroy() {
|
|
107
|
+
if (closed) return writer;
|
|
108
|
+
closed = true;
|
|
109
|
+
writer.writable = false;
|
|
110
|
+
void queue.then(() => fs.close(fd, () => {
|
|
111
|
+
}));
|
|
112
|
+
return writer;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return writer;
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
loadNodePty,
|
|
119
|
+
windowsPtySpawn,
|
|
120
|
+
windowsShell,
|
|
121
|
+
windowsTerminalCapability
|
|
122
|
+
};
|
package/dist/worktrees.d.ts
CHANGED
|
@@ -11,9 +11,19 @@ type Context = {
|
|
|
11
11
|
mappingIds?: string[];
|
|
12
12
|
authorizedRoots?: string[];
|
|
13
13
|
};
|
|
14
|
+
/** What the owner confirms before a legacy managed worktree is adopted (t-c1ba), each proven from Git and the filesystem. */
|
|
15
|
+
export type AdoptionFacts = {
|
|
16
|
+
workspaceId: string;
|
|
17
|
+
directory: string;
|
|
18
|
+
source: string;
|
|
19
|
+
commonDir: string;
|
|
20
|
+
gitDir: string;
|
|
21
|
+
branch: string;
|
|
22
|
+
head: string;
|
|
23
|
+
};
|
|
14
24
|
/** Owner-only file; neither an RPC parameter nor repository configuration can approve a destination. */
|
|
15
25
|
export declare function worktreeMappings(home: string): Promise<Mapping[]>;
|
|
16
|
-
export declare function createWorkspaceWorktrees(home: string, registry: RegistryService, guard: <T>(directory: string, run: () => Promise<T>) => Promise<T>, register: (directory: string) => Promise<void>): {
|
|
26
|
+
export declare function createWorkspaceWorktrees(home: string, registry: RegistryService, guard: <T>(directory: string, run: () => Promise<T>) => Promise<T>, register: (directory: string) => Promise<void>, adoptWorkspace?: (directory: string, verify: (canonical: string) => Promise<void>) => Promise<void>): {
|
|
17
27
|
describe(w: WorkspaceRecord): Promise<{
|
|
18
28
|
managedWorktree?: boolean | undefined;
|
|
19
29
|
branch: string | null;
|
|
@@ -28,6 +38,20 @@ export declare function createWorkspaceWorktrees(home: string, registry: Registr
|
|
|
28
38
|
archivedAt?: string | null;
|
|
29
39
|
idempotencyKey?: string;
|
|
30
40
|
}>;
|
|
41
|
+
/** What adopting this legacy managed worktree would certify (t-c1ba); it changes nothing. */
|
|
42
|
+
adoption(workspaceId: string, context?: Context): Promise<AdoptionFacts>;
|
|
43
|
+
/**
|
|
44
|
+
* Certifies a managed worktree that predates birth certification, once the owner confirmed the
|
|
45
|
+
* facts `adoption` showed. The facts are proven again under the runtime's removal guard, which
|
|
46
|
+
* also refuses any checkout an assignment, claim, lease or session still owns. Removal stays a
|
|
47
|
+
* separate request with all of its own checks.
|
|
48
|
+
*/
|
|
49
|
+
adopt(p: {
|
|
50
|
+
workspaceId: string;
|
|
51
|
+
confirm: AdoptionFacts;
|
|
52
|
+
}, context?: Context): Promise<{
|
|
53
|
+
adopted: AdoptionFacts;
|
|
54
|
+
}>;
|
|
31
55
|
assertAvailable(directory: string): Promise<void>;
|
|
32
56
|
grants(context?: Context): Promise<{
|
|
33
57
|
mappings: {
|
package/dist/worktrees.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// packages/daemon/src/worktrees.ts
|
|
2
2
|
import { randomBytes } from "node:crypto";
|
|
3
|
-
import {
|
|
3
|
+
import { constants } from "node:fs";
|
|
4
|
+
import { lstat, mkdir, open, readFile, realpath, stat } from "node:fs/promises";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import { user_worktree } from "@anhlp/alp-core";
|
|
6
7
|
import { RegistryError } from "./registry.js";
|
|
@@ -40,7 +41,7 @@ async function worktreeMappings(home) {
|
|
|
40
41
|
}
|
|
41
42
|
return value.mappings;
|
|
42
43
|
}
|
|
43
|
-
function createWorkspaceWorktrees(home, registry, guard, register) {
|
|
44
|
+
function createWorkspaceWorktrees(home, registry, guard, register, adoptWorkspace) {
|
|
44
45
|
const adapter = git();
|
|
45
46
|
async function approved(context, source, mappingId, native = true) {
|
|
46
47
|
const m = (await worktreeMappings(home)).find((m2) => m2.id === mappingId && m2.source === source);
|
|
@@ -60,6 +61,46 @@ function createWorkspaceWorktrees(home, registry, guard, register) {
|
|
|
60
61
|
fail("identity_changed", "Source identity changed", 1003);
|
|
61
62
|
return w;
|
|
62
63
|
}
|
|
64
|
+
async function adoptionFacts(r, id) {
|
|
65
|
+
const w = workspace(r, id);
|
|
66
|
+
const meta = w.worktree;
|
|
67
|
+
if (!meta || meta.kind !== "user" || meta.removedAt || w.archivedAt)
|
|
68
|
+
return fail("not_managed", "Only a present managed user worktree can be adopted", 1003);
|
|
69
|
+
if (Object.values(r.worktreeJournal ?? {}).some((j) => j.intent.id === w.id))
|
|
70
|
+
fail("reconciliation_required", "Workspace is pending reconciliation");
|
|
71
|
+
const mapping = (await worktreeMappings(home)).find(
|
|
72
|
+
(m) => m.id === meta.mappingId && m.source === meta.source && m.commonDir === meta.commonDir
|
|
73
|
+
);
|
|
74
|
+
if (!mapping) return fail("outside_workspace", "The host does not approve its destination mapping now", 1003);
|
|
75
|
+
const directory = path.join(mapping.parent, w.id);
|
|
76
|
+
const branch = `alp/workspace/${w.id}`;
|
|
77
|
+
if (!/^wks_[0-9a-f]{16}$/.test(w.id) || w.directory !== directory || (w.canonical ?? w.directory) !== directory || meta.branch !== branch)
|
|
78
|
+
fail("identity_changed", "Not a generated managed worktree", 1003);
|
|
79
|
+
const info = await lstat(directory).catch(() => void 0);
|
|
80
|
+
if (!info?.isDirectory() || await realpath(directory).catch(() => void 0) !== directory)
|
|
81
|
+
fail("identity_changed", "Managed worktree path is missing or not canonical", 1003);
|
|
82
|
+
const origin = await adapter.facts(mapping.source).catch(() => void 0);
|
|
83
|
+
if (origin?.commonDir !== mapping.commonDir) fail("identity_changed", "Source repository identity changed", 1003);
|
|
84
|
+
const row = await adapter.inspect(mapping.source, directory, branch).catch(() => void 0);
|
|
85
|
+
const target = row ? await adapter.facts(directory).catch(() => void 0) : void 0;
|
|
86
|
+
if (!row || !target || target.commonDir !== mapping.commonDir || target.gitDir === target.commonDir || target.gitDir !== meta.gitDir || target.branch !== branch || row.HEAD !== target.head)
|
|
87
|
+
return fail("identity_changed", "Git does not list it as this managed worktree", 1003);
|
|
88
|
+
return { workspaceId: w.id, directory, source: mapping.source, commonDir: mapping.commonDir, gitDir: target.gitDir, branch, head: target.head };
|
|
89
|
+
}
|
|
90
|
+
const owner = (context) => {
|
|
91
|
+
if ((context.principalId ?? "owner") !== "owner" || (context.principalEpoch ?? "owner") !== "owner" || context.mappingIds || context.authorizedRoots)
|
|
92
|
+
fail("owner_only", "Only the host owner adopts a workspace", 1003);
|
|
93
|
+
};
|
|
94
|
+
async function audit(entry) {
|
|
95
|
+
const file = path.join(home, "state", "workspace-adoptions.jsonl");
|
|
96
|
+
await mkdir(path.dirname(file), { recursive: true, mode: 448 });
|
|
97
|
+
const handle = await open(file, constants.O_WRONLY | constants.O_APPEND | constants.O_CREAT | constants.O_NOFOLLOW, 384);
|
|
98
|
+
try {
|
|
99
|
+
await handle.writeFile(JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), ...entry }) + "\n");
|
|
100
|
+
} finally {
|
|
101
|
+
await handle.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
63
104
|
async function clean(source, target, branch, head) {
|
|
64
105
|
if (!await adapter.inspect(source, target, branch))
|
|
65
106
|
fail("outcome_unknown", "Worktree creation needs owner reconciliation", 1005);
|
|
@@ -78,6 +119,37 @@ function createWorkspaceWorktrees(home, registry, guard, register) {
|
|
|
78
119
|
}
|
|
79
120
|
return { ...row, branch, ...worktree ? { managedWorktree: true } : {} };
|
|
80
121
|
},
|
|
122
|
+
/** What adopting this legacy managed worktree would certify (t-c1ba); it changes nothing. */
|
|
123
|
+
async adoption(workspaceId, context = {}) {
|
|
124
|
+
owner(context);
|
|
125
|
+
return adoptionFacts(await registry.snapshot(), workspaceId);
|
|
126
|
+
},
|
|
127
|
+
/**
|
|
128
|
+
* Certifies a managed worktree that predates birth certification, once the owner confirmed the
|
|
129
|
+
* facts `adoption` showed. The facts are proven again under the runtime's removal guard, which
|
|
130
|
+
* also refuses any checkout an assignment, claim, lease or session still owns. Removal stays a
|
|
131
|
+
* separate request with all of its own checks.
|
|
132
|
+
*/
|
|
133
|
+
async adopt(p, context = {}) {
|
|
134
|
+
owner(context);
|
|
135
|
+
if (!adoptWorkspace) return fail("guard_unavailable", "Runtime cannot prove safe adoption", 1005);
|
|
136
|
+
const confirmed = (facts2) => !!p.confirm && typeof p.confirm === "object" && Object.keys(p.confirm).length === Object.keys(facts2).length && Object.keys(facts2).every((k) => p.confirm[k] === facts2[k]);
|
|
137
|
+
const facts = await adoptionFacts(await registry.snapshot(), p.workspaceId);
|
|
138
|
+
if (!confirmed(facts)) fail("confirmation_mismatch", "The workspace differs from what was confirmed; review it and confirm again", 1003);
|
|
139
|
+
await audit({ event: "adoption.requested", actor: "owner", ...facts });
|
|
140
|
+
try {
|
|
141
|
+
await adoptWorkspace(facts.directory, async () => {
|
|
142
|
+
if (!confirmed(await adoptionFacts(await registry.snapshot(), p.workspaceId)))
|
|
143
|
+
fail("confirmation_mismatch", "The workspace changed after it was confirmed; review it and confirm again", 1003);
|
|
144
|
+
});
|
|
145
|
+
} catch (error) {
|
|
146
|
+
await audit({ event: "adoption.refused", actor: "owner", workspaceId: facts.workspaceId, reason: error?.data?.reason ?? "failed", error: error?.message ?? String(error) }).catch(() => {
|
|
147
|
+
});
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
await audit({ event: "adoption.certified", actor: "owner", workspaceId: facts.workspaceId, directory: facts.directory });
|
|
151
|
+
return { adopted: facts };
|
|
152
|
+
},
|
|
81
153
|
async assertAvailable(directory) {
|
|
82
154
|
const r = await registry.snapshot();
|
|
83
155
|
const canonical = await realpath(directory).catch(() => path.resolve(directory));
|
package/native/README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Terminal native owner — candidate, platform matrix incomplete
|
|
2
|
+
|
|
3
|
+
Task t-d71b. Production `src/terminals.ts` now uses this identity-bound owner,
|
|
4
|
+
with no node-pty fallback on macOS or Linux. Linux may use the best-effort root-only mode described below;
|
|
5
|
+
Windows has no protection helper and uses node-pty (ConPTY), best-effort (see "Windows" below). This candidate is NOT accepted for release:
|
|
6
|
+
actual Linux (beyond CI capability checks) and Windows evidence remain missing. Missing or
|
|
7
|
+
unverifiable backends refuse terminal capability explicitly (no plain-PTY fallback on Linux); on Linux a verified helper without full protection (any reason) offers root-only compatibility (best-effort, user decision 2026-10-29). No end-user compiler
|
|
8
|
+
is required. Existing session authentication and host/Paseo opt-ins still apply.
|
|
9
|
+
|
|
10
|
+
## Protocol and lifetime
|
|
11
|
+
|
|
12
|
+
One standalone C process owns forkpty, the startup gate, every signal and root
|
|
13
|
+
wait/reap. JS sends terminal input on stdin and resize (`R cols rows\n`) / cleanup
|
|
14
|
+
(`C\n`) on fd4. PTY output is stdout; fd3 contains bounded JSON ready, root-exit,
|
|
15
|
+
and cleanup records. Input/output queues and identity storage are bounded. Resizes coalesce behind
|
|
16
|
+
writable backpressure; cleanup closes the control pipe immediately. Native startup
|
|
17
|
+
polls the handshake/control descriptors with a 3s deadline; failure closes the
|
|
18
|
+
gate and attempts only identity-bound cleanup with a bounded nonblocking reap.
|
|
19
|
+
|
|
20
|
+
The child reports `getsid(0)==getpid()` before the parent releases its startup
|
|
21
|
+
gate. The owner acquires root identity before release, has default SIGCHLD and no
|
|
22
|
+
other reaper, and uses waitid(WNOWAIT) to observe natural exit. It retains the
|
|
23
|
+
root's live process or zombie until all discovery/signaling ends. This reserves
|
|
24
|
+
the root PID and prevents unrelated sessions reusing that session number. Only
|
|
25
|
+
processes proven to belong to that reserved session can be discovered. Observed
|
|
26
|
+
identities remain authorized if they subsequently leave the session. On the full-protection path there is no
|
|
27
|
+
marker, environment, age, PPid, parentuniqueid, TTY, numeric PID signal or numeric
|
|
28
|
+
group signal fallback. Never-observed children that immediately detach can be
|
|
29
|
+
missed (the approved g3 limit).
|
|
30
|
+
|
|
31
|
+
Linux opens a proc TGID directory with O_RDONLY|O_DIRECTORY (not O_PATH), reads
|
|
32
|
+
stat relative to that SAME descriptor, and uses pidfd_send_signal on that fd with
|
|
33
|
+
flags0/infoNULL. Capability probing checks kernel procfs and that /proc/self PID
|
|
34
|
+
and SID match the caller's namespace coordinates, and requires /proc/self/status
|
|
35
|
+
NSpid to have exactly one field equal to getpid() (proves the procfs PID namespace
|
|
36
|
+
is our active one without reading PID1, so it works for non-root users; missing
|
|
37
|
+
NSpid denies). A mount-privileged actor remounting /proc is outside this guarantee;
|
|
38
|
+
failure denies capability. Linux source has NOT been
|
|
39
|
+
compiled or executed here; permission/race/namespace/minimum-kernel evidence is
|
|
40
|
+
still required.
|
|
41
|
+
|
|
42
|
+
Darwin validates the complete private flavor17 56-byte struct and audit-token
|
|
43
|
+
version at runtime. Discovery uses U_before → reserved getsid → audit token →
|
|
44
|
+
U_after, requiring equal uniqueids and a matching token pidversion. Signals
|
|
45
|
+
refresh only a previously known uniqueid and use proc_signal_with_audittoken.
|
|
46
|
+
Unknown/changed identity never authorizes a numeric signal. Cleanup reports
|
|
47
|
+
observed/live/uncertain separately; it does not claim universal containment.
|
|
48
|
+
|
|
49
|
+
## Accepted finite-generation Darwin limit
|
|
50
|
+
|
|
51
|
+
The Darwin final syscall compares PID + **32-bit global pidversion**, not the
|
|
52
|
+
64-bit private uniqueid. Fork AND exec increment this global generation. If the
|
|
53
|
+
helper is suspended after its last identity check, enough global allocations can
|
|
54
|
+
wrap that generation and a recycled target PID can collide. Keeping a task-name
|
|
55
|
+
port or checking uniqueid again does not atomically bind the eventual syscall.
|
|
56
|
+
This is a source-derived limitation, not an executed 2^32-operation exploit.
|
|
57
|
+
The user explicitly accepted ONLY this residual in g4 (2026-10-29); ordinary PID
|
|
58
|
+
reuse protection, all native checks, packaging, platform tests and independent
|
|
59
|
+
review remain required. No blanket no-wrong-process waiver is inferred.
|
|
60
|
+
|
|
61
|
+
Kernel proof anchors (oracle 275c5e36, advice only; not implementation review):
|
|
62
|
+
|
|
63
|
+
- [XNU PID/zombie/session reservation and fork generations](https://github.com/apple-oss-distributions/xnu/blob/xnu-11215.1.10/bsd/kern/kern_fork.c#L877)
|
|
64
|
+
- [XNU WNOWAIT and reap hash removal](https://github.com/apple-oss-distributions/xnu/blob/xnu-11215.1.10/bsd/kern/kern_exit.c#L2457)
|
|
65
|
+
- [XNU setsid and cross-session restrictions](https://github.com/apple-oss-distributions/xnu/blob/xnu-11215.1.10/bsd/kern/kern_prot.c#L245)
|
|
66
|
+
- [XNU identity-info and final audit signal comparison](https://github.com/apple-oss-distributions/xnu/blob/xnu-11215.1.10/bsd/kern/proc_info.c#L3290)
|
|
67
|
+
- [XNU exec increments generation](https://github.com/apple-oss-distributions/xnu/blob/xnu-11215.1.10/bsd/kern/kern_exec.c#L6475)
|
|
68
|
+
- [Private ABI layout](https://github.com/apple-oss-distributions/xnu/blob/xnu-12377.1.9/bsd/sys/proc_info_private.h#L41)
|
|
69
|
+
- [Linux stored proc-directory identity](https://github.com/torvalds/linux/blob/v6.12/fs/proc/base.c#L3244)
|
|
70
|
+
- [Linux procdirfd signal dispatch](https://github.com/torvalds/linux/blob/v6.12/kernel/signal.c#L3647)
|
|
71
|
+
- [Linux stat session coordinates](https://github.com/torvalds/linux/blob/v6.12/fs/proc/array.c#L505)
|
|
72
|
+
|
|
73
|
+
## Build, distribution and remaining platform evidence
|
|
74
|
+
|
|
75
|
+
`node scripts/build-terminal-native.mjs` is an EXPLICIT developer build, never
|
|
76
|
+
terminal startup or postinstall. Darwin also accepts `--arch=x64`/`--arch=arm64`
|
|
77
|
+
using the existing Apple compiler and ad-hoc codesign; capability execution must
|
|
78
|
+
succeed before a manifest is written. Hashes bind protocol, source and binary.
|
|
79
|
+
`node scripts/terminal-native-assets.mjs --require-matrix` and release pack-check
|
|
80
|
+
FAIL until all six slots exist: Darwin arm64/x64, Linux arm64/x64 × glibc/musl.
|
|
81
|
+
Builds copy only verified prebuilt assets beside root, daemon, CLI and Paseo bundles;
|
|
82
|
+
source-package daemon consumers also carry native source/hash manifests. They do
|
|
83
|
+
not invoke a compiler. A rebuild replaces the generated asset directory wholesale.
|
|
84
|
+
|
|
85
|
+
### Committed prebuilts and the rebuild procedure (t-08cf)
|
|
86
|
+
|
|
87
|
+
All six slots are committed under `prebuilt/<slot>/` (binary with its exec bit, plus
|
|
88
|
+
`manifest.json` binding protocol, `terminal-owner.c` SHA-256 and binary SHA-256), so a
|
|
89
|
+
clean checkout passes `--require-matrix`, pack-check and the release clean-tree gate.
|
|
90
|
+
CI and releases ship the committed binaries; nothing is compiled during build or release.
|
|
91
|
+
|
|
92
|
+
The four Linux slots come from `.github/workflows/terminal-native.yml` (glibc on the
|
|
93
|
+
manylinux_2_28 floor image, musl on Alpine 3.20, each executed non-root in its own libc;
|
|
94
|
+
glibc also in fresh/ancestor PID namespaces). On every CI run that job rebuilds each slot
|
|
95
|
+
from the checked-out source, then requires the COMMITTED slot's manifest to record the
|
|
96
|
+
same source hash as the fresh build, its binary to match its manifest hash, and the
|
|
97
|
+
committed binary to pass the same execution checks. Builds are not byte-reproducible, so
|
|
98
|
+
binary hashes are NOT compared across builds: CI enforces source binding and execution,
|
|
99
|
+
not bit-for-bit provenance.
|
|
100
|
+
|
|
101
|
+
When `terminal-owner.c` changes, rebuild ALL six slots in the same commit:
|
|
102
|
+
|
|
103
|
+
1. Darwin: on macOS, `node scripts/build-terminal-native.mjs --arch=arm64` and
|
|
104
|
+
`--arch=x64` (x64 capability executes through Rosetta).
|
|
105
|
+
2. Linux: push the source change; the terminal-native jobs fail as stale but still upload
|
|
106
|
+
`terminal-native-<slot>` artifacts built from that exact revision. Download them into
|
|
107
|
+
an empty directory (`gh run download <run-id> -p 'terminal-native-*' -D <dir>`; each
|
|
108
|
+
lands as `<dir>/terminal-native-<slot>/<slot>.tar`) and extract each with
|
|
109
|
+
`tar -C packages/daemon/native/prebuilt -xpf <tar>` (tar keeps the exec bit).
|
|
110
|
+
3. `node scripts/terminal-native-assets.mjs --require-matrix`, commit all six slots, and
|
|
111
|
+
check the next CI run is green.
|
|
112
|
+
|
|
113
|
+
Current artifacts: Darwin arm64 executed on macOS27, Darwin x64 capability executed
|
|
114
|
+
through existing Rosetta on that same host. Both target macOS11.0 (LC_BUILD_VERSION),
|
|
115
|
+
matching [Node22's macOS floor](https://github.com/nodejs/node/blob/v22.23.0/BUILDING.md#platform-list).
|
|
116
|
+
This deployment target is NOT proof of runtime compatibility on macOS11 or physical
|
|
117
|
+
x64 hardware. Private-ABI capability validation still fails closed. Linux builds
|
|
118
|
+
must retain the existing libc support baseline (Node22 glibc2.28). The committed Linux
|
|
119
|
+
artifacts were built and capability-executed by CI run 40857935251 (GitHub-hosted
|
|
120
|
+
Ubuntu 24.04 kernels); minimum-kernel execution has not been proved. pidfd_send_signal (Linux5.1 syscall baseline) selects full protection. Without it
|
|
121
|
+
Linux runs the best-effort root-only mode described below, disclosed with a non-blocking notice.
|
|
122
|
+
No permission denial or artifact failure silently selects compatibility.
|
|
123
|
+
|
|
124
|
+
Async startup reserves request IDs and quota before native readiness. Revoke,
|
|
125
|
+
shutdown and host optout cancel startup and await native cleanup before returning;
|
|
126
|
+
late readiness cannot publish an orphan terminal. Root exit is delivered after
|
|
127
|
+
stdio drains. The helper reads the PTY to EOF and advances partial output writes
|
|
128
|
+
for up to one further second; an undrained tail reports explicit uncertainty. Cleanup reports observed/live/uncertain, and uncertain/live results
|
|
129
|
+
refuse success and stop further terminal admission. The existing real PTY cleanup
|
|
130
|
+
scenarios now execute through the native owner (including exec, same-session
|
|
131
|
+
orphans and a late child). Never-observed immediate-setsid escapes remain the
|
|
132
|
+
approved g3 discovery limit. Actual Linux/Windows browser keyboard and Linux
|
|
133
|
+
namespace/proc permissions/races remain NOT_CHECKED.
|
|
134
|
+
|
|
135
|
+
Explicit developer regressions (require a local C compiler, not end-user startup):
|
|
136
|
+
`node --test packages/daemon/native/tests/lifecycle.mjs` exercises delayed native
|
|
137
|
+
startup and a real stalled control reader. `ALP_NATIVE_BASELINE=8ed11fd` runs the
|
|
138
|
+
same checks against the committed pre-correction C/TS in isolated scratch space.
|
|
139
|
+
This mode does not change the checkout. Both cases fail on that baseline and pass
|
|
140
|
+
on the correction. Ordinary lifecycle tests run separately from daemon/tests.
|
|
141
|
+
|
|
142
|
+
## Linux root-only compatibility candidate (g5)
|
|
143
|
+
|
|
144
|
+
Linux is best-effort (user decision 2026-10-29; only macOS is guaranteed). A verified
|
|
145
|
+
helper that fails full protection for ANY reason (ENOSYS, EPERM/EACCES, procfs or
|
|
146
|
+
PID-namespace mismatch) advertises `alp-terminal-owner:1:root-only`; root-only mode
|
|
147
|
+
only signals the unreaped session root and, after the startup capability probe, does not use procfs or pidfd, so
|
|
148
|
+
background jobs may survive close. A corrupt/missing binary or manifest, timeout,
|
|
149
|
+
crash or malformed record still refuses capability (no unverified code runs).
|
|
150
|
+
The owner revalidates immediately before fork; a mode change refuses before shell
|
|
151
|
+
launch, and alpd probes the helper again for the next create.
|
|
152
|
+
|
|
153
|
+
Root-only terminals open directly: no acknowledgment is required (user decision
|
|
154
|
+
2026-10-29, Linux and Windows are best-effort like Orca/Paseo). The deprecated
|
|
155
|
+
`protectionAcknowledgment: "linux-root-only-v1"` parameter is still accepted on
|
|
156
|
+
`terminal.create`/`terminal.attach` for compatibility and ignored. Terminal records
|
|
157
|
+
carry `protection: "root-only"`, so clients disclose the limit: ALP Web shows one
|
|
158
|
+
non-blocking notice ("Limited protection on this Linux host: closing the terminal may
|
|
159
|
+
not stop background processes."), and the terminal stays usable. Paseo's terminal
|
|
160
|
+
protocol has no notice field, so the ALP bridge writes the same notice once as a
|
|
161
|
+
dim line into each Paseo client's view of the terminal (never into alpd's output).
|
|
162
|
+
|
|
163
|
+
Compatibility never scans or explicitly signals descendants or process groups.
|
|
164
|
+
Only its own direct root is signaled, before final reap, with SIGCHLD explicitly
|
|
165
|
+
SIG_DFL and SA_NOCLDWAIT cleared by checked sigaction. A living child or WNOWAIT
|
|
166
|
+
zombie continuously reserves its PID; an unexpected ECHILD permanently retires
|
|
167
|
+
numeric authority. Final reap is checked. This is spawn ownership, not a snapshot
|
|
168
|
+
or a numeric PID-reuse heuristic; helper compromise invalidates that premise.
|
|
169
|
+
Kernel PTY hangup and line-discipline signals may naturally affect foreground jobs.
|
|
170
|
+
|
|
171
|
+
Known reduced coverage is `coverage: "root-only"`; successful cleanup establishes
|
|
172
|
+
only the shell's exit. Unmanaged jobs can survive close/revoke/optout/shutdown and
|
|
173
|
+
keep the PTY open (`outputOpen: true` after bounded draining). This accepted known
|
|
174
|
+
coverage limit alone does not lock admission. Root live/lost ownership, queued
|
|
175
|
+
bytes not delivered, protocol loss or sticky adapter failure remain uncertainty
|
|
176
|
+
and retain the admission lock. No delayed signals occur after root reap.
|
|
177
|
+
|
|
178
|
+
Advice/source proof: oracle18a20d0e examined [Linux5.1 wait/ptrace reap](https://github.com/torvalds/linux/blob/v5.1/kernel/exit.c)
|
|
179
|
+
and [original procdirfd signal dispatch](https://github.com/torvalds/linux/blob/v5.1/kernel/signal.c).
|
|
180
|
+
Actual Linux compilation/execution (old and supported kernel, namespace/permission,
|
|
181
|
+
ptrace/exec/reuse/race) remains NOT_CHECKED here; the four shipped Linux artifacts are committed and CI capability-checked.
|
|
182
|
+
Darwin author regressions validate the unchanged full path only; no seam/mock or
|
|
183
|
+
Rosetta execution is claimed as Linux or physical-x64/minimum-macOS proof.
|
|
184
|
+
|
|
185
|
+
## Windows (best-effort, no protection helper)
|
|
186
|
+
|
|
187
|
+
There is no Windows native owner and pack-check requires no Windows slot. On win32,
|
|
188
|
+
`src/terminals.ts` spawns the shell (`%ComSpec%`, else `cmd.exe`) through node-pty
|
|
189
|
+
(ConPTY), the same platform PTY Paseo uses; node-pty is an optional dependency, and
|
|
190
|
+
when it cannot load, terminals refuse with `terminal_unsupported`. Terminals report
|
|
191
|
+
`protection: "none"`, and clients show a "not guaranteed on Windows" notice. Closing,
|
|
192
|
+
revoking or turning off terminals calls node-pty `kill()` (best-effort): the shell
|
|
193
|
+
ends, but processes it started may keep running. This is the only production use of
|
|
194
|
+
node-pty. Windows behavior has NOT been executed here; only injected-owner unit tests ran.
|
|
195
|
+
|
|
196
|
+
## Termination signals
|
|
197
|
+
|
|
198
|
+
SIGTERM, SIGINT and SIGHUP sent to the owner (for example to the daemon's process group)
|
|
199
|
+
start the same bound cleanup as closing its control pipe, on every platform including
|
|
200
|
+
macOS (deliberate: previously such a signal killed the owner before cleanup). The shell
|
|
201
|
+
child resets them to default before exec.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocol": 1,
|
|
3
|
+
"slot": "darwin-arm64",
|
|
4
|
+
"source": "d2fa72ce0b083e60cddbe76839365beaa80b891451b45987d968b805154d0636",
|
|
5
|
+
"sha256": "354f50aea9e8d5113fc9fb4fd90ccb417d8aad74b89473fdcb711c6d1253f367",
|
|
6
|
+
"buildHost": "v22.23.4",
|
|
7
|
+
"deploymentTarget": "11.0",
|
|
8
|
+
"executionChecked": true,
|
|
9
|
+
"executionProtection": "identity-bound",
|
|
10
|
+
"executionHost": "darwin-arm64"
|
|
11
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocol": 1,
|
|
3
|
+
"slot": "darwin-x64",
|
|
4
|
+
"source": "d2fa72ce0b083e60cddbe76839365beaa80b891451b45987d968b805154d0636",
|
|
5
|
+
"sha256": "606a0bd9a0ae76550156d343c89efa69d97215b8bf95c6aadbf38b6468a041e5",
|
|
6
|
+
"buildHost": "v22.23.4",
|
|
7
|
+
"deploymentTarget": "11.0",
|
|
8
|
+
"executionChecked": true,
|
|
9
|
+
"executionProtection": "identity-bound",
|
|
10
|
+
"executionHost": "darwin-arm64"
|
|
11
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocol": 1,
|
|
3
|
+
"slot": "linux-arm64-glibc",
|
|
4
|
+
"source": "d2fa72ce0b083e60cddbe76839365beaa80b891451b45987d968b805154d0636",
|
|
5
|
+
"sha256": "fa6e8b66f8e449d6fa294518c7f7d107e0707d2048623cc4952031b9580c31e3",
|
|
6
|
+
"buildHost": "v22.23.4",
|
|
7
|
+
"executionChecked": true,
|
|
8
|
+
"executionProtection": "identity-bound",
|
|
9
|
+
"executionHost": "linux-arm64"
|
|
10
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocol": 1,
|
|
3
|
+
"slot": "linux-arm64-musl",
|
|
4
|
+
"source": "d2fa72ce0b083e60cddbe76839365beaa80b891451b45987d968b805154d0636",
|
|
5
|
+
"sha256": "e6935d27c14c626b3207ea8edecd4a56b6bf13c8634b97a7480928e4bd22e9d6",
|
|
6
|
+
"buildHost": "v20.15.1",
|
|
7
|
+
"executionChecked": true,
|
|
8
|
+
"executionProtection": "identity-bound",
|
|
9
|
+
"executionHost": "linux-arm64"
|
|
10
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocol": 1,
|
|
3
|
+
"slot": "linux-x64-glibc",
|
|
4
|
+
"source": "d2fa72ce0b083e60cddbe76839365beaa80b891451b45987d968b805154d0636",
|
|
5
|
+
"sha256": "4746db2e0b89ffd81f9ab14da871a8a8a59b39d219ab9612bb86faa8d8db35b7",
|
|
6
|
+
"buildHost": "v22.23.4",
|
|
7
|
+
"executionChecked": true,
|
|
8
|
+
"executionProtection": "identity-bound",
|
|
9
|
+
"executionHost": "linux-x64"
|
|
10
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocol": 1,
|
|
3
|
+
"slot": "linux-x64-musl",
|
|
4
|
+
"source": "d2fa72ce0b083e60cddbe76839365beaa80b891451b45987d968b805154d0636",
|
|
5
|
+
"sha256": "5d3e964057212ce231ab920426012ede944057138613712f0cf52a81f1397c2d",
|
|
6
|
+
"buildHost": "v20.15.1",
|
|
7
|
+
"executionChecked": true,
|
|
8
|
+
"executionProtection": "identity-bound",
|
|
9
|
+
"executionHost": "linux-x64"
|
|
10
|
+
}
|
|
Binary file
|