@jonit-dev/night-watch-cli 1.5.8 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/cli.js +6 -0
  2. package/dist/cli.js.map +1 -1
  3. package/dist/commands/init.d.ts +13 -0
  4. package/dist/commands/init.d.ts.map +1 -1
  5. package/dist/commands/init.js +39 -11
  6. package/dist/commands/init.js.map +1 -1
  7. package/dist/commands/install.d.ts +2 -0
  8. package/dist/commands/install.d.ts.map +1 -1
  9. package/dist/commands/install.js +23 -0
  10. package/dist/commands/install.js.map +1 -1
  11. package/dist/commands/slice.d.ts +26 -0
  12. package/dist/commands/slice.d.ts.map +1 -0
  13. package/dist/commands/slice.js +175 -0
  14. package/dist/commands/slice.js.map +1 -0
  15. package/dist/commands/state.d.ts +8 -0
  16. package/dist/commands/state.d.ts.map +1 -0
  17. package/dist/commands/state.js +56 -0
  18. package/dist/commands/state.js.map +1 -0
  19. package/dist/commands/uninstall.js +2 -2
  20. package/dist/commands/uninstall.js.map +1 -1
  21. package/dist/config.d.ts.map +1 -1
  22. package/dist/config.js +32 -1
  23. package/dist/config.js.map +1 -1
  24. package/dist/constants.d.ts +4 -0
  25. package/dist/constants.d.ts.map +1 -1
  26. package/dist/constants.js +7 -0
  27. package/dist/constants.js.map +1 -1
  28. package/dist/server/index.d.ts.map +1 -1
  29. package/dist/server/index.js +11 -13
  30. package/dist/server/index.js.map +1 -1
  31. package/dist/storage/json-state-migrator.d.ts +24 -0
  32. package/dist/storage/json-state-migrator.d.ts.map +1 -0
  33. package/dist/storage/json-state-migrator.js +197 -0
  34. package/dist/storage/json-state-migrator.js.map +1 -0
  35. package/dist/storage/repositories/index.d.ts +23 -0
  36. package/dist/storage/repositories/index.d.ts.map +1 -0
  37. package/dist/storage/repositories/index.js +37 -0
  38. package/dist/storage/repositories/index.js.map +1 -0
  39. package/dist/storage/repositories/interfaces.d.ts +37 -0
  40. package/dist/storage/repositories/interfaces.d.ts.map +1 -0
  41. package/dist/storage/repositories/interfaces.js +6 -0
  42. package/dist/storage/repositories/interfaces.js.map +1 -0
  43. package/dist/storage/repositories/sqlite/execution-history-repository.d.ts +21 -0
  44. package/dist/storage/repositories/sqlite/execution-history-repository.d.ts.map +1 -0
  45. package/dist/storage/repositories/sqlite/execution-history-repository.js +94 -0
  46. package/dist/storage/repositories/sqlite/execution-history-repository.js.map +1 -0
  47. package/dist/storage/repositories/sqlite/prd-state-repository.d.ts +17 -0
  48. package/dist/storage/repositories/sqlite/prd-state-repository.d.ts.map +1 -0
  49. package/dist/storage/repositories/sqlite/prd-state-repository.js +74 -0
  50. package/dist/storage/repositories/sqlite/prd-state-repository.js.map +1 -0
  51. package/dist/storage/repositories/sqlite/project-registry-repository.d.ts +16 -0
  52. package/dist/storage/repositories/sqlite/project-registry-repository.d.ts.map +1 -0
  53. package/dist/storage/repositories/sqlite/project-registry-repository.js +34 -0
  54. package/dist/storage/repositories/sqlite/project-registry-repository.js.map +1 -0
  55. package/dist/storage/repositories/sqlite/roadmap-state-repository.d.ts +14 -0
  56. package/dist/storage/repositories/sqlite/roadmap-state-repository.d.ts.map +1 -0
  57. package/dist/storage/repositories/sqlite/roadmap-state-repository.js +47 -0
  58. package/dist/storage/repositories/sqlite/roadmap-state-repository.js.map +1 -0
  59. package/dist/storage/sqlite/client.d.ts +23 -0
  60. package/dist/storage/sqlite/client.d.ts.map +1 -0
  61. package/dist/storage/sqlite/client.js +47 -0
  62. package/dist/storage/sqlite/client.js.map +1 -0
  63. package/dist/storage/sqlite/migrations.d.ts +11 -0
  64. package/dist/storage/sqlite/migrations.d.ts.map +1 -0
  65. package/dist/storage/sqlite/migrations.js +57 -0
  66. package/dist/storage/sqlite/migrations.js.map +1 -0
  67. package/dist/templates/slicer-prompt.d.ts +54 -0
  68. package/dist/templates/slicer-prompt.d.ts.map +1 -0
  69. package/dist/templates/slicer-prompt.js +163 -0
  70. package/dist/templates/slicer-prompt.js.map +1 -0
  71. package/dist/types.d.ts +6 -0
  72. package/dist/types.d.ts.map +1 -1
  73. package/dist/utils/execution-history.d.ts +11 -5
  74. package/dist/utils/execution-history.d.ts.map +1 -1
  75. package/dist/utils/execution-history.js +27 -130
  76. package/dist/utils/execution-history.js.map +1 -1
  77. package/dist/utils/prd-states.d.ts +1 -2
  78. package/dist/utils/prd-states.d.ts.map +1 -1
  79. package/dist/utils/prd-states.js +10 -42
  80. package/dist/utils/prd-states.js.map +1 -1
  81. package/dist/utils/registry.d.ts +9 -4
  82. package/dist/utils/registry.d.ts.map +1 -1
  83. package/dist/utils/registry.js +21 -33
  84. package/dist/utils/registry.js.map +1 -1
  85. package/dist/utils/roadmap-scanner.d.ts +34 -2
  86. package/dist/utils/roadmap-scanner.d.ts.map +1 -1
  87. package/dist/utils/roadmap-scanner.js +218 -105
  88. package/dist/utils/roadmap-scanner.js.map +1 -1
  89. package/dist/utils/roadmap-state.d.ts +13 -6
  90. package/dist/utils/roadmap-state.d.ts.map +1 -1
  91. package/dist/utils/roadmap-state.js +50 -27
  92. package/dist/utils/roadmap-state.js.map +1 -1
  93. package/package.json +6 -1
  94. package/scripts/night-watch-cron.sh +65 -24
  95. package/scripts/night-watch-slicer-cron.sh +90 -0
  96. package/templates/night-watch-slicer.md +219 -0
  97. package/templates/night-watch.config.json +1 -0
@@ -0,0 +1,197 @@
1
+ /**
2
+ * JSON → SQLite migration logic for Night Watch CLI.
3
+ * Reads legacy JSON state files and inserts their contents into SQLite
4
+ * via the repository layer. Safe to run multiple times (idempotent).
5
+ */
6
+ import * as fs from "fs";
7
+ import * as path from "path";
8
+ import { CONFIG_FILE_NAME } from "../constants.js";
9
+ import { getDb } from "./sqlite/client.js";
10
+ import { getRepositories } from "./repositories/index.js";
11
+ /**
12
+ * Attempt to parse a JSON file, returning null if the file does not exist
13
+ * or its content cannot be parsed.
14
+ */
15
+ function tryReadJson(filePath) {
16
+ if (!fs.existsSync(filePath)) {
17
+ return null;
18
+ }
19
+ try {
20
+ const content = fs.readFileSync(filePath, "utf-8");
21
+ return JSON.parse(content);
22
+ }
23
+ catch {
24
+ return null;
25
+ }
26
+ }
27
+ /**
28
+ * Copy a file to the backup directory if it exists.
29
+ */
30
+ function backupFile(src, backupDir) {
31
+ if (fs.existsSync(src)) {
32
+ fs.copyFileSync(src, path.join(backupDir, path.basename(src)));
33
+ }
34
+ }
35
+ /**
36
+ * Collect all PRD directories from the registered projects by reading each
37
+ * project's night-watch.config.json. Falls back to the default "docs/PRDs/night-watch"
38
+ * directory when the config cannot be read.
39
+ */
40
+ function collectPrdDirs(projectPaths) {
41
+ const prdDirs = [];
42
+ for (const projectPath of projectPaths) {
43
+ const configPath = path.join(projectPath, CONFIG_FILE_NAME);
44
+ let prdDir = "docs/PRDs/night-watch";
45
+ if (fs.existsSync(configPath)) {
46
+ try {
47
+ const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
48
+ if (typeof config.prdDir === "string" && config.prdDir.length > 0) {
49
+ prdDir = config.prdDir;
50
+ }
51
+ }
52
+ catch {
53
+ // use default
54
+ }
55
+ }
56
+ const fullPrdDir = path.join(projectPath, prdDir);
57
+ if (fs.existsSync(fullPrdDir)) {
58
+ prdDirs.push(fullPrdDir);
59
+ }
60
+ }
61
+ return prdDirs;
62
+ }
63
+ /**
64
+ * Migrate legacy JSON state files into SQLite.
65
+ *
66
+ * The migration is idempotent: if the key "json_migration_completed" already
67
+ * exists in schema_meta the function returns early without touching the DB.
68
+ *
69
+ * @param nightWatchHome - Path to the Night Watch home directory
70
+ * (e.g. ~/.night-watch or the value of NIGHT_WATCH_HOME).
71
+ */
72
+ export function migrateJsonToSqlite(nightWatchHome) {
73
+ const db = getDb();
74
+ const { projectRegistry, executionHistory, prdState, roadmapState } = getRepositories();
75
+ // --- Idempotency check ---
76
+ const alreadyDone = db
77
+ .prepare("SELECT key FROM schema_meta WHERE key = 'json_migration_completed'")
78
+ .get();
79
+ if (alreadyDone) {
80
+ return {
81
+ projectsMigrated: 0,
82
+ historyRecordsMigrated: 0,
83
+ prdStatesMigrated: 0,
84
+ roadmapStatesMigrated: 0,
85
+ backupDir: "",
86
+ alreadyMigrated: true,
87
+ };
88
+ }
89
+ // --- Backup directory ---
90
+ const backupDir = path.join(nightWatchHome, "backups", `json-migration-${Date.now()}`);
91
+ fs.mkdirSync(backupDir, { recursive: true });
92
+ const projectsJsonPath = path.join(nightWatchHome, "projects.json");
93
+ const historyJsonPath = path.join(nightWatchHome, "history.json");
94
+ const prdStatesJsonPath = path.join(nightWatchHome, "prd-states.json");
95
+ backupFile(projectsJsonPath, backupDir);
96
+ backupFile(historyJsonPath, backupDir);
97
+ backupFile(prdStatesJsonPath, backupDir);
98
+ // --- Migrate projects.json ---
99
+ let projectsMigrated = 0;
100
+ const legacyProjects = tryReadJson(projectsJsonPath) ?? [];
101
+ const migrateProjects = db.transaction(() => {
102
+ for (const entry of legacyProjects) {
103
+ if (typeof entry.name === "string" &&
104
+ typeof entry.path === "string" &&
105
+ entry.name.length > 0 &&
106
+ entry.path.length > 0) {
107
+ projectRegistry.upsert(entry);
108
+ projectsMigrated++;
109
+ }
110
+ }
111
+ });
112
+ migrateProjects();
113
+ // --- Migrate history.json ---
114
+ let historyRecordsMigrated = 0;
115
+ const legacyHistory = tryReadJson(historyJsonPath) ?? {};
116
+ const migrateHistory = db.transaction(() => {
117
+ for (const [projectPath, prdMap] of Object.entries(legacyHistory)) {
118
+ for (const [prdFile, prdHistory] of Object.entries(prdMap)) {
119
+ if (!Array.isArray(prdHistory.records)) {
120
+ continue;
121
+ }
122
+ for (const record of prdHistory.records) {
123
+ if (typeof record.timestamp !== "number" ||
124
+ typeof record.outcome !== "string" ||
125
+ typeof record.exitCode !== "number" ||
126
+ typeof record.attempt !== "number") {
127
+ continue;
128
+ }
129
+ executionHistory.addRecord(projectPath, prdFile, record);
130
+ historyRecordsMigrated++;
131
+ }
132
+ }
133
+ }
134
+ });
135
+ migrateHistory();
136
+ // --- Migrate prd-states.json ---
137
+ let prdStatesMigrated = 0;
138
+ const legacyPrdStates = tryReadJson(prdStatesJsonPath) ?? {};
139
+ const migratePrdStates = db.transaction(() => {
140
+ for (const [projectDir, prdMap] of Object.entries(legacyPrdStates)) {
141
+ for (const [prdName, entry] of Object.entries(prdMap)) {
142
+ if (typeof entry.status === "string" &&
143
+ typeof entry.branch === "string" &&
144
+ typeof entry.timestamp === "number") {
145
+ prdState.set(projectDir, prdName, entry);
146
+ prdStatesMigrated++;
147
+ }
148
+ }
149
+ }
150
+ });
151
+ migratePrdStates();
152
+ // --- Migrate .roadmap-state.json files ---
153
+ let roadmapStatesMigrated = 0;
154
+ const projectPaths = legacyProjects.map((e) => e.path);
155
+ const prdDirs = collectPrdDirs(projectPaths);
156
+ const migrateRoadmapStates = db.transaction(() => {
157
+ for (const prdDir of prdDirs) {
158
+ const stateFilePath = path.join(prdDir, ".roadmap-state.json");
159
+ const state = tryReadJson(stateFilePath);
160
+ if (state === null) {
161
+ continue;
162
+ }
163
+ if (typeof state.version !== "number" ||
164
+ typeof state.items !== "object" ||
165
+ state.items === null) {
166
+ continue;
167
+ }
168
+ // Back up the .roadmap-state.json alongside the other backup files
169
+ const backupName = `roadmap-state-${Buffer.from(prdDir).toString("base64url").slice(0, 32)}.json`;
170
+ try {
171
+ fs.copyFileSync(stateFilePath, path.join(backupDir, backupName));
172
+ }
173
+ catch {
174
+ // non-fatal — backup is best-effort
175
+ }
176
+ roadmapState.save(prdDir, {
177
+ version: state.version,
178
+ lastScan: typeof state.lastScan === "string" ? state.lastScan : "",
179
+ items: state.items,
180
+ });
181
+ roadmapStatesMigrated++;
182
+ }
183
+ });
184
+ migrateRoadmapStates();
185
+ // --- Record completion ---
186
+ db.prepare(`INSERT OR REPLACE INTO schema_meta (key, value)
187
+ VALUES ('json_migration_completed', ?)`).run(new Date().toISOString());
188
+ return {
189
+ projectsMigrated,
190
+ historyRecordsMigrated,
191
+ prdStatesMigrated,
192
+ roadmapStatesMigrated,
193
+ backupDir,
194
+ alreadyMigrated: false,
195
+ };
196
+ }
197
+ //# sourceMappingURL=json-state-migrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-state-migrator.js","sourceRoot":"","sources":["../../src/storage/json-state-migrator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AA2B1D;;;GAGG;AACH,SAAS,WAAW,CAAI,QAAgB;IACtC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAM,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,GAAW,EAAE,SAAiB;IAChD,IAAI,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,YAAsB;IAC5C,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;QACvC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,WA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,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC;YAClG,IAAI,CAAC;gBACH,EAAE,CAAC,YAAY,CAAC,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;YACnE,CAAC;YAAC,MAAM,CAAC;gBACP,oCAAoC;YACtC,CAAC;YAED,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE;gBACxB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,QAAQ,EAAE,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;gBAClE,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB,CAAC,CAAC;YACH,qBAAqB,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,oBAAoB,EAAE,CAAC;IAEvB,4BAA4B;IAC5B,EAAE,CAAC,OAAO,CACR;4CACwC,CACzC,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IAEhC,OAAO;QACL,gBAAgB;QAChB,sBAAsB;QACtB,iBAAiB;QACjB,qBAAqB;QACrB,SAAS;QACT,eAAe,EAAE,KAAK;KACvB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Repository factory for Night Watch CLI.
3
+ * Returns singleton repository instances backed by the SQLite database.
4
+ * Migrations are applied lazily on first access.
5
+ */
6
+ import { IExecutionHistoryRepository, IPrdStateRepository, IProjectRegistryRepository, IRoadmapStateRepository } from "./interfaces.js";
7
+ export interface IRepositories {
8
+ projectRegistry: IProjectRegistryRepository;
9
+ executionHistory: IExecutionHistoryRepository;
10
+ prdState: IPrdStateRepository;
11
+ roadmapState: IRoadmapStateRepository;
12
+ }
13
+ /**
14
+ * Return the set of available repositories, initialising the database and
15
+ * running schema migrations on first call.
16
+ */
17
+ export declare function getRepositories(): IRepositories;
18
+ /**
19
+ * Reset the initialization flag.
20
+ * Primarily useful in tests when the database connection is recycled.
21
+ */
22
+ export declare function resetRepositories(): void;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/repositories/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,0BAA0B,EAC1B,uBAAuB,EACxB,MAAM,iBAAiB,CAAC;AAMzB,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,0BAA0B,CAAC;IAC5C,gBAAgB,EAAE,2BAA2B,CAAC;IAC9C,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,YAAY,EAAE,uBAAuB,CAAC;CACvC;AAID;;;GAGG;AACH,wBAAgB,eAAe,IAAI,aAAa,CAc/C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Repository factory for Night Watch CLI.
3
+ * Returns singleton repository instances backed by the SQLite database.
4
+ * Migrations are applied lazily on first access.
5
+ */
6
+ import { getDb } from "../sqlite/client.js";
7
+ import { runMigrations } from "../sqlite/migrations.js";
8
+ import { SqliteProjectRegistryRepository } from "./sqlite/project-registry-repository.js";
9
+ import { SqliteExecutionHistoryRepository } from "./sqlite/execution-history-repository.js";
10
+ import { SqlitePrdStateRepository } from "./sqlite/prd-state-repository.js";
11
+ import { SqliteRoadmapStateRepository } from "./sqlite/roadmap-state-repository.js";
12
+ let _initialized = false;
13
+ /**
14
+ * Return the set of available repositories, initialising the database and
15
+ * running schema migrations on first call.
16
+ */
17
+ export function getRepositories() {
18
+ const db = getDb();
19
+ if (!_initialized) {
20
+ runMigrations(db);
21
+ _initialized = true;
22
+ }
23
+ return {
24
+ projectRegistry: new SqliteProjectRegistryRepository(db),
25
+ executionHistory: new SqliteExecutionHistoryRepository(db),
26
+ prdState: new SqlitePrdStateRepository(db),
27
+ roadmapState: new SqliteRoadmapStateRepository(db),
28
+ };
29
+ }
30
+ /**
31
+ * Reset the initialization flag.
32
+ * Primarily useful in tests when the database connection is recycled.
33
+ */
34
+ export function resetRepositories() {
35
+ _initialized = false;
36
+ }
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/storage/repositories/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAOxD,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AASpF,IAAI,YAAY,GAAG,KAAK,CAAC;AAEzB;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;IAEnB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,aAAa,CAAC,EAAE,CAAC,CAAC;QAClB,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,OAAO;QACL,eAAe,EAAE,IAAI,+BAA+B,CAAC,EAAE,CAAC;QACxD,gBAAgB,EAAE,IAAI,gCAAgC,CAAC,EAAE,CAAC;QAC1D,QAAQ,EAAE,IAAI,wBAAwB,CAAC,EAAE,CAAC;QAC1C,YAAY,EAAE,IAAI,4BAA4B,CAAC,EAAE,CAAC;KACnD,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,YAAY,GAAG,KAAK,CAAC;AACvB,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Repository interface contracts for Night Watch CLI storage layer.
3
+ * These interfaces define the API that concrete SQLite implementations must satisfy.
4
+ */
5
+ import { IRegistryEntry } from "../../utils/registry.js";
6
+ import { IExecutionRecord } from "../../utils/execution-history.js";
7
+ import { IPrdStateEntry } from "../../utils/prd-states.js";
8
+ import { IRoadmapState } from "../../utils/roadmap-state.js";
9
+ export interface IProjectRegistryRepository {
10
+ getAll(): IRegistryEntry[];
11
+ upsert(entry: IRegistryEntry): void;
12
+ remove(path: string): boolean;
13
+ clear(): void;
14
+ }
15
+ export interface IExecutionHistoryRepository {
16
+ getRecords(projectPath: string, prdFile: string): IExecutionRecord[];
17
+ addRecord(projectPath: string, prdFile: string, record: IExecutionRecord): void;
18
+ trimRecords(projectPath: string, prdFile: string, maxCount: number): void;
19
+ getAllHistory(): Record<string, Record<string, {
20
+ records: IExecutionRecord[];
21
+ }>>;
22
+ replaceAll(history: Record<string, Record<string, {
23
+ records: IExecutionRecord[];
24
+ }>>): void;
25
+ }
26
+ export interface IPrdStateRepository {
27
+ get(projectPath: string, prdName: string): IPrdStateEntry | null;
28
+ getAll(projectPath: string): Record<string, IPrdStateEntry>;
29
+ readAll(): Record<string, Record<string, IPrdStateEntry>>;
30
+ set(projectPath: string, prdName: string, entry: IPrdStateEntry): void;
31
+ delete(projectPath: string, prdName: string): void;
32
+ }
33
+ export interface IRoadmapStateRepository {
34
+ load(prdDir: string): IRoadmapState | null;
35
+ save(prdDir: string, state: IRoadmapState): void;
36
+ }
37
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/storage/repositories/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAA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cAAc,GAAG,IAAI,CAAC;IACvE,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACpD;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAAC;IAC3C,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;CAClD"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Repository interface contracts for Night Watch CLI storage layer.
3
+ * These interfaces define the API that concrete SQLite implementations must satisfy.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/storage/repositories/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * SQLite implementation of IExecutionHistoryRepository.
3
+ * Persists execution records in the `execution_history` table.
4
+ */
5
+ import Database from "better-sqlite3";
6
+ import { IExecutionRecord } from "../../../utils/execution-history.js";
7
+ import { IExecutionHistoryRepository } from "../interfaces.js";
8
+ export declare class SqliteExecutionHistoryRepository implements IExecutionHistoryRepository {
9
+ private readonly _db;
10
+ constructor(db: Database.Database);
11
+ getRecords(projectPath: string, prdFile: string): IExecutionRecord[];
12
+ addRecord(projectPath: string, prdFile: string, record: IExecutionRecord): void;
13
+ getAllHistory(): Record<string, Record<string, {
14
+ records: IExecutionRecord[];
15
+ }>>;
16
+ replaceAll(history: Record<string, Record<string, {
17
+ records: IExecutionRecord[];
18
+ }>>): void;
19
+ trimRecords(projectPath: string, prdFile: string, maxCount: number): void;
20
+ }
21
+ //# sourceMappingURL=execution-history-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-history-repository.d.ts","sourceRoot":"","sources":["../../../../src/storage/repositories/sqlite/execution-history-repository.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAW/D,qBAAa,gCACX,YAAW,2BAA2B;IAEtC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoB;gBAE5B,EAAE,EAAE,QAAQ,CAAC,QAAQ;IAIjC,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAkBpE,SAAS,CACP,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,GACvB,IAAI;IAiBP,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,gBAAgB,EAAE,CAAA;KAAE,CAAC,CAAC;IA2BhF,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,gBAAgB,EAAE,CAAA;KAAE,CAAC,CAAC,GAAG,IAAI;IAmB1F,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;CA8B1E"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * SQLite implementation of IExecutionHistoryRepository.
3
+ * Persists execution records in the `execution_history` table.
4
+ */
5
+ export class SqliteExecutionHistoryRepository {
6
+ _db;
7
+ constructor(db) {
8
+ this._db = db;
9
+ }
10
+ getRecords(projectPath, prdFile) {
11
+ const rows = this._db
12
+ .prepare(`SELECT timestamp, outcome, exit_code, attempt
13
+ FROM execution_history
14
+ WHERE project_path = ? AND prd_file = ?
15
+ ORDER BY timestamp DESC, id DESC`)
16
+ .all(projectPath, prdFile);
17
+ return rows.map((row) => ({
18
+ timestamp: row.timestamp,
19
+ outcome: row.outcome,
20
+ exitCode: row.exit_code,
21
+ attempt: row.attempt,
22
+ }));
23
+ }
24
+ addRecord(projectPath, prdFile, record) {
25
+ this._db
26
+ .prepare(`INSERT INTO execution_history
27
+ (project_path, prd_file, timestamp, outcome, exit_code, attempt)
28
+ VALUES (?, ?, ?, ?, ?, ?)`)
29
+ .run(projectPath, prdFile, record.timestamp, record.outcome, record.exitCode, record.attempt);
30
+ }
31
+ getAllHistory() {
32
+ const rows = this._db
33
+ .prepare(`SELECT project_path, prd_file, timestamp, outcome, exit_code, attempt
34
+ FROM execution_history
35
+ ORDER BY project_path, prd_file, timestamp ASC, id ASC`)
36
+ .all();
37
+ const history = {};
38
+ for (const row of rows) {
39
+ if (!history[row.project_path]) {
40
+ history[row.project_path] = {};
41
+ }
42
+ if (!history[row.project_path][row.prd_file]) {
43
+ history[row.project_path][row.prd_file] = { records: [] };
44
+ }
45
+ history[row.project_path][row.prd_file].records.push({
46
+ timestamp: row.timestamp,
47
+ outcome: row.outcome,
48
+ exitCode: row.exit_code,
49
+ attempt: row.attempt,
50
+ });
51
+ }
52
+ return history;
53
+ }
54
+ replaceAll(history) {
55
+ const replaceAll = this._db.transaction(() => {
56
+ this._db.prepare("DELETE FROM execution_history").run();
57
+ const insert = this._db.prepare(`INSERT INTO execution_history
58
+ (project_path, prd_file, timestamp, outcome, exit_code, attempt)
59
+ VALUES (?, ?, ?, ?, ?, ?)`);
60
+ for (const [projectPath, prdMap] of Object.entries(history)) {
61
+ for (const [prdFile, prdHistory] of Object.entries(prdMap)) {
62
+ for (const record of prdHistory.records) {
63
+ insert.run(projectPath, prdFile, record.timestamp, record.outcome, record.exitCode, record.attempt);
64
+ }
65
+ }
66
+ }
67
+ });
68
+ replaceAll();
69
+ }
70
+ trimRecords(projectPath, prdFile, maxCount) {
71
+ // Count current records for this project/prd pair
72
+ const countRow = this._db
73
+ .prepare(`SELECT COUNT(*) as count
74
+ FROM execution_history
75
+ WHERE project_path = ? AND prd_file = ?`)
76
+ .get(projectPath, prdFile);
77
+ const total = countRow?.count ?? 0;
78
+ if (total <= maxCount) {
79
+ return;
80
+ }
81
+ const deleteCount = total - maxCount;
82
+ // Delete the oldest records (lowest timestamp ids)
83
+ this._db
84
+ .prepare(`DELETE FROM execution_history
85
+ WHERE id IN (
86
+ SELECT id FROM execution_history
87
+ WHERE project_path = ? AND prd_file = ?
88
+ ORDER BY timestamp ASC, id ASC
89
+ LIMIT ?
90
+ )`)
91
+ .run(projectPath, prdFile, deleteCount);
92
+ }
93
+ }
94
+ //# sourceMappingURL=execution-history-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-history-repository.js","sourceRoot":"","sources":["../../../../src/storage/repositories/sqlite/execution-history-repository.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH,MAAM,OAAO,gCAAgC;IAG1B,GAAG,CAAoB;IAExC,YAAY,EAAqB;QAC/B,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,UAAU,CAAC,WAAmB,EAAE,OAAe;QAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG;aAClB,OAAO,CACN;;;0CAGkC,CACnC;aACA,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAE7B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACxB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,OAAO,EAAE,GAAG,CAAC,OAAsC;YACnD,QAAQ,EAAE,GAAG,CAAC,SAAS;YACvB,OAAO,EAAE,GAAG,CAAC,OAAO;SACrB,CAAC,CAAC,CAAC;IACN,CAAC;IAED,SAAS,CACP,WAAmB,EACnB,OAAe,EACf,MAAwB;QAExB,IAAI,CAAC,GAAG;aACL,OAAO,CACN;;mCAE2B,CAC5B;aACA,GAAG,CACF,WAAW,EACX,OAAO,EACP,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,QAAQ,EACf,MAAM,CA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AC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC5D,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC3D,KAAK,MAAM,MAAM,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;wBACxC,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;oBACtG,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACH,UAAU,EAAE,CAAC;IACf,CAAC;IAED,WAAW,CAAC,WAAmB,EAAE,OAAe,EAAE,QAAgB;QAChE,kDAAkD;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG;aACtB,OAAO,CACN;;iDAEyC,CAC1C;aACA,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAE7B,MAAM,KAAK,GAAG,QAAQ,EAAE,KAAK,IAAI,CAAC,CAAC;QACnC,IAAI,KAAK,IAAI,QAAQ,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,MAAM,WAAW,GAAG,KAAK,GAAG,QAAQ,CAAC;QAErC,mDAAmD;QACnD,IAAI,CAAC,GAAG;aACL,OAAO,CACN;;;;;;WAMG,CACJ;aACA,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * SQLite implementation of IPrdStateRepository.
3
+ * Persists PRD state entries in the `prd_states` table.
4
+ */
5
+ import Database from "better-sqlite3";
6
+ import { IPrdStateEntry } from "../../../utils/prd-states.js";
7
+ import { IPrdStateRepository } from "../interfaces.js";
8
+ export declare class SqlitePrdStateRepository implements IPrdStateRepository {
9
+ private readonly _db;
10
+ constructor(db: Database.Database);
11
+ get(projectPath: string, prdName: string): IPrdStateEntry | null;
12
+ getAll(projectPath: string): Record<string, IPrdStateEntry>;
13
+ readAll(): Record<string, Record<string, IPrdStateEntry>>;
14
+ set(projectPath: string, prdName: string, entry: IPrdStateEntry): void;
15
+ delete(projectPath: string, prdName: string): void;
16
+ }
17
+ //# sourceMappingURL=prd-state-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prd-state-repository.d.ts","sourceRoot":"","sources":["../../../../src/storage/repositories/sqlite/prd-state-repository.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAUvD,qBAAa,wBAAyB,YAAW,mBAAmB;IAClE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoB;gBAE5B,EAAE,EAAE,QAAQ,CAAC,QAAQ;IAIjC,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAoBhE,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC;IAoB3D,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAqBzD,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,IAAI;IAatE,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;CAOnD"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * SQLite implementation of IPrdStateRepository.
3
+ * Persists PRD state entries in the `prd_states` table.
4
+ */
5
+ export class SqlitePrdStateRepository {
6
+ _db;
7
+ constructor(db) {
8
+ this._db = db;
9
+ }
10
+ get(projectPath, prdName) {
11
+ const row = this._db
12
+ .prepare(`SELECT status, branch, timestamp
13
+ FROM prd_states
14
+ WHERE project_path = ? AND prd_name = ?`)
15
+ .get(projectPath, prdName);
16
+ if (!row) {
17
+ return null;
18
+ }
19
+ return {
20
+ status: row.status,
21
+ branch: row.branch,
22
+ timestamp: row.timestamp,
23
+ };
24
+ }
25
+ getAll(projectPath) {
26
+ const rows = this._db
27
+ .prepare(`SELECT prd_name, status, branch, timestamp
28
+ FROM prd_states
29
+ WHERE project_path = ?`)
30
+ .all(projectPath);
31
+ const result = {};
32
+ for (const row of rows) {
33
+ result[row.prd_name] = {
34
+ status: row.status,
35
+ branch: row.branch,
36
+ timestamp: row.timestamp,
37
+ };
38
+ }
39
+ return result;
40
+ }
41
+ readAll() {
42
+ const rows = this._db
43
+ .prepare("SELECT project_path, prd_name, status, branch, timestamp FROM prd_states")
44
+ .all();
45
+ const result = {};
46
+ for (const row of rows) {
47
+ if (!result[row.project_path]) {
48
+ result[row.project_path] = {};
49
+ }
50
+ result[row.project_path][row.prd_name] = {
51
+ status: row.status,
52
+ branch: row.branch,
53
+ timestamp: row.timestamp,
54
+ };
55
+ }
56
+ return result;
57
+ }
58
+ set(projectPath, prdName, entry) {
59
+ this._db
60
+ .prepare(`INSERT INTO prd_states (project_path, prd_name, status, branch, timestamp)
61
+ VALUES (?, ?, ?, ?, ?)
62
+ ON CONFLICT(project_path, prd_name)
63
+ DO UPDATE SET status = excluded.status,
64
+ branch = excluded.branch,
65
+ timestamp = excluded.timestamp`)
66
+ .run(projectPath, prdName, entry.status, entry.branch, entry.timestamp);
67
+ }
68
+ delete(projectPath, prdName) {
69
+ this._db
70
+ .prepare(`DELETE FROM prd_states WHERE project_path = ? AND prd_name = ?`)
71
+ .run(projectPath, prdName);
72
+ }
73
+ }
74
+ //# sourceMappingURL=prd-state-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prd-state-repository.js","sourceRoot":"","sources":["../../../../src/storage/repositories/sqlite/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AAC;gBAC9B,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;YAChC,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG;gBACvC,MAAM,EAAE,GAAG,CAAC,MAAkC;gBAC9C,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,SAAS,EAAE,GAAG,CAAC,SAAS;aACzB,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,GAAG,CAAC,WAAmB,EAAE,OAAe,EAAE,KAAqB;QAC7D,IAAI,CAAC,GAAG;aACL,OAAO,CACN;;;;;sDAK8C,CAC/C;aACA,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC5E,CAAC;IAED,MAAM,CAAC,WAAmB,EAAE,OAAe;QACzC,IAAI,CAAC,GAAG;aACL,OAAO,CACN,gEAAgE,CACjE;aACA,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * SQLite implementation of IProjectRegistryRepository.
3
+ * Persists project registry entries in the `projects` table.
4
+ */
5
+ import Database from "better-sqlite3";
6
+ import { IRegistryEntry } from "../../../utils/registry.js";
7
+ import { IProjectRegistryRepository } from "../interfaces.js";
8
+ export declare class SqliteProjectRegistryRepository implements IProjectRegistryRepository {
9
+ private readonly _db;
10
+ constructor(db: Database.Database);
11
+ getAll(): IRegistryEntry[];
12
+ upsert(entry: IRegistryEntry): void;
13
+ remove(projectPath: string): boolean;
14
+ clear(): void;
15
+ }
16
+ //# sourceMappingURL=project-registry-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-registry-repository.d.ts","sourceRoot":"","sources":["../../../../src/storage/repositories/sqlite/project-registry-repository.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAQ9D,qBAAa,+BACX,YAAW,0BAA0B;IAErC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoB;gBAE5B,EAAE,EAAE,QAAQ,CAAC,QAAQ;IAIjC,MAAM,IAAI,cAAc,EAAE;IAQ1B,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAYnC,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAQpC,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * SQLite implementation of IProjectRegistryRepository.
3
+ * Persists project registry entries in the `projects` table.
4
+ */
5
+ export class SqliteProjectRegistryRepository {
6
+ _db;
7
+ constructor(db) {
8
+ this._db = db;
9
+ }
10
+ getAll() {
11
+ const rows = this._db
12
+ .prepare("SELECT name, path FROM projects ORDER BY name")
13
+ .all();
14
+ return rows.map((row) => ({ name: row.name, path: row.path }));
15
+ }
16
+ upsert(entry) {
17
+ const createdAt = Math.floor(Date.now() / 1000);
18
+ this._db
19
+ .prepare(`INSERT INTO projects (name, path, created_at)
20
+ VALUES (?, ?, ?)
21
+ ON CONFLICT(path) DO UPDATE SET name = excluded.name`)
22
+ .run(entry.name, entry.path, createdAt);
23
+ }
24
+ remove(projectPath) {
25
+ const result = this._db
26
+ .prepare("DELETE FROM projects WHERE path = ?")
27
+ .run(projectPath);
28
+ return result.changes > 0;
29
+ }
30
+ clear() {
31
+ this._db.prepare("DELETE FROM projects").run();
32
+ }
33
+ }
34
+ //# sourceMappingURL=project-registry-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-registry-repository.js","sourceRoot":"","sources":["../../../../src/storage/repositories/sqlite/project-registry-repository.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAaH,MAAM,OAAO,+BAA+B;IAGzB,GAAG,CAAoB;IAExC,YAAY,EAAqB;QAC/B,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,MAAM;QACJ,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG;aAClB,OAAO,CAAkB,+CAA+C,CAAC;aACzE,GAAG,EAAE,CAAC;QAET,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,CAAC,KAAqB;QAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAEhD,IAAI,CAAC,GAAG;aACL,OAAO,CACN;;8DAEsD,CACvD;aACA,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,WAAmB;QACxB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG;aACpB,OAAO,CAAW,qCAAqC,CAAC;aACxD,GAAG,CAAC,WAAW,CAAC,CAAC;QAEpB,OAAO,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,GAAG,EAAE,CAAC;IACjD,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * SQLite implementation of IRoadmapStateRepository.
3
+ * Persists roadmap state in the `roadmap_states` table, keyed by prd_dir.
4
+ */
5
+ import Database from "better-sqlite3";
6
+ import { IRoadmapState } from "../../../utils/roadmap-state.js";
7
+ import { IRoadmapStateRepository } from "../interfaces.js";
8
+ export declare class SqliteRoadmapStateRepository implements IRoadmapStateRepository {
9
+ private readonly _db;
10
+ constructor(db: Database.Database);
11
+ load(prdDir: string): IRoadmapState | null;
12
+ save(prdDir: string, state: IRoadmapState): void;
13
+ }
14
+ //# sourceMappingURL=roadmap-state-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roadmap-state-repository.d.ts","sourceRoot":"","sources":["../../../../src/storage/repositories/sqlite/roadmap-state-repository.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAS3D,qBAAa,4BAA6B,YAAW,uBAAuB;IAC1E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoB;gBAE5B,EAAE,EAAE,QAAQ,CAAC,QAAQ;IAIjC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;IA8B1C,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI;CAcjD"}