zelio-cli 0.1.0-beta.1 → 0.1.0-beta.10
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/README.md +41 -148
- package/dist/cli-main.js +521 -0
- package/dist/cli-main.js.map +1 -0
- package/dist/cli.js +17 -464
- package/dist/cli.js.map +1 -1
- package/dist/cloud/account.js +109 -0
- package/dist/cloud/account.js.map +1 -0
- package/dist/cloud/command.js +7 -2
- package/dist/cloud/command.js.map +1 -1
- package/dist/cloud/login.js +2 -1
- package/dist/cloud/login.js.map +1 -1
- package/dist/cloud/push-nudge.js +5 -3
- package/dist/cloud/push-nudge.js.map +1 -1
- package/dist/cloud/relay.js +5 -0
- package/dist/cloud/relay.js.map +1 -1
- package/dist/cloud/tunnel.js +65 -1
- package/dist/cloud/tunnel.js.map +1 -1
- package/dist/db/db.js +381 -157
- package/dist/db/db.js.map +1 -1
- package/dist/db/lifecycle.js +18 -5
- package/dist/db/lifecycle.js.map +1 -1
- package/dist/limits.js +1 -1
- package/dist/orchestrator/area-notes.js +87 -0
- package/dist/orchestrator/area-notes.js.map +1 -0
- package/dist/orchestrator/codex-session.js +10 -9
- package/dist/orchestrator/codex-session.js.map +1 -1
- package/dist/orchestrator/contract.js +30 -22
- package/dist/orchestrator/contract.js.map +1 -1
- package/dist/orchestrator/new-task-prompt.js +4 -4
- package/dist/orchestrator/pi-session.js +6 -0
- package/dist/orchestrator/pi-session.js.map +1 -1
- package/dist/orchestrator/prompt.js +4 -4
- package/dist/orchestrator/research.js +28 -13
- package/dist/orchestrator/research.js.map +1 -1
- package/dist/orchestrator/retrieval.js +333 -0
- package/dist/orchestrator/retrieval.js.map +1 -0
- package/dist/orchestrator/runtime.js +199 -36
- package/dist/orchestrator/runtime.js.map +1 -1
- package/dist/repo/code-map.js +152 -0
- package/dist/repo/code-map.js.map +1 -0
- package/dist/repo/instructions.js +9 -3
- package/dist/repo/instructions.js.map +1 -1
- package/dist/repo/linked-boards.js +20 -123
- package/dist/repo/linked-boards.js.map +1 -1
- package/dist/repo/project-repos.js +78 -0
- package/dist/repo/project-repos.js.map +1 -0
- package/dist/run/actions.js +24 -0
- package/dist/run/actions.js.map +1 -1
- package/dist/run/auto-review.js +116 -0
- package/dist/run/auto-review.js.map +1 -0
- package/dist/run/claude-runtime.js +54 -12
- package/dist/run/claude-runtime.js.map +1 -1
- package/dist/run/codex-client.js +17 -4
- package/dist/run/codex-client.js.map +1 -1
- package/dist/run/codex-planner-config.js +26 -0
- package/dist/run/codex-planner-config.js.map +1 -0
- package/dist/run/codex-runtime.js +200 -97
- package/dist/run/codex-runtime.js.map +1 -1
- package/dist/run/consult.js +109 -0
- package/dist/run/consult.js.map +1 -0
- package/dist/run/developer-sandbox.js +67 -0
- package/dist/run/developer-sandbox.js.map +1 -0
- package/dist/run/diff.js +42 -0
- package/dist/run/diff.js.map +1 -1
- package/dist/run/finish.js +53 -16
- package/dist/run/finish.js.map +1 -1
- package/dist/run/handoff.js +51 -0
- package/dist/run/handoff.js.map +1 -0
- package/dist/run/harness-runtime.js +4 -1
- package/dist/run/harness-runtime.js.map +1 -1
- package/dist/run/harnesses.js +20 -0
- package/dist/run/harnesses.js.map +1 -1
- package/dist/run/lead.js +65 -82
- package/dist/run/lead.js.map +1 -1
- package/dist/run/manager.js +1096 -68
- package/dist/run/manager.js.map +1 -1
- package/dist/run/merge-watch.js +48 -17
- package/dist/run/merge-watch.js.map +1 -1
- package/dist/run/pi-packages.js +72 -0
- package/dist/run/pi-packages.js.map +1 -0
- package/dist/run/pi-rpc.js +61 -9
- package/dist/run/pi-rpc.js.map +1 -1
- package/dist/run/piped-check.js +56 -0
- package/dist/run/piped-check.js.map +1 -0
- package/dist/run/pr-checks.js +67 -0
- package/dist/run/pr-checks.js.map +1 -0
- package/dist/run/prompt.js +64 -4
- package/dist/run/prompt.js.map +1 -1
- package/dist/run/red-check.js +130 -0
- package/dist/run/red-check.js.map +1 -0
- package/dist/run/retro.js +2 -2
- package/dist/run/retro.js.map +1 -1
- package/dist/run/settings.js +5 -2
- package/dist/run/settings.js.map +1 -1
- package/dist/run/skills.js +146 -0
- package/dist/run/skills.js.map +1 -0
- package/dist/run/tests-first.js +146 -0
- package/dist/run/tests-first.js.map +1 -0
- package/dist/run/watchdog.js +266 -0
- package/dist/run/watchdog.js.map +1 -0
- package/dist/run/workflow.js +17 -6
- package/dist/run/workflow.js.map +1 -1
- package/dist/server/app.js +1083 -300
- package/dist/server/app.js.map +1 -1
- package/dist/server/principal.js +5 -2
- package/dist/server/principal.js.map +1 -1
- package/dist/server/provider-auth.js +206 -0
- package/dist/server/provider-auth.js.map +1 -0
- package/dist/server/repo-picker.js +18 -0
- package/dist/server/repo-picker.js.map +1 -0
- package/dist/server/terminal.js +2 -2
- package/dist/server/terminal.js.map +1 -1
- package/dist/setup/config.js +0 -31
- package/dist/setup/config.js.map +1 -1
- package/dist/setup/ink-ui.js +1 -0
- package/dist/setup/ink-ui.js.map +1 -1
- package/dist/setup/onboarding.js +12 -38
- package/dist/setup/onboarding.js.map +1 -1
- package/dist/setup/run.js +4 -5
- package/dist/setup/run.js.map +1 -1
- package/dist/skills.js +151 -0
- package/dist/skills.js.map +1 -0
- package/dist/ticket-cli.js +41 -0
- package/dist/ticket-cli.js.map +1 -1
- package/dist/version.js +13 -0
- package/dist/version.js.map +1 -0
- package/dist/web/assets/index-TN5sUF2z.css +1 -0
- package/dist/web/assets/index-vB3Cucuc.js +258 -0
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +3 -1
- package/media/board.png +0 -0
- package/media/mobile.png +0 -0
- package/media/new-task.png +0 -0
- package/media/review.png +0 -0
- package/package.json +16 -7
- package/dist/web/assets/index-ChuS3qKc.js +0 -254
- package/dist/web/assets/index-DR6WkmzI.css +0 -1
package/dist/db/db.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { DatabaseSync } from "node:sqlite";
|
|
2
2
|
import { mkdirSync } from "node:fs";
|
|
3
3
|
import { dirname } from "node:path";
|
|
4
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { createHash, randomUUID, timingSafeEqual } from "node:crypto";
|
|
5
5
|
import { attachmentPaths } from "../attachments.js";
|
|
6
6
|
import { MAX_ACTION_OUTPUT } from "../run/actions.js";
|
|
7
7
|
import { PROFILES } from "../run/profiles.js";
|
|
8
8
|
import { normaliseRunResult } from "../run/result.js";
|
|
9
|
-
import { asMaxAgents, asPlannerThinking, DEFAULT_MAX_AGENTS, DEFAULT_PLANNER_THINKING, } from "../run/settings.js";
|
|
9
|
+
import { asMaxAgents, asPlannerThinking, DEFAULT_MAX_AGENTS, DEFAULT_PLANNER_CHOICE_ENABLED, DEFAULT_TESTS_FIRST_ENABLED, DEFAULT_PLANNER_THINKING, } from "../run/settings.js";
|
|
10
|
+
import { skillIds } from "../run/skills.js";
|
|
10
11
|
import { parseThinkingLevel } from "../run/thinking.js";
|
|
11
12
|
import { emptyWorkflow, hasWorkflow, isWorkflowStage, normaliseWorkflow, } from "../run/workflow.js";
|
|
12
13
|
import { canTransition, checkSpec, describeRefusal, TransitionError, } from "./lifecycle.js";
|
|
@@ -64,8 +65,6 @@ function parseCommentActions(raw) {
|
|
|
64
65
|
return undefined;
|
|
65
66
|
const value = parsed;
|
|
66
67
|
const actions = {};
|
|
67
|
-
if (typeof value.workflows === "boolean")
|
|
68
|
-
actions.workflows = value.workflows;
|
|
69
68
|
if (typeof value.fixPrompt === "string")
|
|
70
69
|
actions.fixPrompt = value.fixPrompt;
|
|
71
70
|
const issue = value.issue;
|
|
@@ -90,6 +89,7 @@ const MIGRATIONS = [
|
|
|
90
89
|
acceptance TEXT NOT NULL DEFAULT '',
|
|
91
90
|
likely_files TEXT NOT NULL DEFAULT '[]',
|
|
92
91
|
context TEXT NOT NULL DEFAULT '[]',
|
|
92
|
+
plan TEXT,
|
|
93
93
|
attachments TEXT NOT NULL DEFAULT '[]',
|
|
94
94
|
state TEXT NOT NULL,
|
|
95
95
|
profile TEXT,
|
|
@@ -131,6 +131,8 @@ const MIGRATIONS = [
|
|
|
131
131
|
CREATE TABLE IF NOT EXISTS conversations (
|
|
132
132
|
id TEXT PRIMARY KEY,
|
|
133
133
|
plan TEXT,
|
|
134
|
+
planner_harness TEXT,
|
|
135
|
+
planner_model TEXT,
|
|
134
136
|
summary TEXT,
|
|
135
137
|
summary_from TEXT,
|
|
136
138
|
kind TEXT NOT NULL DEFAULT 'panel',
|
|
@@ -183,6 +185,18 @@ const MIGRATIONS = [
|
|
|
183
185
|
duration_ms INTEGER NOT NULL,
|
|
184
186
|
json TEXT NOT NULL
|
|
185
187
|
);
|
|
188
|
+
`,
|
|
189
|
+
`
|
|
190
|
+
-- A cache, not a record: one short note per source folder, written in the
|
|
191
|
+
-- background by a read-only scout and rewritten when the folder's files
|
|
192
|
+
-- change. It survives a board reset because it describes the repo, not the board.
|
|
193
|
+
CREATE TABLE IF NOT EXISTS area_notes (
|
|
194
|
+
path TEXT PRIMARY KEY,
|
|
195
|
+
hash TEXT NOT NULL,
|
|
196
|
+
head TEXT,
|
|
197
|
+
note TEXT NOT NULL,
|
|
198
|
+
written_at TEXT NOT NULL
|
|
199
|
+
);
|
|
186
200
|
`,
|
|
187
201
|
`
|
|
188
202
|
-- What each planner turn cost. A log, not a record: nothing on the board reads
|
|
@@ -207,7 +221,9 @@ const MIGRATIONS = [
|
|
|
207
221
|
output_chars INTEGER NOT NULL DEFAULT 0,
|
|
208
222
|
questions INTEGER NOT NULL DEFAULT 0,
|
|
209
223
|
cards INTEGER NOT NULL DEFAULT 0,
|
|
210
|
-
started_at TEXT NOT NULL
|
|
224
|
+
started_at TEXT NOT NULL,
|
|
225
|
+
-- What the model wrote, kept only when the turn failed on that text.
|
|
226
|
+
output TEXT
|
|
211
227
|
);
|
|
212
228
|
|
|
213
229
|
CREATE INDEX IF NOT EXISTS idx_planner_turns_started
|
|
@@ -242,22 +258,9 @@ const MIGRATIONS = [
|
|
|
242
258
|
);
|
|
243
259
|
`,
|
|
244
260
|
`
|
|
245
|
-
--
|
|
246
|
-
--
|
|
247
|
-
|
|
248
|
-
-- the record after it was refused.
|
|
249
|
-
CREATE TABLE IF NOT EXISTS workflow_suggestions (
|
|
250
|
-
id TEXT PRIMARY KEY,
|
|
251
|
-
stage TEXT NOT NULL,
|
|
252
|
-
ticket_id TEXT NOT NULL,
|
|
253
|
-
evidence TEXT NOT NULL DEFAULT '[]',
|
|
254
|
-
notes TEXT NOT NULL,
|
|
255
|
-
created_at TEXT NOT NULL,
|
|
256
|
-
applied_at TEXT,
|
|
257
|
-
dismissed_at TEXT
|
|
258
|
-
);
|
|
259
|
-
CREATE INDEX IF NOT EXISTS idx_workflow_suggestions_stage
|
|
260
|
-
ON workflow_suggestions(stage, created_at);
|
|
261
|
+
-- Manager notes used to queue here for the Workflows page, one near-identical
|
|
262
|
+
-- rewrite per run. They are a comment on the ticket now; the queue is gone.
|
|
263
|
+
DROP TABLE IF EXISTS workflow_suggestions;
|
|
261
264
|
`,
|
|
262
265
|
`
|
|
263
266
|
-- The board's revision is a counter, not a timestamp: a client that saw
|
|
@@ -301,10 +304,57 @@ const MIGRATIONS = [
|
|
|
301
304
|
output TEXT,
|
|
302
305
|
PRIMARY KEY (run_id, seq)
|
|
303
306
|
);
|
|
307
|
+
`,
|
|
308
|
+
`
|
|
309
|
+
-- Repositories attached to this board besides the home repo. A card with a
|
|
310
|
+
-- non-null tickets.repo works in that repository's checkout.
|
|
311
|
+
CREATE TABLE IF NOT EXISTS project_repos (
|
|
312
|
+
name TEXT PRIMARY KEY,
|
|
313
|
+
root TEXT NOT NULL UNIQUE,
|
|
314
|
+
added_at TEXT NOT NULL
|
|
315
|
+
);
|
|
316
|
+
`,
|
|
317
|
+
`
|
|
318
|
+
-- How long each Verify or workflow-check command took the last time the board
|
|
319
|
+
-- ran it, keyed by the exact command string. The developer prompt quotes it,
|
|
320
|
+
-- so an agent knows a slow command is slow before its shell returns early.
|
|
321
|
+
-- repo is '' for the home repo and the project_repos name otherwise.
|
|
322
|
+
CREATE TABLE IF NOT EXISTS command_durations (
|
|
323
|
+
repo TEXT NOT NULL DEFAULT '',
|
|
324
|
+
command TEXT NOT NULL,
|
|
325
|
+
duration_ms INTEGER NOT NULL,
|
|
326
|
+
measured_at TEXT NOT NULL,
|
|
327
|
+
PRIMARY KEY (repo, command)
|
|
328
|
+
);
|
|
329
|
+
`,
|
|
330
|
+
`
|
|
331
|
+
-- Reusable agent guidance a person keeps on the board. Config, not record: it
|
|
332
|
+
-- survives a board reset. The name is the key, so a skill is found by what it
|
|
333
|
+
-- is called. source is the GitHub link it was loaded from, or '' when typed.
|
|
334
|
+
CREATE TABLE IF NOT EXISTS skills (
|
|
335
|
+
name TEXT PRIMARY KEY,
|
|
336
|
+
body TEXT NOT NULL,
|
|
337
|
+
source TEXT NOT NULL DEFAULT '',
|
|
338
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
339
|
+
created_at TEXT NOT NULL
|
|
340
|
+
);
|
|
304
341
|
`,
|
|
305
342
|
];
|
|
306
343
|
/** A run keeps at most this many tool-call rows; later calls are not recorded. */
|
|
307
344
|
export const MAX_RUN_TOOL_CALLS = 500;
|
|
345
|
+
/**
|
|
346
|
+
* A failed turn keeps at most this much of what the model wrote. The tail is
|
|
347
|
+
* kept, because the plan block is the last thing it writes.
|
|
348
|
+
*/
|
|
349
|
+
export const MAX_PLANNER_OUTPUT_CHARS = 100_000;
|
|
350
|
+
function toSkill(row) {
|
|
351
|
+
return {
|
|
352
|
+
name: String(row.name),
|
|
353
|
+
text: String(row.body ?? ""),
|
|
354
|
+
source: String(row.source ?? ""),
|
|
355
|
+
enabled: Number(row.enabled) === 1,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
308
358
|
function toProfile(row) {
|
|
309
359
|
return {
|
|
310
360
|
name: String(row.name),
|
|
@@ -324,24 +374,56 @@ function toTicket(row) {
|
|
|
324
374
|
acceptance: String(row.acceptance),
|
|
325
375
|
likely_files: JSON.parse(String(row.likely_files)),
|
|
326
376
|
context: parseContext(row.context),
|
|
377
|
+
plan: typeof row.plan === "string" && row.plan.trim() ? row.plan : null,
|
|
327
378
|
attachments: parseAttachments(row.attachments),
|
|
328
379
|
verify: parseVerify(row.verify),
|
|
329
380
|
state: String(row.state),
|
|
330
381
|
profile: row.profile === null ? null : String(row.profile),
|
|
331
382
|
thinking: parseThinkingLevel(row.thinking === null ? null : String(row.thinking)) ?? null,
|
|
383
|
+
model: typeof row.model === "string" && row.model.trim() ? row.model : null,
|
|
384
|
+
planner_harness: typeof row.planner_harness === "string" && row.planner_harness.trim()
|
|
385
|
+
? row.planner_harness
|
|
386
|
+
: null,
|
|
387
|
+
developer_harness: typeof row.developer_harness === "string" && row.developer_harness.trim()
|
|
388
|
+
? row.developer_harness
|
|
389
|
+
: null,
|
|
390
|
+
skills: parseSkills(row.skills),
|
|
332
391
|
blocker_kind: (row.blocker_kind ?? null),
|
|
333
392
|
blocker_reason: row.blocker_reason === null ? null : String(row.blocker_reason),
|
|
334
393
|
blocker_unblock: row.blocker_unblock === null ? null : String(row.blocker_unblock),
|
|
394
|
+
blocker_action: row.blocker_action === "edit_agents" ? "edit_agents" : null,
|
|
335
395
|
quick: Number(row.quick) === 1,
|
|
336
396
|
prepare_error: row.prepare_error === null ? null : String(row.prepare_error),
|
|
337
397
|
pr_url: row.pr_url === null || row.pr_url === undefined ? null : String(row.pr_url),
|
|
338
398
|
branch: row.branch === null || row.branch === undefined ? null : String(row.branch),
|
|
339
399
|
archived_at: row.archived_at === null || row.archived_at === undefined ? null : String(row.archived_at),
|
|
400
|
+
repo: row.repo === null || row.repo === undefined ? null : String(row.repo),
|
|
401
|
+
handoff: typeof row.handed_off_at === "string" && typeof row.handoff_harness === "string"
|
|
402
|
+
? {
|
|
403
|
+
harness: row.handoff_harness,
|
|
404
|
+
session: typeof row.handoff_session === "string" ? row.handoff_session : null,
|
|
405
|
+
at: row.handed_off_at,
|
|
406
|
+
}
|
|
407
|
+
: null,
|
|
340
408
|
created_at: String(row.created_at),
|
|
341
409
|
updated_at: String(row.updated_at),
|
|
342
410
|
confirmed_at: row.confirmed_at === null ? null : String(row.confirmed_at),
|
|
343
411
|
};
|
|
344
412
|
}
|
|
413
|
+
function hashHandoffToken(token) {
|
|
414
|
+
return createHash("sha256").update(token).digest("hex");
|
|
415
|
+
}
|
|
416
|
+
/** A malformed column reads as "no skills chosen", never as a crash. */
|
|
417
|
+
function parseSkills(value) {
|
|
418
|
+
if (typeof value !== "string")
|
|
419
|
+
return [];
|
|
420
|
+
try {
|
|
421
|
+
return skillIds(JSON.parse(value));
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
return [];
|
|
425
|
+
}
|
|
426
|
+
}
|
|
345
427
|
/** A malformed or hostile column reads as "no screenshots", never as a crash. */
|
|
346
428
|
function parseAttachments(value) {
|
|
347
429
|
if (typeof value !== "string")
|
|
@@ -410,7 +492,10 @@ function toAgentRun(row) {
|
|
|
410
492
|
resume_count: Number(row.resume_count) || 0,
|
|
411
493
|
profile: row.profile === null || row.profile === undefined ? null : String(row.profile),
|
|
412
494
|
harness: row.harness === null || row.harness === undefined ? null : String(row.harness),
|
|
413
|
-
|
|
495
|
+
model: row.model === null || row.model === undefined ? null : String(row.model),
|
|
496
|
+
job_source: row.job_source === "comment" || row.job_source === "conflict" || row.job_source === "check"
|
|
497
|
+
? row.job_source
|
|
498
|
+
: "ticket",
|
|
414
499
|
job_prompt: row.job_prompt === null || row.job_prompt === undefined ? null : String(row.job_prompt),
|
|
415
500
|
job_system_prompt: row.job_system_prompt === null || row.job_system_prompt === undefined
|
|
416
501
|
? null
|
|
@@ -506,16 +591,29 @@ export class ZelioDb {
|
|
|
506
591
|
// guard makes the ALTER idempotent: SQLite has no ADD COLUMN IF NOT EXISTS.
|
|
507
592
|
this.ensureColumn("tickets", "attachments", "TEXT NOT NULL DEFAULT '[]'");
|
|
508
593
|
this.ensureColumn("tickets", "context", "TEXT NOT NULL DEFAULT '[]'");
|
|
594
|
+
this.ensureColumn("tickets", "plan", "TEXT");
|
|
509
595
|
this.ensureColumn("tickets", "quick", "INTEGER NOT NULL DEFAULT 0");
|
|
510
596
|
this.ensureColumn("tickets", "thinking", "TEXT");
|
|
597
|
+
this.ensureColumn("tickets", "model", "TEXT");
|
|
598
|
+
this.ensureColumn("tickets", "blocker_action", "TEXT");
|
|
599
|
+
this.ensureColumn("tickets", "planner_harness", "TEXT");
|
|
600
|
+
this.ensureColumn("tickets", "developer_harness", "TEXT");
|
|
601
|
+
this.ensureColumn("tickets", "skills", "TEXT NOT NULL DEFAULT '[]'");
|
|
511
602
|
this.ensureColumn("tickets", "prepare_error", "TEXT");
|
|
512
603
|
this.ensureColumn("tickets", "pr_url", "TEXT");
|
|
513
604
|
this.ensureColumn("tickets", "branch", "TEXT");
|
|
514
605
|
this.ensureColumn("tickets", "archived_at", "TEXT");
|
|
515
606
|
this.ensureColumn("tickets", "verify", "TEXT NOT NULL DEFAULT '[]'");
|
|
607
|
+
this.ensureColumn("tickets", "repo", "TEXT");
|
|
608
|
+
this.ensureColumn("tickets", "handoff_harness", "TEXT");
|
|
609
|
+
this.ensureColumn("tickets", "handoff_session", "TEXT");
|
|
610
|
+
this.ensureColumn("tickets", "handed_off_at", "TEXT");
|
|
611
|
+
this.ensureColumn("tickets", "handoff_token", "TEXT");
|
|
516
612
|
this.ensureColumn("conversations", "summary", "TEXT");
|
|
517
613
|
this.ensureColumn("conversations", "summary_from", "TEXT");
|
|
518
614
|
this.ensureColumn("conversations", "kind", "TEXT NOT NULL DEFAULT 'panel'");
|
|
615
|
+
this.ensureColumn("conversations", "planner_harness", "TEXT");
|
|
616
|
+
this.ensureColumn("conversations", "planner_model", "TEXT");
|
|
519
617
|
this.ensureColumn("orchestrator_messages", "kind", "TEXT NOT NULL DEFAULT 'message'");
|
|
520
618
|
this.ensureColumn("comments", "blocker_kind", "TEXT");
|
|
521
619
|
this.ensureColumn("comments", "reply_to", "TEXT");
|
|
@@ -529,6 +627,7 @@ export class ZelioDb {
|
|
|
529
627
|
this.ensureColumn("agent_runs", "resume_count", "INTEGER NOT NULL DEFAULT 0");
|
|
530
628
|
this.ensureColumn("agent_runs", "profile", "TEXT");
|
|
531
629
|
this.ensureColumn("agent_runs", "harness", "TEXT");
|
|
630
|
+
this.ensureColumn("agent_runs", "model", "TEXT");
|
|
532
631
|
this.ensureColumn("agent_runs", "job_source", "TEXT NOT NULL DEFAULT 'ticket'");
|
|
533
632
|
this.ensureColumn("agent_runs", "job_prompt", "TEXT");
|
|
534
633
|
this.ensureColumn("agent_runs", "job_system_prompt", "TEXT");
|
|
@@ -538,11 +637,8 @@ export class ZelioDb {
|
|
|
538
637
|
this.ensureColumn("agent_runs", "workflow", "TEXT");
|
|
539
638
|
this.ensureColumn("planner_turns", "tool_budget", "INTEGER NOT NULL DEFAULT 0");
|
|
540
639
|
this.ensureColumn("planner_turns", "capped", "TEXT");
|
|
640
|
+
this.ensureColumn("planner_turns", "output", "TEXT");
|
|
541
641
|
this.seedProfiles();
|
|
542
|
-
// A model written before harnesses were paired to profiles belonged to the
|
|
543
|
-
// only runtime that existed then. Record that instead of letting a later
|
|
544
|
-
// machine default send a pi model to Codex.
|
|
545
|
-
this.db.exec("UPDATE agent_profiles SET harness = 'pi' WHERE model <> '' AND (harness IS NULL OR harness = '')");
|
|
546
642
|
}
|
|
547
643
|
/**
|
|
548
644
|
* Seed once, then leave the rows alone: a restart must not undo an edit, and
|
|
@@ -677,9 +773,9 @@ export class ZelioDb {
|
|
|
677
773
|
return this.getProfile(name);
|
|
678
774
|
}
|
|
679
775
|
/**
|
|
680
|
-
* A machine setup is the new choice of harness
|
|
681
|
-
*
|
|
682
|
-
*
|
|
776
|
+
* A machine setup is the new choice of harness, so every profile goes back
|
|
777
|
+
* to following it. Both columns clear together: a harness left pinned would
|
|
778
|
+
* keep sending runs to the old runtime with a model that may not exist there.
|
|
683
779
|
* Thinking and extra prompts are not runtime choices and stay.
|
|
684
780
|
*/
|
|
685
781
|
clearProfileRuntimeOverrides() {
|
|
@@ -691,10 +787,42 @@ export class ZelioDb {
|
|
|
691
787
|
this.seedProfiles();
|
|
692
788
|
return this.listProfiles();
|
|
693
789
|
}
|
|
790
|
+
/** Oldest first, so a skill keeps its place in the list once saved. */
|
|
791
|
+
listSkills() {
|
|
792
|
+
const rows = this.db
|
|
793
|
+
.prepare("SELECT * FROM skills ORDER BY created_at ASC, name ASC")
|
|
794
|
+
.all();
|
|
795
|
+
return rows.map(toSkill);
|
|
796
|
+
}
|
|
797
|
+
getSkill(name) {
|
|
798
|
+
const row = this.db.prepare("SELECT * FROM skills WHERE name = ?").get(name);
|
|
799
|
+
return row ? toSkill(row) : null;
|
|
800
|
+
}
|
|
801
|
+
addSkill(input) {
|
|
802
|
+
this.db
|
|
803
|
+
.prepare("INSERT INTO skills (name, body, source, enabled, created_at) VALUES (?, ?, ?, ?, ?)")
|
|
804
|
+
.run(input.name, input.text, input.source ?? "", input.enabled === false ? 0 : 1, new Date().toISOString());
|
|
805
|
+
return this.getSkill(input.name);
|
|
806
|
+
}
|
|
807
|
+
/** Edits the text or the enabled switch; the name is the key and stays. */
|
|
808
|
+
updateSkill(name, patch) {
|
|
809
|
+
const current = this.getSkill(name);
|
|
810
|
+
if (!current)
|
|
811
|
+
return null;
|
|
812
|
+
const next = { ...current, ...patch };
|
|
813
|
+
this.db
|
|
814
|
+
.prepare("UPDATE skills SET body = ?, enabled = ? WHERE name = ?")
|
|
815
|
+
.run(next.text, next.enabled ? 1 : 0, name);
|
|
816
|
+
return this.getSkill(name);
|
|
817
|
+
}
|
|
694
818
|
createTicket(input) {
|
|
695
819
|
const now = new Date().toISOString();
|
|
696
820
|
const state = input.state ?? "proposed";
|
|
697
821
|
const thinking = parseThinkingLevel(input.thinking ?? null) ?? null;
|
|
822
|
+
const model = input.model?.trim() || null;
|
|
823
|
+
const plannerHarness = input.planner_harness?.trim() || null;
|
|
824
|
+
const developerHarness = input.developer_harness?.trim() || null;
|
|
825
|
+
const skills = skillIds(input.skills);
|
|
698
826
|
const ticket = {
|
|
699
827
|
id: `T-${randomUUID().slice(0, 8)}`,
|
|
700
828
|
title: input.title,
|
|
@@ -703,11 +831,16 @@ export class ZelioDb {
|
|
|
703
831
|
acceptance: input.acceptance ?? "",
|
|
704
832
|
likely_files: input.likely_files ?? [],
|
|
705
833
|
context: input.context ?? [],
|
|
834
|
+
plan: input.plan?.trim() || null,
|
|
706
835
|
attachments: input.attachments ?? [],
|
|
707
836
|
verify: normaliseVerify(input.verify),
|
|
708
837
|
state,
|
|
709
838
|
profile: input.profile ?? null,
|
|
710
839
|
thinking,
|
|
840
|
+
model,
|
|
841
|
+
planner_harness: plannerHarness,
|
|
842
|
+
developer_harness: developerHarness,
|
|
843
|
+
skills,
|
|
711
844
|
blocker_kind: null,
|
|
712
845
|
blocker_reason: null,
|
|
713
846
|
blocker_unblock: null,
|
|
@@ -715,16 +848,18 @@ export class ZelioDb {
|
|
|
715
848
|
prepare_error: null,
|
|
716
849
|
pr_url: null,
|
|
717
850
|
branch: null,
|
|
851
|
+
archived_at: null,
|
|
852
|
+
repo: input.repo?.trim() || null,
|
|
718
853
|
created_at: now,
|
|
719
854
|
updated_at: now,
|
|
720
855
|
confirmed_at: state === "todo" ? now : null,
|
|
721
856
|
};
|
|
722
857
|
this.db
|
|
723
|
-
.prepare(`INSERT INTO tickets (id, title, goal, out_of_scope, acceptance, likely_files, context, attachments,
|
|
724
|
-
verify, state, profile, thinking, blocker_kind, blocker_reason, blocker_unblock,
|
|
725
|
-
prepare_error, created_at, updated_at, confirmed_at)
|
|
726
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
727
|
-
.run(ticket.id, ticket.title, ticket.goal, ticket.out_of_scope, ticket.acceptance, JSON.stringify(ticket.likely_files), JSON.stringify(ticket.context), JSON.stringify(ticket.attachments), JSON.stringify(ticket.verify), ticket.state, ticket.profile, thinking, null, null, null, ticket.quick ? 1 : 0, null, ticket.created_at, ticket.updated_at, ticket.confirmed_at);
|
|
858
|
+
.prepare(`INSERT INTO tickets (id, title, goal, out_of_scope, acceptance, likely_files, context, plan, attachments,
|
|
859
|
+
verify, state, profile, thinking, model, planner_harness, developer_harness, skills, blocker_kind, blocker_reason, blocker_unblock,
|
|
860
|
+
quick, prepare_error, repo, created_at, updated_at, confirmed_at)
|
|
861
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
862
|
+
.run(ticket.id, ticket.title, ticket.goal, ticket.out_of_scope, ticket.acceptance, JSON.stringify(ticket.likely_files), JSON.stringify(ticket.context), ticket.plan?.trim() || null, JSON.stringify(ticket.attachments), JSON.stringify(ticket.verify), ticket.state, ticket.profile, thinking, model, plannerHarness, developerHarness, JSON.stringify(skills), null, null, null, ticket.quick ? 1 : 0, null, ticket.repo ?? null, ticket.created_at, ticket.updated_at, ticket.confirmed_at);
|
|
728
863
|
this.emit({ type: "ticket_created", ticket });
|
|
729
864
|
return ticket;
|
|
730
865
|
}
|
|
@@ -773,13 +908,14 @@ export class ZelioDb {
|
|
|
773
908
|
likely_files: patch.likely_files?.length ? patch.likely_files : ticket.likely_files,
|
|
774
909
|
verify: patch.verify !== undefined ? normaliseVerify(patch.verify) : ticket.verify,
|
|
775
910
|
context: patch.context?.length ? [...patch.context] : (ticket.context ?? []),
|
|
911
|
+
plan: patch.plan?.trim() || ticket.plan || null,
|
|
776
912
|
prepare_error: clearPrepareError ? null : ticket.prepare_error,
|
|
777
913
|
updated_at: now,
|
|
778
914
|
};
|
|
779
915
|
this.db
|
|
780
|
-
.prepare(`UPDATE tickets SET goal = ?, out_of_scope = ?, acceptance = ?, likely_files = ?, verify = ?, context = ?,
|
|
916
|
+
.prepare(`UPDATE tickets SET goal = ?, out_of_scope = ?, acceptance = ?, likely_files = ?, verify = ?, context = ?, plan = ?,
|
|
781
917
|
prepare_error = ?, updated_at = ? WHERE id = ?`)
|
|
782
|
-
.run(next.goal, next.out_of_scope, next.acceptance, JSON.stringify(next.likely_files), JSON.stringify(next.verify), JSON.stringify(next.context), next.prepare_error ?? null, next.updated_at, id);
|
|
918
|
+
.run(next.goal, next.out_of_scope, next.acceptance, JSON.stringify(next.likely_files), JSON.stringify(next.verify), JSON.stringify(next.context), next.plan ?? null, next.prepare_error ?? null, next.updated_at, id);
|
|
783
919
|
this.emit({ type: "ticket_updated", ticket: next });
|
|
784
920
|
return next;
|
|
785
921
|
}
|
|
@@ -829,6 +965,39 @@ export class ZelioDb {
|
|
|
829
965
|
this.emit({ type: "ticket_updated", ticket: next });
|
|
830
966
|
return next;
|
|
831
967
|
}
|
|
968
|
+
/**
|
|
969
|
+
* Moves the ticket to `handed_off` and records who has it, in one statement:
|
|
970
|
+
* a token that outlived its state, or a state with no token, would be a card
|
|
971
|
+
* nobody can write to or one an old agent still can.
|
|
972
|
+
*/
|
|
973
|
+
handOff(id, input) {
|
|
974
|
+
const ticket = this.getTicket(id);
|
|
975
|
+
if (!ticket)
|
|
976
|
+
throw new TransitionError("todo", "handed_off", `no ticket ${id}`);
|
|
977
|
+
if (!canTransition(ticket.state, "handed_off")) {
|
|
978
|
+
throw new TransitionError(ticket.state, "handed_off", describeRefusal(ticket.state, "handed_off"));
|
|
979
|
+
}
|
|
980
|
+
const now = new Date().toISOString();
|
|
981
|
+
this.db
|
|
982
|
+
.prepare(`UPDATE tickets SET state = 'handed_off', blocker_kind = NULL, blocker_reason = NULL,
|
|
983
|
+
blocker_unblock = NULL, blocker_action = NULL, handoff_harness = ?, handoff_session = ?, handed_off_at = ?,
|
|
984
|
+
handoff_token = ?, updated_at = ? WHERE id = ?`)
|
|
985
|
+
.run(input.harness, input.session, now, hashHandoffToken(input.token), now, id);
|
|
986
|
+
const next = this.getTicket(id);
|
|
987
|
+
this.emit({ type: "ticket_updated", ticket: next });
|
|
988
|
+
return next;
|
|
989
|
+
}
|
|
990
|
+
/** The handed-off agent's token, valid only while the card is still handed off. */
|
|
991
|
+
verifyHandoffToken(id, token) {
|
|
992
|
+
if (!token)
|
|
993
|
+
return false;
|
|
994
|
+
const row = this.db.prepare("SELECT state, handoff_token FROM tickets WHERE id = ?").get(id);
|
|
995
|
+
if (!row || row.state !== "handed_off" || typeof row.handoff_token !== "string")
|
|
996
|
+
return false;
|
|
997
|
+
const expected = Buffer.from(row.handoff_token);
|
|
998
|
+
const actual = Buffer.from(hashHandoffToken(token));
|
|
999
|
+
return expected.length === actual.length && timingSafeEqual(expected, actual);
|
|
1000
|
+
}
|
|
832
1001
|
transition(id, to, extra = {}) {
|
|
833
1002
|
const ticket = this.getTicket(id);
|
|
834
1003
|
if (!ticket)
|
|
@@ -843,14 +1012,80 @@ export class ZelioDb {
|
|
|
843
1012
|
throw new TransitionError(ticket.state, to, describeRefusal(ticket.state, to));
|
|
844
1013
|
}
|
|
845
1014
|
const now = new Date().toISOString();
|
|
846
|
-
const next = {
|
|
1015
|
+
const next = {
|
|
1016
|
+
...ticket,
|
|
1017
|
+
...extra,
|
|
1018
|
+
state: to,
|
|
1019
|
+
updated_at: now,
|
|
1020
|
+
// An action belongs to the blocker that named it; any other move drops it.
|
|
1021
|
+
blocker_action: to === "blocked" ? (extra.blocker_action ?? null) : null,
|
|
1022
|
+
};
|
|
847
1023
|
this.db
|
|
848
|
-
.prepare(`UPDATE tickets SET state = ?, profile = ?, blocker_kind = ?, blocker_reason = ?,
|
|
849
|
-
blocker_unblock = ?, updated_at = ?, confirmed_at = ? WHERE id = ?`)
|
|
850
|
-
.run(next.state, next.profile, next.blocker_kind, next.blocker_reason, next.blocker_unblock, next.updated_at, next.confirmed_at, id);
|
|
1024
|
+
.prepare(`UPDATE tickets SET state = ?, profile = ?, model = ?, blocker_kind = ?, blocker_reason = ?,
|
|
1025
|
+
blocker_unblock = ?, blocker_action = ?, updated_at = ?, confirmed_at = ? WHERE id = ?`)
|
|
1026
|
+
.run(next.state, next.profile, next.model ?? null, next.blocker_kind, next.blocker_reason, next.blocker_unblock, next.blocker_action ?? null, next.updated_at, next.confirmed_at, id);
|
|
1027
|
+
// Leaving `handed_off` ends that agent's access; the record of who had it stays.
|
|
1028
|
+
if (ticket.state === "handed_off" && to !== "handed_off") {
|
|
1029
|
+
this.db.prepare("UPDATE tickets SET handoff_token = NULL WHERE id = ?").run(id);
|
|
1030
|
+
}
|
|
851
1031
|
this.emit({ type: "ticket_updated", ticket: next });
|
|
852
1032
|
return next;
|
|
853
1033
|
}
|
|
1034
|
+
/** Attached repositories, oldest first. */
|
|
1035
|
+
listRepos() {
|
|
1036
|
+
const rows = this.db
|
|
1037
|
+
.prepare("SELECT name, root, added_at FROM project_repos ORDER BY added_at ASC, name ASC")
|
|
1038
|
+
.all();
|
|
1039
|
+
return rows.map((row) => ({
|
|
1040
|
+
name: String(row.name),
|
|
1041
|
+
root: String(row.root),
|
|
1042
|
+
added_at: String(row.added_at),
|
|
1043
|
+
}));
|
|
1044
|
+
}
|
|
1045
|
+
addRepo(input) {
|
|
1046
|
+
const repo = {
|
|
1047
|
+
name: input.name,
|
|
1048
|
+
root: input.root,
|
|
1049
|
+
added_at: new Date().toISOString(),
|
|
1050
|
+
};
|
|
1051
|
+
this.db
|
|
1052
|
+
.prepare("INSERT INTO project_repos (name, root, added_at) VALUES (?, ?, ?)")
|
|
1053
|
+
.run(repo.name, repo.root, repo.added_at);
|
|
1054
|
+
this.emit({ type: "repo_changed", name: repo.name });
|
|
1055
|
+
return repo;
|
|
1056
|
+
}
|
|
1057
|
+
/** Detaches a repository row. Its tickets are the caller's to archive or refuse first. */
|
|
1058
|
+
removeRepo(name) {
|
|
1059
|
+
const result = this.db.prepare("DELETE FROM project_repos WHERE name = ?").run(name);
|
|
1060
|
+
if (Number(result.changes) === 0)
|
|
1061
|
+
return false;
|
|
1062
|
+
this.emit({ type: "repo_changed", name });
|
|
1063
|
+
return true;
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Takes every card of one added repository off the board, the same way
|
|
1067
|
+
* archiveDone() does: rows, comments and runs stay.
|
|
1068
|
+
*/
|
|
1069
|
+
archiveRepoTickets(name) {
|
|
1070
|
+
const rows = this.db
|
|
1071
|
+
.prepare("SELECT * FROM tickets WHERE repo = ? AND archived_at IS NULL")
|
|
1072
|
+
.all(name);
|
|
1073
|
+
if (rows.length === 0)
|
|
1074
|
+
return [];
|
|
1075
|
+
const now = new Date().toISOString();
|
|
1076
|
+
this.db
|
|
1077
|
+
.prepare("UPDATE tickets SET archived_at = ?, updated_at = ? WHERE repo = ? AND archived_at IS NULL")
|
|
1078
|
+
.run(now, now, name);
|
|
1079
|
+
const archived = rows.map((row) => {
|
|
1080
|
+
const ticket = toTicket(row);
|
|
1081
|
+
ticket.archived_at = now;
|
|
1082
|
+
ticket.updated_at = now;
|
|
1083
|
+
return ticket;
|
|
1084
|
+
});
|
|
1085
|
+
for (const ticket of archived)
|
|
1086
|
+
this.emit({ type: "ticket_updated", ticket });
|
|
1087
|
+
return archived;
|
|
1088
|
+
}
|
|
854
1089
|
/**
|
|
855
1090
|
* Takes every completed card off the board without deleting anything: the
|
|
856
1091
|
* rows, their comments and their runs stay, and only listTickets() stops
|
|
@@ -1029,6 +1264,12 @@ export class ZelioDb {
|
|
|
1029
1264
|
.run(plan ? JSON.stringify(plan) : null, now, id);
|
|
1030
1265
|
return this.readConversation(id);
|
|
1031
1266
|
}
|
|
1267
|
+
setConversationPlannerChoice(conversationId, harness, model) {
|
|
1268
|
+
this.db
|
|
1269
|
+
.prepare("UPDATE conversations SET planner_harness = ?, planner_model = ? WHERE id = ?")
|
|
1270
|
+
.run(harness, model, conversationId);
|
|
1271
|
+
return this.readConversation(conversationId);
|
|
1272
|
+
}
|
|
1032
1273
|
/**
|
|
1033
1274
|
* The summary belongs to the conversation it compresses. It deliberately
|
|
1034
1275
|
* does not touch updated_at: writing it must not make the old chat active
|
|
@@ -1060,6 +1301,12 @@ export class ZelioDb {
|
|
|
1060
1301
|
summaryFrom: row.summary_from === null || row.summary_from === undefined
|
|
1061
1302
|
? null
|
|
1062
1303
|
: String(row.summary_from),
|
|
1304
|
+
plannerHarness: typeof row.planner_harness === "string" && row.planner_harness.trim()
|
|
1305
|
+
? row.planner_harness
|
|
1306
|
+
: null,
|
|
1307
|
+
plannerModel: typeof row.planner_model === "string" && row.planner_model.trim()
|
|
1308
|
+
? row.planner_model
|
|
1309
|
+
: null,
|
|
1063
1310
|
};
|
|
1064
1311
|
}
|
|
1065
1312
|
/**
|
|
@@ -1103,6 +1350,7 @@ export class ZelioDb {
|
|
|
1103
1350
|
resume_count: session.resumeCount ?? 0,
|
|
1104
1351
|
profile: session.profile ?? null,
|
|
1105
1352
|
harness: session.harness ?? null,
|
|
1353
|
+
model: session.model ?? null,
|
|
1106
1354
|
job_source: session.source ?? "ticket",
|
|
1107
1355
|
job_prompt: session.prompt ?? null,
|
|
1108
1356
|
job_system_prompt: session.systemPrompt ?? null,
|
|
@@ -1114,9 +1362,9 @@ export class ZelioDb {
|
|
|
1114
1362
|
this.db
|
|
1115
1363
|
.prepare(`INSERT INTO agent_runs (id, ticket_id, attempt, state, started_at, ended_at, exit_code,
|
|
1116
1364
|
git_status, git_diff, error, input_tokens, output_tokens, cost, workflow_stage, workflow,
|
|
1117
|
-
session_id, resume_count, profile, harness, job_source, job_prompt, job_system_prompt)
|
|
1118
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
1119
|
-
.run(run.id, run.ticket_id, run.attempt, run.state, run.started_at, null, null, null, null, null, null, null, null, run.workflow_stage, run.workflow ? JSON.stringify(run.workflow) : null, run.session_id, run.resume_count, run.profile, run.harness, run.job_source, run.job_prompt, run.job_system_prompt);
|
|
1365
|
+
session_id, resume_count, profile, harness, model, job_source, job_prompt, job_system_prompt)
|
|
1366
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
1367
|
+
.run(run.id, run.ticket_id, run.attempt, run.state, run.started_at, null, null, null, null, null, null, null, null, run.workflow_stage, run.workflow ? JSON.stringify(run.workflow) : null, run.session_id, run.resume_count, run.profile, run.harness, run.model, run.job_source, run.job_prompt, run.job_system_prompt);
|
|
1120
1368
|
return run;
|
|
1121
1369
|
}
|
|
1122
1370
|
finishAgentRun(id, input) {
|
|
@@ -1135,6 +1383,26 @@ export class ZelioDb {
|
|
|
1135
1383
|
.prepare("UPDATE agent_runs SET input_tokens = ?, output_tokens = ?, cost = ? WHERE id = ? AND state = 'running'")
|
|
1136
1384
|
.run(tokens.input, tokens.output, cost, id);
|
|
1137
1385
|
}
|
|
1386
|
+
/** Keep the latest measured duration of one check command; a later run replaces it. */
|
|
1387
|
+
recordCommandDuration(repo, command, durationMs) {
|
|
1388
|
+
this.db
|
|
1389
|
+
.prepare(`INSERT INTO command_durations (repo, command, duration_ms, measured_at)
|
|
1390
|
+
VALUES (?, ?, ?, ?)
|
|
1391
|
+
ON CONFLICT(repo, command) DO UPDATE SET
|
|
1392
|
+
duration_ms = excluded.duration_ms, measured_at = excluded.measured_at`)
|
|
1393
|
+
.run(repo ?? "", command, Math.max(0, Math.round(durationMs)), new Date().toISOString());
|
|
1394
|
+
}
|
|
1395
|
+
/** The last measured duration of each command that has one, in milliseconds. */
|
|
1396
|
+
commandDurations(repo, commands) {
|
|
1397
|
+
const found = new Map();
|
|
1398
|
+
const read = this.db.prepare("SELECT duration_ms FROM command_durations WHERE repo = ? AND command = ?");
|
|
1399
|
+
for (const command of new Set(commands)) {
|
|
1400
|
+
const row = read.get(repo ?? "", command);
|
|
1401
|
+
if (typeof row?.duration_ms === "number")
|
|
1402
|
+
found.set(command, row.duration_ms);
|
|
1403
|
+
}
|
|
1404
|
+
return found;
|
|
1405
|
+
}
|
|
1138
1406
|
recordCommandEvidence(id, evidence) {
|
|
1139
1407
|
this.db
|
|
1140
1408
|
.prepare("UPDATE agent_runs SET command_evidence = ? WHERE id = ? AND state = 'running'")
|
|
@@ -1194,6 +1462,7 @@ export class ZelioDb {
|
|
|
1194
1462
|
blocker_kind: to === "blocked" ? "decision" : null,
|
|
1195
1463
|
blocker_reason: to === "blocked" ? (report.reason ?? null) : null,
|
|
1196
1464
|
blocker_unblock: to === "blocked" ? (report.unblock ?? null) : null,
|
|
1465
|
+
blocker_action: null,
|
|
1197
1466
|
};
|
|
1198
1467
|
const comment = {
|
|
1199
1468
|
id: randomUUID(),
|
|
@@ -1216,7 +1485,7 @@ export class ZelioDb {
|
|
|
1216
1485
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
1217
1486
|
.run(comment.id, ticket.id, comment.type, text, comment.author, comment.blocker_kind, now, runId);
|
|
1218
1487
|
this.db
|
|
1219
|
-
.prepare(`UPDATE tickets SET state = ?, blocker_kind = ?, blocker_reason = ?, blocker_unblock = ?, updated_at = ? WHERE id = ?`)
|
|
1488
|
+
.prepare(`UPDATE tickets SET state = ?, blocker_kind = ?, blocker_reason = ?, blocker_unblock = ?, blocker_action = NULL, updated_at = ? WHERE id = ?`)
|
|
1220
1489
|
.run(next.state, next.blocker_kind, next.blocker_reason, next.blocker_unblock, now, ticket.id);
|
|
1221
1490
|
this.db.exec("COMMIT");
|
|
1222
1491
|
}
|
|
@@ -1343,6 +1612,25 @@ export class ZelioDb {
|
|
|
1343
1612
|
return null;
|
|
1344
1613
|
}
|
|
1345
1614
|
}
|
|
1615
|
+
listAreaNotes() {
|
|
1616
|
+
const rows = this.db
|
|
1617
|
+
.prepare("SELECT path, hash, head, note, written_at FROM area_notes ORDER BY path")
|
|
1618
|
+
.all();
|
|
1619
|
+
return rows.map((row) => ({
|
|
1620
|
+
path: String(row.path),
|
|
1621
|
+
hash: String(row.hash),
|
|
1622
|
+
head: row.head === null ? null : String(row.head),
|
|
1623
|
+
note: String(row.note),
|
|
1624
|
+
written_at: String(row.written_at),
|
|
1625
|
+
}));
|
|
1626
|
+
}
|
|
1627
|
+
saveAreaNote(note) {
|
|
1628
|
+
this.db
|
|
1629
|
+
.prepare(`INSERT INTO area_notes (path, hash, head, note, written_at) VALUES (?, ?, ?, ?, ?)
|
|
1630
|
+
ON CONFLICT(path) DO UPDATE SET hash = excluded.hash, head = excluded.head,
|
|
1631
|
+
note = excluded.note, written_at = excluded.written_at`)
|
|
1632
|
+
.run(note.path, note.hash, note.head, note.note, note.written_at);
|
|
1633
|
+
}
|
|
1346
1634
|
saveRepoIndex(index) {
|
|
1347
1635
|
this.db
|
|
1348
1636
|
.prepare(`INSERT INTO repo_index (id, head_sha, indexed_at, duration_ms, json) VALUES (1, ?, ?, ?, ?)
|
|
@@ -1350,17 +1638,29 @@ export class ZelioDb {
|
|
|
1350
1638
|
duration_ms = excluded.duration_ms, json = excluded.json`)
|
|
1351
1639
|
.run(index.head, index.indexed_at, index.duration_ms, JSON.stringify(index));
|
|
1352
1640
|
}
|
|
1353
|
-
/**
|
|
1354
|
-
|
|
1641
|
+
/**
|
|
1642
|
+
* One row per planner turn. Append-only: a turn is a fact that already ended.
|
|
1643
|
+
* `output` is what the model wrote, kept only for a turn that failed on it;
|
|
1644
|
+
* it stays out of `listPlannerTurns`, so the metrics payload does not carry it.
|
|
1645
|
+
*/
|
|
1646
|
+
recordPlannerTurn(turn, output = null) {
|
|
1355
1647
|
const row = { ...turn, id: randomUUID() };
|
|
1648
|
+
const kept = output === null || output.length <= MAX_PLANNER_OUTPUT_CHARS
|
|
1649
|
+
? output
|
|
1650
|
+
: output.slice(-MAX_PLANNER_OUTPUT_CHARS);
|
|
1356
1651
|
this.db
|
|
1357
1652
|
.prepare(`INSERT INTO planner_turns (id, conversation_id, kind, mode, ok, error, duration_ms,
|
|
1358
1653
|
index_ms, first_event_ms, harness_ms, tool_calls, tool_errors, tool_budget, capped,
|
|
1359
|
-
prompt_chars, output_chars, questions, cards, started_at)
|
|
1360
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
1361
|
-
.run(row.id, row.conversation_id, row.kind, row.mode, row.ok ? 1 : 0, row.error, row.duration_ms, row.index_ms, row.first_event_ms, row.harness_ms, row.tool_calls, row.tool_errors, row.tool_budget, row.capped, row.prompt_chars, row.output_chars, row.questions, row.cards, row.started_at);
|
|
1654
|
+
prompt_chars, output_chars, questions, cards, started_at, output)
|
|
1655
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
1656
|
+
.run(row.id, row.conversation_id, row.kind, row.mode, row.ok ? 1 : 0, row.error, row.duration_ms, row.index_ms, row.first_event_ms, row.harness_ms, row.tool_calls, row.tool_errors, row.tool_budget, row.capped, row.prompt_chars, row.output_chars, row.questions, row.cards, row.started_at, kept);
|
|
1362
1657
|
return row;
|
|
1363
1658
|
}
|
|
1659
|
+
/** What the model wrote on a failed turn, or null when nothing was kept. */
|
|
1660
|
+
plannerTurnOutput(id) {
|
|
1661
|
+
const row = this.db.prepare("SELECT output FROM planner_turns WHERE id = ?").get(id);
|
|
1662
|
+
return typeof row?.output === "string" ? row.output : null;
|
|
1663
|
+
}
|
|
1364
1664
|
/** Newest first. The reader only ever wants recent turns. */
|
|
1365
1665
|
listPlannerTurns(limit = 50) {
|
|
1366
1666
|
const rows = this.db
|
|
@@ -1395,9 +1695,29 @@ export class ZelioDb {
|
|
|
1395
1695
|
getBoardSettings() {
|
|
1396
1696
|
const maxAgents = this.metaValue("max_agents");
|
|
1397
1697
|
const plannerThinking = this.metaValue("planner_thinking");
|
|
1698
|
+
const testsFirstEnabled = this.metaValue("tests_first_enabled");
|
|
1699
|
+
const plannerChoiceEnabled = this.metaValue("planner_choice_enabled");
|
|
1700
|
+
const plannerHarness = this.metaValue("planner_harness");
|
|
1701
|
+
const plannerModel = this.metaValue("planner_model");
|
|
1702
|
+
const hiddenModels = this.metaValue("hidden_models");
|
|
1398
1703
|
return {
|
|
1399
1704
|
maxAgents: asMaxAgents(maxAgents) ?? DEFAULT_MAX_AGENTS,
|
|
1400
1705
|
plannerThinking: asPlannerThinking(plannerThinking) ?? DEFAULT_PLANNER_THINKING,
|
|
1706
|
+
testsFirstEnabled: testsFirstEnabled === "true"
|
|
1707
|
+
? true
|
|
1708
|
+
: testsFirstEnabled === "false"
|
|
1709
|
+
? false
|
|
1710
|
+
: DEFAULT_TESTS_FIRST_ENABLED,
|
|
1711
|
+
plannerChoiceEnabled: plannerChoiceEnabled === "true"
|
|
1712
|
+
? true
|
|
1713
|
+
: plannerChoiceEnabled === "false"
|
|
1714
|
+
? false
|
|
1715
|
+
: DEFAULT_PLANNER_CHOICE_ENABLED,
|
|
1716
|
+
...(plannerHarness ? { plannerHarness } : {}),
|
|
1717
|
+
...(plannerModel !== null ? { plannerModel } : {}),
|
|
1718
|
+
...(hiddenModels
|
|
1719
|
+
? { hiddenModels: JSON.parse(hiddenModels) }
|
|
1720
|
+
: {}),
|
|
1401
1721
|
};
|
|
1402
1722
|
}
|
|
1403
1723
|
setBoardSettings(patch) {
|
|
@@ -1407,6 +1727,18 @@ export class ZelioDb {
|
|
|
1407
1727
|
if (patch.plannerThinking !== undefined) {
|
|
1408
1728
|
this.writeMeta("planner_thinking", patch.plannerThinking);
|
|
1409
1729
|
}
|
|
1730
|
+
if (patch.testsFirstEnabled !== undefined) {
|
|
1731
|
+
this.writeMeta("tests_first_enabled", String(patch.testsFirstEnabled));
|
|
1732
|
+
}
|
|
1733
|
+
if (patch.plannerChoiceEnabled !== undefined) {
|
|
1734
|
+
this.writeMeta("planner_choice_enabled", String(patch.plannerChoiceEnabled));
|
|
1735
|
+
}
|
|
1736
|
+
if (patch.plannerHarness !== undefined)
|
|
1737
|
+
this.writeMeta("planner_harness", patch.plannerHarness);
|
|
1738
|
+
if (patch.plannerModel !== undefined)
|
|
1739
|
+
this.writeMeta("planner_model", patch.plannerModel);
|
|
1740
|
+
if (patch.hiddenModels !== undefined)
|
|
1741
|
+
this.writeMeta("hidden_models", JSON.stringify(patch.hiddenModels));
|
|
1410
1742
|
return this.getBoardSettings();
|
|
1411
1743
|
}
|
|
1412
1744
|
metaValue(key) {
|
|
@@ -1454,114 +1786,6 @@ export class ZelioDb {
|
|
|
1454
1786
|
.run(stage, JSON.stringify(workflow.checks), 1, workflow.notes, JSON.stringify(workflow.askFirst), new Date().toISOString());
|
|
1455
1787
|
return this.getStageWorkflow(stage);
|
|
1456
1788
|
}
|
|
1457
|
-
/** One row as the API sees it: evidence is JSON in the row, an array outside. */
|
|
1458
|
-
readSuggestion(row) {
|
|
1459
|
-
let evidence = [];
|
|
1460
|
-
try {
|
|
1461
|
-
const parsed = JSON.parse(String(row.evidence ?? "[]"));
|
|
1462
|
-
if (Array.isArray(parsed)) {
|
|
1463
|
-
evidence = parsed.filter((entry) => typeof entry === "string");
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
catch {
|
|
1467
|
-
evidence = [];
|
|
1468
|
-
}
|
|
1469
|
-
return {
|
|
1470
|
-
id: String(row.id),
|
|
1471
|
-
stage: row.stage,
|
|
1472
|
-
ticket_id: String(row.ticket_id),
|
|
1473
|
-
evidence,
|
|
1474
|
-
notes: String(row.notes ?? ""),
|
|
1475
|
-
created_at: String(row.created_at),
|
|
1476
|
-
applied_at: row.applied_at === null || row.applied_at === undefined ? null : String(row.applied_at),
|
|
1477
|
-
dismissed_at: row.dismissed_at === null || row.dismissed_at === undefined
|
|
1478
|
-
? null
|
|
1479
|
-
: String(row.dismissed_at),
|
|
1480
|
-
};
|
|
1481
|
-
}
|
|
1482
|
-
/**
|
|
1483
|
-
* A pending proposal. Duplicates are dropped: the same notes for the same
|
|
1484
|
-
* stage is one decision, however many runs reached it.
|
|
1485
|
-
*/
|
|
1486
|
-
addWorkflowSuggestion(input) {
|
|
1487
|
-
const notes = input.notes.trim();
|
|
1488
|
-
if (!notes)
|
|
1489
|
-
return null;
|
|
1490
|
-
const duplicate = this.db
|
|
1491
|
-
.prepare(`SELECT 1 FROM workflow_suggestions
|
|
1492
|
-
WHERE stage = ? AND notes = ? AND applied_at IS NULL AND dismissed_at IS NULL`)
|
|
1493
|
-
.get(input.stage, notes);
|
|
1494
|
-
if (duplicate)
|
|
1495
|
-
return null;
|
|
1496
|
-
const suggestion = {
|
|
1497
|
-
id: randomUUID(),
|
|
1498
|
-
stage: input.stage,
|
|
1499
|
-
ticket_id: input.ticket_id,
|
|
1500
|
-
evidence: input.evidence
|
|
1501
|
-
.map((entry) => entry.trim())
|
|
1502
|
-
.filter(Boolean)
|
|
1503
|
-
.slice(0, 12),
|
|
1504
|
-
notes,
|
|
1505
|
-
created_at: new Date().toISOString(),
|
|
1506
|
-
applied_at: null,
|
|
1507
|
-
dismissed_at: null,
|
|
1508
|
-
};
|
|
1509
|
-
this.db
|
|
1510
|
-
.prepare(`INSERT INTO workflow_suggestions
|
|
1511
|
-
(id, stage, ticket_id, evidence, notes, created_at, applied_at, dismissed_at)
|
|
1512
|
-
VALUES (?, ?, ?, ?, ?, ?, NULL, NULL)`)
|
|
1513
|
-
.run(suggestion.id, suggestion.stage, suggestion.ticket_id, JSON.stringify(suggestion.evidence), suggestion.notes, suggestion.created_at);
|
|
1514
|
-
this.emit({ type: "workflow_suggestion", suggestion });
|
|
1515
|
-
return suggestion;
|
|
1516
|
-
}
|
|
1517
|
-
/** Pending proposals for a stage, newest first. */
|
|
1518
|
-
listWorkflowSuggestions(stage) {
|
|
1519
|
-
const rows = this.db
|
|
1520
|
-
.prepare(`SELECT * FROM workflow_suggestions
|
|
1521
|
-
WHERE stage = ? AND applied_at IS NULL AND dismissed_at IS NULL
|
|
1522
|
-
ORDER BY created_at DESC`)
|
|
1523
|
-
.all(stage);
|
|
1524
|
-
return rows.map((row) => this.readSuggestion(row));
|
|
1525
|
-
}
|
|
1526
|
-
pendingSuggestion(id) {
|
|
1527
|
-
const row = this.db
|
|
1528
|
-
.prepare(`SELECT * FROM workflow_suggestions
|
|
1529
|
-
WHERE id = ? AND applied_at IS NULL AND dismissed_at IS NULL`)
|
|
1530
|
-
.get(id);
|
|
1531
|
-
return row ? this.readSuggestion(row) : null;
|
|
1532
|
-
}
|
|
1533
|
-
/**
|
|
1534
|
-
* Applies the notes to the stage, keeping checks and ask-first as they are.
|
|
1535
|
-
* A person applying a proposal is the only way it reaches future runs.
|
|
1536
|
-
*/
|
|
1537
|
-
applyWorkflowSuggestion(id) {
|
|
1538
|
-
const suggestion = this.pendingSuggestion(id);
|
|
1539
|
-
if (!suggestion)
|
|
1540
|
-
return null;
|
|
1541
|
-
const current = this.getStageWorkflow(suggestion.stage);
|
|
1542
|
-
const workflow = this.setStageWorkflow(suggestion.stage, {
|
|
1543
|
-
...current,
|
|
1544
|
-
notes: suggestion.notes,
|
|
1545
|
-
});
|
|
1546
|
-
this.db
|
|
1547
|
-
.prepare("UPDATE workflow_suggestions SET applied_at = ? WHERE id = ?")
|
|
1548
|
-
.run(new Date().toISOString(), id);
|
|
1549
|
-
return {
|
|
1550
|
-
suggestion: { ...suggestion, applied_at: new Date().toISOString() },
|
|
1551
|
-
workflow,
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
/** Refuses a proposal without touching the workflow. */
|
|
1555
|
-
dismissWorkflowSuggestion(id) {
|
|
1556
|
-
const suggestion = this.pendingSuggestion(id);
|
|
1557
|
-
if (!suggestion)
|
|
1558
|
-
return null;
|
|
1559
|
-
const dismissed_at = new Date().toISOString();
|
|
1560
|
-
this.db
|
|
1561
|
-
.prepare("UPDATE workflow_suggestions SET dismissed_at = ? WHERE id = ?")
|
|
1562
|
-
.run(dismissed_at, id);
|
|
1563
|
-
return { ...suggestion, dismissed_at };
|
|
1564
|
-
}
|
|
1565
1789
|
/** Tickets in a state where something is (or is about to be) running. */
|
|
1566
1790
|
runningTickets() {
|
|
1567
1791
|
const rows = this.db
|