@amoree-code/ocean 1.11.0 → 2.0.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 +8 -1
- package/dist/application/clients/editors.js +3 -1
- package/dist/application/integrations/skill-auto-sync.js +44 -0
- package/dist/application/onboarding/steps.js +4 -3
- package/dist/interfaces/cli/browser-command.js +34 -1
- package/dist/interfaces/cli/browser-findings.js +19 -7
- package/dist/interfaces/cli/command-registry.js +16 -1
- package/dist/interfaces/cli/help-command.js +3 -3
- package/dist/interfaces/cli/market-command.js +11 -4
- package/market/mcp/chrome-devtools/ocean.capability.json +33 -4
- package/node_modules/@ocean/brain/dist/infrastructure/brain/brain-index.js +29 -2
- package/node_modules/@ocean/brain/dist/memory/brain-dump.js +5 -2
- 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/clean-title.js +17 -0
- package/node_modules/@ocean/core/package.json +1 -1
- package/node_modules/@ocean/loop/dist/tasks/verify-task.js +31 -27
- package/node_modules/@ocean/loop/package.json +1 -1
- package/node_modules/@ocean/market/dist/mcp/chrome-debugging.js +148 -15
- package/node_modules/@ocean/market/dist/mcp/mcp-launch.js +9 -1
- package/node_modules/@ocean/market/dist/skills/core-skill-sync.js +10 -2
- package/node_modules/@ocean/market/dist/skills/skill-hub.js +99 -7
- package/node_modules/@ocean/market/package.json +1 -1
- package/node_modules/@ocean/services/dist/distill/distill.js +2 -1
- package/node_modules/@ocean/services/dist/doctor/workspace-doctor.js +5 -1
- package/node_modules/@ocean/services/dist/harvest/harvest.js +3 -14
- package/node_modules/@ocean/services/dist/projects/projects-overview.js +172 -0
- package/node_modules/@ocean/services/package.json +1 -1
- package/ocean-marketplace.json +66 -39
- package/package.json +7 -7
|
@@ -2,23 +2,142 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { connect } from "node:net";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
// The capability that attaches to the owner's running browser, and the value that names which
|
|
6
|
+
// browser: a profile root, passed to chrome-devtools-mcp as `--userDataDir`. Unset means Chrome.
|
|
7
|
+
export const BROWSER_CAPABILITY = "dev.ocean/chrome-devtools";
|
|
8
|
+
export const BROWSER_PROFILE_VARIABLE = "OCEAN_BROWSER_USER_DATA_DIR";
|
|
9
|
+
// Chromium browsers and where each keeps its profile root, which is where the browser writes
|
|
10
|
+
// DevToolsActivePort while its inspect page's remote debugging is on. Windows paths are under
|
|
11
|
+
// %LOCALAPPDATA% unless marked roaming; Linux paths are under ~/.config.
|
|
12
|
+
export const CHROMIUM_BROWSERS = [
|
|
13
|
+
{
|
|
14
|
+
id: "chrome",
|
|
15
|
+
label: "Chrome",
|
|
16
|
+
roots: {
|
|
17
|
+
darwin: ["Google", "Chrome"],
|
|
18
|
+
win32: ["Google", "Chrome", "User Data"],
|
|
19
|
+
linux: ["google-chrome"],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "chrome-beta",
|
|
24
|
+
label: "Chrome Beta",
|
|
25
|
+
roots: {
|
|
26
|
+
darwin: ["Google", "Chrome Beta"],
|
|
27
|
+
win32: ["Google", "Chrome Beta", "User Data"],
|
|
28
|
+
linux: ["google-chrome-beta"],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "chrome-canary",
|
|
33
|
+
label: "Chrome Canary",
|
|
34
|
+
roots: {
|
|
35
|
+
darwin: ["Google", "Chrome Canary"],
|
|
36
|
+
win32: ["Google", "Chrome SxS", "User Data"],
|
|
37
|
+
linux: ["google-chrome-canary"],
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "chromium",
|
|
42
|
+
label: "Chromium",
|
|
43
|
+
roots: {
|
|
44
|
+
darwin: ["Chromium"],
|
|
45
|
+
win32: ["Chromium", "User Data"],
|
|
46
|
+
linux: ["chromium"],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "brave",
|
|
51
|
+
label: "Brave",
|
|
52
|
+
roots: {
|
|
53
|
+
darwin: ["BraveSoftware", "Brave-Browser"],
|
|
54
|
+
win32: ["BraveSoftware", "Brave-Browser", "User Data"],
|
|
55
|
+
linux: ["BraveSoftware", "Brave-Browser"],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: "edge",
|
|
60
|
+
label: "Microsoft Edge",
|
|
61
|
+
roots: {
|
|
62
|
+
darwin: ["Microsoft Edge"],
|
|
63
|
+
win32: ["Microsoft", "Edge", "User Data"],
|
|
64
|
+
linux: ["microsoft-edge"],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: "vivaldi",
|
|
69
|
+
label: "Vivaldi",
|
|
70
|
+
roots: {
|
|
71
|
+
darwin: ["Vivaldi"],
|
|
72
|
+
win32: ["Vivaldi", "User Data"],
|
|
73
|
+
linux: ["vivaldi"],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "opera",
|
|
78
|
+
label: "Opera",
|
|
79
|
+
roaming: true,
|
|
80
|
+
roots: {
|
|
81
|
+
darwin: ["com.operasoftware.Opera"],
|
|
82
|
+
win32: ["Opera Software", "Opera Stable"],
|
|
83
|
+
linux: ["opera"],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: "arc",
|
|
88
|
+
label: "Arc",
|
|
89
|
+
roots: { darwin: ["Arc", "User Data"] },
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
// A browser's profile root on this platform, or undefined when it has none here.
|
|
93
|
+
export function browserProfileRoot(id, home = os.homedir(), platform = process.platform, env = process.env) {
|
|
94
|
+
const browser = CHROMIUM_BROWSERS.find((each) => each.id === id);
|
|
95
|
+
const parts = platform === "darwin" || platform === "win32"
|
|
96
|
+
? browser?.roots[platform]
|
|
97
|
+
: browser?.roots.linux;
|
|
98
|
+
if (!browser || !parts)
|
|
99
|
+
return undefined;
|
|
100
|
+
const base = platform === "darwin"
|
|
101
|
+
? path.join(home, "Library", "Application Support")
|
|
10
102
|
: platform === "win32"
|
|
11
|
-
?
|
|
12
|
-
env.
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
]
|
|
17
|
-
: [home, ".config", "google-chrome"];
|
|
18
|
-
return path.join(...parts, "DevToolsActivePort");
|
|
103
|
+
? browser.roaming
|
|
104
|
+
? (env.APPDATA ?? path.join(home, "AppData", "Roaming"))
|
|
105
|
+
: (env.LOCALAPPDATA ?? path.join(home, "AppData", "Local"))
|
|
106
|
+
: path.join(home, ".config");
|
|
107
|
+
return path.join(base, ...parts);
|
|
19
108
|
}
|
|
20
|
-
//
|
|
21
|
-
//
|
|
109
|
+
// `ocean browser use <name|path>`: a known browser's profile root, or an absolute path as given
|
|
110
|
+
// (a custom profile, or a Chromium browser not in the list).
|
|
111
|
+
export function resolveBrowserChoice(choice, home = os.homedir(), platform = process.platform, env = process.env) {
|
|
112
|
+
if (path.isAbsolute(choice))
|
|
113
|
+
return path.resolve(choice);
|
|
114
|
+
const root = browserProfileRoot(choice.toLowerCase(), home, platform, env);
|
|
115
|
+
if (root)
|
|
116
|
+
return root;
|
|
117
|
+
const known = CHROMIUM_BROWSERS.filter((each) => browserProfileRoot(each.id, home, platform, env)).map((each) => each.id);
|
|
118
|
+
throw new Error(`unknown browser "${choice}" on ${platform}: use one of ${known.join(", ")}, or an absolute profile path`);
|
|
119
|
+
}
|
|
120
|
+
// The name a profile root goes by, for messages.
|
|
121
|
+
export function browserLabel(root, home = os.homedir(), platform = process.platform, env = process.env) {
|
|
122
|
+
const browser = CHROMIUM_BROWSERS.find((each) => browserProfileRoot(each.id, home, platform, env) === root);
|
|
123
|
+
return browser ? browser.label : `the browser at ${root}`;
|
|
124
|
+
}
|
|
125
|
+
// The browser chosen for this machine: the environment, then the stored choice, then Chrome.
|
|
126
|
+
export function selectedBrowserProfile(options = {}) {
|
|
127
|
+
const env = options.env ?? process.env;
|
|
128
|
+
const home = options.home ?? os.homedir();
|
|
129
|
+
const platform = options.platform ?? process.platform;
|
|
130
|
+
return (env[BROWSER_PROFILE_VARIABLE] ??
|
|
131
|
+
options.stored?.() ??
|
|
132
|
+
browserProfileRoot("chrome", home, platform, env));
|
|
133
|
+
}
|
|
134
|
+
// The browser writes the port of its debugging server here while its inspect page's remote
|
|
135
|
+
// debugging is on; `chrome-devtools-mcp --autoConnect` reads the same file to attach to it.
|
|
136
|
+
export function devToolsPortFile(home = os.homedir(), platform = process.platform, env = process.env, profileRoot = browserProfileRoot("chrome", home, platform, env)) {
|
|
137
|
+
return path.join(profileRoot, "DevToolsActivePort");
|
|
138
|
+
}
|
|
139
|
+
// A plain TCP connect: it tells whether a browser's debugging server is up without opening a
|
|
140
|
+
// DevTools session, so it never raises the browser's permission prompt.
|
|
22
141
|
export async function chromeDebuggingListening(file = devToolsPortFile()) {
|
|
23
142
|
let port;
|
|
24
143
|
try {
|
|
@@ -40,4 +159,18 @@ export async function chromeDebuggingListening(file = devToolsPortFile()) {
|
|
|
40
159
|
socket.once("error", () => finish(false));
|
|
41
160
|
});
|
|
42
161
|
}
|
|
162
|
+
// Every known browser on this platform whose debugging server is listening right now.
|
|
163
|
+
export async function listeningBrowsers(options = {}) {
|
|
164
|
+
const home = options.home ?? os.homedir();
|
|
165
|
+
const platform = options.platform ?? process.platform;
|
|
166
|
+
const env = options.env ?? process.env;
|
|
167
|
+
const probe = options.listening ?? chromeDebuggingListening;
|
|
168
|
+
const found = await Promise.all(CHROMIUM_BROWSERS.map(async (browser) => {
|
|
169
|
+
const root = browserProfileRoot(browser.id, home, platform, env);
|
|
170
|
+
return root && (await probe(path.join(root, "DevToolsActivePort")))
|
|
171
|
+
? { id: browser.id, label: browser.label, root }
|
|
172
|
+
: undefined;
|
|
173
|
+
}));
|
|
174
|
+
return found.filter((each) => each !== undefined);
|
|
175
|
+
}
|
|
43
176
|
//# sourceMappingURL=chrome-debugging.js.map
|
|
@@ -3,12 +3,20 @@ import path from "node:path";
|
|
|
3
3
|
import { remoteUrlAllowed, } from "../adapters/mcp-adapter.js";
|
|
4
4
|
import { PermissionPolicy } from "../security/permissions.js";
|
|
5
5
|
const remoteTransports = ["streamable-http", "sse"];
|
|
6
|
+
const EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
6
7
|
// Where each runner takes its own (runtime) arguments: before the package for npx and uvx,
|
|
7
8
|
// after `run` for docker, so container flags such as `-e` or `-v` reach `docker run`.
|
|
8
9
|
const runners = {
|
|
10
|
+
// An exact version never changes once published, so npx uses its cache when it holds it
|
|
11
|
+
// instead of asking the registry on every server start (~0.3–0.5 s each, T-316).
|
|
9
12
|
npm: (identifier, version, runtime) => ({
|
|
10
13
|
command: "npx",
|
|
11
|
-
args: [
|
|
14
|
+
args: [
|
|
15
|
+
...runtime,
|
|
16
|
+
"-y",
|
|
17
|
+
...(version && EXACT_VERSION.test(version) ? ["--prefer-offline"] : []),
|
|
18
|
+
version ? `${identifier}@${version}` : identifier,
|
|
19
|
+
],
|
|
12
20
|
}),
|
|
13
21
|
pypi: (identifier, version, runtime) => ({
|
|
14
22
|
command: "uvx",
|
|
@@ -11,7 +11,8 @@ export const clientSkillRoots = {
|
|
|
11
11
|
cursor: (home) => path.join(home, ".cursor", "skills"),
|
|
12
12
|
antigravity: (home) => path.join(home, ".config", "antigravity", "skills"),
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
// The engine's core skills, by folder name.
|
|
15
|
+
export async function coreSkillNames() {
|
|
15
16
|
const core = path.join(enginePath("skills"), "core");
|
|
16
17
|
return (await readdir(core, { withFileTypes: true }))
|
|
17
18
|
.filter((entry) => entry.isDirectory())
|
|
@@ -61,7 +62,9 @@ export async function coreSkillReports(home = os.homedir()) {
|
|
|
61
62
|
};
|
|
62
63
|
}));
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
+
// `keepNewer` (the session-start sync): a client copy changed after the engine's version is the
|
|
66
|
+
// owner's edit and stays; a missing skill or one the engine has moved past is copied.
|
|
67
|
+
export async function syncCoreSkills(home = os.homedir(), options = {}) {
|
|
65
68
|
const names = await coreSkillNames();
|
|
66
69
|
const results = [];
|
|
67
70
|
for (const report of await coreSkillReports(home)) {
|
|
@@ -92,6 +95,11 @@ export async function syncCoreSkills(home = os.homedir()) {
|
|
|
92
95
|
catch {
|
|
93
96
|
/* new client skill */
|
|
94
97
|
}
|
|
98
|
+
if (current &&
|
|
99
|
+
!same(sourceBytes, current) &&
|
|
100
|
+
options.keepNewer &&
|
|
101
|
+
(await stat(target)).mtimeMs > (await stat(source)).mtimeMs)
|
|
102
|
+
continue;
|
|
95
103
|
if (!current || !same(sourceBytes, current)) {
|
|
96
104
|
await cp(source, target);
|
|
97
105
|
copied.push(name);
|
|
@@ -2,8 +2,8 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { cp, lstat, mkdir, readdir, readFile, readlink, rename, rm, stat, symlink, } from "node:fs/promises";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
import { clientSkillRoots } from "./core-skill-sync.js";
|
|
5
|
+
import { oceanPath, SYSTEM_DIR } from "@ocean/core/shared/paths.js";
|
|
6
|
+
import { clientSkillRoots, coreSkillNames, } from "./core-skill-sync.js";
|
|
7
7
|
// The hub is the one place skills live inside Ocean. Clients hold symlinks into it, so
|
|
8
8
|
// there is a single copy to edit and nothing drifts per client.
|
|
9
9
|
export function skillHubRoot() {
|
|
@@ -27,14 +27,15 @@ async function skillDirectories(root) {
|
|
|
27
27
|
}
|
|
28
28
|
return names.sort();
|
|
29
29
|
}
|
|
30
|
-
// Additive: copies
|
|
31
|
-
//
|
|
30
|
+
// Additive: copies skill folders from the given sources into the hub. An existing hub skill is
|
|
31
|
+
// never overwritten. The engine's core skills are not put here: they have one source, the
|
|
32
|
+
// engine, and reach the clients through `syncCoreSkills`.
|
|
32
33
|
export async function populateSkillHub(extraSources = []) {
|
|
33
34
|
const hub = skillHubRoot();
|
|
34
35
|
await mkdir(hub, { recursive: true });
|
|
35
36
|
const added = [];
|
|
36
37
|
const kept = [];
|
|
37
|
-
for (const source of
|
|
38
|
+
for (const source of extraSources) {
|
|
38
39
|
for (const name of await skillDirectories(source)) {
|
|
39
40
|
const target = path.join(hub, name);
|
|
40
41
|
try {
|
|
@@ -134,17 +135,41 @@ async function directoryHash(directory) {
|
|
|
134
135
|
await walk(directory, "");
|
|
135
136
|
return hash.digest("hex");
|
|
136
137
|
}
|
|
138
|
+
// The latest change anywhere in a skill directory, so the automatic sync can tell a copy the
|
|
139
|
+
// owner edited in a client (newer than the hub's) from one the hub has moved past.
|
|
140
|
+
async function newestChange(directory) {
|
|
141
|
+
let newest = (await lstat(directory)).mtimeMs;
|
|
142
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
143
|
+
const full = path.join(directory, entry.name);
|
|
144
|
+
newest = Math.max(newest, entry.isDirectory()
|
|
145
|
+
? await newestChange(full)
|
|
146
|
+
: (await lstat(full)).mtimeMs);
|
|
147
|
+
}
|
|
148
|
+
return newest;
|
|
149
|
+
}
|
|
137
150
|
// Gives every client a real copy of every hub skill, replacing the symlink farm. Dry run
|
|
138
151
|
// unless `apply`. A symlink is only unlinked (its target is untouched); a real directory
|
|
139
152
|
// that differs from the hub is moved into a timestamped backup, never deleted. Anything in a
|
|
140
153
|
// client that the hub does not name is left alone.
|
|
154
|
+
//
|
|
155
|
+
// `auto` (the session-start sync and `ocean market`): never touches what the owner made in a
|
|
156
|
+
// client. A copy changed there after the hub's version, or a link pointing outside the hub, is
|
|
157
|
+
// `kept` and left as it is; a missing hub is nothing to copy.
|
|
141
158
|
export async function copyClientSkills(options) {
|
|
142
159
|
const home = options.home ?? os.homedir();
|
|
143
160
|
const hub = options.hub ?? skillHubRoot();
|
|
144
161
|
const backup = path.join(options.archive ?? oceanPath(SYSTEM_DIR, "archive"), `skills-backup-${new Date().toISOString().replace(/[:.]/g, "-")}`);
|
|
145
162
|
const actions = [];
|
|
146
163
|
let backedUp = false;
|
|
147
|
-
|
|
164
|
+
let names;
|
|
165
|
+
try {
|
|
166
|
+
names = await skillDirectories(hub);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
if (options.auto)
|
|
170
|
+
return { actions, backup: null };
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
148
173
|
for (const client of options.clients ?? COPY_CLIENTS) {
|
|
149
174
|
const root = clientSkillRoots[client](home);
|
|
150
175
|
try {
|
|
@@ -181,8 +206,13 @@ export async function copyClientSkills(options) {
|
|
|
181
206
|
? "synchronized"
|
|
182
207
|
: "replace";
|
|
183
208
|
}
|
|
209
|
+
if (options.auto &&
|
|
210
|
+
((action === "unlink" && !ours) ||
|
|
211
|
+
(action === "replace" &&
|
|
212
|
+
(await newestChange(target)) > (await newestChange(source)))))
|
|
213
|
+
action = "kept";
|
|
184
214
|
actions.push({ client, skill, action });
|
|
185
|
-
if (!options.apply || action === "synchronized")
|
|
215
|
+
if (!options.apply || action === "synchronized" || action === "kept")
|
|
186
216
|
continue;
|
|
187
217
|
if (action === "replace" || (action === "unlink" && !ours)) {
|
|
188
218
|
const saved = path.join(backup, client);
|
|
@@ -217,4 +247,66 @@ export async function copyClientSkills(options) {
|
|
|
217
247
|
}
|
|
218
248
|
return { actions, backup: backedUp ? backup : null };
|
|
219
249
|
}
|
|
250
|
+
// The hash of every skill in the hub, by name: taken before `ocean market uninstall` so the
|
|
251
|
+
// copies of a removed skill can be found in the clients afterwards.
|
|
252
|
+
export async function hubSkillHashes(hub = skillHubRoot()) {
|
|
253
|
+
const hashes = new Map();
|
|
254
|
+
let names = [];
|
|
255
|
+
try {
|
|
256
|
+
names = await skillDirectories(hub);
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
return hashes;
|
|
260
|
+
}
|
|
261
|
+
for (const name of names)
|
|
262
|
+
try {
|
|
263
|
+
hashes.set(name, await directoryHash(path.join(hub, name)));
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
/* a skill with a symlink was never copied */
|
|
267
|
+
}
|
|
268
|
+
return hashes;
|
|
269
|
+
}
|
|
270
|
+
// Removes from every client the copies of skills that left the hub since `before` was taken.
|
|
271
|
+
// Only a copy still identical to the hub's version goes; one the owner changed stays.
|
|
272
|
+
export async function pruneClientSkills(before, options = {}) {
|
|
273
|
+
const home = options.home ?? os.homedir();
|
|
274
|
+
const now = await hubSkillHashes(options.hub);
|
|
275
|
+
const removed = [];
|
|
276
|
+
for (const [skill, hash] of before) {
|
|
277
|
+
if (now.has(skill))
|
|
278
|
+
continue;
|
|
279
|
+
for (const client of options.clients ?? COPY_CLIENTS) {
|
|
280
|
+
const target = path.join(clientSkillRoots[client](home), skill);
|
|
281
|
+
const info = await lstat(target).catch(() => null);
|
|
282
|
+
if (!info?.isDirectory())
|
|
283
|
+
continue;
|
|
284
|
+
if ((await directoryHash(target).catch(() => null)) !== hash)
|
|
285
|
+
continue;
|
|
286
|
+
await rm(target, { recursive: true, force: true });
|
|
287
|
+
removed.push(`${client}:${skill}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return removed;
|
|
291
|
+
}
|
|
292
|
+
// Hubs set up before core skills left the hub hold a copy of each, made once and never updated,
|
|
293
|
+
// so it drifts behind the engine. Each one moves into the bridge archive (kept, not deleted);
|
|
294
|
+
// a skill the marketplace installed under the same name carries its marker and stays.
|
|
295
|
+
export async function retireCoreFromHub(options = {}) {
|
|
296
|
+
const hub = options.hub ?? skillHubRoot();
|
|
297
|
+
const archive = path.join(options.archive ?? oceanPath(SYSTEM_DIR, "archive"), `hub-core-skills-${new Date().toISOString().replace(/[:.]/g, "-")}`);
|
|
298
|
+
const moved = [];
|
|
299
|
+
for (const name of await coreSkillNames()) {
|
|
300
|
+
const target = path.join(hub, name);
|
|
301
|
+
const info = await lstat(target).catch(() => null);
|
|
302
|
+
if (!info?.isDirectory())
|
|
303
|
+
continue;
|
|
304
|
+
if (await lstat(path.join(target, ".ocean-capability.json")).catch(() => null))
|
|
305
|
+
continue;
|
|
306
|
+
await mkdir(archive, { recursive: true });
|
|
307
|
+
await rename(target, path.join(archive, name));
|
|
308
|
+
moved.push(name);
|
|
309
|
+
}
|
|
310
|
+
return moved;
|
|
311
|
+
}
|
|
220
312
|
//# sourceMappingURL=skill-hub.js.map
|
|
@@ -2,6 +2,7 @@ import { mkdir, readdir, readFile, rename } from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { proposeMemory } from "@ocean/brain/memory/memory-write.js";
|
|
4
4
|
import { MemoryContractError } from "@ocean/core/domain/mcp/memory-contract.js";
|
|
5
|
+
import { cleanTitle } from "@ocean/core/shared/clean-title.js";
|
|
5
6
|
import { atomicWrite, parseFrontmatter } from "@ocean/core/shared/fs-utils.js";
|
|
6
7
|
import { DAILY_DIR, INBOX_DIR, KNOWLEDGE_DIR, oceanPath, PERSONAL_DIR, } from "@ocean/core/shared/paths.js";
|
|
7
8
|
import { listMilestones } from "../express/express.js";
|
|
@@ -68,7 +69,7 @@ export async function distillWeek(options) {
|
|
|
68
69
|
continue;
|
|
69
70
|
if (!inWeek(fields.date))
|
|
70
71
|
continue;
|
|
71
|
-
const title = /^# (.+)$/m.exec(text)?.[1]
|
|
72
|
+
const title = cleanTitle(/^# (.+)$/m.exec(text)?.[1] ?? "", fields.project || path.basename(file, ".md"));
|
|
72
73
|
sessions.push({ file, text, title, status: fields.status ?? "" });
|
|
73
74
|
}
|
|
74
75
|
const briefs = (await markdownIn(oceanPath(DAILY_DIR, "briefs"))).filter((file) => inWeek(/(\d{4}-\d{2}-\d{2})/.exec(path.basename(file))?.[1]));
|
|
@@ -87,11 +87,15 @@ async function checkStructure() {
|
|
|
87
87
|
// Session summaries are machine-written records that quote links from past chats, and
|
|
88
88
|
// bridge/skills holds installed third-party skill docs whose links are relative to their upstream
|
|
89
89
|
// repo. Neither is authored here, so their links are not ours to fix.
|
|
90
|
-
// Soft-deleted memory in state/memory/trash keeps the links it had when it was deleted
|
|
90
|
+
// Soft-deleted memory in state/memory/trash keeps the links it had when it was deleted, and the
|
|
91
|
+
// version snapshots (memory edits, harvest undo) are copies of records stored away from the
|
|
92
|
+
// folder their relative links point from.
|
|
91
93
|
const UNCHECKED_LINK_DIRS = [
|
|
92
94
|
"sessions",
|
|
93
95
|
"skills",
|
|
94
96
|
path.join("state", "memory", "trash"),
|
|
97
|
+
path.join("state", "memory", "versions"),
|
|
98
|
+
path.join("state", "harvest", "versions"),
|
|
95
99
|
];
|
|
96
100
|
async function checkLinks() {
|
|
97
101
|
const findings = [];
|
|
@@ -2,6 +2,7 @@ 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 { cleanTitle } from "@ocean/core/shared/clean-title.js";
|
|
5
6
|
import { atomicWrite, parseFrontmatter, withFileLock, } from "@ocean/core/shared/fs-utils.js";
|
|
6
7
|
import { DAILY_DIR, INBOX_DIR, KNOWLEDGE_DIR, oceanPath, SYSTEM_DIR, } from "@ocean/core/shared/paths.js";
|
|
7
8
|
import { keepTicks, noteFile, putBlock, readBlock } from "../day/note.js";
|
|
@@ -42,18 +43,6 @@ async function markdownIn(dir, skipArchive = true) {
|
|
|
42
43
|
}
|
|
43
44
|
return files.sort();
|
|
44
45
|
}
|
|
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
|
-
}
|
|
57
46
|
export async function daySessions(date) {
|
|
58
47
|
const sessions = [];
|
|
59
48
|
for (const file of await markdownIn(path.join(sessionsRoot(), date.slice(0, 7)))) {
|
|
@@ -217,7 +206,7 @@ async function fileItem(item, ledger) {
|
|
|
217
206
|
if (current.includes(link))
|
|
218
207
|
return { file: relativeOf(match), action: "same" };
|
|
219
208
|
const copy = stateDir("versions", ledger.date, relativeOf(match));
|
|
220
|
-
await mkdir(path.dirname(copy), { recursive: true });
|
|
209
|
+
await mkdir(path.dirname(copy), { recursive: true, mode: 0o700 });
|
|
221
210
|
await copyFile(match, copy);
|
|
222
211
|
ledger.updated.push({ file: relativeOf(match), copy: relativeOf(copy) });
|
|
223
212
|
let next = setField(current, "last_verified", item.session.date);
|
|
@@ -376,7 +365,7 @@ export async function harvestDay(options) {
|
|
|
376
365
|
if (action === "strengthened")
|
|
377
366
|
result.strengthened.push(file);
|
|
378
367
|
}
|
|
379
|
-
await mkdir(path.dirname(ledgerFile(date)), { recursive: true });
|
|
368
|
+
await mkdir(path.dirname(ledgerFile(date)), { recursive: true, mode: 0o700 });
|
|
380
369
|
await atomicWrite(ledgerFile(date), `${JSON.stringify(previous, null, 2)}\n`);
|
|
381
370
|
const file = noteFile(date);
|
|
382
371
|
await mkdir(path.dirname(file), { recursive: true });
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { atomicWrite, parseFrontmatter } from "@ocean/core/shared/fs-utils.js";
|
|
6
|
+
import { localDate } from "@ocean/core/shared/local-date.js";
|
|
7
|
+
import { DAILY_DIR, oceanPath, PROJECTS_DIR, projectSubdir, } from "@ocean/core/shared/paths.js";
|
|
8
|
+
import { expandHome, listProjectManifests, } from "@ocean/core/shared/project-resolution.js";
|
|
9
|
+
import { listTasks } from "@ocean/loop/tasks/list-tasks.js";
|
|
10
|
+
const execFile = promisify(execFileCallback);
|
|
11
|
+
const ACTIVE_DAYS = 60;
|
|
12
|
+
const WARM_DAYS = 365;
|
|
13
|
+
const OPEN_STATES = new Set(["active", "todo", "paused", "blocked"]);
|
|
14
|
+
async function git(cwd, args) {
|
|
15
|
+
try {
|
|
16
|
+
const { stdout } = await execFile("git", ["-C", cwd, ...args], {
|
|
17
|
+
timeout: 10_000,
|
|
18
|
+
});
|
|
19
|
+
return stdout.trim();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function gitState(dir) {
|
|
26
|
+
const root = await git(dir, ["rev-parse", "--show-toplevel"]);
|
|
27
|
+
if (!root)
|
|
28
|
+
return undefined;
|
|
29
|
+
const [branch, status, lastCommit, remote] = await Promise.all([
|
|
30
|
+
git(dir, ["branch", "--show-current"]),
|
|
31
|
+
git(dir, ["status", "--porcelain"]),
|
|
32
|
+
git(dir, ["log", "-1", "--format=%cs"]),
|
|
33
|
+
git(dir, ["remote", "get-url", "origin"]),
|
|
34
|
+
]);
|
|
35
|
+
return {
|
|
36
|
+
branch: branch || "(detached)",
|
|
37
|
+
dirty: status ? status.split("\n").filter(Boolean).length : 0,
|
|
38
|
+
lastCommit: lastCommit ?? "",
|
|
39
|
+
// A remote URL can carry a token (https://user:token@host/…): keep only host and path.
|
|
40
|
+
remote: (remote ?? "")
|
|
41
|
+
.replace(/^[a-z+]+:\/\/[^@/]*@/, "")
|
|
42
|
+
.replace(/^[a-z+]+:\/\//, "")
|
|
43
|
+
.replace(/^git@/, "")
|
|
44
|
+
.replace(/\.git$/, ""),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function activityOf(lastCommit, today = localDate()) {
|
|
48
|
+
if (!lastCommit)
|
|
49
|
+
return "no git";
|
|
50
|
+
const days = (Date.parse(`${today}T00:00:00Z`) - Date.parse(`${lastCommit}T00:00:00Z`)) /
|
|
51
|
+
86_400_000;
|
|
52
|
+
return days <= ACTIVE_DAYS
|
|
53
|
+
? "active"
|
|
54
|
+
: days <= WARM_DAYS
|
|
55
|
+
? "warm"
|
|
56
|
+
: "dormant";
|
|
57
|
+
}
|
|
58
|
+
function section(source, heading) {
|
|
59
|
+
return (new RegExp(`\\n## ${heading}\\n+([\\s\\S]*?)(?=\\n## |$)`)
|
|
60
|
+
.exec(source)?.[1]
|
|
61
|
+
?.trim()
|
|
62
|
+
.replace(/\s+/g, " ") ?? "");
|
|
63
|
+
}
|
|
64
|
+
// The next action of the most recently updated open task, prefixed with its id.
|
|
65
|
+
async function nextAction(id) {
|
|
66
|
+
const open = (await listTasks(undefined, id))
|
|
67
|
+
.filter((task) => OPEN_STATES.has(task.state))
|
|
68
|
+
.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
69
|
+
const first = open.find((task) => task.state === "active") ?? open[0];
|
|
70
|
+
if (!first)
|
|
71
|
+
return { open: 0, next: "" };
|
|
72
|
+
const file = oceanPath(PROJECTS_DIR, projectSubdir(oceanPath(PROJECTS_DIR), id), "tasks", first.id, "task.md");
|
|
73
|
+
const text = await readFile(file, "utf8").catch(() => "");
|
|
74
|
+
const next = section(text, "Next action") || first.title;
|
|
75
|
+
return { open: open.length, next: `${first.id}: ${next}`.slice(0, 160) };
|
|
76
|
+
}
|
|
77
|
+
// Newest session date per project name, from the session records' frontmatter.
|
|
78
|
+
async function lastSessions() {
|
|
79
|
+
const latest = new Map();
|
|
80
|
+
const root = oceanPath(DAILY_DIR, "sessions");
|
|
81
|
+
const months = await readdir(root).catch(() => []);
|
|
82
|
+
for (const month of months.filter((name) => /^\d{4}-\d{2}$/.test(name))) {
|
|
83
|
+
for (const name of await readdir(path.join(root, month)).catch(() => [])) {
|
|
84
|
+
if (!name.endsWith(".md"))
|
|
85
|
+
continue;
|
|
86
|
+
const head = (await readFile(path.join(root, month, name), "utf8").catch(() => "")).slice(0, 800);
|
|
87
|
+
const fields = parseFrontmatter(head);
|
|
88
|
+
const project = fields.project?.trim();
|
|
89
|
+
const date = fields.date?.trim();
|
|
90
|
+
if (!project || !date)
|
|
91
|
+
continue;
|
|
92
|
+
if ((latest.get(project) ?? "") < date)
|
|
93
|
+
latest.set(project, date);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return latest;
|
|
97
|
+
}
|
|
98
|
+
export async function projectsOverview(today = localDate()) {
|
|
99
|
+
const [manifests, sessions] = await Promise.all([
|
|
100
|
+
listProjectManifests(),
|
|
101
|
+
lastSessions(),
|
|
102
|
+
]);
|
|
103
|
+
const rows = await Promise.all(manifests.map(async (manifest) => {
|
|
104
|
+
const dir = manifest.paths[0] ? expandHome(manifest.paths[0]) : "";
|
|
105
|
+
const [gitInfo, tasks] = await Promise.all([
|
|
106
|
+
dir ? gitState(dir) : Promise.resolve(undefined),
|
|
107
|
+
nextAction(manifest.id),
|
|
108
|
+
]);
|
|
109
|
+
// Sessions are recorded under their working folder's name, which is usually the id.
|
|
110
|
+
const names = [
|
|
111
|
+
manifest.id,
|
|
112
|
+
manifest.name,
|
|
113
|
+
...manifest.paths.map((p) => path.basename(expandHome(p))),
|
|
114
|
+
];
|
|
115
|
+
const lastSession = names
|
|
116
|
+
.map((name) => sessions.get(name) ?? "")
|
|
117
|
+
.sort()
|
|
118
|
+
.at(-1);
|
|
119
|
+
return {
|
|
120
|
+
id: manifest.id,
|
|
121
|
+
path: manifest.paths[0] ?? "",
|
|
122
|
+
git: gitInfo,
|
|
123
|
+
activity: activityOf(gitInfo?.lastCommit, today),
|
|
124
|
+
openTasks: tasks.open,
|
|
125
|
+
nextAction: tasks.next,
|
|
126
|
+
lastSession: lastSession ?? "",
|
|
127
|
+
};
|
|
128
|
+
}));
|
|
129
|
+
const rank = { active: 0, warm: 1, dormant: 2, "no git": 3 };
|
|
130
|
+
return rows.sort((a, b) => rank[a.activity] - rank[b.activity] ||
|
|
131
|
+
(b.git?.lastCommit ?? "").localeCompare(a.git?.lastCommit ?? "") ||
|
|
132
|
+
a.id.localeCompare(b.id));
|
|
133
|
+
}
|
|
134
|
+
const cell = (value) => value.replace(/\|/g, "\\|") || "—";
|
|
135
|
+
export function overviewTable(rows) {
|
|
136
|
+
return [
|
|
137
|
+
"| Project | Activity | Branch | Dirty | Last commit | Last session | Open tasks | Next action |",
|
|
138
|
+
"|---|---|---|---|---|---|---|---|",
|
|
139
|
+
...rows.map((row) => [
|
|
140
|
+
`**${row.id}**`,
|
|
141
|
+
row.activity,
|
|
142
|
+
row.git ? `\`${row.git.branch}\`` : "",
|
|
143
|
+
row.git ? String(row.git.dirty) : "",
|
|
144
|
+
row.git?.lastCommit ?? "",
|
|
145
|
+
row.lastSession,
|
|
146
|
+
String(row.openTasks),
|
|
147
|
+
row.nextAction,
|
|
148
|
+
]
|
|
149
|
+
.map(cell)
|
|
150
|
+
.join(" | ")
|
|
151
|
+
.replace(/^/, "| ")
|
|
152
|
+
.replace(/$/, " |")),
|
|
153
|
+
].join("\n");
|
|
154
|
+
}
|
|
155
|
+
const BEGIN = "<!-- ocean:project-status:begin (generated by `ocean project status --write`) -->";
|
|
156
|
+
const END = "<!-- ocean:project-status:end -->";
|
|
157
|
+
// Puts the generated table into registry.md between its markers, appending them the first time.
|
|
158
|
+
// Everything outside the markers is the owner's and is left as it is.
|
|
159
|
+
export async function writeRegistryBlock(rows, today = localDate()) {
|
|
160
|
+
const file = oceanPath(PROJECTS_DIR, "registry.md");
|
|
161
|
+
const current = await readFile(file, "utf8").catch(() => "# Project registry\n");
|
|
162
|
+
const block = `${BEGIN}\n## Live (generated ${today})\n\n${overviewTable(rows)}\n${END}`;
|
|
163
|
+
const start = current.indexOf(BEGIN);
|
|
164
|
+
const end = current.indexOf(END);
|
|
165
|
+
const next = start >= 0 && end > start
|
|
166
|
+
? `${current.slice(0, start)}${block}${current.slice(end + END.length)}`
|
|
167
|
+
: `${current.replace(/\n*$/, "")}\n\n${block}\n`;
|
|
168
|
+
if (next !== current)
|
|
169
|
+
await atomicWrite(file, next);
|
|
170
|
+
return file;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=projects-overview.js.map
|