@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
|
@@ -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
|
|
@@ -2,18 +2,17 @@ import { copyFile, mkdir, readdir, readFile, rename, rm, } from "node:fs/promise
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { syncMemoryIndexes } from "@ocean/brain/memory/index-sync.js";
|
|
4
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";
|
|
5
|
+
import { atomicWrite, parseFrontmatter, withFileLock, } from "@ocean/core/shared/fs-utils.js";
|
|
6
|
+
import { DAILY_DIR, INBOX_DIR, KNOWLEDGE_DIR, oceanPath, SYSTEM_DIR, } from "@ocean/core/shared/paths.js";
|
|
7
|
+
import { keepTicks, noteFile, putBlock, readBlock } from "../day/note.js";
|
|
7
8
|
import { section } from "../distill/distill.js";
|
|
8
|
-
// The daily harvest (T-
|
|
9
|
+
// The daily harvest (T-314): every session of a day, from every AI client, becomes one summary in
|
|
9
10
|
// that day's note, and what the sessions decided, fixed and learned is filed into 05-knowledge on
|
|
10
11
|
// its own, with no review step (owner's decision, 2026-11-16). Safety instead of review: a record
|
|
11
12
|
// that already says the same thing is strengthened, not duplicated; every write is in a ledger
|
|
12
13
|
// with the record's previous version, and `ocean harvest undo <date>` takes a day back. Nothing
|
|
13
14
|
// here calls a model: the judgement work (legacy records, imports, corrections that become rules)
|
|
14
15
|
// is the daily-harvest skill's.
|
|
15
|
-
const MARK_START = "<!-- ocean:harvest:start -->";
|
|
16
|
-
const MARK_END = "<!-- ocean:harvest:end -->";
|
|
17
16
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
18
17
|
const MAX_SESSION_MS = 8 * 60 * 60 * 1000;
|
|
19
18
|
const MIN_ITEM = 25;
|
|
@@ -43,6 +42,18 @@ async function markdownIn(dir, skipArchive = true) {
|
|
|
43
42
|
}
|
|
44
43
|
return files.sort();
|
|
45
44
|
}
|
|
45
|
+
// A title made from a client's raw first turn carries its tags (`<command-message>…`,
|
|
46
|
+
// `<ide_opened_file>…`); what is left after them, or the project, is the title.
|
|
47
|
+
export function cleanTitle(raw, fallback) {
|
|
48
|
+
const text = raw
|
|
49
|
+
.replace(/<([\w-]+)>[\s\S]*?<\/\1>/g, (whole, tag) => /^(command-name|command-args)$/.test(tag)
|
|
50
|
+
? whole.replace(/<[^>]+>/g, " ")
|
|
51
|
+
: " ")
|
|
52
|
+
.replace(/<[^>]+>/g, " ")
|
|
53
|
+
.replace(/\s+/g, " ")
|
|
54
|
+
.trim();
|
|
55
|
+
return (text || fallback).slice(0, 120);
|
|
56
|
+
}
|
|
46
57
|
export async function daySessions(date) {
|
|
47
58
|
const sessions = [];
|
|
48
59
|
for (const file of await markdownIn(path.join(sessionsRoot(), date.slice(0, 7)))) {
|
|
@@ -53,10 +64,11 @@ export async function daySessions(date) {
|
|
|
53
64
|
sessions.push({
|
|
54
65
|
file,
|
|
55
66
|
relative: relativeOf(file),
|
|
56
|
-
title: /^# (.+)$/m.exec(text)?.[1]
|
|
67
|
+
title: cleanTitle(/^# (.+)$/m.exec(text)?.[1] ?? "", fields.project || path.basename(file, ".md")),
|
|
57
68
|
date,
|
|
58
|
-
project: fields.project || "",
|
|
59
|
-
|
|
69
|
+
project: fields.project || /^- Project: (.+)$/m.exec(text)?.[1]?.trim() || "",
|
|
70
|
+
// A legacy record keeps its client in the body ("- Provider: claude").
|
|
71
|
+
provider: fields.provider || /^- Provider: (.+)$/m.exec(text)?.[1]?.trim() || "",
|
|
60
72
|
status: fields.status || "",
|
|
61
73
|
text,
|
|
62
74
|
});
|
|
@@ -266,10 +278,10 @@ function dayBlock(input) {
|
|
|
266
278
|
]
|
|
267
279
|
: [];
|
|
268
280
|
};
|
|
269
|
-
|
|
281
|
+
// Every Next a session left is an open loop: carried forward each morning until ticked.
|
|
282
|
+
const loops = input.sessions.flatMap((session) => sectionItems(session.text, "Next").map((item) => `- [ ] ${item} (${link(session)})`));
|
|
270
283
|
const minutes = Object.entries(input.minutes).sort((a, b) => b[1] - a[1]);
|
|
271
284
|
return [
|
|
272
|
-
MARK_START,
|
|
273
285
|
"## Day summary",
|
|
274
286
|
"",
|
|
275
287
|
`${input.sessions.length} session(s): ${[...byProvider].map(([provider, n]) => `${provider} ${n}`).join(", ") || "none"}.`,
|
|
@@ -282,11 +294,20 @@ function dayBlock(input) {
|
|
|
282
294
|
...kind("decision", "Decisions"),
|
|
283
295
|
...kind("solution", "Problems → fixes"),
|
|
284
296
|
...kind("discovery", "Learned"),
|
|
285
|
-
...(
|
|
297
|
+
...(input.captures.length
|
|
298
|
+
? ["", "### Captured", "", ...input.captures]
|
|
299
|
+
: []),
|
|
300
|
+
...(input.filed.size
|
|
301
|
+
? [
|
|
302
|
+
"",
|
|
303
|
+
`_Filed into knowledge on its own; undo with \`ocean harvest undo ${input.date}\`._`,
|
|
304
|
+
]
|
|
305
|
+
: []),
|
|
306
|
+
...(loops.length ? ["", "## Open loops", "", ...loops] : []),
|
|
286
307
|
...(input.corrections.length
|
|
287
308
|
? [
|
|
288
309
|
"",
|
|
289
|
-
"
|
|
310
|
+
"## Corrections",
|
|
290
311
|
"",
|
|
291
312
|
...input.corrections.map((text) => `- ${text}`),
|
|
292
313
|
]
|
|
@@ -294,29 +315,29 @@ function dayBlock(input) {
|
|
|
294
315
|
...(minutes.length
|
|
295
316
|
? [
|
|
296
317
|
"",
|
|
297
|
-
"
|
|
318
|
+
"## Time",
|
|
298
319
|
"",
|
|
299
320
|
...minutes.map(([project, n]) => `- ${project}: ${Math.floor(n / 60)}h ${String(n % 60).padStart(2, "0")}m`),
|
|
300
321
|
]
|
|
301
322
|
: []),
|
|
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
323
|
].join("\n");
|
|
310
324
|
}
|
|
311
|
-
//
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
325
|
+
// Captures written that day (00-inbox/captures/), linked from the day's account.
|
|
326
|
+
async function dayCaptures(date) {
|
|
327
|
+
const dir = oceanPath(INBOX_DIR, "captures");
|
|
328
|
+
const lines = [];
|
|
329
|
+
for (const name of (await readdir(dir).catch(() => [])).sort()) {
|
|
330
|
+
if (!name.endsWith(".md"))
|
|
331
|
+
continue;
|
|
332
|
+
const text = await readFile(path.join(dir, name), "utf8").catch(() => "");
|
|
333
|
+
const fields = parseFrontmatter(text);
|
|
334
|
+
const created = fields.created || fields.date || name;
|
|
335
|
+
if (!created.startsWith(date) && localDay(created) !== date)
|
|
336
|
+
continue;
|
|
337
|
+
const title = /^# (.+)$/m.exec(text)?.[1]?.trim() || name.replace(/\.md$/, "");
|
|
338
|
+
lines.push(`- [${title.replace(/[[\]]/g, "")}](../${INBOX_DIR}/captures/${name})`);
|
|
339
|
+
}
|
|
340
|
+
return lines;
|
|
320
341
|
}
|
|
321
342
|
const ledgerFile = (date) => stateDir("ledger", `${date}.json`);
|
|
322
343
|
export async function harvestDay(options) {
|
|
@@ -337,7 +358,8 @@ export async function harvestDay(options) {
|
|
|
337
358
|
corrections,
|
|
338
359
|
minutes,
|
|
339
360
|
};
|
|
340
|
-
|
|
361
|
+
const captures = await dayCaptures(date);
|
|
362
|
+
if (!sessions.length && !ofDay.length && !captures.length)
|
|
341
363
|
return result;
|
|
342
364
|
result.note = `${DAILY_DIR}/${date}.md`;
|
|
343
365
|
if (!options.apply) {
|
|
@@ -356,9 +378,22 @@ export async function harvestDay(options) {
|
|
|
356
378
|
}
|
|
357
379
|
await mkdir(path.dirname(ledgerFile(date)), { recursive: true });
|
|
358
380
|
await atomicWrite(ledgerFile(date), `${JSON.stringify(previous, null, 2)}\n`);
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
381
|
+
const file = noteFile(date);
|
|
382
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
383
|
+
const body = dayBlock({
|
|
384
|
+
sessions,
|
|
385
|
+
items,
|
|
386
|
+
filed,
|
|
387
|
+
corrections,
|
|
388
|
+
minutes,
|
|
389
|
+
captures,
|
|
390
|
+
date,
|
|
391
|
+
});
|
|
392
|
+
await withFileLock(file, async () => {
|
|
393
|
+
const note = await readFile(file, "utf8").catch(() => null);
|
|
394
|
+
const kept = keepTicks(note ? readBlock(note, "harvest") : "", body);
|
|
395
|
+
await atomicWrite(file, putBlock(note, date, "harvest", kept));
|
|
396
|
+
});
|
|
362
397
|
// A legacy record (no sections) is summarized here but read by the daily-harvest skill, which
|
|
363
398
|
// marks it once it has mined it.
|
|
364
399
|
for (const session of sessions.filter(structured))
|
|
@@ -440,7 +475,11 @@ export async function archiveHarvested(options) {
|
|
|
440
475
|
kind: "notes",
|
|
441
476
|
});
|
|
442
477
|
}
|
|
443
|
-
const result = {
|
|
478
|
+
const result = {
|
|
479
|
+
notes: [],
|
|
480
|
+
sessions: [],
|
|
481
|
+
emptied: [],
|
|
482
|
+
};
|
|
444
483
|
for (const move of moves) {
|
|
445
484
|
result[move.kind].push(relativeOf(move.to));
|
|
446
485
|
if (!options.apply)
|
|
@@ -448,6 +487,20 @@ export async function archiveHarvested(options) {
|
|
|
448
487
|
await mkdir(path.dirname(move.to), { recursive: true });
|
|
449
488
|
await rename(move.from, move.to);
|
|
450
489
|
}
|
|
490
|
+
// The inbox keeps no empty folders: reviewed candidate days, the retired brain-dump folder.
|
|
491
|
+
const candidates = oceanPath(INBOX_DIR, "candidates");
|
|
492
|
+
const empty = [
|
|
493
|
+
...(await readdir(candidates).catch(() => [])).map((name) => path.join(candidates, name)),
|
|
494
|
+
oceanPath(INBOX_DIR, "brain-dump"),
|
|
495
|
+
];
|
|
496
|
+
for (const dir of empty) {
|
|
497
|
+
const inside = await readdir(dir).catch(() => null);
|
|
498
|
+
if (!inside || inside.some((name) => name !== ".DS_Store"))
|
|
499
|
+
continue;
|
|
500
|
+
result.emptied.push(relativeOf(dir));
|
|
501
|
+
if (options.apply)
|
|
502
|
+
await rm(dir, { recursive: true, force: true });
|
|
503
|
+
}
|
|
451
504
|
return result;
|
|
452
505
|
}
|
|
453
506
|
//# sourceMappingURL=harvest.js.map
|