@0perator/operator 0.1.282 → 0.1.283

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.
@@ -12,7 +12,8 @@
12
12
  // Pure + framework-agnostic; node builtins (fs/child_process for verify) load lazily so the neutral bundle
13
13
  // is unaffected. The verify predicate (isVerifyCmd/ranButFailed) is shared with the main-loop verify gate.
14
14
  import { isVerifyCmd, ranButFailed } from "./verify-gate.js";
15
- import { applySRFTMask, runMutationCheck } from "../flywheel/processor.js";
15
+ import { applySRFTMask } from "../flywheel/srft.js"; // PURE half — node-free, neutral-graph safe
16
+ // runMutationCheck needs node:fs/child_process — resolved lazily via nodeImport() inside verifyMutation.
16
17
  const nodeImport = (m) => import(m);
17
18
  // Infer the task type from a free-form objective when the caller didn't declare one — keeps the tool
18
19
  // usable with just a task string while still selecting the right schema + verify + lane.
@@ -257,6 +258,7 @@ export async function verifyFinalAnswer(value, type, cwd, opts) {
257
258
  * git stash / revert the turn's diff in a temp worktree. If the suite still passes, the tests don't
258
259
  * test the change (the "37/37 file-exists" class caught by behavior, not regex). */
259
260
  export async function verifyMutation(cwd, verifyCommand, diffSha) {
261
+ const { runMutationCheck } = await nodeImport("../flywheel/processor.js"); // node-only module: never statically bundled (iOS neutral graph)
260
262
  return runMutationCheck(cwd, verifyCommand, diffSha);
261
263
  }
262
264
  /** Apply SRFT step masking to a graded trajectory. Marks each step as productive (keep in loss) or
@@ -3,49 +3,11 @@
3
3
  import { mkdirSync, appendFileSync } from "node:fs";
4
4
  import { screenRecord } from "./secret-gate.js"; // HV3-N1: the training stream must never carry secrets
5
5
  import { join, dirname } from "node:path";
6
- /** Apply SRFT-style step masking to a trajectory.
7
- * Marks each step as productive (keep in loss) or harmful (mask from loss).
8
- * A step is harmful if:
9
- * - It's a tool call that returned an error
10
- * - It's marked as a repetition loop guard
11
- * - It's a parse_fallback lint
12
- * - It triggered a forced redirect
13
- */
14
- export function applySRFTMask(trajectory) {
15
- const mask = [];
16
- let hasErrors = trajectory.stopReason === "repetition" || trajectory.unverified === true;
17
- let isHarmful = hasErrors;
18
- for (let i = 0; i < (trajectory.steps?.length ?? 0); i++) {
19
- const step = trajectory.steps[i];
20
- if (!step) {
21
- mask.push(true); // default: include unknown steps
22
- continue;
23
- }
24
- // Mask tool errors — the model shouldn't learn from failed tool calls
25
- if (step.role === "tool" && step.content?.includes("error") && step.content?.includes("exit")) {
26
- isHarmful = true;
27
- }
28
- // Mask steps that are part of a repetition loop
29
- if (trajectory.stopReason === "repetition" && isHarmful) {
30
- mask.push(false); // mask this step
31
- }
32
- else {
33
- mask.push(true);
34
- }
35
- }
36
- // If the trajectory is graded but has no explicit steps, mask the last few rounds
37
- // (likely the failure tail)
38
- if ((trajectory.steps?.length ?? 0) === 0 && trajectory.rounds > 3) {
39
- const tailRounds = Math.min(trajectory.rounds - 3, 5);
40
- for (let i = 0; i < tailRounds; i++) {
41
- mask.push(false);
42
- }
43
- for (let i = tailRounds; i < trajectory.rounds; i++) {
44
- mask.push(true);
45
- }
46
- }
47
- return mask.length > 0 ? mask : new Array(trajectory.rounds).fill(true);
48
- }
6
+ // ---------------------------------------------------------------------------
7
+ // SRFT (Step Rejection Fine-Tuning) — per-step masking for trajectories
8
+ // ---------------------------------------------------------------------------
9
+ import { applySRFTMask } from "./srft.js";
10
+ export { applySRFTMask } from "./srft.js"; // one import surface for existing consumers
49
11
  /** Run a mutation check on a verified turn.
50
12
  * Stashes the worktree, reverts the diff, runs verify_command.
51
13
  * If the suite still passes, the tests are vacuous (they don't test the change). */
@@ -0,0 +1,43 @@
1
+ /** Apply SRFT-style step masking to a trajectory.
2
+ * Marks each step as productive (keep in loss) or harmful (mask from loss).
3
+ * A step is harmful if:
4
+ * - It's a tool call that returned an error
5
+ * - It's marked as a repetition loop guard
6
+ * - It's a parse_fallback lint
7
+ * - It triggered a forced redirect
8
+ */
9
+ export function applySRFTMask(trajectory) {
10
+ const mask = [];
11
+ let hasErrors = trajectory.stopReason === "repetition" || trajectory.unverified === true;
12
+ let isHarmful = hasErrors;
13
+ for (let i = 0; i < (trajectory.steps?.length ?? 0); i++) {
14
+ const step = trajectory.steps[i];
15
+ if (!step) {
16
+ mask.push(true); // default: include unknown steps
17
+ continue;
18
+ }
19
+ // Mask tool errors — the model shouldn't learn from failed tool calls
20
+ if (step.role === "tool" && step.content?.includes("error") && step.content?.includes("exit")) {
21
+ isHarmful = true;
22
+ }
23
+ // Mask steps that are part of a repetition loop
24
+ if (trajectory.stopReason === "repetition" && isHarmful) {
25
+ mask.push(false); // mask this step
26
+ }
27
+ else {
28
+ mask.push(true);
29
+ }
30
+ }
31
+ // If the trajectory is graded but has no explicit steps, mask the last few rounds
32
+ // (likely the failure tail)
33
+ if ((trajectory.steps?.length ?? 0) === 0 && trajectory.rounds > 3) {
34
+ const tailRounds = Math.min(trajectory.rounds - 3, 5);
35
+ for (let i = 0; i < tailRounds; i++) {
36
+ mask.push(false);
37
+ }
38
+ for (let i = tailRounds; i < trajectory.rounds; i++) {
39
+ mask.push(true);
40
+ }
41
+ }
42
+ return mask.length > 0 ? mask : new Array(trajectory.rounds).fill(true);
43
+ }
@@ -17,10 +17,14 @@ export async function documentGenerate(args) {
17
17
  return "error: document_generate needs `content` (markdown or plain text)";
18
18
  const title = String(args.title ?? "").trim();
19
19
  const subtitle = String(args.subtitle ?? "").trim();
20
- const PDFDocument = (await import("pdfkit")).default;
21
- const { marked } = await import("marked");
22
- const fs = await import("node:fs");
23
- const path = await import("node:path");
20
+ // VARIABLE specifiers: esbuild must not statically resolve these (node-only deps; a literal here drags
21
+ // pdfkit + node builtins into the iOS neutral engine bundle via registry.ts's static tool catalogue —
22
+ // the exact breakage test/neutral-graph.test.mts now catches at suite time). Same idiom as nodeImport.
23
+ const nodeReq = (m) => import(m);
24
+ const PDFDocument = (await nodeReq("pdfkit")).default;
25
+ const { marked } = await nodeReq("marked");
26
+ const fs = await nodeReq("node:fs");
27
+ const path = await nodeReq("node:path");
24
28
  const { operatorPath } = await import("../config/home.js");
25
29
  // Resolve the output path: honor an explicit `out`, else a durable attachments copy.
26
30
  let out = String(args.out ?? "").trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.282",
3
+ "version": "0.1.283",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "operator": "dist/cli.js",