pipeline-worker 0.1.15 → 0.1.17

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/README.md CHANGED
@@ -117,6 +117,10 @@ A stage with no command (`—`) is skipped. If no toolchain is detected and no c
117
117
  | `pipeline-worker serve` | Start the forge MCP server over stdio (used by the agent during fix runs) |
118
118
  | `pipeline-worker resume --branch <name>` | Resume watching/fixing a run after a crash |
119
119
  | `pipeline-worker status --branch <name>` | Print the persisted state of a run |
120
+ | `pipeline-worker sessions [--branch <name>]` | List every persisted run in this repo, or show one run's full step-by-step timeline |
121
+ | `pipeline-worker update` | Install the latest release from npm (`npm install -g pipeline-worker@latest`) |
122
+
123
+ Every time a run hands a turn to Claude Code or the Copilot CLI (resolving a conflict, capturing intent, fixing a failed pipeline), the output includes that turn's duration and an `agent session: <id>` line — `claude --resume <id>` (or `copilot --resume <id>`) opens the same session later to see exactly what it did and why. Copilot CLI has no way to report the session id it picked for itself, so pipeline-worker assigns one via `--name` instead and reports that.
120
124
 
121
125
  ## How the fix loop stays bounded
122
126
 
@@ -20,7 +20,7 @@
20
20
  * surfaces the command line + stderr, so without this the most useful failure
21
21
  * information is silently dropped.
22
22
  */
23
- import type { AgentAdapter } from './types.js';
23
+ import { type AgentAdapter } from './types.js';
24
24
  /** Subset of the rejection shape Node's promisified execFile produces. */
25
25
  interface ExecErrorShape {
26
26
  code?: number | string | null;
@@ -22,9 +22,9 @@
22
22
  */
23
23
  import { execFile } from 'node:child_process';
24
24
  import { promisify } from 'node:util';
25
+ import { AGENT_INVOKE_TIMEOUT_MS } from './types.js';
25
26
  import { writePromptToStdin } from './stdinPrompt.js';
26
27
  const execFileAsync = promisify(execFile);
27
- const INVOKE_TIMEOUT_MS = 300_000;
28
28
  /**
29
29
  * Tail-truncation cap for stdout/stderr in the rejection message. Mirrors
30
30
  * `watchPipeline.ts`'s `.slice(-4000)` so a verbose agent failure (e.g. an
@@ -100,11 +100,12 @@ export const claudeAdapter = {
100
100
  if (opts.model) {
101
101
  args.push('--model', opts.model);
102
102
  }
103
+ const start = Date.now();
103
104
  let stdout;
104
105
  try {
105
106
  const invocation = execFileAsync('claude', args, {
106
107
  cwd: opts.cwd,
107
- timeout: INVOKE_TIMEOUT_MS,
108
+ timeout: AGENT_INVOKE_TIMEOUT_MS,
108
109
  maxBuffer: 64 * 1024 * 1024,
109
110
  });
110
111
  // stdin is always a pipe here since stdio isn't overridden in execFileAsync's options.
@@ -117,13 +118,17 @@ export const claudeAdapter = {
117
118
  throw new Error(formatProcessError(err));
118
119
  }
119
120
  try {
121
+ // duration_ms/session_id come straight from the CLI's own JSON envelope
122
+ // (see the module comment's `claude -p --output-format json` sample);
123
+ // falling back to our own wall-clock reading only covers the
124
+ // never-observed case where that envelope omits duration_ms.
120
125
  const parsed = JSON.parse(stdout);
121
- return { text: parsed.result ?? stdout, raw: parsed };
126
+ return { text: parsed.result ?? stdout, raw: parsed, sessionId: parsed.session_id, durationMs: parsed.duration_ms ?? Date.now() - start };
122
127
  }
123
128
  catch {
124
129
  // --output-format json should always produce parseable JSON; fall back
125
130
  // to the raw stream rather than throwing, since the invocation itself succeeded.
126
- return { text: stdout };
131
+ return { text: stdout, durationMs: Date.now() - start };
127
132
  }
128
133
  },
129
134
  };
@@ -1 +1 @@
1
- {"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/agent/claude.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAWpC;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AsE;YACtE,6DAA6D;YAC7D,6DAA6D;YAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAmE,CAAC;YACpG,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,IAAI,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,WAAW,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;QAC5I,CAAC;QAAC,MAAM,CAAC;YACP,uEAAuE;YACvE,iFAAiF;YACjF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;QAC1D,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -19,6 +19,12 @@
19
19
  * - no per-invocation tool allowlist -> `--allow-all-tools` is always passed,
20
20
  * so `allowedTools` is ignored; a read-only step (e.g. captureIntent.ts)
21
21
  * gets full tool access under this adapter instead of being restricted.
22
+ * - no way to learn the session id the CLI picked for itself in
23
+ * non-interactive mode (open feature request: github/copilot-cli#807) ->
24
+ * every invocation is given an explicit `--name`, which `copilot --resume
25
+ * <name>` (or `/resume` in an interactive session) can look up later, so
26
+ * callers still get a stable identifier to report even though it isn't
27
+ * the CLI's own internal session id.
22
28
  *
23
29
  * The prompt is piped over stdin rather than passed via `-p <prompt>`.
24
30
  * captureIntent.ts embeds a full git diff in the prompt, and a large diff can
@@ -28,5 +34,5 @@
28
34
  * non-interactively since stdin isn't a TTY (documented as
29
35
  * `echo "..." | copilot`).
30
36
  */
31
- import type { AgentAdapter } from './types.js';
37
+ import { type AgentAdapter } from './types.js';
32
38
  export declare const copilotAdapter: AgentAdapter;
@@ -19,6 +19,12 @@
19
19
  * - no per-invocation tool allowlist -> `--allow-all-tools` is always passed,
20
20
  * so `allowedTools` is ignored; a read-only step (e.g. captureIntent.ts)
21
21
  * gets full tool access under this adapter instead of being restricted.
22
+ * - no way to learn the session id the CLI picked for itself in
23
+ * non-interactive mode (open feature request: github/copilot-cli#807) ->
24
+ * every invocation is given an explicit `--name`, which `copilot --resume
25
+ * <name>` (or `/resume` in an interactive session) can look up later, so
26
+ * callers still get a stable identifier to report even though it isn't
27
+ * the CLI's own internal session id.
22
28
  *
23
29
  * The prompt is piped over stdin rather than passed via `-p <prompt>`.
24
30
  * captureIntent.ts embeds a full git diff in the prompt, and a large diff can
@@ -30,9 +36,10 @@
30
36
  */
31
37
  import { execFile } from 'node:child_process';
32
38
  import { promisify } from 'node:util';
39
+ import { randomUUID } from 'node:crypto';
40
+ import { AGENT_INVOKE_TIMEOUT_MS } from './types.js';
33
41
  import { writePromptToStdin } from './stdinPrompt.js';
34
42
  const execFileAsync = promisify(execFile);
35
- const INVOKE_TIMEOUT_MS = 300_000;
36
43
  /** Pulls the outermost JSON object out of a text answer that may have prose around it. */
37
44
  function extractJsonObject(text) {
38
45
  const start = text.indexOf('{');
@@ -55,15 +62,21 @@ export const copilotAdapter = {
55
62
  console.error(`pipeline-worker: copilot CLI has no per-invocation model flag; ignoring the configured model "${opts.model}". ` +
56
63
  "Switch copilot's model via its own /model command or config instead.");
57
64
  }
58
- const invocation = execFileAsync('copilot', ['-s', '--no-ask-user', '--allow-all-tools', '--allow-all-paths'], {
65
+ const sessionName = `pipeline-worker-${randomUUID()}`;
66
+ const start = Date.now();
67
+ const invocation = execFileAsync('copilot', ['-s', '--no-ask-user', '--allow-all-tools', '--allow-all-paths', '--name', sessionName], {
59
68
  cwd: opts.cwd,
60
- timeout: INVOKE_TIMEOUT_MS,
69
+ timeout: AGENT_INVOKE_TIMEOUT_MS,
61
70
  maxBuffer: 64 * 1024 * 1024,
62
71
  });
63
72
  // stdin is always a pipe here since stdio isn't overridden in execFileAsync's options.
64
73
  writePromptToStdin(invocation.child.stdin, prompt);
65
74
  const { stdout } = await invocation;
66
- return { text: opts.jsonSchema ? extractJsonObject(stdout) : stdout.trim() };
75
+ return {
76
+ text: opts.jsonSchema ? extractJsonObject(stdout) : stdout.trim(),
77
+ sessionId: sessionName,
78
+ durationMs: Date.now() - start,
79
+ };
67
80
  },
68
81
  };
69
82
  //# sourceMappingURL=copilot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"copilot.js","sourceRoot":"","sources":["../../src/agent/copilot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC,0FAA0F;AAC1F,SAAS,iBAAiB,CAAC,IAAY;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,KAAK,KAAK,CAAC,CAAC,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACzE,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAiB;IAC1C,KAAK,CAAC,MAAM,CAAC,IAAwB;QACnC,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QACzB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM;gBACJ,oGAAoG;oBACpG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,OAAO,CAAC,KAAK,CACX,mFAAmF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CAAC,UAAU,CAAC,KAAK,CAAC,KAAM,EAAE,MAAM,CAAC,CAAC;QACpD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC;QAEpC,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE;YACjE,SAAS,EAAE,WAAW;YACtB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;SAC/B,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -1,4 +1,13 @@
1
1
  /** Common interface both the Claude Code and Copilot CLI adapters implement. */
2
+ /**
3
+ * Hard ceiling on a single headless agent invocation, shared by both
4
+ * adapters. Conflict resolution and CI-fix turns run under acceptEdits with
5
+ * full tool access (reading/editing multiple files, sometimes re-running
6
+ * build/test commands), so they can legitimately take much longer than a
7
+ * plain completion — 15 minutes gives that room while still bounding a hung
8
+ * unattended run.
9
+ */
10
+ export declare const AGENT_INVOKE_TIMEOUT_MS = 900000;
2
11
  export interface AgentInvokeOptions {
3
12
  /** The instruction given to the agent for this turn. */
4
13
  prompt: string;
@@ -24,6 +33,15 @@ export interface AgentInvokeResult {
24
33
  text: string;
25
34
  /** The parsed structured payload, when the adapter's output format returns one. */
26
35
  raw?: unknown;
36
+ /**
37
+ * Identifier for the underlying agent CLI's own session, so a user can look
38
+ * up what it did later — `claude --resume <id>` or, for Copilot (which has
39
+ * no way to report the session id it picked itself), the `--name` we chose
40
+ * for it, resumable via `copilot --resume <id>`.
41
+ */
42
+ sessionId?: string;
43
+ /** Wall-clock duration of this invocation in milliseconds. */
44
+ durationMs?: number;
27
45
  }
28
46
  export interface AgentAdapter {
29
47
  invoke(opts: AgentInvokeOptions): Promise<AgentInvokeResult>;
@@ -1,3 +1,11 @@
1
1
  /** Common interface both the Claude Code and Copilot CLI adapters implement. */
2
- export {};
2
+ /**
3
+ * Hard ceiling on a single headless agent invocation, shared by both
4
+ * adapters. Conflict resolution and CI-fix turns run under acceptEdits with
5
+ * full tool access (reading/editing multiple files, sometimes re-running
6
+ * build/test commands), so they can legitimately take much longer than a
7
+ * plain completion — 15 minutes gives that room while still bounding a hung
8
+ * unattended run.
9
+ */
10
+ export const AGENT_INVOKE_TIMEOUT_MS = 900_000;
3
11
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,gFAAgF"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAEhF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAC"}
package/dist/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { readFileSync } from 'node:fs';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import path from 'node:path';
5
+ import { spawn } from 'node:child_process';
5
6
  import { Command } from 'commander';
6
7
  import { runWorkflow } from './workflow/orchestrate.js';
7
8
  import { watchPipeline } from './workflow/watchPipeline.js';
@@ -9,7 +10,8 @@ import { startServer } from './mcp/server.js';
9
10
  import { loadConfig } from './config/loader.js';
10
11
  import { createForge } from './forge/index.js';
11
12
  import { selectAgent } from './agent/index.js';
12
- import { loadRunState, saveRunState } from './state/runState.js';
13
+ import { loadRunState, listRunStates, recordEvent } from './state/runState.js';
14
+ import { printSessionList, printSessionDetail } from './ui/sessions.js';
13
15
  import { isWorktreeOnBranch, checkoutExistingBranch, removeWorktree } from './git/worktree.js';
14
16
  import { buildEnvelope, errorEnvelope } from './toon/envelope.js';
15
17
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -67,7 +69,7 @@ program
67
69
  : await checkoutExistingBranch(repoRoot, state.branch);
68
70
  if (worktreePath !== state.worktreePath) {
69
71
  state.worktreePath = worktreePath;
70
- saveRunState(repoRoot, state);
72
+ recordEvent(repoRoot, state, `Recreated worktree at ${worktreePath}`);
71
73
  }
72
74
  let cleanedUp = false;
73
75
  const cleanup = async () => {
@@ -84,6 +86,11 @@ program
84
86
  try {
85
87
  await watchPipeline(forge, config, agent, worktreePath, state.branch, state.targetBranch, state.mrIid, state, repoRoot);
86
88
  }
89
+ catch (error) {
90
+ const message = error instanceof Error ? error.message : String(error);
91
+ recordEvent(repoRoot, state, `Resume failed: ${message}`, 'error');
92
+ throw error;
93
+ }
87
94
  finally {
88
95
  await cleanup();
89
96
  }
@@ -107,6 +114,44 @@ program
107
114
  }
108
115
  console.log(buildEnvelope({ status: 'success', data: state }));
109
116
  });
117
+ program
118
+ .command('sessions')
119
+ .description("List this repo's persisted pipeline-worker runs, or inspect one run's full timeline")
120
+ .option('--branch <name>', 'show the full step-by-step timeline for one run instead of listing all')
121
+ .action((opts) => {
122
+ const repoRoot = process.cwd();
123
+ if (opts.branch) {
124
+ const state = loadRunState(repoRoot, opts.branch);
125
+ if (!state) {
126
+ console.error(`pipeline-worker: no session found for branch ${opts.branch}.`);
127
+ process.exit(1);
128
+ }
129
+ printSessionDetail({ branch: state.branch, state });
130
+ return;
131
+ }
132
+ printSessionList(listRunStates(repoRoot));
133
+ });
134
+ program
135
+ .command('update')
136
+ .description(`Install the latest ${pkg.name} release from npm (npm install -g ${pkg.name}@latest)`)
137
+ .action(async () => {
138
+ console.log(`pipeline-worker: currently v${pkg.version}, installing latest via npm install -g ${pkg.name}@latest ...`);
139
+ try {
140
+ await new Promise((resolve, reject) => {
141
+ // stdio: 'inherit' streams npm's own progress/errors straight to the
142
+ // user's terminal rather than buffering it — an install can take a
143
+ // while and users expect to see npm's usual output live.
144
+ const npm = spawn('npm', ['install', '-g', `${pkg.name}@latest`], { stdio: 'inherit' });
145
+ npm.on('error', reject);
146
+ npm.on('exit', (code) => (code === 0 ? resolve() : reject(new Error(`npm install exited with code ${code}`))));
147
+ });
148
+ }
149
+ catch (error) {
150
+ console.error('pipeline-worker update failed:', error instanceof Error ? error.message : error);
151
+ process.exit(1);
152
+ }
153
+ console.log(`pipeline-worker: updated — run "${pkg.name} -v" to confirm the installed version.`);
154
+ });
110
155
  program.parseAsync(process.argv).catch((error) => {
111
156
  console.error('pipeline-worker: unexpected error:', error instanceof Error ? error.message : error);
112
157
  process.exit(1);
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAElE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/D,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAwB,CA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AK,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;YACxF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACxB,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,gCAAgC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACjH,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAChG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,mCAAmC,GAAG,CAAC,IAAI,wCAAwC,CAAC,CAAC;AACnG,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC/C,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACpG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A per-repo lockfile at <repoRoot>/.pipeline-worker/run.lock, preventing two
3
+ * `pipeline-worker run` invocations from racing against the same working
4
+ * tree — e.g. one instance's `resetRepo` (`git reset --hard`) wiping out
5
+ * uncommitted changes another instance's `captureDiff` hasn't processed yet.
6
+ */
7
+ /**
8
+ * Acquires the lock, throwing if another live process already holds it. A
9
+ * lock left behind by a process that's no longer running (crash, kill -9) is
10
+ * treated as stale and reclaimed. Returns a release function; safe to call
11
+ * more than once.
12
+ *
13
+ * The final write uses the 'wx' flag (fails with EEXIST if the path already
14
+ * exists) as the actual mutual-exclusion guard — the existsSync/liveness
15
+ * check above is only a fast path to produce a clear "who's holding it"
16
+ * error message, since it's inherently racy against another process doing
17
+ * the same check concurrently.
18
+ */
19
+ export declare function acquireLock(repoRoot: string): () => void;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * A per-repo lockfile at <repoRoot>/.pipeline-worker/run.lock, preventing two
3
+ * `pipeline-worker run` invocations from racing against the same working
4
+ * tree — e.g. one instance's `resetRepo` (`git reset --hard`) wiping out
5
+ * uncommitted changes another instance's `captureDiff` hasn't processed yet.
6
+ */
7
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
8
+ import { join } from 'node:path';
9
+ function lockPath(repoRoot) {
10
+ return join(repoRoot, '.pipeline-worker', 'run.lock');
11
+ }
12
+ function isProcessAlive(pid) {
13
+ try {
14
+ // Signal 0 sends nothing but still validates the pid exists/is
15
+ // accessible — the standard liveness check on POSIX and Windows.
16
+ process.kill(pid, 0);
17
+ return true;
18
+ }
19
+ catch {
20
+ return false;
21
+ }
22
+ }
23
+ function removeIfPresent(path) {
24
+ try {
25
+ unlinkSync(path);
26
+ }
27
+ catch {
28
+ // Already gone (e.g. a concurrent process reclaimed it first) — fine.
29
+ }
30
+ }
31
+ /**
32
+ * Acquires the lock, throwing if another live process already holds it. A
33
+ * lock left behind by a process that's no longer running (crash, kill -9) is
34
+ * treated as stale and reclaimed. Returns a release function; safe to call
35
+ * more than once.
36
+ *
37
+ * The final write uses the 'wx' flag (fails with EEXIST if the path already
38
+ * exists) as the actual mutual-exclusion guard — the existsSync/liveness
39
+ * check above is only a fast path to produce a clear "who's holding it"
40
+ * error message, since it's inherently racy against another process doing
41
+ * the same check concurrently.
42
+ */
43
+ export function acquireLock(repoRoot) {
44
+ const dir = join(repoRoot, '.pipeline-worker');
45
+ mkdirSync(dir, { recursive: true });
46
+ const path = lockPath(repoRoot);
47
+ if (existsSync(path)) {
48
+ const heldPid = Number.parseInt(readFileSync(path, 'utf-8').trim(), 10);
49
+ if (Number.isInteger(heldPid) && isProcessAlive(heldPid)) {
50
+ throw new Error(`pipeline-worker: another run (pid ${heldPid}) is already in progress in this repo. ` +
51
+ 'Wait for it to finish, or if it crashed without cleaning up, remove .pipeline-worker/run.lock.');
52
+ }
53
+ removeIfPresent(path);
54
+ }
55
+ try {
56
+ writeFileSync(path, String(process.pid), { flag: 'wx' });
57
+ }
58
+ catch {
59
+ throw new Error('pipeline-worker: another run just started in this repo — try again.');
60
+ }
61
+ let released = false;
62
+ return () => {
63
+ if (released)
64
+ return;
65
+ released = true;
66
+ removeIfPresent(path);
67
+ };
68
+ }
69
+ //# sourceMappingURL=lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock.js","sourceRoot":"","sources":["../../src/state/lock.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,SAAS,QAAQ,CAAC,QAAgB;IAChC,OAAO,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,UAAU,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,IAAI,CAAC;QACH,+DAA+D;QAC/D,iEAAiE;QACjE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;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,3 +7,21 @@
7
7
  import type { RunState } from '../types.js';
8
8
  export declare function saveRunState(repoRoot: string, state: RunState): void;
9
9
  export declare function loadRunState(repoRoot: string, branch: string): RunState | undefined;
10
+ /**
11
+ * Appends a timestamped entry to state.history and persists it — this is the
12
+ * narration `pipeline-worker sessions --branch <name>` renders. Mutates
13
+ * `state` in place, matching how saveRunState is already called throughout
14
+ * orchestrate.ts/watchPipeline.ts.
15
+ */
16
+ export declare function recordEvent(repoRoot: string, state: RunState, message: string, level?: 'info' | 'error'): void;
17
+ export interface RunSession {
18
+ branch: string;
19
+ state: RunState;
20
+ }
21
+ /**
22
+ * Lists every persisted run in this repo (one per state file), most
23
+ * recently updated first. A corrupt/partial state file is skipped rather
24
+ * than failing the whole listing — `pipeline-worker sessions` should show
25
+ * what it can even if one run's file is damaged.
26
+ */
27
+ export declare function listRunStates(repoRoot: string): RunSession[];
@@ -4,17 +4,31 @@
4
4
  * lost state file only degrades `resume`/`status`, it never corrupts GitLab
5
5
  * state (the forge client's findExistingMr is the real idempotency guard).
6
6
  */
7
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
7
+ import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from 'node:fs';
8
+ import { randomUUID } from 'node:crypto';
8
9
  import { join } from 'node:path';
10
+ /** Caps state.history so a long-running CI-fix loop can't grow the state file unboundedly. */
11
+ const MAX_HISTORY_ENTRIES = 200;
12
+ function stateDir(repoRoot) {
13
+ return join(repoRoot, '.pipeline-worker', 'state');
14
+ }
9
15
  function statePath(repoRoot, branch) {
10
16
  const safeName = branch.replace(/\//g, '_');
11
- return join(repoRoot, '.pipeline-worker', 'state', `${safeName}.json`);
17
+ return join(stateDir(repoRoot), `${safeName}.json`);
12
18
  }
13
19
  export function saveRunState(repoRoot, state) {
14
20
  try {
21
+ const dir = stateDir(repoRoot);
22
+ mkdirSync(dir, { recursive: true });
15
23
  const path = statePath(repoRoot, state.branch);
16
- mkdirSync(join(repoRoot, '.pipeline-worker', 'state'), { recursive: true });
17
- writeFileSync(path, JSON.stringify(state, null, 2), 'utf-8');
24
+ // Write to a temp file in the same directory, then rename over the real
25
+ // path. A same-directory rename is atomic on POSIX and Windows, so a
26
+ // process kill mid-write can never leave a truncated/corrupt state file
27
+ // at `path` — a reader always sees either the previous complete write or
28
+ // the new one, never a partial one.
29
+ const tmpPath = join(dir, `.${randomUUID()}.tmp`);
30
+ writeFileSync(tmpPath, JSON.stringify(state, null, 2), 'utf-8');
31
+ renameSync(tmpPath, path);
18
32
  }
19
33
  catch (error) {
20
34
  const message = error instanceof Error ? error.message : String(error);
@@ -34,4 +48,42 @@ export function loadRunState(repoRoot, branch) {
34
48
  return undefined;
35
49
  }
36
50
  }
51
+ /**
52
+ * Appends a timestamped entry to state.history and persists it — this is the
53
+ * narration `pipeline-worker sessions --branch <name>` renders. Mutates
54
+ * `state` in place, matching how saveRunState is already called throughout
55
+ * orchestrate.ts/watchPipeline.ts.
56
+ */
57
+ export function recordEvent(repoRoot, state, message, level = 'info') {
58
+ const now = new Date().toISOString();
59
+ state.startedAt ??= now;
60
+ state.updatedAt = now;
61
+ const history = [...(state.history ?? []), { at: now, phase: state.phase, level, message }];
62
+ state.history = history.length > MAX_HISTORY_ENTRIES ? history.slice(history.length - MAX_HISTORY_ENTRIES) : history;
63
+ saveRunState(repoRoot, state);
64
+ }
65
+ /**
66
+ * Lists every persisted run in this repo (one per state file), most
67
+ * recently updated first. A corrupt/partial state file is skipped rather
68
+ * than failing the whole listing — `pipeline-worker sessions` should show
69
+ * what it can even if one run's file is damaged.
70
+ */
71
+ export function listRunStates(repoRoot) {
72
+ const dir = stateDir(repoRoot);
73
+ if (!existsSync(dir))
74
+ return [];
75
+ const sessions = [];
76
+ for (const entry of readdirSync(dir)) {
77
+ if (!entry.endsWith('.json'))
78
+ continue;
79
+ try {
80
+ const state = JSON.parse(readFileSync(join(dir, entry), 'utf-8'));
81
+ sessions.push({ branch: state.branch, state });
82
+ }
83
+ catch {
84
+ continue;
85
+ }
86
+ }
87
+ return sessions.sort((a, b) => (b.state.updatedAt ?? '').localeCompare(a.state.updatedAt ?? ''));
88
+ }
37
89
  //# sourceMappingURL=runState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runState.js","sourceRoot":"","sources":["../../src/state/runState.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,SAAS,SAAS,CAAC,QAAgB,EAAE,MAAc;IACjD,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,GAAG,QAAQ,OAAO,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,KAAe;IAC5D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/C,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5E,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CAAC,KAAK,CAAC,mDAAmD,KAAK,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC,CAAC;IAC/F,C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AAK,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,SAAS;QACvC,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,CAAa,CAAC;YAC9E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACjD,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;AACnG,CAAC"}
package/dist/types.d.ts CHANGED
@@ -29,6 +29,13 @@ export interface PipelineWorkerConfig {
29
29
  runLintAndTest: boolean;
30
30
  }
31
31
  export type RunPhase = 'diff' | 'intent' | 'checks' | 'mr' | 'watch' | 'done' | 'escalated';
32
+ /** One entry in RunState.history — a timestamped narration of what happened during the run, for `pipeline-worker sessions`. */
33
+ export interface RunHistoryEntry {
34
+ at: string;
35
+ phase: RunPhase;
36
+ level: 'info' | 'error';
37
+ message: string;
38
+ }
32
39
  export interface RunState {
33
40
  branch: string;
34
41
  targetBranch: string;
@@ -37,6 +44,12 @@ export interface RunState {
37
44
  pipelineId?: number;
38
45
  attempt: number;
39
46
  phase: RunPhase;
47
+ /** ISO 8601 timestamp of when this run was first created. Absent on state files written before this field existed. */
48
+ startedAt?: string;
49
+ /** ISO 8601 timestamp of the most recent state write. Absent on state files written before this field existed. */
50
+ updatedAt?: string;
51
+ /** Chronological log of phase transitions, escalations, and errors. Absent on state files written before this field existed. */
52
+ history?: RunHistoryEntry[];
40
53
  }
41
54
  export type RiskLevel = 'low' | 'medium' | 'high';
42
55
  export type ChangeType = 'feature' | 'bugfix' | 'chore';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Human-facing rendering for `pipeline-worker sessions` — lists and inspects
3
+ * runs persisted under .pipeline-worker/state/, mirroring the emoji/color
4
+ * narration style ui/steps.ts uses for a live run.
5
+ */
6
+ import type { RunSession } from '../state/runState.js';
7
+ /** `pipeline-worker sessions` with no --branch: one line per persisted run, most recently updated first. */
8
+ export declare function printSessionList(sessions: RunSession[]): void;
9
+ /** `pipeline-worker sessions --branch <name>`: one run's metadata plus its full step-by-step history. */
10
+ export declare function printSessionDetail(session: RunSession): void;