@amoree-code/ocean 1.7.0 → 1.9.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 +3 -1
- package/dist/infrastructure/process/service.js +22 -1
- package/dist/interfaces/cli/command-registry.js +8 -1
- package/dist/interfaces/cli/daily-command.js +7 -73
- package/dist/interfaces/cli/harvest-command.js +58 -0
- package/dist/interfaces/cli/help-command.js +10 -2
- package/dist/interfaces/cli/rhythm-command.js +81 -0
- package/dist/interfaces/cli/session-facts-command.js +1 -1
- package/node_modules/@ocean/brain/dist/memory/brain-dump.js +55 -0
- package/node_modules/@ocean/brain/dist/memory/session-facts.js +44 -3
- package/node_modules/@ocean/brain/package.json +1 -1
- package/node_modules/@ocean/context/package.json +1 -1
- package/node_modules/@ocean/core/package.json +1 -1
- package/node_modules/@ocean/loop/dist/hooks/desktop-facts.js +21 -1
- package/node_modules/@ocean/loop/dist/hooks/session-facts-hook.js +19 -1
- package/node_modules/@ocean/loop/dist/sessions/session-closeout.js +2 -9
- package/node_modules/@ocean/loop/package.json +1 -1
- package/node_modules/@ocean/market/package.json +1 -1
- package/node_modules/@ocean/services/dist/brief/brief.js +5 -1
- package/node_modules/@ocean/services/dist/day/day.js +203 -0
- package/node_modules/@ocean/services/dist/day/note.js +78 -0
- package/node_modules/@ocean/services/dist/distill/distill.js +1 -1
- package/node_modules/@ocean/services/dist/harvest/harvest.js +506 -0
- package/node_modules/@ocean/services/package.json +1 -1
- package/ocean-marketplace.json +66 -30
- package/package.json +7 -7
- package/skills/core/daily-harvest/SKILL.md +78 -0
- package/skills/core/memory-review/SKILL.md +53 -0
- package/skills/index.json +12 -0
- package/templates/workspace/06-templates/daily.md +0 -5
package/README.md
CHANGED
|
@@ -149,10 +149,12 @@ prints its usage and never runs it. To hand `--help` to a wrapped client, put it
|
|
|
149
149
|
| `ocean brief` | write the daily or weekly brief from your interests' feeds | Writes |
|
|
150
150
|
| `ocean interests` | propose interests from your projects or recurring session topics (as candidates), decay, keep/skip | Writes |
|
|
151
151
|
| `ocean distill` | `--week`: a weekly digest, decisions and lessons as candidates; `--month`: last month against your goals | Writes |
|
|
152
|
+
| `ocean harvest` | a day's sessions from every client into its summary; decisions, fixes and lessons filed into knowledge (undo per day); archive after 30 days | Writes |
|
|
153
|
+
| `ocean rhythm` | the day's rhythm, once per period and with no model: morning note, harvest, archive, last week's digest, last month's review (the service runs it) | Writes |
|
|
152
154
|
| `ocean telemetry` | recurring session errors and failing providers, as proposed backlog lines | Writes |
|
|
153
155
|
| `ocean express` | draft a CV section, LinkedIn post or scholarship paragraph from milestones | Writes |
|
|
154
156
|
| `ocean handoff` | hand work from one session or client to another | Reads; `create` writes |
|
|
155
|
-
| `ocean daily` |
|
|
157
|
+
| `ocean daily` | the morning half of today's note: focus, coming up, open loops, your hours, what waits on you, the brief | Reads; `--apply` writes |
|
|
156
158
|
| `ocean skill` | sync, add, review and learn skills | Reads; `add`, `review`, `learn`, `sync` write |
|
|
157
159
|
| `ocean catalog` | the AI clients Ocean can install | Reads |
|
|
158
160
|
| `ocean obsidian` | connect, sync and write to an Obsidian vault | Writes; vault writes need `--read-write` and `--apply` |
|
|
@@ -78,6 +78,23 @@ export function startBackgroundPull() {
|
|
|
78
78
|
// no pull this time; the next try runs it
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
+
// The day's rhythm (T-314) — morning note, harvest, archive, weekly and monthly reviews — each
|
|
82
|
+
// at most once per period, with no model. Session starts and ends run it; so does the service.
|
|
83
|
+
export function startBackgroundRhythm() {
|
|
84
|
+
if (process.env.OCEAN_NO_PULL_ON_START === "1")
|
|
85
|
+
return;
|
|
86
|
+
try {
|
|
87
|
+
spawn(process.execPath, [process.argv[1], "rhythm", "--yes"], {
|
|
88
|
+
detached: true,
|
|
89
|
+
stdio: "ignore",
|
|
90
|
+
})
|
|
91
|
+
.on("error", () => { })
|
|
92
|
+
.unref();
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// the next start runs it
|
|
96
|
+
}
|
|
97
|
+
}
|
|
81
98
|
const runCommand = (command, args) => promisify(execFile)(command, args);
|
|
82
99
|
function serviceContext(options) {
|
|
83
100
|
const home = options.home ?? os.homedir();
|
|
@@ -212,7 +229,11 @@ export async function runService(shutdownAfterMs) {
|
|
|
212
229
|
}
|
|
213
230
|
const heartbeat = setInterval(() => undefined, 60_000);
|
|
214
231
|
startBackgroundPull();
|
|
215
|
-
|
|
232
|
+
startBackgroundRhythm();
|
|
233
|
+
const dailyPull = setInterval(() => {
|
|
234
|
+
startBackgroundPull();
|
|
235
|
+
startBackgroundRhythm();
|
|
236
|
+
}, HOUR_MS);
|
|
216
237
|
startAutoReindex();
|
|
217
238
|
const autoReindex = setInterval(startAutoReindex, REINDEX_CHECK_MS);
|
|
218
239
|
startClaudeProjectsRefresh();
|
|
@@ -40,7 +40,7 @@ import { selectProfileForTask } from "../../application/profiles/profile-suggest
|
|
|
40
40
|
import { listSchedules, runDueSchedules, runSchedule, runSchedulerWorker, runSchedulerWorkerOnce, saveSchedule, setScheduleEnabled, } from "../../application/scheduler/local-scheduler.js";
|
|
41
41
|
import { defaultAgentRuntime, defaultBrainIndexPort, defaultProviderRegistry, defaultSessionStoreFactory, defaultSessionStoreOpener, defaultWrapperManager, } from "../../composition/runtime.js";
|
|
42
42
|
import { loadRuntimeConfig } from "../../infrastructure/filesystem/runtime-config-loader.js";
|
|
43
|
-
import { ensureService, restartService, runService, startBackgroundPull, } from "../../infrastructure/process/service.js";
|
|
43
|
+
import { ensureService, restartService, runService, startBackgroundPull, startBackgroundRhythm, } from "../../infrastructure/process/service.js";
|
|
44
44
|
import { createOllamaEmbedder } from "../../infrastructure/providers/ollama-embedder.js";
|
|
45
45
|
import { loadProviderRegistry } from "../../infrastructure/providers/provider-registry.js";
|
|
46
46
|
import { installShellPath, registerProvider, setProviderEnabled, syncProviderWrappers, wrapperDoctor, wrapperStatus, } from "../../infrastructure/wrappers/wrapper-manager.js";
|
|
@@ -60,6 +60,7 @@ import { runExpressCommand } from "./express-command.js";
|
|
|
60
60
|
import { gatewayFindings } from "./gateway-findings.js";
|
|
61
61
|
import { runLifecycleCommand, runPolicyCommand } from "./governance-command.js";
|
|
62
62
|
import { runHandoffCommand } from "./handoff-command.js";
|
|
63
|
+
import { runHarvestCommand } from "./harvest-command.js";
|
|
63
64
|
import { runIdeaCommand } from "./idea-command.js";
|
|
64
65
|
import { intercept } from "./intercept-command.js";
|
|
65
66
|
import { runInterestsCommand } from "./interests-command.js";
|
|
@@ -75,6 +76,7 @@ import { manageClients, runOnboardCommand } from "./onboard-command.js";
|
|
|
75
76
|
import { runOperateCommand } from "./operate-command.js";
|
|
76
77
|
import { runProfilesCommand } from "./profiles-command.js";
|
|
77
78
|
import { runPullCommand } from "./pull-command.js";
|
|
79
|
+
import { runRhythmCommand } from "./rhythm-command.js";
|
|
78
80
|
import { runningServerFindings } from "./running-server-findings.js";
|
|
79
81
|
import { insideFactsCall, runSessionFactsCommand, startSessionFacts, } from "./session-facts-command.js";
|
|
80
82
|
import { parseSetupArgs, SETUP_USAGE, setup } from "./setup-command.js";
|
|
@@ -643,6 +645,7 @@ async function commandHook() {
|
|
|
643
645
|
if (flags.includes("--repair"))
|
|
644
646
|
startBackgroundSync();
|
|
645
647
|
startBackgroundPull();
|
|
648
|
+
startBackgroundRhythm();
|
|
646
649
|
const inline = flags.find((arg) => arg.startsWith("--client="));
|
|
647
650
|
const clientIndex = flags.indexOf("--client");
|
|
648
651
|
const client = inline
|
|
@@ -687,6 +690,8 @@ async function commandHook() {
|
|
|
687
690
|
const payload = raw.trim() ? JSON.parse(raw) : {};
|
|
688
691
|
await claudeSessionEndHook(payload, defaultSessionStoreFactory, client);
|
|
689
692
|
await startSessionFacts(payload, client);
|
|
693
|
+
// The day's account picks up the session just closed (T-314), in the background.
|
|
694
|
+
startBackgroundRhythm();
|
|
690
695
|
}
|
|
691
696
|
catch (error) {
|
|
692
697
|
console.error(error instanceof Error ? error.message : String(error));
|
|
@@ -1240,6 +1245,8 @@ export const commandRegistry = {
|
|
|
1240
1245
|
brief: () => runBriefCommand(process.argv.slice(3)),
|
|
1241
1246
|
interests: () => runInterestsCommand(process.argv.slice(3)),
|
|
1242
1247
|
distill: () => runDistillCommand(process.argv.slice(3)),
|
|
1248
|
+
harvest: () => runHarvestCommand(process.argv.slice(3)),
|
|
1249
|
+
rhythm: () => runRhythmCommand(process.argv.slice(3)),
|
|
1243
1250
|
telemetry: () => runTelemetryCommand(process.argv.slice(3)),
|
|
1244
1251
|
express: () => runExpressCommand(process.argv.slice(3)),
|
|
1245
1252
|
daily: commandDaily,
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
1
|
import { createInterface } from "node:readline/promises";
|
|
4
2
|
import { listLessons, setLessonStatus } from "@ocean/brain/memory/lessons.js";
|
|
5
|
-
import { withFileLock } from "@ocean/core/shared/fs-utils.js";
|
|
6
3
|
import { localDate } from "@ocean/core/shared/local-date.js";
|
|
7
|
-
import {
|
|
8
|
-
import { openSessionStore } from "@ocean/loop/infrastructure/persistence/session-store.js";
|
|
9
|
-
import { listTasks } from "./tasks-command.js";
|
|
4
|
+
import { prepareDay } from "@ocean/services/day/day.js";
|
|
10
5
|
/**
|
|
11
6
|
* Interactive human-in-the-loop gate for candidate lessons (see lessons.ts). Only runs on a
|
|
12
7
|
* real TTY, so headless and scheduled invocations of `ocean daily start` never block on input.
|
|
@@ -60,72 +55,11 @@ export async function runDailyCommand(action, args) {
|
|
|
60
55
|
.join(" ")
|
|
61
56
|
.slice(0, 4_000)
|
|
62
57
|
: "";
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
.slice(0, 5)
|
|
70
|
-
.map((session) => ({
|
|
71
|
-
sessionId: session.sessionId,
|
|
72
|
-
title: session.title,
|
|
73
|
-
provider: session.provider,
|
|
74
|
-
status: session.status,
|
|
75
|
-
nextAction: session.nextAction,
|
|
76
|
-
}));
|
|
77
|
-
}
|
|
78
|
-
finally {
|
|
79
|
-
store.close();
|
|
80
|
-
}
|
|
81
|
-
const date = localDate();
|
|
82
|
-
const file = oceanPath(DAILY_DIR, `${date}.md`);
|
|
83
|
-
const content = `${[
|
|
84
|
-
`# Daily brief — ${date}`,
|
|
85
|
-
"",
|
|
86
|
-
"## Brief",
|
|
87
|
-
"",
|
|
88
|
-
tasks.length
|
|
89
|
-
? tasks
|
|
90
|
-
.map((task) => `- ${task.id}: ${task.title} — ${task.goal}`)
|
|
91
|
-
.join("\n")
|
|
92
|
-
: "- No active tasks.",
|
|
93
|
-
"",
|
|
94
|
-
"## Check-in",
|
|
95
|
-
"",
|
|
96
|
-
sessions.length
|
|
97
|
-
? sessions
|
|
98
|
-
.map((session) => `- ${session.sessionId}: ${session.title || session.provider} — ${session.status}${session.nextAction ? `; next: ${session.nextAction}` : ""}`)
|
|
99
|
-
.join("\n")
|
|
100
|
-
: "- No recent sessions.",
|
|
101
|
-
"",
|
|
102
|
-
"## News",
|
|
103
|
-
"",
|
|
104
|
-
news ||
|
|
105
|
-
"- No news supplied. The active AI client may research only the requested topics and pass a bounded summary with `--news`.",
|
|
106
|
-
]
|
|
107
|
-
.join("\n")
|
|
108
|
-
.slice(0, 12_000)}\n`;
|
|
109
|
-
if (apply) {
|
|
110
|
-
await mkdir(path.dirname(file), { recursive: true });
|
|
111
|
-
// Same lock as the session-closeout writers: a closeout landing between the check and
|
|
112
|
-
// the write would otherwise be overwritten (T-257).
|
|
113
|
-
await withFileLock(file, async () => {
|
|
114
|
-
const existing = await readFile(file, "utf8").catch(() => "");
|
|
115
|
-
if (existing.trim())
|
|
116
|
-
throw new Error(`Daily file already has content: ${file}`);
|
|
117
|
-
await writeFile(file, content, "utf8");
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
console.log(JSON.stringify({
|
|
121
|
-
apply,
|
|
122
|
-
date,
|
|
123
|
-
file,
|
|
124
|
-
bytes: Buffer.byteLength(content),
|
|
125
|
-
tasks: tasks.length,
|
|
126
|
-
sessions: sessions.length,
|
|
127
|
-
news: Boolean(news),
|
|
128
|
-
content,
|
|
129
|
-
}, null, 2));
|
|
58
|
+
// The morning half of the daily note (T-314): focus, coming up, open loops, hours, what
|
|
59
|
+
// waits on you, and the brief — between markers, so a rerun replaces only that block.
|
|
60
|
+
const plan = await prepareDay({ date: localDate(), apply, news });
|
|
61
|
+
console.log(JSON.stringify({ apply, ...plan }, null, 2));
|
|
62
|
+
if (!apply)
|
|
63
|
+
console.error("Dry run: pass --apply to write it.");
|
|
130
64
|
}
|
|
131
65
|
//# sourceMappingURL=daily-command.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { localDate } from "@ocean/core/shared/local-date.js";
|
|
2
|
+
import { openSessionStore } from "@ocean/loop/infrastructure/persistence/session-store.js";
|
|
3
|
+
import { archiveHarvested, harvestDay, pendingDays, undoDay, } from "@ocean/services/harvest/harvest.js";
|
|
4
|
+
const USAGE = "Usage: ocean harvest [--date YYYY-MM-DD | --pending] [--yes] | archive [--days N] [--yes] | undo <YYYY-MM-DD>";
|
|
5
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
6
|
+
// `ocean harvest` (T-314): a day's sessions from every AI client into that day's summary, their
|
|
7
|
+
// decisions, fixes and lessons into 05-knowledge on their own (undo per day), then archiving after
|
|
8
|
+
// 30 days. A dry run until --yes. The service runs `--pending --yes` once a day.
|
|
9
|
+
export async function runHarvestCommand(args) {
|
|
10
|
+
const apply = args.includes("--yes");
|
|
11
|
+
const [action] = args;
|
|
12
|
+
if (action === "undo") {
|
|
13
|
+
const date = args[1];
|
|
14
|
+
if (!date || !DATE.test(date))
|
|
15
|
+
throw new Error(USAGE);
|
|
16
|
+
console.log(JSON.stringify(await undoDay(date), null, 2));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (action === "archive") {
|
|
20
|
+
const at = args.indexOf("--days");
|
|
21
|
+
const days = at >= 0 ? Number(args[at + 1]) : 30;
|
|
22
|
+
if (!(days > 0))
|
|
23
|
+
throw new Error(USAGE);
|
|
24
|
+
const result = await archiveHarvested({ today: localDate(), days, apply });
|
|
25
|
+
console.log(JSON.stringify(result, null, 2));
|
|
26
|
+
if (!apply)
|
|
27
|
+
console.error("Dry run: pass --yes to move them.");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const at = args.indexOf("--date");
|
|
31
|
+
const dates = args.includes("--pending")
|
|
32
|
+
? await pendingDays(localDate())
|
|
33
|
+
: [at >= 0 ? args[at + 1] : localDate()];
|
|
34
|
+
if (dates.some((date) => !date || !DATE.test(date)))
|
|
35
|
+
throw new Error(USAGE);
|
|
36
|
+
const store = await openSessionStore();
|
|
37
|
+
try {
|
|
38
|
+
const sessions = store.list();
|
|
39
|
+
const results = [];
|
|
40
|
+
for (const date of dates)
|
|
41
|
+
results.push(await harvestDay({
|
|
42
|
+
date,
|
|
43
|
+
apply,
|
|
44
|
+
store: { sessions, eventsOf: (id) => store.listEvents(id) },
|
|
45
|
+
}));
|
|
46
|
+
// The daily run also archives what has been harvested for 30 days.
|
|
47
|
+
const archived = args.includes("--pending")
|
|
48
|
+
? await archiveHarvested({ today: localDate(), apply })
|
|
49
|
+
: null;
|
|
50
|
+
console.log(JSON.stringify({ days: results, archived }, null, 2));
|
|
51
|
+
if (!apply)
|
|
52
|
+
console.error("Dry run: pass --yes to write.");
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
store.close();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=harvest-command.js.map
|
|
@@ -13,7 +13,7 @@ const commandGroups = [
|
|
|
13
13
|
],
|
|
14
14
|
[
|
|
15
15
|
"Knowledge",
|
|
16
|
-
"memory, pull, desktop, observe, capture, note, brief, interests, distill, telemetry, express, handoff, idea, daily, skill, catalog",
|
|
16
|
+
"memory, pull, desktop, observe, capture, note, brief, interests, distill, harvest, rhythm, telemetry, express, handoff, idea, daily, skill, catalog",
|
|
17
17
|
],
|
|
18
18
|
["Integrations", "obsidian, hook, migrate, layout, env"],
|
|
19
19
|
];
|
|
@@ -164,6 +164,14 @@ export const commandHelp = {
|
|
|
164
164
|
"Distill a week (digest in 01-daily/weekly/, decisions and lessons as candidates), or review last month against goals.md (01-daily/monthly/).",
|
|
165
165
|
"ocean distill --week [--date YYYY-MM-DD] [--yes] | --month [--month-of YYYY-MM] [--yes]",
|
|
166
166
|
],
|
|
167
|
+
harvest: [
|
|
168
|
+
"Harvest a day's sessions from every AI client: the day's summary, decisions, fixes and lessons filed into 05-knowledge (undo per day), archive after 30 days.",
|
|
169
|
+
"ocean harvest [--date YYYY-MM-DD | --pending] [--yes] | archive [--days N] [--yes] | undo <YYYY-MM-DD>",
|
|
170
|
+
],
|
|
171
|
+
rhythm: [
|
|
172
|
+
"Run the day's rhythm once per period, no model: morning note, harvest, archive, last week's digest, last month's review.",
|
|
173
|
+
"ocean rhythm [--yes]",
|
|
174
|
+
],
|
|
167
175
|
telemetry: [
|
|
168
176
|
"Find recurring errors and failing providers in recent sessions; propose them as backlog lines.",
|
|
169
177
|
"ocean telemetry [--days N] [--yes]",
|
|
@@ -185,7 +193,7 @@ export const commandHelp = {
|
|
|
185
193
|
"ocean idea save <title> <content> [--session <id>]|list [status]|classify <id> <target>|discard <id>",
|
|
186
194
|
],
|
|
187
195
|
daily: [
|
|
188
|
-
"
|
|
196
|
+
"Write the morning half of today's note (focus, coming up, open loops, hours, waiting on you, brief); --apply writes it.",
|
|
189
197
|
"ocean daily start [--apply] [--news <bounded-news-summary>]",
|
|
190
198
|
],
|
|
191
199
|
skill: [
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { atomicWrite, withFileLock } from "@ocean/core/shared/fs-utils.js";
|
|
4
|
+
import { localDate } from "@ocean/core/shared/local-date.js";
|
|
5
|
+
import { oceanPath, SYSTEM_DIR } from "@ocean/core/shared/paths.js";
|
|
6
|
+
import { openSessionStore } from "@ocean/loop/infrastructure/persistence/session-store.js";
|
|
7
|
+
import { prepareDay } from "@ocean/services/day/day.js";
|
|
8
|
+
import { hasBlock, noteFile } from "@ocean/services/day/note.js";
|
|
9
|
+
import { distillWeek, isoWeek, reviewMonth, } from "@ocean/services/distill/distill.js";
|
|
10
|
+
import { archiveHarvested, harvestDay, pendingDays, } from "@ocean/services/harvest/harvest.js";
|
|
11
|
+
// `ocean rhythm [--yes]` (T-314): everything the day, week and month need, with no model, each
|
|
12
|
+
// at most once: today's morning note, every day not yet harvested (and today so far), the
|
|
13
|
+
// archive, last week's digest once the week is over, last month's review once the month is over.
|
|
14
|
+
// The background service runs it at each session start; a run with nothing due is quick.
|
|
15
|
+
const stampFile = () => oceanPath(SYSTEM_DIR, "state", "rhythm.json");
|
|
16
|
+
const previousMonth = (date) => {
|
|
17
|
+
const [year, month] = date.split("-").map(Number);
|
|
18
|
+
return month === 1
|
|
19
|
+
? `${year - 1}-12`
|
|
20
|
+
: `${year}-${String(month - 1).padStart(2, "0")}`;
|
|
21
|
+
};
|
|
22
|
+
export async function runRhythmCommand(args) {
|
|
23
|
+
await mkdir(path.dirname(stampFile()), { recursive: true });
|
|
24
|
+
// One run at a time: a session start and the hourly service tick can land together.
|
|
25
|
+
await withFileLock(stampFile(), () => rhythm(args));
|
|
26
|
+
}
|
|
27
|
+
async function rhythm(args) {
|
|
28
|
+
const apply = args.includes("--yes");
|
|
29
|
+
const today = localDate();
|
|
30
|
+
const stamp = JSON.parse(await readFile(stampFile(), "utf8").catch(() => "{}"));
|
|
31
|
+
const done = {};
|
|
32
|
+
// Morning: once a day, when today's note has no Today block yet.
|
|
33
|
+
const note = await readFile(noteFile(today), "utf8").catch(() => "");
|
|
34
|
+
if (!hasBlock(note, "day"))
|
|
35
|
+
done.day = (await prepareDay({ date: today, apply })).note;
|
|
36
|
+
// The days not yet told, then today so far.
|
|
37
|
+
const store = await openSessionStore();
|
|
38
|
+
try {
|
|
39
|
+
const sessions = store.list();
|
|
40
|
+
const eventsOf = (id) => store.listEvents(id);
|
|
41
|
+
const days = [...(await pendingDays(today)), today];
|
|
42
|
+
const told = [];
|
|
43
|
+
for (const date of days) {
|
|
44
|
+
const result = await harvestDay({
|
|
45
|
+
date,
|
|
46
|
+
apply,
|
|
47
|
+
store: { sessions, eventsOf },
|
|
48
|
+
});
|
|
49
|
+
if (result.note)
|
|
50
|
+
told.push(date);
|
|
51
|
+
}
|
|
52
|
+
done.harvested = told;
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
store.close();
|
|
56
|
+
}
|
|
57
|
+
done.archived = await archiveHarvested({ today, apply });
|
|
58
|
+
// Last week, once it is over.
|
|
59
|
+
const lastWeek = isoWeek(new Date(Date.parse(today) - 7 * 24 * 60 * 60 * 1000)
|
|
60
|
+
.toISOString()
|
|
61
|
+
.slice(0, 10));
|
|
62
|
+
if (stamp.week !== lastWeek.label) {
|
|
63
|
+
done.week = await distillWeek({ date: lastWeek.from, apply });
|
|
64
|
+
if (apply)
|
|
65
|
+
stamp.week = lastWeek.label;
|
|
66
|
+
}
|
|
67
|
+
// Last month, once it is over (the review itself is written once and never overwritten).
|
|
68
|
+
const month = previousMonth(today);
|
|
69
|
+
if (stamp.month !== month) {
|
|
70
|
+
done.month = await reviewMonth({ month, apply });
|
|
71
|
+
if (apply)
|
|
72
|
+
stamp.month = month;
|
|
73
|
+
}
|
|
74
|
+
if (apply) {
|
|
75
|
+
await atomicWrite(stampFile(), `${JSON.stringify(stamp, null, 2)}\n`);
|
|
76
|
+
}
|
|
77
|
+
console.log(JSON.stringify(done, null, 2));
|
|
78
|
+
if (!apply)
|
|
79
|
+
console.error("Dry run: pass --yes to write.");
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=rhythm-command.js.map
|
|
@@ -59,7 +59,7 @@ export async function runSessionFactsCommand(args) {
|
|
|
59
59
|
session_id: sessionId,
|
|
60
60
|
transcript_path: transcript,
|
|
61
61
|
cwd: value("--cwd"),
|
|
62
|
-
}, defaultSessionStoreFactory, client, (each) => sessionFactsCompleter(each));
|
|
62
|
+
}, defaultSessionStoreFactory, client, (each) => sessionFactsCompleter(each), { digest: true });
|
|
63
63
|
console.log(JSON.stringify(run, null, 2));
|
|
64
64
|
}
|
|
65
65
|
//# sourceMappingURL=session-facts-command.js.map
|
|
@@ -191,4 +191,59 @@ export async function migrateBrainDumps(options) {
|
|
|
191
191
|
}
|
|
192
192
|
return { moved, skipped };
|
|
193
193
|
}
|
|
194
|
+
// A chat with no session in the store (Claude Desktop, an export: T-314) gets the same record, from
|
|
195
|
+
// the digest its fact extraction returned — no model call of its own. One record per captured
|
|
196
|
+
// stretch of the conversation, dated by its newest message.
|
|
197
|
+
export async function writeDigestRecord(input) {
|
|
198
|
+
const { digest } = input;
|
|
199
|
+
const date = localDate(localMoment(input.endedAt));
|
|
200
|
+
const time = localTime(localMoment(input.startedAt));
|
|
201
|
+
const title = safeText(digest.title || digest.goal, 120) || "Conversation";
|
|
202
|
+
const quote = (value) => JSON.stringify(value);
|
|
203
|
+
const list = (heading, items) => items.length
|
|
204
|
+
? [
|
|
205
|
+
"",
|
|
206
|
+
`## ${heading}`,
|
|
207
|
+
"",
|
|
208
|
+
...items.map((item) => `- ${safeText(item, 300)}`),
|
|
209
|
+
]
|
|
210
|
+
: [];
|
|
211
|
+
const lines = [
|
|
212
|
+
"---",
|
|
213
|
+
"type: session",
|
|
214
|
+
`project: ${quote(input.project ?? "")}`,
|
|
215
|
+
`provider: ${quote(input.provider)}`,
|
|
216
|
+
"status: completed",
|
|
217
|
+
`session_id: ${quote(input.sessionId)}`,
|
|
218
|
+
`date: ${date}`,
|
|
219
|
+
"tags: []",
|
|
220
|
+
"distilled: false",
|
|
221
|
+
"---",
|
|
222
|
+
"",
|
|
223
|
+
`# ${title}`,
|
|
224
|
+
"",
|
|
225
|
+
"## Goal",
|
|
226
|
+
"",
|
|
227
|
+
safeText(digest.goal, 300) || "Not stated.",
|
|
228
|
+
"",
|
|
229
|
+
"## Outcome",
|
|
230
|
+
"",
|
|
231
|
+
safeText(digest.outcome, 300) || "Not stated.",
|
|
232
|
+
...list("Decisions", digest.decisions),
|
|
233
|
+
...list("Problems → fixes", digest.fixes),
|
|
234
|
+
...list("Learned", digest.learned),
|
|
235
|
+
"",
|
|
236
|
+
"## Verification",
|
|
237
|
+
"",
|
|
238
|
+
"NOT PROVEN — summarized from a chat; nothing was run.",
|
|
239
|
+
...list("Next", digest.next),
|
|
240
|
+
"",
|
|
241
|
+
];
|
|
242
|
+
const directory = oceanPath(DAILY_DIR, "sessions", date.slice(0, 7));
|
|
243
|
+
await mkdir(directory, { recursive: true });
|
|
244
|
+
const filename = await uniqueFilename(directory, `${date}-${time.replace(":", "")}-${slugify(title).length >= MIN_USEFUL_SLUG_LENGTH ? slugify(title) : input.provider}`, ".md");
|
|
245
|
+
const file = path.join(directory, filename);
|
|
246
|
+
await writeFile(file, `${lines.join("\n")}\n`, "utf8");
|
|
247
|
+
return { path: path.relative(oceanRoot(), file).split(path.sep).join("/") };
|
|
248
|
+
}
|
|
194
249
|
//# sourceMappingURL=brain-dump.js.map
|
|
@@ -53,7 +53,13 @@ export function selectTurns(turns, budgetChars = DEFAULT_FACTS_BUDGET_CHARS) {
|
|
|
53
53
|
.filter((turn) => chosen.has(turn.index))
|
|
54
54
|
.map(({ role, text }) => ({ role, text }));
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
const DIGEST_ITEMS = 3;
|
|
57
|
+
const DIGEST_ITEM_CHARS = 220;
|
|
58
|
+
const DIGEST_PROMPT = [
|
|
59
|
+
"Also summarize the whole conversation for the user's daily log, in the digest field. Plain short sentences in English; lists may be empty; never a secret or a [REDACTED] value.",
|
|
60
|
+
`title: what the conversation was about, at most 8 words. goal and outcome: one sentence each. decisions, fixes ("problem → fix"), learned, next: at most ${DIGEST_ITEMS} items each.`,
|
|
61
|
+
];
|
|
62
|
+
export function buildFactsPrompt(turns, options = {}) {
|
|
57
63
|
const transcript = turns
|
|
58
64
|
.map((turn) => `[${turn.role === "user" ? "USER" : "ASSISTANT"}] ${turn.text}`)
|
|
59
65
|
.join("\n");
|
|
@@ -63,8 +69,9 @@ export function buildFactsPrompt(turns) {
|
|
|
63
69
|
"Only extract what the USER stated or explicitly confirmed. Never extract the assistant's suggestions, guesses or plans the user did not confirm.",
|
|
64
70
|
"Never extract temporary state (what is being debugged right now, today's to-do, a file being edited), secrets, credentials, or anything marked [REDACTED] or [PRIVATE_PATH].",
|
|
65
71
|
`Return at most ${MAX_FACTS} facts. Returning none is correct and common.`,
|
|
72
|
+
...(options.digest ? DIGEST_PROMPT : []),
|
|
66
73
|
"Answer with JSON only, no prose and no code fence:",
|
|
67
|
-
|
|
74
|
+
`{"facts":[{"title":"short label","content":"the fact as one or two plain sentences","evidence":"an exact quote, copied character for character from one USER line","reason":"why it is durable","type":"one of the types below","project":"project name if the fact is about one, else omit"}]${options.digest ? ',"digest":{"title":"","goal":"","outcome":"","decisions":[],"fixes":[],"learned":[],"next":[]}' : ""}}`,
|
|
68
75
|
`type is one of: ${FACT_TYPES.join(", ")}. Use project only for a fact about one project, and then also give its project name; a fact about the user stays a personal type even when it came up in a project.`,
|
|
69
76
|
'Answer {"facts":[]} when nothing qualifies.',
|
|
70
77
|
"",
|
|
@@ -99,6 +106,39 @@ function factsList(text) {
|
|
|
99
106
|
? parsed.facts
|
|
100
107
|
: null;
|
|
101
108
|
}
|
|
109
|
+
// The digest the answer holds, cleaned and bounded; null when there is none or it says nothing.
|
|
110
|
+
export function parseDigest(text) {
|
|
111
|
+
if (!text)
|
|
112
|
+
return null;
|
|
113
|
+
const start = text.indexOf("{");
|
|
114
|
+
const end = text.lastIndexOf("}");
|
|
115
|
+
if (start < 0 || end <= start)
|
|
116
|
+
return null;
|
|
117
|
+
let value;
|
|
118
|
+
try {
|
|
119
|
+
const parsed = JSON.parse(text.slice(start, end + 1));
|
|
120
|
+
if (!parsed.digest || typeof parsed.digest !== "object")
|
|
121
|
+
return null;
|
|
122
|
+
value = parsed.digest;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const list = (key) => (Array.isArray(value[key]) ? value[key] : [])
|
|
128
|
+
.map((item) => redactSecrets(clean(item, DIGEST_ITEM_CHARS)))
|
|
129
|
+
.filter((item) => item && !/\[(redacted|private_path)\]/i.test(item))
|
|
130
|
+
.slice(0, DIGEST_ITEMS);
|
|
131
|
+
const digest = {
|
|
132
|
+
title: redactSecrets(clean(value.title, 80)),
|
|
133
|
+
goal: redactSecrets(clean(value.goal, DIGEST_ITEM_CHARS)),
|
|
134
|
+
outcome: redactSecrets(clean(value.outcome, DIGEST_ITEM_CHARS)),
|
|
135
|
+
decisions: list("decisions"),
|
|
136
|
+
fixes: list("fixes"),
|
|
137
|
+
learned: list("learned"),
|
|
138
|
+
next: list("next"),
|
|
139
|
+
};
|
|
140
|
+
return digest.title || digest.goal ? digest : null;
|
|
141
|
+
}
|
|
102
142
|
export function parseFacts(text) {
|
|
103
143
|
const list = factsList(text) ?? [];
|
|
104
144
|
const facts = [];
|
|
@@ -145,7 +185,7 @@ export async function extractSessionFacts(options) {
|
|
|
145
185
|
const turns = selectTurns(options.turns, options.budgetChars);
|
|
146
186
|
if (!turns.some((turn) => turn.role === "user"))
|
|
147
187
|
return { facts: [], rejected: [], prompt: "", turns: 0, failed: false };
|
|
148
|
-
const prompt = buildFactsPrompt(turns);
|
|
188
|
+
const prompt = buildFactsPrompt(turns, { digest: options.digest });
|
|
149
189
|
let answer = null;
|
|
150
190
|
try {
|
|
151
191
|
answer = await options.complete(prompt);
|
|
@@ -170,6 +210,7 @@ export async function extractSessionFacts(options) {
|
|
|
170
210
|
prompt,
|
|
171
211
|
turns: turns.length,
|
|
172
212
|
failed: factsList(answer) === null,
|
|
213
|
+
...(options.digest ? { digest: parseDigest(answer) } : {}),
|
|
173
214
|
};
|
|
174
215
|
}
|
|
175
216
|
const factKey = (fact) => `f:${sha256(normalize(fact.content))}`;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mkdir, readFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { writeDigestRecord } from "@ocean/brain/memory/brain-dump.js";
|
|
3
4
|
import { sessionFactsEnabled } from "@ocean/brain/memory/memory-audit.js";
|
|
4
5
|
import { extractSessionFacts, proposeSessionFacts, } from "@ocean/brain/memory/session-facts.js";
|
|
5
6
|
import { atomicWrite, withFileLock } from "@ocean/core/shared/fs-utils.js";
|
|
@@ -119,7 +120,12 @@ async function captureOne(conversation, complete) {
|
|
|
119
120
|
.map(toTurn);
|
|
120
121
|
if (!turns.some((turn) => turn.role === "user"))
|
|
121
122
|
return { ...base, status: "no-user-text" };
|
|
122
|
-
|
|
123
|
+
// The same call also returns the conversation's digest for the day's log (no second call).
|
|
124
|
+
const extraction = await extractSessionFacts({
|
|
125
|
+
turns,
|
|
126
|
+
complete,
|
|
127
|
+
digest: true,
|
|
128
|
+
});
|
|
123
129
|
if (extraction.failed) {
|
|
124
130
|
// Nothing was learned: hand the turns back, unless a later run already claimed past them.
|
|
125
131
|
await locked(async (state) => {
|
|
@@ -143,9 +149,23 @@ async function captureOne(conversation, complete) {
|
|
|
143
149
|
client: DESKTOP_CLIENT,
|
|
144
150
|
facts: extraction.facts,
|
|
145
151
|
});
|
|
152
|
+
let record;
|
|
153
|
+
if (extraction.digest) {
|
|
154
|
+
const times = dated
|
|
155
|
+
.filter((message) => message.createdAt > claim.from)
|
|
156
|
+
.map((message) => message.createdAt);
|
|
157
|
+
record = (await writeDigestRecord({
|
|
158
|
+
provider: DESKTOP_CLIENT,
|
|
159
|
+
sessionId: `desktop:${conversation.uuid}`,
|
|
160
|
+
startedAt: times[0] ?? newest,
|
|
161
|
+
endedAt: newest,
|
|
162
|
+
digest: extraction.digest,
|
|
163
|
+
})).path;
|
|
164
|
+
}
|
|
146
165
|
return {
|
|
147
166
|
...base,
|
|
148
167
|
status: "done",
|
|
168
|
+
...(record ? { record } : {}),
|
|
149
169
|
candidates: proposed.proposed,
|
|
150
170
|
rejected: extraction.rejected.length,
|
|
151
171
|
skipped: proposed.skipped.length,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mkdir, open, stat } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { writeDigestRecord } from "@ocean/brain/memory/brain-dump.js";
|
|
3
4
|
import { sessionFactsEnabled } from "@ocean/brain/memory/memory-audit.js";
|
|
4
5
|
import { extractSessionFacts, proposeSessionFacts, } from "@ocean/brain/memory/session-facts.js";
|
|
5
6
|
import { safeJsonParse, withFileLock } from "@ocean/core/shared/fs-utils.js";
|
|
@@ -91,7 +92,10 @@ function latestClaim(store, sessionId, transcriptPath) {
|
|
|
91
92
|
function lockFile(sessionId) {
|
|
92
93
|
return oceanPath(SYSTEM_DIR, "state", "memory", "extract", sessionId.replace(/[^A-Za-z0-9_-]/g, "_"));
|
|
93
94
|
}
|
|
94
|
-
export async function runSessionFacts(payload, openStore, client, completer,
|
|
95
|
+
export async function runSessionFacts(payload, openStore, client, completer,
|
|
96
|
+
// digest: the same call also returns the stretch's summary, written as a session record so a
|
|
97
|
+
// long session is in the day's account before it ends (T-314) — no second model call.
|
|
98
|
+
options = {}) {
|
|
95
99
|
if (!(await (options.enabled ?? sessionFactsEnabled)()))
|
|
96
100
|
return { status: "off" };
|
|
97
101
|
const sessionId = payload.session_id;
|
|
@@ -130,6 +134,7 @@ export async function runSessionFacts(payload, openStore, client, completer, opt
|
|
|
130
134
|
const extraction = await extractSessionFacts({
|
|
131
135
|
turns: claim.slice.turns,
|
|
132
136
|
complete,
|
|
137
|
+
digest: options.digest,
|
|
133
138
|
});
|
|
134
139
|
if (extraction.failed) {
|
|
135
140
|
// Nothing was learned: hand the turns back, unless a later run already claimed past them.
|
|
@@ -156,8 +161,21 @@ export async function runSessionFacts(payload, openStore, client, completer, opt
|
|
|
156
161
|
client,
|
|
157
162
|
facts: extraction.facts,
|
|
158
163
|
});
|
|
164
|
+
let record;
|
|
165
|
+
if (extraction.digest) {
|
|
166
|
+
const now = new Date().toISOString();
|
|
167
|
+
record = (await writeDigestRecord({
|
|
168
|
+
provider: client,
|
|
169
|
+
sessionId,
|
|
170
|
+
startedAt: now,
|
|
171
|
+
endedAt: now,
|
|
172
|
+
digest: extraction.digest,
|
|
173
|
+
project: payload.cwd ? path.basename(payload.cwd) : "",
|
|
174
|
+
})).path;
|
|
175
|
+
}
|
|
159
176
|
const run = {
|
|
160
177
|
status: "done",
|
|
178
|
+
...(record ? { record } : {}),
|
|
161
179
|
from: claim.from,
|
|
162
180
|
to: claim.slice.offset,
|
|
163
181
|
candidates: proposed.proposed,
|