clawvault 3.0.0 → 3.2.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 +352 -20
- package/bin/clawvault.js +8 -2
- package/bin/command-registration.test.js +3 -1
- package/bin/command-runtime.js +9 -1
- package/bin/register-core-commands.js +23 -10
- package/bin/register-maintenance-commands.js +39 -3
- package/bin/register-query-commands.js +58 -29
- package/bin/register-task-commands.js +18 -1
- package/bin/register-task-commands.test.js +16 -0
- package/bin/register-vault-operations-commands.js +29 -1
- package/bin/register-workgraph-commands.js +1368 -0
- package/dashboard/lib/graph-diff.js +104 -0
- package/dashboard/lib/graph-diff.test.js +75 -0
- package/dashboard/lib/vault-parser.js +556 -0
- package/dashboard/lib/vault-parser.test.js +254 -0
- package/dashboard/public/app.js +796 -0
- package/dashboard/public/index.html +52 -0
- package/dashboard/public/styles.css +221 -0
- package/dashboard/server.js +374 -0
- package/dist/{chunk-F2JEUD4J.js → chunk-23YDQ3QU.js} +6 -8
- package/dist/{chunk-C7OK5WKP.js → chunk-2JQ3O2YL.js} +4 -4
- package/dist/{chunk-VR5NE7PZ.js → chunk-2RAZ4ZFE.js} +1 -1
- package/dist/chunk-2ZDO52B4.js +52 -0
- package/dist/{chunk-ZZA73MFY.js → chunk-33DOSHTA.js} +176 -36
- package/dist/chunk-33VSQP4J.js +37 -0
- package/dist/chunk-4BQTQMJP.js +93 -0
- package/dist/{chunk-GUKMRGM7.js → chunk-4OXMU5S2.js} +1 -1
- package/dist/{chunk-62YTUT6J.js → chunk-4PY655YM.js} +15 -3
- package/dist/chunk-6FH3IULF.js +352 -0
- package/dist/{chunk-3NSBOUT3.js → chunk-77Q5CSPJ.js} +404 -80
- package/dist/{chunk-4VQTUVH7.js → chunk-7YZWHM36.js} +52 -26
- package/dist/chunk-BSJ6RIT7.js +447 -0
- package/dist/chunk-BUEW6IIK.js +364 -0
- package/dist/{chunk-WGRQ6HDV.js → chunk-CLJTREDS.js} +74 -14
- package/dist/chunk-EK6S23ZB.js +469 -0
- package/dist/{chunk-LNJA2UGL.js → chunk-ESFLMDRB.js} +9 -86
- package/dist/{chunk-H34S76MB.js → chunk-ESVS6K2B.js} +6 -6
- package/dist/{chunk-WAZ3NLWL.js → chunk-F55HGNU4.js} +0 -47
- package/dist/{chunk-QK3UCXWL.js → chunk-FHFUXL6G.js} +2 -2
- package/dist/{chunk-YKTA5JOJ.js → chunk-GAOWA7GR.js} +212 -46
- package/dist/chunk-GGA32J2R.js +784 -0
- package/dist/chunk-GNJL4YGR.js +79 -0
- package/dist/chunk-MDIH26GC.js +183 -0
- package/dist/{chunk-LYHGEHXG.js → chunk-MFAWT5O5.js} +0 -1
- package/dist/chunk-MM6QGW3P.js +207 -0
- package/dist/{chunk-P5EPF6MB.js → chunk-MW5C6ZQA.js} +110 -13
- package/dist/chunk-NCKFNBHJ.js +257 -0
- package/dist/{chunk-QBLMXKF2.js → chunk-OIWVQYQF.js} +1 -1
- package/dist/{chunk-42MXU7A6.js → chunk-P62WHA27.js} +58 -47
- package/dist/chunk-PBACDKKP.js +66 -0
- package/dist/{chunk-VGLOTGAS.js → chunk-QSHD36LH.js} +2 -2
- package/dist/{chunk-OZ7RIXTO.js → chunk-QSRRMEYM.js} +2 -2
- package/dist/chunk-QVEERJSP.js +152 -0
- package/dist/{chunk-N2AXRYLC.js → chunk-QWQ3TIKS.js} +1 -1
- package/dist/{chunk-3DHXQHYG.js → chunk-R2MIW5G7.js} +1 -1
- package/dist/{chunk-SJSFRIYS.js → chunk-SLXOR3CC.js} +2 -2
- package/dist/chunk-SS4B7P7V.js +99 -0
- package/dist/{chunk-JY6FYXIT.js → chunk-STCQGCEQ.js} +6 -11
- package/dist/chunk-U4O6C46S.js +154 -0
- package/dist/{chunk-ITPEXLHA.js → chunk-URXDAUVH.js} +24 -5
- package/dist/chunk-VSL7KY3M.js +189 -0
- package/dist/{chunk-U55BGUAU.js → chunk-W4SPAEE7.js} +6 -6
- package/dist/chunk-WMGIIABP.js +15 -0
- package/dist/{chunk-3D6BCTP6.js → chunk-X3SPPUFG.js} +51 -39
- package/dist/{chunk-THRJVD4L.js → chunk-Y6VJKXGL.js} +1 -1
- package/dist/{chunk-ZVVFWOLW.js → chunk-ZN54U2OZ.js} +123 -10
- package/dist/cli/index.js +32 -25
- package/dist/commands/archive.js +3 -3
- package/dist/commands/backlog.js +3 -3
- package/dist/commands/blocked.js +3 -3
- package/dist/commands/canvas.d.ts +15 -0
- package/dist/commands/canvas.js +200 -0
- package/dist/commands/checkpoint.js +2 -2
- package/dist/commands/compat.js +2 -2
- package/dist/commands/context.js +8 -6
- package/dist/commands/doctor.d.ts +11 -7
- package/dist/commands/doctor.js +18 -16
- package/dist/commands/embed.js +5 -6
- package/dist/commands/entities.js +2 -2
- package/dist/commands/graph.js +4 -4
- package/dist/commands/inject.d.ts +1 -1
- package/dist/commands/inject.js +5 -6
- package/dist/commands/kanban.js +4 -4
- package/dist/commands/link.js +5 -5
- package/dist/commands/migrate-observations.js +4 -4
- package/dist/commands/observe.d.ts +0 -1
- package/dist/commands/observe.js +14 -13
- package/dist/commands/project.js +5 -5
- package/dist/commands/rebuild-embeddings.d.ts +21 -0
- package/dist/commands/rebuild-embeddings.js +91 -0
- package/dist/commands/rebuild.js +12 -11
- package/dist/commands/recover.js +3 -3
- package/dist/commands/reflect.js +6 -7
- package/dist/commands/repair-session.js +1 -1
- package/dist/commands/replay.js +14 -14
- package/dist/commands/session-recap.js +1 -1
- package/dist/commands/setup.d.ts +2 -90
- package/dist/commands/setup.js +3 -21
- package/dist/commands/shell-init.js +1 -1
- package/dist/commands/sleep.d.ts +1 -1
- package/dist/commands/sleep.js +20 -19
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +57 -35
- package/dist/commands/sync-bd.d.ts +10 -0
- package/dist/commands/sync-bd.js +10 -0
- package/dist/commands/tailscale.js +3 -3
- package/dist/commands/task.js +4 -4
- package/dist/commands/template.js +2 -2
- package/dist/commands/wake.d.ts +1 -1
- package/dist/commands/wake.js +11 -10
- package/dist/commands/workgraph.d.ts +124 -0
- package/dist/commands/workgraph.js +38 -0
- package/dist/index.d.ts +337 -191
- package/dist/index.js +387 -118
- package/dist/{inject-Bzi5E-By.d.cts → inject-DYUrDqQO.d.ts} +3 -3
- package/dist/ledger-B7g7jhqG.d.ts +44 -0
- package/dist/lib/auto-linker.js +2 -2
- package/dist/lib/canvas-layout.d.ts +100 -16
- package/dist/lib/canvas-layout.js +21 -78
- package/dist/lib/config.d.ts +27 -3
- package/dist/lib/config.js +4 -2
- package/dist/lib/entity-index.js +1 -1
- package/dist/lib/project-utils.js +4 -4
- package/dist/lib/session-repair.js +1 -1
- package/dist/lib/session-utils.js +1 -1
- package/dist/lib/tailscale.js +1 -1
- package/dist/lib/task-utils.js +3 -3
- package/dist/lib/template-engine.js +1 -1
- package/dist/lib/webdav.js +1 -1
- package/dist/onnxruntime_binding-5QEF3SUC.node +0 -0
- package/dist/onnxruntime_binding-BKPKNEGC.node +0 -0
- package/dist/onnxruntime_binding-FMOXGIUT.node +0 -0
- package/dist/onnxruntime_binding-OI2KMXC5.node +0 -0
- package/dist/onnxruntime_binding-UX44MLAZ.node +0 -0
- package/dist/onnxruntime_binding-Y2W7N7WY.node +0 -0
- package/dist/openclaw-plugin.d.ts +8 -0
- package/dist/openclaw-plugin.js +14 -0
- package/dist/registry-BR4326o0.d.ts +30 -0
- package/dist/store-CA-6sKCJ.d.ts +34 -0
- package/dist/thread-B9LhXNU0.d.ts +41 -0
- package/dist/transformers.node-A2ZRORSQ.js +46775 -0
- package/dist/{types-Y2_Um2Ls.d.cts → types-BbWJoC1c.d.ts} +1 -44
- package/dist/workgraph/index.d.ts +5 -0
- package/dist/workgraph/index.js +23 -0
- package/dist/workgraph/ledger.d.ts +2 -0
- package/dist/workgraph/ledger.js +25 -0
- package/dist/workgraph/registry.d.ts +2 -0
- package/dist/workgraph/registry.js +19 -0
- package/dist/workgraph/store.d.ts +2 -0
- package/dist/workgraph/store.js +25 -0
- package/dist/workgraph/thread.d.ts +2 -0
- package/dist/workgraph/thread.js +25 -0
- package/dist/workgraph/types.d.ts +54 -0
- package/dist/workgraph/types.js +7 -0
- package/hooks/clawvault/HOOK.md +34 -4
- package/hooks/clawvault/handler.js +760 -78
- package/hooks/clawvault/handler.test.js +235 -79
- package/hooks/clawvault/openclaw.plugin.json +72 -0
- package/openclaw.plugin.json +65 -38
- package/package.json +15 -18
- package/dist/chunk-3RG5ZIWI.js +0 -10
- package/dist/chunk-6U6MK36V.js +0 -205
- package/dist/chunk-7R7O6STJ.js +0 -88
- package/dist/chunk-CMB7UL7C.js +0 -327
- package/dist/chunk-DEFFDRVP.js +0 -938
- package/dist/chunk-E7MFQB6D.js +0 -163
- package/dist/chunk-GAJV4IGR.js +0 -82
- package/dist/chunk-GQSLDZTS.js +0 -560
- package/dist/chunk-K234IDRJ.js +0 -1073
- package/dist/chunk-MFM6K7PU.js +0 -374
- package/dist/chunk-MXSSG3QU.js +0 -42
- package/dist/chunk-PAH27GSN.js +0 -108
- package/dist/cli/index.cjs +0 -10033
- package/dist/cli/index.d.cts +0 -5
- package/dist/commands/archive.cjs +0 -287
- package/dist/commands/archive.d.cts +0 -11
- package/dist/commands/backlog.cjs +0 -721
- package/dist/commands/backlog.d.cts +0 -53
- package/dist/commands/blocked.cjs +0 -204
- package/dist/commands/blocked.d.cts +0 -26
- package/dist/commands/checkpoint.cjs +0 -244
- package/dist/commands/checkpoint.d.cts +0 -41
- package/dist/commands/compat.cjs +0 -369
- package/dist/commands/compat.d.cts +0 -28
- package/dist/commands/context.cjs +0 -2989
- package/dist/commands/context.d.cts +0 -2
- package/dist/commands/doctor.cjs +0 -3062
- package/dist/commands/doctor.d.cts +0 -21
- package/dist/commands/embed.cjs +0 -232
- package/dist/commands/embed.d.cts +0 -17
- package/dist/commands/entities.cjs +0 -141
- package/dist/commands/entities.d.cts +0 -7
- package/dist/commands/graph.cjs +0 -501
- package/dist/commands/graph.d.cts +0 -21
- package/dist/commands/inject.cjs +0 -1636
- package/dist/commands/inject.d.cts +0 -2
- package/dist/commands/kanban.cjs +0 -884
- package/dist/commands/kanban.d.cts +0 -63
- package/dist/commands/link.cjs +0 -965
- package/dist/commands/link.d.cts +0 -11
- package/dist/commands/migrate-observations.cjs +0 -362
- package/dist/commands/migrate-observations.d.cts +0 -19
- package/dist/commands/observe.cjs +0 -4099
- package/dist/commands/observe.d.cts +0 -23
- package/dist/commands/project.cjs +0 -1341
- package/dist/commands/project.d.cts +0 -85
- package/dist/commands/rebuild.cjs +0 -3136
- package/dist/commands/rebuild.d.cts +0 -11
- package/dist/commands/recover.cjs +0 -361
- package/dist/commands/recover.d.cts +0 -38
- package/dist/commands/reflect.cjs +0 -1008
- package/dist/commands/reflect.d.cts +0 -11
- package/dist/commands/repair-session.cjs +0 -457
- package/dist/commands/repair-session.d.cts +0 -38
- package/dist/commands/replay.cjs +0 -4103
- package/dist/commands/replay.d.cts +0 -16
- package/dist/commands/session-recap.cjs +0 -353
- package/dist/commands/session-recap.d.cts +0 -27
- package/dist/commands/setup.cjs +0 -1345
- package/dist/commands/setup.d.cts +0 -100
- package/dist/commands/shell-init.cjs +0 -75
- package/dist/commands/shell-init.d.cts +0 -7
- package/dist/commands/sleep.cjs +0 -6028
- package/dist/commands/sleep.d.cts +0 -36
- package/dist/commands/status.cjs +0 -2736
- package/dist/commands/status.d.cts +0 -52
- package/dist/commands/tailscale.cjs +0 -1532
- package/dist/commands/tailscale.d.cts +0 -52
- package/dist/commands/task.cjs +0 -1236
- package/dist/commands/task.d.cts +0 -97
- package/dist/commands/template.cjs +0 -457
- package/dist/commands/template.d.cts +0 -36
- package/dist/commands/wake.cjs +0 -2626
- package/dist/commands/wake.d.cts +0 -22
- package/dist/context-BUGaWpyL.d.cts +0 -46
- package/dist/index.cjs +0 -14526
- package/dist/index.d.cts +0 -858
- package/dist/inject-Bzi5E-By.d.ts +0 -137
- package/dist/lib/auto-linker.cjs +0 -176
- package/dist/lib/auto-linker.d.cts +0 -26
- package/dist/lib/canvas-layout.cjs +0 -136
- package/dist/lib/canvas-layout.d.cts +0 -31
- package/dist/lib/config.cjs +0 -78
- package/dist/lib/config.d.cts +0 -11
- package/dist/lib/entity-index.cjs +0 -84
- package/dist/lib/entity-index.d.cts +0 -26
- package/dist/lib/project-utils.cjs +0 -864
- package/dist/lib/project-utils.d.cts +0 -97
- package/dist/lib/session-repair.cjs +0 -239
- package/dist/lib/session-repair.d.cts +0 -110
- package/dist/lib/session-utils.cjs +0 -209
- package/dist/lib/session-utils.d.cts +0 -63
- package/dist/lib/tailscale.cjs +0 -1183
- package/dist/lib/tailscale.d.cts +0 -225
- package/dist/lib/task-utils.cjs +0 -1137
- package/dist/lib/task-utils.d.cts +0 -208
- package/dist/lib/template-engine.cjs +0 -47
- package/dist/lib/template-engine.d.cts +0 -11
- package/dist/lib/webdav.cjs +0 -568
- package/dist/lib/webdav.d.cts +0 -109
- package/dist/plugin/index.cjs +0 -1907
- package/dist/plugin/index.d.cts +0 -36
- package/dist/plugin/index.d.ts +0 -36
- package/dist/plugin/index.js +0 -572
- package/dist/plugin/inject.cjs +0 -356
- package/dist/plugin/inject.d.cts +0 -54
- package/dist/plugin/inject.d.ts +0 -54
- package/dist/plugin/inject.js +0 -17
- package/dist/plugin/observe.cjs +0 -631
- package/dist/plugin/observe.d.cts +0 -39
- package/dist/plugin/observe.d.ts +0 -39
- package/dist/plugin/observe.js +0 -18
- package/dist/plugin/templates.cjs +0 -593
- package/dist/plugin/templates.d.cts +0 -52
- package/dist/plugin/templates.d.ts +0 -52
- package/dist/plugin/templates.js +0 -25
- package/dist/plugin/types.cjs +0 -18
- package/dist/plugin/types.d.cts +0 -209
- package/dist/plugin/types.d.ts +0 -209
- package/dist/plugin/types.js +0 -0
- package/dist/plugin/vault.cjs +0 -927
- package/dist/plugin/vault.d.cts +0 -68
- package/dist/plugin/vault.d.ts +0 -68
- package/dist/plugin/vault.js +0 -22
- package/dist/types-Y2_Um2Ls.d.ts +0 -205
- package/templates/memory-event.md +0 -67
- package/templates/party.md +0 -63
- package/templates/primitive-registry.yaml +0 -551
- package/templates/run.md +0 -68
- package/templates/trigger.md +0 -68
- package/templates/workspace.md +0 -50
|
@@ -1,1008 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/commands/reflect.ts
|
|
31
|
-
var reflect_exports = {};
|
|
32
|
-
__export(reflect_exports, {
|
|
33
|
-
reflectCommand: () => reflectCommand,
|
|
34
|
-
registerReflectCommand: () => registerReflectCommand
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(reflect_exports);
|
|
37
|
-
|
|
38
|
-
// src/lib/config.ts
|
|
39
|
-
var fs = __toESM(require("fs"), 1);
|
|
40
|
-
var path = __toESM(require("path"), 1);
|
|
41
|
-
function findNearestVaultPath(startPath = process.cwd()) {
|
|
42
|
-
let current = path.resolve(startPath);
|
|
43
|
-
while (true) {
|
|
44
|
-
if (fs.existsSync(path.join(current, ".clawvault.json"))) {
|
|
45
|
-
return current;
|
|
46
|
-
}
|
|
47
|
-
const parent = path.dirname(current);
|
|
48
|
-
if (parent === current) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
current = parent;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function resolveVaultPath(options = {}) {
|
|
55
|
-
if (options.explicitPath) {
|
|
56
|
-
return path.resolve(options.explicitPath);
|
|
57
|
-
}
|
|
58
|
-
if (process.env.CLAWVAULT_PATH) {
|
|
59
|
-
return path.resolve(process.env.CLAWVAULT_PATH);
|
|
60
|
-
}
|
|
61
|
-
const discovered = findNearestVaultPath(options.cwd ?? process.cwd());
|
|
62
|
-
if (discovered) {
|
|
63
|
-
return discovered;
|
|
64
|
-
}
|
|
65
|
-
throw new Error("No vault path found. Set CLAWVAULT_PATH, use --vault, or run inside a vault.");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// src/observer/reflection-service.ts
|
|
69
|
-
var fs4 = __toESM(require("fs"), 1);
|
|
70
|
-
var path3 = __toESM(require("path"), 1);
|
|
71
|
-
|
|
72
|
-
// src/lib/ledger.ts
|
|
73
|
-
var fs2 = __toESM(require("fs"), 1);
|
|
74
|
-
var path2 = __toESM(require("path"), 1);
|
|
75
|
-
var DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
76
|
-
var YEAR_RE = /^\d{4}$/;
|
|
77
|
-
var MONTH_RE = /^(0[1-9]|1[0-2])$/;
|
|
78
|
-
var DAY_FILE_RE = /^(0[1-9]|[12]\d|3[01])\.md$/;
|
|
79
|
-
var RAW_DAY_FILE_RE = /^(0[1-9]|[12]\d|3[01])\.jsonl$/;
|
|
80
|
-
function normalizeDateKey(date) {
|
|
81
|
-
if (typeof date === "string") {
|
|
82
|
-
if (!DATE_RE.test(date)) {
|
|
83
|
-
throw new Error(`Invalid date key: ${date}`);
|
|
84
|
-
}
|
|
85
|
-
return date;
|
|
86
|
-
}
|
|
87
|
-
return date.toISOString().slice(0, 10);
|
|
88
|
-
}
|
|
89
|
-
function ensureDir(dirPath) {
|
|
90
|
-
fs2.mkdirSync(dirPath, { recursive: true });
|
|
91
|
-
}
|
|
92
|
-
function walkThreeLevelDateTree(rootPath, extension) {
|
|
93
|
-
if (!fs2.existsSync(rootPath)) {
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
const results = [];
|
|
97
|
-
for (const yearEntry of fs2.readdirSync(rootPath, { withFileTypes: true })) {
|
|
98
|
-
if (!yearEntry.isDirectory() || !YEAR_RE.test(yearEntry.name)) continue;
|
|
99
|
-
const yearDir = path2.join(rootPath, yearEntry.name);
|
|
100
|
-
for (const monthEntry of fs2.readdirSync(yearDir, { withFileTypes: true })) {
|
|
101
|
-
if (!monthEntry.isDirectory() || !MONTH_RE.test(monthEntry.name)) continue;
|
|
102
|
-
const monthDir = path2.join(yearDir, monthEntry.name);
|
|
103
|
-
for (const dayEntry of fs2.readdirSync(monthDir, { withFileTypes: true })) {
|
|
104
|
-
if (!dayEntry.isFile()) continue;
|
|
105
|
-
const matches = extension === ".md" ? DAY_FILE_RE.test(dayEntry.name) : RAW_DAY_FILE_RE.test(dayEntry.name);
|
|
106
|
-
if (!matches) continue;
|
|
107
|
-
const day = dayEntry.name.slice(0, extension.length * -1);
|
|
108
|
-
const date = `${yearEntry.name}-${monthEntry.name}-${day}`;
|
|
109
|
-
if (!DATE_RE.test(date)) continue;
|
|
110
|
-
results.push({
|
|
111
|
-
date,
|
|
112
|
-
absolutePath: path2.join(monthDir, dayEntry.name)
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return results;
|
|
118
|
-
}
|
|
119
|
-
function inDateRange(date, fromDate, toDate) {
|
|
120
|
-
if (fromDate && date < fromDate) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
if (toDate && date > toDate) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
function parseDateKey(date) {
|
|
129
|
-
if (!DATE_RE.test(date)) {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
const parsed = /* @__PURE__ */ new Date(`${date}T00:00:00.000Z`);
|
|
133
|
-
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
|
134
|
-
}
|
|
135
|
-
function getLedgerRoot(vaultPath) {
|
|
136
|
-
return path2.join(path2.resolve(vaultPath), "ledger");
|
|
137
|
-
}
|
|
138
|
-
function getObservationsRoot(vaultPath) {
|
|
139
|
-
return path2.join(getLedgerRoot(vaultPath), "observations");
|
|
140
|
-
}
|
|
141
|
-
function getReflectionsRoot(vaultPath) {
|
|
142
|
-
return path2.join(getLedgerRoot(vaultPath), "reflections");
|
|
143
|
-
}
|
|
144
|
-
function getArchiveObservationsRoot(vaultPath) {
|
|
145
|
-
return path2.join(getLedgerRoot(vaultPath), "archive", "observations");
|
|
146
|
-
}
|
|
147
|
-
function getLegacyObservationsRoot(vaultPath) {
|
|
148
|
-
return path2.join(path2.resolve(vaultPath), "observations");
|
|
149
|
-
}
|
|
150
|
-
function getArchiveObservationPath(vaultPath, date) {
|
|
151
|
-
const dateKey = normalizeDateKey(date);
|
|
152
|
-
const [year, month, day] = dateKey.split("-");
|
|
153
|
-
return path2.join(getArchiveObservationsRoot(vaultPath), year, month, `${day}.md`);
|
|
154
|
-
}
|
|
155
|
-
function listLedgerObservationFiles(vaultPath, options = {}) {
|
|
156
|
-
return walkThreeLevelDateTree(getObservationsRoot(vaultPath), ".md").filter((entry) => inDateRange(entry.date, options.fromDate, options.toDate)).map((entry) => ({
|
|
157
|
-
date: entry.date,
|
|
158
|
-
path: entry.absolutePath,
|
|
159
|
-
location: "ledger"
|
|
160
|
-
})).sort((left, right) => left.date.localeCompare(right.date));
|
|
161
|
-
}
|
|
162
|
-
function listArchiveObservationFiles(vaultPath, options = {}) {
|
|
163
|
-
return walkThreeLevelDateTree(getArchiveObservationsRoot(vaultPath), ".md").filter((entry) => inDateRange(entry.date, options.fromDate, options.toDate)).map((entry) => ({
|
|
164
|
-
date: entry.date,
|
|
165
|
-
path: entry.absolutePath,
|
|
166
|
-
location: "archive"
|
|
167
|
-
})).sort((left, right) => left.date.localeCompare(right.date));
|
|
168
|
-
}
|
|
169
|
-
function listLegacyObservationFiles(vaultPath, options = {}) {
|
|
170
|
-
const legacyRoot = getLegacyObservationsRoot(vaultPath);
|
|
171
|
-
if (!fs2.existsSync(legacyRoot)) {
|
|
172
|
-
return [];
|
|
173
|
-
}
|
|
174
|
-
return fs2.readdirSync(legacyRoot, { withFileTypes: true }).filter((entry) => entry.isFile() && DATE_RE.test(entry.name.replace(/\.md$/, "")) && entry.name.endsWith(".md")).map((entry) => {
|
|
175
|
-
const date = entry.name.replace(/\.md$/, "");
|
|
176
|
-
return {
|
|
177
|
-
date,
|
|
178
|
-
path: path2.join(legacyRoot, entry.name),
|
|
179
|
-
location: "legacy"
|
|
180
|
-
};
|
|
181
|
-
}).filter((entry) => inDateRange(entry.date, options.fromDate, options.toDate)).sort((left, right) => left.date.localeCompare(right.date));
|
|
182
|
-
}
|
|
183
|
-
function listObservationFiles(vaultPath, options = {}) {
|
|
184
|
-
const includeLegacy = options.includeLegacy ?? true;
|
|
185
|
-
const includeArchive = options.includeArchive ?? false;
|
|
186
|
-
const dedupeByDate = options.dedupeByDate ?? true;
|
|
187
|
-
const files = [
|
|
188
|
-
...listLedgerObservationFiles(vaultPath, options),
|
|
189
|
-
...includeLegacy ? listLegacyObservationFiles(vaultPath, options) : [],
|
|
190
|
-
...includeArchive ? listArchiveObservationFiles(vaultPath, options) : []
|
|
191
|
-
];
|
|
192
|
-
if (!dedupeByDate) {
|
|
193
|
-
return files.sort((left, right) => left.date.localeCompare(right.date));
|
|
194
|
-
}
|
|
195
|
-
const byDate = /* @__PURE__ */ new Map();
|
|
196
|
-
const locationRank = {
|
|
197
|
-
ledger: 3,
|
|
198
|
-
legacy: 2,
|
|
199
|
-
archive: 1
|
|
200
|
-
};
|
|
201
|
-
for (const file of files) {
|
|
202
|
-
const existing = byDate.get(file.date);
|
|
203
|
-
if (!existing || locationRank[file.location] > locationRank[existing.location]) {
|
|
204
|
-
byDate.set(file.date, file);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return [...byDate.values()].sort((left, right) => left.date.localeCompare(right.date));
|
|
208
|
-
}
|
|
209
|
-
function getIsoWeekMonday(date) {
|
|
210
|
-
const normalized = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
|
211
|
-
const day = normalized.getUTCDay() || 7;
|
|
212
|
-
normalized.setUTCDate(normalized.getUTCDate() - day + 1);
|
|
213
|
-
return normalized;
|
|
214
|
-
}
|
|
215
|
-
function getIsoWeek(date) {
|
|
216
|
-
const monday = getIsoWeekMonday(date);
|
|
217
|
-
const thursday = new Date(monday);
|
|
218
|
-
thursday.setUTCDate(monday.getUTCDate() + 3);
|
|
219
|
-
const isoYear = thursday.getUTCFullYear();
|
|
220
|
-
const firstThursday = new Date(Date.UTC(isoYear, 0, 4));
|
|
221
|
-
const firstWeekMonday = getIsoWeekMonday(firstThursday);
|
|
222
|
-
const diffMs = monday.getTime() - firstWeekMonday.getTime();
|
|
223
|
-
const week = Math.floor(diffMs / (7 * 24 * 60 * 60 * 1e3)) + 1;
|
|
224
|
-
return { year: isoYear, week };
|
|
225
|
-
}
|
|
226
|
-
function formatIsoWeekKey(input) {
|
|
227
|
-
const weekInfo = input instanceof Date ? getIsoWeek(input) : input;
|
|
228
|
-
return `${weekInfo.year}-W${String(weekInfo.week).padStart(2, "0")}`;
|
|
229
|
-
}
|
|
230
|
-
function getIsoWeekRange(year, week) {
|
|
231
|
-
const januaryFourth = new Date(Date.UTC(year, 0, 4));
|
|
232
|
-
const firstWeekMonday = getIsoWeekMonday(januaryFourth);
|
|
233
|
-
const start = new Date(firstWeekMonday);
|
|
234
|
-
start.setUTCDate(firstWeekMonday.getUTCDate() + (week - 1) * 7);
|
|
235
|
-
const end = new Date(start);
|
|
236
|
-
end.setUTCDate(start.getUTCDate() + 6);
|
|
237
|
-
return { start, end };
|
|
238
|
-
}
|
|
239
|
-
function ensureParentDir(filePath) {
|
|
240
|
-
ensureDir(path2.dirname(filePath));
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// src/lib/observation-format.ts
|
|
244
|
-
var DATE_HEADING_RE = /^##\s+(\d{4}-\d{2}-\d{2})\s*$/;
|
|
245
|
-
var SCORED_LINE_RE = /^(?:-\s*)?\[(decision|preference|fact|commitment|task|todo|commitment-unresolved|milestone|lesson|relationship|project)\|c=(0(?:\.\d+)?|1(?:\.0+)?)\|i=(0(?:\.\d+)?|1(?:\.0+)?)\]\s+(.+)$/i;
|
|
246
|
-
var EMOJI_LINE_RE = /^(?:-\s*)?(🔴|🟡|🟢)\s+(\d{2}:\d{2})?\s*(.+)$/u;
|
|
247
|
-
var DECISION_RE = /\b(decis(?:ion|ions)?|decid(?:e|ed|ing)|chose|selected|opted|went with|picked)\b/i;
|
|
248
|
-
var PREFERENCE_RE = /\b(prefer(?:ence|s|red)?|likes?|dislikes?|default to|always use|never use|enjoys?|loves?|favou?rite|fan of|interested in|go-to|tend(?:s)? to use|passionate about|hobby|hobbies|(?:I|my|our)\s+(?:own|have|use|got|bought|drive|wear|eat|drink|cook|play|watch|read|listen)|(?:I(?:'m| am))\s+(?:a |an |into |allergic|vegetarian|vegan|gluten|lactose|trying to|learning)|usually|every (?:morning|evening|night|day|week)|routine)\b/i;
|
|
249
|
-
var COMMITMENT_RE = /\b(commit(?:ment|ted)?|promised|deadline|due|scheduled|will deliver|agreed to)\b/i;
|
|
250
|
-
var TODO_RE = /(?:\btodo:\s*|\bwe need to\b|\bdon't forget(?: to)?\b|\bremember to\b|\bmake sure to\b)/i;
|
|
251
|
-
var COMMITMENT_TASK_RE = /\b(?:i'?ll|i will|let me|(?:i'?m\s+)?going to|plan to|should)\b/i;
|
|
252
|
-
var UNRESOLVED_RE = /\b(?:need to figure out|tbd|to be determined)\b/i;
|
|
253
|
-
var DEADLINE_RE = /\b(?:by\s+(?:monday|tuesday|wednesday|thursday|friday|saturday|sunday|tomorrow)|before\s+the\s+\w+|deadline is)\b/i;
|
|
254
|
-
var MILESTONE_RE = /\b(released?|shipped|launched|merged|published|milestone|v\d+\.\d+)\b/i;
|
|
255
|
-
var LESSON_RE = /\b(learn(?:ed|ing|t)|lesson|insight|realized|discovered|never again)\b/i;
|
|
256
|
-
var RELATIONSHIP_RE = /\b(talked to|met with|spoke with|asked|client|partner|teammate|colleague)\b/i;
|
|
257
|
-
var PROJECT_RE = /\b(project|feature|service|repo|api|roadmap|sprint)\b/i;
|
|
258
|
-
function clamp01(value) {
|
|
259
|
-
if (!Number.isFinite(value)) return 0;
|
|
260
|
-
if (value < 0) return 0;
|
|
261
|
-
if (value > 1) return 1;
|
|
262
|
-
return value;
|
|
263
|
-
}
|
|
264
|
-
function scoreFromLegacyPriority(priority) {
|
|
265
|
-
if (priority === "\u{1F534}") return 0.9;
|
|
266
|
-
if (priority === "\u{1F7E1}") return 0.6;
|
|
267
|
-
return 0.2;
|
|
268
|
-
}
|
|
269
|
-
function confidenceFromLegacyPriority(priority) {
|
|
270
|
-
if (priority === "\u{1F534}") return 0.9;
|
|
271
|
-
if (priority === "\u{1F7E1}") return 0.8;
|
|
272
|
-
return 0.7;
|
|
273
|
-
}
|
|
274
|
-
function inferObservationType(content) {
|
|
275
|
-
if (DECISION_RE.test(content)) return "decision";
|
|
276
|
-
if (UNRESOLVED_RE.test(content)) return "commitment-unresolved";
|
|
277
|
-
if (TODO_RE.test(content)) return "todo";
|
|
278
|
-
if (PREFERENCE_RE.test(content)) return "preference";
|
|
279
|
-
if (COMMITMENT_TASK_RE.test(content) || DEADLINE_RE.test(content)) return "task";
|
|
280
|
-
if (COMMITMENT_RE.test(content)) return "commitment";
|
|
281
|
-
if (MILESTONE_RE.test(content)) return "milestone";
|
|
282
|
-
if (LESSON_RE.test(content)) return "lesson";
|
|
283
|
-
if (RELATIONSHIP_RE.test(content)) return "relationship";
|
|
284
|
-
if (PROJECT_RE.test(content)) return "project";
|
|
285
|
-
return "fact";
|
|
286
|
-
}
|
|
287
|
-
function normalizeObservationContent(content) {
|
|
288
|
-
return content.replace(/^\d{2}:\d{2}\s+/, "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
289
|
-
}
|
|
290
|
-
function parseObservationLine(line, date) {
|
|
291
|
-
const scored = line.match(SCORED_LINE_RE);
|
|
292
|
-
if (scored) {
|
|
293
|
-
return {
|
|
294
|
-
date,
|
|
295
|
-
type: scored[1].toLowerCase(),
|
|
296
|
-
confidence: clamp01(Number.parseFloat(scored[2])),
|
|
297
|
-
importance: clamp01(Number.parseFloat(scored[3])),
|
|
298
|
-
content: scored[4].trim(),
|
|
299
|
-
format: "scored",
|
|
300
|
-
rawLine: line
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
const emoji = line.match(EMOJI_LINE_RE);
|
|
304
|
-
if (!emoji) {
|
|
305
|
-
return null;
|
|
306
|
-
}
|
|
307
|
-
const priority = emoji[1];
|
|
308
|
-
const time = emoji[2]?.trim();
|
|
309
|
-
const text = emoji[3].trim();
|
|
310
|
-
const content = time ? `${time} ${text}` : text;
|
|
311
|
-
return {
|
|
312
|
-
date,
|
|
313
|
-
type: inferObservationType(content),
|
|
314
|
-
confidence: confidenceFromLegacyPriority(priority),
|
|
315
|
-
importance: scoreFromLegacyPriority(priority),
|
|
316
|
-
content,
|
|
317
|
-
format: "emoji",
|
|
318
|
-
priority,
|
|
319
|
-
time,
|
|
320
|
-
rawLine: line
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
function parseObservationMarkdown(markdown) {
|
|
324
|
-
const parsed = [];
|
|
325
|
-
let currentDate = "";
|
|
326
|
-
for (const line of markdown.split(/\r?\n/)) {
|
|
327
|
-
const heading = line.match(DATE_HEADING_RE);
|
|
328
|
-
if (heading) {
|
|
329
|
-
currentDate = heading[1];
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
if (!currentDate) {
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
const record = parseObservationLine(line.trim(), currentDate);
|
|
336
|
-
if (record) {
|
|
337
|
-
parsed.push(record);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return parsed;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// src/lib/claude-credentials.ts
|
|
344
|
-
var import_child_process = require("child_process");
|
|
345
|
-
var import_fs = require("fs");
|
|
346
|
-
var import_os = require("os");
|
|
347
|
-
var import_path = require("path");
|
|
348
|
-
var CLAUDE_CODE_SERVICE = "Claude Code-credentials";
|
|
349
|
-
var CLAUDE_CODE_ACCOUNT = "Claude Code";
|
|
350
|
-
var OAUTH_CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
|
|
351
|
-
var TOKEN_REFRESH_URL = "https://console.anthropic.com/v1/oauth/token";
|
|
352
|
-
var EXPIRY_BUFFER_MS = 5 * 60 * 1e3;
|
|
353
|
-
function readClaudeCliCredentials(opts) {
|
|
354
|
-
if (process.platform === "darwin") {
|
|
355
|
-
try {
|
|
356
|
-
const raw = (0, import_child_process.execFileSync)(
|
|
357
|
-
"security",
|
|
358
|
-
["find-generic-password", "-s", CLAUDE_CODE_SERVICE, "-w"],
|
|
359
|
-
{ encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }
|
|
360
|
-
).trim();
|
|
361
|
-
const parsed = parseCredentialsJson(raw);
|
|
362
|
-
if (parsed) return parsed;
|
|
363
|
-
} catch {
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
const home = opts?.homeDir ?? (0, import_os.homedir)();
|
|
367
|
-
const credFile = (0, import_path.join)(home, ".claude", ".credentials.json");
|
|
368
|
-
if (!(0, import_fs.existsSync)(credFile)) {
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
try {
|
|
372
|
-
const raw = (0, import_fs.readFileSync)(credFile, "utf8");
|
|
373
|
-
return parseCredentialsJson(raw);
|
|
374
|
-
} catch {
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
function parseCredentialsJson(raw) {
|
|
379
|
-
try {
|
|
380
|
-
const parsed = JSON.parse(raw);
|
|
381
|
-
const oauth = parsed.claudeAiOauth;
|
|
382
|
-
if (oauth && typeof oauth.accessToken === "string" && typeof oauth.refreshToken === "string" && typeof oauth.expiresAt === "number") {
|
|
383
|
-
return {
|
|
384
|
-
accessToken: oauth.accessToken,
|
|
385
|
-
refreshToken: oauth.refreshToken,
|
|
386
|
-
expiresAt: oauth.expiresAt
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
} catch {
|
|
390
|
-
}
|
|
391
|
-
return null;
|
|
392
|
-
}
|
|
393
|
-
async function refreshClaudeOAuthToken(refreshToken, fetchImpl) {
|
|
394
|
-
const f = fetchImpl ?? fetch;
|
|
395
|
-
const response = await f(TOKEN_REFRESH_URL, {
|
|
396
|
-
method: "POST",
|
|
397
|
-
headers: { "content-type": "application/json" },
|
|
398
|
-
body: JSON.stringify({
|
|
399
|
-
grant_type: "refresh_token",
|
|
400
|
-
client_id: OAUTH_CLIENT_ID,
|
|
401
|
-
refresh_token: refreshToken
|
|
402
|
-
})
|
|
403
|
-
});
|
|
404
|
-
if (!response.ok) {
|
|
405
|
-
throw new Error(`OAuth token refresh failed (${response.status})`);
|
|
406
|
-
}
|
|
407
|
-
const data = await response.json();
|
|
408
|
-
return {
|
|
409
|
-
accessToken: data.access_token,
|
|
410
|
-
refreshToken: data.refresh_token,
|
|
411
|
-
expiresAt: Date.now() + data.expires_in * 1e3
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
function writeClaudeCliCredentials(cred, opts) {
|
|
415
|
-
const payload = JSON.stringify({ claudeAiOauth: cred });
|
|
416
|
-
if (process.platform === "darwin") {
|
|
417
|
-
try {
|
|
418
|
-
(0, import_child_process.execFileSync)(
|
|
419
|
-
"security",
|
|
420
|
-
["add-generic-password", "-U", "-s", CLAUDE_CODE_SERVICE, "-a", CLAUDE_CODE_ACCOUNT, "-w", payload],
|
|
421
|
-
{ stdio: "ignore" }
|
|
422
|
-
);
|
|
423
|
-
return;
|
|
424
|
-
} catch {
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
const home = opts?.homeDir ?? (0, import_os.homedir)();
|
|
428
|
-
const credFile = (0, import_path.join)(home, ".claude", ".credentials.json");
|
|
429
|
-
(0, import_fs.writeFileSync)(credFile, payload, "utf8");
|
|
430
|
-
}
|
|
431
|
-
async function resolveClaudeOAuthToken(opts) {
|
|
432
|
-
const cred = readClaudeCliCredentials(opts);
|
|
433
|
-
if (!cred) {
|
|
434
|
-
return null;
|
|
435
|
-
}
|
|
436
|
-
if (cred.expiresAt < Date.now() + EXPIRY_BUFFER_MS) {
|
|
437
|
-
try {
|
|
438
|
-
const refreshed = await refreshClaudeOAuthToken(cred.refreshToken, opts?.fetchImpl);
|
|
439
|
-
writeClaudeCliCredentials(refreshed, opts);
|
|
440
|
-
return refreshed.accessToken;
|
|
441
|
-
} catch {
|
|
442
|
-
return cred.accessToken;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
return cred.accessToken;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// src/lib/llm-provider.ts
|
|
449
|
-
var DEFAULT_MODELS = {
|
|
450
|
-
anthropic: "claude-haiku-4-5",
|
|
451
|
-
openai: "gpt-4o-mini",
|
|
452
|
-
gemini: "gemini-2.0-flash"
|
|
453
|
-
};
|
|
454
|
-
async function resolveAnthropicAuth(fetchImpl) {
|
|
455
|
-
const oauthEnvToken = process.env.ANTHROPIC_OAUTH_TOKEN?.trim();
|
|
456
|
-
if (oauthEnvToken) {
|
|
457
|
-
return { token: oauthEnvToken, isOAuth: true };
|
|
458
|
-
}
|
|
459
|
-
const apiKey = process.env.ANTHROPIC_API_KEY?.trim();
|
|
460
|
-
if (apiKey) {
|
|
461
|
-
return { token: apiKey, isOAuth: false };
|
|
462
|
-
}
|
|
463
|
-
if (process.env.CLAWVAULT_CLAUDE_AUTH) {
|
|
464
|
-
const oauthToken = await resolveClaudeOAuthToken({ fetchImpl });
|
|
465
|
-
if (oauthToken) {
|
|
466
|
-
return { token: oauthToken, isOAuth: true };
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
return null;
|
|
470
|
-
}
|
|
471
|
-
async function resolveLlmProvider(fetchImpl) {
|
|
472
|
-
if (process.env.CLAWVAULT_NO_LLM) {
|
|
473
|
-
return null;
|
|
474
|
-
}
|
|
475
|
-
const anthropicAuth = await resolveAnthropicAuth(fetchImpl);
|
|
476
|
-
if (anthropicAuth) {
|
|
477
|
-
return "anthropic";
|
|
478
|
-
}
|
|
479
|
-
if (process.env.OPENAI_API_KEY) {
|
|
480
|
-
return "openai";
|
|
481
|
-
}
|
|
482
|
-
if (process.env.GEMINI_API_KEY) {
|
|
483
|
-
return "gemini";
|
|
484
|
-
}
|
|
485
|
-
return null;
|
|
486
|
-
}
|
|
487
|
-
async function requestLlmCompletion(options) {
|
|
488
|
-
const provider = options.provider ?? await resolveLlmProvider(options.fetchImpl);
|
|
489
|
-
if (!provider) {
|
|
490
|
-
return "";
|
|
491
|
-
}
|
|
492
|
-
if (provider === "anthropic") {
|
|
493
|
-
return callAnthropic(options, provider);
|
|
494
|
-
}
|
|
495
|
-
if (provider === "gemini") {
|
|
496
|
-
return callGemini(options, provider);
|
|
497
|
-
}
|
|
498
|
-
return callOpenAI(options, provider);
|
|
499
|
-
}
|
|
500
|
-
async function callAnthropic(options, provider) {
|
|
501
|
-
const fetchImpl = options.fetchImpl ?? fetch;
|
|
502
|
-
const auth = await resolveAnthropicAuth(fetchImpl);
|
|
503
|
-
if (!auth) {
|
|
504
|
-
return "";
|
|
505
|
-
}
|
|
506
|
-
const headers = auth.isOAuth ? {
|
|
507
|
-
"content-type": "application/json",
|
|
508
|
-
"authorization": `Bearer ${auth.token}`,
|
|
509
|
-
"anthropic-version": "2023-06-01",
|
|
510
|
-
"anthropic-beta": "claude-code-20250219,oauth-2025-04-20",
|
|
511
|
-
"x-app": "cli",
|
|
512
|
-
"user-agent": "claude-cli/1.0.0 (external, cli)"
|
|
513
|
-
} : {
|
|
514
|
-
"content-type": "application/json",
|
|
515
|
-
"x-api-key": auth.token,
|
|
516
|
-
"anthropic-version": "2023-06-01"
|
|
517
|
-
};
|
|
518
|
-
const systemMessages = [];
|
|
519
|
-
if (auth.isOAuth) {
|
|
520
|
-
systemMessages.push({ type: "text", text: "You are Claude Code, Anthropic's official CLI for Claude." });
|
|
521
|
-
}
|
|
522
|
-
if (options.systemPrompt?.trim()) {
|
|
523
|
-
systemMessages.push({ type: "text", text: options.systemPrompt.trim() });
|
|
524
|
-
}
|
|
525
|
-
const body = {
|
|
526
|
-
model: options.model ?? DEFAULT_MODELS[provider],
|
|
527
|
-
temperature: options.temperature ?? 0.1,
|
|
528
|
-
max_tokens: options.maxTokens ?? 1200,
|
|
529
|
-
messages: [{ role: "user", content: options.prompt }]
|
|
530
|
-
};
|
|
531
|
-
if (systemMessages.length > 0) {
|
|
532
|
-
body.system = systemMessages;
|
|
533
|
-
}
|
|
534
|
-
const response = await fetchImpl("https://api.anthropic.com/v1/messages", {
|
|
535
|
-
method: "POST",
|
|
536
|
-
headers,
|
|
537
|
-
body: JSON.stringify(body)
|
|
538
|
-
});
|
|
539
|
-
if (!response.ok) {
|
|
540
|
-
throw new Error(`Anthropic request failed (${response.status})`);
|
|
541
|
-
}
|
|
542
|
-
const payload = await response.json();
|
|
543
|
-
return payload.content?.filter((entry) => entry.type === "text" && entry.text).map((entry) => entry.text).join("\n").trim() ?? "";
|
|
544
|
-
}
|
|
545
|
-
async function callOpenAI(options, provider) {
|
|
546
|
-
const apiKey = process.env.OPENAI_API_KEY;
|
|
547
|
-
if (!apiKey) {
|
|
548
|
-
return "";
|
|
549
|
-
}
|
|
550
|
-
const fetchImpl = options.fetchImpl ?? fetch;
|
|
551
|
-
const messages = [];
|
|
552
|
-
if (options.systemPrompt?.trim()) {
|
|
553
|
-
messages.push({ role: "system", content: options.systemPrompt.trim() });
|
|
554
|
-
}
|
|
555
|
-
messages.push({ role: "user", content: options.prompt });
|
|
556
|
-
const response = await fetchImpl("https://api.openai.com/v1/chat/completions", {
|
|
557
|
-
method: "POST",
|
|
558
|
-
headers: {
|
|
559
|
-
"content-type": "application/json",
|
|
560
|
-
authorization: `Bearer ${apiKey}`
|
|
561
|
-
},
|
|
562
|
-
body: JSON.stringify({
|
|
563
|
-
model: options.model ?? DEFAULT_MODELS[provider],
|
|
564
|
-
temperature: options.temperature ?? 0.1,
|
|
565
|
-
max_tokens: options.maxTokens ?? 1200,
|
|
566
|
-
messages
|
|
567
|
-
})
|
|
568
|
-
});
|
|
569
|
-
if (!response.ok) {
|
|
570
|
-
throw new Error(`OpenAI request failed (${response.status})`);
|
|
571
|
-
}
|
|
572
|
-
const payload = await response.json();
|
|
573
|
-
return payload.choices?.[0]?.message?.content?.trim() ?? "";
|
|
574
|
-
}
|
|
575
|
-
async function callGemini(options, provider) {
|
|
576
|
-
const apiKey = process.env.GEMINI_API_KEY;
|
|
577
|
-
if (!apiKey) {
|
|
578
|
-
return "";
|
|
579
|
-
}
|
|
580
|
-
const fetchImpl = options.fetchImpl ?? fetch;
|
|
581
|
-
const model = options.model ?? DEFAULT_MODELS[provider];
|
|
582
|
-
const response = await fetchImpl(
|
|
583
|
-
`https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`,
|
|
584
|
-
{
|
|
585
|
-
method: "POST",
|
|
586
|
-
headers: { "content-type": "application/json", "x-goog-api-key": apiKey },
|
|
587
|
-
body: JSON.stringify({
|
|
588
|
-
contents: [{ parts: [{ text: options.prompt }] }],
|
|
589
|
-
generationConfig: {
|
|
590
|
-
temperature: options.temperature ?? 0.1,
|
|
591
|
-
maxOutputTokens: options.maxTokens ?? 1200
|
|
592
|
-
}
|
|
593
|
-
})
|
|
594
|
-
}
|
|
595
|
-
);
|
|
596
|
-
if (!response.ok) {
|
|
597
|
-
throw new Error(`Gemini request failed (${response.status})`);
|
|
598
|
-
}
|
|
599
|
-
const payload = await response.json();
|
|
600
|
-
return payload.candidates?.[0]?.content?.parts?.[0]?.text?.trim() ?? "";
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
// src/observer/archive.ts
|
|
604
|
-
var fs3 = __toESM(require("fs"), 1);
|
|
605
|
-
function archiveObservations(vaultPath, options = {}) {
|
|
606
|
-
const olderThanDays = Number.isFinite(options.olderThanDays) ? Math.max(1, Math.floor(options.olderThanDays)) : 14;
|
|
607
|
-
const dryRun = options.dryRun ?? false;
|
|
608
|
-
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
609
|
-
const today = new Date(now());
|
|
610
|
-
today.setUTCHours(0, 0, 0, 0);
|
|
611
|
-
const cutoff = new Date(today);
|
|
612
|
-
cutoff.setUTCDate(today.getUTCDate() - olderThanDays);
|
|
613
|
-
const cutoffKey = cutoff.toISOString().slice(0, 10);
|
|
614
|
-
const files = listObservationFiles(vaultPath, {
|
|
615
|
-
includeLegacy: true,
|
|
616
|
-
includeArchive: false,
|
|
617
|
-
dedupeByDate: true
|
|
618
|
-
});
|
|
619
|
-
let archived = 0;
|
|
620
|
-
let skipped = 0;
|
|
621
|
-
const archivedDates = [];
|
|
622
|
-
for (const file of files) {
|
|
623
|
-
if (file.date >= cutoffKey) {
|
|
624
|
-
continue;
|
|
625
|
-
}
|
|
626
|
-
const archivePath = getArchiveObservationPath(vaultPath, file.date);
|
|
627
|
-
if (dryRun) {
|
|
628
|
-
archived += 1;
|
|
629
|
-
archivedDates.push(file.date);
|
|
630
|
-
continue;
|
|
631
|
-
}
|
|
632
|
-
ensureParentDir(archivePath);
|
|
633
|
-
fs3.copyFileSync(file.path, archivePath);
|
|
634
|
-
if (file.path !== archivePath) {
|
|
635
|
-
fs3.rmSync(file.path, { force: true });
|
|
636
|
-
} else {
|
|
637
|
-
skipped += 1;
|
|
638
|
-
continue;
|
|
639
|
-
}
|
|
640
|
-
archived += 1;
|
|
641
|
-
archivedDates.push(file.date);
|
|
642
|
-
}
|
|
643
|
-
return {
|
|
644
|
-
scanned: files.length,
|
|
645
|
-
archived,
|
|
646
|
-
skipped,
|
|
647
|
-
dryRun,
|
|
648
|
-
archivedDates
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// src/observer/reflection-service.ts
|
|
653
|
-
var OPEN_LOOP_RE = /\b(open loop|todo|follow[- ]?up|blocked|pending|unresolved|still need)\b/i;
|
|
654
|
-
var CHANGE_RE = /\b(changed?|shift(?:ed)?|switched|moved|instead|no longer|pivot(?:ed)?)\b/i;
|
|
655
|
-
function normalizeDays(days) {
|
|
656
|
-
if (!Number.isFinite(days)) return 14;
|
|
657
|
-
return Math.max(1, Math.floor(days));
|
|
658
|
-
}
|
|
659
|
-
function shouldIncludeDate(date, fromDate, toDate) {
|
|
660
|
-
if (date < fromDate) return false;
|
|
661
|
-
if (date > toDate) return false;
|
|
662
|
-
return true;
|
|
663
|
-
}
|
|
664
|
-
function listReflectionFiles(vaultPath) {
|
|
665
|
-
const reflectionsRoot = getReflectionsRoot(vaultPath);
|
|
666
|
-
if (!fs4.existsSync(reflectionsRoot)) {
|
|
667
|
-
return [];
|
|
668
|
-
}
|
|
669
|
-
return fs4.readdirSync(reflectionsRoot, { withFileTypes: true }).filter((entry) => entry.isFile() && /^\d{4}-W\d{2}\.md$/.test(entry.name)).map((entry) => path3.join(reflectionsRoot, entry.name)).sort((left, right) => left.localeCompare(right));
|
|
670
|
-
}
|
|
671
|
-
function extractPriorReflectionKeys(vaultPath, currentWeek) {
|
|
672
|
-
const keys = /* @__PURE__ */ new Set();
|
|
673
|
-
for (const filePath of listReflectionFiles(vaultPath)) {
|
|
674
|
-
const weekKey = path3.basename(filePath, ".md");
|
|
675
|
-
if (weekKey >= currentWeek) {
|
|
676
|
-
continue;
|
|
677
|
-
}
|
|
678
|
-
const content = fs4.readFileSync(filePath, "utf-8");
|
|
679
|
-
for (const line of content.split(/\r?\n/)) {
|
|
680
|
-
const match = line.match(/^- (.+)$/);
|
|
681
|
-
if (!match?.[1]) continue;
|
|
682
|
-
const value = match[1].trim();
|
|
683
|
-
if (value.startsWith("ledger/observations/")) continue;
|
|
684
|
-
keys.add(normalizeObservationContent(value));
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
return keys;
|
|
688
|
-
}
|
|
689
|
-
function mergeUnique(target, incoming) {
|
|
690
|
-
const seen = new Set(target.map((item) => normalizeObservationContent(item)));
|
|
691
|
-
const merged = [...target];
|
|
692
|
-
for (const item of incoming) {
|
|
693
|
-
const normalized = normalizeObservationContent(item);
|
|
694
|
-
if (!normalized || seen.has(normalized)) continue;
|
|
695
|
-
seen.add(normalized);
|
|
696
|
-
merged.push(item);
|
|
697
|
-
}
|
|
698
|
-
return merged;
|
|
699
|
-
}
|
|
700
|
-
function parseExistingReflectionSections(content) {
|
|
701
|
-
const sections = {
|
|
702
|
-
stablePatterns: [],
|
|
703
|
-
keyDecisions: [],
|
|
704
|
-
openLoops: [],
|
|
705
|
-
changes: [],
|
|
706
|
-
citations: []
|
|
707
|
-
};
|
|
708
|
-
let current = null;
|
|
709
|
-
for (const rawLine of content.split(/\r?\n/)) {
|
|
710
|
-
const line = rawLine.trim();
|
|
711
|
-
if (line === "## Stable Patterns") {
|
|
712
|
-
current = "stablePatterns";
|
|
713
|
-
continue;
|
|
714
|
-
}
|
|
715
|
-
if (line === "## Key Decisions") {
|
|
716
|
-
current = "keyDecisions";
|
|
717
|
-
continue;
|
|
718
|
-
}
|
|
719
|
-
if (line === "## Open Loops") {
|
|
720
|
-
current = "openLoops";
|
|
721
|
-
continue;
|
|
722
|
-
}
|
|
723
|
-
if (line === "## Changes") {
|
|
724
|
-
current = "changes";
|
|
725
|
-
continue;
|
|
726
|
-
}
|
|
727
|
-
if (line === "## Citations") {
|
|
728
|
-
current = "citations";
|
|
729
|
-
continue;
|
|
730
|
-
}
|
|
731
|
-
if (!current) continue;
|
|
732
|
-
const bullet = line.match(/^- (.+)$/);
|
|
733
|
-
if (!bullet?.[1]) continue;
|
|
734
|
-
sections[current].push(bullet[1].trim());
|
|
735
|
-
}
|
|
736
|
-
return sections;
|
|
737
|
-
}
|
|
738
|
-
function classifyItem(item) {
|
|
739
|
-
if (OPEN_LOOP_RE.test(item.content)) {
|
|
740
|
-
return "openLoops";
|
|
741
|
-
}
|
|
742
|
-
if (item.type === "decision" || item.type === "commitment" || item.type === "milestone") {
|
|
743
|
-
return "keyDecisions";
|
|
744
|
-
}
|
|
745
|
-
if (CHANGE_RE.test(item.content)) {
|
|
746
|
-
return "changes";
|
|
747
|
-
}
|
|
748
|
-
return "stablePatterns";
|
|
749
|
-
}
|
|
750
|
-
function toObservationCitationPath(date) {
|
|
751
|
-
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
|
|
752
|
-
return `ledger/observations/${date}.md`;
|
|
753
|
-
}
|
|
754
|
-
const [year, month, day] = date.split("-");
|
|
755
|
-
return `ledger/observations/${year}/${month}/${day}.md`;
|
|
756
|
-
}
|
|
757
|
-
function buildSectionDraft(promoted) {
|
|
758
|
-
const sections = {
|
|
759
|
-
stablePatterns: [],
|
|
760
|
-
keyDecisions: [],
|
|
761
|
-
openLoops: [],
|
|
762
|
-
changes: [],
|
|
763
|
-
citations: []
|
|
764
|
-
};
|
|
765
|
-
for (const item of promoted) {
|
|
766
|
-
sections[classifyItem(item)].push(
|
|
767
|
-
`[${item.type}|c=${item.confidence.toFixed(2)}|i=${item.importance.toFixed(2)}] ${item.content}`
|
|
768
|
-
);
|
|
769
|
-
for (const date of item.dates) {
|
|
770
|
-
sections.citations.push(toObservationCitationPath(date));
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
sections.citations = [...new Set(sections.citations)].sort((left, right) => left.localeCompare(right));
|
|
774
|
-
return sections;
|
|
775
|
-
}
|
|
776
|
-
function formatWeekTitle(weekKey) {
|
|
777
|
-
const [yearRaw, weekRaw] = weekKey.split("-W");
|
|
778
|
-
const year = Number.parseInt(yearRaw, 10);
|
|
779
|
-
const week = Number.parseInt(weekRaw, 10);
|
|
780
|
-
const range = getIsoWeekRange(year, week);
|
|
781
|
-
const monthFormatter = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", timeZone: "UTC" });
|
|
782
|
-
return `# Week ${week}, ${year} (${monthFormatter.format(range.start)}-${monthFormatter.format(range.end)})`;
|
|
783
|
-
}
|
|
784
|
-
function renderReflectionMarkdown(weekKey, sections) {
|
|
785
|
-
const lines = [];
|
|
786
|
-
lines.push(formatWeekTitle(weekKey));
|
|
787
|
-
lines.push("");
|
|
788
|
-
lines.push("## Stable Patterns");
|
|
789
|
-
for (const item of sections.stablePatterns) lines.push(`- ${item}`);
|
|
790
|
-
lines.push("");
|
|
791
|
-
lines.push("## Key Decisions");
|
|
792
|
-
for (const item of sections.keyDecisions) lines.push(`- ${item}`);
|
|
793
|
-
lines.push("");
|
|
794
|
-
lines.push("## Open Loops");
|
|
795
|
-
for (const item of sections.openLoops) lines.push(`- ${item}`);
|
|
796
|
-
lines.push("");
|
|
797
|
-
lines.push("## Changes");
|
|
798
|
-
for (const item of sections.changes) lines.push(`- ${item}`);
|
|
799
|
-
lines.push("");
|
|
800
|
-
lines.push("## Citations");
|
|
801
|
-
for (const item of sections.citations) lines.push(`- ${item}`);
|
|
802
|
-
lines.push("");
|
|
803
|
-
return lines.join("\n").trim();
|
|
804
|
-
}
|
|
805
|
-
function promoteWeekRecords(records) {
|
|
806
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
807
|
-
for (const record of records) {
|
|
808
|
-
const key = normalizeObservationContent(record.content);
|
|
809
|
-
const existing = grouped.get(key);
|
|
810
|
-
if (!existing) {
|
|
811
|
-
grouped.set(key, {
|
|
812
|
-
key,
|
|
813
|
-
type: record.type,
|
|
814
|
-
confidence: record.confidence,
|
|
815
|
-
importance: record.importance,
|
|
816
|
-
content: record.content,
|
|
817
|
-
dates: /* @__PURE__ */ new Set([record.date])
|
|
818
|
-
});
|
|
819
|
-
continue;
|
|
820
|
-
}
|
|
821
|
-
existing.dates.add(record.date);
|
|
822
|
-
if (record.importance > existing.importance) {
|
|
823
|
-
existing.importance = record.importance;
|
|
824
|
-
existing.type = record.type;
|
|
825
|
-
existing.content = record.content;
|
|
826
|
-
}
|
|
827
|
-
if (record.confidence > existing.confidence) {
|
|
828
|
-
existing.confidence = record.confidence;
|
|
829
|
-
}
|
|
830
|
-
grouped.set(key, existing);
|
|
831
|
-
}
|
|
832
|
-
const promoted = [];
|
|
833
|
-
for (const item of grouped.values()) {
|
|
834
|
-
if (item.importance >= 0.8) {
|
|
835
|
-
promoted.push(item);
|
|
836
|
-
continue;
|
|
837
|
-
}
|
|
838
|
-
if (item.importance >= 0.4 && item.dates.size >= 2) {
|
|
839
|
-
promoted.push(item);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
return promoted;
|
|
843
|
-
}
|
|
844
|
-
async function maybeGenerateLlmReflection(weekKey, sections) {
|
|
845
|
-
const provider = await resolveLlmProvider();
|
|
846
|
-
if (!provider) {
|
|
847
|
-
return null;
|
|
848
|
-
}
|
|
849
|
-
const prompt = [
|
|
850
|
-
"Rewrite the weekly reflection draft while preserving section structure and bullets.",
|
|
851
|
-
"Return markdown only using these exact headers:",
|
|
852
|
-
"# Week <N>, <YYYY> (...)",
|
|
853
|
-
"## Stable Patterns",
|
|
854
|
-
"## Key Decisions",
|
|
855
|
-
"## Open Loops",
|
|
856
|
-
"## Changes",
|
|
857
|
-
"## Citations",
|
|
858
|
-
"",
|
|
859
|
-
`Week key: ${weekKey}`,
|
|
860
|
-
"",
|
|
861
|
-
renderReflectionMarkdown(weekKey, sections)
|
|
862
|
-
].join("\n");
|
|
863
|
-
try {
|
|
864
|
-
const output = await requestLlmCompletion({
|
|
865
|
-
provider,
|
|
866
|
-
prompt,
|
|
867
|
-
temperature: 0.1,
|
|
868
|
-
maxTokens: 1200
|
|
869
|
-
});
|
|
870
|
-
if (!output.trim()) {
|
|
871
|
-
return null;
|
|
872
|
-
}
|
|
873
|
-
const cleaned = output.replace(/^```(?:markdown)?\s*/i, "").replace(/\s*```$/, "").trim();
|
|
874
|
-
if (cleaned.includes("## Stable Patterns") && cleaned.includes("## Key Decisions") && cleaned.includes("## Open Loops") && cleaned.includes("## Changes") && cleaned.includes("## Citations")) {
|
|
875
|
-
return cleaned;
|
|
876
|
-
}
|
|
877
|
-
return null;
|
|
878
|
-
} catch {
|
|
879
|
-
return null;
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
async function runReflection(options) {
|
|
883
|
-
const days = normalizeDays(options.days);
|
|
884
|
-
const dryRun = options.dryRun ?? false;
|
|
885
|
-
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
886
|
-
const nowDate = now();
|
|
887
|
-
const toDate = nowDate.toISOString().slice(0, 10);
|
|
888
|
-
const fromDateDate = new Date(nowDate);
|
|
889
|
-
fromDateDate.setDate(nowDate.getDate() - (days - 1));
|
|
890
|
-
const fromDate = fromDateDate.toISOString().slice(0, 10);
|
|
891
|
-
const observationFiles = listObservationFiles(options.vaultPath, {
|
|
892
|
-
includeLegacy: true,
|
|
893
|
-
includeArchive: false,
|
|
894
|
-
dedupeByDate: true
|
|
895
|
-
}).filter((entry) => shouldIncludeDate(entry.date, fromDate, toDate));
|
|
896
|
-
const recordsByWeek = /* @__PURE__ */ new Map();
|
|
897
|
-
for (const entry of observationFiles) {
|
|
898
|
-
const parsedDate = parseDateKey(entry.date);
|
|
899
|
-
if (!parsedDate) continue;
|
|
900
|
-
const week = getIsoWeek(parsedDate);
|
|
901
|
-
const weekKey = formatIsoWeekKey(week);
|
|
902
|
-
const markdown = fs4.readFileSync(entry.path, "utf-8");
|
|
903
|
-
const parsedRecords = parseObservationMarkdown(markdown);
|
|
904
|
-
const bucket = recordsByWeek.get(weekKey) ?? [];
|
|
905
|
-
for (const record of parsedRecords) {
|
|
906
|
-
bucket.push({
|
|
907
|
-
date: record.date,
|
|
908
|
-
type: record.type,
|
|
909
|
-
confidence: record.confidence,
|
|
910
|
-
importance: record.importance,
|
|
911
|
-
content: record.content
|
|
912
|
-
});
|
|
913
|
-
}
|
|
914
|
-
recordsByWeek.set(weekKey, bucket);
|
|
915
|
-
}
|
|
916
|
-
const processedWeeks = [...recordsByWeek.keys()].sort((left, right) => left.localeCompare(right));
|
|
917
|
-
const writtenFiles = [];
|
|
918
|
-
for (const weekKey of processedWeeks) {
|
|
919
|
-
const promoted = promoteWeekRecords(recordsByWeek.get(weekKey) ?? []);
|
|
920
|
-
const priorKeys = extractPriorReflectionKeys(options.vaultPath, weekKey);
|
|
921
|
-
const unseenPromoted = promoted.filter((item) => !priorKeys.has(item.key));
|
|
922
|
-
if (unseenPromoted.length === 0) {
|
|
923
|
-
continue;
|
|
924
|
-
}
|
|
925
|
-
const reflectionPath = path3.join(getReflectionsRoot(options.vaultPath), `${weekKey}.md`);
|
|
926
|
-
const existing = fs4.existsSync(reflectionPath) ? fs4.readFileSync(reflectionPath, "utf-8") : "";
|
|
927
|
-
const existingSections = existing ? parseExistingReflectionSections(existing) : {
|
|
928
|
-
stablePatterns: [],
|
|
929
|
-
keyDecisions: [],
|
|
930
|
-
openLoops: [],
|
|
931
|
-
changes: [],
|
|
932
|
-
citations: []
|
|
933
|
-
};
|
|
934
|
-
const draftSections = buildSectionDraft(unseenPromoted);
|
|
935
|
-
const mergedSections = {
|
|
936
|
-
stablePatterns: mergeUnique(existingSections.stablePatterns, draftSections.stablePatterns),
|
|
937
|
-
keyDecisions: mergeUnique(existingSections.keyDecisions, draftSections.keyDecisions),
|
|
938
|
-
openLoops: mergeUnique(existingSections.openLoops, draftSections.openLoops),
|
|
939
|
-
changes: mergeUnique(existingSections.changes, draftSections.changes),
|
|
940
|
-
citations: mergeUnique(existingSections.citations, draftSections.citations)
|
|
941
|
-
};
|
|
942
|
-
const llmMarkdown = await maybeGenerateLlmReflection(weekKey, mergedSections);
|
|
943
|
-
const markdown = llmMarkdown ?? renderReflectionMarkdown(weekKey, mergedSections);
|
|
944
|
-
if (dryRun) {
|
|
945
|
-
writtenFiles.push(reflectionPath);
|
|
946
|
-
continue;
|
|
947
|
-
}
|
|
948
|
-
fs4.mkdirSync(path3.dirname(reflectionPath), { recursive: true });
|
|
949
|
-
fs4.writeFileSync(reflectionPath, `${markdown.trim()}
|
|
950
|
-
`, "utf-8");
|
|
951
|
-
writtenFiles.push(reflectionPath);
|
|
952
|
-
}
|
|
953
|
-
const archive = dryRun ? null : archiveObservations(options.vaultPath, {
|
|
954
|
-
olderThanDays: 14,
|
|
955
|
-
dryRun: false,
|
|
956
|
-
now
|
|
957
|
-
});
|
|
958
|
-
return {
|
|
959
|
-
processedWeeks: processedWeeks.length,
|
|
960
|
-
writtenWeeks: writtenFiles.length,
|
|
961
|
-
dryRun,
|
|
962
|
-
files: writtenFiles,
|
|
963
|
-
archive
|
|
964
|
-
};
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
// src/commands/reflect.ts
|
|
968
|
-
function parsePositiveInteger(raw, label) {
|
|
969
|
-
const parsed = Number.parseInt(raw, 10);
|
|
970
|
-
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
971
|
-
throw new Error(`Invalid ${label}: ${raw}`);
|
|
972
|
-
}
|
|
973
|
-
return parsed;
|
|
974
|
-
}
|
|
975
|
-
async function reflectCommand(options) {
|
|
976
|
-
const vaultPath = resolveVaultPath({ explicitPath: options.vaultPath });
|
|
977
|
-
const result = await runReflection({
|
|
978
|
-
vaultPath,
|
|
979
|
-
days: options.days,
|
|
980
|
-
dryRun: options.dryRun
|
|
981
|
-
});
|
|
982
|
-
if (result.writtenWeeks === 0) {
|
|
983
|
-
console.log("No new reflections promoted.");
|
|
984
|
-
return;
|
|
985
|
-
}
|
|
986
|
-
if (result.dryRun) {
|
|
987
|
-
console.log(`Dry run: ${result.writtenWeeks} reflection file(s) would be written.`);
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
console.log(`Reflection complete: ${result.writtenWeeks} week file(s) updated.`);
|
|
991
|
-
if (result.archive) {
|
|
992
|
-
console.log(`Archive pass: ${result.archive.archived} observation file(s) archived.`);
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
function registerReflectCommand(program) {
|
|
996
|
-
program.command("reflect").description("Promote stable observation patterns into weekly reflections").option("--days <n>", "Observation window in days (default 14)", "14").option("--dry-run", "Show what would be reflected without writing").option("-v, --vault <path>", "Vault path").action(async (rawOptions) => {
|
|
997
|
-
await reflectCommand({
|
|
998
|
-
vaultPath: rawOptions.vault,
|
|
999
|
-
days: parsePositiveInteger(rawOptions.days, "days"),
|
|
1000
|
-
dryRun: rawOptions.dryRun
|
|
1001
|
-
});
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1005
|
-
0 && (module.exports = {
|
|
1006
|
-
reflectCommand,
|
|
1007
|
-
registerReflectCommand
|
|
1008
|
-
});
|