pipeline-worker 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/copilot.d.ts +7 -2
- package/dist/agent/copilot.js +8 -3
- package/dist/agent/copilot.js.map +1 -1
- package/dist/cli.js +32 -2
- package/dist/cli.js.map +1 -1
- package/dist/git/worktree.d.ts +21 -1
- package/dist/git/worktree.js +41 -3
- package/dist/git/worktree.js.map +1 -1
- package/package.json +1 -1
package/dist/agent/copilot.d.ts
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
* Headless GitHub Copilot CLI adapter. Flags verified against GitHub's
|
|
3
3
|
* "Copilot CLI programmatic reference" docs: `-s` (suppress stats/decoration,
|
|
4
4
|
* output only the agent's response), `--no-ask-user`, `--allow-all-tools`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* and `--allow-all-paths` — both required for unattended fix runs, since
|
|
6
|
+
* tool approval and path/directory-trust approval are separate gates in
|
|
7
|
+
* Copilot CLI. Without `--allow-all-paths`, every run's disposable worktree
|
|
8
|
+
* is a directory Copilot has never seen before, so any shell command
|
|
9
|
+
* touching files there (e.g. listing test projects) trips the "trust this
|
|
10
|
+
* directory?" prompt; with no TTY to answer it, the CLI fails with
|
|
11
|
+
* permission-denied instead. Known gaps vs the Claude adapter, handled here:
|
|
7
12
|
* - no structured-output/JSON-schema flag -> the schema is embedded in the
|
|
8
13
|
* prompt and the JSON object is extracted from the response text;
|
|
9
14
|
* - no per-invocation MCP config flag -> Copilot only reads
|
package/dist/agent/copilot.js
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
* Headless GitHub Copilot CLI adapter. Flags verified against GitHub's
|
|
3
3
|
* "Copilot CLI programmatic reference" docs: `-s` (suppress stats/decoration,
|
|
4
4
|
* output only the agent's response), `--no-ask-user`, `--allow-all-tools`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* and `--allow-all-paths` — both required for unattended fix runs, since
|
|
6
|
+
* tool approval and path/directory-trust approval are separate gates in
|
|
7
|
+
* Copilot CLI. Without `--allow-all-paths`, every run's disposable worktree
|
|
8
|
+
* is a directory Copilot has never seen before, so any shell command
|
|
9
|
+
* touching files there (e.g. listing test projects) trips the "trust this
|
|
10
|
+
* directory?" prompt; with no TTY to answer it, the CLI fails with
|
|
11
|
+
* permission-denied instead. Known gaps vs the Claude adapter, handled here:
|
|
7
12
|
* - no structured-output/JSON-schema flag -> the schema is embedded in the
|
|
8
13
|
* prompt and the JSON object is extracted from the response text;
|
|
9
14
|
* - no per-invocation MCP config flag -> Copilot only reads
|
|
@@ -50,7 +55,7 @@ export const copilotAdapter = {
|
|
|
50
55
|
console.error(`pipeline-worker: copilot CLI has no per-invocation model flag; ignoring the configured model "${opts.model}". ` +
|
|
51
56
|
"Switch copilot's model via its own /model command or config instead.");
|
|
52
57
|
}
|
|
53
|
-
const invocation = execFileAsync('copilot', ['-s', '--no-ask-user', '--allow-all-tools'], {
|
|
58
|
+
const invocation = execFileAsync('copilot', ['-s', '--no-ask-user', '--allow-all-tools', '--allow-all-paths'], {
|
|
54
59
|
cwd: opts.cwd,
|
|
55
60
|
timeout: INVOKE_TIMEOUT_MS,
|
|
56
61
|
maxBuffer: 64 * 1024 * 1024,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copilot.js","sourceRoot":"","sources":["../../src/agent/copilot.ts"],"names":[],"mappings":"AAAA
|
|
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,QA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K,CAAC,KAAM,EAAE,MAAM,CAAC,CAAC;QACpD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC;QAEpC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;IAC/E,CAAC;CACF,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -9,7 +9,8 @@ import { startServer } from './mcp/server.js';
|
|
|
9
9
|
import { loadConfig } from './config/loader.js';
|
|
10
10
|
import { createForge } from './forge/index.js';
|
|
11
11
|
import { selectAgent } from './agent/index.js';
|
|
12
|
-
import { loadRunState } from './state/runState.js';
|
|
12
|
+
import { loadRunState, saveRunState } from './state/runState.js';
|
|
13
|
+
import { isWorktreeOnBranch, checkoutExistingBranch, removeWorktree } from './git/worktree.js';
|
|
13
14
|
import { buildEnvelope, errorEnvelope } from './toon/envelope.js';
|
|
14
15
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
16
|
const pkg = JSON.parse(readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
@@ -56,7 +57,36 @@ program
|
|
|
56
57
|
const config = loadConfig(repoRoot);
|
|
57
58
|
const forge = createForge(config);
|
|
58
59
|
const agent = selectAgent(config);
|
|
59
|
-
|
|
60
|
+
// The worktree from the crashed run is almost always already gone by
|
|
61
|
+
// this point (orchestrate.ts's `finally` removes it on any exception,
|
|
62
|
+
// and on SIGINT/SIGTERM) — reuse it only in the narrow case it
|
|
63
|
+
// survived (e.g. a SIGKILL), otherwise recreate it from the branch's
|
|
64
|
+
// current state on origin.
|
|
65
|
+
const worktreePath = (await isWorktreeOnBranch(state.worktreePath, state.branch))
|
|
66
|
+
? state.worktreePath
|
|
67
|
+
: await checkoutExistingBranch(repoRoot, state.branch);
|
|
68
|
+
if (worktreePath !== state.worktreePath) {
|
|
69
|
+
state.worktreePath = worktreePath;
|
|
70
|
+
saveRunState(repoRoot, state);
|
|
71
|
+
}
|
|
72
|
+
let cleanedUp = false;
|
|
73
|
+
const cleanup = async () => {
|
|
74
|
+
if (cleanedUp)
|
|
75
|
+
return;
|
|
76
|
+
cleanedUp = true;
|
|
77
|
+
await removeWorktree(repoRoot, worktreePath);
|
|
78
|
+
};
|
|
79
|
+
const onSignal = (exitCode) => {
|
|
80
|
+
void cleanup().then(() => process.exit(exitCode));
|
|
81
|
+
};
|
|
82
|
+
process.once('SIGINT', () => onSignal(130));
|
|
83
|
+
process.once('SIGTERM', () => onSignal(143));
|
|
84
|
+
try {
|
|
85
|
+
await watchPipeline(forge, config, agent, worktreePath, state.branch, state.targetBranch, state.mrIid, state, repoRoot);
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
await cleanup();
|
|
89
|
+
}
|
|
60
90
|
console.log(`pipeline-worker: resumed run finished with phase "${state.phase}".`);
|
|
61
91
|
}
|
|
62
92
|
catch (error) {
|
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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AAC,WAAW,EAAE,iCAAiC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACxF,OAAO;IACT,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AACjE,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"}
|
package/dist/git/worktree.d.ts
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Isolated git worktree management. The caller's own working directory is
|
|
3
3
|
* never touched — all workflow steps run inside a disposable worktree that
|
|
4
|
-
* is always removed afterward (see workflow/orchestrate.ts's
|
|
4
|
+
* is always removed afterward (see workflow/orchestrate.ts's and cli.ts's
|
|
5
|
+
* `resume` command's finally blocks).
|
|
5
6
|
*/
|
|
6
7
|
export declare function generateTempBranchName(): string;
|
|
7
8
|
/** Creates a new worktree off HEAD on a fresh branch, returning its path. */
|
|
8
9
|
export declare function createWorktree(repoRoot: string, branchName: string): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* True when `worktreePath` still exists and is checked out to exactly
|
|
12
|
+
* `branch` — the narrow case where a crashed run's original worktree
|
|
13
|
+
* survived (e.g. a SIGKILL that skipped orchestrate.ts's cleanup). Any
|
|
14
|
+
* failure (path missing, not a git worktree, detached HEAD) is treated as
|
|
15
|
+
* "not valid" rather than thrown, since the caller's fallback
|
|
16
|
+
* (checkoutExistingBranch) is always safe to fall back on.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isWorktreeOnBranch(worktreePath: string, branch: string): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Checks out a branch that already exists on origin (used by `pipeline-worker
|
|
21
|
+
* resume`, where the original worktree from the crashed run is normally
|
|
22
|
+
* already gone — see orchestrate.ts's unconditional cleanup). Fetches first
|
|
23
|
+
* and resets the local branch to match origin/branch with `-B` rather than
|
|
24
|
+
* reusing whatever local ref might already exist, so the worktree reflects
|
|
25
|
+
* the branch's actual current state on the forge (what CI is really running
|
|
26
|
+
* against) instead of a possibly stale/diverged local copy.
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkoutExistingBranch(repoRoot: string, branch: string): Promise<string>;
|
|
9
29
|
/**
|
|
10
30
|
* Fetches origin and rebases the worktree's branch onto origin/targetBranch,
|
|
11
31
|
* so the diff applied afterward lands on the freshest possible base instead
|
package/dist/git/worktree.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Isolated git worktree management. The caller's own working directory is
|
|
3
3
|
* never touched — all workflow steps run inside a disposable worktree that
|
|
4
|
-
* is always removed afterward (see workflow/orchestrate.ts's
|
|
4
|
+
* is always removed afterward (see workflow/orchestrate.ts's and cli.ts's
|
|
5
|
+
* `resume` command's finally blocks).
|
|
5
6
|
*/
|
|
6
7
|
import { execFile } from 'node:child_process';
|
|
7
8
|
import { promisify } from 'node:util';
|
|
@@ -45,13 +46,50 @@ function linkNodeModules(repoRoot, worktreePath) {
|
|
|
45
46
|
}
|
|
46
47
|
symlinkSync(sourceNodeModules, destNodeModules, 'dir');
|
|
47
48
|
}
|
|
49
|
+
function newWorktreeDir() {
|
|
50
|
+
const parentDir = mkdtempSync(join(tmpdir(), 'pipeline-worker-'));
|
|
51
|
+
return join(parentDir, 'worktree');
|
|
52
|
+
}
|
|
48
53
|
/** Creates a new worktree off HEAD on a fresh branch, returning its path. */
|
|
49
54
|
export async function createWorktree(repoRoot, branchName) {
|
|
50
|
-
const
|
|
51
|
-
const worktreePath = join(parentDir, 'worktree');
|
|
55
|
+
const worktreePath = newWorktreeDir();
|
|
52
56
|
await execFileAsync('git', ['worktree', 'add', '-b', branchName, worktreePath, 'HEAD'], { cwd: repoRoot });
|
|
53
57
|
return worktreePath;
|
|
54
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* True when `worktreePath` still exists and is checked out to exactly
|
|
61
|
+
* `branch` — the narrow case where a crashed run's original worktree
|
|
62
|
+
* survived (e.g. a SIGKILL that skipped orchestrate.ts's cleanup). Any
|
|
63
|
+
* failure (path missing, not a git worktree, detached HEAD) is treated as
|
|
64
|
+
* "not valid" rather than thrown, since the caller's fallback
|
|
65
|
+
* (checkoutExistingBranch) is always safe to fall back on.
|
|
66
|
+
*/
|
|
67
|
+
export async function isWorktreeOnBranch(worktreePath, branch) {
|
|
68
|
+
if (!existsSync(worktreePath))
|
|
69
|
+
return false;
|
|
70
|
+
try {
|
|
71
|
+
const { stdout } = await execFileAsync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: worktreePath });
|
|
72
|
+
return stdout.trim() === branch;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Checks out a branch that already exists on origin (used by `pipeline-worker
|
|
80
|
+
* resume`, where the original worktree from the crashed run is normally
|
|
81
|
+
* already gone — see orchestrate.ts's unconditional cleanup). Fetches first
|
|
82
|
+
* and resets the local branch to match origin/branch with `-B` rather than
|
|
83
|
+
* reusing whatever local ref might already exist, so the worktree reflects
|
|
84
|
+
* the branch's actual current state on the forge (what CI is really running
|
|
85
|
+
* against) instead of a possibly stale/diverged local copy.
|
|
86
|
+
*/
|
|
87
|
+
export async function checkoutExistingBranch(repoRoot, branch) {
|
|
88
|
+
const worktreePath = newWorktreeDir();
|
|
89
|
+
await execFileAsync('git', ['fetch', 'origin', branch], { cwd: repoRoot });
|
|
90
|
+
await execFileAsync('git', ['worktree', 'add', '-B', branch, worktreePath, `origin/${branch}`], { cwd: repoRoot });
|
|
91
|
+
return worktreePath;
|
|
92
|
+
}
|
|
55
93
|
/**
|
|
56
94
|
* Fetches origin and rebases the worktree's branch onto origin/targetBranch,
|
|
57
95
|
* so the diff applied afterward lands on the freshest possible base instead
|
package/dist/git/worktree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktree.js","sourceRoot":"","sources":["../../src/git/worktree.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worktree.js","sourceRoot":"","sources":["../../src/git/worktree.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACrH,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,MAAM,UAAU,sBAAsB;IACpC,OAAO,uBAAuB,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,eAAe,CAAC,QAAgB,EAAE,YAAoB;IAC7D,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IACzD,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC;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AAE,YAAY,EAAE,CAAC,CAAC;AACrF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,QAAgB,EAAE,YAAoB;IACzE,IAAI,CAAC;QACH,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;IACjG,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,sCAAsC,YAAY,KAAK,OAAO,EAAE,CAAC,CAAC;IAClF,CAAC;IAED,yEAAyE;IACzE,yFAAyF;IACzF,IAAI,CAAC;QACH,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAClE,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,YAAY,KAAK,OAAO,EAAE,CAAC,CAAC;IAC/F,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pipeline-worker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Automated git-worktree workflow: captures intent from a diff via Claude Code or GitHub Copilot CLI, runs build/lint/test, opens a GitLab MR or GitHub PR, and auto-fixes failing pipelines — with a companion forge MCP server (TOON-encoded responses).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mohan TN <mohan.tn100@gmail.com>",
|