oxe-cc 0.9.2 → 1.0.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.
Files changed (163) hide show
  1. package/.cursor/commands/oxe-retro.md +2 -2
  2. package/.cursor/commands/oxe-spec.md +2 -2
  3. package/.github/prompts/oxe-retro.prompt.md +2 -2
  4. package/.github/prompts/oxe-spec.prompt.md +2 -2
  5. package/README.md +1 -1
  6. package/bin/banner.txt +1 -1
  7. package/bin/lib/oxe-context-engine.cjs +1 -0
  8. package/bin/lib/oxe-dashboard.cjs +9 -7
  9. package/bin/lib/oxe-operational.cjs +569 -4
  10. package/bin/oxe-cc.js +141 -57
  11. package/commands/oxe/retro.md +2 -2
  12. package/commands/oxe/spec.md +2 -2
  13. package/lib/runtime/compiler/graph-compiler.d.ts +83 -0
  14. package/lib/runtime/compiler/graph-compiler.js +135 -0
  15. package/lib/runtime/compiler/index.d.ts +1 -0
  16. package/lib/runtime/compiler/index.js +17 -0
  17. package/lib/runtime/context/context-pack-builder.d.ts +36 -0
  18. package/lib/runtime/context/context-pack-builder.js +136 -0
  19. package/lib/runtime/context/index.d.ts +1 -0
  20. package/lib/runtime/context/index.js +17 -0
  21. package/lib/runtime/delivery/branch-manager.d.ts +19 -0
  22. package/lib/runtime/delivery/branch-manager.js +78 -0
  23. package/lib/runtime/delivery/ci-checks.d.ts +34 -0
  24. package/lib/runtime/delivery/ci-checks.js +209 -0
  25. package/lib/runtime/delivery/index.d.ts +3 -0
  26. package/lib/runtime/delivery/index.js +19 -0
  27. package/lib/runtime/delivery/pr-manager.d.ts +30 -0
  28. package/lib/runtime/delivery/pr-manager.js +82 -0
  29. package/lib/runtime/events/bus.d.ts +9 -0
  30. package/lib/runtime/events/bus.js +63 -0
  31. package/lib/runtime/events/catalog.d.ts +3 -0
  32. package/lib/runtime/events/catalog.js +30 -0
  33. package/lib/runtime/events/envelope.d.ts +13 -0
  34. package/lib/runtime/events/envelope.js +2 -0
  35. package/lib/runtime/events/index.d.ts +3 -0
  36. package/lib/runtime/events/index.js +19 -0
  37. package/lib/runtime/evidence/evidence-store.d.ts +22 -0
  38. package/lib/runtime/evidence/evidence-store.js +106 -0
  39. package/lib/runtime/evidence/index.d.ts +1 -0
  40. package/lib/runtime/evidence/index.js +17 -0
  41. package/lib/runtime/gate/gate-manager.d.ts +39 -0
  42. package/lib/runtime/gate/gate-manager.js +104 -0
  43. package/lib/runtime/gate/index.d.ts +1 -0
  44. package/lib/runtime/gate/index.js +17 -0
  45. package/lib/runtime/index.d.ts +16 -0
  46. package/lib/runtime/index.js +40 -0
  47. package/lib/runtime/models/attempt.d.ts +12 -0
  48. package/lib/runtime/models/attempt.js +2 -0
  49. package/lib/runtime/models/evidence.d.ts +9 -0
  50. package/lib/runtime/models/evidence.js +2 -0
  51. package/lib/runtime/models/gate-decision.d.ts +10 -0
  52. package/lib/runtime/models/gate-decision.js +2 -0
  53. package/lib/runtime/models/index.d.ts +8 -0
  54. package/lib/runtime/models/index.js +24 -0
  55. package/lib/runtime/models/run.d.ts +13 -0
  56. package/lib/runtime/models/run.js +2 -0
  57. package/lib/runtime/models/session.d.ts +10 -0
  58. package/lib/runtime/models/session.js +2 -0
  59. package/lib/runtime/models/verification-result.d.ts +9 -0
  60. package/lib/runtime/models/verification-result.js +2 -0
  61. package/lib/runtime/models/work-item.d.ts +15 -0
  62. package/lib/runtime/models/work-item.js +2 -0
  63. package/lib/runtime/models/workspace.d.ts +25 -0
  64. package/lib/runtime/models/workspace.js +2 -0
  65. package/lib/runtime/plugins/index.d.ts +2 -0
  66. package/lib/runtime/plugins/index.js +18 -0
  67. package/lib/runtime/plugins/plugin-abi.d.ts +76 -0
  68. package/lib/runtime/plugins/plugin-abi.js +2 -0
  69. package/lib/runtime/plugins/plugin-registry.d.ts +21 -0
  70. package/lib/runtime/plugins/plugin-registry.js +114 -0
  71. package/lib/runtime/policy/index.d.ts +1 -0
  72. package/lib/runtime/policy/index.js +17 -0
  73. package/lib/runtime/policy/policy-engine.d.ts +40 -0
  74. package/lib/runtime/policy/policy-engine.js +80 -0
  75. package/lib/runtime/projection/index.d.ts +1 -0
  76. package/lib/runtime/projection/index.js +17 -0
  77. package/lib/runtime/projection/projection-engine.d.ts +11 -0
  78. package/lib/runtime/projection/projection-engine.js +218 -0
  79. package/lib/runtime/reducers/debug-reducer.d.ts +10 -0
  80. package/lib/runtime/reducers/debug-reducer.js +30 -0
  81. package/lib/runtime/reducers/index.d.ts +2 -0
  82. package/lib/runtime/reducers/index.js +18 -0
  83. package/lib/runtime/reducers/run-state-reducer.d.ts +20 -0
  84. package/lib/runtime/reducers/run-state-reducer.js +110 -0
  85. package/lib/runtime/scheduler/index.d.ts +1 -0
  86. package/lib/runtime/scheduler/index.js +17 -0
  87. package/lib/runtime/scheduler/multi-agent-coordinator.d.ts +34 -0
  88. package/lib/runtime/scheduler/multi-agent-coordinator.js +166 -0
  89. package/lib/runtime/scheduler/scheduler.d.ts +39 -0
  90. package/lib/runtime/scheduler/scheduler.js +196 -0
  91. package/lib/runtime/verification/index.d.ts +1 -0
  92. package/lib/runtime/verification/index.js +17 -0
  93. package/lib/runtime/verification/verification-compiler.d.ts +56 -0
  94. package/lib/runtime/verification/verification-compiler.js +147 -0
  95. package/lib/runtime/workspace/index.d.ts +5 -0
  96. package/lib/runtime/workspace/index.js +24 -0
  97. package/lib/runtime/workspace/strategies/ephemeral-container.d.ts +22 -0
  98. package/lib/runtime/workspace/strategies/ephemeral-container.js +109 -0
  99. package/lib/runtime/workspace/strategies/git-worktree.d.ts +12 -0
  100. package/lib/runtime/workspace/strategies/git-worktree.js +79 -0
  101. package/lib/runtime/workspace/strategies/inplace.d.ts +10 -0
  102. package/lib/runtime/workspace/strategies/inplace.js +37 -0
  103. package/lib/runtime/workspace/workspace-manager.d.ts +13 -0
  104. package/lib/runtime/workspace/workspace-manager.js +2 -0
  105. package/lib/sdk/index.cjs +24 -7
  106. package/lib/sdk/index.d.ts +17 -7
  107. package/oxe/templates/LESSONS-METRICS.template.json +13 -0
  108. package/oxe/workflows/references/robustness-elevation.md +295 -0
  109. package/oxe/workflows/references/workflow-runtime-contracts.json +32 -4
  110. package/oxe/workflows/retro.md +21 -0
  111. package/oxe/workflows/spec.md +50 -26
  112. package/oxe/workflows/verify.md +36 -0
  113. package/package.json +9 -3
  114. package/packages/runtime/package.json +17 -0
  115. package/packages/runtime/src/compiler/graph-compiler.ts +245 -0
  116. package/packages/runtime/src/compiler/index.ts +1 -0
  117. package/packages/runtime/src/context/context-pack-builder.ts +193 -0
  118. package/packages/runtime/src/context/index.ts +1 -0
  119. package/packages/runtime/src/delivery/branch-manager.ts +84 -0
  120. package/packages/runtime/src/delivery/ci-checks.ts +252 -0
  121. package/packages/runtime/src/delivery/index.ts +3 -0
  122. package/packages/runtime/src/delivery/pr-manager.ts +112 -0
  123. package/packages/runtime/src/events/bus.ts +92 -0
  124. package/packages/runtime/src/events/catalog.ts +29 -0
  125. package/packages/runtime/src/events/envelope.ts +14 -0
  126. package/packages/runtime/src/events/index.ts +3 -0
  127. package/packages/runtime/src/evidence/evidence-store.ts +130 -0
  128. package/packages/runtime/src/evidence/index.ts +1 -0
  129. package/packages/runtime/src/gate/gate-manager.ts +137 -0
  130. package/packages/runtime/src/gate/index.ts +1 -0
  131. package/packages/runtime/src/index.ts +32 -0
  132. package/packages/runtime/src/models/attempt.ts +19 -0
  133. package/packages/runtime/src/models/evidence.ts +21 -0
  134. package/packages/runtime/src/models/gate-decision.ts +21 -0
  135. package/packages/runtime/src/models/index.ts +8 -0
  136. package/packages/runtime/src/models/run.ts +24 -0
  137. package/packages/runtime/src/models/session.ts +11 -0
  138. package/packages/runtime/src/models/verification-result.ts +10 -0
  139. package/packages/runtime/src/models/work-item.ts +25 -0
  140. package/packages/runtime/src/models/workspace.ts +28 -0
  141. package/packages/runtime/src/plugins/index.ts +2 -0
  142. package/packages/runtime/src/plugins/plugin-abi.ts +95 -0
  143. package/packages/runtime/src/plugins/plugin-registry.ts +119 -0
  144. package/packages/runtime/src/policy/index.ts +1 -0
  145. package/packages/runtime/src/policy/policy-engine.ts +113 -0
  146. package/packages/runtime/src/projection/index.ts +1 -0
  147. package/packages/runtime/src/projection/projection-engine.ts +249 -0
  148. package/packages/runtime/src/reducers/debug-reducer.ts +36 -0
  149. package/packages/runtime/src/reducers/index.ts +2 -0
  150. package/packages/runtime/src/reducers/run-state-reducer.ts +127 -0
  151. package/packages/runtime/src/scheduler/index.ts +1 -0
  152. package/packages/runtime/src/scheduler/multi-agent-coordinator.ts +231 -0
  153. package/packages/runtime/src/scheduler/scheduler.ts +281 -0
  154. package/packages/runtime/src/verification/index.ts +1 -0
  155. package/packages/runtime/src/verification/verification-compiler.ts +225 -0
  156. package/packages/runtime/src/workspace/index.ts +5 -0
  157. package/packages/runtime/src/workspace/strategies/ephemeral-container.ts +121 -0
  158. package/packages/runtime/src/workspace/strategies/git-worktree.ts +77 -0
  159. package/packages/runtime/src/workspace/strategies/inplace.ts +35 -0
  160. package/packages/runtime/src/workspace/workspace-manager.ts +15 -0
  161. package/packages/runtime/tsconfig.json +17 -0
  162. package/vscode-extension/oxe-agents-1.0.0.vsix +0 -0
  163. package/vscode-extension/package.json +1 -1
@@ -0,0 +1,193 @@
1
+ import type { WorkItem } from '../models/work-item';
2
+ import type { Evidence } from '../models/evidence';
3
+ import type { RunState } from '../reducers/run-state-reducer';
4
+
5
+ export interface ContextArtifact {
6
+ id: string;
7
+ kind: 'evidence' | 'lesson' | 'file' | 'summary';
8
+ content: string;
9
+ relevanceScore: number;
10
+ tags: string[];
11
+ }
12
+
13
+ export interface LessonMetric {
14
+ lesson_id: string;
15
+ title: string;
16
+ tags: string[];
17
+ embedding?: number[];
18
+ content: string;
19
+ }
20
+
21
+ export interface ContextPackOptions {
22
+ maxArtifacts?: number;
23
+ maxTokensEstimate?: number;
24
+ deduplicateThreshold?: number;
25
+ }
26
+
27
+ export interface ContextPack {
28
+ work_item_id: string;
29
+ artifacts: ContextArtifact[];
30
+ total_artifacts_considered: number;
31
+ redundancy_removed: number;
32
+ built_at: string;
33
+ }
34
+
35
+ // ─── Relevance scoring ────────────────────────────────────────────────────────
36
+
37
+ function scoreEvidenceRelevance(evidence: Evidence, workItem: WorkItem): number {
38
+ let score = 0.5;
39
+ const eid = evidence.evidence_id.toLowerCase();
40
+ const title = workItem.title.toLowerCase();
41
+ const scope = workItem.mutation_scope ?? [];
42
+
43
+ if (scope.some((s) => eid.includes(s.toLowerCase()))) score += 0.3;
44
+ if (title.split(/\s+/).some((w) => w.length > 3 && eid.includes(w))) score += 0.1;
45
+ if (evidence.type === 'junit_xml') score += 0.05;
46
+ if (evidence.type === 'diff') score += 0.05;
47
+
48
+ return Math.min(score, 1.0);
49
+ }
50
+
51
+ function scoreLessonRelevance(lesson: LessonMetric, workItem: WorkItem): number {
52
+ const itemTags = new Set([
53
+ ...workItem.mutation_scope.map((s) => s.toLowerCase()),
54
+ ...workItem.title.toLowerCase().split(/\s+/).filter((w) => w.length > 3),
55
+ ]);
56
+
57
+ const lessonTags = lesson.tags.map((t) => t.toLowerCase());
58
+ const overlap = lessonTags.filter((t) => itemTags.has(t)).length;
59
+ const jaccard = overlap / (itemTags.size + lessonTags.length - overlap || 1);
60
+
61
+ return Math.min(0.3 + jaccard * 0.7, 1.0);
62
+ }
63
+
64
+ // ─── Redundancy elimination ───────────────────────────────────────────────────
65
+
66
+ function cosineSimilarity(a: ContextArtifact, b: ContextArtifact): number {
67
+ const wordsA = new Set(a.content.toLowerCase().split(/\W+/).filter((w) => w.length > 3));
68
+ const wordsB = new Set(b.content.toLowerCase().split(/\W+/).filter((w) => w.length > 3));
69
+ if (wordsA.size === 0 || wordsB.size === 0) return 0;
70
+
71
+ let intersection = 0;
72
+ for (const w of wordsA) if (wordsB.has(w)) intersection++;
73
+ return intersection / Math.sqrt(wordsA.size * wordsB.size);
74
+ }
75
+
76
+ function deduplicateArtifacts(artifacts: ContextArtifact[], threshold: number): { kept: ContextArtifact[]; removed: number } {
77
+ const kept: ContextArtifact[] = [];
78
+ let removed = 0;
79
+
80
+ for (const candidate of artifacts) {
81
+ const isDuplicate = kept.some((existing) => cosineSimilarity(candidate, existing) >= threshold);
82
+ if (isDuplicate) {
83
+ removed++;
84
+ } else {
85
+ kept.push(candidate);
86
+ }
87
+ }
88
+
89
+ return { kept, removed };
90
+ }
91
+
92
+ // ─── Token budget estimation ──────────────────────────────────────────────────
93
+
94
+ function estimateTokens(text: string): number {
95
+ return Math.ceil(text.length / 4);
96
+ }
97
+
98
+ function applyTokenBudget(artifacts: ContextArtifact[], maxTokens: number): ContextArtifact[] {
99
+ let used = 0;
100
+ const result: ContextArtifact[] = [];
101
+ for (const a of artifacts) {
102
+ const t = estimateTokens(a.content);
103
+ if (used + t > maxTokens) break;
104
+ result.push(a);
105
+ used += t;
106
+ }
107
+ return result;
108
+ }
109
+
110
+ // ─── Context Pack Builder ─────────────────────────────────────────────────────
111
+
112
+ export class ContextPackBuilder {
113
+ constructor(private readonly opts: ContextPackOptions = {}) {}
114
+
115
+ build(
116
+ workItem: WorkItem,
117
+ state: RunState,
118
+ evidenceItems: Evidence[],
119
+ evidenceContents: Map<string, string>,
120
+ lessons: LessonMetric[],
121
+ ): ContextPack {
122
+ const {
123
+ maxArtifacts = 20,
124
+ maxTokensEstimate = 8000,
125
+ deduplicateThreshold = 0.85,
126
+ } = this.opts;
127
+
128
+ const raw: ContextArtifact[] = [];
129
+
130
+ // Score and collect evidence
131
+ for (const ev of evidenceItems) {
132
+ const content = evidenceContents.get(ev.evidence_id) ?? '';
133
+ if (!content) continue;
134
+ raw.push({
135
+ id: ev.evidence_id,
136
+ kind: 'evidence',
137
+ content,
138
+ relevanceScore: scoreEvidenceRelevance(ev, workItem),
139
+ tags: [ev.type, workItem.work_item_id],
140
+ });
141
+ }
142
+
143
+ // Score and collect lessons
144
+ for (const lesson of lessons) {
145
+ raw.push({
146
+ id: lesson.lesson_id,
147
+ kind: 'lesson',
148
+ content: lesson.content,
149
+ relevanceScore: scoreLessonRelevance(lesson, workItem),
150
+ tags: lesson.tags,
151
+ });
152
+ }
153
+
154
+ // Add run-level summary if available
155
+ const completedCount = state.completedWorkItems.size;
156
+ if (completedCount > 0) {
157
+ raw.push({
158
+ id: `run-summary-${workItem.run_id}`,
159
+ kind: 'summary',
160
+ content: `Run progress: ${completedCount} completed, ${state.failedWorkItems.size} failed, ${state.blockedWorkItems.size} blocked.`,
161
+ relevanceScore: 0.4,
162
+ tags: ['run-context'],
163
+ });
164
+ }
165
+
166
+ const totalConsidered = raw.length;
167
+
168
+ // Sort by relevance descending
169
+ raw.sort((a, b) => b.relevanceScore - a.relevanceScore);
170
+
171
+ // Deduplicate
172
+ const { kept, removed } = deduplicateArtifacts(raw, deduplicateThreshold);
173
+
174
+ // Apply max artifacts cap
175
+ const capped = kept.slice(0, maxArtifacts);
176
+
177
+ // Apply token budget
178
+ const final = applyTokenBudget(capped, maxTokensEstimate);
179
+
180
+ return {
181
+ work_item_id: workItem.work_item_id,
182
+ artifacts: final,
183
+ total_artifacts_considered: totalConsidered,
184
+ redundancy_removed: removed,
185
+ built_at: new Date().toISOString(),
186
+ };
187
+ }
188
+
189
+ /** Convenience: build with no evidence, just lessons and state summary */
190
+ buildLightweight(workItem: WorkItem, state: RunState, lessons: LessonMetric[]): ContextPack {
191
+ return this.build(workItem, state, [], new Map(), lessons);
192
+ }
193
+ }
@@ -0,0 +1 @@
1
+ export * from './context-pack-builder';
@@ -0,0 +1,84 @@
1
+ import { execFileSync, spawnSync } from 'child_process';
2
+
3
+ export interface BranchInfo {
4
+ name: string;
5
+ current: boolean;
6
+ commit: string;
7
+ }
8
+
9
+ export class BranchManager {
10
+ constructor(private readonly projectRoot: string) {}
11
+
12
+ currentBranch(): string {
13
+ return this.git(['rev-parse', '--abbrev-ref', 'HEAD']).trim();
14
+ }
15
+
16
+ currentCommit(): string {
17
+ return this.git(['rev-parse', 'HEAD']).trim();
18
+ }
19
+
20
+ createSessionBranch(sessionId: string): string {
21
+ const name = `oxe/${sessionId}`;
22
+ this.git(['checkout', '-b', name]);
23
+ return name;
24
+ }
25
+
26
+ createOxeBranch(name: string, base?: string): string {
27
+ const fullName = name.startsWith('oxe/') ? name : `oxe/${name}`;
28
+ if (base) {
29
+ this.git(['checkout', '-b', fullName, base]);
30
+ } else {
31
+ this.git(['checkout', '-b', fullName]);
32
+ }
33
+ return fullName;
34
+ }
35
+
36
+ switchTo(branchName: string): void {
37
+ this.git(['checkout', branchName]);
38
+ }
39
+
40
+ deleteBranch(name: string, force = false): void {
41
+ const flag = force ? '-D' : '-d';
42
+ this.git(['branch', flag, name]);
43
+ }
44
+
45
+ listOxeBranches(): BranchInfo[] {
46
+ const raw = this.git(['branch', '--list', 'oxe/*', '--format=%(refname:short) %(objectname:short) %(HEAD)']);
47
+ return raw
48
+ .split('\n')
49
+ .filter(Boolean)
50
+ .map((line) => {
51
+ const parts = line.trim().split(/\s+/);
52
+ return {
53
+ name: parts[0],
54
+ commit: parts[1] ?? '',
55
+ current: parts[2] === '*',
56
+ };
57
+ });
58
+ }
59
+
60
+ mergeWorktreeBranch(worktreeBranch: string, targetBranch: string): void {
61
+ const saved = this.currentBranch();
62
+ try {
63
+ this.git(['checkout', targetBranch]);
64
+ this.git(['merge', '--no-ff', worktreeBranch, '-m', `oxe: merge ${worktreeBranch}`]);
65
+ } finally {
66
+ try { this.git(['checkout', saved]); } catch { /* best effort */ }
67
+ }
68
+ }
69
+
70
+ branchExists(name: string): boolean {
71
+ const result = spawnSync('git', ['rev-parse', '--verify', name], {
72
+ cwd: this.projectRoot,
73
+ encoding: 'utf8',
74
+ });
75
+ return result.status === 0;
76
+ }
77
+
78
+ private git(args: string[]): string {
79
+ return execFileSync('git', args, {
80
+ cwd: this.projectRoot,
81
+ encoding: 'utf8',
82
+ });
83
+ }
84
+ }
@@ -0,0 +1,252 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import type { EvidenceStore } from '../evidence/evidence-store';
4
+
5
+ export type CICheckStatus = 'pass' | 'fail' | 'skip' | 'error';
6
+
7
+ export interface CICheckContext {
8
+ projectRoot: string;
9
+ sessionId: string | null;
10
+ runId?: string;
11
+ evidenceStore?: EvidenceStore;
12
+ }
13
+
14
+ export interface CICheckResult {
15
+ check: string;
16
+ status: CICheckStatus;
17
+ message: string;
18
+ details?: unknown;
19
+ }
20
+
21
+ export interface CICheck {
22
+ name: string;
23
+ description: string;
24
+ run(ctx: CICheckContext): Promise<CICheckResult>;
25
+ }
26
+
27
+ // ─── Check: plan-consistency ─────────────────────────────────────────────────
28
+
29
+ export const planConsistencyCheck: CICheck = {
30
+ name: 'oxe-plan-consistency',
31
+ description: 'Verifies ACTIVE-RUN.json exists and has a compiled ExecutionGraph',
32
+ async run(ctx) {
33
+ const activeRunPath = ctx.sessionId
34
+ ? path.join(ctx.projectRoot, '.oxe', ctx.sessionId, 'execution', 'ACTIVE-RUN.json')
35
+ : path.join(ctx.projectRoot, '.oxe', 'ACTIVE-RUN.json');
36
+
37
+ if (!fs.existsSync(activeRunPath)) {
38
+ return { check: this.name, status: 'skip', message: 'No ACTIVE-RUN.json found' };
39
+ }
40
+
41
+ try {
42
+ const raw = JSON.parse(fs.readFileSync(activeRunPath, 'utf8')) as Record<string, unknown>;
43
+ const hasGraph = raw.compiled_graph && typeof raw.compiled_graph === 'object';
44
+ const hasRunId = typeof raw.run_id === 'string';
45
+
46
+ if (!hasRunId) {
47
+ return { check: this.name, status: 'fail', message: 'ACTIVE-RUN.json missing run_id', details: raw };
48
+ }
49
+ if (!hasGraph) {
50
+ return { check: this.name, status: 'fail', message: 'No compiled ExecutionGraph found in ACTIVE-RUN.json', details: { run_id: raw.run_id } };
51
+ }
52
+ return { check: this.name, status: 'pass', message: `Run ${String(raw.run_id)} has compiled graph` };
53
+ } catch (err) {
54
+ return { check: this.name, status: 'error', message: `Failed to parse ACTIVE-RUN.json: ${String(err)}` };
55
+ }
56
+ },
57
+ };
58
+
59
+ // ─── Check: verify-acceptance ────────────────────────────────────────────────
60
+
61
+ export const verifyAcceptanceCheck: CICheck = {
62
+ name: 'oxe-verify-acceptance',
63
+ description: 'Checks that VERIFY.md exists and contains no failed criteria',
64
+ async run(ctx) {
65
+ const verifyPath = ctx.sessionId
66
+ ? path.join(ctx.projectRoot, '.oxe', ctx.sessionId, 'verification', 'VERIFY.md')
67
+ : path.join(ctx.projectRoot, '.oxe', 'VERIFY.md');
68
+
69
+ if (!fs.existsSync(verifyPath)) {
70
+ return { check: this.name, status: 'skip', message: 'No VERIFY.md found — run /oxe-verify first' };
71
+ }
72
+
73
+ const content = fs.readFileSync(verifyPath, 'utf8');
74
+ const failLines = content.split('\n').filter((l) => l.includes('✗ FAIL'));
75
+ const passLines = content.split('\n').filter((l) => l.includes('✓ PASS'));
76
+
77
+ if (failLines.length > 0) {
78
+ return {
79
+ check: this.name,
80
+ status: 'fail',
81
+ message: `${failLines.length} acceptance criteria failed`,
82
+ details: { failed: failLines, passed: passLines.length },
83
+ };
84
+ }
85
+ if (passLines.length === 0) {
86
+ return { check: this.name, status: 'skip', message: 'VERIFY.md has no pass/fail markers' };
87
+ }
88
+ return { check: this.name, status: 'pass', message: `${passLines.length} acceptance criteria passed` };
89
+ },
90
+ };
91
+
92
+ // ─── Check: policy ───────────────────────────────────────────────────────────
93
+
94
+ export const policyCheck: CICheck = {
95
+ name: 'oxe-policy',
96
+ description: 'Checks that no gates are pending (unresolved human approval)',
97
+ async run(ctx) {
98
+ const gatesPath = ctx.sessionId
99
+ ? path.join(ctx.projectRoot, '.oxe', ctx.sessionId, 'execution', 'GATES.json')
100
+ : path.join(ctx.projectRoot, '.oxe', 'execution', 'GATES.json');
101
+
102
+ if (!fs.existsSync(gatesPath)) {
103
+ return { check: this.name, status: 'pass', message: 'No pending gates' };
104
+ }
105
+
106
+ try {
107
+ const gates = JSON.parse(fs.readFileSync(gatesPath, 'utf8')) as Array<{ status: string; scope: string; gate_id: string }>;
108
+ const pending = gates.filter((g) => g.status === 'pending');
109
+ if (pending.length > 0) {
110
+ return {
111
+ check: this.name,
112
+ status: 'fail',
113
+ message: `${pending.length} unresolved gate(s)`,
114
+ details: pending.map((g) => ({ gate_id: g.gate_id, scope: g.scope })),
115
+ };
116
+ }
117
+ return { check: this.name, status: 'pass', message: 'All gates resolved' };
118
+ } catch (err) {
119
+ return { check: this.name, status: 'error', message: `Failed to read GATES.json: ${String(err)}` };
120
+ }
121
+ },
122
+ };
123
+
124
+ // ─── Check: security-baseline ────────────────────────────────────────────────
125
+
126
+ const SECRET_PATTERNS = [
127
+ /(?:password|passwd|secret|api[_-]?key|auth[_-]?token)\s*[:=]\s*['"]?\S{8,}/i,
128
+ /(?:AKIA|ASIA)[A-Z0-9]{16}/,
129
+ /-----BEGIN (?:RSA|EC|OPENSSH) PRIVATE KEY-----/,
130
+ ];
131
+
132
+ export const securityBaselineCheck: CICheck = {
133
+ name: 'oxe-security-baseline',
134
+ description: 'Scans evidence artifacts for common secret patterns',
135
+ async run(ctx) {
136
+ if (!ctx.evidenceStore || !ctx.runId) {
137
+ return { check: this.name, status: 'skip', message: 'No evidence store or run ID provided' };
138
+ }
139
+
140
+ const evidenceDir = path.join(ctx.projectRoot, '.oxe', 'evidence', 'runs', ctx.runId);
141
+ if (!fs.existsSync(evidenceDir)) {
142
+ return { check: this.name, status: 'skip', message: 'No evidence found for this run' };
143
+ }
144
+
145
+ const findings: string[] = [];
146
+ walkDir(evidenceDir, (filePath) => {
147
+ if (filePath.endsWith('.json') || filePath.endsWith('.patch') || filePath.endsWith('.txt')) {
148
+ try {
149
+ const content = fs.readFileSync(filePath, 'utf8');
150
+ for (const pattern of SECRET_PATTERNS) {
151
+ if (pattern.test(content)) {
152
+ findings.push(`${path.basename(filePath)}: matches pattern ${pattern.source.slice(0, 40)}`);
153
+ break;
154
+ }
155
+ }
156
+ } catch { /* skip unreadable */ }
157
+ }
158
+ });
159
+
160
+ if (findings.length > 0) {
161
+ return { check: this.name, status: 'fail', message: `Secret patterns detected in ${findings.length} evidence file(s)`, details: findings };
162
+ }
163
+ return { check: this.name, status: 'pass', message: 'No secret patterns detected in evidence' };
164
+ },
165
+ };
166
+
167
+ // ─── Check: runtime-evidence-integrity ───────────────────────────────────────
168
+
169
+ export const runtimeEvidenceIntegrityCheck: CICheck = {
170
+ name: 'oxe-runtime-evidence-integrity',
171
+ description: 'Validates that all evidence index files are valid JSON and files exist on disk',
172
+ async run(ctx) {
173
+ if (!ctx.runId) {
174
+ return { check: this.name, status: 'skip', message: 'No run ID provided' };
175
+ }
176
+
177
+ const runEvidenceDir = path.join(ctx.projectRoot, '.oxe', 'evidence', 'runs', ctx.runId);
178
+ if (!fs.existsSync(runEvidenceDir)) {
179
+ return { check: this.name, status: 'skip', message: 'No evidence directory for this run' };
180
+ }
181
+
182
+ const errors: string[] = [];
183
+ let indexCount = 0;
184
+ let evidenceCount = 0;
185
+
186
+ walkDir(runEvidenceDir, (filePath) => {
187
+ if (path.basename(filePath) !== 'index.json') return;
188
+ indexCount++;
189
+ try {
190
+ const items = JSON.parse(fs.readFileSync(filePath, 'utf8')) as Array<{ path: string; evidence_id: string }>;
191
+ for (const item of items) {
192
+ evidenceCount++;
193
+ const absPath = path.join(ctx.projectRoot, item.path);
194
+ if (!fs.existsSync(absPath)) {
195
+ errors.push(`Missing file for ${item.evidence_id}: ${item.path}`);
196
+ }
197
+ }
198
+ } catch (err) {
199
+ errors.push(`Corrupt index at ${filePath}: ${String(err)}`);
200
+ }
201
+ });
202
+
203
+ if (errors.length > 0) {
204
+ return { check: this.name, status: 'fail', message: `${errors.length} integrity error(s)`, details: errors };
205
+ }
206
+ return {
207
+ check: this.name,
208
+ status: indexCount === 0 ? 'skip' : 'pass',
209
+ message: `${evidenceCount} evidence artifact(s) across ${indexCount} index(es) — all valid`,
210
+ };
211
+ },
212
+ };
213
+
214
+ // ─── Suite ───────────────────────────────────────────────────────────────────
215
+
216
+ export const OXE_CI_CHECKS: CICheck[] = [
217
+ planConsistencyCheck,
218
+ verifyAcceptanceCheck,
219
+ policyCheck,
220
+ securityBaselineCheck,
221
+ runtimeEvidenceIntegrityCheck,
222
+ ];
223
+
224
+ export async function runCIChecks(
225
+ ctx: CICheckContext,
226
+ checks: CICheck[] = OXE_CI_CHECKS
227
+ ): Promise<CICheckResult[]> {
228
+ const results: CICheckResult[] = [];
229
+ for (const check of checks) {
230
+ results.push(await check.run(ctx));
231
+ }
232
+ return results;
233
+ }
234
+
235
+ export function summarizeCIResults(results: CICheckResult[]): {
236
+ total: number; pass: number; fail: number; skip: number; error: number; allPassed: boolean;
237
+ } {
238
+ const counts = { total: results.length, pass: 0, fail: 0, skip: 0, error: 0 };
239
+ for (const r of results) counts[r.status]++;
240
+ return { ...counts, allPassed: counts.fail === 0 && counts.error === 0 };
241
+ }
242
+
243
+ // ─── Helpers ─────────────────────────────────────────────────────────────────
244
+
245
+ function walkDir(dir: string, visitor: (filePath: string) => void): void {
246
+ if (!fs.existsSync(dir)) return;
247
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
248
+ const full = path.join(dir, entry.name);
249
+ if (entry.isDirectory()) walkDir(full, visitor);
250
+ else visitor(full);
251
+ }
252
+ }
@@ -0,0 +1,3 @@
1
+ export * from './branch-manager';
2
+ export * from './pr-manager';
3
+ export * from './ci-checks';
@@ -0,0 +1,112 @@
1
+ import { spawnSync } from 'child_process';
2
+
3
+ export interface PRDraftOptions {
4
+ title: string;
5
+ body: string;
6
+ base?: string;
7
+ head?: string;
8
+ draft?: boolean;
9
+ }
10
+
11
+ export interface PRInfo {
12
+ number: number;
13
+ title: string;
14
+ url: string;
15
+ state: string;
16
+ draft: boolean;
17
+ head: string;
18
+ base: string;
19
+ }
20
+
21
+ export interface PRResult {
22
+ success: boolean;
23
+ url?: string;
24
+ error?: string;
25
+ pr?: PRInfo;
26
+ }
27
+
28
+ function isGhAvailable(cwd: string): boolean {
29
+ const result = spawnSync('gh', ['--version'], { cwd, encoding: 'utf8' });
30
+ return result.status === 0;
31
+ }
32
+
33
+ export class PRManager {
34
+ constructor(private readonly projectRoot: string) {}
35
+
36
+ isAvailable(): boolean {
37
+ return isGhAvailable(this.projectRoot);
38
+ }
39
+
40
+ createDraft(opts: PRDraftOptions): PRResult {
41
+ if (!this.isAvailable()) {
42
+ return { success: false, error: 'gh CLI not available — install from https://cli.github.com' };
43
+ }
44
+ const args = [
45
+ 'pr', 'create',
46
+ '--title', opts.title,
47
+ '--body', opts.body,
48
+ ];
49
+ if (opts.draft !== false) args.push('--draft');
50
+ if (opts.base) args.push('--base', opts.base);
51
+ if (opts.head) args.push('--head', opts.head);
52
+
53
+ const result = spawnSync('gh', args, {
54
+ cwd: this.projectRoot,
55
+ encoding: 'utf8',
56
+ });
57
+
58
+ if (result.status !== 0) {
59
+ return { success: false, error: result.stderr?.trim() ?? 'gh pr create failed' };
60
+ }
61
+ const url = result.stdout?.trim();
62
+ return { success: true, url };
63
+ }
64
+
65
+ view(prNumberOrUrl: string | number): PRResult {
66
+ if (!this.isAvailable()) {
67
+ return { success: false, error: 'gh CLI not available' };
68
+ }
69
+ const result = spawnSync(
70
+ 'gh',
71
+ ['pr', 'view', String(prNumberOrUrl), '--json', 'number,title,url,state,isDraft,headRefName,baseRefName'],
72
+ { cwd: this.projectRoot, encoding: 'utf8' }
73
+ );
74
+ if (result.status !== 0) {
75
+ return { success: false, error: result.stderr?.trim() };
76
+ }
77
+ try {
78
+ const raw = JSON.parse(result.stdout) as {
79
+ number: number; title: string; url: string; state: string;
80
+ isDraft: boolean; headRefName: string; baseRefName: string;
81
+ };
82
+ return {
83
+ success: true,
84
+ url: raw.url,
85
+ pr: {
86
+ number: raw.number,
87
+ title: raw.title,
88
+ url: raw.url,
89
+ state: raw.state.toLowerCase(),
90
+ draft: raw.isDraft,
91
+ head: raw.headRefName,
92
+ base: raw.baseRefName,
93
+ },
94
+ };
95
+ } catch {
96
+ return { success: false, error: 'Failed to parse gh output' };
97
+ }
98
+ }
99
+
100
+ mergePR(prNumber: number, method: 'merge' | 'squash' | 'rebase' = 'merge'): PRResult {
101
+ if (!this.isAvailable()) {
102
+ return { success: false, error: 'gh CLI not available' };
103
+ }
104
+ const result = spawnSync('gh', ['pr', 'merge', String(prNumber), `--${method}`, '--delete-branch'], {
105
+ cwd: this.projectRoot,
106
+ encoding: 'utf8',
107
+ });
108
+ return result.status === 0
109
+ ? { success: true }
110
+ : { success: false, error: result.stderr?.trim() };
111
+ }
112
+ }