@amoree-code/ocean 1.6.2 → 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 +10 -1
- package/dist/application/clients/desktop-watcher.js +234 -0
- package/dist/application/clients/opencode-plugin.js +4 -3
- package/dist/application/layout/layout-plan.js +1 -0
- package/dist/application/onboarding/steps.js +20 -1
- package/dist/infrastructure/desktop/claude-export.js +84 -0
- package/dist/infrastructure/desktop/desktop-chat.js +165 -0
- package/dist/infrastructure/desktop/indexeddb.js +158 -0
- package/dist/infrastructure/desktop/leveldb.js +247 -0
- package/dist/infrastructure/desktop/snappy.js +74 -0
- package/dist/infrastructure/process/service.js +8 -0
- package/dist/interfaces/cli/brief-command.js +17 -0
- package/dist/interfaces/cli/capture-command.js +1 -1
- package/dist/interfaces/cli/clients-command.js +15 -2
- package/dist/interfaces/cli/command-registry.js +31 -2
- package/dist/interfaces/cli/desktop-command.js +124 -0
- package/dist/interfaces/cli/distill-command.js +36 -0
- package/dist/interfaces/cli/express-command.js +18 -0
- package/dist/interfaces/cli/harvest-command.js +58 -0
- package/dist/interfaces/cli/help-command.js +34 -2
- package/dist/interfaces/cli/interests-command.js +33 -0
- package/dist/interfaces/cli/memory-command.js +37 -3
- package/dist/interfaces/cli/note-command.js +7 -0
- package/dist/interfaces/cli/setup-command.js +2 -1
- package/dist/interfaces/cli/telemetry-command.js +23 -0
- package/node_modules/@ocean/brain/dist/brain/brain-reindex.js +4 -1
- package/node_modules/@ocean/brain/dist/brain/brain-service.js +11 -1
- package/node_modules/@ocean/brain/dist/memory/brain-dump.js +73 -24
- package/node_modules/@ocean/brain/dist/memory/fact-routing.js +54 -0
- package/node_modules/@ocean/brain/dist/memory/frontmatter-flatten.js +89 -0
- package/node_modules/@ocean/brain/dist/memory/lessons.js +20 -0
- package/node_modules/@ocean/brain/dist/memory/memory-paths.js +3 -1
- package/node_modules/@ocean/brain/dist/memory/memory-review.js +19 -2
- package/node_modules/@ocean/brain/dist/memory/memory-write.js +45 -3
- package/node_modules/@ocean/brain/dist/memory/people.js +70 -0
- package/node_modules/@ocean/brain/dist/memory/routing.json +39 -0
- package/node_modules/@ocean/brain/dist/memory/session-facts.js +7 -1
- package/node_modules/@ocean/brain/dist/memory/session-promotion.js +1 -1
- package/node_modules/@ocean/brain/package.json +1 -1
- package/node_modules/@ocean/context/package.json +1 -1
- package/node_modules/@ocean/core/dist/shared/paths.js +7 -0
- package/node_modules/@ocean/core/package.json +1 -1
- package/node_modules/@ocean/loop/dist/handoff/handoff-service.js +5 -1
- package/node_modules/@ocean/loop/dist/hooks/desktop-facts.js +154 -0
- package/node_modules/@ocean/loop/dist/hooks/session-end-hook.js +1 -1
- 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 +218 -0
- package/node_modules/@ocean/services/dist/brief/interest-discovery.js +236 -0
- package/node_modules/@ocean/services/dist/brief/source-registry.json +35 -0
- package/node_modules/@ocean/services/dist/distill/distill.js +258 -0
- package/node_modules/@ocean/services/dist/doctor/workspace-doctor.js +129 -8
- package/node_modules/@ocean/services/dist/express/express.js +99 -0
- package/node_modules/@ocean/services/dist/harvest/harvest.js +453 -0
- package/node_modules/@ocean/services/dist/infrastructure/mcp/ocean-server.js +17 -1
- package/node_modules/@ocean/services/dist/journey/telemetry.js +81 -0
- package/node_modules/@ocean/services/dist/obsidian/folder-templates.js +82 -0
- package/node_modules/@ocean/services/dist/onboarding/onboarding.js +62 -0
- package/node_modules/@ocean/services/package.json +1 -1
- package/ocean-marketplace.json +82 -28
- package/package.json +7 -7
- package/skills/core/daily-harvest/SKILL.md +72 -0
- package/skills/core/memory-review/SKILL.md +53 -0
- package/skills/core/weekly-review/SKILL.md +24 -0
- package/skills/index.json +18 -0
- package/templates/workspace/02-personal/education/study/study.base +15 -0
- package/templates/workspace/02-personal/milestones/milestones.base +14 -0
- package/templates/workspace/02-personal/people/people.base +18 -0
- package/templates/workspace/06-templates/TEMPLATES.md +12 -0
- package/templates/workspace/06-templates/capture.md +9 -0
- package/templates/workspace/06-templates/daily.md +13 -0
- package/templates/workspace/06-templates/decision.md +8 -0
- package/templates/workspace/06-templates/failure.md +13 -0
- package/templates/workspace/06-templates/intelligence.md +7 -0
- package/templates/workspace/06-templates/interest.md +13 -0
- package/templates/workspace/06-templates/lesson.md +16 -0
- package/templates/workspace/06-templates/milestone.md +10 -0
- package/templates/workspace/06-templates/note.md +8 -0
- package/templates/workspace/06-templates/person.md +15 -0
- package/templates/workspace/06-templates/session.md +10 -0
- package/templates/workspace/06-templates/solution.md +14 -0
- package/templates/workspace/06-templates/study.md +14 -0
- package/templates/workspace/07-notes/.gitkeep +0 -0
- package/templates/workspace/MANIFEST.json +14 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"react": { "topic": "React", "source": "github:facebook/react" },
|
|
3
|
+
"next": { "topic": "Next.js", "source": "github:vercel/next.js" },
|
|
4
|
+
"vite": { "topic": "Vite", "source": "github:vitejs/vite" },
|
|
5
|
+
"vue": { "topic": "Vue", "source": "github:vuejs/core" },
|
|
6
|
+
"tailwindcss": {
|
|
7
|
+
"topic": "Tailwind CSS",
|
|
8
|
+
"source": "github:tailwindlabs/tailwindcss"
|
|
9
|
+
},
|
|
10
|
+
"typescript": {
|
|
11
|
+
"topic": "TypeScript",
|
|
12
|
+
"source": "github:microsoft/TypeScript"
|
|
13
|
+
},
|
|
14
|
+
"@nestjs/core": { "topic": "NestJS", "source": "github:nestjs/nest" },
|
|
15
|
+
"@prisma/client": { "topic": "Prisma", "source": "github:prisma/prisma" },
|
|
16
|
+
"prisma": { "topic": "Prisma", "source": "github:prisma/prisma" },
|
|
17
|
+
"express": { "topic": "Express", "source": "github:expressjs/express" },
|
|
18
|
+
"zod": { "topic": "Zod", "source": "github:colinhacks/zod" },
|
|
19
|
+
"@tanstack/react-query": {
|
|
20
|
+
"topic": "TanStack Query",
|
|
21
|
+
"source": "github:TanStack/query"
|
|
22
|
+
},
|
|
23
|
+
"@modelcontextprotocol/sdk": {
|
|
24
|
+
"topic": "MCP",
|
|
25
|
+
"source": "github:modelcontextprotocol/typescript-sdk"
|
|
26
|
+
},
|
|
27
|
+
"@anthropic-ai/sdk": {
|
|
28
|
+
"topic": "Anthropic SDK",
|
|
29
|
+
"source": "github:anthropics/anthropic-sdk-typescript"
|
|
30
|
+
},
|
|
31
|
+
"@anthropic-ai/claude-agent-sdk": {
|
|
32
|
+
"topic": "Claude Agent SDK",
|
|
33
|
+
"source": "github:anthropics/claude-agent-sdk-typescript"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { mkdir, readdir, readFile, rename } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { proposeMemory } from "@ocean/brain/memory/memory-write.js";
|
|
4
|
+
import { MemoryContractError } from "@ocean/core/domain/mcp/memory-contract.js";
|
|
5
|
+
import { atomicWrite, parseFrontmatter } from "@ocean/core/shared/fs-utils.js";
|
|
6
|
+
import { DAILY_DIR, INBOX_DIR, KNOWLEDGE_DIR, oceanPath, PERSONAL_DIR, } from "@ocean/core/shared/paths.js";
|
|
7
|
+
import { listMilestones } from "../express/express.js";
|
|
8
|
+
// The weekly distill (T-314): a week's session records and briefs become one digest in
|
|
9
|
+
// 01-daily/weekly/, the Decisions and Learned sections become knowledge candidates for review,
|
|
10
|
+
// each record read is marked `distilled: true`, and inbox captures marked processed move to
|
|
11
|
+
// 00-inbox/archive/<week>/. Dry run unless `apply`. Nothing is written as knowledge directly.
|
|
12
|
+
const DAY = 24 * 60 * 60 * 1000;
|
|
13
|
+
// ISO week of a YYYY-MM-DD date: its label (2026-W47) and its Monday..Sunday.
|
|
14
|
+
export function isoWeek(date) {
|
|
15
|
+
const day = new Date(`${date}T00:00:00Z`);
|
|
16
|
+
const weekday = (day.getUTCDay() + 6) % 7;
|
|
17
|
+
const monday = new Date(day.getTime() - weekday * DAY);
|
|
18
|
+
const thursday = new Date(monday.getTime() + 3 * DAY);
|
|
19
|
+
const yearStart = Date.UTC(thursday.getUTCFullYear(), 0, 1);
|
|
20
|
+
const week = Math.ceil(((thursday.getTime() - yearStart) / DAY + 1) / 7);
|
|
21
|
+
const iso = (time) => new Date(time).toISOString().slice(0, 10);
|
|
22
|
+
return {
|
|
23
|
+
label: `${thursday.getUTCFullYear()}-W${String(week).padStart(2, "0")}`,
|
|
24
|
+
from: iso(monday.getTime()),
|
|
25
|
+
to: iso(monday.getTime() + 6 * DAY),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function markdownIn(dir) {
|
|
29
|
+
const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
30
|
+
const files = [];
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
if (entry.name.startsWith("."))
|
|
33
|
+
continue;
|
|
34
|
+
const file = path.join(dir, entry.name);
|
|
35
|
+
if (entry.isDirectory())
|
|
36
|
+
files.push(...(await markdownIn(file)));
|
|
37
|
+
else if (entry.name.endsWith(".md"))
|
|
38
|
+
files.push(file);
|
|
39
|
+
}
|
|
40
|
+
return files.sort();
|
|
41
|
+
}
|
|
42
|
+
export function section(text, heading) {
|
|
43
|
+
const match = new RegExp(
|
|
44
|
+
// `(?![\\s\\S])` is the end of the text: with the m flag, `$` would end it at the first line.
|
|
45
|
+
`^## ${heading}\\n+([\\s\\S]*?)(?=\\n## |\\nRaw events|(?![\\s\\S]))`, "m").exec(text);
|
|
46
|
+
return match?.[1]?.trim() ?? "";
|
|
47
|
+
}
|
|
48
|
+
const relativeOf = (file) => path.relative(oceanPath(), file).split(path.sep).join("/");
|
|
49
|
+
// Within the frontmatter only: a body line that happens to start with `distilled:` is left alone.
|
|
50
|
+
function setDistilled(text) {
|
|
51
|
+
const end = text.startsWith("---\n") ? text.indexOf("\n---", 3) : -1;
|
|
52
|
+
if (end < 0)
|
|
53
|
+
return text;
|
|
54
|
+
const head = text.slice(0, end);
|
|
55
|
+
const next = /^distilled:.*$/m.test(head)
|
|
56
|
+
? head.replace(/^distilled:.*$/m, "distilled: true")
|
|
57
|
+
: `${head}\ndistilled: true`;
|
|
58
|
+
return next + text.slice(end);
|
|
59
|
+
}
|
|
60
|
+
export async function distillWeek(options) {
|
|
61
|
+
const week = isoWeek(options.date);
|
|
62
|
+
const inWeek = (date) => !!date && date >= week.from && date <= week.to;
|
|
63
|
+
const sessions = [];
|
|
64
|
+
for (const file of await markdownIn(oceanPath(DAILY_DIR, "sessions"))) {
|
|
65
|
+
const text = await readFile(file, "utf8");
|
|
66
|
+
const fields = parseFrontmatter(text);
|
|
67
|
+
if (fields.type !== "session" || fields.distilled === "true")
|
|
68
|
+
continue;
|
|
69
|
+
if (!inWeek(fields.date))
|
|
70
|
+
continue;
|
|
71
|
+
const title = /^# (.+)$/m.exec(text)?.[1]?.trim() ?? path.basename(file, ".md");
|
|
72
|
+
sessions.push({ file, text, title, status: fields.status ?? "" });
|
|
73
|
+
}
|
|
74
|
+
const briefs = (await markdownIn(oceanPath(DAILY_DIR, "briefs"))).filter((file) => inWeek(/(\d{4}-\d{2}-\d{2})/.exec(path.basename(file))?.[1]));
|
|
75
|
+
const captures = [];
|
|
76
|
+
for (const file of await markdownIn(oceanPath(INBOX_DIR, "captures")))
|
|
77
|
+
if (/^status:\s*processed\s*$/m.test(await readFile(file, "utf8")))
|
|
78
|
+
captures.push(file);
|
|
79
|
+
const result = {
|
|
80
|
+
week: week.label,
|
|
81
|
+
digest: null,
|
|
82
|
+
sessions: sessions.map((item) => relativeOf(item.file)),
|
|
83
|
+
candidates: [],
|
|
84
|
+
archived: captures.map((file) => `${INBOX_DIR}/archive/${week.label}/${path.basename(file)}`),
|
|
85
|
+
};
|
|
86
|
+
const archiveCaptures = async () => {
|
|
87
|
+
for (const file of captures) {
|
|
88
|
+
const target = oceanPath(INBOX_DIR, "archive", week.label, path.basename(file));
|
|
89
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
90
|
+
await rename(file, target);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
if (!sessions.length && !briefs.length) {
|
|
94
|
+
// No digest without records, but processed captures still leave the inbox.
|
|
95
|
+
if (options.apply)
|
|
96
|
+
await archiveCaptures();
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
const pick = (heading) => sessions
|
|
100
|
+
.map((item) => ({ item, text: section(item.text, heading) }))
|
|
101
|
+
.filter(({ text }) => text);
|
|
102
|
+
const decisions = pick("Decisions");
|
|
103
|
+
const learned = pick("Learned");
|
|
104
|
+
const problems = pick("Problems → fixes");
|
|
105
|
+
const next = pick("Next");
|
|
106
|
+
const link = (file, label) => `[${label.replace(/[[\]]/g, "")}](../${path.relative(oceanPath(DAILY_DIR), file).split(path.sep).join("/")})`;
|
|
107
|
+
const list = (items) => items.map(({ item, text }) => `- ${link(item.file, item.title)}: ${text.replace(/\s+/g, " ").slice(0, 400)}`);
|
|
108
|
+
const digestRelative = `${DAILY_DIR}/weekly/${week.label}.md`;
|
|
109
|
+
result.digest = digestRelative;
|
|
110
|
+
if (!options.apply)
|
|
111
|
+
return result;
|
|
112
|
+
const body = [
|
|
113
|
+
"---",
|
|
114
|
+
"type: weekly",
|
|
115
|
+
`week: ${week.label}`,
|
|
116
|
+
`from: ${week.from}`,
|
|
117
|
+
`to: ${week.to}`,
|
|
118
|
+
`sessions: ${sessions.length}`,
|
|
119
|
+
"---",
|
|
120
|
+
"",
|
|
121
|
+
`# Week ${week.label}`,
|
|
122
|
+
"",
|
|
123
|
+
"## Sessions",
|
|
124
|
+
"",
|
|
125
|
+
...(sessions.length
|
|
126
|
+
? sessions.map((item) => `- ${link(item.file, item.title)} — ${item.status || "unknown"}`)
|
|
127
|
+
: ["- none"]),
|
|
128
|
+
...(decisions.length ? ["", "## Decisions", "", ...list(decisions)] : []),
|
|
129
|
+
...(problems.length
|
|
130
|
+
? ["", "## Problems → fixes", "", ...list(problems)]
|
|
131
|
+
: []),
|
|
132
|
+
...(learned.length ? ["", "## Learned", "", ...list(learned)] : []),
|
|
133
|
+
...(next.length ? ["", "## Open next steps", "", ...list(next)] : []),
|
|
134
|
+
...(briefs.length
|
|
135
|
+
? [
|
|
136
|
+
"",
|
|
137
|
+
"## Briefs",
|
|
138
|
+
"",
|
|
139
|
+
...briefs.map((file) => `- ${link(file, path.basename(file, ".md"))}`),
|
|
140
|
+
]
|
|
141
|
+
: []),
|
|
142
|
+
"",
|
|
143
|
+
].join("\n");
|
|
144
|
+
const digest = oceanPath(digestRelative);
|
|
145
|
+
await mkdir(path.dirname(digest), { recursive: true });
|
|
146
|
+
await atomicWrite(digest, body);
|
|
147
|
+
// Decisions and lessons from the week wait for review as knowledge candidates.
|
|
148
|
+
for (const [kind, items] of [
|
|
149
|
+
["decision", decisions],
|
|
150
|
+
["lesson", learned],
|
|
151
|
+
])
|
|
152
|
+
for (const { item, text } of items) {
|
|
153
|
+
try {
|
|
154
|
+
const { candidate } = await proposeMemory({
|
|
155
|
+
content: `# ${item.title}\n\n${text}\n\nFrom: ${relativeOf(item.file)}\n`,
|
|
156
|
+
origin: "inferred",
|
|
157
|
+
source: `distill:${week.label}`,
|
|
158
|
+
reason: `${kind} recorded in a session of ${week.label}; file it under ${KNOWLEDGE_DIR}/`,
|
|
159
|
+
meta: { kind, week: week.label },
|
|
160
|
+
});
|
|
161
|
+
result.candidates.push(candidate);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
if (!(error instanceof MemoryContractError))
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const item of sessions)
|
|
169
|
+
await atomicWrite(item.file, setDistilled(item.text));
|
|
170
|
+
await archiveCaptures();
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
export async function goalNames() {
|
|
174
|
+
const text = await readFile(oceanPath(PERSONAL_DIR, "goals.md"), "utf8").catch(() => "");
|
|
175
|
+
// Active goals are the bold-led bullets before the first `## ` section (set-aside goals follow).
|
|
176
|
+
const body = text.replace(/^---\n[\s\S]*?\n---\n/, "").split(/^## /m)[0];
|
|
177
|
+
return [...body.matchAll(/^- \*\*(.+?)\*\*/gm)].map((match) => match[1].replace(/[.:]$/, "").trim());
|
|
178
|
+
}
|
|
179
|
+
export async function reviewMonth(options) {
|
|
180
|
+
const { month } = options;
|
|
181
|
+
const first = `${month}-01`;
|
|
182
|
+
const last = `${month}-31`;
|
|
183
|
+
const weeks = [];
|
|
184
|
+
for (const file of await markdownIn(oceanPath(DAILY_DIR, "weekly"))) {
|
|
185
|
+
const fields = parseFrontmatter(await readFile(file, "utf8"));
|
|
186
|
+
if (fields.type !== "weekly")
|
|
187
|
+
continue;
|
|
188
|
+
// A week that straddles two months belongs to both reviews.
|
|
189
|
+
if ((fields.to ?? "") >= first && (fields.from ?? "") <= last)
|
|
190
|
+
weeks.push(file);
|
|
191
|
+
}
|
|
192
|
+
const milestones = (await listMilestones()).filter((item) => item.date.startsWith(month));
|
|
193
|
+
const sessions = (await markdownIn(oceanPath(DAILY_DIR, "sessions", month)))
|
|
194
|
+
.length;
|
|
195
|
+
const goals = await goalNames();
|
|
196
|
+
const relative = `${DAILY_DIR}/monthly/${month}.md`;
|
|
197
|
+
const result = {
|
|
198
|
+
month,
|
|
199
|
+
review: relative,
|
|
200
|
+
weeks: weeks.map(relativeOf),
|
|
201
|
+
milestones: milestones.map((item) => item.title),
|
|
202
|
+
sessions,
|
|
203
|
+
goals,
|
|
204
|
+
};
|
|
205
|
+
if (!weeks.length && !milestones.length && !sessions) {
|
|
206
|
+
result.review = null;
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
if (!options.apply)
|
|
210
|
+
return result;
|
|
211
|
+
const file = oceanPath(relative);
|
|
212
|
+
// The owner's answers live in this file; a rerun never overwrites them.
|
|
213
|
+
if (await readFile(file, "utf8").then(() => true, () => false))
|
|
214
|
+
return result;
|
|
215
|
+
const link = (target, label) => `[${label.replace(/[[\]]/g, "")}](../${path.relative(oceanPath(DAILY_DIR), target).split(path.sep).join("/")})`;
|
|
216
|
+
const body = [
|
|
217
|
+
"---",
|
|
218
|
+
"type: monthly",
|
|
219
|
+
`month: ${month}`,
|
|
220
|
+
`sessions: ${sessions}`,
|
|
221
|
+
`milestones: ${milestones.length}`,
|
|
222
|
+
"reviewed: false",
|
|
223
|
+
"---",
|
|
224
|
+
"",
|
|
225
|
+
`# Month ${month}`,
|
|
226
|
+
"",
|
|
227
|
+
"## Goals",
|
|
228
|
+
"",
|
|
229
|
+
"For each goal: did this month move it? One line of evidence, or why not.",
|
|
230
|
+
"",
|
|
231
|
+
...(goals.length
|
|
232
|
+
? goals.map((goal) => `- [ ] **${goal}** — `)
|
|
233
|
+
: [`- none found in ${PERSONAL_DIR}/goals.md`]),
|
|
234
|
+
"",
|
|
235
|
+
"## Finished",
|
|
236
|
+
"",
|
|
237
|
+
...(milestones.length
|
|
238
|
+
? milestones.map((item) => `- **${item.title}** (${item.date}) — ${item.kind}`)
|
|
239
|
+
: ["- no milestone marked done"]),
|
|
240
|
+
"",
|
|
241
|
+
"## Weeks",
|
|
242
|
+
"",
|
|
243
|
+
...(weeks.length
|
|
244
|
+
? weeks.map((week) => `- ${link(week, path.basename(week, ".md"))}`)
|
|
245
|
+
: ["- no weekly digest"]),
|
|
246
|
+
"",
|
|
247
|
+
`Sessions recorded: ${sessions}.`,
|
|
248
|
+
"",
|
|
249
|
+
"## Next month",
|
|
250
|
+
"",
|
|
251
|
+
"- ",
|
|
252
|
+
"",
|
|
253
|
+
].join("\n");
|
|
254
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
255
|
+
await atomicWrite(file, body);
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=distill.js.map
|
|
@@ -3,9 +3,10 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
import { access, chmod, mkdir, readdir, readFile, stat, writeFile, } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
|
+
import { inTypeLocation } from "@ocean/brain/memory/fact-routing.js";
|
|
6
7
|
import { doctorMemoryIndexes, syncMemoryIndexes, } from "@ocean/brain/memory/index-sync.js";
|
|
7
8
|
import { memorySettings } from "@ocean/brain/memory/memory-audit.js";
|
|
8
|
-
import { BRAIN_RECORD_DIRS, CHARTER_DIR, enginePath, INBOX_DIR, oceanEnv, oceanPath, POLICIES_DIR, PROJECTS_DIR, projectDir, repoPath, SYSTEM_DIR, workspaceTasksRoot, } from "@ocean/core/shared/paths.js";
|
|
9
|
+
import { BRAIN_RECORD_DIRS, CHARTER_DIR, enginePath, INBOX_DIR, NOTES_DIR, oceanEnv, oceanPath, POLICIES_DIR, PROJECTS_DIR, projectDir, repoPath, SYSTEM_DIR, workspaceTasksRoot, } from "@ocean/core/shared/paths.js";
|
|
9
10
|
import { ensureProjectLayout, listProjectManifests, PROJECT_ROOT_ENTRIES, scanProjectManifests, UNCATEGORIZED, } from "@ocean/core/shared/project-resolution.js";
|
|
10
11
|
const execFile = promisify(execFileCallback);
|
|
11
12
|
const roots = [...BRAIN_RECORD_DIRS, PROJECTS_DIR, SYSTEM_DIR];
|
|
@@ -64,13 +65,22 @@ async function checkStructure() {
|
|
|
64
65
|
message: `${root} root exists`,
|
|
65
66
|
fixable: false,
|
|
66
67
|
}
|
|
67
|
-
:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
: // 07-notes arrived in a later version (T-314): a workspace made before it is not broken.
|
|
69
|
+
root === NOTES_DIR
|
|
70
|
+
? {
|
|
71
|
+
code: "ROOT_MISSING",
|
|
72
|
+
severity: "WARN",
|
|
73
|
+
path: root,
|
|
74
|
+
message: `${root} (your own notes) does not exist yet; \`ocean setup\` creates it`,
|
|
75
|
+
fixable: false,
|
|
76
|
+
}
|
|
77
|
+
: {
|
|
78
|
+
code: "ROOT_MISSING",
|
|
79
|
+
severity: "FAIL",
|
|
80
|
+
path: root,
|
|
81
|
+
message: `${root} root is missing`,
|
|
82
|
+
fixable: false,
|
|
83
|
+
});
|
|
74
84
|
}
|
|
75
85
|
return findings;
|
|
76
86
|
}
|
|
@@ -370,6 +380,115 @@ async function checkProjectCategories() {
|
|
|
370
380
|
}
|
|
371
381
|
return findings;
|
|
372
382
|
}
|
|
383
|
+
// The inbox is a waiting room, not a home (T-314): what sits there longer than a week was never
|
|
384
|
+
// sorted. Its own index and the clients' native memory staging are not items.
|
|
385
|
+
const INBOX_STALE_DAYS = 7;
|
|
386
|
+
async function checkInboxStale(now = Date.now()) {
|
|
387
|
+
const inbox = oceanPath(INBOX_DIR);
|
|
388
|
+
const cutoff = now - INBOX_STALE_DAYS * 24 * 60 * 60 * 1000;
|
|
389
|
+
const byFolder = new Map();
|
|
390
|
+
for (const file of await markdownFiles(inbox)) {
|
|
391
|
+
const [folder, ...rest] = path.relative(inbox, file).split(path.sep);
|
|
392
|
+
if (!rest.length || folder === "native")
|
|
393
|
+
continue;
|
|
394
|
+
if ((await stat(file)).mtimeMs >= cutoff)
|
|
395
|
+
continue;
|
|
396
|
+
byFolder.set(folder, (byFolder.get(folder) ?? 0) + 1);
|
|
397
|
+
}
|
|
398
|
+
const total = [...byFolder.values()].reduce((sum, n) => sum + n, 0);
|
|
399
|
+
return [
|
|
400
|
+
total
|
|
401
|
+
? {
|
|
402
|
+
code: "INBOX_STALE",
|
|
403
|
+
severity: "WARN",
|
|
404
|
+
path: INBOX_DIR,
|
|
405
|
+
message: `${total} inbox item(s) older than ${INBOX_STALE_DAYS} days: ${[
|
|
406
|
+
...byFolder,
|
|
407
|
+
]
|
|
408
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
409
|
+
.map(([folder, n]) => `${folder} ${n}`)
|
|
410
|
+
.join(", ")}; sort them or archive them`,
|
|
411
|
+
fixable: false,
|
|
412
|
+
}
|
|
413
|
+
: {
|
|
414
|
+
code: "INBOX_FRESH",
|
|
415
|
+
severity: "OK",
|
|
416
|
+
path: INBOX_DIR,
|
|
417
|
+
message: `nothing in the inbox is older than ${INBOX_STALE_DAYS} days`,
|
|
418
|
+
fixable: false,
|
|
419
|
+
},
|
|
420
|
+
];
|
|
421
|
+
}
|
|
422
|
+
// Every record carries frontmatter, and a record whose type has one home sits there (T-314,
|
|
423
|
+
// routing.json). Index files, templates, task folders and the inbox's machine areas are not
|
|
424
|
+
// records; neither are the owner's notes, which are his to shape.
|
|
425
|
+
const INDEX_FILE = /^[A-Z][A-Z0-9_-]*\.md$/;
|
|
426
|
+
const NOT_RECORDS = [
|
|
427
|
+
/^00-inbox\/(?:candidates|native|brain-dump)\//,
|
|
428
|
+
/^06-templates\//,
|
|
429
|
+
/^07-notes\//,
|
|
430
|
+
/^04-projects\/(?:.+\/)?tasks\//,
|
|
431
|
+
// Indexes Ocean generates or appends to, not records: frontmatter there would be rewritten away.
|
|
432
|
+
/^04-projects\/(?:backlog|registry)\.md$/,
|
|
433
|
+
/^04-projects\/.+\/index\.md$/,
|
|
434
|
+
];
|
|
435
|
+
async function checkRecordShape() {
|
|
436
|
+
// Relative to the records prefix (flat: the root; nested: brain/), the form routing.json uses.
|
|
437
|
+
const base = oceanPath(path.posix.dirname(INBOX_DIR));
|
|
438
|
+
const missing = new Map();
|
|
439
|
+
const misplaced = [];
|
|
440
|
+
for (const root of new Set([...BRAIN_RECORD_DIRS, PROJECTS_DIR]))
|
|
441
|
+
for (const file of await markdownFiles(oceanPath(root))) {
|
|
442
|
+
const relative = path.relative(base, file).split(path.sep).join("/");
|
|
443
|
+
if (INDEX_FILE.test(path.basename(file)))
|
|
444
|
+
continue;
|
|
445
|
+
if (NOT_RECORDS.some((pattern) => pattern.test(relative)))
|
|
446
|
+
continue;
|
|
447
|
+
const text = await readFile(file, "utf8");
|
|
448
|
+
if (!/^---\r?\n/.test(text)) {
|
|
449
|
+
const area = relative.split("/")[0];
|
|
450
|
+
missing.set(area, (missing.get(area) ?? 0) + 1);
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
const head = text.split(/\r?\n---/, 1)[0];
|
|
454
|
+
const type = /^type:\s*["']?([\w-]+)/m.exec(head)?.[1];
|
|
455
|
+
if (type && !inTypeLocation(relative, type))
|
|
456
|
+
misplaced.push(`${relative} (${type})`);
|
|
457
|
+
}
|
|
458
|
+
const total = [...missing.values()].reduce((sum, n) => sum + n, 0);
|
|
459
|
+
const counts = [...missing]
|
|
460
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
461
|
+
.map(([area, n]) => `${area} ${n}`)
|
|
462
|
+
.join(", ");
|
|
463
|
+
return [
|
|
464
|
+
total
|
|
465
|
+
? {
|
|
466
|
+
code: "FRONTMATTER_MISSING",
|
|
467
|
+
severity: "WARN",
|
|
468
|
+
message: `${total} record(s) without frontmatter: ${counts}`,
|
|
469
|
+
fixable: false,
|
|
470
|
+
}
|
|
471
|
+
: {
|
|
472
|
+
code: "FRONTMATTER_PRESENT",
|
|
473
|
+
severity: "OK",
|
|
474
|
+
message: "every record has frontmatter",
|
|
475
|
+
fixable: false,
|
|
476
|
+
},
|
|
477
|
+
misplaced.length
|
|
478
|
+
? {
|
|
479
|
+
code: "TYPE_LOCATION",
|
|
480
|
+
severity: "WARN",
|
|
481
|
+
message: `${misplaced.length} record(s) outside their type's folder (routing.json): ${misplaced.slice(0, 5).join("; ")}${misplaced.length > 5 ? "; …" : ""}`,
|
|
482
|
+
fixable: false,
|
|
483
|
+
}
|
|
484
|
+
: {
|
|
485
|
+
code: "TYPE_LOCATION_OK",
|
|
486
|
+
severity: "OK",
|
|
487
|
+
message: "every typed record sits in its type's folder",
|
|
488
|
+
fixable: false,
|
|
489
|
+
},
|
|
490
|
+
];
|
|
491
|
+
}
|
|
373
492
|
async function checkDuplicates() {
|
|
374
493
|
const seen = new Map();
|
|
375
494
|
const duplicates = [];
|
|
@@ -550,6 +669,8 @@ async function scanWorkspace(wrapperManager) {
|
|
|
550
669
|
...(await checkWorkspaceContracts()),
|
|
551
670
|
...(await checkPermissions()),
|
|
552
671
|
...(await checkDuplicates()),
|
|
672
|
+
...(await checkInboxStale()),
|
|
673
|
+
...(await checkRecordShape()),
|
|
553
674
|
...(await checkProjectLayout()),
|
|
554
675
|
...(await checkClaudeProjects()),
|
|
555
676
|
...(await checkProjectCategories()),
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { mkdir, readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { atomicWrite, parseFrontmatter } from "@ocean/core/shared/fs-utils.js";
|
|
4
|
+
import { INBOX_DIR, oceanPath, PERSONAL_DIR, } from "@ocean/core/shared/paths.js";
|
|
5
|
+
// Express (T-314): the owner's milestones, turned into drafts he edits before using — a CV
|
|
6
|
+
// section, a LinkedIn post, a scholarship paragraph. Built from the records alone (no model, no
|
|
7
|
+
// invented facts), written to 00-inbox/drafts/ for review, never sent anywhere.
|
|
8
|
+
export const EXPRESS_KINDS = ["cv", "linkedin", "scholarship"];
|
|
9
|
+
export async function listMilestones() {
|
|
10
|
+
const dir = oceanPath(PERSONAL_DIR, "milestones");
|
|
11
|
+
const milestones = [];
|
|
12
|
+
for (const name of await readdir(dir).catch(() => [])) {
|
|
13
|
+
if (!name.endsWith(".md"))
|
|
14
|
+
continue;
|
|
15
|
+
// One unreadable file is skipped, not fatal to the draft.
|
|
16
|
+
const raw = await readFile(path.join(dir, name), "utf8").catch(() => null);
|
|
17
|
+
if (raw === null)
|
|
18
|
+
continue;
|
|
19
|
+
const text = raw.replace(/\r\n/g, "\n");
|
|
20
|
+
const fields = parseFrontmatter(text);
|
|
21
|
+
if (fields.type !== "milestone")
|
|
22
|
+
continue;
|
|
23
|
+
const end = text.startsWith("---") ? text.indexOf("\n---", 3) : -1;
|
|
24
|
+
const body = end < 0 ? text : text.slice(end + 4);
|
|
25
|
+
const title = /^# (.+)$/m.exec(body)?.[1]?.trim() ?? name.replace(/\.md$/, "");
|
|
26
|
+
const summary = body
|
|
27
|
+
.replace(/^# .+$/m, "")
|
|
28
|
+
.split("\n")
|
|
29
|
+
.map((line) => line.trim())
|
|
30
|
+
.filter((line) => line && !line.startsWith("#"))
|
|
31
|
+
.join(" ")
|
|
32
|
+
.slice(0, 300);
|
|
33
|
+
milestones.push({
|
|
34
|
+
title,
|
|
35
|
+
date: fields.date ?? "",
|
|
36
|
+
kind: fields.kind || "other",
|
|
37
|
+
// Only a milestone that says it is done is drafted as an achievement.
|
|
38
|
+
status: fields.status ?? "",
|
|
39
|
+
summary,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return milestones
|
|
43
|
+
.filter((item) => item.status === "done")
|
|
44
|
+
.sort((a, b) => b.date.localeCompare(a.date) || a.title.localeCompare(b.title));
|
|
45
|
+
}
|
|
46
|
+
const line = (item) => `- **${item.title}**${item.date ? ` (${item.date.slice(0, 7)})` : ""}${item.summary ? ` — ${item.summary}` : ""}`;
|
|
47
|
+
const ACADEMIC = new Set([
|
|
48
|
+
"certificate",
|
|
49
|
+
"education",
|
|
50
|
+
"exam",
|
|
51
|
+
"scholarship",
|
|
52
|
+
"course",
|
|
53
|
+
]);
|
|
54
|
+
export function draft(kind, milestones) {
|
|
55
|
+
if (kind === "cv") {
|
|
56
|
+
const groups = new Map();
|
|
57
|
+
for (const item of milestones)
|
|
58
|
+
groups.set(item.kind, [...(groups.get(item.kind) ?? []), item]);
|
|
59
|
+
return [...groups]
|
|
60
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
61
|
+
.map(([group, items]) => `## ${group[0].toUpperCase()}${group.slice(1)}\n\n${items.map(line).join("\n")}`)
|
|
62
|
+
.join("\n\n");
|
|
63
|
+
}
|
|
64
|
+
if (kind === "linkedin") {
|
|
65
|
+
const recent = milestones.slice(0, 3);
|
|
66
|
+
return [
|
|
67
|
+
"<!-- Draft: rewrite in your own voice before posting. -->",
|
|
68
|
+
"",
|
|
69
|
+
"A few things I finished recently:",
|
|
70
|
+
"",
|
|
71
|
+
...recent.map(line),
|
|
72
|
+
"",
|
|
73
|
+
"What I learned along the way: <one honest sentence>.",
|
|
74
|
+
].join("\n");
|
|
75
|
+
}
|
|
76
|
+
const academic = milestones.filter((item) => ACADEMIC.has(item.kind));
|
|
77
|
+
return [
|
|
78
|
+
"<!-- Draft: one paragraph for an application; check every claim against its record. -->",
|
|
79
|
+
"",
|
|
80
|
+
academic.length
|
|
81
|
+
? `My preparation so far: ${academic
|
|
82
|
+
.map((item) => `${item.title}${item.date ? ` (${item.date.slice(0, 4)})` : ""}`)
|
|
83
|
+
.join("; ")}.`
|
|
84
|
+
: "No academic milestones are recorded yet.",
|
|
85
|
+
].join("\n");
|
|
86
|
+
}
|
|
87
|
+
export async function writeDraft(options) {
|
|
88
|
+
const milestones = await listMilestones();
|
|
89
|
+
const body = draft(options.kind, milestones);
|
|
90
|
+
const text = `---\ntype: draft\nkind: ${options.kind}\ncreated: ${options.date}\nsource: milestones\n---\n\n# ${options.kind} draft — ${options.date}\n\n${body}\n`;
|
|
91
|
+
if (options.dryRun || !milestones.length)
|
|
92
|
+
return { file: null, milestones: milestones.length, text };
|
|
93
|
+
const relative = `${INBOX_DIR}/drafts/${options.kind}-${options.date}.md`;
|
|
94
|
+
const file = oceanPath(relative);
|
|
95
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
96
|
+
await atomicWrite(file, text);
|
|
97
|
+
return { file: relative, milestones: milestones.length, text };
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=express.js.map
|