@amoree-code/ocean 2.7.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/infrastructure/providers/task-reviewer.js +35 -0
  2. package/dist/interfaces/cli/help-command.js +1 -1
  3. package/dist/interfaces/cli/memory-command.js +36 -10
  4. package/dist/interfaces/cli/operate-command.js +2 -0
  5. package/dist/interfaces/cli/tasks-command.js +18 -3
  6. package/node_modules/@ocean/brain/dist/brain/brain-eval.js +45 -9
  7. package/node_modules/@ocean/brain/dist/brain/brain-markdown.js +10 -1
  8. package/node_modules/@ocean/brain/dist/brain/brain-reindex.js +4 -1
  9. package/node_modules/@ocean/brain/dist/brain/brain-service.js +69 -8
  10. package/node_modules/@ocean/brain/dist/infrastructure/brain/brain-index.js +5 -3
  11. package/node_modules/@ocean/brain/dist/memory/lesson-learning.js +35 -3
  12. package/node_modules/@ocean/brain/dist/memory/session-promotion.js +2 -1
  13. package/node_modules/@ocean/brain/package.json +1 -1
  14. package/node_modules/@ocean/context/package.json +1 -1
  15. package/node_modules/@ocean/core/dist/domain/ports/brain-index-port.js +3 -2
  16. package/node_modules/@ocean/core/package.json +1 -1
  17. package/node_modules/@ocean/loop/dist/infrastructure/persistence/session-store.js +15 -0
  18. package/node_modules/@ocean/loop/dist/operations/task-operations.js +6 -1
  19. package/node_modules/@ocean/loop/dist/tasks/archive-tasks.js +11 -9
  20. package/node_modules/@ocean/loop/dist/tasks/claim-task.js +11 -3
  21. package/node_modules/@ocean/loop/dist/tasks/task-git.js +28 -0
  22. package/node_modules/@ocean/loop/dist/tasks/task-verification.js +302 -0
  23. package/node_modules/@ocean/loop/dist/tasks/verify-task.js +69 -21
  24. package/node_modules/@ocean/loop/package.json +1 -1
  25. package/node_modules/@ocean/market/package.json +1 -1
  26. package/node_modules/@ocean/services/dist/infrastructure/mcp/ocean-server.js +18 -0
  27. package/node_modules/@ocean/services/package.json +1 -1
  28. package/ocean-marketplace.json +34 -34
  29. package/package.json +7 -7
  30. package/templates/workspace/charter/policies/contracts/task.md +44 -1
  31. package/templates/workspace/charter/policies/task.md +5 -1
@@ -2,7 +2,7 @@ import { access, mkdir, readdir, readFile, rename, rmdir, writeFile, } from "nod
2
2
  import path from "node:path";
3
3
  import { resolveWithin, WORKSPACE_PROJECT_ID, workspaceTasksRoot, } from "@ocean/core/shared/paths.js";
4
4
  import { projectArchiveName, WORKSPACE_ARCHIVE_NAMESPACE, } from "@ocean/core/shared/task-reference.js";
5
- import { verifyTask } from "./verify-task.js";
5
+ import { verifyTask, } from "./verify-task.js";
6
6
  const field = (source, name) => source
7
7
  .match(new RegExp(`^${name}:\\s*(.+)$`, "m"))?.[1]
8
8
  ?.trim()
@@ -76,22 +76,24 @@ export async function completeTask(id, root = workspaceTasksRoot(), options = {}
76
76
  const issues = completionIssues(source);
77
77
  if (issues.length)
78
78
  throw new Error(`Cannot complete ${id}: ${issues.join("; ")}`);
79
- const outcome = await verifyTask(id, root, {
80
- cwd: options.cwd,
81
- run: options.run,
82
- });
79
+ const outcome = options.verify
80
+ ? await options.verify(id, root)
81
+ : await verifyTask(id, root, { cwd: options.cwd, run: options.run });
83
82
  if (!outcome.passed)
84
83
  throw new Error(`Cannot complete ${id}: ${outcome.reason}`);
85
- if (field(source, "state") !== "done")
86
- await writeFile(taskFile, setState(source, "done"));
84
+ // Re-read: a recording verifier has just written the verdict into the file.
85
+ const verifiedSource = await readFile(taskFile, "utf8");
86
+ if (field(verifiedSource, "state") !== "done")
87
+ await writeFile(taskFile, setState(verifiedSource, "done"));
87
88
  const archived = await archiveDoneTasks(root, true, {
88
- ...options,
89
+ cwd: options.cwd,
90
+ run: options.run,
89
91
  verified: new Set([id]),
90
92
  only: new Set([id]),
91
93
  });
92
94
  const skipped = archived.skipped.find((entry) => entry.id === id);
93
95
  if (skipped) {
94
- await writeFile(taskFile, source, "utf8");
96
+ await writeFile(taskFile, verifiedSource, "utf8");
95
97
  throw new Error(`Cannot complete ${id}: ${skipped.reason}`);
96
98
  }
97
99
  return { id, state: "done", ...archived };
@@ -1,6 +1,7 @@
1
1
  import { readdir, readFile, writeFile } from "node:fs/promises";
2
2
  import { localDate } from "@ocean/core/shared/local-date.js";
3
- import { resolveWithin } from "@ocean/core/shared/paths.js";
3
+ import { oceanRoot, resolveWithin } from "@ocean/core/shared/paths.js";
4
+ import { headCommit } from "./task-git.js";
4
5
  // Keep equal to CLAIM_TTL_MS in scripts/validate-tasks.mjs (a test pins the two together).
5
6
  export const CLAIM_TTL_MS = 2 * 60 * 60 * 1000;
6
7
  const OWNER = /^[\w.@/-]{1,64}$/;
@@ -41,7 +42,7 @@ export function isStale(claim, now = new Date()) {
41
42
  const STARTS_ON_CLAIM = new Set(["todo", "paused"]);
42
43
  // Replace the claim lines in the frontmatter (and bump `updated`), keeping every other line.
43
44
  // Claiming also moves a `todo`/`paused` task to `active`; releasing leaves the state alone.
44
- function withClaim(source, claim, today) {
45
+ function withClaim(source, claim, today, baseCommit = null) {
45
46
  const end = source.indexOf("\n---", 4);
46
47
  const kept = source
47
48
  .slice(4, end)
@@ -59,6 +60,10 @@ function withClaim(source, claim, today) {
59
60
  if (claim.paths.length)
60
61
  kept.push(`claimed_paths: [${claim.paths.join(", ")}]`);
61
62
  }
63
+ // Sticky: written by the first claim only, and kept through release and re-claim, so
64
+ // `tasks verify` can tell whether the claimed paths changed at all since work began.
65
+ if (baseCommit && !kept.some((line) => /^base_commit:/.test(line)))
66
+ kept.push(`base_commit: ${baseCommit}`);
62
67
  return `---\n${kept.join("\n")}${source.slice(end)}`;
63
68
  }
64
69
  async function liveClaimsElsewhere(root, id, now) {
@@ -108,7 +113,10 @@ export async function claimTask(id, root, input) {
108
113
  throw new Error(`${clash} overlaps ${other.claim.paths.join(", ")} claimed by ${other.claim.by} on ${other.id}.`);
109
114
  }
110
115
  const claim = { by: input.by, at: now.toISOString(), paths };
111
- await writeFile(taskFile, withClaim(source, claim, localDate(now)), "utf8");
116
+ const baseCommit = fields.base_commit
117
+ ? null
118
+ : await (input.head ?? (() => headCommit(oceanRoot())))();
119
+ await writeFile(taskFile, withClaim(source, claim, localDate(now), baseCommit), "utf8");
112
120
  // Read-modify-write is not atomic: if a concurrent claim landed between our read and write,
113
121
  // the file now names someone else. Re-read so the loser finds out instead of assuming it won.
114
122
  const written = parseClaim(frontmatterFields(await readFile(taskFile, "utf8")));
@@ -0,0 +1,28 @@
1
+ import { execFile as execFileCallback } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ const execFile = promisify(execFileCallback);
4
+ // The commit checked out at `cwd`, or null outside a repository (T-320 F1).
5
+ export async function headCommit(cwd) {
6
+ try {
7
+ const { stdout } = await execFile("git", ["rev-parse", "HEAD"], { cwd });
8
+ return stdout.trim() || null;
9
+ }
10
+ catch {
11
+ return null;
12
+ }
13
+ }
14
+ // Whether anything under `paths` differs from `base`: committed since, staged, unstaged or
15
+ // untracked. null when git cannot answer (no repository, unknown commit).
16
+ export async function changedSince(cwd, base, paths) {
17
+ try {
18
+ const { stdout: diff } = await execFile("git", ["diff", "--name-only", base, "--", ...paths], { cwd, maxBuffer: 16 * 1024 * 1024 });
19
+ if (diff.trim())
20
+ return true;
21
+ const { stdout: untracked } = await execFile("git", ["ls-files", "--others", "--exclude-standard", "--", ...paths], { cwd, maxBuffer: 16 * 1024 * 1024 });
22
+ return Boolean(untracked.trim());
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ //# sourceMappingURL=task-git.js.map
@@ -0,0 +1,302 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { readFile, writeFile } from "node:fs/promises";
3
+ import { parseFrontmatter } from "@ocean/core/shared/fs-utils.js";
4
+ import { localDate } from "@ocean/core/shared/local-date.js";
5
+ import { oceanRoot, projectOfTasksRoot, repoRoot, resolveWithin, } from "@ocean/core/shared/paths.js";
6
+ import { changedSince } from "./task-git.js";
7
+ import { verifyTask, } from "./verify-task.js";
8
+ const VERIFY_PROFILE = "tasks-verify";
9
+ const REVIEW_LANE_CLASSES = new Set(["high", "large"]);
10
+ function inlineList(value) {
11
+ const inner = value?.match(/^\[(.*)\]$/)?.[1] ?? "";
12
+ return inner
13
+ .split(",")
14
+ .map((item) => item.trim().replace(/^['"]|['"]$/g, ""))
15
+ .filter(Boolean);
16
+ }
17
+ function section(source, heading) {
18
+ const header = new RegExp(`^## ${heading}[ \\t]*\\r?$`, "m").exec(source);
19
+ if (!header)
20
+ return "";
21
+ const start = source.indexOf("\n", header.index) + 1;
22
+ const next = /^## /m.exec(source.slice(start));
23
+ return source.slice(start, next ? start + next.index : source.length);
24
+ }
25
+ // `AC-n` ids named by the Definition of done (C3), in order of first appearance.
26
+ export function acceptanceIds(source) {
27
+ const ids = [
28
+ ...section(source, "Definition of done").matchAll(/\bAC-\d+\b/gi),
29
+ ].map((match) => match[0].toUpperCase());
30
+ return [...new Set(ids)];
31
+ }
32
+ // The review's verdict is its last non-empty line: `pass`, or `fail — <reason>`.
33
+ export function parseReviewVerdict(answer) {
34
+ const line = answer
35
+ ?.split("\n")
36
+ .map((entry) => entry.trim().replace(/^[`*]+|[`*]+$/g, ""))
37
+ .filter(Boolean)
38
+ .at(-1);
39
+ if (!line)
40
+ return null;
41
+ if (/^pass\b/i.test(line))
42
+ return { passed: true, line };
43
+ if (/^fail\b/i.test(line))
44
+ return { passed: false, line };
45
+ return null;
46
+ }
47
+ function reviewPrompt(id, source, outcome) {
48
+ return [
49
+ `You are a read-only verifier for task ${id}. Do not edit, fix or run anything that changes state.`,
50
+ "Check only one thing: every claimed item (each checked box `[x]` in Scope and Definition of done) points to evidence — a passing check listed below, a commit, a file path that exists, or an event id. An item claimed with no evidence fails the review.",
51
+ "Deterministic checks already ran; their result is below. Do not repeat them.",
52
+ "",
53
+ "## Deterministic result",
54
+ JSON.stringify({
55
+ passed: outcome.passed,
56
+ reason: outcome.reason,
57
+ checks: outcome.checks,
58
+ }, null, 2),
59
+ "",
60
+ "## Task file",
61
+ source,
62
+ "",
63
+ "End your answer with exactly one line: `pass` or `fail — <reason>`.",
64
+ ].join("\n");
65
+ }
66
+ // Replace (or add) frontmatter fields, keeping every other line. A block-list value under a
67
+ // replaced key (`key:` then indented `- item` lines) is replaced with it.
68
+ export function setFrontmatterFields(source, fields) {
69
+ const end = source.indexOf("\n---", 4);
70
+ if (!source.startsWith("---\n") || end < 0)
71
+ return source;
72
+ const lines = source.slice(4, end).split("\n");
73
+ const kept = [];
74
+ const seen = new Set();
75
+ let skippingList = false;
76
+ for (const line of lines) {
77
+ if (skippingList && /^\s+-\s/.test(line))
78
+ continue;
79
+ skippingList = false;
80
+ const key = line.match(/^([\w-]+):/)?.[1];
81
+ if (key && key in fields) {
82
+ kept.push(`${key}: ${fields[key]}`);
83
+ seen.add(key);
84
+ skippingList = true;
85
+ continue;
86
+ }
87
+ kept.push(line);
88
+ }
89
+ for (const [key, value] of Object.entries(fields))
90
+ if (!seen.has(key))
91
+ kept.push(`${key}: ${value}`);
92
+ return `---\n${kept.join("\n")}${source.slice(end)}`;
93
+ }
94
+ // Frontmatter lists are inline; an item never carries a comma or a bracket.
95
+ const listItem = (text) => text.replace(/[,[\]]/g, ";");
96
+ /**
97
+ * Run a task's declared checks with no model, decide `verified`, and record it: one evidence
98
+ * event per check in a `tasks-verify` session linked to the task (copied to every session
99
+ * already linked to it, whose `verification_status` follows), and `verified`, `verified_at`,
100
+ * `evidence` (event ids) and `assumed` in the task's frontmatter.
101
+ */
102
+ export async function verifyAndRecord(id, root, options = {}) {
103
+ const now = options.now ?? new Date();
104
+ const taskFile = resolveWithin(root, id, "task.md");
105
+ const source = await readFile(taskFile, "utf8");
106
+ const fields = parseFrontmatter(source);
107
+ const outcome = await verifyTask(id, root, {
108
+ cwd: options.cwd,
109
+ run: options.run,
110
+ });
111
+ let passed = outcome.passed;
112
+ let reason = outcome.reason;
113
+ const assumed = new Set(inlineList(fields.assumed));
114
+ // F1: work that changed nothing under its claimed paths is not done, whatever the checks say.
115
+ let change = null;
116
+ const paths = inlineList(fields.claimed_paths);
117
+ if (fields.base_commit && paths.length) {
118
+ const changed = await (options.changed ?? ((base, list) => changedSince(oceanRoot(), base, list)))(fields.base_commit, paths);
119
+ change = { base: fields.base_commit, paths, changed };
120
+ if (changed === false) {
121
+ passed = false;
122
+ reason = `no change in ${paths.join(", ")} since base commit ${fields.base_commit.slice(0, 12)}`;
123
+ }
124
+ else if (changed === null)
125
+ assumed.add(listItem(`claimed paths changed since ${fields.base_commit.slice(0, 12)} (git could not tell)`));
126
+ }
127
+ // C3: each acceptance criterion needs a passing check of its own.
128
+ const acceptance = acceptanceIds(source).map((ac) => {
129
+ const checks = outcome.checks.filter((check) => check.ac === ac);
130
+ return { id: ac, ok: checks.length ? checks.every((c) => c.ok) : null };
131
+ });
132
+ const uncovered = acceptance.filter((entry) => entry.ok === null);
133
+ let verified = !passed
134
+ ? "no"
135
+ : uncovered.length
136
+ ? "partial"
137
+ : "yes";
138
+ if (uncovered.length && passed)
139
+ reason = `${reason}; no check for ${uncovered.map((entry) => entry.id).join(", ")}`;
140
+ // F2 + C3 lane: class high asks for a review; it runs only when the owner opts in per task
141
+ // (`review: agent`), after the deterministic checks, and never when they already failed.
142
+ const taskClass = (fields.class ?? "").toLowerCase();
143
+ const lane = REVIEW_LANE_CLASSES.has(taskClass)
144
+ ? "verify+review"
145
+ : "verify";
146
+ const optedIn = (fields.review ?? "").toLowerCase() === "agent";
147
+ const review = { ran: false };
148
+ const records = [];
149
+ if (optedIn && verified !== "no") {
150
+ const reviewer = options.reviewer?.() ?? null;
151
+ const answer = reviewer
152
+ ? await reviewer(reviewPrompt(id, source, outcome)).catch(() => null)
153
+ : null;
154
+ const verdict = parseReviewVerdict(answer);
155
+ if (!verdict) {
156
+ review.skipped = reviewer
157
+ ? "the review gave no pass or fail line"
158
+ : "no reviewer is available";
159
+ verified = "partial";
160
+ assumed.add(listItem(`independent review did not run: ${review.skipped}`));
161
+ }
162
+ else {
163
+ review.ran = true;
164
+ review.passed = verdict.passed;
165
+ review.line = verdict.line;
166
+ records.push({
167
+ criterion: "review",
168
+ result: verdict.passed ? "proven" : "not_proven",
169
+ type: "task_review",
170
+ payload: { line: verdict.line },
171
+ });
172
+ if (!verdict.passed) {
173
+ verified = "no";
174
+ passed = false;
175
+ reason = `review: ${verdict.line}`;
176
+ }
177
+ }
178
+ }
179
+ else if (optedIn)
180
+ review.skipped = "deterministic checks failed";
181
+ else if (lane === "verify+review") {
182
+ review.skipped = "review: agent not set";
183
+ assumed.add(listItem(`independent review not run (class ${taskClass}; set review: agent to run it)`));
184
+ }
185
+ outcome.checks.forEach((check, index) => {
186
+ records.push({
187
+ criterion: check.ac ?? `check-${index + 1}`,
188
+ result: check.ok ? "proven" : "not_proven",
189
+ type: "task_verify",
190
+ payload: { command: check.command, exitCode: check.exitCode },
191
+ });
192
+ });
193
+ for (const entry of uncovered)
194
+ records.push({
195
+ criterion: entry.id,
196
+ result: "limitation",
197
+ type: "task_verify",
198
+ payload: { reason: "no check declared for this acceptance criterion" },
199
+ });
200
+ if (change)
201
+ records.push({
202
+ criterion: "claimed-paths-changed",
203
+ result: change.changed === false
204
+ ? "not_proven"
205
+ : change.changed
206
+ ? "proven"
207
+ : "limitation",
208
+ type: "task_verify",
209
+ payload: { base: change.base, paths: change.paths },
210
+ });
211
+ if (!outcome.checks.length)
212
+ records.push({
213
+ criterion: "verification",
214
+ result: "not_proven",
215
+ type: "task_verify",
216
+ payload: { reason: outcome.reason },
217
+ });
218
+ const verifiedAt = now.toISOString();
219
+ const evidence = [];
220
+ const sessions = [];
221
+ let recordError;
222
+ const projectId = projectOfTasksRoot(root) ?? null;
223
+ if (options.openStore) {
224
+ let store = null;
225
+ try {
226
+ store = await options.openStore();
227
+ const linked = store
228
+ .listTaskSessions(id, projectId)
229
+ .filter((session) => session.profile !== VERIFY_PROFILE);
230
+ const sessionId = randomUUID();
231
+ store.create({
232
+ sessionId,
233
+ title: `tasks verify ${id}`,
234
+ taskId: id,
235
+ projectId,
236
+ provider: "ocean",
237
+ providerSessionId: null,
238
+ parentSessionId: null,
239
+ profile: VERIFY_PROFILE,
240
+ profileIdentity: "",
241
+ workingDirectory: options.cwd ?? repoRoot(),
242
+ resumeData: null,
243
+ });
244
+ store.updateStatus(sessionId, "running");
245
+ const status = verified === "yes" ? "proven" : "not_proven";
246
+ for (const record of records) {
247
+ const data = JSON.stringify({
248
+ evidenceId: randomUUID(),
249
+ sessionId,
250
+ type: record.type,
251
+ source: "ocean-tasks-verify",
252
+ observedAt: verifiedAt,
253
+ result: record.result,
254
+ criterion: record.criterion,
255
+ taskId: id,
256
+ payload: JSON.stringify(record.payload),
257
+ });
258
+ const event = store.appendEvent(sessionId, "evidence", data);
259
+ evidence.push(listItem(`${record.criterion}:event:${event.eventId}`));
260
+ for (const session of linked)
261
+ store.appendEvent(session.sessionId, "evidence", data);
262
+ }
263
+ store.updateStatus(sessionId, "completed");
264
+ store.setVerificationStatus(sessionId, status);
265
+ for (const session of linked) {
266
+ store.setVerificationStatus(session.sessionId, status);
267
+ sessions.push(session.sessionId);
268
+ }
269
+ }
270
+ catch (error) {
271
+ recordError = error instanceof Error ? error.message : String(error);
272
+ }
273
+ finally {
274
+ store?.close();
275
+ }
276
+ }
277
+ // Re-read: the checks may have run for minutes, and the task file is the record.
278
+ const current = await readFile(taskFile, "utf8");
279
+ await writeFile(taskFile, setFrontmatterFields(current, {
280
+ verified,
281
+ verified_at: verifiedAt,
282
+ evidence: `[${evidence.join(", ")}]`,
283
+ ...(assumed.size ? { assumed: `[${[...assumed].join(", ")}]` } : {}),
284
+ updated: localDate(now),
285
+ }), "utf8");
286
+ return {
287
+ ...outcome,
288
+ passed,
289
+ reason,
290
+ verified,
291
+ verifiedAt,
292
+ lane,
293
+ acceptance,
294
+ change,
295
+ review,
296
+ evidence,
297
+ assumed: [...assumed],
298
+ sessions,
299
+ ...(recordError ? { recordError } : {}),
300
+ };
301
+ }
302
+ //# sourceMappingURL=task-verification.js.map
@@ -43,23 +43,63 @@ const defaultRunner = async (command, cwd) => {
43
43
  return { exitCode: code };
44
44
  }
45
45
  };
46
+ // `AC-3: pnpm test` labels a check with the Definition-of-done item it proves (T-320).
47
+ const AC_LABEL = /^(AC-\d+):\s*/i;
48
+ function labelled(raw) {
49
+ const trimmed = raw.trim();
50
+ const label = trimmed.match(AC_LABEL);
51
+ return label
52
+ ? { ac: label[1].toUpperCase(), command: trimmed.slice(label[0].length) }
53
+ : { command: trimmed };
54
+ }
55
+ // The `verify:` field, read from the frontmatter only (a body line never counts). Inline
56
+ // (`verify: a, b`) splits on `,`, `&&` and `;`; a block list (`verify:` then ` - AC-1: a`)
57
+ // keeps each item whole, so one acceptance criterion may chain its own steps.
58
+ function frontmatterVerify(source) {
59
+ if (!source.startsWith("---\n"))
60
+ return null;
61
+ const end = source.indexOf("\n---", 4);
62
+ if (end < 0)
63
+ return null;
64
+ const lines = source.slice(4, end).split("\n");
65
+ const at = lines.findIndex((line) => /^verify:/.test(line));
66
+ if (at < 0)
67
+ return null;
68
+ const inline = lines[at]
69
+ .slice("verify:".length)
70
+ .trim()
71
+ .replace(/^['"]|['"]$/g, "");
72
+ if (inline && inline !== "[]") {
73
+ const list = inline.match(/^\[(.*)\]$/)?.[1] ?? inline;
74
+ return list
75
+ .split(/\s*(?:,|&&|;)\s*/)
76
+ .map((part) => part.trim())
77
+ .filter(Boolean)
78
+ .map(labelled)
79
+ .filter((entry) => entry.command);
80
+ }
81
+ const items = [];
82
+ for (const line of lines.slice(at + 1)) {
83
+ const item = line.match(/^\s+-\s+(.+)$/);
84
+ if (!item)
85
+ break;
86
+ const entry = labelled(item[1]);
87
+ if (entry.command)
88
+ items.push(entry);
89
+ }
90
+ return items.length ? items : null;
91
+ }
46
92
  /**
47
93
  * Pull runnable commands out of a task's verification declaration. A `verify:`
48
- * frontmatter field (string or comma-separated list) wins; otherwise each non-empty
49
- * line inside a fenced code block of the `## Verification` section. Inline-backtick
50
- * spans are prose, never commands: on T-308 a prose span naming `npm publish` was run
51
- * (T-317).
94
+ * frontmatter field wins; otherwise each non-empty line inside a fenced code block of
95
+ * the `## Verification` section. Inline-backtick spans are prose, never commands: on
96
+ * T-308 a prose span naming `npm publish` was run (T-317). Any command may carry an
97
+ * `AC-n:` label naming the acceptance criterion it proves.
52
98
  */
53
- function candidateCommands(source) {
54
- const frontmatter = source
55
- .match(/^verify:\s*(.+)$/m)?.[1]
56
- ?.trim()
57
- .replace(/^['"]|['"]$/g, "");
99
+ export function declaredCommands(source) {
100
+ const frontmatter = frontmatterVerify(source);
58
101
  if (frontmatter)
59
- return frontmatter
60
- .split(/\s*(?:,|&&|;)\s*/)
61
- .map((part) => part.trim())
62
- .filter(Boolean);
102
+ return frontmatter;
63
103
  const section = source
64
104
  .match(/\n## Verification\n\n([\s\S]*?)(?=\n## |$)/)?.[1]
65
105
  ?.trim();
@@ -70,10 +110,11 @@ function candidateCommands(source) {
70
110
  for (const line of match[1].split("\n")) {
71
111
  const trimmed = line.trim();
72
112
  if (trimmed && !trimmed.startsWith("#"))
73
- fenced.push(trimmed);
113
+ fenced.push(labelled(trimmed));
74
114
  }
75
- return fenced;
115
+ return fenced.filter((entry) => entry.command);
76
116
  }
117
+ const candidateCommands = (source) => declaredCommands(source).map((entry) => entry.command);
77
118
  export function extractVerificationCommands(source) {
78
119
  return candidateCommands(source).filter((command) => isAllowedCommand(command));
79
120
  }
@@ -152,8 +193,10 @@ function isAllowedCommand(command, origin = "task") {
152
193
  export async function verifyTask(id, root = workspaceTasksRoot(), options = {}) {
153
194
  const taskFile = resolveWithin(root, id, "task.md");
154
195
  const source = await readFile(taskFile, "utf8");
155
- const candidates = candidateCommands(source);
156
- const taskCommands = candidates.filter((command) => isAllowedCommand(command));
196
+ const declared = declaredCommands(source);
197
+ const candidates = declared.map((entry) => entry.command);
198
+ const taskEntries = declared.filter((entry) => isAllowedCommand(entry.command));
199
+ const taskCommands = taskEntries.map((entry) => entry.command);
157
200
  const fail = (reason, from) => ({
158
201
  id,
159
202
  passed: false,
@@ -165,7 +208,7 @@ export async function verifyTask(id, root = workspaceTasksRoot(), options = {})
165
208
  // Commands were declared but none may run: that is a failure, never a reason to fall back.
166
209
  if (candidates.length > 0 && taskCommands.length === 0)
167
210
  return fail(`declared verification commands are not allowed: ${candidates.join(", ")}`, "task");
168
- let commands = taskCommands;
211
+ let commands = taskEntries;
169
212
  let cwd = options.cwd ?? repoRoot();
170
213
  let from = "task";
171
214
  const project = projectOfTasksRoot(root);
@@ -209,13 +252,18 @@ export async function verifyTask(id, root = workspaceTasksRoot(), options = {})
209
252
  return fail(`project verify needs the project's first path to be an absolute, existing directory: ${manifest.paths[0] ? expandHome(manifest.paths[0]) : "(none)"}`, from);
210
253
  cwd = dir;
211
254
  }
212
- commands = verify;
255
+ commands = verify.map((command) => ({ command }));
213
256
  }
214
257
  const run = options.run ?? defaultRunner;
215
258
  const checks = [];
216
- for (const command of commands) {
259
+ for (const { command, ac } of commands) {
217
260
  const { exitCode } = await run(command, cwd);
218
- checks.push({ command, exitCode, ok: exitCode === 0 });
261
+ checks.push({
262
+ command,
263
+ exitCode,
264
+ ok: exitCode === 0,
265
+ ...(ac ? { ac } : {}),
266
+ });
219
267
  }
220
268
  const passed = checks.every((check) => check.ok);
221
269
  return {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocean/loop",
3
- "version": "2.7.0",
3
+ "version": "2.9.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocean/market",
3
- "version": "2.7.0",
3
+ "version": "2.9.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -193,6 +193,14 @@ const tools = new McpToolRegistry(withContextAck([
193
193
  query: { type: "string" },
194
194
  limit: { type: "number" },
195
195
  types: { type: "array", items: { type: "string" } },
196
+ since: {
197
+ type: "string",
198
+ description: "YYYY-MM-DD: only records dated on or after it",
199
+ },
200
+ asOf: {
201
+ type: "string",
202
+ description: "YYYY-MM-DD: only facts valid on that day (valid_from / superseded_by)",
203
+ },
196
204
  project: { type: "string" },
197
205
  cwd: { type: "string" },
198
206
  },
@@ -580,6 +588,8 @@ async function callTool(name, args, ports) {
580
588
  types: Array.isArray(args.types)
581
589
  ? args.types.filter((item) => typeof item === "string")
582
590
  : undefined,
591
+ since: isoDay(args.since, "since"),
592
+ asOf: isoDay(args.asOf, "asOf"),
583
593
  indexPort: ports.brainIndex,
584
594
  embedder: ports.embedder ? await ports.embedder() : null,
585
595
  });
@@ -767,6 +777,14 @@ async function readResource(uri, ports) {
767
777
  text: JSON.stringify(value, null, 2),
768
778
  };
769
779
  }
780
+ // An optional YYYY-MM-DD argument; anything else is refused rather than silently ignored.
781
+ function isoDay(value, key) {
782
+ if (value === undefined || value === null || value === "")
783
+ return undefined;
784
+ if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value))
785
+ throw new Error(`${key} must be a YYYY-MM-DD date`);
786
+ return value;
787
+ }
770
788
  function requiredArgument(args, key) {
771
789
  const value = args[key];
772
790
  if (typeof value !== "string" || !value)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocean/services",
3
- "version": "2.7.0",
3
+ "version": "2.9.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {