lastlight 0.5.1 → 0.6.1

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 (43) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/README.md +39 -0
  3. package/agent-context/rules.md +0 -38
  4. package/agent-context/soul.md +0 -11
  5. package/dist/cli.js +24 -0
  6. package/dist/cli.js.map +1 -1
  7. package/dist/config.d.ts +1 -1
  8. package/dist/config.js +3 -3
  9. package/dist/config.js.map +1 -1
  10. package/dist/engine/agent-executor.d.ts +2 -139
  11. package/dist/engine/agent-executor.js +76 -996
  12. package/dist/engine/agent-executor.js.map +1 -1
  13. package/dist/engine/executors/backends.d.ts +41 -0
  14. package/dist/engine/executors/backends.js +541 -0
  15. package/dist/engine/executors/backends.js.map +1 -0
  16. package/dist/engine/executors/shared.d.ts +189 -0
  17. package/dist/engine/executors/shared.js +612 -0
  18. package/dist/engine/executors/shared.js.map +1 -0
  19. package/dist/sandbox/index.d.ts +1 -1
  20. package/dist/sandbox/index.js +1 -1
  21. package/dist/sandbox/index.js.map +1 -1
  22. package/dist/sandbox/smol.d.ts +162 -0
  23. package/dist/sandbox/smol.integration.test.d.ts +1 -0
  24. package/dist/sandbox/smol.integration.test.js +130 -0
  25. package/dist/sandbox/smol.integration.test.js.map +1 -0
  26. package/dist/sandbox/smol.js +485 -0
  27. package/dist/sandbox/smol.js.map +1 -0
  28. package/dist/skills-install.d.ts +12 -0
  29. package/dist/skills-install.js +179 -0
  30. package/dist/skills-install.js.map +1 -0
  31. package/package.json +4 -2
  32. package/plugins/lastlight/.claude-plugin/plugin.json +12 -0
  33. package/plugins/lastlight/README.md +44 -0
  34. package/plugins/lastlight/skills/lastlight-client/SKILL.md +82 -0
  35. package/plugins/lastlight/skills/lastlight-evals/SKILL.md +97 -0
  36. package/plugins/lastlight/skills/lastlight-evals/references/instance-schema.md +84 -0
  37. package/plugins/lastlight/skills/lastlight-evals/references/models-json.md +42 -0
  38. package/plugins/lastlight/skills/lastlight-overlay/SKILL.md +72 -0
  39. package/plugins/lastlight/skills/lastlight-overlay/references/forking.md +55 -0
  40. package/plugins/lastlight/skills/lastlight-overlay/references/overlay-layout.md +52 -0
  41. package/plugins/lastlight/skills/lastlight-server/SKILL.md +124 -0
  42. package/plugins/lastlight/skills/lastlight-server/references/env-schema.md +103 -0
  43. package/plugins/lastlight/skills/lastlight-server/references/operations.md +60 -0
@@ -0,0 +1,612 @@
1
+ import { resolve, basename, join } from "path";
2
+ import { appendFileSync, cpSync, existsSync, mkdirSync, readFileSync, rmSync, symlinkSync } from "fs";
3
+ import { truncateForLog, safeStringify } from "../event-shim.js";
4
+ import { BuildAssetStore } from "../../state/build-assets.js";
5
+ /**
6
+ * Shared building blocks for the per-backend executors
7
+ * ({@link ../executors/backends.ts}). These have NO dependency on the
8
+ * executors or the dispatcher, so the import DAG stays acyclic:
9
+ * shared → backends → agent-executor.
10
+ */
11
+ export const DEFAULT_MODEL = "anthropic/claude-sonnet-4-6";
12
+ export const DOCKER_WORKSPACE_DIR = "/home/agent/workspace";
13
+ // Directory holding one skill bundle per phase. Deliberately NOT named
14
+ // `.agents/skills` (pi's auto-discovery path): we map each phase's bundle
15
+ // explicitly via --skill / skillPaths so two phases sharing a workspace —
16
+ // sequential today, parallel via worktrees tomorrow — can never clobber each
17
+ // other's catalogue. The agent keeps cwd = the repo (no `cd` preamble on
18
+ // every command); the bundle is staged at the workspace ROOT — a sibling of
19
+ // the repo, never in its git tree — and reached by an absolute path. On
20
+ // docker/none that root is genuinely outside the repo. gondolin mounts only
21
+ // cwd, so there the bundle is staged under the repo and added to the
22
+ // checkout's local `.git/info/exclude` (never committed; see `excludeFromGit`).
23
+ export const SKILL_BUNDLE_ROOT = ".lastlight-skills";
24
+ export const THINKING_LEVELS = new Set([
25
+ "off", "minimal", "low", "medium", "high", "xhigh",
26
+ ]);
27
+ /**
28
+ * Stage this phase's declared skills into a per-phase bundle directory at
29
+ * `<workspaceRoot>/.lastlight-skills/<phaseKey>/<basename>/` and return the
30
+ * staged skill dirs, so the caller can point pi at them explicitly (via
31
+ * `--skill` for docker or `skillPaths` for the in-process backends). Each
32
+ * skill is a directory containing SKILL.md plus any `scripts/` / `references/`
33
+ * / `assets/` — the whole tree comes along.
34
+ *
35
+ * Keyed by phase so concurrent phases in one workspace never touch each
36
+ * other's bundle: only the phase's own `<phaseKey>` subtree is cleared, so a
37
+ * clean slate per phase doesn't disturb a sibling phase mid-run.
38
+ *
39
+ * `mode` controls how each skill lands:
40
+ * - "symlink": one symlink per skill → host source. gondolin/none, where pi
41
+ * reads skill files host-side / through the cwd mount. Zero-copy.
42
+ * - "copy": recursive copy. docker, where the agent's tools run inside the
43
+ * container and host symlink targets wouldn't resolve; the copy lands
44
+ * under the bind-mounted workspace.
45
+ *
46
+ * Returns `undefined` when the phase declares no skills (after clearing its
47
+ * bundle), so a phase with no `skills:` gets no catalogue at all.
48
+ */
49
+ export function stageSkillBundle(workspaceRoot, phaseKey, skillPaths, mode) {
50
+ const bundleDir = join(workspaceRoot, SKILL_BUNDLE_ROOT, phaseKey);
51
+ if (existsSync(bundleDir)) {
52
+ rmSync(bundleDir, { recursive: true, force: true });
53
+ }
54
+ if (!skillPaths?.length)
55
+ return undefined;
56
+ mkdirSync(bundleDir, { recursive: true });
57
+ const staged = [];
58
+ for (const hostPath of skillPaths) {
59
+ const dest = join(bundleDir, basename(hostPath));
60
+ if (mode === "symlink") {
61
+ symlinkSync(hostPath, dest, "dir");
62
+ }
63
+ else {
64
+ cpSync(hostPath, dest, { recursive: true, dereference: true });
65
+ }
66
+ staged.push(dest);
67
+ }
68
+ return staged;
69
+ }
70
+ /**
71
+ * Sanitized per-phase key for the skill bundle directory. Phase name first
72
+ * (unique even for loop iterations like `reviewer_fix_1`), then workflow name,
73
+ * then a constant fallback — so the bundle is always isolated per phase.
74
+ */
75
+ export function skillBundleKey(config) {
76
+ const raw = config.telemetry?.phaseName || config.telemetry?.workflowName || "phase";
77
+ return raw.replace(/[^A-Za-z0-9_-]/g, "_") || "phase";
78
+ }
79
+ /**
80
+ * Add `entry` to a checkout's local `.git/info/exclude` (idempotent) so the
81
+ * agent's own `git add`/`commit` can never pick it up. This file lives inside
82
+ * `.git/` — it is never tracked, committed, or pushed, and it leaves the repo's
83
+ * real `.gitignore` untouched; the exclusion applies only to this ephemeral
84
+ * sandbox checkout. Used for the gondolin backend, where the skill bundle must
85
+ * be staged under cwd (the only mounted dir) rather than as an out-of-repo
86
+ * sibling. No-op when `repoDir` isn't a git checkout (e.g. the workspace root).
87
+ */
88
+ export function excludeFromGit(repoDir, entry) {
89
+ const gitDir = join(repoDir, ".git");
90
+ if (!existsSync(gitDir))
91
+ return; // not a checkout — nothing to exclude
92
+ const infoDir = join(gitDir, "info");
93
+ const excludeFile = join(infoDir, "exclude");
94
+ const line = `/${entry}/`;
95
+ let current = "";
96
+ try {
97
+ current = readFileSync(excludeFile, "utf8");
98
+ }
99
+ catch { /* may not exist yet */ }
100
+ if (current.split(/\r?\n/).includes(line))
101
+ return;
102
+ mkdirSync(infoDir, { recursive: true });
103
+ appendFileSync(excludeFile, `${current.length && !current.endsWith("\n") ? "\n" : ""}${line}\n`);
104
+ }
105
+ // ── Server-mode build assets ────────────────────────────────────────
106
+ //
107
+ // In "server" mode the per-phase handoff docs live in the Last Light store
108
+ // rather than being committed into the target repo. The seam is symmetric to
109
+ // the skill bundle but bidirectional: stage the run's stored docs into the
110
+ // repo's `.lastlight/<issueKey>/` before the agent runs (so a later phase /
111
+ // resumed run sees prior context), and harvest whatever the phase wrote back
112
+ // to the store afterwards. The directory is the SAME relative path as repo
113
+ // mode (`{{issueDir}}`), so prompts are unchanged except for gating their
114
+ // `git add .lastlight/ && commit` off — the dir is git-excluded here too as a
115
+ // backstop against the agent's `git add -A` feature commit sweeping it in.
116
+ const ARTIFACT_DIR_ROOT = ".lastlight";
117
+ /**
118
+ * Resolve the server-mode artifact context for a run, or undefined when not in
119
+ * server mode (the default — the whole seam is then skipped and behaviour is
120
+ * byte-for-byte repo mode). `hostRepoDir` is the host-visible repo checkout
121
+ * (for docker that's the bind-mounted workspace path, not the in-container one).
122
+ */
123
+ export function serverArtifacts(config, hostRepoDir) {
124
+ if (config.buildAssets !== "server" || !config.buildAssetsDir || !config.buildAssetsKey) {
125
+ return undefined;
126
+ }
127
+ const store = new BuildAssetStore(config.buildAssetsDir);
128
+ const ref = config.buildAssetsKey;
129
+ return { store, ref, dir: join(hostRepoDir, ARTIFACT_DIR_ROOT, ref.issueKey), repoDir: hostRepoDir };
130
+ }
131
+ /** Stage stored docs into the workspace + exclude the dir from git (server mode). */
132
+ export function stageArtifactsIn(art) {
133
+ if (!art)
134
+ return;
135
+ try {
136
+ // Stage the run's stored docs into `<repoDir>/.lastlight/<issueKey>/`. This
137
+ // is safe for every workflow shape here: pre-cloned workflows (build, pr-*)
138
+ // already have the checkout at `repoDir`, and non-pre-cloned ones (explore)
139
+ // clone the repo into a *subdir* — so `repoDir` is the workspace root and a
140
+ // `.lastlight/` there never collides with the agent's clone. (A future
141
+ // workflow that `git clone … .` into cwd would be the one exception.)
142
+ art.store.stageInto(art.ref, art.dir);
143
+ // Backstop the prompt-level commit gate: when this is a real checkout, keep
144
+ // the docs out of the agent's `git add -A` feature commit. No-op at the
145
+ // workspace root (no `.git`), where the docs sit outside the repo subtree
146
+ // and are never in the repo's git tree anyway.
147
+ excludeFromGit(art.repoDir, ARTIFACT_DIR_ROOT);
148
+ }
149
+ catch (err) {
150
+ const msg = err instanceof Error ? err.message : String(err);
151
+ console.warn(`[executor] Could not stage build assets: ${msg}`);
152
+ }
153
+ }
154
+ /** Persist docs the phase wrote back to the store (server mode). */
155
+ export function harvestArtifactsOut(art) {
156
+ if (!art)
157
+ return;
158
+ try {
159
+ art.store.harvestFrom(art.ref, art.dir);
160
+ }
161
+ catch (err) {
162
+ const msg = err instanceof Error ? err.message : String(err);
163
+ console.warn(`[executor] Could not harvest build assets: ${msg}`);
164
+ }
165
+ }
166
+ export class RunResultAccumulator {
167
+ sessionId;
168
+ finalText = "";
169
+ agentEnded = false;
170
+ toolErrors = false;
171
+ maxStepsReached = false;
172
+ lastToolError;
173
+ // True iff the last assistant turn ended with a tool call — i.e. the agent
174
+ // asked for a tool and the loop terminated before it could respond to the
175
+ // result. That's a truncated run (pi hit its internal step cap mid-task),
176
+ // not a finished one. See `finalizeFromRunResult`'s truncation guard.
177
+ lastAssistantHadToolCall = false;
178
+ fatalError;
179
+ snapshotStats;
180
+ messages = [];
181
+ // Per-message usage accumulation (the compaction-proof source).
182
+ assistantMessages = 0;
183
+ userMessages = 0;
184
+ toolCalls = 0;
185
+ toolResults = 0;
186
+ msgInput = 0;
187
+ msgOutput = 0;
188
+ msgCacheRead = 0;
189
+ msgCacheWrite = 0;
190
+ msgCost = 0;
191
+ // Extension status events (file-search / github / web-search), keyed by
192
+ // extension name. Emitted once each at run start; we keep the raw payload
193
+ // (minus type/extension) so build() can map them onto the RunResult.
194
+ ext = {};
195
+ // Skill-loading status. agentic-pi emits a single (gated) `skills_status`
196
+ // event at run start; we keep the raw payload (minus type) so skills()
197
+ // can normalize it onto the RunResult, mirroring `ext` above for tools.
198
+ skillsRaw;
199
+ feed(r) {
200
+ switch (r.type) {
201
+ case "session":
202
+ if (typeof r.id === "string")
203
+ this.sessionId = r.id;
204
+ break;
205
+ case "extension_status": {
206
+ if (typeof r.extension === "string") {
207
+ const { type: _t, extension: _e, ...rest } = r;
208
+ this.ext[r.extension] = rest;
209
+ }
210
+ break;
211
+ }
212
+ case "skills_status": {
213
+ const { type: _t, ...rest } = r;
214
+ this.skillsRaw = rest;
215
+ break;
216
+ }
217
+ case "message_end": {
218
+ const m = r.message;
219
+ if (m?.role === "assistant" && Array.isArray(m.content)) {
220
+ const text = m.content
221
+ .filter((c) => c.type === "text" && typeof c.text === "string")
222
+ .map((c) => c.text)
223
+ .join("");
224
+ if (text)
225
+ this.finalText = text;
226
+ this.assistantMessages += 1;
227
+ const toolCallsInTurn = m.content.filter((c) => c.type === "toolCall").length;
228
+ this.toolCalls += toolCallsInTurn;
229
+ // Track whether the *latest* assistant turn requested a tool. If the
230
+ // run ends here (no synthesis turn follows the tool result), the
231
+ // agent was cut off mid-task.
232
+ this.lastAssistantHadToolCall = toolCallsInTurn > 0;
233
+ this.accumulateUsage(m.usage);
234
+ }
235
+ else if (m?.role === "user") {
236
+ this.userMessages += 1;
237
+ }
238
+ break;
239
+ }
240
+ case "tool_execution_end":
241
+ this.toolResults += 1;
242
+ if (r.isError === true) {
243
+ this.toolErrors = true;
244
+ // Keep the actual failure text (not just a boolean) so a run that
245
+ // ends in `error_tool` can report which tool failed and why —
246
+ // e.g. a provider `insufficient_quota` surfaced through an MCP
247
+ // call, or a bash command's stderr. Last error wins (it's the
248
+ // one that ended the run). truncate: tool output can be huge.
249
+ const raw = r.error ?? r.result ?? r.output;
250
+ const message = truncateForLog(typeof raw === "string" ? raw : safeStringify(raw), 4096);
251
+ const tool = typeof r.tool === "string"
252
+ ? r.tool
253
+ : typeof r.toolName === "string"
254
+ ? r.toolName
255
+ : undefined;
256
+ if (message)
257
+ this.lastToolError = { tool, message };
258
+ }
259
+ break;
260
+ case "agent_end":
261
+ this.agentEnded = true;
262
+ if (Array.isArray(r.messages))
263
+ this.messages = r.messages;
264
+ break;
265
+ case "max_steps_reached":
266
+ this.maxStepsReached = true;
267
+ break;
268
+ case "usage_snapshot":
269
+ this.snapshotStats = r.stats;
270
+ break;
271
+ case "fatal_error":
272
+ this.fatalError = r.error;
273
+ break;
274
+ }
275
+ }
276
+ accumulateUsage(usage) {
277
+ if (!usage || typeof usage !== "object")
278
+ return;
279
+ const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : 0;
280
+ this.msgInput += num(usage.input);
281
+ this.msgOutput += num(usage.output);
282
+ this.msgCacheRead += num(usage.cacheRead);
283
+ this.msgCacheWrite += num(usage.cacheWrite);
284
+ const cost = usage.cost;
285
+ if (cost && typeof cost === "object")
286
+ this.msgCost += num(cost.total);
287
+ }
288
+ /** Stats summed from per-message usage, or undefined if none was seen. */
289
+ accumulatedStats() {
290
+ const total = this.msgInput + this.msgOutput + this.msgCacheRead + this.msgCacheWrite;
291
+ if (this.assistantMessages === 0 && total === 0)
292
+ return undefined;
293
+ return {
294
+ userMessages: this.userMessages,
295
+ assistantMessages: this.assistantMessages,
296
+ toolCalls: this.toolCalls,
297
+ toolResults: this.toolResults,
298
+ tokens: {
299
+ input: this.msgInput,
300
+ output: this.msgOutput,
301
+ cacheRead: this.msgCacheRead,
302
+ cacheWrite: this.msgCacheWrite,
303
+ total,
304
+ },
305
+ cost: this.msgCost,
306
+ };
307
+ }
308
+ /**
309
+ * Prefer the per-message accumulation (compaction-proof) over pi's
310
+ * terminal `usage_snapshot`. Fall back to the snapshot only when the
311
+ * accumulation carries no token data — e.g. a provider that doesn't
312
+ * report per-message usage — so a non-compacted snapshot still wins.
313
+ */
314
+ bestStats() {
315
+ const acc = this.accumulatedStats();
316
+ if (acc && acc.tokens.total > 0)
317
+ return acc;
318
+ return this.snapshotStats ?? acc;
319
+ }
320
+ build(exitCode) {
321
+ return {
322
+ exitCode: exitCode,
323
+ ok: exitCode === 0 && !this.fatalError,
324
+ agentEnded: this.agentEnded,
325
+ toolErrors: this.toolErrors,
326
+ maxStepsReached: this.maxStepsReached,
327
+ fatalError: this.fatalError,
328
+ sessionId: this.sessionId,
329
+ finalText: this.finalText,
330
+ messages: this.messages,
331
+ stats: this.bestStats(),
332
+ records: [],
333
+ warnings: [],
334
+ };
335
+ }
336
+ /**
337
+ * Normalized extension status captured from `extension_status` events
338
+ * (file-search / github / web-search), or undefined if none reported.
339
+ * Decoupled from agentic-pi's `RunResult` type, which lags the runtime —
340
+ * the docker sandbox's agentic-pi emits file-search even when the harness's
341
+ * pinned `RunResult` type doesn't yet declare it.
342
+ */
343
+ extensions() {
344
+ const out = {};
345
+ for (const [name, v] of Object.entries(this.ext)) {
346
+ if (v && typeof v.status === "string") {
347
+ out[name] = {
348
+ status: v.status,
349
+ ...(typeof v.mode === "string" ? { mode: v.mode } : {}),
350
+ ...(typeof v.provider === "string" ? { provider: v.provider } : {}),
351
+ ...(typeof v.toolCount === "number" ? { toolCount: v.toolCount } : {}),
352
+ ...(typeof v.reason === "string" ? { reason: v.reason } : {}),
353
+ };
354
+ }
355
+ }
356
+ return Object.keys(out).length > 0 ? out : undefined;
357
+ }
358
+ /**
359
+ * Normalized skill-loading status from the gated `skills_status` event, or
360
+ * undefined if none was reported (agentic-pi suppresses it on a run that
361
+ * configured no skills and discovered none). The skill-loading counterpart
362
+ * to {@link extensions}.
363
+ */
364
+ skills() {
365
+ const s = this.skillsRaw;
366
+ if (!s || typeof s.status !== "string")
367
+ return undefined;
368
+ const skills = Array.isArray(s.skills)
369
+ ? s.skills
370
+ .filter((x) => !!x && typeof x === "object")
371
+ .map((x) => ({
372
+ name: typeof x.name === "string" ? x.name : "",
373
+ source: typeof x.source === "string" ? x.source : "",
374
+ modelInvocable: x.modelInvocable === true,
375
+ }))
376
+ : [];
377
+ return {
378
+ status: s.status,
379
+ discovered: typeof s.discovered === "number" ? s.discovered : skills.length,
380
+ skills,
381
+ mappedPaths: Array.isArray(s.mappedPaths)
382
+ ? s.mappedPaths.filter((p) => typeof p === "string")
383
+ : [],
384
+ noSkills: s.noSkills === true,
385
+ };
386
+ }
387
+ /**
388
+ * The last tool result that came back with `isError: true`, including the
389
+ * failure text — or undefined if no tool errored. This is what turns a
390
+ * bare `error_tool` stop reason into a human-readable cause.
391
+ */
392
+ toolError() {
393
+ return this.lastToolError;
394
+ }
395
+ /**
396
+ * True iff the run's final assistant turn ended on a tool call — meaning
397
+ * the agent intended to keep going but the loop stopped before it could
398
+ * respond to the tool result and write its answer. The signal a run was
399
+ * truncated (step-limit) rather than genuinely finished.
400
+ */
401
+ endedOnToolCall() {
402
+ return this.lastAssistantHadToolCall;
403
+ }
404
+ }
405
+ // ── Helpers ─────────────────────────────────────────────────────────
406
+ /** Provider account/billing/auth failures pi may surface as error text. */
407
+ const ACCOUNT_ERROR_MARKERS = [
408
+ "credit balance",
409
+ "insufficient_quota",
410
+ "insufficient quota",
411
+ "rate limit",
412
+ "unauthorized",
413
+ "invalid_api_key",
414
+ ];
415
+ /**
416
+ * Detect a provider account error (out of credit, quota, rate-limited, bad key)
417
+ * that pi may have surfaced as plain text rather than a hard failure.
418
+ *
419
+ * Critically, on a **successful** run we scan ONLY the genuine provider-error
420
+ * channel (`agentErrorMessage`, which `extractAgentError` already turns into a
421
+ * non-success stopReason when set — so it's empty here). The agent's own output
422
+ * (`finalText`) and tool results (`fatalError`, `toolError`) are NOT scanned on
423
+ * success: a legitimate `verify`/`qa-test` report or a `curl` probing a 401
424
+ * endpoint routinely contains "unauthorized" / "rate limit" as part of the task
425
+ * itself, and folding that in would wrongly fail a genuinely successful run
426
+ * (and drop its report). Only on a failed run do we fold those in to label why.
427
+ */
428
+ export function detectAccountError(opts) {
429
+ const combined = [
430
+ opts.success ? undefined : opts.fatalErrorMessage,
431
+ opts.agentErrorMessage,
432
+ opts.success ? undefined : opts.finalText,
433
+ opts.success ? undefined : opts.toolErrorText,
434
+ ]
435
+ .filter((s) => typeof s === "string" && s.length > 0)
436
+ .join("\n")
437
+ .toLowerCase();
438
+ return ACCOUNT_ERROR_MARKERS.some((m) => combined.includes(m));
439
+ }
440
+ export function finalizeFromRunResult(result, _prompt, shim, startTime, extensions, skills, toolError, endedOnToolCall = false) {
441
+ const durationMs = Date.now() - startTime;
442
+ const stats = result.stats;
443
+ // pi-agent-core swallows provider API errors (insufficient_quota, rate
444
+ // limit, auth) inside `handleRunFailure`: it synthesizes an assistant
445
+ // message with stopReason "error" + errorMessage and emits a clean
446
+ // agent_end. Without this check the run would map to "success" and the
447
+ // workflow would silently advance with no output. See message scan below.
448
+ const agentError = extractAgentError(result);
449
+ let stopReason = agentError?.stopReason ?? mapStopReason(result);
450
+ // Truncation guard. A run that *would* map to "success" but whose final
451
+ // assistant turn ended on a tool call was cut off mid-task: the agent
452
+ // asked for a tool and the loop stopped before it could read the result
453
+ // and synthesize an answer (pi hit its internal step cap — agentic-pi
454
+ // v0.2.7 exposes no maxSteps knob to lift it). In that state `finalText`
455
+ // is the agent's "let me just check X" preamble, NOT an answer. Reclassify
456
+ // as a failure so the workflow fires `on_failure` instead of delivering
457
+ // the fragment as if it were the result.
458
+ const truncated = stopReason === "success" && !agentError && endedOnToolCall;
459
+ if (truncated)
460
+ stopReason = "error_truncated";
461
+ const success = stopReason === "success";
462
+ const truncationMessage = "Agent stopped mid-task before producing a final answer (hit the agent " +
463
+ "step limit). No answer was delivered.";
464
+ // A bare `error_tool` stop reason is useless on its own. Surface the
465
+ // failing tool's actual error text so the executions row and dashboard
466
+ // show *why* the run died (e.g. "Tool `bash` failed: insufficient_quota").
467
+ const toolErrorText = toolError
468
+ ? toolError.tool
469
+ ? `Tool \`${toolError.tool}\` failed: ${toolError.message}`
470
+ : toolError.message
471
+ : undefined;
472
+ const inputTokens = stats?.tokens.input ?? 0;
473
+ const outputTokens = stats?.tokens.output ?? 0;
474
+ const cacheRead = stats?.tokens.cacheRead ?? 0;
475
+ const cacheWrite = stats?.tokens.cacheWrite ?? 0;
476
+ const costUsd = stats?.cost ?? 0;
477
+ const turns = stats?.assistantMessages ?? 0;
478
+ const costStr = costUsd > 0 ? `, $${costUsd.toFixed(4)}` : "";
479
+ console.log(` [executor] Result: ${stopReason} (${turns} turns, ${Math.round(durationMs / 1000)}s${costStr})` +
480
+ `${result.sessionId ? ` [session ${result.sessionId}]` : ""}`);
481
+ shim.finalize({
482
+ finalText: result.finalText,
483
+ turns,
484
+ costUsd,
485
+ inputTokens,
486
+ outputTokens,
487
+ cacheReadInputTokens: cacheRead,
488
+ cacheCreationInputTokens: cacheWrite,
489
+ stopReason,
490
+ durationMs,
491
+ apiErrorMessage: agentError?.errorMessage ??
492
+ (success ? undefined : (toolErrorText ?? (truncated ? truncationMessage : undefined))),
493
+ });
494
+ void shim.flush();
495
+ const accountError = detectAccountError({
496
+ success,
497
+ fatalErrorMessage: result.fatalError?.message,
498
+ agentErrorMessage: agentError?.errorMessage,
499
+ finalText: result.finalText,
500
+ toolErrorText,
501
+ });
502
+ const errorText = result.fatalError?.message ||
503
+ agentError?.errorMessage ||
504
+ toolErrorText ||
505
+ (truncated ? truncationMessage : result.finalText) ||
506
+ stopReason;
507
+ if (!success || accountError) {
508
+ if (accountError)
509
+ console.error(` [executor] Account error: ${errorText}`);
510
+ else
511
+ console.error(` [executor] Run failed (${stopReason}): ${errorText}`);
512
+ }
513
+ return {
514
+ success: success && !accountError,
515
+ output: result.finalText,
516
+ turns,
517
+ error: success && !accountError ? undefined : errorText,
518
+ durationMs,
519
+ sessionId: result.sessionId,
520
+ costUsd: costUsd > 0 ? costUsd : undefined,
521
+ inputTokens: inputTokens || undefined,
522
+ outputTokens: outputTokens || undefined,
523
+ cacheReadInputTokens: cacheRead || undefined,
524
+ cacheCreationInputTokens: cacheWrite || undefined,
525
+ stopReason,
526
+ extensions,
527
+ skills,
528
+ };
529
+ }
530
+ export function mapStopReason(result) {
531
+ if (result.fatalError)
532
+ return "error_fatal";
533
+ if (result.toolErrors && result.finalText.length === 0)
534
+ return "error_tool";
535
+ if (!result.ok)
536
+ return `error_exit_${result.exitCode}`;
537
+ if (result.agentEnded || result.finalText.length > 0)
538
+ return "success";
539
+ return "unknown";
540
+ }
541
+ /**
542
+ * Scan agent_end's messages for a failed assistant turn. pi-agent-core's
543
+ * `handleRunFailure` catches provider errors, synthesizes an assistant
544
+ * message with stopReason "error"/"aborted" + errorMessage, and emits a
545
+ * normal agent_end — so the only signal that the run actually failed
546
+ * lives on the last assistant message.
547
+ */
548
+ export function extractAgentError(result) {
549
+ if (!Array.isArray(result.messages))
550
+ return undefined;
551
+ for (let i = result.messages.length - 1; i >= 0; i--) {
552
+ const m = result.messages[i];
553
+ if (m?.role !== "assistant")
554
+ continue;
555
+ if (m.stopReason === "error" || m.stopReason === "aborted") {
556
+ return {
557
+ stopReason: m.stopReason === "aborted" ? "error_aborted" : "error_agent",
558
+ errorMessage: m.errorMessage || m.stopReason,
559
+ };
560
+ }
561
+ return undefined;
562
+ }
563
+ return undefined;
564
+ }
565
+ export function coerceThinking(raw) {
566
+ if (!raw)
567
+ return undefined;
568
+ const v = raw.trim().toLowerCase();
569
+ if (!THINKING_LEVELS.has(v)) {
570
+ console.warn(`[executor] Ignoring unknown thinking level "${raw}" — must be one of: ${[...THINKING_LEVELS].join(", ")}`);
571
+ return undefined;
572
+ }
573
+ return v;
574
+ }
575
+ export function resolveSessionsDir(config) {
576
+ if (config.sessionsDir)
577
+ return resolve(config.sessionsDir);
578
+ const stateDir = config.stateDir || resolve("data");
579
+ return process.env.LASTLIGHT_SESSIONS_DIR
580
+ ? resolve(process.env.LASTLIGHT_SESSIONS_DIR)
581
+ : resolve(stateDir, "agent-sessions");
582
+ }
583
+ export function emptyResult(stopReason, durationMs) {
584
+ return {
585
+ finalText: "",
586
+ turns: 0,
587
+ costUsd: 0,
588
+ inputTokens: 0,
589
+ outputTokens: 0,
590
+ cacheReadInputTokens: 0,
591
+ cacheCreationInputTokens: 0,
592
+ stopReason,
593
+ durationMs,
594
+ };
595
+ }
596
+ /** Splice values into process.env for the duration of a sync block. */
597
+ export function applyEnv(env) {
598
+ const saved = {};
599
+ for (const [k, v] of Object.entries(env)) {
600
+ saved[k] = process.env[k];
601
+ process.env[k] = v;
602
+ }
603
+ return () => {
604
+ for (const [k, v] of Object.entries(saved)) {
605
+ if (v === undefined)
606
+ delete process.env[k];
607
+ else
608
+ process.env[k] = v;
609
+ }
610
+ };
611
+ }
612
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/engine/executors/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,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AQ,CAAC,GAA2B;IAClD,MAAM,KAAK,GAAuC,EAAE,CAAC;IACrD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACzC,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,EAAE;QACV,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;;gBACtC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -102,4 +102,4 @@ type PrePopulate = {
102
102
  * This is the re-review fast path from issue #107.
103
103
  */
104
104
  export { prePopulateWorkspace as __prePopulateWorkspaceForTest };
105
- declare function prePopulateWorkspace(workDir: string, pre: PrePopulate): void;
105
+ export declare function prePopulateWorkspace(workDir: string, pre: PrePopulate): void;
@@ -158,7 +158,7 @@ const RUN_MARKER = ".lastlight-run";
158
158
  * This is the re-review fast path from issue #107.
159
159
  */
160
160
  export { prePopulateWorkspace as __prePopulateWorkspaceForTest };
161
- function prePopulateWorkspace(workDir, pre) {
161
+ export function prePopulateWorkspace(workDir, pre) {
162
162
  // Token shape is asserted in src/engine/git-auth.ts before we get here,
163
163
  // but re-check the narrow set here too — defense in depth, this string
164
164
  // crosses a process boundary into git's command line.