@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
|
@@ -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,
|
|
@@ -13,6 +13,7 @@ const BRIEFS_DIR = `${DAILY_DIR}/briefs`;
|
|
|
13
13
|
const DAILY_LIMIT = 5;
|
|
14
14
|
const WEEKLY_LIMIT = 15;
|
|
15
15
|
const FETCH_TIMEOUT_MS = 10_000;
|
|
16
|
+
const PRERELEASE = /[-.](dev|rc|alpha|beta|canary|nightly|next|insiders|pre)(\b|\d|\.)/i;
|
|
16
17
|
function listField(block, key) {
|
|
17
18
|
const lines = block.split("\n");
|
|
18
19
|
const index = lines.findIndex((line) => line.startsWith(`${key}:`));
|
|
@@ -175,8 +176,11 @@ export async function buildBrief(options) {
|
|
|
175
176
|
continue;
|
|
176
177
|
if (found.some((other) => other.link === item.link))
|
|
177
178
|
continue;
|
|
178
|
-
// A releases feed is wanted whole
|
|
179
|
+
// A releases feed is wanted whole, less its pre-releases (dev, rc, beta, canary…: daily
|
|
180
|
+
// noise); a general feed is narrowed by the keywords.
|
|
179
181
|
const general = !source.startsWith("github:");
|
|
182
|
+
if (!general && PRERELEASE.test(item.title))
|
|
183
|
+
continue;
|
|
180
184
|
if (general &&
|
|
181
185
|
keywords.length &&
|
|
182
186
|
!keywords.some((word) => item.title.toLowerCase().includes(word)))
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { mkdir, readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { memoryDigest } from "@ocean/brain/memory/memory-digest.js";
|
|
4
|
+
import { atomicWrite, withFileLock } from "@ocean/core/shared/fs-utils.js";
|
|
5
|
+
import { DAILY_DIR, oceanPath, PERSONAL_DIR, } from "@ocean/core/shared/paths.js";
|
|
6
|
+
import { listTasks } from "@ocean/loop/tasks/list-tasks.js";
|
|
7
|
+
import { buildBrief } from "../brief/brief.js";
|
|
8
|
+
import { keepTicks, loopKey, noteFile, noteRelative, putBlock, readBlock, } from "./note.js";
|
|
9
|
+
// The morning half of the daily note (T-314), with no model: what to focus on (open tasks), what
|
|
10
|
+
// is coming (dated lines in the owner's records within 30 days), what was left open (unticked
|
|
11
|
+
// open loops from recent days), when he studies (his schedule), what waits on him, and the brief.
|
|
12
|
+
// Written between markers under the title; rerunning replaces only that block.
|
|
13
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
14
|
+
const AHEAD_DAYS = 30;
|
|
15
|
+
const LOOP_DAYS = 14;
|
|
16
|
+
const EVENT = /\b(exam|deadline|due|interview|meeting|appointment|call|submit|test)\b|موعد|امتحان|مقابلة/i;
|
|
17
|
+
const OPEN_STATES = new Set([
|
|
18
|
+
"active",
|
|
19
|
+
"in_progress",
|
|
20
|
+
"blocked",
|
|
21
|
+
"todo",
|
|
22
|
+
"planned",
|
|
23
|
+
]);
|
|
24
|
+
const days = (from, to) => Math.round((Date.parse(to) - Date.parse(from)) / DAY_MS);
|
|
25
|
+
async function markdownIn(dir) {
|
|
26
|
+
const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
27
|
+
const files = [];
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
if (entry.name.startsWith(".") || entry.name === "archive")
|
|
30
|
+
continue;
|
|
31
|
+
const file = path.join(dir, entry.name);
|
|
32
|
+
if (entry.isDirectory())
|
|
33
|
+
files.push(...(await markdownIn(file)));
|
|
34
|
+
else if (entry.name.endsWith(".md") && entry.name !== "CONFLICTS.md")
|
|
35
|
+
files.push(file);
|
|
36
|
+
}
|
|
37
|
+
return files.sort();
|
|
38
|
+
}
|
|
39
|
+
const relative = (file) => path.relative(oceanPath(), file).split(path.sep).join("/");
|
|
40
|
+
// Lines in the owner's records that name a date between today and 30 days ahead: exams,
|
|
41
|
+
// deadlines, appointments. Frontmatter dates (created, updated) are not events.
|
|
42
|
+
export async function upcoming(date) {
|
|
43
|
+
const found = [];
|
|
44
|
+
for (const file of await markdownIn(oceanPath(PERSONAL_DIR))) {
|
|
45
|
+
const text = (await readFile(file, "utf8")).replace(/\r\n/g, "\n");
|
|
46
|
+
const body = text.startsWith("---\n")
|
|
47
|
+
? text.slice(text.indexOf("\n---", 3) + 4)
|
|
48
|
+
: text;
|
|
49
|
+
for (const raw of body.split("\n")) {
|
|
50
|
+
const line = raw
|
|
51
|
+
.replace(/^[\s>|*-]+/, "")
|
|
52
|
+
.replace(/\|/g, " ")
|
|
53
|
+
.replace(/\s+/g, " ")
|
|
54
|
+
.trim();
|
|
55
|
+
for (const match of line.matchAll(/\b(\d{4}-\d{2}-\d{2})\b/g)) {
|
|
56
|
+
const at = match[1];
|
|
57
|
+
if (Number.isNaN(Date.parse(at)))
|
|
58
|
+
continue;
|
|
59
|
+
const ahead = days(date, at);
|
|
60
|
+
if (ahead < 0 || ahead > AHEAD_DAYS)
|
|
61
|
+
continue;
|
|
62
|
+
// Today's date in a record is usually when it was written; only an event line counts.
|
|
63
|
+
if (ahead === 0 && !EVENT.test(line))
|
|
64
|
+
continue;
|
|
65
|
+
const label = ahead === 0 ? "today" : ahead === 1 ? "tomorrow" : `in ${ahead} days`;
|
|
66
|
+
found.push({
|
|
67
|
+
at,
|
|
68
|
+
line: `${at} (${label}) — ${line.slice(0, 140)} ([${path.basename(file, ".md")}](../${relative(file)}))`,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const seen = new Set();
|
|
74
|
+
return found
|
|
75
|
+
.sort((a, b) => a.at.localeCompare(b.at))
|
|
76
|
+
.map((item) => item.line)
|
|
77
|
+
.filter((line) => !seen.has(line) && seen.add(line))
|
|
78
|
+
.slice(0, 8);
|
|
79
|
+
}
|
|
80
|
+
// Unticked open loops from the last two weeks of notes, oldest first; ticking one in any note
|
|
81
|
+
// (`- [x]`) closes it everywhere.
|
|
82
|
+
export async function openLoops(date) {
|
|
83
|
+
const notes = [];
|
|
84
|
+
for (const name of await readdir(oceanPath(DAILY_DIR)).catch(() => [])) {
|
|
85
|
+
const day = /^(\d{4}-\d{2}-\d{2})\.md$/.exec(name)?.[1];
|
|
86
|
+
if (!day || day >= date || days(day, date) > LOOP_DAYS)
|
|
87
|
+
continue;
|
|
88
|
+
notes.push({
|
|
89
|
+
day,
|
|
90
|
+
text: await readFile(oceanPath(DAILY_DIR, name), "utf8"),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
notes.sort((a, b) => a.day.localeCompare(b.day));
|
|
94
|
+
const closed = new Set();
|
|
95
|
+
const open = new Map();
|
|
96
|
+
for (const { day, text } of notes)
|
|
97
|
+
for (const line of text.split("\n")) {
|
|
98
|
+
if (/^- \[[xX]\] /.test(line))
|
|
99
|
+
closed.add(loopKey(line));
|
|
100
|
+
else if (/^- \[ \] /.test(line)) {
|
|
101
|
+
const key = loopKey(line);
|
|
102
|
+
if (!open.has(key))
|
|
103
|
+
open.set(key, /_\(from \d{4}-\d{2}-\d{2}\)_$/.test(line)
|
|
104
|
+
? line
|
|
105
|
+
: `${line} _(from ${day})_`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return [...open]
|
|
109
|
+
.filter(([key]) => !closed.has(key))
|
|
110
|
+
.map(([, line]) => line)
|
|
111
|
+
.slice(0, 10);
|
|
112
|
+
}
|
|
113
|
+
async function schedule() {
|
|
114
|
+
const lines = [];
|
|
115
|
+
for (const file of await markdownIn(oceanPath(PERSONAL_DIR, "schedule")))
|
|
116
|
+
for (const line of (await readFile(file, "utf8")).split("\n"))
|
|
117
|
+
if (/^- /.test(line))
|
|
118
|
+
lines.push(line);
|
|
119
|
+
return lines.slice(0, 5);
|
|
120
|
+
}
|
|
121
|
+
const section = (title, lines, empty) => lines.length || empty
|
|
122
|
+
? ["", `### ${title}`, "", ...(lines.length ? lines : [`- ${empty}`])]
|
|
123
|
+
: [];
|
|
124
|
+
export async function prepareDay(options) {
|
|
125
|
+
const { date } = options;
|
|
126
|
+
const tasks = (await listTasks())
|
|
127
|
+
.filter((task) => OPEN_STATES.has(task.state))
|
|
128
|
+
.map((task) => {
|
|
129
|
+
const title = task.title.replace(/\s+/g, " ").split(/[:—]/)[0].trim();
|
|
130
|
+
return `- ${task.id} — ${title.slice(0, 90)}${task.state === "blocked" ? " (blocked)" : ""}`;
|
|
131
|
+
});
|
|
132
|
+
const deadlines = (await upcoming(date)).map((line) => `- ${line}`);
|
|
133
|
+
const loops = await openLoops(date);
|
|
134
|
+
const hours = await schedule();
|
|
135
|
+
const waiting = (await memoryDigest({ stale: null })).map((line) => `- ${line}`);
|
|
136
|
+
const brief = await buildBrief({
|
|
137
|
+
date,
|
|
138
|
+
dryRun: !options.apply,
|
|
139
|
+
fetchText: options.fetchText,
|
|
140
|
+
}).catch(() => null);
|
|
141
|
+
// Items already in today's brief (an earlier run marked them seen) still lead the morning.
|
|
142
|
+
const briefFile = oceanPath(DAILY_DIR, "briefs", `${date}.md`);
|
|
143
|
+
const earlier = (await readFile(briefFile, "utf8").catch(() => ""))
|
|
144
|
+
.split("\n")
|
|
145
|
+
.filter((line) => line.startsWith("- **"));
|
|
146
|
+
const fresh = (brief?.items ?? []).map((item) => `- **${item.interest}** — [${item.title.replace(/[[\]]/g, "")}](${item.link})`);
|
|
147
|
+
const top = [
|
|
148
|
+
...fresh,
|
|
149
|
+
...earlier.map((line) => line.replace(/ \(\d{4}-\d{2}-\d{2}\)$/, "")),
|
|
150
|
+
]
|
|
151
|
+
.filter((line, index, all) => all.indexOf(line) === index)
|
|
152
|
+
.slice(0, 3);
|
|
153
|
+
const hasFile = Boolean(brief?.file) || earlier.length > 0;
|
|
154
|
+
const briefLines = [
|
|
155
|
+
...top,
|
|
156
|
+
...(hasFile ? [`- Full brief: [${date}](briefs/${date}.md)`] : []),
|
|
157
|
+
...(brief?.resurface ? [`- Look again: ${brief.resurface}`] : []),
|
|
158
|
+
...(options.news
|
|
159
|
+
? [`- ${options.news.replace(/\s+/g, " ").slice(0, 600)}`]
|
|
160
|
+
: []),
|
|
161
|
+
];
|
|
162
|
+
const body = [
|
|
163
|
+
"## Today",
|
|
164
|
+
...section("Focus", tasks, "no open task"),
|
|
165
|
+
...section("Coming up", deadlines),
|
|
166
|
+
...section("Open loops", loops),
|
|
167
|
+
...section("Your hours", hours),
|
|
168
|
+
...section("Waiting on you", waiting),
|
|
169
|
+
"",
|
|
170
|
+
"## Brief",
|
|
171
|
+
"",
|
|
172
|
+
...(briefLines.length
|
|
173
|
+
? briefLines
|
|
174
|
+
: ["- nothing new from the sources you follow"]),
|
|
175
|
+
].join("\n");
|
|
176
|
+
const plan = {
|
|
177
|
+
date,
|
|
178
|
+
note: noteRelative(date),
|
|
179
|
+
tasks,
|
|
180
|
+
deadlines,
|
|
181
|
+
loops,
|
|
182
|
+
schedule: hours,
|
|
183
|
+
waiting,
|
|
184
|
+
brief: briefLines,
|
|
185
|
+
};
|
|
186
|
+
if (!options.apply)
|
|
187
|
+
return plan;
|
|
188
|
+
const file = noteFile(date);
|
|
189
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
190
|
+
await withFileLock(file, async () => {
|
|
191
|
+
const note = await readFile(file, "utf8").catch(() => null);
|
|
192
|
+
const kept = keepTicks(note ? readBlock(note, "day") : "", body);
|
|
193
|
+
await atomicWrite(file, dropEmptyStubs(putBlock(note, date, "day", kept)));
|
|
194
|
+
});
|
|
195
|
+
return plan;
|
|
196
|
+
}
|
|
197
|
+
// The old template's headings (Focus, Work log, Decisions, Problems, Next, Observations) left
|
|
198
|
+
// empty are dropped: the blocks say all of that now. A heading with anything under it stays.
|
|
199
|
+
export function dropEmptyStubs(note) {
|
|
200
|
+
return note.replace(/^## (Focus|Work log|Decisions|Problems|Next|Observations)\n+(?=## |<!-- ocean:|$(?![\s\S]))/gm, "");
|
|
201
|
+
}
|
|
202
|
+
export { readBlock };
|
|
203
|
+
//# sourceMappingURL=day.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { DAILY_DIR, oceanPath } from "@ocean/core/shared/paths.js";
|
|
2
|
+
const start = (name) => `<!-- ocean:${name}:start -->`;
|
|
3
|
+
const end = (name) => `<!-- ocean:${name}:end -->`;
|
|
4
|
+
export const noteRelative = (date) => `${DAILY_DIR}/${date}.md`;
|
|
5
|
+
export const noteFile = (date) => oceanPath(noteRelative(date));
|
|
6
|
+
const WEEKDAYS = [
|
|
7
|
+
"Sunday",
|
|
8
|
+
"Monday",
|
|
9
|
+
"Tuesday",
|
|
10
|
+
"Wednesday",
|
|
11
|
+
"Thursday",
|
|
12
|
+
"Friday",
|
|
13
|
+
"Saturday",
|
|
14
|
+
];
|
|
15
|
+
export function weekday(date) {
|
|
16
|
+
return WEEKDAYS[new Date(`${date}T12:00:00Z`).getUTCDay()];
|
|
17
|
+
}
|
|
18
|
+
export function newNote(date) {
|
|
19
|
+
return `---\ntype: daily\ndate: ${date}\n---\n\n# ${date} — ${weekday(date)}\n\n## Notes\n`;
|
|
20
|
+
}
|
|
21
|
+
export function hasBlock(note, name) {
|
|
22
|
+
return note.includes(start(name)) && note.includes(end(name));
|
|
23
|
+
}
|
|
24
|
+
export function readBlock(note, name) {
|
|
25
|
+
const from = note.indexOf(start(name));
|
|
26
|
+
const to = note.indexOf(end(name));
|
|
27
|
+
return from >= 0 && to > from
|
|
28
|
+
? note.slice(from + start(name).length, to)
|
|
29
|
+
: "";
|
|
30
|
+
}
|
|
31
|
+
export function putBlock(note, date, name, body) {
|
|
32
|
+
const text = (note ?? newNote(date)).replace(/\r\n/g, "\n");
|
|
33
|
+
const block = `${start(name)}\n${body.trim()}\n${end(name)}`;
|
|
34
|
+
const from = text.indexOf(start(name));
|
|
35
|
+
const to = text.indexOf(end(name));
|
|
36
|
+
if (from >= 0 && to > from)
|
|
37
|
+
return text.slice(0, from) + block + text.slice(to + end(name).length);
|
|
38
|
+
if (name === "day") {
|
|
39
|
+
// Under the title; a note without one gets it after its frontmatter.
|
|
40
|
+
const title = /^# .*$/m.exec(text);
|
|
41
|
+
if (title) {
|
|
42
|
+
const at = title.index + title[0].length;
|
|
43
|
+
return `${text.slice(0, at)}\n\n${block}${text.slice(at)}`;
|
|
44
|
+
}
|
|
45
|
+
const fm = text.startsWith("---\n") ? text.indexOf("\n---", 3) : -1;
|
|
46
|
+
const at = fm < 0 ? 0 : fm + 4;
|
|
47
|
+
return `${text.slice(0, at)}\n${block}\n${text.slice(at)}`;
|
|
48
|
+
}
|
|
49
|
+
// The day's account goes before the owner's own notes, else at the end.
|
|
50
|
+
const notes = /^## Notes$/m.exec(text);
|
|
51
|
+
if (notes)
|
|
52
|
+
return `${text.slice(0, notes.index)}${block}\n\n${text.slice(notes.index)}`;
|
|
53
|
+
return `${text.replace(/\n*$/, "")}\n\n${block}\n`;
|
|
54
|
+
}
|
|
55
|
+
// An open loop's identity: its text without the checkbox, the session link or the origin date.
|
|
56
|
+
export const loopKey = (line) => line
|
|
57
|
+
.replace(/^- \[[ xX]\]\s*/, "")
|
|
58
|
+
.replace(/\s*_\(from \d{4}-\d{2}-\d{2}\)_$/, "")
|
|
59
|
+
.replace(/\s*\(\[[^\]]*\]\([^)]*\)\)\s*$/, "")
|
|
60
|
+
.toLowerCase()
|
|
61
|
+
.replace(/\s+/g, " ")
|
|
62
|
+
.trim();
|
|
63
|
+
// The owner ticks loops inside Ocean's blocks; a rewrite keeps every tick he made.
|
|
64
|
+
export function keepTicks(previous, body) {
|
|
65
|
+
const ticked = new Set(previous
|
|
66
|
+
.split("\n")
|
|
67
|
+
.filter((line) => /^- \[[xX]\] /.test(line))
|
|
68
|
+
.map(loopKey));
|
|
69
|
+
if (!ticked.size)
|
|
70
|
+
return body;
|
|
71
|
+
return body
|
|
72
|
+
.split("\n")
|
|
73
|
+
.map((line) => /^- \[ \] /.test(line) && ticked.has(loopKey(line))
|
|
74
|
+
? line.replace("- [ ] ", "- [x] ")
|
|
75
|
+
: line)
|
|
76
|
+
.join("\n");
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=note.js.map
|
|
@@ -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);
|