@amoree-code/ocean 1.8.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 +2 -1
- package/dist/infrastructure/process/service.js +18 -5
- package/dist/interfaces/cli/command-registry.js +7 -2
- package/dist/interfaces/cli/daily-command.js +7 -73
- package/dist/interfaces/cli/harvest-command.js +1 -1
- package/dist/interfaces/cli/help-command.js +6 -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/harvest/harvest.js +87 -34
- package/node_modules/@ocean/services/package.json +1 -1
- package/ocean-marketplace.json +35 -35
- package/package.json +7 -7
- package/skills/core/daily-harvest/SKILL.md +11 -5
- package/templates/workspace/06-templates/daily.md +0 -5
package/README.md
CHANGED
|
@@ -150,10 +150,11 @@ prints its usage and never runs it. To hand `--help` to a wrapped client, put it
|
|
|
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
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 |
|
|
153
154
|
| `ocean telemetry` | recurring session errors and failing providers, as proposed backlog lines | Writes |
|
|
154
155
|
| `ocean express` | draft a CV section, LinkedIn post or scholarship paragraph from milestones | Writes |
|
|
155
156
|
| `ocean handoff` | hand work from one session or client to another | Reads; `create` writes |
|
|
156
|
-
| `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 |
|
|
157
158
|
| `ocean skill` | sync, add, review and learn skills | Reads; `add`, `review`, `learn`, `sync` write |
|
|
158
159
|
| `ocean catalog` | the AI clients Ocean can install | Reads |
|
|
159
160
|
| `ocean obsidian` | connect, sync and write to an Obsidian vault | Writes; vault writes need `--read-write` and `--apply` |
|
|
@@ -73,9 +73,18 @@ export function startBackgroundPull() {
|
|
|
73
73
|
})
|
|
74
74
|
.on("error", () => { })
|
|
75
75
|
.unref();
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// no pull this time; the next try runs it
|
|
79
|
+
}
|
|
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"], {
|
|
79
88
|
detached: true,
|
|
80
89
|
stdio: "ignore",
|
|
81
90
|
})
|
|
@@ -83,7 +92,7 @@ export function startBackgroundPull() {
|
|
|
83
92
|
.unref();
|
|
84
93
|
}
|
|
85
94
|
catch {
|
|
86
|
-
//
|
|
95
|
+
// the next start runs it
|
|
87
96
|
}
|
|
88
97
|
}
|
|
89
98
|
const runCommand = (command, args) => promisify(execFile)(command, args);
|
|
@@ -220,7 +229,11 @@ export async function runService(shutdownAfterMs) {
|
|
|
220
229
|
}
|
|
221
230
|
const heartbeat = setInterval(() => undefined, 60_000);
|
|
222
231
|
startBackgroundPull();
|
|
223
|
-
|
|
232
|
+
startBackgroundRhythm();
|
|
233
|
+
const dailyPull = setInterval(() => {
|
|
234
|
+
startBackgroundPull();
|
|
235
|
+
startBackgroundRhythm();
|
|
236
|
+
}, HOUR_MS);
|
|
224
237
|
startAutoReindex();
|
|
225
238
|
const autoReindex = setInterval(startAutoReindex, REINDEX_CHECK_MS);
|
|
226
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";
|
|
@@ -56,11 +56,11 @@ import { runContextCommand, runContextCostCommand } from "./context-command.js";
|
|
|
56
56
|
import { runDailyCommand } from "./daily-command.js";
|
|
57
57
|
import { runDesktopCommand } from "./desktop-command.js";
|
|
58
58
|
import { runDistillCommand } from "./distill-command.js";
|
|
59
|
-
import { runHarvestCommand } from "./harvest-command.js";
|
|
60
59
|
import { runExpressCommand } from "./express-command.js";
|
|
61
60
|
import { gatewayFindings } from "./gateway-findings.js";
|
|
62
61
|
import { runLifecycleCommand, runPolicyCommand } from "./governance-command.js";
|
|
63
62
|
import { runHandoffCommand } from "./handoff-command.js";
|
|
63
|
+
import { runHarvestCommand } from "./harvest-command.js";
|
|
64
64
|
import { runIdeaCommand } from "./idea-command.js";
|
|
65
65
|
import { intercept } from "./intercept-command.js";
|
|
66
66
|
import { runInterestsCommand } from "./interests-command.js";
|
|
@@ -76,6 +76,7 @@ import { manageClients, runOnboardCommand } from "./onboard-command.js";
|
|
|
76
76
|
import { runOperateCommand } from "./operate-command.js";
|
|
77
77
|
import { runProfilesCommand } from "./profiles-command.js";
|
|
78
78
|
import { runPullCommand } from "./pull-command.js";
|
|
79
|
+
import { runRhythmCommand } from "./rhythm-command.js";
|
|
79
80
|
import { runningServerFindings } from "./running-server-findings.js";
|
|
80
81
|
import { insideFactsCall, runSessionFactsCommand, startSessionFacts, } from "./session-facts-command.js";
|
|
81
82
|
import { parseSetupArgs, SETUP_USAGE, setup } from "./setup-command.js";
|
|
@@ -644,6 +645,7 @@ async function commandHook() {
|
|
|
644
645
|
if (flags.includes("--repair"))
|
|
645
646
|
startBackgroundSync();
|
|
646
647
|
startBackgroundPull();
|
|
648
|
+
startBackgroundRhythm();
|
|
647
649
|
const inline = flags.find((arg) => arg.startsWith("--client="));
|
|
648
650
|
const clientIndex = flags.indexOf("--client");
|
|
649
651
|
const client = inline
|
|
@@ -688,6 +690,8 @@ async function commandHook() {
|
|
|
688
690
|
const payload = raw.trim() ? JSON.parse(raw) : {};
|
|
689
691
|
await claudeSessionEndHook(payload, defaultSessionStoreFactory, client);
|
|
690
692
|
await startSessionFacts(payload, client);
|
|
693
|
+
// The day's account picks up the session just closed (T-314), in the background.
|
|
694
|
+
startBackgroundRhythm();
|
|
691
695
|
}
|
|
692
696
|
catch (error) {
|
|
693
697
|
console.error(error instanceof Error ? error.message : String(error));
|
|
@@ -1242,6 +1246,7 @@ export const commandRegistry = {
|
|
|
1242
1246
|
interests: () => runInterestsCommand(process.argv.slice(3)),
|
|
1243
1247
|
distill: () => runDistillCommand(process.argv.slice(3)),
|
|
1244
1248
|
harvest: () => runHarvestCommand(process.argv.slice(3)),
|
|
1249
|
+
rhythm: () => runRhythmCommand(process.argv.slice(3)),
|
|
1245
1250
|
telemetry: () => runTelemetryCommand(process.argv.slice(3)),
|
|
1246
1251
|
express: () => runExpressCommand(process.argv.slice(3)),
|
|
1247
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
|
|
@@ -3,7 +3,7 @@ import { openSessionStore } from "@ocean/loop/infrastructure/persistence/session
|
|
|
3
3
|
import { archiveHarvested, harvestDay, pendingDays, undoDay, } from "@ocean/services/harvest/harvest.js";
|
|
4
4
|
const USAGE = "Usage: ocean harvest [--date YYYY-MM-DD | --pending] [--yes] | archive [--days N] [--yes] | undo <YYYY-MM-DD>";
|
|
5
5
|
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
6
|
-
// `ocean harvest` (T-
|
|
6
|
+
// `ocean harvest` (T-314): a day's sessions from every AI client into that day's summary, their
|
|
7
7
|
// decisions, fixes and lessons into 05-knowledge on their own (undo per day), then archiving after
|
|
8
8
|
// 30 days. A dry run until --yes. The service runs `--pending --yes` once a day.
|
|
9
9
|
export async function runHarvestCommand(args) {
|
|
@@ -13,7 +13,7 @@ const commandGroups = [
|
|
|
13
13
|
],
|
|
14
14
|
[
|
|
15
15
|
"Knowledge",
|
|
16
|
-
"memory, pull, desktop, observe, capture, note, brief, interests, distill, harvest, 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
|
];
|
|
@@ -168,6 +168,10 @@ export const commandHelp = {
|
|
|
168
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
169
|
"ocean harvest [--date YYYY-MM-DD | --pending] [--yes] | archive [--days N] [--yes] | undo <YYYY-MM-DD>",
|
|
170
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
|
+
],
|
|
171
175
|
telemetry: [
|
|
172
176
|
"Find recurring errors and failing providers in recent sessions; propose them as backlog lines.",
|
|
173
177
|
"ocean telemetry [--days N] [--yes]",
|
|
@@ -189,7 +193,7 @@ export const commandHelp = {
|
|
|
189
193
|
"ocean idea save <title> <content> [--session <id>]|list [status]|classify <id> <target>|discard <id>",
|
|
190
194
|
],
|
|
191
195
|
daily: [
|
|
192
|
-
"
|
|
196
|
+
"Write the morning half of today's note (focus, coming up, open loops, hours, waiting on you, brief); --apply writes it.",
|
|
193
197
|
"ocean daily start [--apply] [--news <bounded-news-summary>]",
|
|
194
198
|
],
|
|
195
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,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { writeBrainDump } from "@ocean/brain/memory/brain-dump.js";
|
|
2
|
-
import { appendDailyNarrative, appendObservations, } from "@ocean/brain/memory/daily-narrative.js";
|
|
3
2
|
import { learnFromSession, } from "@ocean/brain/memory/lesson-learning.js";
|
|
4
3
|
import { generateModelNarrative } from "@ocean/brain/memory/model-narrative.js";
|
|
5
4
|
import { writeSessionSummary, } from "@ocean/brain/memory/session-summary.js";
|
|
@@ -107,7 +106,6 @@ export async function finalizeSession(store, sessionId, input = {}) {
|
|
|
107
106
|
promoted: learning.promoted,
|
|
108
107
|
errors: learning.errors,
|
|
109
108
|
}));
|
|
110
|
-
await appendObservations(session, observations);
|
|
111
109
|
}
|
|
112
110
|
catch (error) {
|
|
113
111
|
store.appendEvent(sessionId, "closeout_warning", error instanceof Error ? error.message : String(error));
|
|
@@ -119,13 +117,8 @@ export async function finalizeSession(store, sessionId, input = {}) {
|
|
|
119
117
|
changedFiles: files,
|
|
120
118
|
nextAction: input.nextAction,
|
|
121
119
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
events,
|
|
125
|
-
exitCode,
|
|
126
|
-
nextAction: input.nextAction,
|
|
127
|
-
narrative,
|
|
128
|
-
});
|
|
120
|
+
// The daily note is written by the harvest from the session record below (T-314); the
|
|
121
|
+
// closeout no longer adds its own lines there, so the day is told once.
|
|
129
122
|
await writeBrainDump({
|
|
130
123
|
session,
|
|
131
124
|
events,
|