@anhlp/alp-runtime 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.
Files changed (53) hide show
  1. package/dist/acp-transport.js +2 -0
  2. package/dist/antigravity-transport.d.ts +10 -2
  3. package/dist/antigravity-transport.js +26 -4
  4. package/dist/assignment-results.d.ts +5 -2
  5. package/dist/assignment-results.js +27 -15
  6. package/dist/catalog.js +2 -1
  7. package/dist/claude-transport.d.ts +42 -0
  8. package/dist/claude-transport.js +52 -2
  9. package/dist/contracts.d.ts +23 -1
  10. package/dist/index.d.ts +5 -4
  11. package/dist/index.js +9 -2
  12. package/dist/language.d.ts +2 -0
  13. package/dist/language.js +6 -0
  14. package/dist/live.d.ts +2 -2
  15. package/dist/live.js +7 -2
  16. package/dist/model-catalog.d.ts +87 -1
  17. package/dist/model-catalog.js +151 -6
  18. package/dist/model-probes.d.ts +1 -1
  19. package/dist/model-probes.js +2 -2
  20. package/dist/recall.d.ts +2 -2
  21. package/dist/recall.js +4 -3
  22. package/dist/resolve.d.ts +1 -0
  23. package/dist/resolve.js +6 -4
  24. package/dist/runtime.js +258 -34
  25. package/dist/session-config.d.ts +75 -6
  26. package/dist/session-config.js +9 -5
  27. package/dist/session-state.d.ts +2 -0
  28. package/dist/skill-resources.d.ts +30 -0
  29. package/dist/skill-resources.js +55 -0
  30. package/dist/tools.d.ts +27 -1
  31. package/dist/tools.js +20 -1
  32. package/dist/write-error.d.ts +2 -0
  33. package/dist/write-error.js +10 -0
  34. package/package.json +4 -4
  35. package/src/acp-transport.ts +3 -0
  36. package/src/antigravity-transport.ts +39 -8
  37. package/src/assignment-results.ts +23 -15
  38. package/src/catalog.ts +3 -1
  39. package/src/claude-transport.ts +85 -5
  40. package/src/contracts.ts +19 -0
  41. package/src/index.ts +5 -4
  42. package/src/language.ts +10 -0
  43. package/src/live.ts +7 -3
  44. package/src/model-catalog.ts +156 -6
  45. package/src/model-probes.ts +2 -2
  46. package/src/recall.ts +4 -3
  47. package/src/resolve.ts +11 -5
  48. package/src/runtime.ts +277 -30
  49. package/src/session-config.ts +13 -5
  50. package/src/session-state.ts +2 -0
  51. package/src/skill-resources.ts +73 -0
  52. package/src/tools.ts +22 -1
  53. package/src/write-error.ts +4 -0
@@ -14,11 +14,51 @@ export type ProviderState = {
14
14
  error?: string;
15
15
  models: LiveModel[];
16
16
  };
17
+ /** What ALP learned of an ACP provider's models (t-d0b0): nothing until a session or an explicit probe tells it. */
18
+ export type AcpStatus = 'unprobed' | 'ok' | 'failed';
19
+ export type AcpState = {
20
+ status: AcpStatus;
21
+ fetchedAt?: string;
22
+ error?: string;
23
+ models: LiveModel[];
24
+ };
17
25
  export type CatalogSnapshot = {
18
26
  fetchedAt?: string;
19
27
  providers: Partial<Record<CatalogRuntime, ProviderState>>;
28
+ acp?: Record<string, AcpState>;
20
29
  };
21
30
  export type Probe = (signal: AbortSignal) => Promise<LiveModel[]>;
31
+ /** A provider of the library (providers/<id>.json), as loadProvider reads it. */
32
+ export type AcpProviderConfig = {
33
+ id: string;
34
+ kind?: string;
35
+ label?: string;
36
+ description?: string;
37
+ enabled?: boolean;
38
+ models?: Array<{
39
+ id: string;
40
+ label?: string;
41
+ description?: string;
42
+ }>;
43
+ additionalModels?: Array<{
44
+ id: string;
45
+ label?: string;
46
+ description?: string;
47
+ }>;
48
+ };
49
+ export type AcpProbe = (provider: AcpProviderConfig, signal: AbortSignal) => Promise<LiveModel[]>;
50
+ /** An ACP row of the catalog: `acp:<provider>` (the agent's own default) and `acp:<provider>/<model>`. */
51
+ export type AcpRow = {
52
+ runtime: 'acp';
53
+ provider: string;
54
+ id: string;
55
+ label: string;
56
+ description: string;
57
+ efforts: string[];
58
+ source: 'configured' | 'live';
59
+ enabled: boolean;
60
+ status: AcpStatus;
61
+ };
22
62
  export declare const REFRESH_MS: number;
23
63
  export declare const PROBE_TIMEOUT_MS = 15000;
24
64
  export declare const POLICY: {
@@ -30,6 +70,8 @@ export declare const POLICY: {
30
70
  export declare const mergeCatalog: (base: CatalogEntry[], live: Partial<Record<CatalogRuntime, LiveModel[] | undefined>>) => CatalogEntry[];
31
71
  /** Only well-formed rows: a string id, string label/description/effort, string efforts. */
32
72
  export declare function sanitizeModels(value: unknown): LiveModel[];
73
+ /** The models a `session/new` answer offers (ACP `models.availableModels`, or a model select config option). */
74
+ export declare function acpSessionModels(result: any): LiveModel[];
33
75
  type Listener = (snapshot: CatalogSnapshot, entries: CatalogEntry[]) => void;
34
76
  export declare class ModelCatalog {
35
77
  private readonly options;
@@ -39,6 +81,19 @@ export declare class ModelCatalog {
39
81
  private timer?;
40
82
  private running?;
41
83
  private readonly file?;
84
+ private acpConfigs;
85
+ private acpRunning?;
86
+ private acpError?;
87
+ private acpLearning;
88
+ /** Cache writes under way: stop() waits for them, so whoever stopped the catalog may remove its home. */
89
+ private writes;
90
+ /** Set once stop() has drained: a late answer (a session's models, an ingest) still updates memory but writes nothing. */
91
+ private stopped;
92
+ /**
93
+ * ACP providers (t-d0b0) come from `acpProviders` (the library's providers/<id>.json) without starting
94
+ * them; their models are learned from sessions (learnAcp) and probed (acpProbe) only by refreshAcp,
95
+ * which alpd calls on catalog.refresh and when the user enables a provider. Never at start or on the timer.
96
+ */
42
97
  constructor(options: {
43
98
  home?: string;
44
99
  probes: Partial<Record<CatalogRuntime, Probe>>;
@@ -46,13 +101,24 @@ export declare class ModelCatalog {
46
101
  refreshMs?: number;
47
102
  now?: () => Date;
48
103
  apply?: boolean;
104
+ acpProviders?: () => Promise<AcpProviderConfig[] | {
105
+ providers: AcpProviderConfig[];
106
+ error?: string;
107
+ }>;
108
+ acpProbe?: AcpProbe;
49
109
  });
50
110
  entries(): CatalogEntry[];
51
111
  state(): CatalogSnapshot;
52
112
  onUpdated(listener: Listener): () => boolean;
53
113
  /** Loads the cache, then refreshes in the background and every refreshMs. Never blocks on a provider. */
54
114
  start(): Promise<void>;
55
- stop(): void;
115
+ /**
116
+ * Stops the timer and the listeners, then waits for what already started (a background refresh, a
117
+ * refreshAcp a saved provider asked for, a learned model's cache write) to finish writing the cache
118
+ * (t-5294.2). After that it writes the cache no more, until start() again. A caller that only stops may
119
+ * ignore the promise; one that removes the home awaits it.
120
+ */
121
+ stop(): Promise<void>;
56
122
  load(): Promise<void>;
57
123
  /** Asks every provider (or the named ones; a refresh already running answers instead) at once; each answer is bounded, and a failure keeps that provider's previous list. */
58
124
  refresh(runtimes?: CatalogRuntime[]): Promise<CatalogSnapshot>;
@@ -62,6 +128,24 @@ export declare class ModelCatalog {
62
128
  * probe answered; a list with nothing new changes nothing.
63
129
  */
64
130
  ingest(runtime: CatalogRuntime, models: LiveModel[]): Promise<boolean>;
131
+ /** Rereads the ACP providers' files; starts none of them. */
132
+ loadAcp(): Promise<void>;
133
+ /** Why the last reading of the ACP providers failed, if it did. */
134
+ acpLoadError(): string | undefined;
135
+ /** The ACP rows: each provider's default, then its models (the file's `models` replace learned ones; `additionalModels` add). */
136
+ acpRows(): AcpRow[];
137
+ /** The models ALP learned or probed for one ACP provider. */
138
+ acpModels(provider: string): LiveModel[];
139
+ /**
140
+ * A list an ACP session's `session/new` reported (t-d0b0). Additive, as ingest: it never removes a model
141
+ * a probe answered; a list with nothing new changes nothing.
142
+ */
143
+ learnAcp(provider: string, models: LiveModel[]): Promise<boolean>;
144
+ /**
145
+ * Starts each enabled ACP provider (or the named ones) once to read its models: only on an explicit
146
+ * catalog.refresh or when the user enables a provider. A failure keeps what ALP knew and records why.
147
+ */
148
+ refreshAcp(ids?: string[]): Promise<CatalogSnapshot>;
65
149
  private publish;
66
150
  }
67
151
  /** Reads a session's orchestration context models (`runtime:id`, label, description, thinking) as live models. */
@@ -73,4 +157,6 @@ export declare function liveFromContext(context: any): {
73
157
  export declare function setActiveCatalog(catalog: ModelCatalog | undefined): void;
74
158
  export declare function activeCatalog(): ModelCatalog | undefined;
75
159
  export declare function feedCatalog(context: unknown): void;
160
+ /** An ACP session's `session/new` answer teaches the daemon's catalog that provider's models (t-d0b0). */
161
+ export declare function feedAcpSession(provider: string, result: unknown): void;
76
162
  export {};
@@ -41,9 +41,24 @@ function sanitize(value) {
41
41
  if (!state || typeof state !== "object") continue;
42
42
  providers[runtime] = { status: state.status === "ok" ? "ok" : "failed", ...typeof state.fetchedAt === "string" ? { fetchedAt: state.fetchedAt } : {}, models: sanitizeModels(state.models) };
43
43
  }
44
- return { ...typeof value?.fetchedAt === "string" ? { fetchedAt: value.fetchedAt } : {}, providers };
44
+ const acp = {};
45
+ if (value?.acp && typeof value.acp === "object") for (const [id, state] of Object.entries(value.acp)) {
46
+ if (!/^[\w.-]+$/.test(id) || !state || typeof state !== "object") continue;
47
+ acp[id] = { status: state.status === "ok" ? "ok" : state.status === "failed" ? "failed" : "unprobed", ...typeof state.fetchedAt === "string" ? { fetchedAt: state.fetchedAt } : {}, ...typeof state.error === "string" ? { error: state.error } : {}, models: sanitizeModels(state.models) };
48
+ }
49
+ return { ...typeof value?.fetchedAt === "string" ? { fetchedAt: value.fetchedAt } : {}, providers, ...Object.keys(acp).length ? { acp } : {} };
50
+ }
51
+ function acpSessionModels(result) {
52
+ const config = Array.isArray(result?.configOptions) ? result.configOptions.find((option) => option?.category === "model" && option?.type === "select") : void 0;
53
+ const listed = Array.isArray(result?.models?.availableModels) ? result.models.availableModels : config ? (config.options ?? []).flatMap((option) => option?.options ?? [option]).map((option) => ({ modelId: option?.value, name: option?.name, description: option?.description })) : [];
54
+ return sanitizeModels(listed.map((model) => ({ id: model?.modelId ?? model?.id, ...typeof model?.name === "string" && model.name ? { label: model.name } : {}, ...typeof model?.description === "string" && model.description ? { description: model.description } : {} })));
45
55
  }
46
56
  var ModelCatalog = class {
57
+ /**
58
+ * ACP providers (t-d0b0) come from `acpProviders` (the library's providers/<id>.json) without starting
59
+ * them; their models are learned from sessions (learnAcp) and probed (acpProbe) only by refreshAcp,
60
+ * which alpd calls on catalog.refresh and when the user enables a provider. Never at start or on the timer.
61
+ */
47
62
  constructor(options) {
48
63
  this.options = options;
49
64
  this.file = options.home ? catalogCacheFile(options.home) : void 0;
@@ -54,6 +69,14 @@ var ModelCatalog = class {
54
69
  timer;
55
70
  running;
56
71
  file;
72
+ acpConfigs = [];
73
+ acpRunning;
74
+ acpError;
75
+ acpLearning = /* @__PURE__ */ new Map();
76
+ /** Cache writes under way: stop() waits for them, so whoever stopped the catalog may remove its home. */
77
+ writes = /* @__PURE__ */ new Set();
78
+ /** Set once stop() has drained: a late answer (a session's models, an ingest) still updates memory but writes nothing. */
79
+ stopped = false;
57
80
  entries() {
58
81
  return this.current;
59
82
  }
@@ -66,7 +89,10 @@ var ModelCatalog = class {
66
89
  }
67
90
  /** Loads the cache, then refreshes in the background and every refreshMs. Never blocks on a provider. */
68
91
  async start() {
92
+ this.stopped = false;
69
93
  await this.load();
94
+ await this.loadAcp().catch(() => {
95
+ });
70
96
  void this.refresh().catch(() => {
71
97
  });
72
98
  const every = this.options.refreshMs ?? REFRESH_MS;
@@ -78,10 +104,18 @@ var ModelCatalog = class {
78
104
  this.timer.unref?.();
79
105
  }
80
106
  }
81
- stop() {
107
+ /**
108
+ * Stops the timer and the listeners, then waits for what already started (a background refresh, a
109
+ * refreshAcp a saved provider asked for, a learned model's cache write) to finish writing the cache
110
+ * (t-5294.2). After that it writes the cache no more, until start() again. A caller that only stops may
111
+ * ignore the promise; one that removes the home awaits it.
112
+ */
113
+ async stop() {
82
114
  if (this.timer) clearInterval(this.timer);
83
115
  this.timer = void 0;
84
116
  this.listeners.clear();
117
+ while (this.running || this.acpRunning || this.writes.size) await Promise.allSettled([this.running, this.acpRunning, ...this.writes]);
118
+ this.stopped = true;
85
119
  }
86
120
  async load() {
87
121
  if (!this.file) return;
@@ -134,16 +168,120 @@ var ModelCatalog = class {
134
168
  await this.publish(true);
135
169
  return true;
136
170
  }
171
+ /** Rereads the ACP providers' files; starts none of them. */
172
+ async loadAcp() {
173
+ if (!this.options.acpProviders) return;
174
+ try {
175
+ const loaded = await this.options.acpProviders();
176
+ this.acpConfigs = (Array.isArray(loaded) ? loaded : loaded.providers).filter((provider) => provider.kind !== "antigravity");
177
+ this.acpError = Array.isArray(loaded) ? void 0 : loaded.error;
178
+ } catch (error) {
179
+ this.acpError = error instanceof Error ? error.message : String(error);
180
+ }
181
+ }
182
+ /** Why the last reading of the ACP providers failed, if it did. */
183
+ acpLoadError() {
184
+ return this.acpError;
185
+ }
186
+ /** The ACP rows: each provider's default, then its models (the file's `models` replace learned ones; `additionalModels` add). */
187
+ acpRows() {
188
+ const rows = [];
189
+ for (const provider of this.acpConfigs) {
190
+ const state = this.snapshot.acp?.[provider.id];
191
+ const status = state?.status ?? "unprobed";
192
+ const enabled = provider.enabled !== false;
193
+ const label = provider.label ?? provider.id;
194
+ const row = (id, text, description, source) => ({ runtime: "acp", provider: provider.id, id, label: text, description, efforts: [], source, enabled, status });
195
+ rows.push(row(provider.id, `${label} \xB7 agent default`, provider.description ?? "", "configured"));
196
+ const seen = /* @__PURE__ */ new Set();
197
+ const add = (models, source) => {
198
+ for (const model of models) if (!seen.has(model.id)) {
199
+ seen.add(model.id);
200
+ rows.push(row(`${provider.id}/${model.id}`, `${label} \xB7 ${model.label ?? model.id}`, model.description ?? "", source));
201
+ }
202
+ };
203
+ add(provider.models ?? state?.models ?? [], provider.models ? "configured" : "live");
204
+ add(provider.additionalModels ?? [], "configured");
205
+ }
206
+ return rows;
207
+ }
208
+ /** The models ALP learned or probed for one ACP provider. */
209
+ acpModels(provider) {
210
+ return this.snapshot.acp?.[provider]?.models ?? [];
211
+ }
212
+ /**
213
+ * A list an ACP session's `session/new` reported (t-d0b0). Additive, as ingest: it never removes a model
214
+ * a probe answered; a list with nothing new changes nothing.
215
+ */
216
+ async learnAcp(provider, models) {
217
+ if (!/^[\w.-]+$/.test(provider)) return false;
218
+ const reported = sanitizeModels(models);
219
+ for (const model of reported) this.acpLearning.get(provider)?.add(model.id);
220
+ const prior = this.snapshot.acp?.[provider];
221
+ const known = new Set((prior?.models ?? []).map((model) => model.id));
222
+ const added = reported.filter((model) => !known.has(model.id));
223
+ if (!added.length) return false;
224
+ this.snapshot.acp = { ...this.snapshot.acp, [provider]: { status: "ok", fetchedAt: (this.options.now?.() ?? /* @__PURE__ */ new Date()).toISOString(), models: [...prior?.models ?? [], ...added] } };
225
+ await this.publish(true);
226
+ return true;
227
+ }
228
+ /**
229
+ * Starts each enabled ACP provider (or the named ones) once to read its models: only on an explicit
230
+ * catalog.refresh or when the user enables a provider. A failure keeps what ALP knew and records why.
231
+ */
232
+ refreshAcp(ids) {
233
+ if (this.acpRunning) return this.acpRunning.then(() => this.refreshAcp(ids));
234
+ this.acpRunning = (async () => {
235
+ await this.loadAcp();
236
+ const probe = this.options.acpProbe;
237
+ const targets = this.acpConfigs.filter((provider) => provider.enabled !== false && (!ids || ids.includes(provider.id)));
238
+ if (!probe || !targets.length) return this.snapshot;
239
+ const now = () => (this.options.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
240
+ await Promise.all(targets.map(async (provider) => {
241
+ const learned = /* @__PURE__ */ new Set();
242
+ this.acpLearning.set(provider.id, learned);
243
+ let outcome;
244
+ try {
245
+ outcome = { ok: true, models: sanitizeModels(await bounded((signal) => probe(provider, signal), this.options.timeoutMs ?? PROBE_TIMEOUT_MS)) };
246
+ } catch (error) {
247
+ outcome = { ok: false, error: error instanceof Error ? error.message : String(error) };
248
+ }
249
+ this.acpLearning.delete(provider.id);
250
+ const current = this.snapshot.acp?.[provider.id];
251
+ const known = current?.models ?? [];
252
+ let next;
253
+ if (outcome.ok) {
254
+ const ids2 = new Set(outcome.models.map((model) => model.id));
255
+ next = { status: "ok", fetchedAt: now(), models: [...outcome.models, ...known.filter((model) => learned.has(model.id) && !ids2.has(model.id))] };
256
+ } else next = { status: "failed", ...current?.fetchedAt ? { fetchedAt: current.fetchedAt } : {}, error: outcome.error, models: known };
257
+ this.snapshot.acp = { ...this.snapshot.acp, [provider.id]: next };
258
+ }));
259
+ await this.publish(true);
260
+ return this.snapshot;
261
+ })().finally(() => {
262
+ this.acpRunning = void 0;
263
+ });
264
+ return this.acpRunning;
265
+ }
137
266
  async publish(save) {
138
267
  const next = mergeCatalog(staticRows(), Object.fromEntries(Object.entries(this.snapshot.providers).map(([runtime, state]) => [runtime, state?.models])));
139
268
  const changed = JSON.stringify(next) !== JSON.stringify(this.current);
140
269
  this.current = next;
141
270
  if (this.options.apply !== false) applyCatalog(next);
142
- if (save && this.file) {
271
+ if (save && this.file && !this.stopped) {
272
+ const file = this.file;
273
+ const write = (async () => {
274
+ try {
275
+ await mkdir(path.dirname(file), { recursive: true });
276
+ await writeAtomic(file, JSON.stringify(this.snapshot, null, 2));
277
+ } catch {
278
+ }
279
+ })();
280
+ this.writes.add(write);
143
281
  try {
144
- await mkdir(path.dirname(this.file), { recursive: true });
145
- await writeAtomic(this.file, JSON.stringify(this.snapshot, null, 2));
146
- } catch {
282
+ await write;
283
+ } finally {
284
+ this.writes.delete(write);
147
285
  }
148
286
  }
149
287
  if (save) for (const listener of this.listeners) {
@@ -179,12 +317,19 @@ function feedCatalog(context) {
179
317
  if (live && active) void active.ingest(live.runtime, live.models).catch(() => {
180
318
  });
181
319
  }
320
+ function feedAcpSession(provider, result) {
321
+ const models = acpSessionModels(result);
322
+ if (models.length && active) void active.learnAcp(provider, models).catch(() => {
323
+ });
324
+ }
182
325
  export {
183
326
  ModelCatalog,
184
327
  POLICY,
185
328
  PROBE_TIMEOUT_MS,
186
329
  REFRESH_MS,
330
+ acpSessionModels,
187
331
  activeCatalog,
332
+ feedAcpSession,
188
333
  feedCatalog,
189
334
  liveFromContext,
190
335
  mergeCatalog,
@@ -3,5 +3,5 @@ export declare function codexProbe(command?: string, env?: NodeJS.ProcessEnv): P
3
3
  export declare function claudeProbe(command?: string, env?: NodeJS.ProcessEnv): Probe;
4
4
  /** `agy models` prints one model per line, `id<TAB>label`. */
5
5
  export declare function parseAgyModels(stdout: string): LiveModel[];
6
- export declare function antigravityProbe(command?: string, env?: NodeJS.ProcessEnv): Probe;
6
+ export declare function antigravityProbe(command?: string, env?: NodeJS.ProcessEnv, args?: string[]): Probe;
7
7
  export declare function liveProbes(env?: NodeJS.ProcessEnv): Record<CatalogRuntime, Probe>;
@@ -45,9 +45,9 @@ function parseAgyModels(stdout) {
45
45
  return { id, label: label || id };
46
46
  }).filter((model) => model.id && /^[A-Za-z0-9][\w.:\-\[\]/]*$/.test(model.id));
47
47
  }
48
- function antigravityProbe(command = process.env.ALP_ANTIGRAVITY_BIN ?? "agy", env = process.env) {
48
+ function antigravityProbe(command = process.env.ALP_ANTIGRAVITY_BIN ?? "agy", env = process.env, args = []) {
49
49
  return (signal) => new Promise((resolve, reject) => {
50
- const child = spawn(command, ["models"], { cwd: os.tmpdir(), env, stdio: ["ignore", "pipe", "ignore"], windowsHide: true, signal });
50
+ const child = spawn(command, [...args, "models"], { cwd: os.tmpdir(), env, stdio: ["ignore", "pipe", "ignore"], windowsHide: true, signal });
51
51
  let stdout = "";
52
52
  child.stdout.on("data", (chunk) => {
53
53
  stdout += chunk;
package/dist/recall.d.ts CHANGED
@@ -30,8 +30,8 @@ export declare const RECALL_KEEP_MS: number;
30
30
  export declare const RECALL_MAX = 1000;
31
31
  export declare const RECALL_QUESTION_CHARS = 4000;
32
32
  export declare const RECALL_TIMEOUT_MS = 300000;
33
- /** The record of recallable threads, kept in `file` when given, else in memory. */
34
- export declare function createRecallBook(file?: string): {
33
+ /** The record of recallable threads, kept in `file` when given, else in memory; `onError` hears of each failed write. */
34
+ export declare function createRecallBook(file?: string, onError?: (error: unknown) => void): {
35
35
  all(): Promise<RecallEntry[]>;
36
36
  add(entry: RecallEntry): Promise<void>;
37
37
  /** Removes and returns the entries past their time, and the oldest beyond RECALL_MAX. */
package/dist/recall.js CHANGED
@@ -2,12 +2,14 @@
2
2
  import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
3
3
  import { randomBytes } from "node:crypto";
4
4
  import path from "node:path";
5
+ import { tell } from "./write-error.js";
5
6
  var RECALL_KEEP_MS = 14 * 24 * 60 * 60 * 1e3;
6
7
  var RECALL_MAX = 1e3;
7
8
  var RECALL_QUESTION_CHARS = 4e3;
8
9
  var RECALL_TIMEOUT_MS = 3e5;
9
10
  var valid = (entry) => !!entry && typeof entry === "object" && ["assignmentId", "rootId", "agent", "project", "runtime", "threadId", "cwd", "model", "status", "finishedAt"].every((key) => typeof entry[key] === "string") && Array.isArray(entry.requesters);
10
- function createRecallBook(file) {
11
+ function createRecallBook(file, onError = () => {
12
+ }) {
11
13
  let entries;
12
14
  let writes = Promise.resolve();
13
15
  const load = () => entries ??= file ? readFile(file, "utf8").then((text) => JSON.parse(text).filter(valid), () => []) : Promise.resolve([]);
@@ -19,8 +21,7 @@ function createRecallBook(file) {
19
21
  const temporary = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
20
22
  await writeFile(temporary, body, { mode: 384 });
21
23
  await rename(temporary, file);
22
- }).catch(() => {
23
- });
24
+ }).catch((error) => tell(onError, error));
24
25
  return writes;
25
26
  };
26
27
  return {
package/dist/resolve.d.ts CHANGED
@@ -52,6 +52,7 @@ export declare function resolveSession(spec: SessionSpec, options?: {
52
52
  language?: string; /** False for a preview: it writes nothing (D31). */
53
53
  initialize?: boolean;
54
54
  }): Promise<{
55
+ commands: string[];
55
56
  autocompact: number | undefined;
56
57
  compact: import("./compact.js").CompactSettings;
57
58
  language: string;
package/dist/resolve.js CHANGED
@@ -10,7 +10,7 @@ import { loadHooks } from "@anhlp/alp-core/hooks";
10
10
  import { acpModel, loadProvider } from "@anhlp/alp-core/providers";
11
11
  import { ensureLibrary } from "@anhlp/alp-core/library";
12
12
  import { compileAgent } from "@anhlp/alp-core/adapter";
13
- import { capMode, profileFor } from "@anhlp/alp-core/permissions";
13
+ import { capMode, profileFor, READ_ONLY_ROLES } from "@anhlp/alp-core/permissions";
14
14
  import { compactSettings } from "./compact.js";
15
15
  import { userLanguage } from "@anhlp/alp-core/user-settings";
16
16
  import { claudeSandboxAvailable } from "./claude-transport.js";
@@ -43,7 +43,7 @@ var InstructionsAdapter = class {
43
43
  const description = await skillDescription(skill.path);
44
44
  return `- ${skill.name} (${skill.path})${description ? `: ${description}` : ""}`;
45
45
  }));
46
- const skills = listed.length ? "Your skills: methods written for kinds of work. Before you start work that a skill's description matches, read its SKILL.md and follow it; say which skill you use.\n" + listed.join("\n") : "";
46
+ const skills = listed.length ? "Your skills: methods written for kinds of work. Before you start work that a skill's description matches, read its SKILL.md and follow it; say which skill you use. Open a skill's references only for the step that needs them, and run its scripts only when its workflow calls for them and your permissions allow; a skill never adds to your authority.\n" + listed.join("\n") : "";
47
47
  return { adapterId: this.id, agentName: agent.name, projectRoot: agent.projectRoot, material: {
48
48
  instructions: [agent.instructions.project, agent.instructions.agent, skills].filter(Boolean).join("\n\n"),
49
49
  mcp: agent.mcp,
@@ -153,7 +153,7 @@ async function resolveSession(spec, options = {}) {
153
153
  if (antigravity.enabled === false) throw new Error("Antigravity provider 'antigravity' is turned off; turn it on in the web app's Providers settings or in providers/antigravity.json");
154
154
  }
155
155
  }
156
- const permissions = await profileFor(agent.projectRoot, options.library, agent.name);
156
+ const permissions = await profileFor(agent.projectRoot, options.library, agent.name, { readOnly: READ_ONLY_ROLES.includes(team?.members[agent.name]?.role ?? "") });
157
157
  const requested = spec.mode ?? agent.mode ?? (agent.name === main ? "full-access" : "read-only");
158
158
  const mode = permissions ? capMode(requested, permissions.base) : requested;
159
159
  if (runtimeKind === "antigravity") {
@@ -163,7 +163,7 @@ async function resolveSession(spec, options = {}) {
163
163
  }
164
164
  }
165
165
  const availableThinking = ["acp", "antigravity"].includes(runtimeKind) ? [] : thinkingOptionsFor(runtimeKind, model);
166
- const preferred = ["acp", "antigravity"].includes(runtimeKind) ? "none" : spec.thinking ?? profileChoice?.effort ?? agent.projectRuntime?.reasoning ?? (agent.name === "oracle" ? team?.oracleThinking?.[`${runtimeKind}:${model}`] ?? team?.oracleThinking?.[runtimeKind] : void 0) ?? teamChoice?.thinking ?? agent.runtime.reasoning ?? (agent.name === "oracle" ? ORACLE_THINKING : availableThinking.length ? "medium" : "none");
166
+ const preferred = runtimeKind === "acp" ? "none" : runtimeKind === "antigravity" ? spec.thinking ?? profileChoice?.effort ?? (agent.name === "oracle" ? team?.oracleThinking?.[`${runtimeKind}:${model}`] ?? team?.oracleThinking?.[runtimeKind] : void 0) ?? teamChoice?.thinking ?? "none" : spec.thinking ?? profileChoice?.effort ?? agent.projectRuntime?.reasoning ?? (agent.name === "oracle" ? team?.oracleThinking?.[`${runtimeKind}:${model}`] ?? team?.oracleThinking?.[runtimeKind] : void 0) ?? teamChoice?.thinking ?? agent.runtime.reasoning ?? (agent.name === "oracle" ? ORACLE_THINKING : availableThinking.length ? "medium" : "none");
167
167
  const thinking = spec.thinking === void 0 && availableThinking.length && !availableThinking.some((candidate) => candidate.id === preferred) ? models.find((candidate) => candidate.id === `${runtimeKind}:${model}`)?.defaultThinkingOptionId ?? availableThinking[0].id : preferred;
168
168
  if (!model.trim()) throw new Error("Model must be nonempty");
169
169
  if (!modes.some((m) => m.id === mode)) throw new Error(`Unsupported mode '${mode}'`);
@@ -224,6 +224,8 @@ ${project}` : "");
224
224
  keepThread: spec.keepThread ?? false,
225
225
  // ALPD §57: the window the agent works in before its runtime compacts; absent, the model's.
226
226
  ...agent.context ? { context: agent.context } : {},
227
+ // t-efa3: the runtime's own commands and skills the "/" list offers; its ALP skills always.
228
+ commands: Array.isArray(profile?.commands) ? profile.commands.filter((name) => typeof name === "string") : [],
227
229
  autocompact: typeof profile?.autocompact === "number" ? profile.autocompact : typeof agent.autocompact === "number" ? agent.autocompact : void 0,
228
230
  // t-0e56: when main's context is compacted at a turn boundary.
229
231
  compact: compactSettings(projectSettings.compact),