@anhlp/alp-runtime 0.0.0-stage → 0.0.1-beta.10
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/LICENSE +202 -0
- package/NOTICE +7 -0
- package/README.md +6 -2
- package/dist/acp-transport.d.ts +130 -0
- package/dist/acp-transport.js +482 -0
- package/dist/antigravity-transport.d.ts +107 -0
- package/dist/antigravity-transport.js +665 -0
- package/dist/assignment-results.d.ts +55 -0
- package/dist/assignment-results.js +181 -0
- package/dist/attachments.d.ts +84 -0
- package/dist/attachments.js +213 -0
- package/dist/board-domain.d.ts +56 -0
- package/dist/board-domain.js +157 -0
- package/dist/board.d.ts +27 -0
- package/dist/board.js +76 -0
- package/dist/catalog.d.ts +44 -0
- package/dist/catalog.js +47 -0
- package/dist/claude-transport.d.ts +251 -0
- package/dist/claude-transport.js +931 -0
- package/dist/compact.d.ts +29 -0
- package/dist/compact.js +49 -0
- package/dist/configure.d.ts +44 -0
- package/dist/configure.js +64 -0
- package/dist/contracts.d.ts +378 -0
- package/dist/contracts.js +16 -0
- package/dist/conversation.d.ts +45 -0
- package/dist/conversation.js +62 -0
- package/dist/events.d.ts +1 -0
- package/dist/events.js +0 -0
- package/dist/github.d.ts +10 -0
- package/dist/github.js +39 -0
- package/dist/handoff.d.ts +36 -0
- package/dist/handoff.js +73 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +122 -0
- package/dist/input-limits.d.ts +25 -0
- package/dist/input-limits.js +48 -0
- package/dist/language.d.ts +51 -0
- package/dist/language.js +94 -0
- package/dist/live.d.ts +48 -0
- package/dist/live.js +50 -0
- package/dist/mailbox.d.ts +26 -0
- package/dist/mailbox.js +38 -0
- package/dist/mcp-tools.d.ts +123 -0
- package/dist/mcp-tools.js +97 -0
- package/dist/model-catalog.d.ts +162 -0
- package/dist/model-catalog.js +338 -0
- package/dist/model-probes.d.ts +7 -0
- package/dist/model-probes.js +69 -0
- package/dist/permission-path.d.ts +2 -0
- package/dist/permission-path.js +44 -0
- package/dist/process-info.d.ts +14 -0
- package/dist/process-info.js +32 -0
- package/dist/providers.d.ts +28 -0
- package/dist/providers.js +73 -0
- package/dist/recall.d.ts +42 -0
- package/dist/recall.js +61 -0
- package/dist/resolve.d.ts +123 -0
- package/dist/resolve.js +242 -0
- package/dist/runtime-context.d.ts +43 -0
- package/dist/runtime-context.js +61 -0
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.js +4818 -0
- package/dist/session-config.d.ts +2345 -0
- package/dist/session-config.js +209 -0
- package/dist/session-state.d.ts +190 -0
- package/dist/session-state.js +0 -0
- package/dist/skill-resources.d.ts +30 -0
- package/dist/skill-resources.js +55 -0
- package/dist/tool-detail.d.ts +81 -0
- package/dist/tool-detail.js +332 -0
- package/dist/tool-results.d.ts +12 -0
- package/dist/tool-results.js +25 -0
- package/dist/tools.d.ts +827 -0
- package/dist/tools.js +463 -0
- package/dist/transport.d.ts +47 -0
- package/dist/transport.js +171 -0
- package/dist/usage.d.ts +25 -0
- package/dist/usage.js +60 -0
- package/dist/workspace.d.ts +127 -0
- package/dist/workspace.js +340 -0
- package/dist/worktree-domain.d.ts +89 -0
- package/dist/worktree-domain.js +199 -0
- package/dist/write-error.d.ts +2 -0
- package/dist/write-error.js +10 -0
- package/package.json +262 -4
- package/src/acp-transport.ts +481 -0
- package/src/antigravity-transport.ts +740 -0
- package/src/assignment-results.ts +154 -0
- package/src/attachments.ts +254 -0
- package/src/board-domain.ts +185 -0
- package/src/board.ts +87 -0
- package/src/catalog.ts +43 -0
- package/src/claude-transport.ts +1097 -0
- package/src/compact.ts +62 -0
- package/src/configure.ts +93 -0
- package/src/contracts.ts +363 -0
- package/src/conversation.ts +81 -0
- package/src/events.ts +1 -0
- package/src/github.ts +37 -0
- package/src/handoff.ts +86 -0
- package/src/index.ts +41 -0
- package/src/input-limits.ts +65 -0
- package/src/language.ts +130 -0
- package/src/live.ts +90 -0
- package/src/mailbox.ts +49 -0
- package/src/mcp-tools.ts +106 -0
- package/src/model-catalog.ts +316 -0
- package/src/model-probes.ts +58 -0
- package/src/permission-path.ts +37 -0
- package/src/process-info.ts +40 -0
- package/src/providers.ts +87 -0
- package/src/recall.ts +86 -0
- package/src/resolve.ts +238 -0
- package/src/runtime-context.ts +49 -0
- package/src/runtime.ts +5608 -0
- package/src/session-config.ts +312 -0
- package/src/session-state.ts +180 -0
- package/src/skill-resources.ts +73 -0
- package/src/tool-detail.ts +397 -0
- package/src/tool-results.ts +26 -0
- package/src/tools.ts +466 -0
- package/src/transport.ts +118 -0
- package/src/usage.ts +79 -0
- package/src/workspace.ts +424 -0
- package/src/worktree-domain.ts +220 -0
- package/src/write-error.ts +4 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// packages/runtime/src/transport.ts
|
|
2
|
+
import { optionalRead, codexUsage } from "./runtime-context.js";
|
|
3
|
+
import { spawn, execFile } from "node:child_process";
|
|
4
|
+
import { createInterface } from "node:readline";
|
|
5
|
+
import { scriptCommand } from "@anhlp/alp-core/packaged";
|
|
6
|
+
function unanswered(error) {
|
|
7
|
+
return Object.assign(new Error(error.message), { outcomeUnknown: true });
|
|
8
|
+
}
|
|
9
|
+
var CodexTransport = class {
|
|
10
|
+
child;
|
|
11
|
+
sequence = 0;
|
|
12
|
+
pending = /* @__PURE__ */ new Map();
|
|
13
|
+
listeners = /* @__PURE__ */ new Set();
|
|
14
|
+
failures = /* @__PURE__ */ new Set();
|
|
15
|
+
closed = false;
|
|
16
|
+
requestHandler;
|
|
17
|
+
exit;
|
|
18
|
+
constructor(command, cwd, env, args = ["app-server", "--listen", "stdio://"]) {
|
|
19
|
+
if (/\.(cmd|bat|ps1)$/i.test(command)) throw new Error("Codex executable must be a native binary, not a shell launcher");
|
|
20
|
+
const script = process.platform === "win32" && /\.[cm]?js$/i.test(command);
|
|
21
|
+
const run = script ? scriptCommand(command, args) : { command, args, env: void 0 };
|
|
22
|
+
this.child = spawn(run.command, run.args, { cwd, env: run.env ? { ...env, ...run.env } : env, windowsHide: true, stdio: ["pipe", "pipe", "pipe"] });
|
|
23
|
+
this.exit = new Promise((resolve) => {
|
|
24
|
+
this.child.once("close", resolve);
|
|
25
|
+
this.child.once("error", () => resolve());
|
|
26
|
+
});
|
|
27
|
+
this.child.stderr.on("data", () => {
|
|
28
|
+
});
|
|
29
|
+
this.child.stdin.on("error", (error) => this.fail(error));
|
|
30
|
+
this.child.on("error", (error) => this.fail(error));
|
|
31
|
+
this.child.on("close", (code) => {
|
|
32
|
+
if (!this.closed) this.fail(new Error(`Codex app-server exited (${code})`));
|
|
33
|
+
});
|
|
34
|
+
const lines = createInterface({ input: this.child.stdout });
|
|
35
|
+
lines.on("line", (line) => {
|
|
36
|
+
if (line.length > 16 * 1024 * 1024) {
|
|
37
|
+
this.fail(new Error("Codex frame exceeds size limit"));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const message = JSON.parse(line);
|
|
42
|
+
if (message.method && message.id !== void 0) {
|
|
43
|
+
if (["item/tool/call", "item/commandExecution/requestApproval", "item/fileChange/requestApproval"].includes(message.method) && this.requestHandler) {
|
|
44
|
+
void Promise.resolve().then(() => this.requestHandler(message.method, message.params)).then(
|
|
45
|
+
(result) => {
|
|
46
|
+
if (!this.closed) this.write({ id: message.id, result });
|
|
47
|
+
},
|
|
48
|
+
(error) => {
|
|
49
|
+
if (!this.closed) this.write({ id: message.id, error: { code: -32603, message: error instanceof Error ? error.message : String(error) } });
|
|
50
|
+
}
|
|
51
|
+
).catch((error) => this.fail(error));
|
|
52
|
+
} else {
|
|
53
|
+
this.write({ id: message.id, error: { code: -32601, message: "Unsupported runtime request" } });
|
|
54
|
+
}
|
|
55
|
+
} else if (message.id !== void 0) {
|
|
56
|
+
const waiter = this.pending.get(message.id);
|
|
57
|
+
if (waiter) {
|
|
58
|
+
this.pending.delete(message.id);
|
|
59
|
+
clearTimeout(waiter.timer);
|
|
60
|
+
if (message.error) waiter.reject(new Error(message.error.message ?? "Runtime request failed"));
|
|
61
|
+
else waiter.resolve(message.result);
|
|
62
|
+
}
|
|
63
|
+
} else if (message.method) {
|
|
64
|
+
for (const listener of this.listeners) listener(message.method, message.params);
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
this.fail(error instanceof Error ? error : new Error(String(error)));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
write(value) {
|
|
72
|
+
if (this.closed) throw new Error("Runtime is closed");
|
|
73
|
+
this.child.stdin.write(`${JSON.stringify(value)}
|
|
74
|
+
`);
|
|
75
|
+
}
|
|
76
|
+
fail(error) {
|
|
77
|
+
if (this.closed) return;
|
|
78
|
+
for (const p of this.pending.values()) {
|
|
79
|
+
clearTimeout(p.timer);
|
|
80
|
+
p.reject(unanswered(error));
|
|
81
|
+
}
|
|
82
|
+
this.pending.clear();
|
|
83
|
+
for (const listener of this.failures) listener(error);
|
|
84
|
+
void this.close();
|
|
85
|
+
}
|
|
86
|
+
request(method, params, timeout = 3e4, fatalTimeout = true) {
|
|
87
|
+
if (this.closed) return Promise.reject(new Error("Runtime is closed"));
|
|
88
|
+
const id = ++this.sequence;
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
const timer = setTimeout(() => {
|
|
91
|
+
const error = new Error(`Runtime request timed out: ${method}`);
|
|
92
|
+
if (fatalTimeout) this.fail(error);
|
|
93
|
+
else {
|
|
94
|
+
this.pending.delete(id);
|
|
95
|
+
reject(unanswered(error));
|
|
96
|
+
}
|
|
97
|
+
}, timeout);
|
|
98
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
99
|
+
try {
|
|
100
|
+
this.write({ id, method, params });
|
|
101
|
+
} catch (error) {
|
|
102
|
+
clearTimeout(timer);
|
|
103
|
+
this.pending.delete(id);
|
|
104
|
+
reject(error);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async orchestrationContext() {
|
|
109
|
+
const [catalog, usage] = await Promise.all([
|
|
110
|
+
optionalRead(() => this.request("model/list", { limit: 100, includeHidden: false }, 1200, false)),
|
|
111
|
+
optionalRead(() => this.request("account/rateLimits/read", {}, 1200, false))
|
|
112
|
+
]);
|
|
113
|
+
return {
|
|
114
|
+
runtime: "codex",
|
|
115
|
+
observedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
116
|
+
catalogAvailable: Array.isArray(catalog?.data),
|
|
117
|
+
catalogComplete: catalog ? !catalog.nextCursor : false,
|
|
118
|
+
models: (catalog?.data ?? []).map((model) => ({
|
|
119
|
+
id: `codex:${model.model}`,
|
|
120
|
+
description: model.description,
|
|
121
|
+
label: model.displayName,
|
|
122
|
+
thinking: model.supportedReasoningEfforts
|
|
123
|
+
})),
|
|
124
|
+
usage: codexUsage(usage)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async initialize() {
|
|
128
|
+
await this.request("initialize", { clientInfo: { name: "alp", title: "ALP", version: "0.0.0" }, capabilities: { experimentalApi: true } });
|
|
129
|
+
this.write({ method: "initialized" });
|
|
130
|
+
}
|
|
131
|
+
onNotification(listener) {
|
|
132
|
+
this.listeners.add(listener);
|
|
133
|
+
return () => this.listeners.delete(listener);
|
|
134
|
+
}
|
|
135
|
+
onFailure(listener) {
|
|
136
|
+
this.failures.add(listener);
|
|
137
|
+
return () => this.failures.delete(listener);
|
|
138
|
+
}
|
|
139
|
+
onRequest(handler) {
|
|
140
|
+
this.requestHandler = handler;
|
|
141
|
+
}
|
|
142
|
+
async close() {
|
|
143
|
+
if (this.closed) return this.exit;
|
|
144
|
+
this.closed = true;
|
|
145
|
+
for (const p of this.pending.values()) {
|
|
146
|
+
clearTimeout(p.timer);
|
|
147
|
+
p.reject(unanswered(new Error("Runtime closed")));
|
|
148
|
+
}
|
|
149
|
+
this.pending.clear();
|
|
150
|
+
this.listeners.clear();
|
|
151
|
+
this.failures.clear();
|
|
152
|
+
this.child.stdin.end();
|
|
153
|
+
const timer = setTimeout(() => {
|
|
154
|
+
if (process.platform === "win32" && this.child.pid) execFile("taskkill.exe", ["/PID", String(this.child.pid), "/T", "/F"], { windowsHide: true }, () => {
|
|
155
|
+
});
|
|
156
|
+
else this.child.kill("SIGKILL");
|
|
157
|
+
}, 1500);
|
|
158
|
+
let deadline;
|
|
159
|
+
try {
|
|
160
|
+
await Promise.race([this.exit, new Promise((resolve) => {
|
|
161
|
+
deadline = setTimeout(resolve, 4e3);
|
|
162
|
+
})]);
|
|
163
|
+
} finally {
|
|
164
|
+
clearTimeout(timer);
|
|
165
|
+
clearTimeout(deadline);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
export {
|
|
170
|
+
CodexTransport
|
|
171
|
+
};
|
package/dist/usage.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SessionUsage } from './events.js';
|
|
2
|
+
/** Account-free usage data shown in ALP's viewers. */
|
|
3
|
+
export type UsageWindow = {
|
|
4
|
+
name: string;
|
|
5
|
+
usedPercent: number | null;
|
|
6
|
+
resetsAt: string | null;
|
|
7
|
+
};
|
|
8
|
+
export type ProviderUsage = {
|
|
9
|
+
runtime: 'codex' | 'claude';
|
|
10
|
+
available: boolean;
|
|
11
|
+
checkedAt: string;
|
|
12
|
+
plan: string | null;
|
|
13
|
+
limited: boolean;
|
|
14
|
+
windows: UsageWindow[];
|
|
15
|
+
};
|
|
16
|
+
export declare function providerUsage(runtime: ProviderUsage['runtime'], usage: any, checkedAt?: string): ProviderUsage;
|
|
17
|
+
/**
|
|
18
|
+
* A session's usage after one token report (ALPD §57), as Paseo's AgentUsage. Every transport
|
|
19
|
+
* reports as Codex's thread/tokenUsage/updated does: `last` the latest model call, of which
|
|
20
|
+
* `totalTokens` is what the context holds now; `modelContextWindow` the window once known;
|
|
21
|
+
* `totalCostUsd` the session's cost where the runtime counts it. The fields a report carries
|
|
22
|
+
* replace the session's; the others are kept, except that the latest response's input, cached and
|
|
23
|
+
* output counts are replaced together. Undefined when the report changes nothing.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sessionUsage(previous: SessionUsage | undefined, report: any): SessionUsage | undefined;
|
package/dist/usage.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// packages/runtime/src/usage.ts
|
|
2
|
+
var text = (value) => typeof value === "string" && value.trim() ? value : null;
|
|
3
|
+
function resetTime(value) {
|
|
4
|
+
const ms = typeof value === "number" ? value * 1e3 : typeof value === "string" ? Date.parse(value) : NaN;
|
|
5
|
+
return Number.isFinite(ms) && Math.abs(ms) <= 864e13 ? new Date(ms).toISOString() : null;
|
|
6
|
+
}
|
|
7
|
+
function windowName(window, index) {
|
|
8
|
+
if (text(window.name)) return window.name.replaceAll("_", " ");
|
|
9
|
+
const minutes = window.windowMinutes;
|
|
10
|
+
if (typeof minutes === "number" && minutes > 0) {
|
|
11
|
+
if (minutes % 1440 === 0) return `${minutes / 1440} day window`;
|
|
12
|
+
if (minutes % 60 === 0) return `${minutes / 60} hour window`;
|
|
13
|
+
return `${minutes} minute window`;
|
|
14
|
+
}
|
|
15
|
+
return `Window ${index + 1}`;
|
|
16
|
+
}
|
|
17
|
+
function providerUsage(runtime, usage, checkedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
18
|
+
const limits = Array.isArray(usage?.limits) ? usage.limits : [];
|
|
19
|
+
const windows = (limits.length ? limits.flatMap((limit) => (Array.isArray(limit?.windows) ? limit.windows : []).map((window) => ({ ...window, group: text(limit.name) ?? text(limit.model) }))) : Array.isArray(usage?.windows) ? usage.windows : []).filter((window) => window && typeof window === "object").map((window, index) => ({
|
|
20
|
+
name: `${window.group ? `${window.group} \xB7 ` : ""}${windowName(window, index)}`,
|
|
21
|
+
usedPercent: typeof window.usedPercent === "number" && Number.isFinite(window.usedPercent) ? Math.min(100, Math.max(0, window.usedPercent)) : null,
|
|
22
|
+
resetsAt: resetTime(window.resetsAt)
|
|
23
|
+
}));
|
|
24
|
+
return {
|
|
25
|
+
runtime,
|
|
26
|
+
available: usage?.available === true,
|
|
27
|
+
checkedAt,
|
|
28
|
+
plan: text(usage?.plan) ?? limits.map((limit) => text(limit?.plan)).find(Boolean) ?? null,
|
|
29
|
+
limited: usage?.ordinaryUsageAllowed === false || limits.some((limit) => limit?.spendControlReached === true) || windows.some((window) => window.usedPercent === 100),
|
|
30
|
+
windows
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
var tokens = (value, least = 0) => typeof value === "number" && Number.isInteger(value) && value >= least ? value : void 0;
|
|
34
|
+
function sessionUsage(previous, report) {
|
|
35
|
+
if (!report || typeof report !== "object") return void 0;
|
|
36
|
+
const last = report.last && typeof report.last === "object" ? report.last : {};
|
|
37
|
+
const cost = report.totalCostUsd;
|
|
38
|
+
const fields = {
|
|
39
|
+
contextWindowUsedTokens: tokens(last.totalTokens),
|
|
40
|
+
contextWindowMaxTokens: tokens(report.modelContextWindow, 1),
|
|
41
|
+
inputTokens: tokens(last.inputTokens),
|
|
42
|
+
cachedInputTokens: tokens(last.cachedInputTokens ?? report.cachedInputTokens),
|
|
43
|
+
outputTokens: tokens(last.outputTokens),
|
|
44
|
+
totalCostUsd: typeof cost === "number" && Number.isFinite(cost) && cost >= 0 ? cost : void 0
|
|
45
|
+
};
|
|
46
|
+
const next = { ...previous };
|
|
47
|
+
if (fields.inputTokens !== void 0 || fields.cachedInputTokens !== void 0 || fields.outputTokens !== void 0) {
|
|
48
|
+
delete next.inputTokens;
|
|
49
|
+
delete next.cachedInputTokens;
|
|
50
|
+
delete next.outputTokens;
|
|
51
|
+
}
|
|
52
|
+
for (const [key, value] of Object.entries(fields)) if (value !== void 0) next[key] = value;
|
|
53
|
+
const keys = Object.keys(next);
|
|
54
|
+
if (keys.length === Object.keys(previous ?? {}).length && keys.every((key) => previous?.[key] === next[key])) return void 0;
|
|
55
|
+
return next;
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
providerUsage,
|
|
59
|
+
sessionUsage
|
|
60
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase C isolation (plans/reference/ALPD.md §16): a writing assignment may run in its
|
|
3
|
+
* own git worktree, so writers do not share a checkout. Its work is committed to a
|
|
4
|
+
* branch when it ends, and the requester merges the change into its checkout or
|
|
5
|
+
* discards it. Branches outlive their worktrees, so work is never deleted silently.
|
|
6
|
+
*/
|
|
7
|
+
export type Worktree = {
|
|
8
|
+
/** The requester's checkout, which receives the change on merge. */
|
|
9
|
+
checkout: string;
|
|
10
|
+
/** The worktree's top level, and the assignment's working directory inside it. */
|
|
11
|
+
path: string;
|
|
12
|
+
workdir: string;
|
|
13
|
+
branch: string;
|
|
14
|
+
/** The requester's state when the assignment started: HEAD plus uncommitted tracked changes. */
|
|
15
|
+
base: string;
|
|
16
|
+
/** checkoutFingerprint of the requester's checkout then, to tell whether it changed since. */
|
|
17
|
+
fingerprint?: string;
|
|
18
|
+
};
|
|
19
|
+
export type WorktreeChange = {
|
|
20
|
+
commit: string;
|
|
21
|
+
files: string[];
|
|
22
|
+
stat: string;
|
|
23
|
+
};
|
|
24
|
+
/** The environment ALP runs git in: the caller's, without git's own context, and never prompting. */
|
|
25
|
+
export declare function gitEnvironment(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
26
|
+
/** The top level of the git checkout containing `directory`, or undefined outside git. */
|
|
27
|
+
export declare function checkoutOf(directory: string): Promise<string | undefined>;
|
|
28
|
+
/** The key that writers of one checkout share: its top level, or the directory itself outside git. */
|
|
29
|
+
export declare function checkoutKey(directory: string): Promise<string>;
|
|
30
|
+
/** Whether the checkout containing `directory` has a local branch of that name. */
|
|
31
|
+
export declare function branchExists(directory: string, branch: string): Promise<boolean>;
|
|
32
|
+
/** Creates a worktree for `id` from the current state of the checkout containing `workdir`. */
|
|
33
|
+
/**
|
|
34
|
+
* Creates a worktree for `id` from the current state of the checkout containing `workdir`,
|
|
35
|
+
* or, with `from`, from an earlier assignment's committed change, keeping that assignment's
|
|
36
|
+
* base so a merge applies both changes together.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createWorktree(workdir: string, root: string, id: string, from?: Pick<Worktree, 'base' | 'fingerprint'> & {
|
|
39
|
+
commit: string;
|
|
40
|
+
}): Promise<Worktree>;
|
|
41
|
+
/**
|
|
42
|
+
* Continues an assignment in its worktree after a restart. A worktree that is still valid
|
|
43
|
+
* is reused as is, whatever it holds. A directory left without valid git metadata (a crash
|
|
44
|
+
* mid-write) is never deleted: it moves aside to `preserved` and the branch is checked out
|
|
45
|
+
* again at its place.
|
|
46
|
+
*/
|
|
47
|
+
export declare function reattachWorktree(worktree: Worktree): Promise<Worktree & {
|
|
48
|
+
preserved?: string;
|
|
49
|
+
}>;
|
|
50
|
+
/** A digest of a checkout's state: HEAD, its uncommitted changes, and the names of untracked files. */
|
|
51
|
+
export declare function checkoutFingerprint(checkout: string): Promise<string | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Links the project's node_modules into the same place in a worktree that has none,
|
|
54
|
+
* so its build and tests run; returns what undoes it. Commits never see the link,
|
|
55
|
+
* because ALP removes it before the worktree is committed again.
|
|
56
|
+
*/
|
|
57
|
+
export declare function linkModules(projectDir: string, worktreeDir: string): Promise<() => Promise<void>>;
|
|
58
|
+
/** Commits whatever the assignment left in its worktree and describes the change from its base. */
|
|
59
|
+
export declare function commitWorktree(worktree: Worktree, message: string): Promise<WorktreeChange>;
|
|
60
|
+
/**
|
|
61
|
+
* Applies the change to the requester's working tree without committing or touching
|
|
62
|
+
* its index. A patch that applies cleanly is applied as is; otherwise each file is
|
|
63
|
+
* merged three ways against the requester's current file, leaving conflict markers.
|
|
64
|
+
* Where a file was deleted on one side or is binary, the requester's version is kept
|
|
65
|
+
* and reported as a conflict.
|
|
66
|
+
*/
|
|
67
|
+
export declare function mergeWorktree(worktree: Worktree, change: WorktreeChange): Promise<{
|
|
68
|
+
status: "empty";
|
|
69
|
+
files: never[];
|
|
70
|
+
conflicts?: undefined;
|
|
71
|
+
} | {
|
|
72
|
+
status: "applied";
|
|
73
|
+
files: string[];
|
|
74
|
+
conflicts?: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
status: "conflicts";
|
|
77
|
+
files: string[];
|
|
78
|
+
conflicts: string[];
|
|
79
|
+
}>;
|
|
80
|
+
/** Removes the worktree directory; the branch stays unless `deleteBranch`. */
|
|
81
|
+
export declare function removeWorktree(worktree: Worktree, { deleteBranch }?: {
|
|
82
|
+
deleteBranch?: boolean | undefined;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Why reclaimWorktrees left a directory in place: `invalid`, not the top level of a working git
|
|
86
|
+
* worktree; `not-linked`, a repository of its own rather than a worktree of one; `other-branch`,
|
|
87
|
+
* another branch or a detached HEAD, which does not hold this work; `commit-failed`, its work could
|
|
88
|
+
* not be committed (`detail` says why); `uncommitted`, something was still not committed after
|
|
89
|
+
* that; `ignored-files`, its work is committed but it holds ignored files that exist nowhere else.
|
|
90
|
+
*/
|
|
91
|
+
export type LeftWorktree = {
|
|
92
|
+
name: string;
|
|
93
|
+
path: string;
|
|
94
|
+
reason: 'invalid' | 'not-linked' | 'other-branch' | 'commit-failed' | 'uncommitted' | 'ignored-files';
|
|
95
|
+
branch?: string;
|
|
96
|
+
detail?: string;
|
|
97
|
+
files?: string[];
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* After a crash: commits work left in worktrees under `root` to their branches and
|
|
101
|
+
* removes the directories. Returns the branches that were kept, and the directories left in
|
|
102
|
+
* place with the reason. A directory is removed only once everything in it is committed to
|
|
103
|
+
* its own `alp/<name>` branch and it holds no ignored file to keep (`.env*`); any other one
|
|
104
|
+
* stays, so recovery reuses or preserves it and nothing uncommitted is lost. Stale locks a
|
|
105
|
+
* killed git command left in such a worktree are removed first (clearStaleLocks).
|
|
106
|
+
*/
|
|
107
|
+
export declare function reclaimWorktrees(root: string): Promise<{
|
|
108
|
+
kept: string[];
|
|
109
|
+
left: LeftWorktree[];
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* A disposable copy of a checkout for an assignment that may build and test but
|
|
113
|
+
* must not touch the requester's tree (ALPD §26): a detached worktree at the
|
|
114
|
+
* requester's HEAD with its uncommitted changes applied as uncommitted changes, so
|
|
115
|
+
* `git diff` and `git status` there show what they show the requester, plus its
|
|
116
|
+
* untracked files.
|
|
117
|
+
* A top-level node_modules is linked, not copied. Nothing in it is ever merged.
|
|
118
|
+
*/
|
|
119
|
+
export type Copy = {
|
|
120
|
+
checkout: string;
|
|
121
|
+
path: string;
|
|
122
|
+
workdir: string;
|
|
123
|
+
};
|
|
124
|
+
export declare function createCopy(workdir: string, root: string, id: string): Promise<Copy>;
|
|
125
|
+
export declare function removeCopy(copy: Copy): Promise<void>;
|
|
126
|
+
/** After a crash: removes copies left under `root`; they hold nothing to keep. */
|
|
127
|
+
export declare function reclaimCopies(root: string): Promise<number>;
|