@anhlp/alp-daemon 0.0.1-beta.6 → 0.0.1-beta.8
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 +1 -1
- package/dist/alpd.js +10508 -4233
- package/dist/build-manifest.json +8 -2
- package/dist/git.d.ts +6 -1
- package/dist/git.js +86 -32
- package/dist/main.js +51 -10
- package/dist/model-catalog.d.ts +2 -0
- package/dist/model-catalog.js +44 -0
- package/dist/native-terminal.js +2 -3
- package/dist/operations.d.ts +8 -1
- package/dist/operations.js +32 -5
- package/dist/scheduler.js +2 -0
- package/dist/server.js +61 -11
- package/dist/terminals.d.ts +12 -2
- package/dist/terminals.js +3 -3
- package/dist/windows-terminal.d.ts +6 -3
- package/dist/windows-terminal.js +30 -73
- package/package.json +6 -6
- package/src/git.ts +102 -22
- package/src/main.ts +56 -7
- package/src/model-catalog.ts +36 -0
- package/src/native-terminal.ts +2 -5
- package/src/operations.ts +18 -5
- package/src/scheduler.ts +6 -0
- package/src/server.ts +66 -12
- package/src/terminals.ts +18 -6
- package/src/windows-terminal.ts +33 -82
package/dist/build-manifest.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.1-beta.
|
|
2
|
+
"version": "0.0.1-beta.8",
|
|
3
3
|
"entries": {
|
|
4
4
|
"packages/daemon/dist/alpd.js": {
|
|
5
5
|
"inputs": [
|
|
6
|
+
"packages/client/src/acp-probe.js",
|
|
6
7
|
"packages/client/src/index.js",
|
|
7
8
|
"packages/client/src/ipc.js",
|
|
9
|
+
"packages/client/src/mcp-probe.js",
|
|
8
10
|
"packages/client/src/portable.js",
|
|
9
11
|
"packages/client/src/rpc/client.js",
|
|
10
12
|
"packages/client/src/rpc/errors.js",
|
|
@@ -41,6 +43,7 @@
|
|
|
41
43
|
"packages/core/src/resolver.js",
|
|
42
44
|
"packages/core/src/safe-path.js",
|
|
43
45
|
"packages/core/src/shell.js",
|
|
46
|
+
"packages/core/src/skill-validate.js",
|
|
44
47
|
"packages/core/src/state-schema.js",
|
|
45
48
|
"packages/core/src/task-rows.js",
|
|
46
49
|
"packages/core/src/tasks.js",
|
|
@@ -63,6 +66,7 @@
|
|
|
63
66
|
"packages/daemon/src/lifecycle.ts",
|
|
64
67
|
"packages/daemon/src/lock.ts",
|
|
65
68
|
"packages/daemon/src/main.ts",
|
|
69
|
+
"packages/daemon/src/model-catalog.ts",
|
|
66
70
|
"packages/daemon/src/native-terminal.ts",
|
|
67
71
|
"packages/daemon/src/operations.ts",
|
|
68
72
|
"packages/daemon/src/registry.ts",
|
|
@@ -110,13 +114,15 @@
|
|
|
110
114
|
"packages/runtime/src/runtime-context.ts",
|
|
111
115
|
"packages/runtime/src/runtime.ts",
|
|
112
116
|
"packages/runtime/src/session-config.ts",
|
|
117
|
+
"packages/runtime/src/skill-resources.ts",
|
|
113
118
|
"packages/runtime/src/tool-detail.ts",
|
|
114
119
|
"packages/runtime/src/tool-results.ts",
|
|
115
120
|
"packages/runtime/src/tools.ts",
|
|
116
121
|
"packages/runtime/src/transport.ts",
|
|
117
122
|
"packages/runtime/src/usage.ts",
|
|
118
123
|
"packages/runtime/src/workspace.ts",
|
|
119
|
-
"packages/runtime/src/worktree-domain.ts"
|
|
124
|
+
"packages/runtime/src/worktree-domain.ts",
|
|
125
|
+
"packages/runtime/src/write-error.ts"
|
|
120
126
|
],
|
|
121
127
|
"external": [
|
|
122
128
|
"child_process",
|
package/dist/git.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Stats } from 'node:fs';
|
|
1
2
|
import type { GitCompare, GitDiffPage, GitFacts, GitStatus } from '@anhlp/alp-protocol';
|
|
2
3
|
/**
|
|
3
4
|
* `workspace.git.status` and `workspace.git.diff` (docs/protocol/alp-json-rpc-v1.md §12.5): the
|
|
@@ -40,6 +41,8 @@ export declare const GIT_READ: Readonly<{
|
|
|
40
41
|
maxErrorBytes: number;
|
|
41
42
|
/** Configuration, change list and untracked list output, at most. */
|
|
42
43
|
maxListBytes: number;
|
|
44
|
+
/** Ancestors retained per listing; exceeding the budget fails the read closed. */
|
|
45
|
+
maxAncestors: 16384;
|
|
43
46
|
/** One patch stream, at most (its files are at most a window's worth of content). */
|
|
44
47
|
maxPatchStreamBytes: number;
|
|
45
48
|
/** One side of a file scanned for a private key; a larger side is `too_large`. */
|
|
@@ -77,6 +80,8 @@ export type GitReaderOptions = {
|
|
|
77
80
|
log?: (message: string, fields: Record<string, unknown>) => void;
|
|
78
81
|
/** Tests only: called after a window's contents were scanned and before Git writes their patch, where a racing writer could change a file. */
|
|
79
82
|
probe?: (step: 'scanned') => Promise<void> | void;
|
|
83
|
+
/** Tests only: how an untracked path's ancestor directories are inspected (default async lstat), to inject its failures. */
|
|
84
|
+
inspect?: (file: string) => Stats | Promise<Stats>;
|
|
80
85
|
};
|
|
81
86
|
type DiffParams = {
|
|
82
87
|
workspaceId: string;
|
|
@@ -84,7 +89,7 @@ type DiffParams = {
|
|
|
84
89
|
path?: string;
|
|
85
90
|
cursor?: string;
|
|
86
91
|
};
|
|
87
|
-
export declare function createGitReader({ registry, binary, timeoutMs, log, probe }: GitReaderOptions): {
|
|
92
|
+
export declare function createGitReader({ registry, binary, timeoutMs, log, probe, inspect }: GitReaderOptions): {
|
|
88
93
|
status: (workspaceId: unknown) => Promise<GitStatus>;
|
|
89
94
|
diff: (params: DiffParams) => Promise<GitDiffPage>;
|
|
90
95
|
facts: (directory: unknown) => Promise<GitFacts>;
|
package/dist/git.js
CHANGED
|
@@ -18,6 +18,8 @@ var GIT_READ = Object.freeze({
|
|
|
18
18
|
maxErrorBytes: 16 * 1024,
|
|
19
19
|
/** Configuration, change list and untracked list output, at most. */
|
|
20
20
|
maxListBytes: 16 * 1024 * 1024,
|
|
21
|
+
/** Ancestors retained per listing; exceeding the budget fails the read closed. */
|
|
22
|
+
maxAncestors: 16384,
|
|
21
23
|
/** One patch stream, at most (its files are at most a window's worth of content). */
|
|
22
24
|
maxPatchStreamBytes: 32 * 1024 * 1024,
|
|
23
25
|
/** One side of a file scanned for a private key; a larger side is `too_large`. */
|
|
@@ -143,13 +145,15 @@ function runGit(box, args, { stdin, okCodes = [0], maxBytes = GIT_READ.maxListBy
|
|
|
143
145
|
else child.kill("SIGKILL");
|
|
144
146
|
} catch {
|
|
145
147
|
}
|
|
148
|
+
child.stdout?.resume();
|
|
146
149
|
};
|
|
147
150
|
let timer;
|
|
151
|
+
let consuming = Promise.resolve();
|
|
148
152
|
const finish = (outcome) => {
|
|
149
153
|
if (settled) return;
|
|
150
154
|
settled = true;
|
|
151
155
|
if (timer) clearTimeout(timer);
|
|
152
|
-
release
|
|
156
|
+
void consuming.then(release);
|
|
153
157
|
outcome();
|
|
154
158
|
};
|
|
155
159
|
try {
|
|
@@ -174,35 +178,43 @@ function runGit(box, args, { stdin, okCodes = [0], maxBytes = GIT_READ.maxListBy
|
|
|
174
178
|
let err = "";
|
|
175
179
|
child.stdout.on("data", (chunk) => {
|
|
176
180
|
if (settled || stopped) return;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
child.stdout.pause();
|
|
182
|
+
consuming = consuming.then(async () => {
|
|
183
|
+
if (settled || stopped) return;
|
|
184
|
+
if (onData) {
|
|
185
|
+
if (await onData(chunk)) {
|
|
186
|
+
stopped = true;
|
|
187
|
+
kill();
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
outBytes += chunk.length;
|
|
191
|
+
if (outBytes > maxBytes) throw new GitReadFailed("output over its bound");
|
|
192
|
+
out.push(chunk);
|
|
181
193
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (outBytes > maxBytes) finish(() => {
|
|
194
|
+
}).then(() => {
|
|
195
|
+
if (!settled && !stopped) child.stdout.resume();
|
|
196
|
+
}, (error) => finish(() => {
|
|
186
197
|
kill();
|
|
187
|
-
reject(
|
|
188
|
-
});
|
|
189
|
-
else out.push(chunk);
|
|
198
|
+
reject(error);
|
|
199
|
+
}));
|
|
190
200
|
});
|
|
191
201
|
child.stderr.on("data", (chunk) => {
|
|
192
202
|
if (err.length < GIT_READ.maxErrorBytes) err += chunk.toString("utf8");
|
|
193
203
|
});
|
|
194
204
|
child.on("error", (error) => finish(() => reject(new GitReadFailed(`spawn: ${error.message}`))));
|
|
195
|
-
child.on("close", (code) =>
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
child.on("close", (code) => {
|
|
206
|
+
void consuming.then(() => finish(() => {
|
|
207
|
+
if (stopped) {
|
|
208
|
+
resolve({ code: code ?? -1, stdout: Buffer.alloc(0), stopped: true });
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (code === null || !okCodes.includes(code)) {
|
|
212
|
+
reject(new GitReadFailed(`${args[0]} exit ${code}: ${err.trim().slice(0, 1e3)}`));
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
resolve({ code, stdout: Buffer.concat(out), stopped: false });
|
|
216
|
+
}));
|
|
217
|
+
});
|
|
206
218
|
if (stdin !== void 0) {
|
|
207
219
|
child.stdin.on("error", () => {
|
|
208
220
|
});
|
|
@@ -559,8 +571,30 @@ function sized(file) {
|
|
|
559
571
|
return { file: large, cost: cost(large) };
|
|
560
572
|
}
|
|
561
573
|
var PAGE_BYTES = WORKSPACE_GIT.maxTotalBytes - 16 * 1024;
|
|
574
|
+
async function untrackedEntry(root, name, ancestors, inspect, deadline) {
|
|
575
|
+
const segments = name.split("/");
|
|
576
|
+
for (let count = 1; count < segments.length; count++) {
|
|
577
|
+
if (Date.now() >= deadline) throw new GitReadFailed("timed out");
|
|
578
|
+
const prefix = segments.slice(0, count).join("/");
|
|
579
|
+
let ancestor = ancestors.get(prefix);
|
|
580
|
+
if (ancestor === void 0) {
|
|
581
|
+
if (ancestors.size >= GIT_READ.maxAncestors) throw new GitReadFailed("ancestor cache over its bound");
|
|
582
|
+
try {
|
|
583
|
+
const info = await inspect(path.join(root, ...segments.slice(0, count)));
|
|
584
|
+
ancestor = info.isSymbolicLink() ? "link" : info.isDirectory() ? "directory" : "uninspectable";
|
|
585
|
+
} catch {
|
|
586
|
+
ancestor = "uninspectable";
|
|
587
|
+
}
|
|
588
|
+
if (Date.now() >= deadline) throw new GitReadFailed("timed out");
|
|
589
|
+
ancestors.set(prefix, ancestor);
|
|
590
|
+
}
|
|
591
|
+
if (ancestor === "link") return prefix;
|
|
592
|
+
if (ancestor === "uninspectable") return void 0;
|
|
593
|
+
}
|
|
594
|
+
return name;
|
|
595
|
+
}
|
|
562
596
|
function createGitReader({ registry, binary = "git", timeoutMs = GIT_READ.timeoutMs, log = () => {
|
|
563
|
-
}, probe }) {
|
|
597
|
+
}, probe, inspect = lstat }) {
|
|
564
598
|
const key = randomBytes(32);
|
|
565
599
|
const mac = (scope) => createHmac("sha256", key).update(scope).digest("base64url").slice(0, 32);
|
|
566
600
|
async function workspaceRoot(workspaceId) {
|
|
@@ -647,6 +681,8 @@ function createGitReader({ registry, binary = "git", timeoutMs = GIT_READ.timeou
|
|
|
647
681
|
const digest = createHash("sha256");
|
|
648
682
|
let pending = "";
|
|
649
683
|
let pendingRename;
|
|
684
|
+
const ancestors = /* @__PURE__ */ new Map();
|
|
685
|
+
const collapsed = /* @__PURE__ */ new Set();
|
|
650
686
|
const take = (row) => {
|
|
651
687
|
dirty = true;
|
|
652
688
|
if (blockedFilePath(row.path) || row.oldPath && blockedFilePath(row.oldPath) || [...row.path].length > 4096 || [...row.oldPath ?? ""].length > 4096) {
|
|
@@ -660,7 +696,7 @@ function createGitReader({ registry, binary = "git", timeoutMs = GIT_READ.timeou
|
|
|
660
696
|
files.push(row);
|
|
661
697
|
return false;
|
|
662
698
|
};
|
|
663
|
-
const record = (field) => {
|
|
699
|
+
const record = async (field) => {
|
|
664
700
|
if (pendingRename) {
|
|
665
701
|
const [kind2, xy] = pendingRename;
|
|
666
702
|
pendingRename = void 0;
|
|
@@ -695,8 +731,18 @@ function createGitReader({ registry, binary = "git", timeoutMs = GIT_READ.timeou
|
|
|
695
731
|
return take({ path: rowPath, change, staged: x !== ".", unstaged: y !== "." });
|
|
696
732
|
}
|
|
697
733
|
if (kind === "?") {
|
|
698
|
-
const
|
|
699
|
-
|
|
734
|
+
const listed = field.slice(2).replace(/\/$/, "");
|
|
735
|
+
if (!listed) return false;
|
|
736
|
+
const rowPath = await untrackedEntry(repo.root, listed, ancestors, inspect, repo.deadline);
|
|
737
|
+
if (rowPath === void 0) {
|
|
738
|
+
dirty = true;
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
if (rowPath !== listed) {
|
|
742
|
+
if (collapsed.has(rowPath)) return false;
|
|
743
|
+
collapsed.add(rowPath);
|
|
744
|
+
}
|
|
745
|
+
return take({ path: rowPath, change: "untracked", staged: false, unstaged: true });
|
|
700
746
|
}
|
|
701
747
|
if (kind === "!") return false;
|
|
702
748
|
failed("unexpected status");
|
|
@@ -704,12 +750,12 @@ function createGitReader({ registry, binary = "git", timeoutMs = GIT_READ.timeou
|
|
|
704
750
|
};
|
|
705
751
|
let seen = 0;
|
|
706
752
|
const { stopped } = await runGit(repo, ["status", "--porcelain=v2", "-z", "--branch", "--ahead-behind", "--untracked-files=all", "--ignored=no", "--ignore-submodules=dirty", "--find-renames"], {
|
|
707
|
-
onData: (chunk) => {
|
|
753
|
+
onData: async (chunk) => {
|
|
708
754
|
seen += chunk.length;
|
|
709
755
|
digest.update(chunk);
|
|
710
756
|
const fields = (pending + chunk.toString("utf8")).split("\0");
|
|
711
757
|
pending = fields.pop();
|
|
712
|
-
for (const field of fields) if (field && record(field)) return true;
|
|
758
|
+
for (const field of fields) if (field && await record(field)) return true;
|
|
713
759
|
if (seen > GIT_READ.maxListBytes) {
|
|
714
760
|
truncated = true;
|
|
715
761
|
return true;
|
|
@@ -843,12 +889,20 @@ function createGitReader({ registry, binary = "git", timeoutMs = GIT_READ.timeou
|
|
|
843
889
|
let hidden = 0;
|
|
844
890
|
let more = false;
|
|
845
891
|
let pending = "";
|
|
892
|
+
const ancestors = /* @__PURE__ */ new Map();
|
|
893
|
+
const collapsed = /* @__PURE__ */ new Set();
|
|
846
894
|
const { stopped } = await runGit(repo, ["ls-files", "-z", "--others", "--exclude-standard", "--", ...relative ? [relative] : []], {
|
|
847
|
-
onData: (chunk) => {
|
|
895
|
+
onData: async (chunk) => {
|
|
848
896
|
const fields = (pending + chunk.toString("utf8")).split("\0");
|
|
849
897
|
pending = fields.pop();
|
|
850
|
-
for (const
|
|
851
|
-
if (!
|
|
898
|
+
for (const listed of fields) {
|
|
899
|
+
if (!listed || listed.endsWith("/")) continue;
|
|
900
|
+
const name = await untrackedEntry(repo.root, listed, ancestors, inspect, repo.deadline);
|
|
901
|
+
if (name === void 0) continue;
|
|
902
|
+
if (name !== listed) {
|
|
903
|
+
if (collapsed.has(name)) continue;
|
|
904
|
+
collapsed.add(name);
|
|
905
|
+
}
|
|
852
906
|
if (relative && name !== relative) continue;
|
|
853
907
|
if (blockedFilePath(name) || [...name].length > 4096) {
|
|
854
908
|
hidden++;
|