@anhlp/alp-daemon 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.
Files changed (115) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +14 -2
  4. package/dist/THIRD-PARTY-NOTICES.txt +456 -0
  5. package/dist/alp-templates.d.ts +5 -0
  6. package/dist/alpd.js +64050 -0
  7. package/dist/attachments.d.ts +187 -0
  8. package/dist/attachments.js +856 -0
  9. package/dist/build-manifest.json +150 -0
  10. package/dist/conversation.d.ts +119 -0
  11. package/dist/conversation.js +688 -0
  12. package/dist/disk.d.ts +67 -0
  13. package/dist/disk.js +152 -0
  14. package/dist/files.d.ts +262 -0
  15. package/dist/files.js +674 -0
  16. package/dist/git.d.ts +98 -0
  17. package/dist/git.js +1246 -0
  18. package/dist/gitignore.d.ts +62 -0
  19. package/dist/gitignore.js +254 -0
  20. package/dist/history.d.ts +24 -0
  21. package/dist/history.js +149 -0
  22. package/dist/index.d.ts +11 -0
  23. package/dist/index.js +28 -0
  24. package/dist/lifecycle.d.ts +101 -0
  25. package/dist/lifecycle.js +239 -0
  26. package/dist/lock.d.ts +21 -0
  27. package/dist/lock.js +42 -0
  28. package/dist/main.d.ts +1 -0
  29. package/dist/main.js +363 -0
  30. package/dist/model-catalog.d.ts +2 -0
  31. package/dist/model-catalog.js +44 -0
  32. package/dist/native-entry.d.ts +2 -0
  33. package/dist/native-entry.js +3 -0
  34. package/dist/native-register.d.ts +1 -0
  35. package/dist/native-register.js +13 -0
  36. package/dist/native-terminal.d.ts +45 -0
  37. package/dist/native-terminal.js +201 -0
  38. package/dist/operations.d.ts +40 -0
  39. package/dist/operations.js +313 -0
  40. package/dist/registry.d.ts +89 -0
  41. package/dist/registry.js +343 -0
  42. package/dist/rpc-error.d.ts +6 -0
  43. package/dist/rpc-error.js +11 -0
  44. package/dist/scheduler.d.ts +96 -0
  45. package/dist/scheduler.js +298 -0
  46. package/dist/schedules.d.ts +70 -0
  47. package/dist/schedules.js +246 -0
  48. package/dist/server.d.ts +60 -0
  49. package/dist/server.js +1958 -0
  50. package/dist/store.d.ts +178 -0
  51. package/dist/store.js +386 -0
  52. package/dist/terminal-native/README.md +201 -0
  53. package/dist/terminal-native/prebuilt/darwin-arm64/manifest.json +11 -0
  54. package/dist/terminal-native/prebuilt/darwin-arm64/terminal-owner +0 -0
  55. package/dist/terminal-native/prebuilt/darwin-x64/manifest.json +11 -0
  56. package/dist/terminal-native/prebuilt/darwin-x64/terminal-owner +0 -0
  57. package/dist/terminal-native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
  58. package/dist/terminal-native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
  59. package/dist/terminal-native/prebuilt/linux-arm64-musl/manifest.json +10 -0
  60. package/dist/terminal-native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
  61. package/dist/terminal-native/prebuilt/linux-x64-glibc/manifest.json +10 -0
  62. package/dist/terminal-native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
  63. package/dist/terminal-native/prebuilt/linux-x64-musl/manifest.json +10 -0
  64. package/dist/terminal-native/prebuilt/linux-x64-musl/terminal-owner +0 -0
  65. package/dist/terminal-native/terminal-owner.c +389 -0
  66. package/dist/terminal-screen.d.ts +24 -0
  67. package/dist/terminal-screen.js +99 -0
  68. package/dist/terminals.d.ts +203 -0
  69. package/dist/terminals.js +570 -0
  70. package/dist/windows-terminal.d.ts +32 -0
  71. package/dist/windows-terminal.js +79 -0
  72. package/dist/worktrees.d.ts +65 -0
  73. package/dist/worktrees.js +318 -0
  74. package/native/README.md +201 -0
  75. package/native/prebuilt/darwin-arm64/manifest.json +11 -0
  76. package/native/prebuilt/darwin-arm64/terminal-owner +0 -0
  77. package/native/prebuilt/darwin-x64/manifest.json +11 -0
  78. package/native/prebuilt/darwin-x64/terminal-owner +0 -0
  79. package/native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
  80. package/native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
  81. package/native/prebuilt/linux-arm64-musl/manifest.json +10 -0
  82. package/native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
  83. package/native/prebuilt/linux-x64-glibc/manifest.json +10 -0
  84. package/native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
  85. package/native/prebuilt/linux-x64-musl/manifest.json +10 -0
  86. package/native/prebuilt/linux-x64-musl/terminal-owner +0 -0
  87. package/native/terminal-owner.c +389 -0
  88. package/package.json +163 -4
  89. package/src/alp-templates.d.ts +5 -0
  90. package/src/attachments.ts +908 -0
  91. package/src/conversation.ts +857 -0
  92. package/src/disk.ts +175 -0
  93. package/src/files.ts +884 -0
  94. package/src/git.ts +1220 -0
  95. package/src/gitignore.ts +277 -0
  96. package/src/history.ts +118 -0
  97. package/src/index.ts +12 -0
  98. package/src/lifecycle.ts +283 -0
  99. package/src/lock.ts +53 -0
  100. package/src/main.ts +381 -0
  101. package/src/model-catalog.ts +36 -0
  102. package/src/native-entry.ts +5 -0
  103. package/src/native-register.ts +21 -0
  104. package/src/native-terminal.ts +127 -0
  105. package/src/operations.ts +329 -0
  106. package/src/registry.ts +238 -0
  107. package/src/rpc-error.ts +4 -0
  108. package/src/scheduler.ts +438 -0
  109. package/src/schedules.ts +297 -0
  110. package/src/server.ts +2238 -0
  111. package/src/store.ts +449 -0
  112. package/src/terminal-screen.ts +74 -0
  113. package/src/terminals.ts +653 -0
  114. package/src/windows-terminal.ts +74 -0
  115. package/src/worktrees.ts +382 -0
@@ -0,0 +1,313 @@
1
+ // packages/daemon/src/operations.ts
2
+ import { createHash, createHmac, randomBytes } from "node:crypto";
3
+ import { lstat, stat } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { CAPABILITY, ERROR, RPC_ERROR } from "@anhlp/alp-protocol";
6
+ import { closeTask, createTask, epicReport, loadTasks, rejectGate, reopenTask, resolveGate } from "@anhlp/alp-core/tasks";
7
+ import { taskRows } from "@anhlp/alp-core/task-rows";
8
+ import { deleteEntry, duplicateEntry, getEntry, listEntries, renameEntry, saveEntry, setGivenSkills } from "@anhlp/alp-core/library-edit";
9
+ import { listTeams } from "@anhlp/alp-core/teams";
10
+ import { catalogEntries } from "@anhlp/alp-runtime/index";
11
+ import { listProviders } from "@anhlp/alp-core/providers";
12
+ import { languageSetting, setLanguage, LANGUAGE_CHARS } from "@anhlp/alp-core/user-settings";
13
+ import { syncProjectSettings } from "@anhlp/alp-core/init";
14
+ import { RpcError } from "./rpc-error.js";
15
+ var REQUEST_TTL_MS = 10 * 60 * 1e3;
16
+ var MAX_REQUESTS = 1e4;
17
+ var MARKER = "$secret";
18
+ var KEEP = "keep";
19
+ var SECRET_MAPS = {
20
+ mcp: [["server", "env"], ["server", "headers"]],
21
+ providers: [["provider", "env"]]
22
+ };
23
+ var failure = (code, reason, message, extra = {}) => new RpcError(code, message, { reason, ...extra });
24
+ function fromCore(error, context = {}) {
25
+ if (error instanceof RpcError || typeof error?.code !== "string" || error?.name !== "AlpError") return error;
26
+ const message = error.message;
27
+ switch (error.code) {
28
+ case "UNSAFE_LIBRARY_WRITE":
29
+ return failure(ERROR.forbidden, "library_policy", message);
30
+ case "UNSAFE_PATH":
31
+ return failure(ERROR.forbidden, "unsafe_path", message);
32
+ case "TASK_NOT_FOUND":
33
+ return failure(ERROR.notFound, "unknown_task", message);
34
+ case "TASK_CHANGED":
35
+ case "REVISION_CONFLICT":
36
+ return failure(ERROR.conflict, "revision_conflict", message);
37
+ case "INVALID_TASK":
38
+ case "TASK_CYCLE":
39
+ case "TASK_TAKEN":
40
+ case "TASK_UNVERIFIED":
41
+ return failure(ERROR.conflict, "task_state", message);
42
+ case "GATE_USER_ONLY":
43
+ return failure(ERROR.forbidden, "user_only", message);
44
+ case "TASKS_LOCKED":
45
+ return failure(ERROR.unavailable, "busy", message);
46
+ case "IN_USE":
47
+ return failure(ERROR.conflict, "in_use", message);
48
+ case "INVALID_SCOPE":
49
+ return failure(RPC_ERROR.invalidParams, "invalid_scope", message);
50
+ case "INVALID_LIBRARY":
51
+ case "INVALID_SETTINGS":
52
+ return failure(ERROR.failed, "unreadable", message);
53
+ }
54
+ if (error.code === "NOT_FOUND" || error.code.endsWith("_NOT_FOUND")) {
55
+ return context.notFound === "invalid_entry" ? failure(RPC_ERROR.invalidParams, "invalid_entry", message) : failure(ERROR.notFound, "not_found", message);
56
+ }
57
+ if (error.code.startsWith("INVALID_")) return failure(RPC_ERROR.invalidParams, "invalid_entry", message);
58
+ return error;
59
+ }
60
+ var object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
61
+ var pointer = (parts) => parts.map((part) => `/${part.replaceAll("~", "~0").replaceAll("/", "~1")}`).join("");
62
+ var isMarker = (value) => object(value) && Object.keys(value).length === 1 && value[MARKER] === KEEP;
63
+ var at = (content, parts) => parts.reduce((value, part) => object(value) ? value[part] : void 0, content);
64
+ function redact(kind, content) {
65
+ const copy = structuredClone(content);
66
+ const secrets = [];
67
+ for (const parts of SECRET_MAPS[kind] ?? []) {
68
+ const map = at(copy, parts);
69
+ if (!object(map)) continue;
70
+ for (const key of Object.keys(map)) {
71
+ if (typeof map[key] !== "string") continue;
72
+ map[key] = { [MARKER]: KEEP };
73
+ secrets.push(pointer([...parts, key]));
74
+ }
75
+ }
76
+ return { content: copy, secrets };
77
+ }
78
+ function unredact(kind, content, previous) {
79
+ const next = structuredClone(content);
80
+ for (const parts of SECRET_MAPS[kind] ?? []) {
81
+ const map = at(next, parts);
82
+ if (!object(map)) continue;
83
+ const stored = at(previous, parts);
84
+ for (const key of Object.keys(map)) {
85
+ if (!isMarker(map[key])) continue;
86
+ const value = object(stored) ? stored[key] : void 0;
87
+ if (typeof value !== "string") throw failure(RPC_ERROR.invalidParams, "secret_marker", `There is no stored value of ${pointer([...parts, key])} to keep; send the value instead`);
88
+ map[key] = value;
89
+ }
90
+ }
91
+ const stray = (value, parts) => {
92
+ if (isMarker(value) || object(value) && Object.hasOwn(value, MARKER)) return pointer(parts);
93
+ if (Array.isArray(value)) for (const [index, item] of value.entries()) {
94
+ const found2 = stray(item, [...parts, String(index)]);
95
+ if (found2) return found2;
96
+ }
97
+ if (object(value)) for (const [key, item] of Object.entries(value)) {
98
+ const found2 = stray(item, [...parts, key]);
99
+ if (found2) return found2;
100
+ }
101
+ return void 0;
102
+ };
103
+ const found = stray(next, []);
104
+ if (found !== void 0) throw failure(RPC_ERROR.invalidParams, "secret_marker", `${found || "content"} holds a secret marker where no secret is kept`);
105
+ return next;
106
+ }
107
+ function createOperations({ home, templates, knownProjects = () => [], onGateChange, onProviderSaved, learnedModels } = {}) {
108
+ const revisionKey = randomBytes(32);
109
+ const toWire = (revision) => revision == null ? null : `r${createHmac("sha256", revisionKey).update(revision).digest("base64url").slice(0, 22)}`;
110
+ let writes = Promise.resolve();
111
+ const serial = (work) => {
112
+ const run = writes.catch(() => {
113
+ }).then(work);
114
+ writes = run;
115
+ return run;
116
+ };
117
+ const requests = /* @__PURE__ */ new Map();
118
+ async function project(value) {
119
+ if (!path.isAbsolute(value) || path.resolve(value) !== value) throw failure(RPC_ERROR.invalidParams, "invalid_path", "projectRoot must be an absolute, normalized path");
120
+ if (!(await stat(value).catch(() => void 0))?.isDirectory()) throw failure(ERROR.notFound, "not_alp_project", `${value} is not a directory`);
121
+ const alp = await lstat(path.join(value, ".alp")).catch(() => void 0);
122
+ if (alp?.isSymbolicLink()) throw failure(ERROR.forbidden, "unsafe_path", `${path.join(value, ".alp")} is a symlink`);
123
+ if (!alp?.isDirectory()) throw failure(ERROR.notFound, "not_alp_project", `${value} is not an ALP project; run alp init there`);
124
+ return value;
125
+ }
126
+ async function where(projectRoot, scope) {
127
+ if (scope === "project" && projectRoot === void 0) throw failure(RPC_ERROR.invalidParams, "invalid_scope", "scope project needs projectRoot");
128
+ return { root: projectRoot === void 0 ? void 0 : await project(projectRoot), library: home, templates };
129
+ }
130
+ async function layer(kind, name, options, scope) {
131
+ try {
132
+ return await getEntry(kind, name, { ...options, ...scope ? { scope } : {} });
133
+ } catch (error) {
134
+ if (error?.code === "NOT_FOUND") return void 0;
135
+ throw error;
136
+ }
137
+ }
138
+ const guard = (handler, context) => async (params, caller) => {
139
+ try {
140
+ return await handler(params, caller);
141
+ } catch (error) {
142
+ throw fromCore(error, context);
143
+ }
144
+ };
145
+ const taskHandlers = {
146
+ "task.list": guard(async ({ projectRoot }) => {
147
+ const root = await project(projectRoot);
148
+ const { tasks, unreadable } = await taskRows(root);
149
+ return { projectRoot: root, tasks, unreadable, revision: createHash("sha256").update(JSON.stringify([tasks, unreadable])).digest("hex").slice(0, 16) };
150
+ }),
151
+ "task.create": guard(async ({ projectRoot, title, priority, requestId }) => {
152
+ const root = await project(projectRoot);
153
+ const create = () => createTask(root, { title: title.trim(), ...priority !== void 0 ? { priority } : {} }, "user").then((task) => ({ id: task.id }));
154
+ if (requestId === void 0) return create();
155
+ const now = Date.now();
156
+ for (const [key2, entry] of requests) if (now - entry.at > REQUEST_TTL_MS) requests.delete(key2);
157
+ const key = JSON.stringify([root, requestId]);
158
+ const fingerprint = JSON.stringify([title.trim(), priority ?? null]);
159
+ const existing = requests.get(key);
160
+ if (existing) {
161
+ if (existing.fingerprint !== fingerprint) throw failure(ERROR.conflict, "key_conflict", `Request ${requestId} was already used for another task`);
162
+ return { ...await existing.result, duplicate: true };
163
+ }
164
+ const result = create();
165
+ if (requests.size >= MAX_REQUESTS) requests.delete(requests.keys().next().value);
166
+ requests.set(key, { fingerprint, at: now, result });
167
+ result.catch(() => {
168
+ if (requests.get(key)?.result === result) requests.delete(key);
169
+ });
170
+ return result;
171
+ }),
172
+ "task.update": guard(async ({ projectRoot, id, action, note, ifRev }, caller) => {
173
+ const root = await project(projectRoot);
174
+ const options = ifRev !== void 0 ? { ifRev } : void 0;
175
+ if (action === "reopen") {
176
+ const task2 = await reopenTask(root, id, { ...note ? { note } : {} }, "user", options);
177
+ return { id: task2.id, status: task2.status, rev: task2.rev };
178
+ }
179
+ const task = await closeTask(root, id, { reason: "done", ...note ? { summary: note } : {}, agent: caller?.agent === true, channel: "web" }, "user", options);
180
+ const { tasks } = await loadTasks(root);
181
+ const landed = tasks.some((entry) => entry.parent === task.id) ? epicReport(task.id, tasks).text.split("\n")[0] : void 0;
182
+ return { id: task.id, status: task.status, rev: task.rev, ...landed ? { landed } : {} };
183
+ }),
184
+ // Approves a gate, or with reject records the user's rejection and leaves it open. Either way
185
+ // the runtime is told, so main gets the decision by mail (at least once) and the gate's card settles.
186
+ "task.gate.resolve": guard(async ({ projectRoot, id, gate, note, ifRev, choice, reject, channel = "web" }, caller) => {
187
+ const root = await project(projectRoot);
188
+ if (caller?.agent) {
189
+ const { tasks } = await loadTasks(root);
190
+ if (tasks.find((task2) => task2.id === id)?.gates.find((entry) => entry.id === gate)?.kind === "human") throw failure(ERROR.forbidden, "user_only", "Only the user decides a human gate; this connection was opened by an ALP agent");
191
+ }
192
+ const guarded = ifRev !== void 0 ? { ifRev } : {};
193
+ const task = reject === true ? await rejectGate(root, id, gate, { by: "user", channel, ...note ? { reason: note } : {}, ...guarded }) : await resolveGate(root, id, gate, { by: "user", channel, ...note ? { note } : {}, ...choice !== void 0 ? { choice } : {}, ...guarded });
194
+ await onGateChange?.(root);
195
+ return { id: task.id, status: task.status, rev: task.rev };
196
+ })
197
+ };
198
+ const libraryHandlers = {
199
+ "team.list": guard(async ({ projectRoot }) => {
200
+ const { root } = await where(projectRoot);
201
+ const teams = await listTeams(root, { library: home, templates });
202
+ return { projectRoot: root ?? null, teams: teams.map(({ path: _path, ...team }) => team) };
203
+ }),
204
+ "library.list": guard(async ({ kind, projectRoot }) => {
205
+ const options = await where(projectRoot);
206
+ const entries = await listEntries(kind, options);
207
+ return { projectRoot: options.root ?? null, entries: entries.map(({ path: _path, ...entry }) => entry) };
208
+ }),
209
+ "library.get": guard(async ({ kind, name, projectRoot, scope }) => {
210
+ const options = await where(projectRoot, scope);
211
+ const entry = await getEntry(kind, name, { ...options, ...scope ? { scope } : {} });
212
+ const { content, secrets } = redact(kind, entry.content);
213
+ return { ...entry, content, revision: toWire(entry.revision), ...secrets.length ? { secrets } : {} };
214
+ }),
215
+ "library.save": guard(({ kind, name, scope, projectRoot, content, revision, policy, sync = "none" }) => serial(async () => {
216
+ if (policy === "project-data" && sync !== "none") throw failure(ERROR.forbidden, "library_policy", "Project-data writes cannot synchronize projects");
217
+ const options = await where(projectRoot, scope);
218
+ const current = await layer(kind, name, options, scope);
219
+ if (revision !== void 0 && revision !== toWire(current?.revision ?? null)) {
220
+ throw failure(ERROR.conflict, "revision_conflict", current === void 0 ? `${kind} '${name}' is not in the ${scope}` : revision === null ? `${kind} '${name}' already exists in the ${scope}` : `${kind} '${name}' changed in the ${scope} since you opened it; reload it and apply your change again`);
221
+ }
222
+ const previous = current?.content ?? (await layer(kind, name, options))?.content;
223
+ const next = unredact(kind, content, previous);
224
+ const saved = await saveEntry(kind, name, next, { ...options, scope, policy, ...revision !== void 0 ? { revision: current?.revision ?? null } : {} });
225
+ if (kind === "providers") {
226
+ try {
227
+ onProviderSaved?.(name, previous?.provider?.enabled === false && next?.provider?.enabled !== false);
228
+ } catch {
229
+ }
230
+ }
231
+ if (kind !== "teams" || sync !== "known-projects") return { revision: toWire(saved.revision) };
232
+ const roots = new Set(options.root ? [options.root] : []);
233
+ if (scope === "library") {
234
+ for (const root of knownProjects()) if (typeof root === "string" && path.isAbsolute(root)) roots.add(path.resolve(root));
235
+ }
236
+ let syncedProjects = 0;
237
+ const syncErrors = [];
238
+ for (const root of roots) {
239
+ try {
240
+ if (await syncProjectSettings(root, { library: home, templates, teamIds: [name], replaceModels: true })) syncedProjects += 1;
241
+ } catch (error) {
242
+ syncErrors.push(`${root}: ${error instanceof Error ? error.message : String(error)}`);
243
+ }
244
+ }
245
+ return { revision: toWire(saved.revision), syncedProjects, syncErrors };
246
+ }), { notFound: "invalid_entry" }),
247
+ "library.delete": guard(({ kind, name, scope, projectRoot, revision, policy }) => serial(async () => {
248
+ const options = await where(projectRoot, scope);
249
+ const current = await layer(kind, name, options, scope);
250
+ if (!current) throw failure(ERROR.notFound, "not_found", `No ${kind} entry '${name}' in the ${scope}`);
251
+ if (revision !== void 0 && revision !== toWire(current.revision)) throw failure(ERROR.conflict, "revision_conflict", `${kind} '${name}' changed in the ${scope} since you opened it`);
252
+ const deleted = await deleteEntry(kind, name, { ...options, scope, policy, ...revision !== void 0 ? { revision: current.revision } : {} });
253
+ if (kind === "providers") {
254
+ try {
255
+ onProviderSaved?.(name, false);
256
+ } catch {
257
+ }
258
+ }
259
+ return deleted;
260
+ })),
261
+ "library.duplicate": guard(({ kind, from, to, scope, projectRoot, policy }) => serial(async () => {
262
+ const options = await where(projectRoot, scope);
263
+ try {
264
+ await getEntry(kind, from, options);
265
+ } catch (error) {
266
+ throw fromCore(error, { notFound: "not_found" });
267
+ }
268
+ const result = { revision: toWire((await duplicateEntry(kind, from, to, { ...options, scope, policy })).revision) };
269
+ if (kind === "providers") {
270
+ try {
271
+ onProviderSaved?.(to, false);
272
+ } catch {
273
+ }
274
+ }
275
+ return result;
276
+ }), { notFound: "invalid_entry" }),
277
+ "library.rename": guard(({ kind, from, to, scope, projectRoot, policy }) => serial(async () => {
278
+ const options = await where(projectRoot, scope);
279
+ const renamed = await renameEntry(kind, from, to, { ...options, scope, policy });
280
+ if (kind === "providers") {
281
+ try {
282
+ onProviderSaved?.(to, false);
283
+ } catch {
284
+ }
285
+ }
286
+ return { revision: toWire(renamed.revision) };
287
+ })),
288
+ "library.skills.set": guard(({ agent, skills }) => serial(() => setGivenSkills(agent, skills, { library: home })), { notFound: "invalid_entry" }),
289
+ "library.models": guard(async () => {
290
+ const models = catalogEntries.map((model) => ({ id: `${model.runtime}:${model.id}`, label: `${model.runtime} \xB7 ${model.label}`, efforts: model.efforts, ...model.effort ? { effort: model.effort } : {} }));
291
+ for (const provider of await listProviders(home)) {
292
+ if (provider.enabled === false || provider.kind === "antigravity") continue;
293
+ models.push({ id: `acp:${provider.id}`, label: `${provider.label} \xB7 Provider default`, efforts: [] });
294
+ for (const model of [...provider.models ?? learnedModels?.(provider.id) ?? [], ...provider.additionalModels ?? []]) models.push({ id: `acp:${provider.id}/${model.id}`, label: `${provider.label} \xB7 ${model.label ?? model.id}`, efforts: [] });
295
+ }
296
+ return { models: [...new Map(models.map((model) => [model.id, model])).values()] };
297
+ }),
298
+ "settings.language.get": guard(async () => languageSetting(home)),
299
+ "settings.language.set": guard(async ({ language }) => {
300
+ if (language !== null && language.trim().length > LANGUAGE_CHARS) throw failure(RPC_ERROR.invalidParams, "invalid_params", `A language is a name of at most ${LANGUAGE_CHARS} characters`);
301
+ return serial(() => setLanguage(home, language));
302
+ })
303
+ };
304
+ const library = home !== void 0;
305
+ return {
306
+ handlers: { ...taskHandlers, ...library ? libraryHandlers : {} },
307
+ capabilities: [CAPABILITY.task, ...library ? [CAPABILITY.team, CAPABILITY.library, CAPABILITY.libraryProjectWrite, CAPABILITY.settingsLanguage] : []]
308
+ };
309
+ }
310
+ export {
311
+ createOperations,
312
+ fromCore
313
+ };
@@ -0,0 +1,89 @@
1
+ import { writeFile } from 'node:fs/promises';
2
+ export type ProjectRecord = {
3
+ id: string;
4
+ root: string;
5
+ canonical?: string;
6
+ customName?: string | null;
7
+ addedAt: string;
8
+ removedAt?: string | null;
9
+ };
10
+ export type WorkspaceRecord = {
11
+ id: string;
12
+ projectId: string;
13
+ directory: string;
14
+ canonical?: string;
15
+ title?: string | null;
16
+ pinnedAt?: string | null;
17
+ labels: string[];
18
+ createdAt: string;
19
+ archivedAt?: string | null;
20
+ idempotencyKey?: string;
21
+ worktree?: ManagedWorktree;
22
+ };
23
+ export type ManagedWorktree = {
24
+ kind: 'user';
25
+ sourceWorkspaceId: string;
26
+ source: string;
27
+ commonDir: string;
28
+ gitDir: string;
29
+ mappingId: string;
30
+ principalId: string;
31
+ grantEpoch: string;
32
+ requestId?: string;
33
+ ifRevision?: number;
34
+ branch: string;
35
+ head: string;
36
+ removedAt?: string;
37
+ };
38
+ export type Registry = {
39
+ version: 1;
40
+ revision: number;
41
+ projects: ProjectRecord[];
42
+ workspaces: WorkspaceRecord[];
43
+ sessions: Record<string, string>;
44
+ labels: {
45
+ generation: string;
46
+ seq: number;
47
+ catalog: {
48
+ name: string;
49
+ color: string;
50
+ }[];
51
+ };
52
+ worktreeJournal?: Record<string, {
53
+ fingerprint: string;
54
+ intent: any;
55
+ }>;
56
+ receipts: Record<string, {
57
+ fingerprint: string;
58
+ result: unknown;
59
+ }>;
60
+ };
61
+ export declare class RegistryError extends Error {
62
+ readonly code: number;
63
+ readonly data: {
64
+ reason: string;
65
+ };
66
+ constructor(code: number, message: string, data: {
67
+ reason: string;
68
+ });
69
+ }
70
+ /** Sole mutable owner. Failed writes never publish the draft or consume a requestId. */
71
+ export declare function createRegistry(home: string, options?: {
72
+ write?: typeof writeFile;
73
+ }): {
74
+ /** Native intent and receipt share the sole registry writer and atomic persistence boundary. */
75
+ nativeMutation: (method: string, args: any, context: {
76
+ actor: string;
77
+ requestId: string;
78
+ ifRevision: number;
79
+ }, prepare: (r: Registry) => Promise<any>, apply: (intent: any, draft: Registry) => Promise<any>) => Promise<any>;
80
+ snapshot: () => Promise<Registry>;
81
+ mutate: (method: string, args: any, context: {
82
+ actor?: string;
83
+ allowedRoots?: string[];
84
+ ifRevision?: number;
85
+ requestId: string;
86
+ }) => Promise<any>;
87
+ resolve(workspaceId: string, cwd?: string, includeArchived?: boolean): Promise<string>;
88
+ };
89
+ export type RegistryService = ReturnType<typeof createRegistry>;