@cardor/agent-harness-kit 2.3.1 → 2.5.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/README.md +21 -1
- package/dist/agent-templates/builder.md +4 -4
- package/dist/agent-templates/consultant.md +6 -3
- package/dist/agent-templates/explorer.md +3 -1
- package/dist/agent-templates/lead.md +4 -4
- package/dist/agent-templates/reviewer.md +5 -3
- package/dist/{chunk-URMVLD2S.js → chunk-LURM3C4M.js} +2 -2
- package/dist/{chunk-JTACLEGM.js → chunk-TWG3KVZQ.js} +73 -4
- package/dist/chunk-TWG3KVZQ.js.map +1 -0
- package/dist/cli.js +223 -12
- package/dist/cli.js.map +1 -1
- package/dist/{db-L3AADJF5.js → db-3B2W2EBA.js} +2 -2
- package/dist/{mysql-AUPKARWA.js → mysql-ZU3T7DWV.js} +3 -3
- package/dist/{postgres-BB4GY4PN.js → postgres-H5TLXDTW.js} +4 -4
- package/dist/postgres-H5TLXDTW.js.map +1 -0
- package/dist/skills/ahk-test/SKILL.md +61 -0
- package/dist/{sqlite-5OWKTUUZ.js → sqlite-UDXCFIEN.js} +4 -4
- package/dist/sqlite-UDXCFIEN.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-JTACLEGM.js.map +0 -1
- package/dist/postgres-BB4GY4PN.js.map +0 -1
- package/dist/sqlite-5OWKTUUZ.js.map +0 -1
- /package/dist/{chunk-URMVLD2S.js.map → chunk-LURM3C4M.js.map} +0 -0
- /package/dist/{db-L3AADJF5.js.map → db-3B2W2EBA.js.map} +0 -0
- /package/dist/{mysql-AUPKARWA.js.map → mysql-ZU3T7DWV.js.map} +0 -0
package/README.md
CHANGED
|
@@ -361,10 +361,30 @@ Reports three categories:
|
|
|
361
361
|
|
|
362
362
|
- **lib version** — compares installed version against the latest on npm. Shows `[✓]` if up to date, `[!]` if an update is available, or `[~]` if the registry could not be reached.
|
|
363
363
|
- **agent files** — checks only that a definition file exists for every role. Reports `[!]` with the file name if one is missing. The contents are never read, so **editing an agent file by hand is a fully supported state and is never reported** — customise the body, the description, or the restrictions freely and `ahk doctor` stays green.
|
|
364
|
-
- **harness skills** — checks that `ahk-ask`, `ahk-consultant`, `ahk-triage`, and `ahk-
|
|
364
|
+
- **harness skills** — checks that `ahk-ask`, `ahk-consultant`, `ahk-triage`, `ahk-review`, and `ahk-test` skills exist and match the bundled source. Reports `[!]` if missing or outdated.
|
|
365
365
|
|
|
366
366
|
Run `ahk build` to fix any reported issues.
|
|
367
367
|
|
|
368
|
+
### Bundled skills
|
|
369
|
+
|
|
370
|
+
The kit ships five lightweight skills that are materialized into every provider's skills directory on `init` and restored by `build`. Each skill is read-only instruction text — no MCP tools, no CLI commands, no database changes. They guide AI agents through focused workflows using only subagent invocations.
|
|
371
|
+
|
|
372
|
+
| Skill | Purpose | Limits |
|
|
373
|
+
|-------|---------|--------|
|
|
374
|
+
| `ahk-ask` | Answer codebase questions by reading relevant files and summarizing findings | Read-only; no writes, no MCP calls, no builder/reviewer |
|
|
375
|
+
| `ahk-consultant` | Give technical advice on approaches, designs, or trade-offs before implementation | Advisory only; never writes code or creates tasks |
|
|
376
|
+
| `ahk-triage` | Diagnose bugs and unexpected behavior with deep diagnostic analysis | Diagnostic only; does not fix the bug itself |
|
|
377
|
+
| `ahk-review` | Preview a code review against ticket/objective alignment with semantic analysis | Review only; does not modify code |
|
|
378
|
+
| `ahk-test` | Design, write, and run behavior-focused tests for an objective or existing code | Test files only; production is READ-ONLY unless explicitly authorized; NO harness MCP calls |
|
|
379
|
+
|
|
380
|
+
Invocation example for `ahk-test`:
|
|
381
|
+
|
|
382
|
+
```text
|
|
383
|
+
Use the ahk-test skill to create tests for toLibraryListBody. all must send movie and series; never anime.
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
All skills follow the same contract: they invoke Explorer, Builder, or Reviewer as subagents with bounded instructions, never call harness MCP tools directly, and never create or modify harness tasks.
|
|
387
|
+
|
|
368
388
|
---
|
|
369
389
|
|
|
370
390
|
### `ahk sync`
|
|
@@ -4,7 +4,7 @@ description: >
|
|
|
4
4
|
Use this agent to implement code changes for a task that has already been planned by lead
|
|
5
5
|
and analyzed by explorer. The builder writes, edits, and creates files based on the plan
|
|
6
6
|
and the explorer's analysis. Invoke only after the explorer has completed its action.
|
|
7
|
-
Never invoke without a
|
|
7
|
+
Never invoke without a canonical handoff addressed to builder.
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
# Builder Agent — {{projectName}}
|
|
@@ -73,13 +73,13 @@ If you touched 5 files and made 12 tool calls across the session, every one of t
|
|
|
73
73
|
|
|
74
74
|
## Workflow
|
|
75
75
|
|
|
76
|
-
### 1. Read the
|
|
76
|
+
### 1. Read the canonical handoff
|
|
77
77
|
|
|
78
78
|
```
|
|
79
|
-
actions.get(taskId)
|
|
79
|
+
actions.handoff.get(taskId, recipient: 'builder')
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
Start from the handoff. If it is not found, record a blocker; do not fall back to the full task history. If a named detail needs checking, navigate narrowly with `actions.list`, `actions.get_by_id`, then `actions.sections.get`. Reserve `actions.get(taskId)` for audit or diagnosis only.
|
|
83
83
|
|
|
84
84
|
### 2. Register your action
|
|
85
85
|
|
|
@@ -3,7 +3,7 @@ name: consultant
|
|
|
3
3
|
description: >
|
|
4
4
|
Technical advisor agent for {{projectName}}. Runs after the explorer and before the builder.
|
|
5
5
|
Provides structured advisory — patterns, best practices, warnings, and risks — written
|
|
6
|
-
directly to the harness
|
|
6
|
+
directly to the harness through a canonical builder handoff. Never writes code.
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# Consultant Agent — {{projectName}}
|
|
@@ -56,7 +56,7 @@ Return structured plain text (not written to harness) with these sections:
|
|
|
56
56
|
|
|
57
57
|
## Responsibilities
|
|
58
58
|
|
|
59
|
-
- Read the explorer's output
|
|
59
|
+
- Read the explorer's output through compact action and section reads
|
|
60
60
|
- Analyse the relevant code sections identified by the explorer
|
|
61
61
|
- Produce a structured advisory covering: patterns to follow, pitfalls to avoid, best practices, risks
|
|
62
62
|
- Record your advisory directly in the harness so the builder reads it without lead filtering
|
|
@@ -68,7 +68,9 @@ Return structured plain text (not written to harness) with these sections:
|
|
|
68
68
|
### 1. Read context
|
|
69
69
|
|
|
70
70
|
```
|
|
71
|
-
actions.
|
|
71
|
+
actions.list(taskId)
|
|
72
|
+
→ actions.get_by_id(actionId)
|
|
73
|
+
→ actions.sections.get(sectionId)
|
|
72
74
|
```
|
|
73
75
|
|
|
74
76
|
### 2. Analyse
|
|
@@ -84,6 +86,7 @@ Read the files the explorer mapped. Focus on:
|
|
|
84
86
|
```
|
|
85
87
|
actions.start(taskId, 'consultant') → save actionId
|
|
86
88
|
actions.write(actionId, 'result', '<your structured advisory>')
|
|
89
|
+
actions.handoff.write(actionId, recipient: 'builder', ...)
|
|
87
90
|
```
|
|
88
91
|
|
|
89
92
|
Structure your advisory with clear headings:
|
|
@@ -57,7 +57,9 @@ Example flush after a few calls:
|
|
|
57
57
|
### 1. Read the lead's plan
|
|
58
58
|
|
|
59
59
|
```
|
|
60
|
-
actions.
|
|
60
|
+
actions.list(taskId, agent: 'lead', status: 'completed')
|
|
61
|
+
→ actions.get_by_id(actionId)
|
|
62
|
+
→ actions.sections.get(sectionId)
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
Understand exactly what you need to map before reading anything.
|
|
@@ -95,7 +95,7 @@ These calls are **not optional**. The dashboard cannot display what you do not r
|
|
|
95
95
|
|
|
96
96
|
### Log every tool call you make
|
|
97
97
|
|
|
98
|
-
`actions.record_tool` is **batch-only** — it takes an array of calls, never a single bespoke call. As you work, accumulate the tool invocations you make (Bash, tasks.get, tasks.claim, actions.
|
|
98
|
+
`actions.record_tool` is **batch-only** — it takes an array of calls, never a single bespoke call. As you work, accumulate the tool invocations you make (Bash, tasks.get, tasks.claim, actions.list) and flush them periodically — every few calls, or at a natural checkpoint — via:
|
|
99
99
|
|
|
100
100
|
```
|
|
101
101
|
actions.record_tool(actionId, calls: [
|
|
@@ -107,7 +107,7 @@ actions.record_tool(actionId, calls: [
|
|
|
107
107
|
Even a single tool call must go through this array shape — a one-element array, never a bespoke single-call form.
|
|
108
108
|
|
|
109
109
|
Example flush after a few calls:
|
|
110
|
-
- `actions.record_tool(actionId, calls: [{ toolName: 'Bash', argsJson: 'bash health.sh', resultSummary: 'verify codebase health before making changes' }, { toolName: 'tasks.get', argsJson: 'pending', resultSummary: 'find next task to claim' }, { toolName: 'actions.
|
|
110
|
+
- `actions.record_tool(actionId, calls: [{ toolName: 'Bash', argsJson: 'bash health.sh', resultSummary: 'verify codebase health before making changes' }, { toolName: 'tasks.get', argsJson: 'pending', resultSummary: 'find next task to claim' }, { toolName: 'actions.list', argsJson: 'taskId=123', resultSummary: 'inspect the compact action index' }])`
|
|
111
111
|
|
|
112
112
|
**Log every call, batched.** This applies from the moment you have an `actionId` (after step 3 below) — flush at each phase boundary rather than round-tripping once per individual tool use, and never let calls go unrecorded by the time you complete the action.
|
|
113
113
|
|
|
@@ -218,7 +218,7 @@ Record it:
|
|
|
218
218
|
actions.write(actionId, 'result', '<your structured plan>')
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
-
Format your plan clearly
|
|
221
|
+
Format your plan clearly and write a canonical handoff for the next recipient.
|
|
222
222
|
|
|
223
223
|
### 6. Complete your action
|
|
224
224
|
|
|
@@ -232,7 +232,7 @@ Invoke: **Explorer** → **Consultant** (conditional) → **Builder** → **Revi
|
|
|
232
232
|
|
|
233
233
|
After each agent completes, read their output:
|
|
234
234
|
```
|
|
235
|
-
actions.
|
|
235
|
+
actions.list(taskId) → actions.get_by_id(actionId) → actions.sections.get(sectionId)
|
|
236
236
|
```
|
|
237
237
|
|
|
238
238
|
**Invoke the Consultant when ANY of these are true:**
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: reviewer
|
|
3
3
|
description: >
|
|
4
4
|
Use this agent to verify that a completed implementation meets all acceptance criteria
|
|
5
|
-
for the current task. The reviewer reads the
|
|
5
|
+
for the current task. The reviewer reads the builder's compact action record, checks the builder's
|
|
6
6
|
changes against each criterion, runs the health check, and either approves or blocks
|
|
7
7
|
with specific, actionable feedback. Invoke only after the builder has completed its action.
|
|
8
8
|
---
|
|
@@ -55,10 +55,12 @@ If the task has 3 criteria, you must make exactly 3 `tasks.acceptance.update` ca
|
|
|
55
55
|
|
|
56
56
|
## Workflow
|
|
57
57
|
|
|
58
|
-
### 1. Read the
|
|
58
|
+
### 1. Read the builder record
|
|
59
59
|
|
|
60
60
|
```
|
|
61
|
-
actions.
|
|
61
|
+
actions.list(taskId, agent: 'builder')
|
|
62
|
+
→ actions.get_by_id(actionId)
|
|
63
|
+
→ actions.sections.get(sectionId)
|
|
62
64
|
```
|
|
63
65
|
|
|
64
66
|
Read in order:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resetAutoincrementSequences
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TWG3KVZQ.js";
|
|
4
4
|
|
|
5
5
|
// src/core/drivers/migrate-actions.ts
|
|
6
6
|
var OLD_SUFFIX = "_old_v2migration";
|
|
@@ -144,4 +144,4 @@ async function applySchema(driver, dbType, schemaSql) {
|
|
|
144
144
|
export {
|
|
145
145
|
migrateActionsToIntegerIds
|
|
146
146
|
};
|
|
147
|
-
//# sourceMappingURL=chunk-
|
|
147
|
+
//# sourceMappingURL=chunk-LURM3C4M.js.map
|
|
@@ -39,6 +39,33 @@ var ActionRepository = class {
|
|
|
39
39
|
[taskId]
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
|
+
/** Compact newest-first index used by actions.list. The cursor is the last
|
|
43
|
+
* row from the previous page, so it remains stable when new actions arrive. */
|
|
44
|
+
async listForTask(taskId, options) {
|
|
45
|
+
const where = ["a.task_id = ?"];
|
|
46
|
+
const params = [taskId];
|
|
47
|
+
if (options.agent) {
|
|
48
|
+
where.push("a.agent = ?");
|
|
49
|
+
params.push(options.agent);
|
|
50
|
+
}
|
|
51
|
+
if (options.status) {
|
|
52
|
+
where.push("a.status = ?");
|
|
53
|
+
params.push(options.status);
|
|
54
|
+
}
|
|
55
|
+
if (options.cursor) {
|
|
56
|
+
where.push("(a.created_at < ? OR (a.created_at = ? AND a.id < ?))");
|
|
57
|
+
params.push(options.cursor.createdAt, options.cursor.createdAt, options.cursor.id);
|
|
58
|
+
}
|
|
59
|
+
params.push(options.limit);
|
|
60
|
+
return this.driver.query(
|
|
61
|
+
`SELECT a.*, COUNT(s.id) AS section_count
|
|
62
|
+
FROM actions a LEFT JOIN action_sections s ON s.action_id = a.id
|
|
63
|
+
WHERE ${where.join(" AND ")}
|
|
64
|
+
GROUP BY a.id, a.task_id, a.agent, a.status, a.created_at, a.completed_at, a.summary
|
|
65
|
+
ORDER BY a.created_at DESC, a.id DESC LIMIT ?`,
|
|
66
|
+
params
|
|
67
|
+
);
|
|
68
|
+
}
|
|
42
69
|
async getAll() {
|
|
43
70
|
return this.driver.query(`SELECT * FROM actions ORDER BY created_at`);
|
|
44
71
|
}
|
|
@@ -66,6 +93,36 @@ var ActionRepository = class {
|
|
|
66
93
|
[actionId]
|
|
67
94
|
);
|
|
68
95
|
}
|
|
96
|
+
async getSectionById(sectionId) {
|
|
97
|
+
return this.driver.queryOne(`SELECT * FROM action_sections WHERE id = ?`, [sectionId]);
|
|
98
|
+
}
|
|
99
|
+
async listSections(actionId, options) {
|
|
100
|
+
const where = ["action_id = ?"];
|
|
101
|
+
const params = [actionId];
|
|
102
|
+
if (options.types?.length) {
|
|
103
|
+
where.push(`section_type IN (${options.types.map(() => "?").join(", ")})`);
|
|
104
|
+
params.push(...options.types);
|
|
105
|
+
}
|
|
106
|
+
if (options.cursor !== void 0) {
|
|
107
|
+
where.push("id < ?");
|
|
108
|
+
params.push(options.cursor);
|
|
109
|
+
}
|
|
110
|
+
params.push(options.limit);
|
|
111
|
+
return this.driver.query(
|
|
112
|
+
`SELECT id, action_id, section_type, LENGTH(content) AS chars, created_at
|
|
113
|
+
FROM action_sections WHERE ${where.join(" AND ")} ORDER BY id DESC LIMIT ?`,
|
|
114
|
+
params
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
async getCompletedHandoffSections(taskId) {
|
|
118
|
+
return this.driver.query(
|
|
119
|
+
`SELECT s.*, a.agent, a.completed_at
|
|
120
|
+
FROM action_sections s JOIN actions a ON a.id = s.action_id
|
|
121
|
+
WHERE a.task_id = ? AND a.status = 'completed' AND s.section_type = 'handoff'
|
|
122
|
+
ORDER BY s.created_at DESC, s.id DESC`,
|
|
123
|
+
[taskId]
|
|
124
|
+
);
|
|
125
|
+
}
|
|
69
126
|
async getAllSections() {
|
|
70
127
|
return this.driver.query(`SELECT * FROM action_sections ORDER BY created_at`);
|
|
71
128
|
}
|
|
@@ -492,9 +549,21 @@ var HarnessDB = class {
|
|
|
492
549
|
async getActionsForTask(taskId) {
|
|
493
550
|
return this.actions.getForTask(taskId);
|
|
494
551
|
}
|
|
552
|
+
async listActionsForTask(taskId, options) {
|
|
553
|
+
return this.actions.listForTask(taskId, options);
|
|
554
|
+
}
|
|
495
555
|
async getActionSections(actionId) {
|
|
496
556
|
return this.actions.getSections(actionId);
|
|
497
557
|
}
|
|
558
|
+
async getActionSection(sectionId) {
|
|
559
|
+
return this.actions.getSectionById(sectionId);
|
|
560
|
+
}
|
|
561
|
+
async listActionSections(actionId, options) {
|
|
562
|
+
return this.actions.listSections(actionId, options);
|
|
563
|
+
}
|
|
564
|
+
async getCompletedHandoffSections(taskId) {
|
|
565
|
+
return this.actions.getCompletedHandoffSections(taskId);
|
|
566
|
+
}
|
|
498
567
|
/** Batch-only (task #74) — records N files in one atomic transaction. There
|
|
499
568
|
* is no single-entry variant; callers pass a one-element array to log a
|
|
500
569
|
* single file. Mirrors the driver.transaction() pattern from claimTask()
|
|
@@ -807,13 +876,13 @@ async function openDB(config, cwd, homeDir = homedir()) {
|
|
|
807
876
|
const dbConfig = config.database;
|
|
808
877
|
let driver;
|
|
809
878
|
if (dbConfig.type === "postgres") {
|
|
810
|
-
const { PostgresDriver } = await import("./postgres-
|
|
879
|
+
const { PostgresDriver } = await import("./postgres-H5TLXDTW.js");
|
|
811
880
|
driver = new PostgresDriver(dbConfig);
|
|
812
881
|
} else if (dbConfig.type === "mysql") {
|
|
813
|
-
const { MySQLDriver } = await import("./mysql-
|
|
882
|
+
const { MySQLDriver } = await import("./mysql-ZU3T7DWV.js");
|
|
814
883
|
driver = new MySQLDriver(dbConfig);
|
|
815
884
|
} else {
|
|
816
|
-
const { SQLiteDriver } = await import("./sqlite-
|
|
885
|
+
const { SQLiteDriver } = await import("./sqlite-UDXCFIEN.js");
|
|
817
886
|
if (dbConfig.type !== "sqlite") {
|
|
818
887
|
throw new Error("Invalid database type");
|
|
819
888
|
}
|
|
@@ -860,4 +929,4 @@ export {
|
|
|
860
929
|
readStorageStateFile,
|
|
861
930
|
openDB
|
|
862
931
|
};
|
|
863
|
-
//# sourceMappingURL=chunk-
|
|
932
|
+
//# sourceMappingURL=chunk-TWG3KVZQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/db.ts","../src/core/repositories/ActionRepository.ts","../src/core/repositories/StatsRepository.ts","../src/core/repositories/TaskRepository.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { dirname, join, resolve } from 'node:path'\n\nimport { ActionRepository } from './repositories/ActionRepository'\nimport { StatsRepository } from './repositories/StatsRepository'\nimport { TaskRepository } from './repositories/TaskRepository'\n\nimport type { DBDriver } from './drivers/types'\nimport type {\n ActionFileRow,\n ActionRow,\n ActionSectionRow,\n ActionToolRow,\n AgentName,\n HarnessConfig,\n StorageState,\n TaskAcceptanceRow,\n TaskRow,\n TaskStatus,\n} from '@/types'\n\n/** Full relational export of every table — used by `ahk migrate storage` and\n * `ahk export --json`. MUST include all 6 tables (tasks, task_acceptance,\n * actions, action_sections, action_files, action_tools); omitting any of\n * them silently drops user data during a migration. */\nexport interface FullExport {\n tasks: TaskRow[]\n taskAcceptance: TaskAcceptanceRow[]\n actions: ActionRow[]\n sections: ActionSectionRow[]\n actionFiles: ActionFileRow[]\n actionTools: ActionToolRow[]\n}\n\n/** Tables with an integer autoincrement/serial primary key, in FK-safe\n * insertion order (parents before children). Since task #73, `actions.id`\n * is a driver-generated autoincrement INTEGER (previously an\n * application-generated UUID/TEXT id, which is why it used to be excluded\n * from this list) — see src/core/drivers/migrate-actions.ts for the\n * one-time migration that upgrades a pre-existing DB in place. */\nconst AUTOINCREMENT_TABLES = ['tasks', 'task_acceptance', 'actions', 'action_sections', 'action_files', 'action_tools'] as const\n\n/** Full insertion order across all 6 tables, respecting FK constraints\n * (parent before child): tasks -> task_acceptance -> actions ->\n * action_sections/action_files/action_tools. */\nconst TABLE_INSERT_ORDER = ['tasks', 'task_acceptance', 'actions', 'action_sections', 'action_files', 'action_tools'] as const\n\n/** Reverse of TABLE_INSERT_ORDER — used to TRUNCATE a non-empty destination\n * safely (children before parents) when `--force` is used. */\nconst TABLE_DELETE_ORDER = [...TABLE_INSERT_ORDER].reverse()\n\n// ─── Global storage path resolution ────────────────────────────────────────\n\n/** Default relative sqlite path used whenever `LocalStorageConfig.sqlitePath`\n * is omitted, and as the fallback filename component for `scope: 'global'`\n * (which never reads a configured path at all — see resolveSqlitePath()).\n * Centralized here (task #56) to stop the literal '.harness/harness.db'\n * from drifting across config.ts/templates.ts/tests. */\nexport const DEFAULT_SQLITE_PATH = '.harness/harness.db'\n\n/** Default relative current.md fallback path, used as the fallback filename\n * component whenever a caller needs \"the local markdown path\" for a scope\n * that ISN'T `config.storage`'s own current scope — `markdownFallback.path`\n * only exists on `LocalStorageConfig`, so there's no field to read it from\n * when `config.storage.scope === 'global'`. See `defaultMarkdownPathForConfig`\n * usage in src/commands/migrate-storage.ts. */\nexport const DEFAULT_MARKDOWN_PATH = '.harness/current.md'\n\n/** Resolves the directory used for 'global' scope storage: ~/.harness/dbs/<projectId>/\n * Uses os.homedir() (not $HOME env var) for portability. Callers are\n * responsible for creating the directory (mkdirSync recursive) before use. */\nexport function resolveGlobalStorageDir(config: HarnessConfig, homeDir: string = homedir()): string {\n return join(homeDir, '.harness', 'dbs', config.storage.projectId)\n}\n\n// ─── DB class ─────────────────────────────────────────────────────────────────\n\nexport class HarnessDB {\n readonly tasks: TaskRepository\n readonly actions: ActionRepository\n readonly stats: StatsRepository\n private driver: DBDriver\n private config: HarnessConfig\n /** Overridable home directory, used to keep 'global' scope tests off the real $HOME. */\n private homeDir: string\n\n constructor(driver: DBDriver, config: HarnessConfig, homeDir: string = homedir()) {\n this.driver = driver\n this.config = config\n this.homeDir = homeDir\n this.tasks = new TaskRepository(driver)\n this.actions = new ActionRepository(driver)\n this.stats = new StatsRepository(driver)\n }\n\n // ─── Tasks (public facade — delegates to TaskRepository) ──────────────────\n\n async addTask(params: {\n slug: string\n title: string\n description?: string\n acceptance?: string[]\n }): Promise<TaskRow> {\n const taskId = await this.tasks.add({\n slug: params.slug,\n title: params.title,\n description: params.description,\n })\n if (params.acceptance?.length) {\n await this.tasks.addAcceptance(taskId, params.acceptance)\n }\n await this.regenerateCurrentMd()\n return (await this.tasks.getById(taskId))!\n }\n\n async getTasks(status?: TaskStatus, includeArchived = false): Promise<TaskRow[]> {\n return this.tasks.getAll(status, includeArchived)\n }\n\n async getTaskById(id: number): Promise<TaskRow | null> {\n return this.tasks.getById(id)\n }\n\n async getTaskBySlug(slug: string): Promise<TaskRow | null> {\n return this.tasks.getBySlug(slug)\n }\n\n async getTaskAcceptance(taskId: number): Promise<TaskAcceptanceRow[]> {\n return this.tasks.getAcceptance(taskId)\n }\n\n async updateTaskStatus(idOrSlug: number | string, status: TaskStatus): Promise<TaskRow> {\n const now = new Date().toISOString()\n const task =\n typeof idOrSlug === 'number'\n ? await this.tasks.getById(idOrSlug)\n : await this.tasks.getBySlug(idOrSlug)\n if (!task) throw new Error(`Task not found: ${idOrSlug}`)\n\n if (status === 'in_progress' && !task.started_at) {\n await this.tasks.setStatus(task.id, status, { started_at: now })\n } else if (status === 'done') {\n await this.tasks.setStatus(task.id, status, { completed_at: now })\n } else {\n await this.tasks.setStatus(task.id, status)\n }\n\n await this.regenerateCurrentMd()\n return (await this.tasks.getById(task.id))!\n }\n\n async claimTask(id: number, agent: string): Promise<TaskRow | null> {\n const now = new Date().toISOString()\n return this.driver.transaction(async (tx) => {\n // need to create a new TaskRepository instance bound to the transaction\n const txTasks = new TaskRepository(tx)\n const changed = await txTasks.claim(id, agent, now)\n if (!changed) return null\n const task = await txTasks.getById(id)\n if (!task || task.status !== 'in_progress' || task.assigned_to !== agent) return null\n await this.regenerateCurrentMd()\n return task\n })\n }\n\n async markAcceptanceMet(criterionId: number): Promise<void> {\n return this.tasks.markAcceptanceMet(criterionId)\n }\n\n async updateTask(id: number, params: { title?: string; description?: string | null; slug?: string }): Promise<TaskRow> {\n await this.tasks.update(id, params)\n await this.regenerateCurrentMd()\n return (await this.tasks.getById(id))!\n }\n\n async updateTaskAcceptance(taskId: number, criteria: string[]): Promise<void> {\n await this.tasks.replaceAcceptance(taskId, criteria)\n await this.regenerateCurrentMd()\n }\n\n async archiveTask(id: number): Promise<TaskRow> {\n await this.tasks.archive(id)\n await this.regenerateCurrentMd()\n return (await this.tasks.getById(id))!\n }\n\n async unarchiveTask(id: number): Promise<TaskRow> {\n await this.tasks.unarchive(id)\n await this.regenerateCurrentMd()\n return (await this.tasks.getById(id))!\n }\n\n async getArchivedTasks(): Promise<TaskRow[]> {\n return this.tasks.getArchived()\n }\n\n async getStatusSummary(): Promise<{ status: string; total: number }[]> {\n return this.tasks.getStatusSummary()\n }\n\n // ─── Actions (public facade — delegates to ActionRepository) ──────────────\n\n async startAction(taskId: number, agent: AgentName): Promise<ActionRow> {\n const now = new Date().toISOString()\n const id = await this.actions.create(taskId, agent, now)\n await this.regenerateCurrentMd()\n return (await this.actions.getById(id))!\n }\n\n async writeSection(actionId: number, sectionType: string, content: string): Promise<void> {\n const now = new Date().toISOString()\n await this.actions.addSection(actionId, sectionType, content, now)\n await this.regenerateCurrentMd()\n }\n\n async completeAction(actionId: number, summary: string): Promise<ActionRow> {\n const now = new Date().toISOString()\n await this.actions.complete(actionId, summary, now)\n await this.regenerateCurrentMd()\n return (await this.actions.getById(actionId))!\n }\n\n async closeOrphanedActions(taskId: number): Promise<number> {\n const now = new Date().toISOString()\n return this.actions.closeOrphaned(taskId, now)\n }\n\n async getAction(actionId: number): Promise<ActionRow | null> {\n return this.actions.getById(actionId)\n }\n\n async getActionsForTask(taskId: number): Promise<ActionRow[]> {\n return this.actions.getForTask(taskId)\n }\n\n async listActionsForTask(\n taskId: number,\n options: {\n agent?: AgentName\n status?: ActionRow['status']\n cursor?: { createdAt: string; id: number }\n limit: number\n },\n ) {\n return this.actions.listForTask(taskId, options)\n }\n\n async getActionSections(actionId: number): Promise<ActionSectionRow[]> {\n return this.actions.getSections(actionId)\n }\n\n async getActionSection(sectionId: number): Promise<ActionSectionRow | null> {\n return this.actions.getSectionById(sectionId)\n }\n\n async listActionSections(actionId: number, options: { types?: string[]; cursor?: number; limit: number }) {\n return this.actions.listSections(actionId, options)\n }\n\n async getCompletedHandoffSections(taskId: number) {\n return this.actions.getCompletedHandoffSections(taskId)\n }\n\n /** Batch-only (task #74) — records N files in one atomic transaction. There\n * is no single-entry variant; callers pass a one-element array to log a\n * single file. Mirrors the driver.transaction() pattern from claimTask()\n * above: a fresh ActionRepository is bound to the tx driver so every\n * insert in the loop participates in the same transaction and any failure\n * rolls back the whole batch. Returns the number of files recorded. */\n async recordFiles(\n actionId: number,\n files: Array<{ filePath: string; operation: ActionFileRow['operation']; notes?: string }>,\n ): Promise<number> {\n return this.driver.transaction(async (tx) => {\n const txActions = new ActionRepository(tx)\n for (const f of files) {\n await txActions.addFile(actionId, f.filePath, f.operation, f.notes ?? null)\n }\n return files.length\n })\n }\n\n /** Batch-only (task #74) — records N tool calls in one atomic transaction.\n * See recordFiles() above for the pattern; a one-element array is the\n * only way to log a single tool call. Returns the number of calls\n * recorded. */\n async recordTools(\n actionId: number,\n calls: Array<{ toolName: string; argsJson?: string; resultSummary?: string }>,\n ): Promise<number> {\n const now = new Date().toISOString()\n return this.driver.transaction(async (tx) => {\n const txActions = new ActionRepository(tx)\n for (const c of calls) {\n await txActions.addTool(actionId, c.toolName, c.argsJson ?? null, c.resultSummary ?? null, now)\n }\n return calls.length\n })\n }\n\n async getFilesForTask(taskId: number): Promise<(ActionFileRow & { agent: AgentName })[]> {\n return this.actions.getFilesForTask(taskId)\n }\n\n async getTopTools(limit = 10): Promise<{ tool_name: string; uses: number }[]> {\n return this.actions.getTopTools(limit)\n }\n\n // ─── current.md fallback ──────────────────────────────────────────────────\n\n async regenerateCurrentMd(): Promise<void> {\n if (!this.config.storage.markdownFallback.enabled) return\n\n const mdPath =\n this.config.storage.scope === 'global'\n ? join(resolveGlobalStorageDir(this.config, this.homeDir), 'current.md')\n : resolve(this.config.storage.markdownFallback.path)\n mkdirSync(dirname(mdPath), { recursive: true })\n\n const inProgress = await this.tasks.getAll('in_progress')\n const now = new Date().toISOString()\n\n let md = `<!-- AUTO-GENERATED by agent-harness-kit — DO NOT EDIT MANUALLY -->\\n`\n md += `<!-- Last updated: ${now} -->\\n\\n`\n md += `# Current Session\\n\\n`\n\n if (inProgress.length === 0) {\n md += `## No tasks in progress\\n\\n`\n const pending = await this.tasks.getAll('pending')\n if (pending.length > 0) {\n md += `### Next pending tasks\\n`\n for (const t of pending.slice(0, 5)) {\n md += `- **#${t.id}** ${t.title} (\\`${t.slug}\\`)\\n`\n }\n }\n } else {\n for (const task of inProgress) {\n md += `## Active Task\\n`\n md += `- **ID:** ${task.id}\\n`\n md += `- **Slug:** ${task.slug}\\n`\n md += `- **Status:** ${task.status}\\n`\n md += `- **Started:** ${task.started_at ?? 'unknown'}\\n\\n`\n\n const taskActions = await this.actions.getForTask(task.id)\n if (taskActions.length > 0) {\n md += `## Actions this session\\n`\n md += `| Agent | Status | Summary | Started |\\n`\n md += `|----------|-------------|----------------------------------|-------------|\\n`\n for (const a of taskActions) {\n const started = a.created_at.slice(11, 16)\n const summary = (a.summary ?? '').slice(0, 34).padEnd(34)\n md += `| ${a.agent.padEnd(8)} | ${a.status.padEnd(11)} | ${summary} | ${started} |\\n`\n }\n md += `\\n`\n }\n\n const acceptance = await this.tasks.getAcceptance(task.id)\n if (acceptance.length > 0) {\n md += `## Acceptance Criteria\\n`\n for (const a of acceptance) {\n md += `- [${a.met ? 'x' : ' '}] ${a.criterion}\\n`\n }\n md += `\\n`\n }\n }\n }\n\n writeFileSync(mdPath, md, 'utf8')\n }\n\n // ─── Raw query escape hatch ───────────────────────────────────────────────\n\n async queryRaw<T = Record<string, unknown>>(sql: string, ...params: unknown[]): Promise<T[]> {\n return this.driver.query<T>(sql, params)\n }\n\n // ─── Export helpers ───────────────────────────────────────────────────────\n\n /** Full relational export of ALL 6 tables (tasks, task_acceptance, actions,\n * action_sections, action_files, action_tools). Extended for task #47 —\n * the previous version (tasks/actions/sections only) silently dropped\n * acceptance criteria and file/tool records on export/migrate. */\n async exportJson(): Promise<FullExport> {\n return {\n tasks: await this.tasks.getAll(undefined, true),\n taskAcceptance: await this.tasks.getAllAcceptance(),\n actions: await this.actions.getAll(),\n sections: await this.actions.getAllSections(),\n actionFiles: await this.actions.getAllFiles(),\n actionTools: await this.actions.getAllTools(),\n }\n }\n\n /** Row counts for all 6 tables against THIS db's driver — used to decide\n * whether a destination is \"empty\" (safe to import into directly) before\n * a migration. Counts are queried directly (COUNT(*)), never inferred\n * from storage-state.json. */\n async getRowCounts(): Promise<Record<(typeof TABLE_INSERT_ORDER)[number], number>> {\n return getRowCounts(this.driver)\n }\n\n /** Imports a full export into THIS db's driver — see standalone\n * `importFullExport()` for the transactional/rollback/sequence-reset\n * guarantees. `dbType` must match `this.config.database.type`. */\n async importFullExport(data: FullExport, dbType: 'sqlite' | 'postgres' | 'mysql', opts?: { truncateFirst: boolean }): Promise<void> {\n return importFullExport(this.driver, data, dbType, opts)\n }\n\n async reconnect(): Promise<void> {\n await this.driver.reconnect()\n }\n\n async close(): Promise<void> {\n await this.driver.close()\n }\n\n // ─── feature_list.json sync ───────────────────────────────────────────────\n\n async syncFromFeatureList(\n seeds: { slug: string; title: string; description?: string; acceptance?: string[] }[],\n ): Promise<{ added: number; skipped: number }> {\n let added = 0\n let skipped = 0\n for (const t of seeds) {\n if (await this.tasks.getBySlug(t.slug)) {\n skipped++\n continue\n }\n await this.addTask(t)\n added++\n }\n return { added, skipped }\n }\n\n async writeFeatureList(cwd: string): Promise<void> {\n const allTasks = await this.tasks.getAll(undefined, true)\n const list = await Promise.all(\n allTasks.map(async (t) => ({\n slug: t.slug,\n title: t.title,\n description: t.description ?? undefined,\n acceptance: (await this.tasks.getAcceptance(t.id)).map((a) => a.criterion),\n status: t.status,\n })),\n )\n const path = join(resolve(cwd), this.config.storage.dir, 'feature_list.json')\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, JSON.stringify(list, null, 2) + '\\n', 'utf8')\n }\n\n // ─── storage-state.json (real storage state, for `ahk migrate storage`) ──\n\n /** Writes .harness/storage-state.json, ALWAYS project-local regardless of\n * scope. Reflects the REAL current storage state (scope/projectId/dbType\n * actually in use right now), as opposed to agent-harness-kit.config.ts\n * which reflects the DESIRED state. Format is stable — task #47 (ahk\n * migrate storage) depends on it; do not change field names/shape. */\n async writeStorageState(cwd: string): Promise<void> {\n writeStorageStateFile(cwd, this.config.storage.dir, {\n scope: this.config.storage.scope,\n projectId: this.config.storage.projectId,\n dbType: this.config.database.type,\n migratedAt: new Date().toISOString(),\n })\n }\n}\n\n// ─── Full DB migration helpers (task #47 — `ahk migrate storage`) ─────────\n\n/** Row counts for all 6 tables, queried directly (never inferred). Used to\n * decide whether a destination DB is \"empty\" before an sqlite↔remote\n * migration. */\nexport async function getRowCounts(driver: DBDriver): Promise<Record<(typeof TABLE_INSERT_ORDER)[number], number>> {\n const counts = {} as Record<(typeof TABLE_INSERT_ORDER)[number], number>\n for (const table of TABLE_INSERT_ORDER) {\n const row = await driver.queryOne<{ n: number }>(`SELECT COUNT(*) as n FROM ${table}`)\n counts[table] = Number(row?.n ?? 0)\n }\n return counts\n}\n\n/** True if every table is empty (COUNT(*) = 0 for all 6 tables). */\nexport async function isEmptyDatabase(driver: DBDriver): Promise<boolean> {\n const counts = await getRowCounts(driver)\n return Object.values(counts).every((n) => n === 0)\n}\n\n/** Deletes all rows from all 6 tables, children-before-parents, so FK\n * constraints never block the delete. Only ever called immediately before\n * a `--force` import, inside the same transaction as the import itself —\n * never on its own. */\nasync function truncateAllTables(tx: DBDriver): Promise<void> {\n for (const table of TABLE_DELETE_ORDER) {\n await tx.exec(`DELETE FROM ${table}`)\n }\n}\n\n/** Re-synchronizes the destination's internal autoincrement/serial counter\n * with the highest id actually present, AFTER inserting rows with explicit\n * ids. Required because inserting explicit ids does NOT advance\n * Postgres SERIAL sequences or SQLite's `sqlite_sequence` table — without\n * this, the first unrelated `INSERT ... (no id)` after a migration (e.g.\n * `tasksRepository.add()`) would collide with an imported id.\n * MySQL AUTO_INCREMENT advances automatically on explicit-id inserts\n * greater than the current counter — no action needed there. */\nexport async function resetAutoincrementSequences(\n tx: DBDriver,\n dbType: 'sqlite' | 'postgres' | 'mysql',\n): Promise<void> {\n if (dbType === 'mysql') return // AUTO_INCREMENT self-advances on explicit-id insert — verified in tests.\n\n for (const table of AUTOINCREMENT_TABLES) {\n const row = await tx.queryOne<{ max: number | null }>(`SELECT MAX(id) as max FROM ${table}`)\n const max = row?.max\n if (!max) continue // table stayed empty — nothing to advance\n\n if (dbType === 'postgres') {\n await tx.execRaw(`SELECT setval(pg_get_serial_sequence('${table}','id'), ${max}, true)`)\n } else {\n // sqlite: sqlite_sequence only gets a row once a real AUTOINCREMENT\n // insert happens; explicit-id inserts bypass that, so upsert it.\n await tx.execRaw(\n `INSERT INTO sqlite_sequence (name, seq) SELECT '${table}', ${max} WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = '${table}')`,\n )\n await tx.execRaw(`UPDATE sqlite_sequence SET seq = ${max} WHERE name = '${table}'`)\n }\n }\n}\n\n/** Imports a full export (all 6 tables) into `destDriver`, preserving\n * original ids (required to keep foreign keys intact — see task #47\n * consultant advisory). The ENTIRE import (and, when `truncateFirst` is\n * set, the pre-import wipe) runs inside a single `destDriver.transaction()`\n * call: if anything fails partway, the whole operation rolls back and the\n * destination is left exactly as it was found.\n *\n * Callers MUST only mark the migration successful (e.g. call\n * `db.writeStorageState()`) AFTER this promise resolves without throwing —\n * never inside the transaction callback, never in a `finally`. */\nexport async function importFullExport(\n destDriver: DBDriver,\n data: FullExport,\n destDbType: 'sqlite' | 'postgres' | 'mysql',\n opts: { truncateFirst: boolean } = { truncateFirst: false },\n): Promise<void> {\n // Task #73: actions.id moved from a UUID/TEXT id to an autoincrement\n // INTEGER. An export produced by a pre-2.0 build still carries string\n // action ids, which would otherwise fail deep inside the transaction below\n // with a raw, confusing driver error (a datatype mismatch on sqlite's\n // INTEGER PRIMARY KEY rowid alias, or a hard insert error on postgres/\n // mysql). Fail fast with a clear, actionable message instead.\n if (data.actions.some((a) => typeof (a as { id: unknown }).id !== 'number')) {\n throw new Error(\n 'This export was produced by an older version of agent-harness-kit (actions used text/UUID ids, pre-2.0) and ' +\n 'cannot be imported into a database using the current integer-id actions schema. Re-exporting from the old build ' +\n 'is the only way to fix this — importing this file as-is is not supported.',\n )\n }\n\n await destDriver.transaction(async (tx) => {\n if (opts.truncateFirst) {\n await truncateAllTables(tx)\n }\n\n for (const task of data.tasks) {\n await tx.exec(\n `INSERT INTO tasks (id, slug, title, description, status, assigned_to, created_at, started_at, completed_at, archived_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n [\n task.id,\n task.slug,\n task.title,\n task.description,\n task.status,\n task.assigned_to,\n task.created_at,\n task.started_at,\n task.completed_at,\n task.archived_at,\n task.updated_at,\n ],\n )\n }\n\n for (const ta of data.taskAcceptance) {\n await tx.exec(\n `INSERT INTO task_acceptance (id, task_id, criterion, met) VALUES (?, ?, ?, ?)`,\n [ta.id, ta.task_id, ta.criterion, ta.met],\n )\n }\n\n for (const action of data.actions) {\n await tx.exec(\n `INSERT INTO actions (id, task_id, agent, status, created_at, completed_at, summary) VALUES (?, ?, ?, ?, ?, ?, ?)`,\n [action.id, action.task_id, action.agent, action.status, action.created_at, action.completed_at, action.summary],\n )\n }\n\n for (const section of data.sections) {\n await tx.exec(\n `INSERT INTO action_sections (id, action_id, section_type, content, created_at) VALUES (?, ?, ?, ?, ?)`,\n [section.id, section.action_id, section.section_type, section.content, section.created_at],\n )\n }\n\n for (const file of data.actionFiles) {\n await tx.exec(\n `INSERT INTO action_files (id, action_id, file_path, operation, notes) VALUES (?, ?, ?, ?, ?)`,\n [file.id, file.action_id, file.file_path, file.operation, file.notes],\n )\n }\n\n for (const tool of data.actionTools) {\n await tx.exec(\n `INSERT INTO action_tools (id, action_id, tool_name, args_json, result_summary, called_at) VALUES (?, ?, ?, ?, ?, ?)`,\n [tool.id, tool.action_id, tool.tool_name, tool.args_json, tool.result_summary, tool.called_at],\n )\n }\n\n await resetAutoincrementSequences(tx, destDbType)\n })\n}\n\n/** Resolves the physical sqlite file path for a given scope, sharing the\n * exact convention `openDB()` uses — extracted so `ahk migrate storage` can\n * locate the OLD file (by scope) without duplicating path logic. Does not\n * create any directories or files. */\nexport function resolveSqlitePathForScope(\n scope: 'local' | 'global',\n sqlitePath: string,\n cwd: string,\n config: HarnessConfig,\n homeDir: string,\n): string {\n return scope === 'global'\n ? join(resolveGlobalStorageDir(config, homeDir), 'harness.db')\n : resolve(cwd, sqlitePath)\n}\n\n/** Resolves the physical sqlite file path for `config`'s OWN current scope\n * (as opposed to `resolveSqlitePathForScope`, which resolves an arbitrary\n * scope — used by `ahk migrate storage` to probe both candidates). This is\n * the single mandatory entry point every call site should use instead of\n * reading `config.database`/`config.storage.sqlitePath` directly — routing\n * everything through here is what keeps new call sites from re-introducing\n * the \"reads a local-only field while scope=global\" bug class (task #55/#56). */\nexport function resolveSqlitePath(config: HarnessConfig, cwd: string, homeDir: string = homedir()): string {\n const sqlitePath = config.storage.scope === 'local' ? (config.storage.sqlitePath ?? DEFAULT_SQLITE_PATH) : DEFAULT_SQLITE_PATH\n return resolveSqlitePathForScope(config.storage.scope, sqlitePath, cwd, config, homeDir)\n}\n\n/** Resolves the physical current.md fallback path for `config`'s OWN current\n * scope, sharing the exact convention `HarnessDB.regenerateCurrentMd()`\n * uses. Mirrors `resolveSqlitePath()` — call sites (materializers, reset,\n * health) should use this instead of reading `storage.markdownFallback.path`\n * directly, since that field doesn't exist at all under scope='global'. */\nexport function resolveMarkdownFallbackPath(config: HarnessConfig, cwd: string, homeDir: string = homedir()): string {\n return config.storage.scope === 'global'\n ? join(resolveGlobalStorageDir(config, homeDir), 'current.md')\n : resolve(cwd, config.storage.markdownFallback.path)\n}\n\n/** Writes `<storageDir>/storage-state.json` under `cwd`. Standalone (not tied\n * to a live HarnessDB instance) so it can be called during init before a DB\n * connection exists, and reused by future migration tooling. */\nexport function writeStorageStateFile(cwd: string, storageDir: string, state: StorageState): void {\n const path = join(resolve(cwd), storageDir, 'storage-state.json')\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, JSON.stringify(state, null, 2) + '\\n', 'utf8')\n}\n\n/** Reads `<storageDir>/storage-state.json` under `cwd`. Returns `null` if it\n * doesn't exist or is malformed. Used by future migration tooling (#47) to\n * determine the real current storage state before migrating. */\nexport function readStorageStateFile(cwd: string, storageDir: string): StorageState | null {\n try {\n const path = join(resolve(cwd), storageDir, 'storage-state.json')\n if (!existsSync(path)) return null\n return JSON.parse(readFileSync(path, 'utf8')) as StorageState\n } catch {\n return null\n }\n}\n\n// ─── Factory ─────────────────────────────────────────────────────────────────\n\nexport async function openDB(config: HarnessConfig, cwd: string, homeDir: string = homedir()): Promise<HarnessDB> {\n const dbConfig = config.database\n let driver: DBDriver\n\n if (dbConfig.type === 'postgres') {\n const { PostgresDriver } = await import('./drivers/postgres')\n driver = new PostgresDriver(dbConfig)\n } else if (dbConfig.type === 'mysql') {\n const { MySQLDriver } = await import('./drivers/mysql')\n driver = new MySQLDriver(dbConfig)\n } else {\n const { SQLiteDriver } = await import('./drivers/sqlite')\n if (dbConfig.type !== 'sqlite') {\n throw new Error('Invalid database type')\n }\n\n let dbPath: string\n if (config.storage.scope === 'global') {\n const globalDir = resolveGlobalStorageDir(config, homeDir)\n // Defensive check: a UUID collision is negligible, but if the target\n // dir already exists with a DIFFERENT project's state, don't silently\n // reuse it — surface the conflict instead of assuming it's free.\n const existingStatePath = join(globalDir, 'storage-state.json')\n if (existsSync(existingStatePath)) {\n try {\n const existingState = JSON.parse(readFileSync(existingStatePath, 'utf8')) as StorageState\n if (existingState.projectId !== config.storage.projectId) {\n throw new Error(\n `Global storage dir ${globalDir} already holds a different project (projectId: ${existingState.projectId}). Refusing to reuse it.`,\n )\n }\n } catch (err) {\n if (err instanceof Error && err.message.includes('already holds a different project')) throw err\n // Malformed/unreadable state file — ignore and proceed, mkdirSync below is idempotent.\n }\n }\n mkdirSync(globalDir, { recursive: true })\n dbPath = join(globalDir, 'harness.db')\n } else {\n dbPath = resolve(cwd, config.storage.sqlitePath ?? DEFAULT_SQLITE_PATH)\n }\n\n driver = new SQLiteDriver(dbPath)\n }\n\n await driver.ensureSchema()\n return new HarnessDB(driver, config, homeDir)\n}\n","import type { DBDriver } from '../drivers/types'\nimport type { ActionFileRow, ActionRow, ActionSectionRow, ActionToolRow, AgentName } from '@/types'\n\nexport interface ActionWithDetails extends ActionRow {\n sections: ActionSectionRow[]\n files: ActionFileRow[]\n tools: ActionToolRow[]\n}\n\nexport interface ActionListRow extends ActionRow {\n section_count: number\n}\n\nexport interface ActionSectionIndexRow {\n id: number\n action_id: number\n section_type: string\n chars: number\n created_at: string\n}\n\nexport class ActionRepository {\n constructor(private driver: DBDriver) {}\n\n /** Returns the new autoincrement id — mirrors TaskRepository.add(). Since\n * task #73, `actions.id` is a driver-generated INTEGER, not an\n * application-generated UUID, so callers no longer pass an id in. */\n async create(taskId: number, agent: AgentName, now: string): Promise<number> {\n return this.driver.insert(\n `INSERT INTO actions (task_id, agent, status, created_at) VALUES (?, ?, 'in_progress', ?)`,\n [taskId, agent, now],\n )\n }\n\n async complete(actionId: number, summary: string, now: string): Promise<void> {\n await this.driver.exec(\n `UPDATE actions SET status = 'completed', completed_at = ?, summary = ? WHERE id = ?`,\n [now, summary, actionId],\n )\n }\n\n async closeOrphaned(taskId: number, now: string): Promise<number> {\n return this.driver.exec(\n `UPDATE actions SET status = 'completed', completed_at = ?, summary = 'Auto-closed: task marked done' WHERE task_id = ? AND status = 'in_progress'`,\n [now, taskId],\n )\n }\n\n async getById(actionId: number): Promise<ActionRow | null> {\n return this.driver.queryOne<ActionRow>(`SELECT * FROM actions WHERE id = ?`, [actionId])\n }\n\n async getForTask(taskId: number): Promise<ActionRow[]> {\n return this.driver.query<ActionRow>(\n `SELECT * FROM actions WHERE task_id = ? ORDER BY created_at`,\n [taskId],\n )\n }\n\n /** Compact newest-first index used by actions.list. The cursor is the last\n * row from the previous page, so it remains stable when new actions arrive. */\n async listForTask(\n taskId: number,\n options: {\n agent?: AgentName\n status?: ActionRow['status']\n cursor?: { createdAt: string; id: number }\n limit: number\n },\n ): Promise<ActionListRow[]> {\n const where = ['a.task_id = ?']\n const params: unknown[] = [taskId]\n if (options.agent) {\n where.push('a.agent = ?')\n params.push(options.agent)\n }\n if (options.status) {\n where.push('a.status = ?')\n params.push(options.status)\n }\n if (options.cursor) {\n where.push('(a.created_at < ? OR (a.created_at = ? AND a.id < ?))')\n params.push(options.cursor.createdAt, options.cursor.createdAt, options.cursor.id)\n }\n params.push(options.limit)\n return this.driver.query<ActionListRow>(\n `SELECT a.*, COUNT(s.id) AS section_count\n FROM actions a LEFT JOIN action_sections s ON s.action_id = a.id\n WHERE ${where.join(' AND ')}\n GROUP BY a.id, a.task_id, a.agent, a.status, a.created_at, a.completed_at, a.summary\n ORDER BY a.created_at DESC, a.id DESC LIMIT ?`,\n params,\n )\n }\n\n async getAll(): Promise<ActionRow[]> {\n return this.driver.query<ActionRow>(`SELECT * FROM actions ORDER BY created_at`)\n }\n\n async getWithDetails(taskId: number): Promise<ActionWithDetails[]> {\n const actions = await this.getForTask(taskId)\n return Promise.all(\n actions.map(async (action) => ({\n ...action,\n sections: await this.getSections(action.id),\n files: await this.getFiles(action.id),\n tools: await this.getTools(action.id),\n })),\n )\n }\n\n // ─── Sections ─────────────────────────────────────────────────────────────\n\n async addSection(actionId: number, sectionType: string, content: string, now: string): Promise<void> {\n await this.driver.exec(\n `INSERT INTO action_sections (action_id, section_type, content, created_at) VALUES (?, ?, ?, ?)`,\n [actionId, sectionType, content, now],\n )\n }\n\n async getSections(actionId: number): Promise<ActionSectionRow[]> {\n return this.driver.query<ActionSectionRow>(\n `SELECT * FROM action_sections WHERE action_id = ? ORDER BY created_at`,\n [actionId],\n )\n }\n\n async getSectionById(sectionId: number): Promise<ActionSectionRow | null> {\n return this.driver.queryOne<ActionSectionRow>(`SELECT * FROM action_sections WHERE id = ?`, [sectionId])\n }\n\n async listSections(\n actionId: number,\n options: { types?: string[]; cursor?: number; limit: number },\n ): Promise<ActionSectionIndexRow[]> {\n const where = ['action_id = ?']\n const params: unknown[] = [actionId]\n if (options.types?.length) {\n where.push(`section_type IN (${options.types.map(() => '?').join(', ')})`)\n params.push(...options.types)\n }\n if (options.cursor !== undefined) {\n where.push('id < ?')\n params.push(options.cursor)\n }\n params.push(options.limit)\n return this.driver.query<ActionSectionIndexRow>(\n `SELECT id, action_id, section_type, LENGTH(content) AS chars, created_at\n FROM action_sections WHERE ${where.join(' AND ')} ORDER BY id DESC LIMIT ?`,\n params,\n )\n }\n\n async getCompletedHandoffSections(taskId: number): Promise<Array<ActionSectionRow & Pick<ActionRow, 'agent' | 'completed_at'>>> {\n return this.driver.query(\n `SELECT s.*, a.agent, a.completed_at\n FROM action_sections s JOIN actions a ON a.id = s.action_id\n WHERE a.task_id = ? AND a.status = 'completed' AND s.section_type = 'handoff'\n ORDER BY s.created_at DESC, s.id DESC`,\n [taskId],\n )\n }\n\n async getAllSections(): Promise<ActionSectionRow[]> {\n return this.driver.query<ActionSectionRow>(`SELECT * FROM action_sections ORDER BY created_at`)\n }\n\n // ─── Files ────────────────────────────────────────────────────────────────\n\n async addFile(\n actionId: number,\n filePath: string,\n operation: ActionFileRow['operation'],\n notes: string | null,\n ): Promise<void> {\n await this.driver.exec(\n `INSERT INTO action_files (action_id, file_path, operation, notes) VALUES (?, ?, ?, ?)`,\n [actionId, filePath, operation, notes],\n )\n }\n\n async getFiles(actionId: number): Promise<ActionFileRow[]> {\n return this.driver.query<ActionFileRow>(\n `SELECT * FROM action_files WHERE action_id = ?`,\n [actionId],\n )\n }\n\n async getFilesForTask(taskId: number): Promise<(ActionFileRow & { agent: AgentName })[]> {\n return this.driver.query<ActionFileRow & { agent: AgentName }>(\n `SELECT af.*, a.agent FROM action_files af JOIN actions a ON af.action_id = a.id WHERE a.task_id = ? ORDER BY a.agent, af.operation`,\n [taskId],\n )\n }\n\n /** Returns ALL action_files rows regardless of action — used by full DB\n * exports (e.g. `ahk migrate storage`) so file-touch records aren't lost. */\n async getAllFiles(): Promise<ActionFileRow[]> {\n return this.driver.query<ActionFileRow>(`SELECT * FROM action_files ORDER BY id`)\n }\n\n // ─── Tools ────────────────────────────────────────────────────────────────\n\n async addTool(\n actionId: number,\n toolName: string,\n argsJson: string | null,\n resultSummary: string | null,\n now: string,\n ): Promise<void> {\n await this.driver.exec(\n `INSERT INTO action_tools (action_id, tool_name, args_json, result_summary, called_at) VALUES (?, ?, ?, ?, ?)`,\n [actionId, toolName, argsJson, resultSummary, now],\n )\n }\n\n async getTools(actionId: number): Promise<ActionToolRow[]> {\n return this.driver.query<ActionToolRow>(\n `SELECT * FROM action_tools WHERE action_id = ? ORDER BY called_at`,\n [actionId],\n )\n }\n\n /** Returns ALL action_tools rows regardless of action — used by full DB\n * exports (e.g. `ahk migrate storage`) so tool-call records aren't lost. */\n async getAllTools(): Promise<ActionToolRow[]> {\n return this.driver.query<ActionToolRow>(`SELECT * FROM action_tools ORDER BY id`)\n }\n\n async getTopTools(limit: number): Promise<{ tool_name: string; uses: number }[]> {\n return this.driver.query<{ tool_name: string; uses: number }>(\n `SELECT tool_name, COUNT(*) as uses FROM action_tools GROUP BY tool_name ORDER BY uses DESC LIMIT ?`,\n [limit],\n )\n }\n}\n","import type { DBDriver } from '../drivers/types'\nimport type {\n AgentStatRow,\n CountRow,\n RecentFileRow,\n RecentToolRow,\n TimelineRow,\n TopFileRow,\n} from '../server-types'\n\nexport interface DBCounts {\n totalActions: number\n totalFiles: number\n uniqueTools: number\n activeAgents: number\n}\n\nexport { AgentStatRow, RecentFileRow, RecentToolRow, TimelineRow, TopFileRow }\n\nconst AGENT_ORDER = ['lead', 'explorer', 'builder', 'reviewer']\n\nexport class StatsRepository {\n constructor(private driver: DBDriver) { }\n\n async getCounts(): Promise<DBCounts> {\n const [{ total: totalActions }] = await this.driver.query<CountRow>(\n `SELECT COUNT(*) as total FROM actions`,\n )\n const [{ total: totalFiles }] = await this.driver.query<CountRow>(\n `SELECT COUNT(*) as total FROM action_files`,\n )\n const [{ total: uniqueTools }] = await this.driver.query<CountRow>(\n `SELECT COUNT(DISTINCT tool_name) as total FROM action_tools`,\n )\n const [{ total: activeAgents }] = await this.driver.query<CountRow>(\n `SELECT COUNT(DISTINCT agent) as total FROM actions WHERE status = 'in_progress'`,\n )\n return { totalActions, totalFiles, uniqueTools, activeAgents }\n }\n\n async getRecentTools(limit: number): Promise<RecentToolRow[]> {\n return this.driver.query<RecentToolRow>(\n `SELECT at.*, t.id as task_id, t.title as task_title, t.slug as task_slug, a.agent\n FROM action_tools at\n JOIN actions a ON at.action_id = a.id\n JOIN tasks t ON a.task_id = t.id\n ORDER BY at.called_at DESC\n LIMIT ?`,\n [limit],\n )\n }\n\n async getTopFiles(limit: number): Promise<TopFileRow[]> {\n return this.driver.query<TopFileRow>(\n `SELECT\n file_path,\n COUNT(*) as total,\n SUM(CASE WHEN operation='read' THEN 1 ELSE 0 END) as read,\n SUM(CASE WHEN operation='created' THEN 1 ELSE 0 END) as created,\n SUM(CASE WHEN operation='modified' THEN 1 ELSE 0 END) as modified,\n SUM(CASE WHEN operation='deleted' THEN 1 ELSE 0 END) as deleted\n FROM action_files\n GROUP BY file_path\n ORDER BY total DESC\n LIMIT ?`,\n [limit],\n )\n }\n\n async getRecentFiles(limit: number): Promise<RecentFileRow[]> {\n return this.driver.query<RecentFileRow>(\n `SELECT af.*, t.id as task_id, t.title as task_title, t.slug as task_slug,\n a.agent, a.created_at as called_at\n FROM action_files af\n JOIN actions a ON af.action_id = a.id\n JOIN tasks t ON a.task_id = t.id\n ORDER BY a.created_at DESC\n LIMIT ?`,\n [limit],\n )\n }\n\n async getAgentStats(): Promise<AgentStatRow[]> {\n const rows = await this.driver.query<AgentStatRow>(\n `SELECT\n a.agent,\n COUNT(*) as actions_total,\n SUM(CASE WHEN a.status='completed' THEN 1 ELSE 0 END) as actions_done,\n SUM(CASE WHEN a.status='blocked' THEN 1 ELSE 0 END) as actions_blocked,\n COUNT(DISTINCT a.task_id) as tasks_worked,\n COUNT(DISTINCT af.file_path) as files_touched\n FROM actions a\n LEFT JOIN action_files af ON af.action_id = a.id\n GROUP BY a.agent\n ORDER BY actions_total DESC`,\n )\n return rows.sort((a, b) => {\n const ai = AGENT_ORDER.indexOf(a.agent)\n const bi = AGENT_ORDER.indexOf(b.agent)\n if (ai === -1 && bi === -1) return 0\n if (ai === -1) return 1\n if (bi === -1) return -1\n return ai - bi\n })\n }\n\n async getTimeline(limit: number): Promise<TimelineRow[]> {\n return this.driver.query<TimelineRow>(\n `SELECT a.*, t.title as task_title, t.slug as task_slug, t.status as task_status\n FROM actions a\n JOIN tasks t ON a.task_id = t.id\n ORDER BY a.created_at DESC\n LIMIT ?`,\n [limit],\n )\n }\n}\n","import type { DBDriver } from '../drivers/types'\nimport type { TaskAcceptanceRow, TaskRow, TaskStatus } from '@/types'\n\nexport interface TaskWithAcceptance extends TaskRow {\n acceptance_total: number\n acceptance_met: number\n}\n\nexport class TaskRepository {\n constructor(private driver: DBDriver) {}\n\n async add(params: {\n slug: string\n title: string\n description?: string | null\n status?: TaskStatus\n }): Promise<number> {\n const now = new Date().toISOString()\n return this.driver.insert(\n `INSERT INTO tasks (slug, title, description, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)`,\n [params.slug, params.title, params.description ?? null, params.status ?? 'pending', now, now],\n )\n }\n\n async addAcceptance(taskId: number, criteria: string[]): Promise<void> {\n for (const criterion of criteria) {\n await this.driver.exec(\n `INSERT INTO task_acceptance (task_id, criterion) VALUES (?, ?)`,\n [taskId, criterion],\n )\n }\n }\n\n async getAll(status?: TaskStatus, includeArchived = false): Promise<TaskRow[]> {\n let sql = `SELECT * FROM tasks`\n const params: unknown[] = []\n const conditions: string[] = []\n\n if (!includeArchived) {\n conditions.push(`archived_at IS NULL`)\n }\n if (status) {\n conditions.push(`status = ?`)\n params.push(status)\n }\n if (conditions.length > 0) {\n sql += ` WHERE ${conditions.join(' AND ')}`\n }\n sql += ` ORDER BY CASE status WHEN 'pending' THEN 1 WHEN 'in_progress' THEN 2 WHEN 'blocked' THEN 3 WHEN 'done' THEN 4 ELSE 5 END, updated_at DESC`\n\n return this.driver.query<TaskRow>(sql, params)\n }\n\n async getAllWithAcceptanceCounts(includeArchived = false): Promise<TaskWithAcceptance[]> {\n let sql = `\n SELECT t.*,\n COUNT(ta.id) as acceptance_total,\n COALESCE(SUM(ta.met), 0) as acceptance_met\n FROM tasks t\n LEFT JOIN task_acceptance ta ON ta.task_id = t.id\n `\n if (!includeArchived) {\n sql += ` WHERE t.archived_at IS NULL`\n }\n sql += ` GROUP BY t.id ORDER BY CASE t.status WHEN 'pending' THEN 1 WHEN 'in_progress' THEN 2 WHEN 'blocked' THEN 3 WHEN 'done' THEN 4 ELSE 5 END, t.updated_at DESC`\n return this.driver.query<TaskWithAcceptance>(sql)\n }\n\n async getById(id: number): Promise<TaskRow | null> {\n return this.driver.queryOne<TaskRow>(`SELECT * FROM tasks WHERE id = ?`, [id])\n }\n\n async getBySlug(slug: string): Promise<TaskRow | null> {\n return this.driver.queryOne<TaskRow>(`SELECT * FROM tasks WHERE slug = ?`, [slug])\n }\n\n async getAcceptance(taskId: number): Promise<TaskAcceptanceRow[]> {\n return this.driver.query<TaskAcceptanceRow>(\n `SELECT * FROM task_acceptance WHERE task_id = ?`,\n [taskId],\n )\n }\n\n /** Returns ALL task_acceptance rows regardless of task — used by full DB\n * exports (e.g. `ahk migrate storage`) so criteria aren't silently dropped. */\n async getAllAcceptance(): Promise<TaskAcceptanceRow[]> {\n return this.driver.query<TaskAcceptanceRow>(`SELECT * FROM task_acceptance ORDER BY id`)\n }\n\n async setStatus(id: number, status: TaskStatus, extra?: { started_at?: string; completed_at?: string }): Promise<void> {\n const now = new Date().toISOString()\n if (extra?.started_at) {\n await this.driver.exec(\n `UPDATE tasks SET status = ?, started_at = ?, updated_at = ? WHERE id = ?`,\n [status, extra.started_at, now, id],\n )\n } else if (extra?.completed_at) {\n await this.driver.exec(\n `UPDATE tasks SET status = ?, completed_at = ?, updated_at = ? WHERE id = ?`,\n [status, extra.completed_at, now, id],\n )\n } else {\n await this.driver.exec(`UPDATE tasks SET status = ?, updated_at = ? WHERE id = ?`, [status, now, id])\n }\n }\n\n async update(id: number, params: { title?: string; description?: string | null; slug?: string }): Promise<void> {\n const sets: string[] = []\n const vals: unknown[] = []\n const now = new Date().toISOString()\n if (params.title !== undefined) { sets.push('title = ?'); vals.push(params.title) }\n if (params.description !== undefined) { sets.push('description = ?'); vals.push(params.description) }\n if (params.slug !== undefined) { sets.push('slug = ?'); vals.push(params.slug) }\n if (sets.length === 0) return\n sets.push('updated_at = ?')\n vals.push(now)\n vals.push(id)\n await this.driver.exec(`UPDATE tasks SET ${sets.join(', ')} WHERE id = ?`, vals)\n }\n\n async replaceAcceptance(taskId: number, criteria: string[]): Promise<void> {\n await this.driver.exec(`DELETE FROM task_acceptance WHERE task_id = ?`, [taskId])\n for (const criterion of criteria) {\n await this.driver.exec(\n `INSERT INTO task_acceptance (task_id, criterion) VALUES (?, ?)`,\n [taskId, criterion],\n )\n }\n }\n\n async archive(id: number): Promise<void> {\n const now = new Date().toISOString()\n await this.driver.exec(`UPDATE tasks SET archived_at = ?, updated_at = ? WHERE id = ?`, [now, now, id])\n }\n\n async unarchive(id: number): Promise<void> {\n const now = new Date().toISOString()\n await this.driver.exec(`UPDATE tasks SET archived_at = NULL, updated_at = ? WHERE id = ?`, [now, id])\n }\n\n async getArchived(): Promise<TaskRow[]> {\n return this.driver.query<TaskRow>(\n `SELECT * FROM tasks WHERE archived_at IS NOT NULL ORDER BY archived_at DESC`\n )\n }\n\n async claim(id: number, agent: string, now: string): Promise<number> {\n return this.driver.exec(\n `UPDATE tasks SET status = 'in_progress', assigned_to = ?, started_at = ?, updated_at = ? WHERE id = ? AND status = 'pending'`,\n [agent, now, now, id],\n )\n }\n\n async markAcceptanceMet(criterionId: number): Promise<void> {\n await this.driver.exec(`UPDATE task_acceptance SET met = 1 WHERE id = ?`, [criterionId])\n }\n\n async getStatusSummary(): Promise<{ status: string; total: number }[]> {\n return this.driver.query<{ status: string; total: number }>(\n `SELECT status, COUNT(*) as total FROM tasks WHERE archived_at IS NULL GROUP BY status`,\n )\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,eAAe;AACxB,SAAS,SAAS,MAAM,eAAe;;;ACmBhC,IAAM,mBAAN,MAAuB;AAAA,EAC5B,YAAoB,QAAkB;AAAlB;AAAA,EAAmB;AAAA,EAAnB;AAAA;AAAA;AAAA;AAAA,EAKpB,MAAM,OAAO,QAAgB,OAAkB,KAA8B;AAC3E,WAAO,KAAK,OAAO;AAAA,MACjB;AAAA,MACA,CAAC,QAAQ,OAAO,GAAG;AAAA,IACrB;AAAA,EACF;AAAA,EAEA,MAAM,SAAS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