@codetreker/daynight 0.29.0 → 0.31.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 (100) hide show
  1. package/README.md +93 -30
  2. package/dist/api/index.d.ts +1 -1
  3. package/dist/api/index.js +1 -1
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/api/task-properties.d.ts +1 -0
  6. package/dist/api/task-properties.js +5 -0
  7. package/dist/api/task-properties.js.map +1 -1
  8. package/dist/commands/controller/independent.js +31 -15
  9. package/dist/commands/controller/independent.js.map +1 -1
  10. package/dist/commands/controller/journal-format.d.ts +4 -0
  11. package/dist/commands/controller/journal-format.js +42 -0
  12. package/dist/commands/controller/journal-format.js.map +1 -0
  13. package/dist/commands/controller/lifecycle-store.d.ts +7 -5
  14. package/dist/commands/controller/lifecycle-store.js +114 -85
  15. package/dist/commands/controller/lifecycle-store.js.map +1 -1
  16. package/dist/commands/controller/local-content.d.ts +10 -5
  17. package/dist/commands/controller/local-content.js +8 -2
  18. package/dist/commands/controller/local-content.js.map +1 -1
  19. package/dist/commands/controller/resume-lease-format.d.ts +4 -0
  20. package/dist/commands/controller/resume-lease-format.js +35 -0
  21. package/dist/commands/controller/resume-lease-format.js.map +1 -0
  22. package/dist/commands/controller/resume.js +85 -21
  23. package/dist/commands/controller/resume.js.map +1 -1
  24. package/dist/commands/controller/sqlite/journal/001-baseline.sql +17 -0
  25. package/dist/commands/controller/sqlite/journal/002-projection.sql +8 -0
  26. package/dist/commands/controller/sqlite/journal/003-operation-acknowledgements.sql +1 -0
  27. package/dist/commands/controller/sqlite/journal/004-projection-gap.sql +1 -0
  28. package/dist/commands/controller/sqlite/journal/005-resources.sql +7 -0
  29. package/dist/commands/controller/sqlite/resume-lease/001-baseline.sql +7 -0
  30. package/dist/commands/review/listing.js +1 -1
  31. package/dist/commands/review/listing.js.map +1 -1
  32. package/dist/commands/review/runtime.js +3 -1
  33. package/dist/commands/review/runtime.js.map +1 -1
  34. package/dist/commands/review/sqlite/001-baseline.sql +65 -0
  35. package/dist/commands/review/sqlite/002-publications.sql +15 -0
  36. package/dist/commands/review/store-format.d.ts +2 -0
  37. package/dist/commands/review/store-format.js +35 -0
  38. package/dist/commands/review/store-format.js.map +1 -0
  39. package/dist/commands/review/store.d.ts +8 -1
  40. package/dist/commands/review/store.js +46 -176
  41. package/dist/commands/review/store.js.map +1 -1
  42. package/dist/commands/skill/skills/using-daynight/references/autopilot-managed-task.md +19 -7
  43. package/dist/commands/worker/backends/sqlite/001-baseline.sql +4 -0
  44. package/dist/commands/worker/backends/web-process.js +6 -3
  45. package/dist/commands/worker/backends/web-process.js.map +1 -1
  46. package/dist/commands/worker/backends/web-record.d.ts +11 -0
  47. package/dist/commands/worker/backends/web-record.js +151 -0
  48. package/dist/commands/worker/backends/web-record.js.map +1 -0
  49. package/dist/commands/worker/backends/web-store-format.d.ts +2 -0
  50. package/dist/commands/worker/backends/web-store-format.js +33 -0
  51. package/dist/commands/worker/backends/web-store-format.js.map +1 -0
  52. package/dist/commands/worker/backends/web-store.d.ts +4 -1
  53. package/dist/commands/worker/backends/web-store.js +43 -170
  54. package/dist/commands/worker/backends/web-store.js.map +1 -1
  55. package/dist/commands/worker/backends/web.js +5 -4
  56. package/dist/commands/worker/backends/web.js.map +1 -1
  57. package/dist/commands/worker/cleanup.d.ts +1 -1
  58. package/dist/commands/worker/cleanup.js.map +1 -1
  59. package/dist/commands/worker/coordinator.js +1 -1
  60. package/dist/commands/worker/coordinator.js.map +1 -1
  61. package/dist/commands/worker/diagnostics.d.ts +3 -0
  62. package/dist/commands/worker/diagnostics.js +15 -0
  63. package/dist/commands/worker/diagnostics.js.map +1 -1
  64. package/dist/commands/worker/execution.d.ts +2 -0
  65. package/dist/commands/worker/execution.js +17 -4
  66. package/dist/commands/worker/execution.js.map +1 -1
  67. package/dist/commands/worker/herdr/agents.d.ts +6 -1
  68. package/dist/commands/worker/herdr/agents.js +8 -3
  69. package/dist/commands/worker/herdr/agents.js.map +1 -1
  70. package/dist/commands/worker/herdr.d.ts +2 -2
  71. package/dist/commands/worker/herdr.js.map +1 -1
  72. package/dist/commands/worker/prompts.js +7 -2
  73. package/dist/commands/worker/prompts.js.map +1 -1
  74. package/dist/commands/worker/runtime.js +8 -3
  75. package/dist/commands/worker/runtime.js.map +1 -1
  76. package/dist/commands/worker/sqlite/005-baseline.sql +18 -0
  77. package/dist/commands/worker/store-format.d.ts +2 -0
  78. package/dist/commands/worker/store-format.js +35 -0
  79. package/dist/commands/worker/store-format.js.map +1 -0
  80. package/dist/commands/worker/store.d.ts +2 -0
  81. package/dist/commands/worker/store.js +36 -69
  82. package/dist/commands/worker/store.js.map +1 -1
  83. package/dist/platform/diagnostics.js +3 -0
  84. package/dist/platform/diagnostics.js.map +1 -1
  85. package/dist/platform/instance-lock.d.ts +15 -0
  86. package/dist/platform/instance-lock.js +45 -3
  87. package/dist/platform/instance-lock.js.map +1 -1
  88. package/dist/platform/sqlite-access.d.ts +40 -0
  89. package/dist/platform/sqlite-access.js +333 -0
  90. package/dist/platform/sqlite-access.js.map +1 -0
  91. package/dist/platform/sqlite-error.d.ts +39 -0
  92. package/dist/platform/sqlite-error.js +36 -0
  93. package/dist/platform/sqlite-error.js.map +1 -0
  94. package/dist/platform/sqlite-format.d.ts +31 -0
  95. package/dist/platform/sqlite-format.js +98 -0
  96. package/dist/platform/sqlite-format.js.map +1 -0
  97. package/dist/platform/sqlite-sql.d.ts +12 -0
  98. package/dist/platform/sqlite-sql.js +61 -0
  99. package/dist/platform/sqlite-sql.js.map +1 -0
  100. package/package.json +3 -3
@@ -0,0 +1,36 @@
1
+ export class SqliteAccessError extends Error {
2
+ kind;
3
+ context;
4
+ outcome;
5
+ connectionClosed;
6
+ constructor(kind, context, options = {}) {
7
+ const versions = context.fromVersion === undefined ? "" : ` from version ${context.fromVersion}${context.toVersion === undefined ? "" : ` to ${context.toVersion}`}`;
8
+ super(`SQLite ${context.database} ${context.phase}${versions}: ${kind}.`, options.cause === undefined ? undefined : { cause: options.cause });
9
+ this.name = "SqliteAccessError";
10
+ this.kind = kind;
11
+ this.context = context;
12
+ this.outcome = options.outcome === undefined ? "not-started" : options.outcome;
13
+ this.connectionClosed = options.connectionClosed === true;
14
+ }
15
+ }
16
+ const safeCode = (error) => {
17
+ if (typeof error !== "object" || error === null || !("code" in error) || typeof error.code !== "string")
18
+ return undefined;
19
+ return /^(SQLITE_[A-Z_]+|E[A-Z0-9]+)$/.test(error.code) ? error.code : undefined;
20
+ };
21
+ /** Raw parser and SQLite messages can contain stored values; retain them only in memory. */
22
+ export const serializeSqliteError = (error, depth = 0) => {
23
+ const code = safeCode(error);
24
+ const base = { name: error instanceof Error ? error.name : "UnknownError", ...(code === undefined ? {} : { sqliteCode: code }) };
25
+ if (error instanceof SqliteAccessError)
26
+ Object.assign(base, { kind: error.kind, message: error.message, ...error.context, outcome: error.outcome });
27
+ if (depth < 6 && error instanceof Error) {
28
+ if (error.cause !== undefined)
29
+ base.cause = serializeSqliteError(error.cause, depth + 1);
30
+ if (error instanceof AggregateError)
31
+ base.errors = error.errors.map((item) => serializeSqliteError(item, depth + 1));
32
+ }
33
+ return base;
34
+ };
35
+ export const formatSqliteError = (error) => JSON.stringify(serializeSqliteError(error));
36
+ //# sourceMappingURL=sqlite-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-error.js","sourceRoot":"","sources":["../../src/platform/sqlite-error.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,CAAkB;IACtB,OAAO,CAAqB;IAC5B,OAAO,CAAgB;IACvB,gBAAgB,CAAU;IACnC,YAAY,IAAqB,EAAE,OAA2B,EAAE,OAAO,GAA6E,EAAE;QACpJ,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,SAAS,KAAK,S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,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,EAAE,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAClJ,IAAI,KAAK,YAAY,iBAAiB;QAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACpJ,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QACxC,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,oBAAoB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QACzF,IAAI,KAAK,YAAY,cAAc;YAAE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAa,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;IAChI,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAwB,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type Database from "better-sqlite3";
2
+ export type SqliteMigration = {
3
+ readonly toVersion: number;
4
+ readonly up: (db: Database.Database) => undefined;
5
+ };
6
+ export type SqliteFormat = {
7
+ readonly name: string;
8
+ readonly baseline: {
9
+ readonly version: number;
10
+ readonly create: (db: Database.Database) => undefined;
11
+ };
12
+ readonly migrations: readonly SqliteMigration[];
13
+ readonly validateVersioned: (db: Database.Database, version: number) => undefined;
14
+ };
15
+ export type SqliteSource = {
16
+ readonly kind: "empty" | "unversioned";
17
+ readonly version: 0;
18
+ } | {
19
+ readonly kind: "outdated" | "current";
20
+ readonly version: number;
21
+ };
22
+ export type SqliteTransition = {
23
+ readonly fromVersion: number;
24
+ readonly toVersion: number;
25
+ readonly initialized: boolean;
26
+ readonly reset: boolean;
27
+ };
28
+ export declare const currentSqliteVersion: (format: SqliteFormat) => number;
29
+ export declare const inspectSqlite: (db: Database.Database, format: SqliteFormat) => SqliteSource;
30
+ export declare const assertCurrentSqlite: (db: Database.Database, format: SqliteFormat) => undefined;
31
+ export declare const upgradeSqlite: (db: Database.Database, format: SqliteFormat) => SqliteTransition | null;
@@ -0,0 +1,98 @@
1
+ import { SqliteAccessError } from "./sqlite-error.js";
2
+ const validVersion = (value) => Number.isInteger(value) && value > 0 && value <= 2_147_483_647;
3
+ export const currentSqliteVersion = (format) => {
4
+ if (!validVersion(format.baseline.version))
5
+ throw new TypeError("SQLite baseline must be a positive signed 32-bit integer.");
6
+ let current = format.baseline.version;
7
+ for (const migration of format.migrations) {
8
+ if (!validVersion(migration.toVersion) || migration.toVersion !== current + 1)
9
+ throw new TypeError("SQLite migration versions must be consecutive after the baseline.");
10
+ current = migration.toVersion;
11
+ }
12
+ return current;
13
+ };
14
+ const versionOf = (db) => db.pragma("user_version", { simple: true });
15
+ const invalid = (format, version, cause) => new SqliteAccessError("invalid-format", { database: format.name, phase: "inspect", fromVersion: version, toVersion: currentSqliteVersion(format) }, cause === undefined ? {} : { cause });
16
+ export const inspectSqlite = (db, format) => {
17
+ const target = currentSqliteVersion(format), version = versionOf(db);
18
+ if (!Number.isInteger(version) || version < 0 || version > target || version !== 0 && version < format.baseline.version)
19
+ throw new SqliteAccessError("unsupported-version", { database: format.name, phase: "inspect", fromVersion: version, toVersion: target });
20
+ try {
21
+ if (version === 0) {
22
+ const objects = db.prepare("SELECT name FROM sqlite_schema WHERE name NOT GLOB 'sqlite_*'").all();
23
+ return { kind: objects.length === 0 ? "empty" : "unversioned", version: 0 };
24
+ }
25
+ format.validateVersioned(db, version);
26
+ return { kind: version === target ? "current" : "outdated", version };
27
+ }
28
+ catch (cause) {
29
+ if (cause instanceof SqliteAccessError)
30
+ throw cause;
31
+ throw invalid(format, version, cause);
32
+ }
33
+ };
34
+ export const assertCurrentSqlite = (db, format) => {
35
+ if (!db.inTransaction)
36
+ throw new Error("SQLite format assertion requires a transaction.");
37
+ const version = versionOf(db), target = currentSqliteVersion(format);
38
+ if (version !== target)
39
+ throw new SqliteAccessError("unsupported-version", { database: format.name, phase: "assert-current", fromVersion: version, toVersion: target });
40
+ };
41
+ const quoteIdentifier = (name) => `"${name.replaceAll('"', '""')}"`;
42
+ const resetUnversionedSqlite = (db) => {
43
+ if (db.pragma("foreign_keys", { simple: true }) !== 0)
44
+ throw new Error("SQLite unversioned reset requires foreign_keys=OFF before beginning the transaction.");
45
+ const objects = db.prepare("SELECT name, type FROM main.sqlite_schema WHERE type IN ('trigger', 'view') AND name NOT GLOB 'sqlite_*' ORDER BY type, name").all();
46
+ for (const object of objects)
47
+ db.exec(`DROP ${object.type.toUpperCase()} main.${quoteIdentifier(object.name)}`);
48
+ const virtualTables = db.pragma("main.table_list")
49
+ .filter(table => table.schema === "main" && !table.name.startsWith("sqlite_") && table.type === "virtual");
50
+ for (const table of virtualTables)
51
+ db.exec(`DROP TABLE main.${quoteIdentifier(table.name)}`);
52
+ if (virtualTables.length !== 0) {
53
+ // FTS5 external content can retain its cached shadow flag after its virtual table is dropped.
54
+ // RESET reloads the schema and keeps schema writes disabled: https://sqlite.org/pragma.html#pragma_writable_schema
55
+ db.pragma("writable_schema = RESET");
56
+ }
57
+ const tables = db.pragma("main.table_list")
58
+ .filter(table => table.schema === "main" && !table.name.startsWith("sqlite_") && (table.type === "table" || table.type === "shadow"));
59
+ for (const table of tables)
60
+ db.exec(`DROP TABLE main.${quoteIdentifier(table.name)}`);
61
+ };
62
+ export const upgradeSqlite = (db, format) => {
63
+ if (!db.inTransaction)
64
+ throw new Error("SQLite migration requires an immediate transaction.");
65
+ const source = inspectSqlite(db, format);
66
+ if (source.kind === "current")
67
+ return null;
68
+ let version = source.version;
69
+ if (source.kind === "empty" || source.kind === "unversioned") {
70
+ try {
71
+ if (source.kind === "unversioned")
72
+ resetUnversionedSqlite(db);
73
+ format.baseline.create(db);
74
+ format.validateVersioned(db, format.baseline.version);
75
+ db.pragma(`user_version = ${format.baseline.version}`);
76
+ version = format.baseline.version;
77
+ }
78
+ catch (cause) {
79
+ throw new SqliteAccessError("migration-failed", { database: format.name, phase: source.kind === "empty" ? "initialize" : "reset", fromVersion: source.version, toVersion: currentSqliteVersion(format), stepVersion: format.baseline.version }, { cause, outcome: "unknown" });
80
+ }
81
+ }
82
+ for (const migration of format.migrations) {
83
+ if (migration.toVersion <= version)
84
+ continue;
85
+ try {
86
+ migration.up(db);
87
+ format.validateVersioned(db, migration.toVersion);
88
+ db.pragma(`user_version = ${migration.toVersion}`);
89
+ version = migration.toVersion;
90
+ }
91
+ catch (cause) {
92
+ throw new SqliteAccessError("migration-failed", { database: format.name, phase: "migrate", fromVersion: source.version, toVersion: currentSqliteVersion(format), stepVersion: migration.toVersion }, { cause, outcome: "unknown" });
93
+ }
94
+ }
95
+ format.validateVersioned(db, version);
96
+ return { fromVersion: source.version, toVersion: version, initialized: source.kind === "empty", reset: source.kind === "unversioned" };
97
+ };
98
+ //# sourceMappingURL=sqlite-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-format.js","sourceRoot":"","sources":["../../src/platform/sqlite-format.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAYtD,MAAM,YAAY,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,I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M,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QACtO,CAAC;IACH,CAAC;IACD,MAAM,CAAC,iBAAiB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACtC,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;AACzI,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ export type SqliteSchemaObject = {
2
+ readonly name: string;
3
+ readonly type: string;
4
+ readonly sql: string | null;
5
+ };
6
+ export type SqliteSchemaStep = {
7
+ readonly version: number;
8
+ readonly sql: string;
9
+ };
10
+ export declare const loadSqliteSql: (resource: URL) => string;
11
+ export declare const loadSqliteSequence: (directory: URL) => readonly [SqliteSchemaStep, ...SqliteSchemaStep[]];
12
+ export declare const sqliteSchemaSnapshots: (steps: readonly SqliteSchemaStep[]) => ReadonlyMap<number, readonly SqliteSchemaObject[]>;
@@ -0,0 +1,61 @@
1
+ import { readFileSync, readdirSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
+ import Database from "better-sqlite3";
5
+ export const loadSqliteSql = (resource) => {
6
+ const sql = readFileSync(resource, "utf8");
7
+ if (sql.trim().length === 0)
8
+ throw new Error(`SQLite SQL resource is empty: ${resource.href}`);
9
+ return sql;
10
+ };
11
+ export const loadSqliteSequence = (directory) => {
12
+ const files = readdirSync(directory, { withFileTypes: true }).filter(entry => entry.name.toLowerCase().endsWith(".sql")).sort((a, b) => a.name < b.name ? -1 : a.name === b.name ? 0 : 1);
13
+ if (files.length === 0)
14
+ throw new Error(`SQLite SQL sequence is empty: ${directory.href}`);
15
+ let width, previous;
16
+ const resources = files.map(entry => {
17
+ const resource = pathToFileURL(path.join(fileURLToPath(directory), entry.name));
18
+ const match = /^([0-9]{3,})-([a-z][a-z0-9]*(?:-[a-z0-9]+)*)\.sql$/.exec(entry.name);
19
+ if (!entry.isFile() || match === null)
20
+ throw new Error(`Invalid SQLite SQL filename: ${resource.href}`);
21
+ const prefix = match[1], version = Number(prefix);
22
+ if (!Number.isInteger(version) || version < 1 || version > 2_147_483_647)
23
+ throw new Error(`SQLite SQL version must be a positive signed 32-bit integer: ${resource.href}`);
24
+ if (width !== undefined && prefix.length !== width)
25
+ throw new Error(`SQLite SQL version prefixes must use the same zero-padding width: ${resource.href}`);
26
+ if (version === previous)
27
+ throw new Error(`Duplicate SQLite SQL version: ${resource.href}`);
28
+ if (previous !== undefined && version !== previous + 1)
29
+ throw new Error(`SQLite SQL versions must be consecutive after the baseline: ${resource.href}`);
30
+ width = prefix.length;
31
+ previous = version;
32
+ return { version, resource };
33
+ });
34
+ const steps = resources.map(({ version, resource }) => Object.freeze({ version, sql: loadSqliteSql(resource) }));
35
+ return Object.freeze(steps);
36
+ };
37
+ export const sqliteSchemaSnapshots = (steps) => {
38
+ const db = new Database(":memory:"), snapshots = new Map();
39
+ let failed = false, failure;
40
+ try {
41
+ for (const step of steps) {
42
+ db.exec(step.sql);
43
+ const objects = db.prepare("SELECT name, type, sql FROM sqlite_schema WHERE name NOT GLOB 'sqlite_*' ORDER BY name").all();
44
+ snapshots.set(step.version, Object.freeze(objects.map(object => Object.freeze(object))));
45
+ }
46
+ }
47
+ catch (cause) {
48
+ failed = true;
49
+ failure = cause;
50
+ }
51
+ try {
52
+ db.close();
53
+ }
54
+ catch (close) {
55
+ throw failed ? new AggregateError([failure, close], "SQLite reference schema construction and connection shutdown failed.") : close;
56
+ }
57
+ if (failed)
58
+ throw failure;
59
+ return snapshots;
60
+ };
61
+ //# sourceMappingURL=sqlite-sql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-sql.js","sourceRoot":"","sources":["../../src/platform/sql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AC,CAAC;IACtJ,IAAI,MAAM;QAAE,MAAM,OAAO,CAAC;IAC1B,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codetreker/daynight",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "description": "A client command toolkit for development workflows",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,7 +20,7 @@
20
20
  "node": ">=22"
21
21
  },
22
22
  "scripts": {
23
- "build": "node scripts/clean-dist.ts && tsc -p tsconfig.build.json && node scripts/copy-skills.ts",
23
+ "build": "node scripts/clean-dist.ts && tsc -p tsconfig.build.json && node scripts/copy-resources.ts",
24
24
  "typecheck": "tsc --noEmit",
25
25
  "test": "pnpm run build && vitest run",
26
26
  "test:apfs": "DAYNIGHT_TEST_APFS=1 vitest run test/commands/review/apfs.test.ts",
@@ -54,5 +54,5 @@
54
54
  "vite": "8.3.4",
55
55
  "vitest": "5.0.5"
56
56
  },
57
- "gitHead": "829423d4ac66f9228b0f28b3095eb4c06437e5b3"
57
+ "gitHead": "4fde16f3609bcaf91f3f7bbedb68df2665744db8"
58
58
  }