@amoree-code/ocean 2.10.0 → 2.12.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 -2
- package/dist/interfaces/cli/browser-command.js +13 -2
- package/dist/interfaces/cli/browser-findings.js +18 -1
- package/dist/interfaces/cli/browser-settings.js +173 -0
- package/dist/interfaces/cli/command-registry.js +7 -1
- package/dist/interfaces/cli/failures-command.js +71 -0
- package/dist/interfaces/cli/help-command.js +7 -3
- package/dist/interfaces/cli/scorecard-command.js +15 -1
- package/dist/interfaces/cli/telemetry-command.js +23 -3
- package/market/mcp/chrome-devtools/ocean.capability.json +54 -5
- package/market/mcp/firefox-devtools/ocean.capability.json +71 -0
- package/node_modules/@ocean/brain/dist/memory/lesson-learning.js +3 -1
- 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/runs/run-agent.js +3 -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/journey/failures.js +252 -0
- package/node_modules/@ocean/services/dist/journey/lesson-effect.js +79 -0
- package/node_modules/@ocean/services/dist/journey/telemetry.js +63 -19
- package/node_modules/@ocean/services/dist/scorecard/scorecard.js +30 -7
- package/node_modules/@ocean/services/package.json +1 -1
- package/ocean-marketplace.json +186 -40
- package/package.json +7 -7
- package/skills/core/use-browser/SKILL.md +23 -12
- package/skills/index.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "mcp",
|
|
3
|
+
"name": "dev.ocean/firefox-devtools",
|
|
4
|
+
"description": "Control Firefox through Mozilla's Firefox MCP (WebDriver BiDi): tabs, navigation, clicks, forms, screenshots, console and network. By default it starts its own Firefox with a separate profile, never the owner's daily one; `ocean browser use firefox` keeps that profile between runs. CONNECT_EXISTING=true attaches to a Firefox the owner started with `--marionette --remote-debugging-port` instead, with that session's cookies and logins. On first use it downloads geckodriver from GitHub. The filesystem permission is declared for consent but not enforced at runtime, and the npm package is pinned by version, not by digest.",
|
|
5
|
+
"permissions": {
|
|
6
|
+
"filesystem": {
|
|
7
|
+
"read": ["/Applications/Firefox.app"],
|
|
8
|
+
"write": ["~/.local/state/ocean-firefox", "~/.cache/selenium"]
|
|
9
|
+
},
|
|
10
|
+
"network": [
|
|
11
|
+
"registry.npmjs.org",
|
|
12
|
+
"github.com",
|
|
13
|
+
"objects.githubusercontent.com",
|
|
14
|
+
"release-assets.githubusercontent.com",
|
|
15
|
+
"localhost",
|
|
16
|
+
"127.0.0.1"
|
|
17
|
+
],
|
|
18
|
+
"env": [
|
|
19
|
+
"OCEAN_FIREFOX_PROFILE",
|
|
20
|
+
"CONNECT_EXISTING",
|
|
21
|
+
"MARIONETTE_PORT",
|
|
22
|
+
"FIREFOX_HEADLESS",
|
|
23
|
+
"TOOL_PRESET"
|
|
24
|
+
],
|
|
25
|
+
"exec": ["npx"]
|
|
26
|
+
},
|
|
27
|
+
"server": {
|
|
28
|
+
"name": "dev.ocean/firefox-devtools",
|
|
29
|
+
"description": "Mozilla's Firefox MCP 0.11.0: drives Firefox over WebDriver BiDi and Marionette, in a separate profile unless told to attach to a running Firefox.",
|
|
30
|
+
"packages": [
|
|
31
|
+
{
|
|
32
|
+
"registryType": "npm",
|
|
33
|
+
"identifier": "@mozilla/firefox-mcp",
|
|
34
|
+
"version": "0.11.0",
|
|
35
|
+
"transport": { "type": "stdio" },
|
|
36
|
+
"packageArguments": [
|
|
37
|
+
{
|
|
38
|
+
"type": "named",
|
|
39
|
+
"name": "--profile-path",
|
|
40
|
+
"value": "{OCEAN_FIREFOX_PROFILE}",
|
|
41
|
+
"isRequired": false,
|
|
42
|
+
"description": "Folder for the dedicated Firefox profile; unset uses a fresh temporary one each run. Set with `ocean browser use firefox`."
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"environmentVariables": [
|
|
46
|
+
{
|
|
47
|
+
"name": "CONNECT_EXISTING",
|
|
48
|
+
"isRequired": false,
|
|
49
|
+
"description": "true attaches to a running Firefox started with --marionette --remote-debugging-port, instead of starting one."
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"name": "MARIONETTE_PORT",
|
|
53
|
+
"isRequired": false,
|
|
54
|
+
"description": "Marionette port of that running Firefox (default 2828)."
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "FIREFOX_HEADLESS",
|
|
58
|
+
"isRequired": false,
|
|
59
|
+
"description": "true starts Firefox without a window."
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "TOOL_PRESET",
|
|
63
|
+
"isRequired": false,
|
|
64
|
+
"description": "slim, basic (default), developer (debugging, network, console, profiler) or all."
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"_meta": { "dev.ocean": { "clientKey": "firefox-devtools" } }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -117,7 +117,9 @@ function lessonIdFor(signal) {
|
|
|
117
117
|
}
|
|
118
118
|
function activatedLessonIds(events) {
|
|
119
119
|
const ids = events
|
|
120
|
-
|
|
120
|
+
// `lesson_applied` since T-323; sessions recorded before it carry the old name.
|
|
121
|
+
.filter((event) => event.type === "lesson_applied" ||
|
|
122
|
+
event.type === "skill_auto_activated")
|
|
121
123
|
.map((event) => safeJsonParse(event.data)?.id)
|
|
122
124
|
.filter((id) => typeof id === "string");
|
|
123
125
|
return [...new Set(ids)];
|
|
@@ -100,8 +100,10 @@ export async function runAgent(request, deps) {
|
|
|
100
100
|
: { text: "", partial: false };
|
|
101
101
|
const skillIndex = await deps.loadSkillIndex(profile.skills, request.cwd);
|
|
102
102
|
const autoSkills = await deps.loadActiveLessons(request.prompt, PROMOTED_SKILL_MAX_BYTES);
|
|
103
|
+
// One `lesson_applied` per injected lesson (T-323; `skill_auto_activated` before), so a
|
|
104
|
+
// lesson's sessions can be compared with the ones that ran without it.
|
|
103
105
|
for (const skill of autoSkills) {
|
|
104
|
-
sessionStore.appendEvent(sessionId, "
|
|
106
|
+
sessionStore.appendEvent(sessionId, "lesson_applied", JSON.stringify({
|
|
105
107
|
id: skill.id,
|
|
106
108
|
name: skill.title,
|
|
107
109
|
sourceSessionId: skill.sourceSessionId ?? null,
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { mkdir, readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { setLessonStatus } from "@ocean/brain/memory/lessons.js";
|
|
4
|
+
import { atomicWrite, parseFrontmatter, withFileLock, } from "@ocean/core/shared/fs-utils.js";
|
|
5
|
+
import { localDate } from "@ocean/core/shared/local-date.js";
|
|
6
|
+
import { KNOWLEDGE_DIR, oceanPath } from "@ocean/core/shared/paths.js";
|
|
7
|
+
// Failure records (T-323): one markdown file per failure signature in 05-knowledge/failures/.
|
|
8
|
+
// A record states the mechanism, not the symptom, and carries a closed status
|
|
9
|
+
// open → fix-landing → absorbed → superseded-by <id>
|
|
10
|
+
// changed only by code, one field per update, with a line appended to its status log; the
|
|
11
|
+
// body above that log is never rewritten. A guardrail ladder (lesson → doctor → test) says
|
|
12
|
+
// how the failure is guarded: when an absorbed signature comes back, telemetry proposes
|
|
13
|
+
// climbing one rung and the owner approves with `ocean failures climb`.
|
|
14
|
+
export const RUNGS = ["lesson", "doctor", "test"];
|
|
15
|
+
// F4: absorb with the cheapest mechanism first, in this order.
|
|
16
|
+
export const ABSORB_MECHANISMS = [
|
|
17
|
+
"doctor",
|
|
18
|
+
"template",
|
|
19
|
+
"code",
|
|
20
|
+
"skill-edit",
|
|
21
|
+
"new-skill",
|
|
22
|
+
];
|
|
23
|
+
export class FailureRecordError extends Error {
|
|
24
|
+
}
|
|
25
|
+
const ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,80}$/;
|
|
26
|
+
const SIGNATURE_PATTERN = /^[a-z]+\/[A-Za-z_]+\/[0-9a-f]{8}$/;
|
|
27
|
+
const NEXT = {
|
|
28
|
+
open: ["fix-landing", "absorbed"],
|
|
29
|
+
"fix-landing": ["absorbed", "open"],
|
|
30
|
+
// Back to open only by climbing the ladder.
|
|
31
|
+
absorbed: [],
|
|
32
|
+
};
|
|
33
|
+
export const failuresDir = () => oceanPath(KNOWLEDGE_DIR, "failures");
|
|
34
|
+
const failureFile = (id) => path.join(failuresDir(), `${id}.md`);
|
|
35
|
+
function parse(source) {
|
|
36
|
+
const fields = parseFrontmatter(source);
|
|
37
|
+
// Records written before T-323 carry no signature; the tooling leaves them alone.
|
|
38
|
+
if (!fields.id || !SIGNATURE_PATTERN.test(fields.signature ?? ""))
|
|
39
|
+
return null;
|
|
40
|
+
const superseded = /^superseded-by\s+(\S+)$/.exec(fields.status ?? "");
|
|
41
|
+
const status = superseded ? "superseded" : fields.status;
|
|
42
|
+
if (!superseded && !(status in NEXT))
|
|
43
|
+
return null;
|
|
44
|
+
const rung = fields.rung;
|
|
45
|
+
if (!RUNGS.includes(rung))
|
|
46
|
+
return null;
|
|
47
|
+
const absorbedBy = (fields.absorbed_by || null);
|
|
48
|
+
if (absorbedBy && !ABSORB_MECHANISMS.includes(absorbedBy))
|
|
49
|
+
return null;
|
|
50
|
+
return {
|
|
51
|
+
id: fields.id,
|
|
52
|
+
title: fields.title ?? fields.id,
|
|
53
|
+
signature: fields.signature,
|
|
54
|
+
status,
|
|
55
|
+
supersededBy: superseded?.[1] ?? null,
|
|
56
|
+
rung,
|
|
57
|
+
mechanism: fields.mechanism ?? "",
|
|
58
|
+
absorbedBy,
|
|
59
|
+
absorbedAt: fields.absorbed_at || null,
|
|
60
|
+
lesson: fields.lesson || null,
|
|
61
|
+
created: fields.created ?? "",
|
|
62
|
+
updated: fields.updated ?? "",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export async function readFailure(id) {
|
|
66
|
+
if (!ID_PATTERN.test(id))
|
|
67
|
+
throw new FailureRecordError(`Invalid id: ${id}`);
|
|
68
|
+
const source = await readFile(failureFile(id), "utf8").catch(() => null);
|
|
69
|
+
return source === null ? null : parse(source);
|
|
70
|
+
}
|
|
71
|
+
export async function listFailures() {
|
|
72
|
+
const names = await readdir(failuresDir()).catch(() => []);
|
|
73
|
+
const records = [];
|
|
74
|
+
for (const name of names.filter((entry) => entry.endsWith(".md")).sort()) {
|
|
75
|
+
const source = await readFile(path.join(failuresDir(), name), "utf8");
|
|
76
|
+
const record = parse(source);
|
|
77
|
+
if (record)
|
|
78
|
+
records.push(record);
|
|
79
|
+
}
|
|
80
|
+
return records;
|
|
81
|
+
}
|
|
82
|
+
export async function openFailure(input, now = new Date()) {
|
|
83
|
+
const rung = input.rung ?? RUNGS[0];
|
|
84
|
+
if (!RUNGS.includes(rung))
|
|
85
|
+
throw new FailureRecordError(`Rung is one of ${RUNGS.join(" → ")}`);
|
|
86
|
+
if (!ID_PATTERN.test(input.id))
|
|
87
|
+
throw new FailureRecordError(`Invalid id: ${input.id}`);
|
|
88
|
+
if (!SIGNATURE_PATTERN.test(input.signature))
|
|
89
|
+
throw new FailureRecordError(`Invalid signature: ${input.signature} (expected <command>/<class>/<hash>, from ocean telemetry)`);
|
|
90
|
+
if (!input.mechanism.trim())
|
|
91
|
+
throw new FailureRecordError("A failure record states its mechanism: why it happens, not what was seen");
|
|
92
|
+
const owner = (await listFailures()).find((record) => record.signature === input.signature);
|
|
93
|
+
if (owner)
|
|
94
|
+
throw new FailureRecordError(`Signature ${input.signature} already has a record: ${owner.id}`);
|
|
95
|
+
const file = failureFile(input.id);
|
|
96
|
+
await mkdir(failuresDir(), { recursive: true });
|
|
97
|
+
return withFileLock(file, async () => {
|
|
98
|
+
if (await readFile(file, "utf8").catch(() => null))
|
|
99
|
+
throw new FailureRecordError(`Failure ${input.id} already exists`);
|
|
100
|
+
const head = [
|
|
101
|
+
`id: ${input.id}`,
|
|
102
|
+
"type: failure",
|
|
103
|
+
`title: ${JSON.stringify(input.title)}`,
|
|
104
|
+
`signature: ${input.signature}`,
|
|
105
|
+
"status: open",
|
|
106
|
+
`rung: ${rung}`,
|
|
107
|
+
`mechanism: ${JSON.stringify(input.mechanism.replace(/\s+/g, " ").trim())}`,
|
|
108
|
+
input.lesson ? `lesson: ${input.lesson}` : "",
|
|
109
|
+
`created: ${localDate(now)}`,
|
|
110
|
+
`updated: ${localDate(now)}`,
|
|
111
|
+
].filter(Boolean);
|
|
112
|
+
await atomicWrite(file, [
|
|
113
|
+
`---\n${head.join("\n")}\n---`,
|
|
114
|
+
`# ${input.title}`,
|
|
115
|
+
`## Mechanism\n\n${input.mechanism.trim()}`,
|
|
116
|
+
`## Fix\n\n${input.fix?.trim() || "Pending."}`,
|
|
117
|
+
`## Guardrail\n\n${input.guardrail?.trim() || "Pending."}`,
|
|
118
|
+
// Recurrence is not stored: `ocean failures` counts it from the sessions.
|
|
119
|
+
`## Status log\n\n- ${now.toISOString()} — open (rung ${rung})\n`,
|
|
120
|
+
].join("\n\n"));
|
|
121
|
+
const record = parse(await readFile(file, "utf8"));
|
|
122
|
+
if (!record)
|
|
123
|
+
throw new FailureRecordError(`Could not read back ${file}`);
|
|
124
|
+
return record;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
// One change per update: the given frontmatter fields are replaced in place, `updated` is
|
|
128
|
+
// stamped and one line is appended to the status log. Nothing else in the file moves.
|
|
129
|
+
async function amend(id, change, now) {
|
|
130
|
+
const file = failureFile(id);
|
|
131
|
+
return withFileLock(file, async () => {
|
|
132
|
+
const source = await readFile(file, "utf8").catch(() => null);
|
|
133
|
+
const record = source === null ? null : parse(source);
|
|
134
|
+
if (!source || !record)
|
|
135
|
+
throw new FailureRecordError(`No failure record: ${id}`);
|
|
136
|
+
const { fields, log } = change(record);
|
|
137
|
+
const end = source.indexOf("\n---", 3);
|
|
138
|
+
let head = source.slice(0, end);
|
|
139
|
+
for (const [key, value] of Object.entries({
|
|
140
|
+
...fields,
|
|
141
|
+
updated: localDate(now),
|
|
142
|
+
})) {
|
|
143
|
+
const line = new RegExp(`^${key}:.*$`, "m");
|
|
144
|
+
head = line.test(head)
|
|
145
|
+
? head.replace(line, `${key}: ${value}`)
|
|
146
|
+
: `${head}\n${key}: ${value}`;
|
|
147
|
+
}
|
|
148
|
+
const body = source.slice(end).replace(/\n*$/, "\n");
|
|
149
|
+
await atomicWrite(file, `${head}${body}- ${now.toISOString()} — ${log}\n`);
|
|
150
|
+
const updated = parse(await readFile(file, "utf8"));
|
|
151
|
+
if (!updated)
|
|
152
|
+
throw new FailureRecordError(`Could not read back ${file}`);
|
|
153
|
+
return updated;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
export async function setFailureStatus(id, next, options = {}) {
|
|
157
|
+
const now = options.now ?? new Date();
|
|
158
|
+
const record = await amend(id, (current) => {
|
|
159
|
+
if (current.status === "superseded")
|
|
160
|
+
throw new FailureRecordError(`${id} is superseded by ${current.supersededBy}; it no longer changes`);
|
|
161
|
+
const superseded = /^superseded-by\s+([a-z0-9][a-z0-9-]*)$/.exec(next);
|
|
162
|
+
if (superseded) {
|
|
163
|
+
if (superseded[1] === id)
|
|
164
|
+
throw new FailureRecordError("A record cannot supersede itself");
|
|
165
|
+
return { fields: { status: next }, log: next };
|
|
166
|
+
}
|
|
167
|
+
if (!NEXT[current.status].includes(next))
|
|
168
|
+
throw new FailureRecordError(`${id}: ${current.status} → ${next} is not allowed (${current.status} → ${NEXT[current.status].join(" | ") || "climb"})`);
|
|
169
|
+
if (next !== "absorbed")
|
|
170
|
+
return { fields: { status: next }, log: next };
|
|
171
|
+
const by = options.by;
|
|
172
|
+
if (!by || !ABSORB_MECHANISMS.includes(by))
|
|
173
|
+
throw new FailureRecordError(`Absorbing needs --by <mechanism>, cheapest first: ${ABSORB_MECHANISMS.join(" → ")}`);
|
|
174
|
+
return {
|
|
175
|
+
fields: {
|
|
176
|
+
status: "absorbed",
|
|
177
|
+
absorbed_by: by,
|
|
178
|
+
absorbed_at: now.toISOString(),
|
|
179
|
+
},
|
|
180
|
+
log: `absorbed by ${by}`,
|
|
181
|
+
};
|
|
182
|
+
}, now);
|
|
183
|
+
// An absorbed failure's lesson has done its job and leaves context.
|
|
184
|
+
if (record.status === "absorbed" && record.lesson)
|
|
185
|
+
await setLessonStatus(record.lesson, "retired").catch(() => undefined);
|
|
186
|
+
return record;
|
|
187
|
+
}
|
|
188
|
+
// The owner's approval of a proposed climb: one rung up, and the failure is open again.
|
|
189
|
+
export async function climbFailure(id, now = new Date()) {
|
|
190
|
+
return amend(id, (current) => {
|
|
191
|
+
if (current.status === "superseded")
|
|
192
|
+
throw new FailureRecordError(`${id} is superseded`);
|
|
193
|
+
const at = RUNGS.indexOf(current.rung);
|
|
194
|
+
const next = RUNGS[at + 1];
|
|
195
|
+
if (!next)
|
|
196
|
+
throw new FailureRecordError(`${id} is already on the top rung (${current.rung}); supersede it with a new record instead`);
|
|
197
|
+
return {
|
|
198
|
+
fields: { rung: next, status: "open", absorbed_at: "" },
|
|
199
|
+
log: `climbed ${current.rung} → ${next}; open`,
|
|
200
|
+
};
|
|
201
|
+
}, now);
|
|
202
|
+
}
|
|
203
|
+
// The Definition of done's bar: an absorbed failure clean this many days is driven to zero.
|
|
204
|
+
export const RECURRENCE_WINDOW_DAYS = 14;
|
|
205
|
+
export function failureRecurrence(records,
|
|
206
|
+
// Read over all history, so a recurrence long after absorption still counts.
|
|
207
|
+
stats, now = new Date(), windowDays = RECURRENCE_WINDOW_DAYS) {
|
|
208
|
+
const windowMs = windowDays * 86_400_000;
|
|
209
|
+
return records.map((record) => {
|
|
210
|
+
const seen = stats.get(record.signature);
|
|
211
|
+
const absorbedAt = record.absorbedAt;
|
|
212
|
+
const sinceAbsorbed = absorbedAt
|
|
213
|
+
? new Set((seen?.hits ?? [])
|
|
214
|
+
.filter((hit) => hit.at > absorbedAt)
|
|
215
|
+
.map((hit) => hit.sessionId)).size
|
|
216
|
+
: 0;
|
|
217
|
+
const lastSeen = seen?.lastSeen ?? null;
|
|
218
|
+
const anchor = record.status === "absorbed" && record.absorbedAt
|
|
219
|
+
? [record.absorbedAt, lastSeen ?? ""].sort().at(-1)
|
|
220
|
+
: null;
|
|
221
|
+
return {
|
|
222
|
+
id: record.id,
|
|
223
|
+
signature: record.signature,
|
|
224
|
+
status: record.status,
|
|
225
|
+
rung: record.rung,
|
|
226
|
+
recent: new Set((seen?.hits ?? [])
|
|
227
|
+
.filter((hit) => Date.parse(hit.at) >= now.getTime() - windowMs)
|
|
228
|
+
.map((hit) => hit.sessionId)).size,
|
|
229
|
+
sinceAbsorbed,
|
|
230
|
+
lastSeen,
|
|
231
|
+
cleanDays: anchor
|
|
232
|
+
? Math.floor((now.getTime() - Date.parse(anchor)) / 86_400_000)
|
|
233
|
+
: null,
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
// Telemetry's ladder proposals: an absorbed failure whose signature came back.
|
|
238
|
+
export function ladderFindings(recurrence) {
|
|
239
|
+
return recurrence
|
|
240
|
+
.filter((entry) => entry.status === "absorbed" && entry.sinceAbsorbed > 0)
|
|
241
|
+
.map((entry) => {
|
|
242
|
+
const next = RUNGS[RUNGS.indexOf(entry.rung) + 1];
|
|
243
|
+
return {
|
|
244
|
+
line: next
|
|
245
|
+
? `Failure ${entry.id} came back in ${entry.sinceAbsorbed} sessions after it was absorbed: climb its guardrail ${entry.rung} → ${next} with \`ocean failures climb ${entry.id}\``
|
|
246
|
+
: `Failure ${entry.id} came back in ${entry.sinceAbsorbed} sessions after it was absorbed, on the top rung (${entry.rung}): supersede it with a new record`,
|
|
247
|
+
sessions: entry.sinceAbsorbed,
|
|
248
|
+
signature: entry.signature,
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=failures.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { scoreSession } from "@ocean/brain/memory/lesson-learning.js";
|
|
2
|
+
import { safeJsonParse } from "@ocean/core/shared/fs-utils.js";
|
|
3
|
+
import { failureSignature } from "./telemetry.js";
|
|
4
|
+
// Does a lesson help? (T-323, ACE): every injected lesson leaves a `lesson_applied` event, so the
|
|
5
|
+
// sessions that had it can be compared with comparable sessions that did not — on verified rate,
|
|
6
|
+
// and, for a lesson tied to a failure record, on how often that failure's signature appeared.
|
|
7
|
+
// A lesson that does no better on either, with enough sessions on both sides, is proposed for
|
|
8
|
+
// retirement; nothing is retired without the owner.
|
|
9
|
+
// `skill_auto_activated` is the same event under its name before T-323.
|
|
10
|
+
export const LESSON_APPLIED_TYPES = new Set([
|
|
11
|
+
"lesson_applied",
|
|
12
|
+
"skill_auto_activated",
|
|
13
|
+
]);
|
|
14
|
+
// Lessons are only ever injected into runs that assembled context; others are not comparable.
|
|
15
|
+
const COMPARABLE_EVENT = "context_manifest";
|
|
16
|
+
export const MIN_SAMPLE = 5;
|
|
17
|
+
export function appliedLessonIds(events) {
|
|
18
|
+
const ids = events
|
|
19
|
+
.filter((event) => LESSON_APPLIED_TYPES.has(event.type))
|
|
20
|
+
.map((event) => safeJsonParse(event.data)?.id)
|
|
21
|
+
.filter((id) => typeof id === "string");
|
|
22
|
+
return [...new Set(ids)];
|
|
23
|
+
}
|
|
24
|
+
const rate = (n, of) => (of ? n / of : 0);
|
|
25
|
+
export function lessonEffects(sessions, eventsOf, sinceIso, failures = []) {
|
|
26
|
+
const runs = sessions
|
|
27
|
+
.filter((session) => session.createdAt >= sinceIso)
|
|
28
|
+
.map((session) => {
|
|
29
|
+
const events = eventsOf(session.sessionId);
|
|
30
|
+
return { session, events };
|
|
31
|
+
})
|
|
32
|
+
.filter(({ events }) => events.some((e) => e.type === COMPARABLE_EVENT))
|
|
33
|
+
.map(({ session, events }) => ({
|
|
34
|
+
verified: scoreSession(session, events).verified,
|
|
35
|
+
applied: new Set(appliedLessonIds(events)),
|
|
36
|
+
signatures: new Set(events
|
|
37
|
+
.map((event) => failureSignature(event.type, event.data))
|
|
38
|
+
.filter((signature) => signature !== null)),
|
|
39
|
+
}));
|
|
40
|
+
const lessons = new Set(runs.flatMap((run) => [...run.applied]));
|
|
41
|
+
return [...lessons].sort().map((lesson) => {
|
|
42
|
+
const failure = failures.find((record) => record.lesson === lesson) ?? null;
|
|
43
|
+
const sides = { with: blank(), without: blank() };
|
|
44
|
+
for (const run of runs) {
|
|
45
|
+
const side = run.applied.has(lesson) ? sides.with : sides.without;
|
|
46
|
+
side.sessions++;
|
|
47
|
+
if (run.verified)
|
|
48
|
+
side.verified++;
|
|
49
|
+
if (failure && run.signatures.has(failure.signature))
|
|
50
|
+
side.recurred++;
|
|
51
|
+
}
|
|
52
|
+
const enough = sides.with.sessions >= MIN_SAMPLE && sides.without.sessions >= MIN_SAMPLE;
|
|
53
|
+
const betterVerified = rate(sides.with.verified, sides.with.sessions) >
|
|
54
|
+
rate(sides.without.verified, sides.without.sessions);
|
|
55
|
+
const fewerRecurrences = failure !== null &&
|
|
56
|
+
rate(sides.with.recurred, sides.with.sessions) <
|
|
57
|
+
rate(sides.without.recurred, sides.without.sessions);
|
|
58
|
+
return {
|
|
59
|
+
lesson,
|
|
60
|
+
...sides,
|
|
61
|
+
failure: failure?.id ?? null,
|
|
62
|
+
verdict: !enough
|
|
63
|
+
? "too-few"
|
|
64
|
+
: betterVerified || fewerRecurrences
|
|
65
|
+
? "helps"
|
|
66
|
+
: "no-better",
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const blank = () => ({ sessions: 0, verified: 0, recurred: 0 });
|
|
71
|
+
export function retirementFindings(effects) {
|
|
72
|
+
return effects
|
|
73
|
+
.filter((effect) => effect.verdict === "no-better")
|
|
74
|
+
.map((effect) => ({
|
|
75
|
+
line: `Lesson ${effect.lesson} does no better than without it (verified ${effect.with.verified}/${effect.with.sessions} vs ${effect.without.verified}/${effect.without.sessions}${effect.failure ? `; ${effect.failure} recurred ${effect.with.recurred}/${effect.with.sessions} vs ${effect.without.recurred}/${effect.without.sessions}` : ""}): retire it with \`ocean skill review ${effect.lesson} rejected\``,
|
|
76
|
+
sessions: effect.with.sessions,
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=lesson-effect.js.map
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { proposeMemory } from "@ocean/brain/memory/memory-write.js";
|
|
2
3
|
import { MemoryContractError } from "@ocean/core/domain/mcp/memory-contract.js";
|
|
3
4
|
// Session telemetry (T-314): what keeps going wrong in Ocean's own sessions becomes a proposed
|
|
4
5
|
// backlog line for the owner — never a task, never applied without review. Read from the session
|
|
5
6
|
// store: an error seen in at least MIN_REPEATS sessions, and providers whose sessions fail or are
|
|
6
|
-
// left unfinished.
|
|
7
|
+
// left unfinished. T-323 names each error by a signature so a failure record can track it.
|
|
7
8
|
const MIN_REPEATS = 3;
|
|
8
9
|
const STUCK_AFTER_MS = 6 * 60 * 60 * 1000;
|
|
9
|
-
|
|
10
|
+
// The event type says which step failed; the signature names that step.
|
|
11
|
+
const COMMAND_OF = {
|
|
12
|
+
error: "run",
|
|
13
|
+
provider_blocked: "provider",
|
|
14
|
+
closeout_warning: "closeout",
|
|
15
|
+
};
|
|
16
|
+
export const isFailureEvent = (type) => type in COMMAND_OF;
|
|
10
17
|
// The same failure with different ids, paths or numbers counts as one.
|
|
11
18
|
export function errorShape(text) {
|
|
12
19
|
return text
|
|
@@ -17,26 +24,63 @@ export function errorShape(text) {
|
|
|
17
24
|
.trim()
|
|
18
25
|
.slice(0, 120);
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
// What kind of error, without the message: a zod issue code, a Node errno, or an Error's name.
|
|
28
|
+
export function errorClass(text) {
|
|
29
|
+
return (/"code"\s*:\s*"([a-z_]+)"/.exec(text)?.[1] ??
|
|
30
|
+
/\b(E[A-Z]{3,})\b/.exec(text)?.[1] ??
|
|
31
|
+
/\b([A-Z][A-Za-z]*Error)\b/.exec(text)?.[1] ??
|
|
32
|
+
"error");
|
|
33
|
+
}
|
|
34
|
+
// `<command>/<error class>/<hash of the shape>`: stable across ids, paths and numbers, short
|
|
35
|
+
// enough to name a failure record by.
|
|
36
|
+
export function failureSignature(eventType, text) {
|
|
37
|
+
const command = COMMAND_OF[eventType];
|
|
38
|
+
const shape = errorShape(text);
|
|
39
|
+
if (!command || !shape)
|
|
40
|
+
return null;
|
|
41
|
+
const hash = createHash("sha256").update(shape).digest("hex").slice(0, 8);
|
|
42
|
+
return `${command}/${errorClass(text)}/${hash}`;
|
|
43
|
+
}
|
|
44
|
+
// Every signature seen since `sinceIso`, with the sessions it appeared in, however rare.
|
|
45
|
+
export function signatureStats(sessions, eventsOf, sinceIso) {
|
|
46
|
+
const stats = new Map();
|
|
47
|
+
for (const session of sessions) {
|
|
48
|
+
if (session.createdAt < sinceIso)
|
|
49
|
+
continue;
|
|
24
50
|
for (const event of eventsOf(session.sessionId)) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const shape = errorShape(event.data);
|
|
28
|
-
if (!shape)
|
|
51
|
+
const signature = failureSignature(event.type, event.data);
|
|
52
|
+
if (!signature)
|
|
29
53
|
continue;
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
54
|
+
const at = event.createdAt ?? session.createdAt;
|
|
55
|
+
const entry = stats.get(signature) ?? {
|
|
56
|
+
shape: errorShape(event.data),
|
|
57
|
+
sessions: new Set(),
|
|
58
|
+
hits: [],
|
|
59
|
+
firstSeen: at,
|
|
60
|
+
lastSeen: at,
|
|
61
|
+
};
|
|
62
|
+
entry.sessions.add(session.sessionId);
|
|
63
|
+
entry.hits.push({ sessionId: session.sessionId, at });
|
|
64
|
+
if (at < entry.firstSeen)
|
|
65
|
+
entry.firstSeen = at;
|
|
66
|
+
if (at > entry.lastSeen)
|
|
67
|
+
entry.lastSeen = at;
|
|
68
|
+
stats.set(signature, entry);
|
|
33
69
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
70
|
+
}
|
|
71
|
+
return stats;
|
|
72
|
+
}
|
|
73
|
+
export function analyzeSessions(sessions, eventsOf, sinceIso, now = Date.now()) {
|
|
74
|
+
const recent = sessions.filter((session) => session.createdAt >= sinceIso);
|
|
75
|
+
const findings = [
|
|
76
|
+
...signatureStats(recent, eventsOf, sinceIso),
|
|
77
|
+
]
|
|
78
|
+
.filter(([, stats]) => stats.sessions.size >= MIN_REPEATS)
|
|
79
|
+
.sort((a, b) => b[1].sessions.size - a[1].sessions.size)
|
|
80
|
+
.map(([signature, stats]) => ({
|
|
81
|
+
line: `Recurring error in ${stats.sessions.size} sessions [${signature}]: ${stats.shape}`,
|
|
82
|
+
sessions: stats.sessions.size,
|
|
83
|
+
signature,
|
|
40
84
|
}));
|
|
41
85
|
const byProvider = new Map();
|
|
42
86
|
for (const session of recent) {
|
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { atomicWrite, parseFrontmatter } from "@ocean/core/shared/fs-utils.js";
|
|
4
4
|
import { DAILY_DIR, KNOWLEDGE_DIR, listProjectDirs, oceanPath, SYSTEM_DIR, } from "@ocean/core/shared/paths.js";
|
|
5
5
|
import { sessionTokens } from "@ocean/loop/runs/session-tokens.js";
|
|
6
|
+
import { RECURRENCE_WINDOW_DAYS, } from "../journey/failures.js";
|
|
6
7
|
// Moved to the loop package (T-322) so run guards can count tokens; re-exported for callers.
|
|
7
8
|
export { sessionTokens };
|
|
8
9
|
const percent = (n, of) => of ? `${Math.round((n / of) * 1000) / 10}%` : "n/a";
|
|
@@ -129,10 +130,10 @@ export function schedulesRow(schedules) {
|
|
|
129
130
|
source: "ocean schedule list",
|
|
130
131
|
};
|
|
131
132
|
}
|
|
132
|
-
// "Used"
|
|
133
|
-
export function lessonsRows(lessons) {
|
|
133
|
+
// "Used" counts lessons injected into at least one run (`lesson_applied`, T-323).
|
|
134
|
+
export function lessonsRows(lessons, applied = []) {
|
|
134
135
|
const active = lessons.filter((fields) => fields.status === "active").length;
|
|
135
|
-
const
|
|
136
|
+
const used = new Set(applied);
|
|
136
137
|
return [
|
|
137
138
|
{
|
|
138
139
|
id: "lessons-active",
|
|
@@ -142,9 +143,30 @@ export function lessonsRows(lessons) {
|
|
|
142
143
|
of: lessons.length,
|
|
143
144
|
source: "05-knowledge/lessons status",
|
|
144
145
|
},
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
ratio("lessons-used", "Lessons used", lessons.filter((fields) => used.has(fields.id)).length, lessons.length, "lesson_applied events"),
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
// Recurrence per failure signature (T-323): one summary row, then one row per failure record.
|
|
150
|
+
export function failuresRows(failures) {
|
|
151
|
+
const zero = failures.filter((entry) => entry.status === "absorbed" &&
|
|
152
|
+
entry.recent === 0 &&
|
|
153
|
+
(entry.cleanDays ?? 0) >= RECURRENCE_WINDOW_DAYS).length;
|
|
154
|
+
return [
|
|
155
|
+
{
|
|
156
|
+
id: "failures-zero",
|
|
157
|
+
label: `Failures at zero ${RECURRENCE_WINDOW_DAYS}+ days`,
|
|
158
|
+
value: `${zero} of ${failures.length}`,
|
|
159
|
+
n: zero,
|
|
160
|
+
of: failures.length,
|
|
161
|
+
source: "05-knowledge/failures + session signatures",
|
|
162
|
+
},
|
|
163
|
+
...failures.map((entry) => ({
|
|
164
|
+
id: `failure:${entry.id}`,
|
|
165
|
+
label: ` ${entry.id}`,
|
|
166
|
+
value: `${entry.status}, rung ${entry.rung}: ${entry.recent} sessions in ${RECURRENCE_WINDOW_DAYS} d${entry.cleanDays === null ? "" : `, clean ${entry.cleanDays} d`}`,
|
|
167
|
+
n: entry.recent,
|
|
168
|
+
source: `signature ${entry.signature}`,
|
|
169
|
+
})),
|
|
148
170
|
];
|
|
149
171
|
}
|
|
150
172
|
export function tokensRow(tokens) {
|
|
@@ -194,7 +216,8 @@ export function scorecardRows(input) {
|
|
|
194
216
|
tasksVerifiedRow(input.tasks),
|
|
195
217
|
...searchRows(input.search, input.searchEval),
|
|
196
218
|
schedulesRow(input.schedules),
|
|
197
|
-
...lessonsRows(input.lessons),
|
|
219
|
+
...lessonsRows(input.lessons, input.lessonsApplied),
|
|
220
|
+
...failuresRows(input.failures),
|
|
198
221
|
tokensRow(input.tokens),
|
|
199
222
|
hygieneRow(input.hygiene),
|
|
200
223
|
driftRow(input.drift),
|