great-cto 3.47.0 → 3.49.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.
package/dist/run.js ADDED
@@ -0,0 +1,321 @@
1
+ /** Daily entry points. Adapters reuse host-owned state, checks and permissions. */
2
+ import { randomUUID } from 'node:crypto';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { existsSync } from 'node:fs';
5
+ import { join, resolve, dirname } from 'node:path';
6
+ import { spawnSync } from 'node:child_process';
7
+ import { codexControllerCandidates } from './codex-host.js';
8
+ const sharedTaskPath = codexControllerCandidates().map(p => join(dirname(p), 'lib', 'work-tasks.mjs')).find(existsSync);
9
+ // Variable URL keeps one runtime implementation shared with hooks/controller/board.
10
+ const sharedTasks = sharedTaskPath ? await import(pathToFileURL(sharedTaskPath).href) : null;
11
+ const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
12
+ const terminal = new Set(['done', 'cancelled']);
13
+ export const dailyUsage = `great-cto run "describe the task" [--host claude-code|codex] [--dir PATH]
14
+ great-cto status [--task TASK_UUID | RUN_UUID] [--host claude-code|codex] [--dir PATH] [--json]
15
+ great-cto resume [--task TASK_UUID | RUN_UUID] [--host claude-code|codex] [--dir PATH]
16
+
17
+ Default host: Claude Code (interactive /start and exact-session /resume).
18
+ Status reads task metadata; it does not launch a model.
19
+ Tasks persist goal, optional repeated --accept criteria and host links.
20
+ Use --task UUID for exact task status/resume; --json works for either host.
21
+ Use --operation UUID to replay a launch receipt without dispatching twice.
22
+ Codex runs require --allow PATHS (comma-separated write scope).
23
+ Codex resume selects the only unfinished run in this project; gates stay pending.
24
+ Research tasks use --intent research; controlled scope is report-only.
25
+ Advanced decisions/outcomes/measurements: great-cto task work.
26
+ Use --dry-run to preview a launch without starting an agent.
27
+ Advanced controller options remain available through great-cto codex-host.
28
+ `;
29
+ function parse(action, args, cwd) {
30
+ const out = { host: 'claude-code', dir: cwd, prompt: '', dryRun: false, json: false, help: false, acceptance: [], hostExplicit: false, intent: 'delivery', maxAttempts: 3 };
31
+ const positional = [];
32
+ let literal = false;
33
+ for (let i = 0; i < args.length; i++) {
34
+ const arg = args[i];
35
+ if (literal) {
36
+ positional.push(arg);
37
+ continue;
38
+ }
39
+ if (arg === '--') {
40
+ literal = true;
41
+ continue;
42
+ }
43
+ if (arg === '--dry-run') {
44
+ out.dryRun = true;
45
+ continue;
46
+ }
47
+ if (arg === '--json') {
48
+ out.json = true;
49
+ continue;
50
+ }
51
+ if (arg === '--help' || arg === '-h') {
52
+ out.help = true;
53
+ continue;
54
+ }
55
+ const key = arg.split('=')[0];
56
+ if (['--host', '--dir', '--allow', '--accept', '--task', '--operation', '--revision', '--intent', '--max-attempts'].includes(key)) {
57
+ const value = arg.includes('=') ? arg.slice(arg.indexOf('=') + 1) : args[++i];
58
+ if (!value || value.startsWith('--'))
59
+ throw Error(`${key} requires a value`);
60
+ if (key === '--host') {
61
+ if (value !== 'codex' && value !== 'claude-code')
62
+ throw Error('host must be claude-code or codex');
63
+ out.host = value;
64
+ out.hostExplicit = true;
65
+ }
66
+ else if (key === '--dir')
67
+ out.dir = resolve(cwd, value);
68
+ else if (key === '--allow')
69
+ out.allow = value;
70
+ else if (key === '--accept')
71
+ out.acceptance.push(value);
72
+ else if (key === '--intent') {
73
+ if (value !== 'delivery' && value !== 'research')
74
+ throw Error('--intent must be delivery or research');
75
+ out.intent = value;
76
+ }
77
+ else if (key === '--max-attempts') {
78
+ out.maxAttempts = Number(value);
79
+ if (!Number.isInteger(out.maxAttempts) || out.maxAttempts < 1 || out.maxAttempts > 5)
80
+ throw Error('--max-attempts must be 1..5');
81
+ }
82
+ else if (key === '--task') {
83
+ if (!uuid.test(value))
84
+ throw Error('--task requires a task UUID');
85
+ out.taskId = value;
86
+ }
87
+ else if (key === '--operation') {
88
+ if (!uuid.test(value))
89
+ throw Error('--operation requires an operation UUID');
90
+ out.operationId = value;
91
+ }
92
+ else {
93
+ out.revision = Number(value);
94
+ if (!Number.isInteger(out.revision) || out.revision < 1)
95
+ throw Error('--revision requires a positive integer');
96
+ }
97
+ }
98
+ else if (arg.startsWith('-'))
99
+ throw Error(`unknown option: ${arg}`);
100
+ else
101
+ positional.push(arg);
102
+ }
103
+ if (out.help)
104
+ return out;
105
+ if (action === 'run') {
106
+ out.prompt = positional.join(' ').trim();
107
+ if (!out.prompt)
108
+ throw Error('describe the task: great-cto run "..."');
109
+ }
110
+ else {
111
+ if (positional.length > 1 || (positional[0] && !uuid.test(positional[0])))
112
+ throw Error('expected one run UUID');
113
+ out.id = positional[0];
114
+ }
115
+ if (out.allow && (action !== 'run' || out.host !== 'codex'))
116
+ throw Error('--allow is only supported for run --host codex');
117
+ if (out.json && action !== 'status')
118
+ throw Error('--json is only supported for status');
119
+ if (out.acceptance.length && action !== 'run')
120
+ throw Error('--accept is only supported for run');
121
+ if (out.taskId && action === 'run')
122
+ throw Error('--task is for existing task status/resume');
123
+ if (out.taskId && out.id)
124
+ throw Error('select task or run UUID, not both');
125
+ if (action !== 'run' && args.some(a => a === '--intent' || a.startsWith('--intent=') || a === '--max-attempts' || a.startsWith('--max-attempts=')))
126
+ throw Error('--intent and --max-attempts are start-only');
127
+ if (out.host === 'claude-code' && args.some(a => a === '--max-attempts' || a.startsWith('--max-attempts=')))
128
+ throw Error('native rework budget is host-owned');
129
+ if (out.operationId && action === 'status')
130
+ throw Error('--operation is for execution only');
131
+ if (out.revision && action !== 'resume')
132
+ throw Error('--revision is for resume only');
133
+ if (out.id && out.host !== 'codex')
134
+ throw Error('run UUIDs belong to the controlled host; use --host codex');
135
+ if (action === 'run' && out.host === 'codex' && (!out.allow || out.allow.split(',').some(p => !p.trim()))) {
136
+ throw Error('Codex requires explicit write scope: --allow src,tests,docs');
137
+ }
138
+ return out;
139
+ }
140
+ /** Selection never uses filesystem order or UUID order as a proxy for recency. */
141
+ export function selectRun(runs, id) {
142
+ const candidates = id ? runs.filter(r => r.id === id) : runs.filter(r => !terminal.has(r.status));
143
+ if (!candidates.length)
144
+ throw Error(id ? 'run not found in this project' : 'no unfinished run in this project');
145
+ if (candidates.length !== 1)
146
+ throw Error('multiple unfinished runs; choose a UUID from great-cto status --host codex');
147
+ return candidates[0];
148
+ }
149
+ export function runDaily(action, args, { cwd = process.cwd(), exists = existsSync, spawn = spawnSync, write = (text) => { process.stdout.write(text); }, tasks = sharedTasks, taskStore = undefined, fail = (text) => { process.stderr.write(`great-cto: ${text}\n`); }, } = {}) {
150
+ let heldWork = null;
151
+ const release = () => { const lease = heldWork?.lease; heldWork = null; lease?.release(); };
152
+ try {
153
+ const options = parse(action, args, cwd);
154
+ if (options.help) {
155
+ write(dailyUsage);
156
+ return 0;
157
+ }
158
+ if (!exists(options.dir))
159
+ throw Error(`project directory does not exist: ${options.dir}`);
160
+ if (!tasks)
161
+ throw Error('shared task runtime missing; reinstall great-cto');
162
+ const storeOptions = taskStore ? { store: taskStore } : {};
163
+ // Dry runs stay pure; no metadata lookup is needed to preview an explicit host.
164
+ if (options.dryRun) {
165
+ write(JSON.stringify({ host: options.host, action, cwd: options.dir, dir: options.dir,
166
+ ...(options.host === 'claude-code' && action !== 'status' ? { command: 'claude', args: [action === 'run' ? `${options.intent === 'research' ? '/audit' : '/start'} ${options.prompt}` : '/resume'] } : {}),
167
+ intent: options.intent, maxAttempts: options.host === 'codex' ? options.maxAttempts : null,
168
+ taskId: options.taskId || null, id: options.id || 'project-scoped selection' }) + '\n');
169
+ return 0;
170
+ }
171
+ const taskListing = tasks.listWorkTasks(options.dir, storeOptions);
172
+ if (taskListing.state === 'degraded')
173
+ throw Error('task state is unreadable; selection is blocked');
174
+ let selectedTask = null;
175
+ if (options.taskId) {
176
+ selectedTask = taskListing.tasks.find((t) => t.taskId === options.taskId);
177
+ if (!selectedTask)
178
+ throw Error('task not found in this project');
179
+ if (options.hostExplicit && selectedTask.host !== options.host)
180
+ throw Error('task host cannot change during resume');
181
+ options.host = selectedTask.host;
182
+ }
183
+ if (action === 'run' && options.operationId && taskListing.tasks.some((t) => t.operations.some((o) => o.operationId === options.operationId))) {
184
+ const previous = tasks.beginWork({ root: options.dir, host: options.host, goal: options.prompt, acceptance: options.acceptance, intent: options.intent, maxAttempts: options.maxAttempts,
185
+ authority: options.host === 'codex' ? { mode: 'explicit-paths', writeScope: options.allow.split(',').map(p => p.trim()) } : { mode: 'native-interactive', writeScope: null },
186
+ operationId: options.operationId }, storeOptions);
187
+ write(JSON.stringify(tasks.publicWorkTask(previous.task)) + '\n');
188
+ return previous.operation.exitCode ?? 2;
189
+ }
190
+ if (action === 'resume' && options.operationId) {
191
+ const receiptTask = taskListing.tasks.find((t) => t.operations.some((o) => o.operationId === options.operationId));
192
+ if (receiptTask) {
193
+ if ((selectedTask && selectedTask.taskId !== receiptTask.taskId) || (options.id && !receiptTask.links.runs.includes(options.id))
194
+ || (options.hostExplicit && options.host !== receiptTask.host))
195
+ throw Error('idempotency key conflicts with another task');
196
+ const replay = tasks.beginWork({ root: options.dir, host: receiptTask.host, kind: 'resume', taskId: receiptTask.taskId,
197
+ operationId: options.operationId, expectedRevision: options.revision ?? null }, storeOptions);
198
+ write(JSON.stringify(tasks.publicWorkTask(replay.task)) + '\n');
199
+ return replay.operation.exitCode ?? 2;
200
+ }
201
+ }
202
+ if (options.host === 'claude-code') {
203
+ if (action === 'status') {
204
+ const shown = selectedTask ? [selectedTask] : taskListing.tasks.filter((t) => t.host === 'claude-code');
205
+ if (options.json)
206
+ write(JSON.stringify({ schemaVersion: 1, state: taskListing.state, tasks: shown.map(tasks.publicWorkTask) }, null, 2) + '\n');
207
+ else
208
+ write(shown.length ? shown.map((t) => `${t.taskId} ${t.phase} ${t.goal}`).join('\n') + '\n' : 'No tracked Claude tasks in this project.\n');
209
+ return 0;
210
+ }
211
+ if (action === 'resume' && !selectedTask) {
212
+ const candidates = taskListing.tasks.filter((t) => t.host === 'claude-code' && t.phase !== 'cancelled');
213
+ if (candidates.length > 1)
214
+ throw Error('multiple Claude tasks; select --task UUID');
215
+ selectedTask = candidates[0] || null;
216
+ }
217
+ if (action === 'resume' && !selectedTask)
218
+ throw Error('no tracked Claude task; use native /resume for legacy context');
219
+ const work = tasks.beginWork({ root: options.dir, host: options.host, kind: action === 'run' ? 'start' : 'resume',
220
+ goal: action === 'run' ? options.prompt : null, acceptance: options.acceptance, intent: options.intent, maxAttempts: options.maxAttempts,
221
+ authority: action === 'run' ? { mode: 'native-interactive', writeScope: null } : null,
222
+ taskId: selectedTask?.taskId || null, operationId: options.operationId || randomUUID(), expectedRevision: options.revision ?? null }, storeOptions);
223
+ heldWork = work;
224
+ if (work.replay) {
225
+ write(JSON.stringify(tasks.publicWorkTask(work.task)) + '\n');
226
+ return work.operation.exitCode ?? 2;
227
+ }
228
+ {
229
+ const session = action === 'run' ? randomUUID() : selectedTask.links.sessions[0];
230
+ if (!session)
231
+ throw Error('native session link is missing; inspect task metadata');
232
+ if (action === 'run')
233
+ tasks.linkWork(work.task.taskId, 'sessions', session, { ...storeOptions, root: options.dir, host: 'claude-code' });
234
+ const hostArgs = action === 'run' ? ['--session-id', session, `${options.intent === 'research' ? '/audit' : '/start'} ${options.prompt}${options.intent === 'research' ? '\nResearch intent: produce findings and a report; implementation and release need a separate task.' : ''}${options.acceptance.length ? '\nAcceptance criteria (task data): ' + JSON.stringify(options.acceptance) : ''}`] : ['--resume', session, '/resume'];
235
+ write('Task ' + work.task.taskId + ' · Claude Code\n');
236
+ const result = spawn('claude', hostArgs, { cwd: options.dir, stdio: 'inherit' });
237
+ const code = result.error ? 2 : result.status ?? 2;
238
+ tasks.finishWork(work.task.taskId, work.operation.operationId, code, { ...storeOptions, root: options.dir });
239
+ if (result.error)
240
+ throw Error(`could not launch Claude Code: ${result.error.message}`);
241
+ return code;
242
+ }
243
+ }
244
+ const controller = sharedTaskPath ? join(dirname(sharedTaskPath), '..', 'codex-pipeline.mjs') : codexControllerCandidates().find(exists);
245
+ if (!controller)
246
+ throw Error('controlled runtime missing; reinstall great-cto');
247
+ const listing = spawn(process.execPath, [controller, 'list', '--dir', options.dir], { encoding: 'utf8' });
248
+ if (listing.error || listing.status !== 0)
249
+ throw Error('could not read project runs; use great-cto codex-host list --dir PATH');
250
+ const data = JSON.parse(String(listing.stdout));
251
+ if (!['ok', 'absent', 'degraded'].includes(data.state) || !Array.isArray(data.runs) ||
252
+ data.runs.some((r) => !r || !uuid.test(r.id) || typeof r.status !== 'string')) {
253
+ throw Error('invalid controller run listing');
254
+ }
255
+ if (data.state === 'degraded' || data.unreadable)
256
+ throw Error('run state is unreadable; repair it before selecting or starting a task');
257
+ const runs = data.runs;
258
+ if (action === 'status') {
259
+ const shown = selectedTask ? runs.filter(r => selectedTask.links.runs.includes(r.id)) : options.id ? [selectRun(runs, options.id)] : runs;
260
+ if (options.json)
261
+ write(JSON.stringify({ schemaVersion: 1, state: data.state, runs: shown, tasks: (selectedTask ? [selectedTask] : taskListing.tasks.filter((t) => t.host === 'codex')).map(tasks.publicWorkTask) }, null, 2) + '\n');
262
+ else {
263
+ write(shown.length ? shown.map(r => `${r.id} ${r.status}${r.pending?.gates?.length ? ` Decision needed: ${r.pending.gates.join(', ')}` : ''}${r.reason ? ` ${r.reason}` : ''}`).join('\n') + '\n' : 'No controlled runs in this project.\n');
264
+ }
265
+ return 0;
266
+ }
267
+ let forwarded;
268
+ let work = null;
269
+ if (action === 'resume') {
270
+ if (selectedTask && selectedTask.links.runs.length !== 1)
271
+ throw Error('task run link is missing or ambiguous');
272
+ const selected = selectRun(runs, selectedTask?.links.runs[0] || options.id);
273
+ selectedTask ||= taskListing.tasks.find((t) => t.links.runs.includes(selected.id));
274
+ if (terminal.has(selected.status))
275
+ throw Error(`run is ${selected.status}; start a new task instead`);
276
+ if (selectedTask)
277
+ heldWork = work = tasks.beginWork({ root: options.dir, host: 'codex', kind: 'resume', taskId: selectedTask.taskId,
278
+ operationId: options.operationId || randomUUID(), expectedRevision: options.revision ?? null }, storeOptions);
279
+ if (!selectedTask && (options.operationId || options.revision))
280
+ throw Error('legacy run has no task receipt; use advanced controller resume');
281
+ forwarded = ['resume', selected.id];
282
+ }
283
+ else {
284
+ if (runs.some(r => !terminal.has(r.status)))
285
+ throw Error('unfinished task exists; use great-cto resume --host codex or choose a run from status');
286
+ // Existing projects enter architecture; new projects enter product discovery.
287
+ const entry = options.intent === 'research' ? 'project-auditor' : exists(join(options.dir, '.great_cto', 'PROJECT.md')) ? 'architect' : 'product-owner';
288
+ heldWork = work = tasks.beginWork({ root: options.dir, host: 'codex', goal: options.prompt, acceptance: options.acceptance, intent: options.intent, maxAttempts: options.maxAttempts,
289
+ authority: { mode: 'explicit-paths', writeScope: options.allow.split(',').map(p => p.trim()) },
290
+ operationId: options.operationId || randomUUID() }, storeOptions);
291
+ forwarded = ['start', '--dir', options.dir, '--prompt', options.prompt, '--allow', options.allow, '--entry', entry, '--task-id', work.task.taskId];
292
+ }
293
+ if (work?.replay) {
294
+ write(JSON.stringify(tasks.publicWorkTask(work.task)) + '\n');
295
+ return work.operation.exitCode ?? 2;
296
+ }
297
+ {
298
+ const result = spawn(process.execPath, [controller, ...forwarded], { stdio: 'inherit',
299
+ env: { ...process.env, ...(taskStore ? { GREAT_CTO_TASKS_DIR: taskStore } : {}), ...(work ? { GREAT_CTO_WORK_LEASE: work.lease.token } : {}) } });
300
+ const code = result.error ? 2 : result.status ?? 2;
301
+ if (work)
302
+ tasks.finishWork(work.task.taskId, work.operation.operationId, code, { ...storeOptions, root: options.dir });
303
+ if (result.error)
304
+ throw Error(`could not launch controlled runtime: ${result.error.message}`);
305
+ return code;
306
+ }
307
+ }
308
+ catch (error) {
309
+ if (heldWork && !heldWork.replay) {
310
+ try {
311
+ tasks?.finishWork(heldWork.task.taskId, heldWork.operation.operationId, 2, taskStore ? { store: taskStore } : {});
312
+ }
313
+ catch { /* preserve the original failure; no dispatch retry */ }
314
+ }
315
+ fail(error.message);
316
+ return 2;
317
+ }
318
+ finally {
319
+ release();
320
+ }
321
+ }
@@ -0,0 +1,18 @@
1
+ /** Advanced task operations share the same source/bundled runtime as daily entry. */
2
+ import { spawnSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+ import { join, dirname } from 'node:path';
5
+ import { codexControllerCandidates } from './codex-host.js';
6
+ export function runWorkTask(args) {
7
+ const script = codexControllerCandidates().map(p => join(dirname(p), 'work-task.mjs')).find(existsSync);
8
+ if (!script) {
9
+ process.stderr.write('great-cto: task operations runtime is missing; reinstall package\n');
10
+ return 2;
11
+ }
12
+ const result = spawnSync(process.execPath, [script, ...args], { stdio: 'inherit' });
13
+ if (result.error) {
14
+ process.stderr.write('great-cto: ' + result.error.message + '\n');
15
+ return 2;
16
+ }
17
+ return result.status ?? 2;
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "great-cto",
3
- "version": "3.47.0",
3
+ "version": "3.49.0",
4
4
  "description": "One command install for the great_cto Claude Code plugin. Auto-detects your stack, picks the right archetype, bootstraps PROJECT.md.",
5
5
  "keywords": [
6
6
  "claude-code",