opencastle 0.36.0 → 0.36.2
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/cli/convoy/engine.d.ts.map +1 -1
- package/dist/cli/convoy/engine.js +0 -7
- package/dist/cli/convoy/engine.js.map +1 -1
- package/dist/cli/convoy/engine.test.js +0 -1
- package/dist/cli/convoy/engine.test.js.map +1 -1
- package/dist/cli/convoy/event-emission.test.d.ts +2 -0
- package/dist/cli/convoy/event-emission.test.d.ts.map +1 -0
- package/dist/cli/convoy/event-emission.test.js +73 -0
- package/dist/cli/convoy/event-emission.test.js.map +1 -0
- package/dist/cli/convoy/event-schemas.d.ts.map +1 -1
- package/dist/cli/convoy/event-schemas.js +0 -25
- package/dist/cli/convoy/event-schemas.js.map +1 -1
- package/dist/cli/convoy/events.test.js +2 -2
- package/dist/cli/convoy/events.test.js.map +1 -1
- package/dist/cli/convoy/last-run.d.ts +53 -0
- package/dist/cli/convoy/last-run.d.ts.map +1 -0
- package/dist/cli/convoy/last-run.js +54 -0
- package/dist/cli/convoy/last-run.js.map +1 -0
- package/dist/cli/convoy/last-run.test.d.ts +2 -0
- package/dist/cli/convoy/last-run.test.d.ts.map +1 -0
- package/dist/cli/convoy/last-run.test.js +110 -0
- package/dist/cli/convoy/last-run.test.js.map +1 -0
- package/dist/cli/convoy/spec-types.d.ts +8 -2
- package/dist/cli/convoy/spec-types.d.ts.map +1 -1
- package/dist/cli/convoy/store.d.ts +3 -2
- package/dist/cli/convoy/store.d.ts.map +1 -1
- package/dist/cli/convoy/store.js +33 -8
- package/dist/cli/convoy/store.js.map +1 -1
- package/dist/cli/convoy/store.test.js +76 -13
- package/dist/cli/convoy/store.test.js.map +1 -1
- package/dist/cli/convoy/types.d.ts +0 -35
- package/dist/cli/convoy/types.d.ts.map +1 -1
- package/dist/cli/convoy/types.js +0 -4
- package/dist/cli/convoy/types.js.map +1 -1
- package/dist/cli/convoy-args.test.d.ts +2 -0
- package/dist/cli/convoy-args.test.d.ts.map +1 -0
- package/dist/cli/convoy-args.test.js +132 -0
- package/dist/cli/convoy-args.test.js.map +1 -0
- package/dist/cli/convoy-cmd.d.ts +25 -0
- package/dist/cli/convoy-cmd.d.ts.map +1 -1
- package/dist/cli/convoy-cmd.js +155 -19
- package/dist/cli/convoy-cmd.js.map +1 -1
- package/dist/cli/publish-workflow.test.js +12 -0
- package/dist/cli/publish-workflow.test.js.map +1 -1
- package/dist/cli/run/adapters/codex.d.ts.map +1 -1
- package/dist/cli/run/adapters/codex.js +8 -1
- package/dist/cli/run/adapters/codex.js.map +1 -1
- package/dist/cli/run/adapters/permission-modes.d.ts +20 -0
- package/dist/cli/run/adapters/permission-modes.d.ts.map +1 -0
- package/dist/cli/run/adapters/permission-modes.js +82 -0
- package/dist/cli/run/adapters/permission-modes.js.map +1 -0
- package/dist/cli/run/adapters/permission-modes.test.d.ts +2 -0
- package/dist/cli/run/adapters/permission-modes.test.d.ts.map +1 -0
- package/dist/cli/run/adapters/permission-modes.test.js +95 -0
- package/dist/cli/run/adapters/permission-modes.test.js.map +1 -0
- package/dist/cli/run/schema.d.ts.map +1 -1
- package/dist/cli/run/schema.js +69 -0
- package/dist/cli/run/schema.js.map +1 -1
- package/dist/cli/run/schema.test.js +62 -0
- package/dist/cli/run/schema.test.js.map +1 -1
- package/dist/cli/run-dry-run.test.d.ts +2 -0
- package/dist/cli/run-dry-run.test.d.ts.map +1 -0
- package/dist/cli/run-dry-run.test.js +83 -0
- package/dist/cli/run-dry-run.test.js.map +1 -0
- package/dist/cli/run-executor-flags.test.d.ts +2 -0
- package/dist/cli/run-executor-flags.test.d.ts.map +1 -0
- package/dist/cli/run-executor-flags.test.js +31 -0
- package/dist/cli/run-executor-flags.test.js.map +1 -0
- package/dist/cli/run.d.ts +40 -0
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +198 -24
- package/dist/cli/run.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/convoy/TELEMETRY.md +0 -2
- package/src/cli/convoy/engine.test.ts +0 -1
- package/src/cli/convoy/engine.ts +0 -7
- package/src/cli/convoy/event-emission.test.ts +79 -0
- package/src/cli/convoy/event-schemas.ts +0 -25
- package/src/cli/convoy/events.test.ts +2 -2
- package/src/cli/convoy/last-run.test.ts +130 -0
- package/src/cli/convoy/last-run.ts +87 -0
- package/src/cli/convoy/spec-types.ts +8 -2
- package/src/cli/convoy/store.test.ts +87 -13
- package/src/cli/convoy/store.ts +40 -12
- package/src/cli/convoy/types.ts +0 -10
- package/src/cli/convoy-args.test.ts +156 -0
- package/src/cli/convoy-cmd.ts +162 -19
- package/src/cli/publish-workflow.test.ts +13 -0
- package/src/cli/run/adapters/codex.ts +9 -1
- package/src/cli/run/adapters/permission-modes.test.ts +114 -0
- package/src/cli/run/adapters/permission-modes.ts +89 -0
- package/src/cli/run/schema.test.ts +72 -0
- package/src/cli/run/schema.ts +71 -0
- package/src/cli/run-dry-run.test.ts +97 -0
- package/src/cli/run-executor-flags.test.ts +38 -0
- package/src/cli/run.ts +242 -29
- package/src/dashboard/dist/index.html +1 -1
- package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
- package/src/dashboard/src/pages/index.astro +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every declared event type is emitted by something.
|
|
3
|
+
*
|
|
4
|
+
* Four types were declared, schema'd, listed in TELEMETRY.md against a source
|
|
5
|
+
* file, offered as a dashboard filter — and emitted by nothing:
|
|
6
|
+
* `weak_area_skipped`, `discovered_issue`, `context_compacted` and
|
|
7
|
+
* `skill_refinement_proposed`. ARCHITECTURE.md described one of them as a
|
|
8
|
+
* shipped feature ("weak-area avoidance skips agents for files they've
|
|
9
|
+
* historically struggled with"), and TELEMETRY.md attributed another to an
|
|
10
|
+
* `issues.ts` that has never existed.
|
|
11
|
+
*
|
|
12
|
+
* The existing test asserted that the registry *contains* each name, which is
|
|
13
|
+
* true of a name that nothing emits — it could not have caught this, and did
|
|
14
|
+
* not, for as long as the four had been there. This asserts the other
|
|
15
|
+
* direction: a name in the registry has to correspond to a call somewhere.
|
|
16
|
+
*
|
|
17
|
+
* Source text, not runtime behaviour. Reaching every emission site by running
|
|
18
|
+
* the engine would need a convoy that fails, disputes, trips a breaker and
|
|
19
|
+
* leaks a secret; the defect being guarded is a declaration with no code behind
|
|
20
|
+
* it anywhere, and that is visible statically.
|
|
21
|
+
*/
|
|
22
|
+
import { describe, it, expect } from 'vitest'
|
|
23
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs'
|
|
24
|
+
import { join, resolve } from 'node:path'
|
|
25
|
+
import { KNOWN_EVENT_TYPES } from './types.js'
|
|
26
|
+
|
|
27
|
+
const SRC = resolve(import.meta.dirname, '..', '..')
|
|
28
|
+
|
|
29
|
+
/** Every .ts file under src/, excluding tests and the declarations themselves. */
|
|
30
|
+
function sourceFiles(dir: string, out: string[] = []): string[] {
|
|
31
|
+
for (const entry of readdirSync(dir)) {
|
|
32
|
+
if (entry === 'node_modules' || entry === 'dist' || entry === '.astro') continue
|
|
33
|
+
const full = join(dir, entry)
|
|
34
|
+
if (statSync(full).isDirectory()) {
|
|
35
|
+
sourceFiles(full, out)
|
|
36
|
+
continue
|
|
37
|
+
}
|
|
38
|
+
if (!entry.endsWith('.ts')) continue
|
|
39
|
+
if (entry.endsWith('.test.ts')) continue
|
|
40
|
+
// The files that *declare* the types would match every name trivially.
|
|
41
|
+
if (entry === 'types.ts' || entry === 'event-schemas.ts') continue
|
|
42
|
+
out.push(full)
|
|
43
|
+
}
|
|
44
|
+
return out
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const corpus = sourceFiles(SRC)
|
|
48
|
+
.map((f) => readFileSync(f, 'utf8'))
|
|
49
|
+
.join('\n')
|
|
50
|
+
|
|
51
|
+
describe('declared event types', () => {
|
|
52
|
+
it('are each produced somewhere in the product', () => {
|
|
53
|
+
const orphans = [...KNOWN_EVENT_TYPES].filter(
|
|
54
|
+
(type) => !new RegExp(`['"\`]${type}['"\`]`).test(corpus),
|
|
55
|
+
)
|
|
56
|
+
expect(
|
|
57
|
+
orphans,
|
|
58
|
+
`declared but never emitted — implement the emission or drop the declaration:\n ${orphans.join('\n ')}`,
|
|
59
|
+
).toEqual([])
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('has a registry that is not trivially empty', () => {
|
|
63
|
+
// A guard against the check above passing because the corpus or the
|
|
64
|
+
// registry failed to load.
|
|
65
|
+
expect(KNOWN_EVENT_TYPES.size).toBeGreaterThan(30)
|
|
66
|
+
expect(corpus.length).toBeGreaterThan(10_000)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('no longer declares the four that nothing produced', () => {
|
|
70
|
+
for (const dead of [
|
|
71
|
+
'weak_area_skipped',
|
|
72
|
+
'discovered_issue',
|
|
73
|
+
'context_compacted',
|
|
74
|
+
'skill_refinement_proposed',
|
|
75
|
+
]) {
|
|
76
|
+
expect(KNOWN_EVENT_TYPES.has(dead), `${dead} is back without an emitter`).toBe(false)
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
})
|
|
@@ -112,11 +112,6 @@ const EVENT_DATA_SCHEMAS: Record<string, AnySchema> = {
|
|
|
112
112
|
reason: v.optional(v.string()),
|
|
113
113
|
}),
|
|
114
114
|
|
|
115
|
-
weak_area_skipped: v.looseObject({
|
|
116
|
-
agent: v.optional(v.string()),
|
|
117
|
-
weak_areas: v.optional(v.array(v.string())),
|
|
118
|
-
task_files: v.optional(v.array(v.string())),
|
|
119
|
-
}),
|
|
120
115
|
swarm_concurrency_update: v.looseObject({
|
|
121
116
|
new_concurrency: v.optional(v.number()),
|
|
122
117
|
reason: v.optional(v.string()),
|
|
@@ -171,13 +166,6 @@ const EVENT_DATA_SCHEMAS: Record<string, AnySchema> = {
|
|
|
171
166
|
worker_id: v.optional(v.string()),
|
|
172
167
|
task_id: v.optional(v.string()),
|
|
173
168
|
}),
|
|
174
|
-
discovered_issue: v.looseObject({
|
|
175
|
-
task_id: v.optional(v.string()),
|
|
176
|
-
title: v.optional(v.string()),
|
|
177
|
-
file: v.optional(v.string()),
|
|
178
|
-
description: v.optional(v.string()),
|
|
179
|
-
severity: v.optional(v.string()),
|
|
180
|
-
}),
|
|
181
169
|
contract_violation: v.looseObject({
|
|
182
170
|
task_id: v.optional(v.string()),
|
|
183
171
|
agent: v.optional(v.string()),
|
|
@@ -190,19 +178,6 @@ const EVENT_DATA_SCHEMAS: Record<string, AnySchema> = {
|
|
|
190
178
|
actual: v.optional(v.array(v.string())),
|
|
191
179
|
violations: v.optional(v.array(v.string())),
|
|
192
180
|
}),
|
|
193
|
-
context_compacted: v.looseObject({
|
|
194
|
-
task_id: v.optional(v.string()),
|
|
195
|
-
compaction_count: v.optional(v.number()),
|
|
196
|
-
summary_path: v.optional(v.string()),
|
|
197
|
-
model: v.optional(v.string()),
|
|
198
|
-
tokens_used: v.optional(v.number()),
|
|
199
|
-
}),
|
|
200
|
-
skill_refinement_proposed: v.looseObject({
|
|
201
|
-
skill_name: v.optional(v.string()),
|
|
202
|
-
proposal_path: v.optional(v.string()),
|
|
203
|
-
failure_count: v.optional(v.number()),
|
|
204
|
-
confidence: v.optional(v.string()),
|
|
205
|
-
}),
|
|
206
181
|
tdd_check_passed: v.looseObject({
|
|
207
182
|
task_id: v.optional(v.string()),
|
|
208
183
|
new_source_files: v.optional(v.number()),
|
|
@@ -345,11 +345,11 @@ describe('KNOWN_EVENT_TYPES', () => {
|
|
|
345
345
|
'merge_conflict_detected', 'merge_conflict_failed',
|
|
346
346
|
'file_injection_received', 'artifact_limit_reached',
|
|
347
347
|
'agent_identity_captured', 'agent_identity_rejected',
|
|
348
|
-
'
|
|
348
|
+
'swarm_concurrency_update', 'post_convoy_hook_failed',
|
|
349
349
|
'session', 'delegation',
|
|
350
350
|
'secret_leak_prevented', 'ndjson_write_failed', 'built_in_gate_result',
|
|
351
351
|
'watch_started', 'watch_cycle_start', 'watch_cycle_end', 'watch_stopped',
|
|
352
|
-
'worker_killed',
|
|
352
|
+
'worker_killed',
|
|
353
353
|
]
|
|
354
354
|
for (const type of canonical) {
|
|
355
355
|
expect(KNOWN_EVENT_TYPES.has(type)).toBe(true)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which run "the last run" means.
|
|
3
|
+
*
|
|
4
|
+
* The defect these cover: `resume` preferred the newest *pipeline* row over the
|
|
5
|
+
* newest convoy unconditionally, so a project that ran a pipeline and then ran a
|
|
6
|
+
* standalone spec got a status screen naming one run and a `resume` that
|
|
7
|
+
* continued a different one — permanently, since the done-pipeline branch exited
|
|
8
|
+
* rather than falling through to the convoy.
|
|
9
|
+
*/
|
|
10
|
+
import { describe, it, expect } from 'vitest'
|
|
11
|
+
import { selectLastRun, isResumable, selectResumableRun } from './last-run.js'
|
|
12
|
+
import type { LastRunSource } from './last-run.js'
|
|
13
|
+
import type { ConvoyRecord, PipelineRecord } from './types.js'
|
|
14
|
+
|
|
15
|
+
function pipeline(over: Partial<PipelineRecord> = {}): PipelineRecord {
|
|
16
|
+
return {
|
|
17
|
+
id: 'pipe-1',
|
|
18
|
+
name: 'A Pipeline',
|
|
19
|
+
status: 'failed',
|
|
20
|
+
branch: null,
|
|
21
|
+
spec_yaml: 'name: A Pipeline\nversion: 2\n',
|
|
22
|
+
convoy_specs: '[]',
|
|
23
|
+
created_at: '2026-01-01T00:00:00.000Z',
|
|
24
|
+
started_at: null,
|
|
25
|
+
finished_at: null,
|
|
26
|
+
total_tokens: null,
|
|
27
|
+
total_cost_usd: null,
|
|
28
|
+
...over,
|
|
29
|
+
} as PipelineRecord
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function convoy(over: Partial<ConvoyRecord> = {}): ConvoyRecord {
|
|
33
|
+
return {
|
|
34
|
+
id: 'conv-1',
|
|
35
|
+
name: 'A Convoy',
|
|
36
|
+
spec_hash: 'deadbeef',
|
|
37
|
+
status: 'running',
|
|
38
|
+
branch: null,
|
|
39
|
+
created_at: '2026-08-10T00:00:00.000Z',
|
|
40
|
+
started_at: null,
|
|
41
|
+
finished_at: null,
|
|
42
|
+
spec_yaml: 'name: A Convoy\nversion: 1\n',
|
|
43
|
+
total_tokens: null,
|
|
44
|
+
total_cost_usd: null,
|
|
45
|
+
pipeline_id: null,
|
|
46
|
+
circuit_state: null,
|
|
47
|
+
review_tokens_total: null,
|
|
48
|
+
review_budget: null,
|
|
49
|
+
...over,
|
|
50
|
+
} as ConvoyRecord
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function source(p: PipelineRecord | undefined, c: ConvoyRecord | undefined): LastRunSource {
|
|
54
|
+
return { getLatestPipeline: () => p, getLatestStandaloneConvoy: () => c }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe('selectLastRun', () => {
|
|
58
|
+
it('picks the newer run when a convoy was started after a pipeline', () => {
|
|
59
|
+
// The shipped defect: an old failed pipeline shadowed a newer convoy.
|
|
60
|
+
const last = selectLastRun(source(pipeline(), convoy()))
|
|
61
|
+
expect(last).toEqual({ kind: 'convoy', record: expect.objectContaining({ id: 'conv-1' }) })
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('picks the pipeline when it is the newer run', () => {
|
|
65
|
+
const last = selectLastRun(
|
|
66
|
+
source(pipeline({ created_at: '2026-09-01T00:00:00.000Z' }), convoy()),
|
|
67
|
+
)
|
|
68
|
+
expect(last?.kind).toBe('pipeline')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('gives a tie to the pipeline, which creates its first convoy in the same instant', () => {
|
|
72
|
+
const at = '2026-05-05T00:00:00.000Z'
|
|
73
|
+
const last = selectLastRun(source(pipeline({ created_at: at }), convoy({ created_at: at })))
|
|
74
|
+
expect(last?.kind).toBe('pipeline')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('returns whichever exists when there is only one', () => {
|
|
78
|
+
expect(selectLastRun(source(pipeline(), undefined))?.kind).toBe('pipeline')
|
|
79
|
+
expect(selectLastRun(source(undefined, convoy()))?.kind).toBe('convoy')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('returns null on an empty database', () => {
|
|
83
|
+
expect(selectLastRun(source(undefined, undefined))).toBeNull()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe('isResumable', () => {
|
|
88
|
+
it('treats a failed pipeline as resumable — the chain carries on past a bad link', () => {
|
|
89
|
+
expect(isResumable({ kind: 'pipeline', record: pipeline({ status: 'failed' }) })).toBe(true)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('treats a failed convoy as not resumable — retry is that verb', () => {
|
|
93
|
+
expect(isResumable({ kind: 'convoy', record: convoy({ status: 'failed' }) })).toBe(false)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('treats a done run of either kind as finished', () => {
|
|
97
|
+
expect(isResumable({ kind: 'pipeline', record: pipeline({ status: 'done' }) })).toBe(false)
|
|
98
|
+
expect(isResumable({ kind: 'convoy', record: convoy({ status: 'done' }) })).toBe(false)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('resumes pending and running convoys', () => {
|
|
102
|
+
for (const status of ['pending', 'running'] as const) {
|
|
103
|
+
expect(isResumable({ kind: 'convoy', record: convoy({ status }) })).toBe(true)
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
describe('selectResumableRun', () => {
|
|
109
|
+
it('reaches a standalone convoy even when a done pipeline exists', () => {
|
|
110
|
+
// The trap: the old code exited on a done pipeline instead of falling
|
|
111
|
+
// through, so no standalone convoy could ever be resumed afterwards.
|
|
112
|
+
const selected = selectResumableRun(
|
|
113
|
+
source(pipeline({ status: 'done' }), convoy({ status: 'running' })),
|
|
114
|
+
)
|
|
115
|
+
expect(selected).toEqual({
|
|
116
|
+
run: { kind: 'convoy', record: expect.objectContaining({ id: 'conv-1' }) },
|
|
117
|
+
resumable: true,
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('names the blocking run rather than reporting an empty database', () => {
|
|
122
|
+
const selected = selectResumableRun(source(undefined, convoy({ status: 'done' })))
|
|
123
|
+
expect(selected?.resumable).toBe(false)
|
|
124
|
+
expect(selected?.run.record.name).toBe('A Convoy')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('is null only when there is genuinely nothing recorded', () => {
|
|
128
|
+
expect(selectResumableRun(source(undefined, undefined))).toBeNull()
|
|
129
|
+
})
|
|
130
|
+
})
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ConvoyRecord, PipelineRecord } from './types.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Which run "the last run" means, answered once.
|
|
5
|
+
*
|
|
6
|
+
* `resume` decided this for itself and the status screen decided it for itself,
|
|
7
|
+
* and they disagreed: the screen read the newest convoy row, `resume` read the
|
|
8
|
+
* newest *pipeline* row and preferred it unconditionally. A project that ran a
|
|
9
|
+
* pipeline, saw it fail, and then ran a standalone spec got a status screen
|
|
10
|
+
* naming the standalone convoy and printing "Next: opencastle convoy resume",
|
|
11
|
+
* while `resume` reopened the older pipeline. Nothing in the output said so.
|
|
12
|
+
*
|
|
13
|
+
* Worse, it could not be escaped. The pipeline branch was taken whenever the
|
|
14
|
+
* newest pipeline was not `done`, and when it *was* done the surrounding code
|
|
15
|
+
* exited rather than falling through — so once a project had ever run a
|
|
16
|
+
* pipeline, no standalone convoy could be resumed again.
|
|
17
|
+
*
|
|
18
|
+
* The rule is the one a person would state: whichever run was started most
|
|
19
|
+
* recently, provided it is in a state that can be continued.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** A run `resume` may take over, and which orchestrator owns it. */
|
|
23
|
+
export type LastRun =
|
|
24
|
+
| { kind: 'pipeline'; record: PipelineRecord }
|
|
25
|
+
| { kind: 'convoy'; record: ConvoyRecord }
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A finished run has nothing to continue.
|
|
29
|
+
*
|
|
30
|
+
* `failed` is resumable for a pipeline — a convoy in the chain failed, the user
|
|
31
|
+
* fixes it, the chain carries on — but not for a standalone convoy, where
|
|
32
|
+
* `retry` is the verb that reopens failed work. That asymmetry is the existing
|
|
33
|
+
* behaviour of both branches; it is preserved here rather than invented.
|
|
34
|
+
*/
|
|
35
|
+
const RESUMABLE_PIPELINE = new Set(['pending', 'running', 'failed'])
|
|
36
|
+
const RESUMABLE_CONVOY = new Set(['pending', 'running'])
|
|
37
|
+
|
|
38
|
+
export interface LastRunSource {
|
|
39
|
+
getLatestPipeline(): PipelineRecord | undefined
|
|
40
|
+
getLatestStandaloneConvoy(): ConvoyRecord | undefined
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The newest run of either kind, resumable or not.
|
|
45
|
+
*
|
|
46
|
+
* What the status screen reports: it describes where things stand, including
|
|
47
|
+
* when where-things-stand is "finished". `selectResumableRun` narrows this to
|
|
48
|
+
* what `resume` may act on.
|
|
49
|
+
*/
|
|
50
|
+
export function selectLastRun(store: LastRunSource): LastRun | null {
|
|
51
|
+
const pipeline = store.getLatestPipeline()
|
|
52
|
+
const convoy = store.getLatestStandaloneConvoy()
|
|
53
|
+
|
|
54
|
+
if (pipeline && convoy) {
|
|
55
|
+
// Ties go to the pipeline: a chain creates its first convoy in the same
|
|
56
|
+
// instant it creates itself, and the orchestrator is the one that should
|
|
57
|
+
// drive it.
|
|
58
|
+
return convoy.created_at > pipeline.created_at
|
|
59
|
+
? { kind: 'convoy', record: convoy }
|
|
60
|
+
: { kind: 'pipeline', record: pipeline }
|
|
61
|
+
}
|
|
62
|
+
if (pipeline) return { kind: 'pipeline', record: pipeline }
|
|
63
|
+
if (convoy) return { kind: 'convoy', record: convoy }
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** True when `resume` can continue this run. */
|
|
68
|
+
export function isResumable(run: LastRun): boolean {
|
|
69
|
+
return run.kind === 'pipeline'
|
|
70
|
+
? RESUMABLE_PIPELINE.has(run.record.status)
|
|
71
|
+
: RESUMABLE_CONVOY.has(run.record.status)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The run `resume` should continue, or the newest run explaining why it cannot.
|
|
76
|
+
*
|
|
77
|
+
* Returning the blocking run rather than `null` is what lets the caller say
|
|
78
|
+
* *which* run is finished instead of "nothing to resume" — the message that
|
|
79
|
+
* sent people looking for a database that was in front of them all along.
|
|
80
|
+
*/
|
|
81
|
+
export function selectResumableRun(
|
|
82
|
+
store: LastRunSource,
|
|
83
|
+
): { run: LastRun; resumable: boolean } | null {
|
|
84
|
+
const run = selectLastRun(store)
|
|
85
|
+
if (!run) return null
|
|
86
|
+
return { run, resumable: isResumable(run) }
|
|
87
|
+
}
|
|
@@ -195,8 +195,14 @@ export interface ExecuteOptions {
|
|
|
195
195
|
verbose?: boolean;
|
|
196
196
|
/** Working directory for the agent process (defaults to process.cwd()). */
|
|
197
197
|
cwd?: string;
|
|
198
|
-
/**
|
|
199
|
-
*
|
|
198
|
+
/**
|
|
199
|
+
* How much the worker may do unattended.
|
|
200
|
+
*
|
|
201
|
+
* Claude passes it as `--permission-mode`; codex maps it onto the `exec -s`
|
|
202
|
+
* sandbox. An adapter that cannot express a mode no longer ignores it — the
|
|
203
|
+
* run is refused up front instead. See `adapters/permission-modes.ts` for
|
|
204
|
+
* which adapter honours which.
|
|
205
|
+
*/
|
|
200
206
|
permissionMode?: PermissionMode;
|
|
201
207
|
/** MCP servers to make available during execution (Phase 19.7). */
|
|
202
208
|
mcpServers?: MCPServerConfig[];
|
|
@@ -99,11 +99,11 @@ describe('DB creation', () => {
|
|
|
99
99
|
expect(row.journal_mode).toBe('wal')
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
it('sets schema version to
|
|
102
|
+
it('sets schema version to 13', () => {
|
|
103
103
|
const db = new DatabaseSync(dbPath)
|
|
104
104
|
const row = db.prepare('PRAGMA user_version').get() as { user_version: number }
|
|
105
105
|
db.close()
|
|
106
|
-
expect(row.user_version).toBe(
|
|
106
|
+
expect(row.user_version).toBe(13)
|
|
107
107
|
})
|
|
108
108
|
|
|
109
109
|
it('creates all required tables', () => {
|
|
@@ -131,7 +131,7 @@ describe('DB creation', () => {
|
|
|
131
131
|
store2.close()
|
|
132
132
|
// Reassign so afterEach does not double-close
|
|
133
133
|
store = createConvoyStore(dbPath)
|
|
134
|
-
expect(row.user_version).toBe(
|
|
134
|
+
expect(row.user_version).toBe(13)
|
|
135
135
|
})
|
|
136
136
|
})
|
|
137
137
|
|
|
@@ -208,8 +208,8 @@ describe('schema migration', () => {
|
|
|
208
208
|
verifyDb.close()
|
|
209
209
|
|
|
210
210
|
expect(cols.map(c => c.name)).toContain('adapter')
|
|
211
|
-
// v1 chains through v2→v3→v4→...→
|
|
212
|
-
expect(version.user_version).toBe(
|
|
211
|
+
// v1 chains through v2→v3→v4→...→v10→v11→v12→v13 in one init, so final version is 13
|
|
212
|
+
expect(version.user_version).toBe(13)
|
|
213
213
|
})
|
|
214
214
|
|
|
215
215
|
it('schema migration v2 to v3 adds cost columns', () => {
|
|
@@ -295,7 +295,7 @@ describe('schema migration', () => {
|
|
|
295
295
|
expect(convoyColNames).toContain('total_tokens')
|
|
296
296
|
expect(convoyColNames).toContain('total_cost_usd')
|
|
297
297
|
|
|
298
|
-
expect(version.user_version).toBe(
|
|
298
|
+
expect(version.user_version).toBe(13)
|
|
299
299
|
})
|
|
300
300
|
|
|
301
301
|
it('schema migration v1 to v3 chains correctly in a single init', () => {
|
|
@@ -381,7 +381,7 @@ describe('schema migration', () => {
|
|
|
381
381
|
expect(convoyColNames).toContain('total_tokens')
|
|
382
382
|
expect(convoyColNames).toContain('total_cost_usd')
|
|
383
383
|
|
|
384
|
-
expect(version.user_version).toBe(
|
|
384
|
+
expect(version.user_version).toBe(13)
|
|
385
385
|
})
|
|
386
386
|
|
|
387
387
|
it('schema migration v3 to v4 creates pipeline table and adds pipeline_id to convoy', () => {
|
|
@@ -464,7 +464,7 @@ describe('schema migration', () => {
|
|
|
464
464
|
|
|
465
465
|
expect(convoyCols.map(c => c.name)).toContain('pipeline_id')
|
|
466
466
|
expect(tables.map(t => t.name)).toContain('pipeline')
|
|
467
|
-
expect(version.user_version).toBe(
|
|
467
|
+
expect(version.user_version).toBe(13)
|
|
468
468
|
})
|
|
469
469
|
})
|
|
470
470
|
|
|
@@ -1458,7 +1458,7 @@ describe('schema migration v5 → v6', () => {
|
|
|
1458
1458
|
v5Verify.close()
|
|
1459
1459
|
migratedStore.close()
|
|
1460
1460
|
|
|
1461
|
-
expect(row.user_version).toBe(
|
|
1461
|
+
expect(row.user_version).toBe(13)
|
|
1462
1462
|
expect(taskStepTable?.name).toBe('task_step')
|
|
1463
1463
|
expect(convoy?.id).toBe('convoy-auto')
|
|
1464
1464
|
expect(task?.id).toBe('task-auto')
|
|
@@ -1628,7 +1628,7 @@ describe('schema migration v6→v7 (drift detection columns)', () => {
|
|
|
1628
1628
|
|
|
1629
1629
|
expect(cols.map(c => c.name)).toContain('drift_score')
|
|
1630
1630
|
expect(cols.map(c => c.name)).toContain('drift_retried')
|
|
1631
|
-
expect(version.user_version).toBe(
|
|
1631
|
+
expect(version.user_version).toBe(13)
|
|
1632
1632
|
})
|
|
1633
1633
|
|
|
1634
1634
|
it('new databases include drift_score and drift_retried in CREATE TABLE', () => {
|
|
@@ -1862,7 +1862,7 @@ describe('migration full chain v4→v10', () => {
|
|
|
1862
1862
|
const verifyDb = new DatabaseSync(chainDbPath)
|
|
1863
1863
|
verifyDb.exec('PRAGMA foreign_keys = 0')
|
|
1864
1864
|
const version = (verifyDb.prepare('PRAGMA user_version').get() as { user_version: number }).user_version
|
|
1865
|
-
expect(version).toBe(
|
|
1865
|
+
expect(version).toBe(13)
|
|
1866
1866
|
|
|
1867
1867
|
// Verify all new tables exist
|
|
1868
1868
|
const tables = (verifyDb.prepare("SELECT name FROM sqlite_master WHERE type='table'").all() as Array<{ name: string }>).map(t => t.name)
|
|
@@ -1876,11 +1876,19 @@ describe('migration full chain v4→v10', () => {
|
|
|
1876
1876
|
'gates', 'on_exhausted', 'injected', 'provenance', 'idempotency_key',
|
|
1877
1877
|
'current_step', 'total_steps', 'review_level', 'review_verdict', 'review_tokens',
|
|
1878
1878
|
'review_model', 'panel_attempts', 'dispute_id', 'drift_score', 'drift_retried',
|
|
1879
|
-
'outputs', 'inputs',
|
|
1879
|
+
'outputs', 'inputs',
|
|
1880
1880
|
]) {
|
|
1881
1881
|
expect(taskCols).toContain(col)
|
|
1882
1882
|
}
|
|
1883
1883
|
|
|
1884
|
+
// And the two the v12→v13 step takes back out again. A v4 database gains
|
|
1885
|
+
// `discovered_issues` at v7 and `compaction_count` at v10, so this chain is
|
|
1886
|
+
// the one that proves the drop runs after the adds rather than instead of
|
|
1887
|
+
// them — the columns have to appear and then go.
|
|
1888
|
+
for (const col of ['discovered_issues', 'compaction_count']) {
|
|
1889
|
+
expect(taskCols, `${col} survived the v12→v13 drop`).not.toContain(col)
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1884
1892
|
// Verify all new columns on convoy
|
|
1885
1893
|
const convoyCols = (verifyDb.prepare('PRAGMA table_info(convoy)').all() as Array<{ name: string }>).map(c => c.name)
|
|
1886
1894
|
for (const col of ['circuit_state', 'review_tokens_total', 'review_budget']) {
|
|
@@ -1909,6 +1917,72 @@ describe('migration full chain v4→v10', () => {
|
|
|
1909
1917
|
})
|
|
1910
1918
|
})
|
|
1911
1919
|
|
|
1920
|
+
// ── v12 → v13: the last of the intelligence suite ─────────────────────────────
|
|
1921
|
+
|
|
1922
|
+
/**
|
|
1923
|
+
* `compaction_count` and `discovered_issues` outlived the feature that wrote
|
|
1924
|
+
* them. Phase 4b of the refactoring plan deleted the intelligence modules and
|
|
1925
|
+
* the config keys they exposed; these two columns stayed behind, set to a
|
|
1926
|
+
* literal 0 and a literal null on every insert and read by nothing.
|
|
1927
|
+
*
|
|
1928
|
+
* Dropping a column rewrites the table, so what these cover is the part that
|
|
1929
|
+
* can go wrong: the rows have to come through it untouched.
|
|
1930
|
+
*/
|
|
1931
|
+
describe('migration v12 → v13', () => {
|
|
1932
|
+
it('drops both columns and keeps every row', () => {
|
|
1933
|
+
const dbPath13 = join(tmpDir, 'v12-to-v13.db')
|
|
1934
|
+
|
|
1935
|
+
// Build a v12 database the way the store itself would, then wind the version
|
|
1936
|
+
// back so the migration has something real to run against.
|
|
1937
|
+
const seeded = createConvoyStore(dbPath13)
|
|
1938
|
+
seeded.insertConvoy(makeConvoy({ id: 'c1', name: 'Kept' }))
|
|
1939
|
+
seeded.insertTask(makeTask({ id: 't1', convoy_id: 'c1', agent: 'developer' }))
|
|
1940
|
+
seeded.insertTask(makeTask({ id: 't2', convoy_id: 'c1', agent: 'architect' }))
|
|
1941
|
+
seeded.close()
|
|
1942
|
+
|
|
1943
|
+
const raw = new DatabaseSync(dbPath13)
|
|
1944
|
+
raw.exec('ALTER TABLE task ADD COLUMN compaction_count INTEGER NOT NULL DEFAULT 0')
|
|
1945
|
+
raw.exec('ALTER TABLE task ADD COLUMN discovered_issues TEXT')
|
|
1946
|
+
raw.exec('PRAGMA user_version = 12')
|
|
1947
|
+
raw.close()
|
|
1948
|
+
|
|
1949
|
+
const migrated = createConvoyStore(dbPath13)
|
|
1950
|
+
const t1 = migrated.getTask('t1', 'c1')
|
|
1951
|
+
const t2 = migrated.getTask('t2', 'c1')
|
|
1952
|
+
const convoy = migrated.getConvoy('c1')
|
|
1953
|
+
migrated.close()
|
|
1954
|
+
|
|
1955
|
+
const verify = new DatabaseSync(dbPath13)
|
|
1956
|
+
const cols = (verify.prepare('PRAGMA table_info(task)').all() as Array<{ name: string }>).map(c => c.name)
|
|
1957
|
+
const version = (verify.prepare('PRAGMA user_version').get() as { user_version: number }).user_version
|
|
1958
|
+
verify.close()
|
|
1959
|
+
|
|
1960
|
+
expect(cols).not.toContain('compaction_count')
|
|
1961
|
+
expect(cols).not.toContain('discovered_issues')
|
|
1962
|
+
expect(version).toBe(13)
|
|
1963
|
+
|
|
1964
|
+
// The rows, and the fields beside the dropped ones, survive the rewrite.
|
|
1965
|
+
expect(convoy?.name).toBe('Kept')
|
|
1966
|
+
expect(t1?.id).toBe('t1')
|
|
1967
|
+
expect(t1?.agent).toBe('developer')
|
|
1968
|
+
expect(t2?.agent).toBe('architect')
|
|
1969
|
+
})
|
|
1970
|
+
|
|
1971
|
+
it('is idempotent across a reopen', () => {
|
|
1972
|
+
const dbPath13 = join(tmpDir, 'v13-reopen.db')
|
|
1973
|
+
const first = createConvoyStore(dbPath13)
|
|
1974
|
+
first.insertConvoy(makeConvoy({ id: 'c1' }))
|
|
1975
|
+
first.close()
|
|
1976
|
+
|
|
1977
|
+
// A database already at 13 must not have the drop attempted again — the
|
|
1978
|
+
// columns are gone, and DROP COLUMN on a missing column throws.
|
|
1979
|
+
expect(() => {
|
|
1980
|
+
const again = createConvoyStore(dbPath13)
|
|
1981
|
+
again.close()
|
|
1982
|
+
}).not.toThrow()
|
|
1983
|
+
})
|
|
1984
|
+
})
|
|
1985
|
+
|
|
1912
1986
|
// ── Agent Identity ────────────────────────────────────────────────────────────
|
|
1913
1987
|
|
|
1914
1988
|
describe('agent identity', () => {
|
|
@@ -2541,7 +2615,7 @@ describe('v9→v10 migration', () => {
|
|
|
2541
2615
|
// Verify version = 11
|
|
2542
2616
|
const verifyDb = new DatabaseSync(migDb)
|
|
2543
2617
|
const version = (verifyDb.prepare('PRAGMA user_version').get() as { user_version: number }).user_version
|
|
2544
|
-
expect(version).toBe(
|
|
2618
|
+
expect(version).toBe(13)
|
|
2545
2619
|
|
|
2546
2620
|
// Verify new REAL columns exist
|
|
2547
2621
|
const convoyCols = (verifyDb.prepare('PRAGMA table_info(convoy)').all() as Array<{ name: string }>).map(c => c.name)
|