@imdeadpool/guardex 8.2.0 → 8.3.0

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.
@@ -20,6 +20,28 @@
20
20
  set -euo pipefail
21
21
 
22
22
  repo_root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
23
+ if [[ "${1:-}" == "--guardex-capabilities" ]]; then
24
+ printf '%s\n' 'guardex-target-worktree-v1'
25
+ exit 0
26
+ fi
27
+ if [[ "${1:-}" == "--guardex-target-worktree" ]]; then
28
+ if [[ "$#" -ne 2 || -z "$2" ]]; then
29
+ echo "[agent-preflight] --guardex-target-worktree requires exactly one path." >&2
30
+ exit 1
31
+ fi
32
+ GUARDEX_PREFLIGHT_TARGET_WORKTREE="$2"
33
+ fi
34
+ if [[ -n "${GUARDEX_PREFLIGHT_TARGET_WORKTREE:-}" ]]; then
35
+ repo_root="$(cd "$GUARDEX_PREFLIGHT_TARGET_WORKTREE" 2>/dev/null && pwd -P)" || {
36
+ echo "[agent-preflight] Invalid GUARDEX_PREFLIGHT_TARGET_WORKTREE." >&2
37
+ exit 1
38
+ }
39
+ target_git_root="$(git -C "$repo_root" rev-parse --show-toplevel 2>/dev/null || true)"
40
+ if [[ -z "$target_git_root" || "$(cd "$target_git_root" && pwd -P)" != "$repo_root" ]]; then
41
+ echo "[agent-preflight] Target is not a Git worktree root: $repo_root" >&2
42
+ exit 1
43
+ fi
44
+ fi
23
45
  cd "$repo_root"
24
46
 
25
47
  ran=0 # steps that PASSED
@@ -40,6 +62,14 @@ run_verification_command() {
40
62
  -u ALLOW_PUSH_ON_PROTECTED_BRANCH \
41
63
  -u GUARDEX_CLI_ENTRY \
42
64
  -u GUARDEX_NODE_BIN \
65
+ -u GUARDEX_FINISH_ACTIVE_CWD \
66
+ -u GUARDEX_FINISH_CHECKLIST \
67
+ -u GUARDEX_FINISH_GATE_DONE \
68
+ -u GUARDEX_FINISH_REQUIRE_PREFLIGHT \
69
+ -u GUARDEX_FINISH_EVENT_FILE \
70
+ -u GUARDEX_FINISH_RUN_ID \
71
+ -u GUARDEX_FINISH_EVENT_BRANCH \
72
+ -u GUARDEX_FINISH_EVENT_BASE \
43
73
  "$@"
44
74
  }
45
75
 
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const cp = require('node:child_process');
5
+ const fs = require('node:fs');
6
+ const path = require('node:path');
7
+
8
+ const TASK_LINE = /^(\s*-\s+\[)([ xX])(\]\s+.*)$/;
9
+ const TASKS_PATH = /^openspec\/changes\/[^/]+\/tasks\.md$/;
10
+
11
+ function isOpenSpecTasksPath(filePath) {
12
+ return TASKS_PATH.test(String(filePath || ''));
13
+ }
14
+
15
+ function mergeTaskDocuments(base, ours, theirs) {
16
+ const baseLines = String(base).split('\n');
17
+ const oursLines = String(ours).split('\n');
18
+ const theirsLines = String(theirs).split('\n');
19
+ if (baseLines.length !== oursLines.length || oursLines.length !== theirsLines.length) {
20
+ throw new Error('task documents have different line counts');
21
+ }
22
+
23
+ let taskCount = 0;
24
+ const merged = oursLines.map((oursLine, index) => {
25
+ const baseLine = baseLines[index];
26
+ const theirsLine = theirsLines[index];
27
+ const baseTask = baseLine.match(TASK_LINE);
28
+ const oursTask = oursLine.match(TASK_LINE);
29
+ const theirsTask = theirsLine.match(TASK_LINE);
30
+
31
+ if (!baseTask && !oursTask && !theirsTask) {
32
+ if (baseLine !== oursLine || oursLine !== theirsLine) {
33
+ throw new Error(`non-checklist content differs at line ${index + 1}`);
34
+ }
35
+ return oursLine;
36
+ }
37
+ if (!baseTask || !oursTask || !theirsTask) {
38
+ throw new Error(`checklist structure differs at line ${index + 1}`);
39
+ }
40
+ const baseText = `${baseTask[1]} ${baseTask[3]}`;
41
+ if (
42
+ baseText !== `${oursTask[1]} ${oursTask[3]}` ||
43
+ baseText !== `${theirsTask[1]} ${theirsTask[3]}`
44
+ ) {
45
+ throw new Error(`checklist text differs at line ${index + 1}`);
46
+ }
47
+
48
+ taskCount += 1;
49
+ const baseChecked = /x/i.test(baseTask[2]);
50
+ const oursChecked = /x/i.test(oursTask[2]);
51
+ const theirsChecked = /x/i.test(theirsTask[2]);
52
+ const checked = oursChecked === baseChecked ? theirsChecked : oursChecked;
53
+ return `${oursTask[1]}${checked ? 'x' : ' '}${oursTask[3]}`;
54
+ });
55
+
56
+ if (taskCount === 0) {
57
+ throw new Error('task document contains no checklist items');
58
+ }
59
+ return merged.join('\n');
60
+ }
61
+
62
+ function readIndexStage(worktree, stage, filePath) {
63
+ return cp.execFileSync('git', ['-C', worktree, 'show', `:${stage}:${filePath}`], {
64
+ encoding: 'utf8',
65
+ maxBuffer: 4 * 1024 * 1024
66
+ });
67
+ }
68
+
69
+ function reconcileFromIndex(worktree, filePath) {
70
+ if (!isOpenSpecTasksPath(filePath)) {
71
+ throw new Error(`unsupported conflict path: ${filePath}`);
72
+ }
73
+ const base = readIndexStage(worktree, 1, filePath);
74
+ const ours = readIndexStage(worktree, 2, filePath);
75
+ const theirs = readIndexStage(worktree, 3, filePath);
76
+ const merged = mergeTaskDocuments(base, ours, theirs);
77
+ const destination = path.join(worktree, filePath);
78
+ fs.writeFileSync(destination, merged);
79
+ cp.execFileSync('git', ['-C', worktree, 'add', '--', filePath], { stdio: 'pipe' });
80
+ return merged;
81
+ }
82
+
83
+ function main(argv) {
84
+ const [worktree, filePath] = argv;
85
+ if (!worktree || !filePath) {
86
+ throw new Error('usage: agent-reconcile-openspec-tasks.js <worktree> <path>');
87
+ }
88
+ reconcileFromIndex(path.resolve(worktree), filePath);
89
+ process.stdout.write(`${filePath}\n`);
90
+ }
91
+
92
+ if (require.main === module) {
93
+ try {
94
+ main(process.argv.slice(2));
95
+ } catch (error) {
96
+ process.stderr.write(`[agent-reconcile-openspec-tasks] ${error.message}\n`);
97
+ process.exitCode = 2;
98
+ }
99
+ }
100
+
101
+ module.exports = {
102
+ isOpenSpecTasksPath,
103
+ mergeTaskDocuments,
104
+ reconcileFromIndex
105
+ };