@amoree-code/ocean 1.7.0 → 1.8.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 CHANGED
@@ -149,6 +149,7 @@ 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 |
152
153
  | `ocean telemetry` | recurring session errors and failing providers, as proposed backlog lines | Writes |
153
154
  | `ocean express` | draft a CV section, LinkedIn post or scholarship paragraph from milestones | Writes |
154
155
  | `ocean handoff` | hand work from one session or client to another | Reads; `create` writes |
@@ -73,6 +73,14 @@ export function startBackgroundPull() {
73
73
  })
74
74
  .on("error", () => { })
75
75
  .unref();
76
+ // The daily harvest (T-316) rides the same start: days not yet harvested, then the archive.
77
+ // It returns at once when nothing is pending.
78
+ spawn(process.execPath, [process.argv[1], "harvest", "--pending", "--yes"], {
79
+ detached: true,
80
+ stdio: "ignore",
81
+ })
82
+ .on("error", () => { })
83
+ .unref();
76
84
  }
77
85
  catch {
78
86
  // no pull this time; the next try runs it
@@ -56,6 +56,7 @@ 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";
59
60
  import { runExpressCommand } from "./express-command.js";
60
61
  import { gatewayFindings } from "./gateway-findings.js";
61
62
  import { runLifecycleCommand, runPolicyCommand } from "./governance-command.js";
@@ -1240,6 +1241,7 @@ export const commandRegistry = {
1240
1241
  brief: () => runBriefCommand(process.argv.slice(3)),
1241
1242
  interests: () => runInterestsCommand(process.argv.slice(3)),
1242
1243
  distill: () => runDistillCommand(process.argv.slice(3)),
1244
+ harvest: () => runHarvestCommand(process.argv.slice(3)),
1243
1245
  telemetry: () => runTelemetryCommand(process.argv.slice(3)),
1244
1246
  express: () => runExpressCommand(process.argv.slice(3)),
1245
1247
  daily: commandDaily,
@@ -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-316): 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, telemetry, express, handoff, idea, daily, skill, catalog",
17
17
  ],
18
18
  ["Integrations", "obsidian, hook, migrate, layout, env"],
19
19
  ];
@@ -164,6 +164,10 @@ 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
+ ],
167
171
  telemetry: [
168
172
  "Find recurring errors and failing providers in recent sessions; propose them as backlog lines.",
169
173
  "ocean telemetry [--days N] [--yes]",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocean/brain",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocean/context",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocean/core",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocean/loop",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocean/market",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -39,7 +39,7 @@ async function markdownIn(dir) {
39
39
  }
40
40
  return files.sort();
41
41
  }
42
- function section(text, heading) {
42
+ export function section(text, heading) {
43
43
  const match = new RegExp(
44
44
  // `(?![\\s\\S])` is the end of the text: with the m flag, `$` would end it at the first line.
45
45
  `^## ${heading}\\n+([\\s\\S]*?)(?=\\n## |\\nRaw events|(?![\\s\\S]))`, "m").exec(text);
@@ -0,0 +1,453 @@
1
+ import { copyFile, mkdir, readdir, readFile, rename, rm, } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { syncMemoryIndexes } from "@ocean/brain/memory/index-sync.js";
4
+ import { containsKnownSecret } from "@ocean/core/domain/redaction/redaction.js";
5
+ import { atomicWrite, parseFrontmatter } from "@ocean/core/shared/fs-utils.js";
6
+ import { DAILY_DIR, KNOWLEDGE_DIR, oceanPath, SYSTEM_DIR, } from "@ocean/core/shared/paths.js";
7
+ import { section } from "../distill/distill.js";
8
+ // The daily harvest (T-316): every session of a day, from every AI client, becomes one summary in
9
+ // that day's note, and what the sessions decided, fixed and learned is filed into 05-knowledge on
10
+ // its own, with no review step (owner's decision, 2026-11-16). Safety instead of review: a record
11
+ // that already says the same thing is strengthened, not duplicated; every write is in a ledger
12
+ // with the record's previous version, and `ocean harvest undo <date>` takes a day back. Nothing
13
+ // here calls a model: the judgement work (legacy records, imports, corrections that become rules)
14
+ // is the daily-harvest skill's.
15
+ const MARK_START = "<!-- ocean:harvest:start -->";
16
+ const MARK_END = "<!-- ocean:harvest:end -->";
17
+ const DAY_MS = 24 * 60 * 60 * 1000;
18
+ const MAX_SESSION_MS = 8 * 60 * 60 * 1000;
19
+ const MIN_ITEM = 25;
20
+ const SAME_TITLE = 0.6;
21
+ // Where each kind of harvested item is filed, and the record type it carries.
22
+ const KINDS = {
23
+ decision: { heading: "Decisions", folder: "decisions" },
24
+ solution: { heading: "Problems → fixes", folder: "solutions" },
25
+ discovery: { heading: "Learned", folder: "discoveries" },
26
+ };
27
+ const relativeOf = (file) => path.relative(oceanPath(), file).split(path.sep).join("/");
28
+ const sessionsRoot = () => oceanPath(DAILY_DIR, "sessions");
29
+ const stateDir = (...parts) => oceanPath(SYSTEM_DIR, "state", "harvest", ...parts);
30
+ async function markdownIn(dir, skipArchive = true) {
31
+ const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
32
+ const files = [];
33
+ for (const entry of entries) {
34
+ if (entry.name.startsWith("."))
35
+ continue;
36
+ if (skipArchive && entry.name === "archive")
37
+ continue;
38
+ const file = path.join(dir, entry.name);
39
+ if (entry.isDirectory())
40
+ files.push(...(await markdownIn(file, skipArchive)));
41
+ else if (entry.name.endsWith(".md"))
42
+ files.push(file);
43
+ }
44
+ return files.sort();
45
+ }
46
+ export async function daySessions(date) {
47
+ const sessions = [];
48
+ for (const file of await markdownIn(path.join(sessionsRoot(), date.slice(0, 7)))) {
49
+ const text = (await readFile(file, "utf8")).replace(/\r\n/g, "\n");
50
+ const fields = parseFrontmatter(text);
51
+ if (fields.type !== "session" || fields.date !== date)
52
+ continue;
53
+ sessions.push({
54
+ file,
55
+ relative: relativeOf(file),
56
+ title: /^# (.+)$/m.exec(text)?.[1]?.trim() ?? path.basename(file, ".md"),
57
+ date,
58
+ project: fields.project || "",
59
+ provider: fields.provider || "",
60
+ status: fields.status || "",
61
+ text,
62
+ });
63
+ }
64
+ return sessions;
65
+ }
66
+ const clean = (text) => text
67
+ .replace(/^[-*]\s+/, "")
68
+ .replace(/\s+/g, " ")
69
+ .trim();
70
+ // A section's items: its bullets, or the whole paragraph when it has none. Placeholders and
71
+ // fragments too short to stand alone are dropped.
72
+ export function sectionItems(text, heading) {
73
+ const body = section(text, heading);
74
+ if (!body)
75
+ return [];
76
+ const lines = body.split("\n").filter((line) => line.trim());
77
+ const bullets = lines.filter((line) => /^\s*[-*]\s+/.test(line));
78
+ const items = bullets.length ? bullets.map(clean) : [clean(body)];
79
+ return items.filter((item) => item.length >= MIN_ITEM &&
80
+ !/^(none|n\/a|nothing|no )/i.test(item) &&
81
+ !containsKnownSecret(item));
82
+ }
83
+ // A record written with sections (Goal, Outcome, Decisions, …) can be mined here; an older dump
84
+ // (one "What happened" paragraph) needs the skill's reading.
85
+ export const structured = (session) => /^## (Goal|Outcome|Decisions|Learned)$/m.test(session.text);
86
+ export function harvestItems(sessions) {
87
+ const items = [];
88
+ for (const session of sessions)
89
+ for (const kind of Object.keys(KINDS))
90
+ for (const text of sectionItems(session.text, KINDS[kind].heading))
91
+ items.push({ kind, text, session });
92
+ return items;
93
+ }
94
+ // What the owner said to correct an AI ("no, not like that", "غلط", "don't …"): candidates for a
95
+ // standing rule. Read from his own turns only, never the model's.
96
+ const CORRECTION = /(^|[\s,.!])(no,|nope|wrong|don't|do not|stop |not like that|i said|instead of)|(^|\s)(لا |غلط|مو هيچ|مو هيج|مو هيك|ما اريد|لا تسوي|ليش سويت|گلتلك|قلتلك)/i;
97
+ export function detectCorrections(events) {
98
+ const found = [];
99
+ for (const event of events) {
100
+ if (event.type !== "user_input")
101
+ continue;
102
+ const text = event.data.replace(/\s+/g, " ").trim();
103
+ if (!text || text.length > 600 || containsKnownSecret(text))
104
+ continue;
105
+ // Text a client injects as the user's turn (a skill body, a command, a notice) is not his.
106
+ if (/^(base directory for this skill|<|caveat:|\[request interrupted|this session is being continued)/i.test(text))
107
+ continue;
108
+ if (CORRECTION.test(text))
109
+ found.push(text.slice(0, 160));
110
+ }
111
+ return found;
112
+ }
113
+ const localDay = (iso) => {
114
+ const day = new Date(iso);
115
+ return `${day.getFullYear()}-${String(day.getMonth() + 1).padStart(2, "0")}-${String(day.getDate()).padStart(2, "0")}`;
116
+ };
117
+ // Minutes per project for sessions started that day: from the start to the latest of its close,
118
+ // its last update and its last event, each session capped at eight hours. A session the store saw
119
+ // only for seconds counts nothing, and a project with nothing recorded is left out.
120
+ export function minutesByProject(sessions, date, eventsOf = () => []) {
121
+ const minutes = {};
122
+ for (const session of sessions) {
123
+ if (localDay(session.createdAt) !== date)
124
+ continue;
125
+ const ends = [
126
+ session.closedAt,
127
+ session.updatedAt,
128
+ ...eventsOf(session.sessionId).map((event) => event.createdAt),
129
+ ]
130
+ .map((time) => Date.parse(time ?? ""))
131
+ .filter((time) => !Number.isNaN(time));
132
+ const span = Math.min(Math.max(0, Math.max(...ends, 0) - Date.parse(session.createdAt)), MAX_SESSION_MS);
133
+ const counted = Math.round(span / 60_000);
134
+ if (!counted)
135
+ continue;
136
+ const project = session.projectId || path.basename(session.workingDirectory) || "other";
137
+ minutes[project] = (minutes[project] ?? 0) + counted;
138
+ }
139
+ return minutes;
140
+ }
141
+ const slug = (text) => text
142
+ .toLowerCase()
143
+ .replace(/`[^`]*`/g, (code) => code.slice(1, -1))
144
+ .replace(/[^a-z0-9؀-ۿ]+/g, " ")
145
+ .trim()
146
+ .split(" ")
147
+ .filter(Boolean)
148
+ .slice(0, 8)
149
+ .join("-")
150
+ .slice(0, 80);
151
+ const words = (text) => new Set(text
152
+ .toLowerCase()
153
+ .split(/[^a-z0-9؀-ۿ]+/)
154
+ .filter((word) => word.length > 2));
155
+ function similarity(a, b) {
156
+ const left = words(a);
157
+ const right = words(b);
158
+ // Too few words to tell two statements apart: never the same record.
159
+ if (Math.min(left.size, right.size) < 3)
160
+ return 0;
161
+ let shared = 0;
162
+ for (const word of left)
163
+ if (right.has(word))
164
+ shared++;
165
+ return shared / Math.min(left.size, right.size);
166
+ }
167
+ const titleOf = (text) => {
168
+ const sentence = text.split(/(?<=[.!?])\s/)[0] ?? text;
169
+ return sentence.length > 90 ? `${sentence.slice(0, 87).trim()}…` : sentence;
170
+ };
171
+ function setField(text, key, value) {
172
+ const end = text.startsWith("---\n") ? text.indexOf("\n---", 3) : -1;
173
+ if (end < 0)
174
+ return text;
175
+ const head = text.slice(0, end);
176
+ const line = new RegExp(`^${key}:.*$`, "m");
177
+ const next = line.test(head)
178
+ ? head.replace(line, `${key}: ${value}`)
179
+ : `${head}\n${key}: ${value}`;
180
+ return next + text.slice(end);
181
+ }
182
+ // One harvested item into 05-knowledge: the record that already says it gains this day as
183
+ // evidence and a fresh last_verified; otherwise a new record. Returns the file and what happened.
184
+ async function fileItem(item, ledger) {
185
+ const folder = oceanPath(KNOWLEDGE_DIR, KINDS[item.kind].folder);
186
+ const title = titleOf(item.text);
187
+ let match = null;
188
+ for (const name of await readdir(folder).catch(() => [])) {
189
+ if (!name.endsWith(".md"))
190
+ continue;
191
+ const existing = await readFile(path.join(folder, name), "utf8");
192
+ const heading = /^# (.+)$/m.exec(existing)?.[1] ?? name;
193
+ if (name === `${slug(item.text)}.md` ||
194
+ similarity(heading, title) >= SAME_TITLE) {
195
+ match = path.join(folder, name);
196
+ break;
197
+ }
198
+ }
199
+ const link = `- ${item.session.date}: [${item.session.title.replace(/[[\]]/g, "")}](${path
200
+ .relative(folder, item.session.file)
201
+ .split(path.sep)
202
+ .join("/")})`;
203
+ if (match) {
204
+ const current = await readFile(match, "utf8");
205
+ if (current.includes(link))
206
+ return { file: relativeOf(match), action: "same" };
207
+ const copy = stateDir("versions", ledger.date, relativeOf(match));
208
+ await mkdir(path.dirname(copy), { recursive: true });
209
+ await copyFile(match, copy);
210
+ ledger.updated.push({ file: relativeOf(match), copy: relativeOf(copy) });
211
+ let next = setField(current, "last_verified", item.session.date);
212
+ next = /^## Evidence$/m.test(next)
213
+ ? next.replace(/^## Evidence\n+/m, (head) => `${head}${link}\n`)
214
+ : `${next.replace(/\n*$/, "")}\n\n## Evidence\n\n${link}\n`;
215
+ await atomicWrite(match, next);
216
+ return { file: relativeOf(match), action: "strengthened" };
217
+ }
218
+ const file = path.join(folder, `${slug(item.text) || "untitled"}.md`);
219
+ const body = [
220
+ "---",
221
+ `type: ${item.kind}`,
222
+ `title: ${JSON.stringify(title)}`,
223
+ "status: active",
224
+ "origin: harvested",
225
+ `source: ${JSON.stringify(`session:${item.session.provider || "unknown"}`)}`,
226
+ ...(item.session.project
227
+ ? [`project: ${JSON.stringify(item.session.project)}`]
228
+ : []),
229
+ `created: ${item.session.date}`,
230
+ `last_verified: ${item.session.date}`,
231
+ "---",
232
+ "",
233
+ `# ${title}`,
234
+ "",
235
+ item.text,
236
+ "",
237
+ "## Evidence",
238
+ "",
239
+ link,
240
+ "",
241
+ ].join("\n");
242
+ await mkdir(folder, { recursive: true });
243
+ await atomicWrite(file, body);
244
+ ledger.created.push(relativeOf(file));
245
+ return { file: relativeOf(file), action: "created" };
246
+ }
247
+ function dayBlock(input) {
248
+ const link = (session) => `[${session.title.replace(/[[\]]/g, "")}](${path
249
+ .relative(oceanPath(DAILY_DIR), session.file)
250
+ .split(path.sep)
251
+ .join("/")})`;
252
+ const byProvider = new Map();
253
+ for (const session of input.sessions)
254
+ byProvider.set(session.provider || "unknown", (byProvider.get(session.provider || "unknown") ?? 0) + 1);
255
+ const kind = (k, label) => {
256
+ const items = input.items.filter((item) => item.kind === k);
257
+ return items.length
258
+ ? [
259
+ "",
260
+ `### ${label}`,
261
+ "",
262
+ ...items.map((item) => {
263
+ const filed = input.filed.get(item);
264
+ return `- ${item.text}${filed ? ` → \`${filed}\`` : ""} (${link(item.session)})`;
265
+ }),
266
+ ]
267
+ : [];
268
+ };
269
+ const next = input.sessions.flatMap((session) => sectionItems(session.text, "Next").map((item) => `- ${item} (${link(session)})`));
270
+ const minutes = Object.entries(input.minutes).sort((a, b) => b[1] - a[1]);
271
+ return [
272
+ MARK_START,
273
+ "## Day summary",
274
+ "",
275
+ `${input.sessions.length} session(s): ${[...byProvider].map(([provider, n]) => `${provider} ${n}`).join(", ") || "none"}.`,
276
+ "",
277
+ "### Sessions",
278
+ "",
279
+ ...(input.sessions.length
280
+ ? input.sessions.map((session) => `- ${link(session)} — ${[session.project, session.provider, session.status].filter(Boolean).join(" · ")}`)
281
+ : ["- none"]),
282
+ ...kind("decision", "Decisions"),
283
+ ...kind("solution", "Problems → fixes"),
284
+ ...kind("discovery", "Learned"),
285
+ ...(next.length ? ["", "### Open next", "", ...next] : []),
286
+ ...(input.corrections.length
287
+ ? [
288
+ "",
289
+ "### Corrections you made",
290
+ "",
291
+ ...input.corrections.map((text) => `- ${text}`),
292
+ ]
293
+ : []),
294
+ ...(minutes.length
295
+ ? [
296
+ "",
297
+ "### Time",
298
+ "",
299
+ ...minutes.map(([project, n]) => `- ${project}: ${Math.floor(n / 60)}h ${String(n % 60).padStart(2, "0")}m`),
300
+ ]
301
+ : []),
302
+ ...(input.filed.size
303
+ ? [
304
+ "",
305
+ `Filed into knowledge on its own; undo with \`ocean harvest undo ${input.date}\`.`,
306
+ ]
307
+ : []),
308
+ MARK_END,
309
+ ].join("\n");
310
+ }
311
+ // The day's note keeps what the owner wrote: only the block between the markers is Ocean's.
312
+ export function withBlock(note, date, block) {
313
+ if (note === null)
314
+ return `---\ntype: daily\ndate: ${date}\n---\n\n# ${date}\n\n${block}\n`;
315
+ const start = note.indexOf(MARK_START);
316
+ const end = note.indexOf(MARK_END);
317
+ if (start >= 0 && end > start)
318
+ return note.slice(0, start) + block + note.slice(end + MARK_END.length);
319
+ return `${note.replace(/\n*$/, "")}\n\n${block}\n`;
320
+ }
321
+ const ledgerFile = (date) => stateDir("ledger", `${date}.json`);
322
+ export async function harvestDay(options) {
323
+ const { date } = options;
324
+ const sessions = await daySessions(date);
325
+ const items = harvestItems(sessions);
326
+ const ofDay = (options.store?.sessions ?? []).filter((session) => localDay(session.createdAt) === date);
327
+ const corrections = [
328
+ ...new Set(ofDay.flatMap((session) => detectCorrections(options.store?.eventsOf(session.sessionId) ?? []))),
329
+ ];
330
+ const minutes = minutesByProject(ofDay, date, (id) => options.store ? options.store.eventsOf(id) : []);
331
+ const result = {
332
+ date,
333
+ sessions: sessions.length,
334
+ note: null,
335
+ created: [],
336
+ strengthened: [],
337
+ corrections,
338
+ minutes,
339
+ };
340
+ if (!sessions.length && !ofDay.length)
341
+ return result;
342
+ result.note = `${DAILY_DIR}/${date}.md`;
343
+ if (!options.apply) {
344
+ result.created = items.map((item) => `${KINDS[item.kind].folder}: ${titleOf(item.text)}`);
345
+ return result;
346
+ }
347
+ const previous = JSON.parse(await readFile(ledgerFile(date), "utf8").catch(() => "null")) ?? { date, created: [], updated: [] };
348
+ const filed = new Map();
349
+ for (const item of items) {
350
+ const { file, action } = await fileItem(item, previous);
351
+ filed.set(item, file);
352
+ if (action === "created")
353
+ result.created.push(file);
354
+ if (action === "strengthened")
355
+ result.strengthened.push(file);
356
+ }
357
+ await mkdir(path.dirname(ledgerFile(date)), { recursive: true });
358
+ await atomicWrite(ledgerFile(date), `${JSON.stringify(previous, null, 2)}\n`);
359
+ const noteFile = oceanPath(result.note);
360
+ const note = await readFile(noteFile, "utf8").catch(() => null);
361
+ await atomicWrite(noteFile, withBlock(note, date, dayBlock({ sessions, items, filed, corrections, minutes, date })));
362
+ // A legacy record (no sections) is summarized here but read by the daily-harvest skill, which
363
+ // marks it once it has mined it.
364
+ for (const session of sessions.filter(structured))
365
+ await atomicWrite(session.file, setField(session.text, "harvested", date));
366
+ if (result.created.length || result.strengthened.length)
367
+ await syncMemoryIndexes(true);
368
+ return result;
369
+ }
370
+ // Days before today whose session records have not been harvested yet (the service runs this).
371
+ export async function pendingDays(today, lookbackDays = 45) {
372
+ const cutoff = new Date(Date.parse(today) - lookbackDays * DAY_MS)
373
+ .toISOString()
374
+ .slice(0, 10);
375
+ const days = new Set();
376
+ for (const file of await markdownIn(sessionsRoot())) {
377
+ const head = (await readFile(file, "utf8")).slice(0, 4096);
378
+ const fields = parseFrontmatter(head);
379
+ if (fields.type !== "session" || fields.harvested)
380
+ continue;
381
+ if (fields.date && fields.date < today && fields.date >= cutoff)
382
+ days.add(fields.date);
383
+ }
384
+ return [...days].sort();
385
+ }
386
+ // Undo one day's knowledge writes: records it created are removed, records it strengthened get
387
+ // their earlier version back. The day's summary and session flags stay.
388
+ export async function undoDay(date) {
389
+ const ledger = JSON.parse(await readFile(ledgerFile(date), "utf8").catch(() => "null"));
390
+ if (!ledger)
391
+ throw new Error(`no harvest ledger for ${date}`);
392
+ const removed = [];
393
+ const restored = [];
394
+ for (const file of ledger.created) {
395
+ await rm(oceanPath(file), { force: true });
396
+ removed.push(file);
397
+ }
398
+ // Oldest version first wins: a file strengthened twice returns to how it was before the day.
399
+ const seen = new Set();
400
+ for (const { file, copy } of ledger.updated) {
401
+ if (seen.has(file))
402
+ continue;
403
+ seen.add(file);
404
+ await copyFile(oceanPath(copy), oceanPath(file));
405
+ restored.push(file);
406
+ }
407
+ await rename(ledgerFile(date), stateDir("ledger", `${date}.undone.json`));
408
+ return { removed, restored };
409
+ }
410
+ // After `days`, a harvested day leaves the working folders: the day's note to
411
+ // 01-daily/archive/<YYYY-MM>/, its session records to 01-daily/sessions/archive/<YYYY-MM>/ (still
412
+ // searched). Nothing is deleted, and nothing unharvested moves.
413
+ export async function archiveHarvested(options) {
414
+ const cutoff = new Date(Date.parse(options.today) - (options.days ?? 30) * DAY_MS)
415
+ .toISOString()
416
+ .slice(0, 10);
417
+ const moves = [];
418
+ for (const file of await markdownIn(sessionsRoot())) {
419
+ const fields = parseFrontmatter((await readFile(file, "utf8")).slice(0, 4096));
420
+ if (fields.type !== "session" || !fields.date || fields.date >= cutoff)
421
+ continue;
422
+ if (!fields.harvested)
423
+ continue;
424
+ moves.push({
425
+ from: file,
426
+ to: path.join(sessionsRoot(), "archive", fields.date.slice(0, 7), path.basename(file)),
427
+ kind: "sessions",
428
+ });
429
+ }
430
+ for (const name of await readdir(oceanPath(DAILY_DIR)).catch(() => [])) {
431
+ const day = /^(\d{4}-\d{2}-\d{2})\.md$/.exec(name)?.[1];
432
+ if (!day || day >= cutoff)
433
+ continue;
434
+ // A day leaves once none of its sessions waits to be harvested.
435
+ if ((await daySessions(day)).some((session) => !/^harvested:/m.test(session.text)))
436
+ continue;
437
+ moves.push({
438
+ from: oceanPath(DAILY_DIR, name),
439
+ to: oceanPath(DAILY_DIR, "archive", day.slice(0, 7), name),
440
+ kind: "notes",
441
+ });
442
+ }
443
+ const result = { notes: [], sessions: [] };
444
+ for (const move of moves) {
445
+ result[move.kind].push(relativeOf(move.to));
446
+ if (!options.apply)
447
+ continue;
448
+ await mkdir(path.dirname(move.to), { recursive: true });
449
+ await rename(move.from, move.to);
450
+ }
451
+ return result;
452
+ }
453
+ //# sourceMappingURL=harvest.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocean/services",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -5,9 +5,9 @@
5
5
  {
6
6
  "kind": "skill",
7
7
  "name": "dev.ocean.skills.business-logic",
8
- "version": "1.7.0",
8
+ "version": "1.8.0",
9
9
  "engines": {
10
- "ocean": ">=1.7.0"
10
+ "ocean": ">=1.8.0"
11
11
  },
12
12
  "source": {
13
13
  "type": "path",
@@ -23,9 +23,9 @@
23
23
  {
24
24
  "kind": "skill",
25
25
  "name": "dev.ocean.skills.catch-up",
26
- "version": "1.7.0",
26
+ "version": "1.8.0",
27
27
  "engines": {
28
- "ocean": ">=1.7.0"
28
+ "ocean": ">=1.8.0"
29
29
  },
30
30
  "source": {
31
31
  "type": "path",
@@ -41,9 +41,9 @@
41
41
  {
42
42
  "kind": "skill",
43
43
  "name": "dev.ocean.skills.core-thinking",
44
- "version": "1.7.0",
44
+ "version": "1.8.0",
45
45
  "engines": {
46
- "ocean": ">=1.7.0"
46
+ "ocean": ">=1.8.0"
47
47
  },
48
48
  "source": {
49
49
  "type": "path",
@@ -56,12 +56,30 @@
56
56
  "directory": "core-thinking"
57
57
  }
58
58
  },
59
+ {
60
+ "kind": "skill",
61
+ "name": "dev.ocean.skills.daily-harvest",
62
+ "version": "1.8.0",
63
+ "engines": {
64
+ "ocean": ">=1.8.0"
65
+ },
66
+ "source": {
67
+ "type": "path",
68
+ "path": "skills/core/daily-harvest"
69
+ },
70
+ "integrity": {
71
+ "sha256": "356cc76057780394e2ed485e6853fc675d1d03bfc3541268ccc3e9d3b2bfd76d"
72
+ },
73
+ "spec": {
74
+ "directory": "daily-harvest"
75
+ }
76
+ },
59
77
  {
60
78
  "kind": "skill",
61
79
  "name": "dev.ocean.skills.design-thinking",
62
- "version": "1.7.0",
80
+ "version": "1.8.0",
63
81
  "engines": {
64
- "ocean": ">=1.7.0"
82
+ "ocean": ">=1.8.0"
65
83
  },
66
84
  "source": {
67
85
  "type": "path",
@@ -77,9 +95,9 @@
77
95
  {
78
96
  "kind": "skill",
79
97
  "name": "dev.ocean.skills.graft",
80
- "version": "1.7.0",
98
+ "version": "1.8.0",
81
99
  "engines": {
82
- "ocean": ">=1.7.0"
100
+ "ocean": ">=1.8.0"
83
101
  },
84
102
  "source": {
85
103
  "type": "path",
@@ -95,9 +113,9 @@
95
113
  {
96
114
  "kind": "skill",
97
115
  "name": "dev.ocean.skills.loop",
98
- "version": "1.7.0",
116
+ "version": "1.8.0",
99
117
  "engines": {
100
- "ocean": ">=1.7.0"
118
+ "ocean": ">=1.8.0"
101
119
  },
102
120
  "source": {
103
121
  "type": "path",
@@ -110,12 +128,30 @@
110
128
  "directory": "loop"
111
129
  }
112
130
  },
131
+ {
132
+ "kind": "skill",
133
+ "name": "dev.ocean.skills.memory-review",
134
+ "version": "1.8.0",
135
+ "engines": {
136
+ "ocean": ">=1.8.0"
137
+ },
138
+ "source": {
139
+ "type": "path",
140
+ "path": "skills/core/memory-review"
141
+ },
142
+ "integrity": {
143
+ "sha256": "9d43b15aa4fe676a4e260943f072452fba749c83b99df94f2fc18a82a3efb8cd"
144
+ },
145
+ "spec": {
146
+ "directory": "memory-review"
147
+ }
148
+ },
113
149
  {
114
150
  "kind": "skill",
115
151
  "name": "dev.ocean.skills.session-handoff",
116
- "version": "1.7.0",
152
+ "version": "1.8.0",
117
153
  "engines": {
118
- "ocean": ">=1.7.0"
154
+ "ocean": ">=1.8.0"
119
155
  },
120
156
  "source": {
121
157
  "type": "path",
@@ -131,9 +167,9 @@
131
167
  {
132
168
  "kind": "skill",
133
169
  "name": "dev.ocean.skills.use-browser",
134
- "version": "1.7.0",
170
+ "version": "1.8.0",
135
171
  "engines": {
136
- "ocean": ">=1.7.0"
172
+ "ocean": ">=1.8.0"
137
173
  },
138
174
  "source": {
139
175
  "type": "path",
@@ -149,9 +185,9 @@
149
185
  {
150
186
  "kind": "skill",
151
187
  "name": "dev.ocean.skills.verification",
152
- "version": "1.7.0",
188
+ "version": "1.8.0",
153
189
  "engines": {
154
- "ocean": ">=1.7.0"
190
+ "ocean": ">=1.8.0"
155
191
  },
156
192
  "source": {
157
193
  "type": "path",
@@ -167,9 +203,9 @@
167
203
  {
168
204
  "kind": "skill",
169
205
  "name": "dev.ocean.skills.weekly-review",
170
- "version": "1.7.0",
206
+ "version": "1.8.0",
171
207
  "engines": {
172
- "ocean": ">=1.7.0"
208
+ "ocean": ">=1.8.0"
173
209
  },
174
210
  "source": {
175
211
  "type": "path",
@@ -201,9 +237,9 @@
201
237
  "npx"
202
238
  ]
203
239
  },
204
- "version": "1.7.0",
240
+ "version": "1.8.0",
205
241
  "engines": {
206
- "ocean": ">=1.7.0"
242
+ "ocean": ">=1.8.0"
207
243
  },
208
244
  "source": {
209
245
  "type": "path",
@@ -236,9 +272,9 @@
236
272
  "kind": "mcp",
237
273
  "name": "dev.ocean/mcp-gateway",
238
274
  "description": "One MCP endpoint for every registered server: Ocean's own and those installed from the marketplace.",
239
- "version": "1.7.0",
275
+ "version": "1.8.0",
240
276
  "engines": {
241
- "ocean": ">=1.7.0"
277
+ "ocean": ">=1.8.0"
242
278
  },
243
279
  "source": {
244
280
  "type": "path",
@@ -280,9 +316,9 @@
280
316
  "kind": "mcp",
281
317
  "name": "dev.ocean/obsidian",
282
318
  "description": "Ocean's Obsidian vault bridge over MCP.",
283
- "version": "1.7.0",
319
+ "version": "1.8.0",
284
320
  "engines": {
285
- "ocean": ">=1.7.0"
321
+ "ocean": ">=1.8.0"
286
322
  },
287
323
  "source": {
288
324
  "type": "path",
@@ -324,9 +360,9 @@
324
360
  "kind": "mcp",
325
361
  "name": "dev.ocean/ocean",
326
362
  "description": "Ocean's own MCP server: workspace status, tasks, handoffs, sessions and the brain.",
327
- "version": "1.7.0",
363
+ "version": "1.8.0",
328
364
  "engines": {
329
- "ocean": ">=1.7.0"
365
+ "ocean": ">=1.8.0"
330
366
  },
331
367
  "source": {
332
368
  "type": "path",
@@ -378,9 +414,9 @@
378
414
  "npx"
379
415
  ]
380
416
  },
381
- "version": "1.7.0",
417
+ "version": "1.8.0",
382
418
  "engines": {
383
- "ocean": ">=1.7.0"
419
+ "ocean": ">=1.8.0"
384
420
  },
385
421
  "source": {
386
422
  "type": "path",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@amoree-code/ocean",
3
3
  "description": "Local-first memory, tasks and session capture shared by every AI coding client: one private workspace for Claude, Codex, Gemini and more.",
4
- "version": "1.7.0",
4
+ "version": "1.8.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "author": "AMEER ABDULKAREEM JABBAR LAMI",
@@ -45,12 +45,12 @@
45
45
  "@langchain/core": "1.2.14",
46
46
  "@langchain/langgraph": "1.4.19",
47
47
  "@modelcontextprotocol/sdk": "1.32.0",
48
- "@ocean/brain": "1.7.0",
49
- "@ocean/context": "1.7.0",
50
- "@ocean/core": "1.7.0",
51
- "@ocean/loop": "1.7.0",
52
- "@ocean/market": "1.7.0",
53
- "@ocean/services": "1.7.0",
48
+ "@ocean/brain": "1.8.0",
49
+ "@ocean/context": "1.8.0",
50
+ "@ocean/core": "1.8.0",
51
+ "@ocean/loop": "1.8.0",
52
+ "@ocean/market": "1.8.0",
53
+ "@ocean/services": "1.8.0",
54
54
  "playwright-core": "^1.48.0",
55
55
  "sqlite-vec": "0.1.9",
56
56
  "zod": "^4.6.5"
@@ -0,0 +1,72 @@
1
+ ---
2
+ name: daily-harvest
3
+ description: Turn everything the inbox and the daily folder hold - sessions from every AI client, imported memories, candidates, corrections - into filed knowledge and a better system, with no manual review, then archive. Use when the owner says harvest, process the inbox, file everything, improve the knowledge, or clean up 00-inbox and 01-daily.
4
+ version: 1.0.0
5
+ category: core
6
+ ---
7
+
8
+ # Daily harvest
9
+
10
+ The owner decided (2026-11-16) that Ocean files what it learns on its own. You do not ask him to
11
+ review each item. You decide where each fact belongs, write it there, and report what you did
12
+ with a way to undo it. Only a contradiction stops and waits for him.
13
+
14
+ ## Where everything lives
15
+
16
+ - A session from any client (Claude Code, Claude Desktop, Codex, Gemini, …) is one record in
17
+ `01-daily/sessions/YYYY-MM/`, its client in `provider`.
18
+ - A fact is filed by **topic, not by which AI said it**: `routing.json` maps its type to a folder
19
+ (identity, preference, goal, education, career, project memory, decision, solution, discovery,
20
+ …). Its frontmatter keeps where it came from: `origin: imported|harvested`, `source:
21
+ <client>`, the date.
22
+ - Raw memory pulled from a client waits in `00-inbox/native/<client>/` until harvested, then
23
+ moves to `00-inbox/archive/native/<client>/<YYYY-MM>/`.
24
+
25
+ ## 1. The mechanical pass
26
+
27
+ Run `ocean harvest --pending --yes` (the service also runs it daily). For each day it writes the
28
+ summary block in `01-daily/<date>.md` (sessions per client, decisions, fixes, lessons, open next,
29
+ the owner's corrections, time per project), files structured Decisions / Problems → fixes /
30
+ Learned into `05-knowledge/` (a record that already says it is strengthened instead), and marks
31
+ the sessions harvested. Read its JSON: that is your work list.
32
+
33
+ ## 2. The judgement pass
34
+
35
+ Work through these in order. For every fact: search first (`ocean memory search`), then either
36
+ strengthen the record that holds it (merge into one current statement, fresh `updated` /
37
+ `last_verified`) or create the record where `routing.json` puts its type. Never duplicate.
38
+
39
+ 1. **Candidates** (`ocean memory review list`): a duplicate of a record → reject; new and
40
+ consistent → approve with `--type` (or `--to`), then merge cleanly (the memory-review skill's
41
+ step 3); unsure what it means → leave it and list it in the report.
42
+ 2. **Native memory** in `00-inbox/native/<client>/` and the files in `02-personal/imported/`:
43
+ split each into facts, file each by topic with `origin: imported` and its client, then move the
44
+ raw file to the archive. A project fact goes to that project's `memory/`.
45
+ 3. **Legacy session records** (no Decisions / Learned sections): read a month at a time; pull out
46
+ decisions, fixes and lessons; file them as above; add `harvested: <date>` to each record read.
47
+ 4. **Corrections** in the day summaries: one the owner gave twice, or with "always" / "never",
48
+ becomes a feedback record in `02-personal/work/` (rule, **Why:**, **How to apply:**). A rule
49
+ for every client goes to the backlog as a charter change, not into the charter itself.
50
+ 5. **The system itself**: an error recurring across sessions (`ocean telemetry --yes`); the same
51
+ manual steps in three or more sessions → a backlog line `skill: <what it would do>`; a failure
52
+ in `05-knowledge/failures/` with no linked solution → look for the fix in the sessions.
53
+ 6. **Knowledge hygiene**: merge records that say the same thing; list decisions whose
54
+ `last_verified` is over 90 days old; fix broken links; run `ocean memory sync --apply`.
55
+ 7. **The owner's journey**: a study session (IELTS, Letspeak) adds to his study log; finished,
56
+ notable work becomes a milestone (`status: done`); a project's state goes to its `memory/`.
57
+
58
+ **Stop and do not write** when a fact contradicts a record or one of his notes in `07-notes/`:
59
+ propose it with `contradicts` so it waits in `02-personal/CONFLICTS.md`. Never write a secret;
60
+ about other people, only what the work needs; never invent a detail.
61
+
62
+ ## 3. Archive
63
+
64
+ Run `ocean harvest archive --yes`: harvested days older than 30 days leave `01-daily/` for
65
+ `01-daily/archive/<YYYY-MM>/` (notes) and `01-daily/sessions/archive/<YYYY-MM>/` (records, still
66
+ searched). Nothing is deleted.
67
+
68
+ ## 4. Report
69
+
70
+ In the owner's language, short: days harvested, records created and strengthened (by folder),
71
+ facts filed from other AIs, corrections turned into rules, backlog lines added, what waits in
72
+ CONFLICTS.md, what moved to the archive, and `ocean harvest undo <date>` for any day he wants back.
@@ -0,0 +1,53 @@
1
+ ---
2
+ name: memory-review
3
+ description: Review pending memory candidates with the owner one at a time - compare each with the record it would change, recommend, and merge approved facts cleanly into that record. Use when he says review candidates, review my memory, go through the proposals, or clear the inbox candidates.
4
+ version: 1.0.0
5
+ category: core
6
+ ---
7
+
8
+ # Memory review
9
+
10
+ Candidates are facts Ocean proposed (inferred, imported or harvested). None is memory until the
11
+ owner approves it. You prepare each decision; he makes it.
12
+
13
+ ## 1. Survey
14
+
15
+ Run `ocean memory review list`. Before asking anything, group what you see:
16
+
17
+ - **Duplicates**: the same source harvested twice (same `harvested from` path, same text). Decide
18
+ them once, together.
19
+ - **Already recorded**: read the target record (or search with `ocean memory search <q>`). A
20
+ candidate that adds nothing new is a reject to recommend, not a question to ask blind.
21
+ - **Age**: oldest first. Tell him the total and how many are older than seven days.
22
+
23
+ ## 2. One candidate at a time
24
+
25
+ For each, read the candidate file and the record it would change. Show, in plain words in his
26
+ language:
27
+
28
+ 1. **Now**: what the record says today (or that there is none).
29
+ 2. **Proposed**: what the candidate adds or changes, with its source and date.
30
+ 3. **Recommendation**: approve, merge, reject, or ask, with one line of why. Flag what may be
31
+ stale ("as of October; still true?").
32
+
33
+ Then ask one question and wait. Never approve without his answer; never batch items he has not
34
+ seen.
35
+
36
+ ## 3. Apply his answer
37
+
38
+ - **Approve, no target**: `ocean memory review approve <id> --type <type>` (`routing.json` picks
39
+ the folder) or `--to <path>`. A project fact goes to that project's `memory/`.
40
+ - **Approve, existing record**: `ocean memory review approve <id>` appends the candidate's text
41
+ to the record. Then merge by hand: fold the new facts into the right lines, delete what they
42
+ replace, remove the appended raw paragraph, keep the frontmatter flat and set `updated` and
43
+ `last_verified` to today. The record must read as one current statement, not a log.
44
+ - **Edit**: write his corrected version into the record, then reject the candidate.
45
+ - **Reject**: `ocean memory review reject <id>`.
46
+ - **His extra answers** (a date, "I cancelled that") go into the record too, dated.
47
+
48
+ Show him the few lines that changed after each one; nothing else.
49
+
50
+ ## 4. Close
51
+
52
+ Run `ocean memory doctor` and report the count still waiting. Never write secrets, never record
53
+ facts about third parties beyond what work needs, and never invent a detail he did not give.
package/skills/index.json CHANGED
@@ -17,6 +17,12 @@
17
17
  "version": "1.0.0",
18
18
  "category": "core"
19
19
  },
20
+ {
21
+ "name": "daily-harvest",
22
+ "description": "Turn everything the inbox and the daily folder hold - sessions from every AI client, imported memories, candidates, corrections - into filed knowledge and a better system, with no manual review, then archive. Use when the owner says harvest, process the inbox, file everything, improve the knowledge, or clean up 00-inbox and 01-daily.",
23
+ "version": "1.0.0",
24
+ "category": "core"
25
+ },
20
26
  {
21
27
  "name": "design-thinking",
22
28
  "description": "Frame a problem, clarify the desired outcome, compare simple solutions, and define success before implementation.",
@@ -35,6 +41,12 @@
35
41
  "version": "1.0.0",
36
42
  "category": "core"
37
43
  },
44
+ {
45
+ "name": "memory-review",
46
+ "description": "Review pending memory candidates with the owner one at a time - compare each with the record it would change, recommend, and merge approved facts cleanly into that record. Use when he says review candidates, review my memory, go through the proposals, or clear the inbox candidates.",
47
+ "version": "1.0.0",
48
+ "category": "core"
49
+ },
38
50
  {
39
51
  "name": "session-handoff",
40
52
  "description": "Produce a compact continuation packet with the next action and verification commands.",