@workit-dev/pi 2.13.0 → 2.15.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/dist/worker.js CHANGED
@@ -7410,7 +7410,7 @@ var workspaceConfigSchema = object({
7410
7410
  fanout: object({
7411
7411
  tierModels: unknown().optional().describe("The model per slice TIER (mundane, standard, hard), as one name or per host.")
7412
7412
  }).passthrough().optional().describe("Fanout settings."),
7413
- models: object({ roles: modelRoles }).passthrough().optional().describe("Model and effort per role and host (roles), the lead's own advisory model (lead) and whether a model the lead names on a spawn wins (allowLeadOverride, default false); the same key at the top of workspaces.json is the global default."),
7413
+ models: object({ roles: modelRoles }).passthrough().optional().describe("Model and effort per role and host (roles), the lead's own advisory model (lead), how a role model applies (enforce: advise, the default, or strict) and, under strict, whether a model the lead names on a spawn wins (allowLeadOverride, default false); the same key at the top of workspaces.json is the global default."),
7414
7414
  resources: unknown().optional().describe("Heavy-check limits on this machine: slots, scope, heavy, light, memoryMax, cpuQuota, wait."),
7415
7415
  remotes: array(nonBlank.refine((pattern) => remotePattern(pattern) !== null, "is not a remote URL (https://host/owner/repo, git@host:owner/repo, a path, or owner/*)")).optional().describe("Remote URLs this entry owns: a checkout pushing to or opening PRs on one never exceeds this entry's grants, wherever the folder is (`owner/*` claims a whole owner). Only the user changes it, in their own terminal."),
7416
7416
  autonomy: object(Object.fromEntries(["push", "pr", "merge", "release", "rerun"].map((kind) => [
@@ -7448,7 +7448,7 @@ var workspaceConfigSchema = object({
7448
7448
  });
7449
7449
  var workspacesFileSchema = object({
7450
7450
  workspaces: array(workspaceConfigSchema).optional().describe("Workspace entries, each mapping a path glob to its forge, policies and grants."),
7451
- models: object({ roles: modelRoles }).passthrough().optional().describe("The global default model and effort per role and host (roles), the lead's own advisory model (lead) and whether a model the lead names on a spawn wins (allowLeadOverride, default false).")
7451
+ models: object({ roles: modelRoles }).passthrough().optional().describe("The global default model and effort per role and host (roles), the lead's own advisory model (lead), how a role model applies (enforce: advise, the default, or strict) and, under strict, whether a model the lead names on a spawn wins (allowLeadOverride, default false).")
7452
7452
  }).passthrough().superRefine((file, context) => {
7453
7453
  const names = new Set;
7454
7454
  for (const [index, workspace] of (file.workspaces ?? []).entries()) {
@@ -8716,16 +8716,19 @@ var HOST_KEYS = new Set([
8716
8716
  "pi",
8717
8717
  "default"
8718
8718
  ]);
8719
- var BUILT_IN_CLAUDE_CODE = {
8719
+ var CLAUDE_AGENT_FILES = {
8720
8720
  decider: { model: "fable", effort: "high" },
8721
- "implementer.hard": { model: "opus" },
8722
- "implementer.standard": { model: "sonnet" },
8723
- "implementer.mundane": { model: "haiku" },
8721
+ implementer: { model: "sonnet" },
8724
8722
  verifier: { model: "sonnet" },
8725
8723
  reviewer: { model: "opus" },
8726
- explore: { model: "haiku" },
8727
8724
  babysit: { model: "haiku" }
8728
8725
  };
8726
+ var BUILT_IN_CLAUDE_CODE = {
8727
+ ...CLAUDE_AGENT_FILES,
8728
+ "implementer.hard": { model: "opus" },
8729
+ "implementer.standard": { model: "sonnet" },
8730
+ "implementer.mundane": { model: "haiku" }
8731
+ };
8729
8732
  var isObject3 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
8730
8733
  var name = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
8731
8734
  var leaf = (value) => {
@@ -8809,18 +8812,20 @@ var firstAvailable = (candidates, host, now = new Date) => {
8809
8812
  }
8810
8813
  return { ...primary, skipped, allExhausted: true };
8811
8814
  };
8815
+ var FILE_ROLES = new Set(["decider", "verifier", "reviewer", "babysit"]);
8812
8816
  var CLAUDE_ALIASES = new Set(["sonnet", "opus", "haiku", "fable"]);
8813
8817
  var CLAUDE_EFFORTS = new Set(["low", "medium", "high", "xhigh", "max"]);
8814
8818
  var CLAUDE_SPAWNS = [
8815
- ...["hard", "standard", "mundane"].map((tier) => ({
8816
- label: tier === "hard" ? "workit:implementer hard" : tier,
8819
+ ...MODEL_TIERS.map((tier) => ({
8820
+ label: `workit:implementer ${tier}`,
8817
8821
  selector: { role: "implementer", tier }
8818
8822
  })),
8819
- { label: "workit:verifier", selector: { role: "verifier" } },
8820
- { label: "workit:reviewer", selector: { role: "reviewer" } },
8823
+ ...["verifier", "reviewer", "decider"].map((role) => ({
8824
+ label: `workit:${role}`,
8825
+ selector: { role }
8826
+ })),
8827
+ { label: "workit:babysitter", selector: { role: "babysit" } },
8821
8828
  { label: "Explore", selector: { role: "explore" } },
8822
- { label: "ROLE: decider", selector: { role: "decider" } },
8823
- { label: "ROLE: babysit", selector: { role: "babysit" } },
8824
8829
  { label: "general-purpose", selector: { role: "default" } }
8825
8830
  ];
8826
8831
  var uniformImplementerModel = (cwd, host, dir) => {
@@ -9214,11 +9219,12 @@ var WRITE_TOOLS = new Set([
9214
9219
  var CLAUDE_CODE_DESCRIPTOR = {
9215
9220
  host: "claude_code",
9216
9221
  label: "Claude Code",
9217
- verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary)",
9222
+ verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary; SessionEnd: 2.1.327)",
9218
9223
  docs: ["https://code.claude.com/docs/en/hooks"],
9219
9224
  transport: "hook-process",
9220
9225
  events: {
9221
9226
  "session.start": { support: "native", native: "SessionStart" },
9227
+ "session.end": { support: "native", native: "SessionEnd" },
9222
9228
  "context.turn": { support: "native", native: "UserPromptSubmit" },
9223
9229
  "shell.pre": { support: "native", native: "PreToolUse" },
9224
9230
  "tool.pre": { support: "native", native: "PreToolUse" },
@@ -9328,6 +9334,7 @@ var CODEX_DESCRIPTOR = {
9328
9334
  transport: "hook-process",
9329
9335
  events: {
9330
9336
  "session.start": { support: "native", native: "SessionStart" },
9337
+ "session.end": { support: "none", native: null },
9331
9338
  "context.turn": { support: "native", native: "UserPromptSubmit" },
9332
9339
  "shell.pre": { support: "native", native: "PreToolUse" },
9333
9340
  "tool.pre": { support: "native", native: "PreToolUse" },
@@ -9438,6 +9445,7 @@ var CURSOR_DESCRIPTOR = {
9438
9445
  transport: "hook-process",
9439
9446
  events: {
9440
9447
  "session.start": { support: "native", native: "sessionStart" },
9448
+ "session.end": { support: "native", native: "sessionEnd" },
9441
9449
  "context.turn": none,
9442
9450
  "shell.pre": { support: "native", native: "beforeShellExecution" },
9443
9451
  "tool.pre": { support: "native", native: "preToolUse" },
@@ -9544,6 +9552,7 @@ var OPENCODE_DESCRIPTOR = {
9544
9552
  transport: "in-process-plugin",
9545
9553
  events: {
9546
9554
  "session.start": { support: "none", native: null },
9555
+ "session.end": { support: "partial", native: 'event("session.deleted")' },
9547
9556
  "context.turn": { support: "native", native: 'session.hook("context")' },
9548
9557
  "shell.pre": { support: "native", native: 'permission.hook("evaluate")' },
9549
9558
  "tool.pre": { support: "native", native: 'tool.hook("execute.before")' },
@@ -9613,6 +9622,7 @@ var PI_DESCRIPTOR = {
9613
9622
  transport: "in-process-plugin",
9614
9623
  events: {
9615
9624
  "session.start": { support: "native", native: "session_start" },
9625
+ "session.end": { support: "native", native: "session_shutdown" },
9616
9626
  "context.turn": { support: "native", native: "before_agent_start" },
9617
9627
  "shell.pre": { support: "native", native: "tool_call" },
9618
9628
  "tool.pre": { support: "native", native: "tool_call" },
package/dist/workit.js CHANGED
@@ -9171,7 +9171,7 @@ var workspaceConfigSchema = object({
9171
9171
  fanout: object({
9172
9172
  tierModels: unknown().optional().describe("The model per slice TIER (mundane, standard, hard), as one name or per host.")
9173
9173
  }).passthrough().optional().describe("Fanout settings."),
9174
- models: object({ roles: modelRoles }).passthrough().optional().describe("Model and effort per role and host (roles), the lead's own advisory model (lead) and whether a model the lead names on a spawn wins (allowLeadOverride, default false); the same key at the top of workspaces.json is the global default."),
9174
+ models: object({ roles: modelRoles }).passthrough().optional().describe("Model and effort per role and host (roles), the lead's own advisory model (lead), how a role model applies (enforce: advise, the default, or strict) and, under strict, whether a model the lead names on a spawn wins (allowLeadOverride, default false); the same key at the top of workspaces.json is the global default."),
9175
9175
  resources: unknown().optional().describe("Heavy-check limits on this machine: slots, scope, heavy, light, memoryMax, cpuQuota, wait."),
9176
9176
  remotes: array(nonBlank.refine((pattern) => remotePattern(pattern) !== null, "is not a remote URL (https://host/owner/repo, git@host:owner/repo, a path, or owner/*)")).optional().describe("Remote URLs this entry owns: a checkout pushing to or opening PRs on one never exceeds this entry's grants, wherever the folder is (`owner/*` claims a whole owner). Only the user changes it, in their own terminal."),
9177
9177
  autonomy: object(Object.fromEntries(["push", "pr", "merge", "release", "rerun"].map((kind) => [
@@ -9209,7 +9209,7 @@ var workspaceConfigSchema = object({
9209
9209
  });
9210
9210
  var workspacesFileSchema = object({
9211
9211
  workspaces: array(workspaceConfigSchema).optional().describe("Workspace entries, each mapping a path glob to its forge, policies and grants."),
9212
- models: object({ roles: modelRoles }).passthrough().optional().describe("The global default model and effort per role and host (roles), the lead's own advisory model (lead) and whether a model the lead names on a spawn wins (allowLeadOverride, default false).")
9212
+ models: object({ roles: modelRoles }).passthrough().optional().describe("The global default model and effort per role and host (roles), the lead's own advisory model (lead), how a role model applies (enforce: advise, the default, or strict) and, under strict, whether a model the lead names on a spawn wins (allowLeadOverride, default false).")
9213
9213
  }).passthrough().superRefine((file, context) => {
9214
9214
  const names = new Set;
9215
9215
  for (const [index, workspace] of (file.workspaces ?? []).entries()) {
@@ -17886,16 +17886,19 @@ var HOST_KEYS = new Set([
17886
17886
  "pi",
17887
17887
  "default"
17888
17888
  ]);
17889
- var BUILT_IN_CLAUDE_CODE = {
17889
+ var CLAUDE_AGENT_FILES = {
17890
17890
  decider: { model: "fable", effort: "high" },
17891
- "implementer.hard": { model: "opus" },
17892
- "implementer.standard": { model: "sonnet" },
17893
- "implementer.mundane": { model: "haiku" },
17891
+ implementer: { model: "sonnet" },
17894
17892
  verifier: { model: "sonnet" },
17895
17893
  reviewer: { model: "opus" },
17896
- explore: { model: "haiku" },
17897
17894
  babysit: { model: "haiku" }
17898
17895
  };
17896
+ var BUILT_IN_CLAUDE_CODE = {
17897
+ ...CLAUDE_AGENT_FILES,
17898
+ "implementer.hard": { model: "opus" },
17899
+ "implementer.standard": { model: "sonnet" },
17900
+ "implementer.mundane": { model: "haiku" }
17901
+ };
17899
17902
  var isObject6 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
17900
17903
  var name = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
17901
17904
  var leaf = (value) => {
@@ -17985,12 +17988,15 @@ var fallbackText = (chosen) => {
17985
17988
  const passed = chosen.skipped.map((one) => `${one.model} (${one.provider} exhausted until ${shortTime(one.until)})`).join(", ");
17986
17989
  return chosen.allExhausted ? `every model configured for it is exhausted: ${passed}; it runs on ${chosen.model} anyway. Add a model of another provider to the list in workspaces.json, then run \`workit models show\`.` : `fell back past ${passed}.`;
17987
17990
  };
17988
- var leadOverrideAllowed = (cwd, dir) => {
17991
+ var modelsKey = (cwd, key, dir) => {
17989
17992
  for (const source of modelSources(cwd, dir))
17990
- if (isObject6(source.models) && Object.hasOwn(source.models, "allowLeadOverride"))
17991
- return source.models.allowLeadOverride === true;
17992
- return false;
17993
+ if (isObject6(source.models) && Object.hasOwn(source.models, key))
17994
+ return source.models[key];
17995
+ return;
17993
17996
  };
17997
+ var leadOverrideAllowed = (cwd, dir) => modelsKey(cwd, "allowLeadOverride", dir) === true;
17998
+ var enforceMode = (cwd, dir) => modelsKey(cwd, "enforce", dir) === "strict" ? "strict" : "advise";
17999
+ var FILE_ROLES = new Set(["decider", "verifier", "reviewer", "babysit"]);
17994
18000
  var CLAUDE_ALIASES = new Set(["sonnet", "opus", "haiku", "fable"]);
17995
18001
  var CLAUDE_EFFORTS = new Set(["low", "medium", "high", "xhigh", "max"]);
17996
18002
  var FULL_CLAUDE_ID = /^(?:[\w.-]+[./])?claude-(?:\d[\d.-]*-)?(sonnet|opus|haiku|fable)(?:[-.@[]|$)/u;
@@ -18016,7 +18022,7 @@ var chooseSpawnModel = (cwd, selector, host, given, accept, dir) => {
18016
18022
  const givenModel = name(given.model);
18017
18023
  const label = roleLabel(selector);
18018
18024
  const configured = resolved.source !== "built-in";
18019
- if (givenModel && (!configured || leadOverrideAllowed(cwd, dir)))
18025
+ if (givenModel && (!configured || enforceMode(cwd, dir) === "advise" || leadOverrideAllowed(cwd, dir)))
18020
18026
  return none;
18021
18027
  const model = accept(resolved.model);
18022
18028
  const effort = resolved.effort && !name(given.effort) ? resolved.effort : null;
@@ -18042,37 +18048,31 @@ var chooseSpawnModel = (cwd, selector, host, given, accept, dir) => {
18042
18048
  model,
18043
18049
  effort,
18044
18050
  basis,
18045
- note: givenModel ? `Workit replaced model ${givenModel} with ${model} on this spawn: role ${label} is set in ${resolved.source}.${why} Next time ${next} on the spawn. To let a spawn's own model win, set "allowLeadOverride": true under models in workspaces.json.` : `Workit set ${model}${effort ? ` (effort ${effort})` : ""} on this spawn: role ${label}, ${resolved.source}.${why}${configured ? "" : " Name a model to choose another."}`
18046
- };
18047
- };
18048
- var claudeSpawnArgs = (cwd, selector, dir) => {
18049
- const choice = chooseSpawnModel(cwd, selector, "claude_code", {}, claudeAgentModel, dir);
18050
- if (!choice.model)
18051
- return null;
18052
- const effort = choice.effort?.toLowerCase() ?? null;
18053
- return {
18054
- model: choice.model,
18055
- effort: effort && CLAUDE_EFFORTS.has(effort) ? effort : null
18051
+ note: givenModel ? `Workit replaced model ${givenModel} with ${model} on this spawn: role ${label} is set in ${resolved.source}.${why} Next time ${next} on the spawn, or set models.enforce "advise" so a named model wins.` : `Workit set ${model}${effort ? ` (effort ${effort})` : ""} on this spawn: role ${label}, ${resolved.source}.${why}${configured ? "" : " Name a model to choose another."}`
18056
18052
  };
18057
18053
  };
18058
18054
  var CLAUDE_SPAWNS = [
18059
- ...["hard", "standard", "mundane"].map((tier) => ({
18060
- label: tier === "hard" ? "workit:implementer hard" : tier,
18055
+ ...MODEL_TIERS.map((tier) => ({
18056
+ label: `workit:implementer ${tier}`,
18061
18057
  selector: { role: "implementer", tier }
18062
18058
  })),
18063
- { label: "workit:verifier", selector: { role: "verifier" } },
18064
- { label: "workit:reviewer", selector: { role: "reviewer" } },
18059
+ ...["verifier", "reviewer", "decider"].map((role) => ({
18060
+ label: `workit:${role}`,
18061
+ selector: { role }
18062
+ })),
18063
+ { label: "workit:babysitter", selector: { role: "babysit" } },
18065
18064
  { label: "Explore", selector: { role: "explore" } },
18066
- { label: "ROLE: decider", selector: { role: "decider" } },
18067
- { label: "ROLE: babysit", selector: { role: "babysit" } },
18068
18065
  { label: "general-purpose", selector: { role: "default" } }
18069
18066
  ];
18070
18067
  var claudeSpawnTable = (cwd, dir) => {
18071
18068
  const rows = CLAUDE_SPAWNS.flatMap(({ label, selector }) => {
18072
- const args = claudeSpawnArgs(cwd, selector, dir);
18073
- return args ? [`${label} ${args.model}${args.effort ? `/${args.effort}` : ""}`] : [];
18069
+ const want = resolveRoleModel(cwd, selector, "claude_code", dir);
18070
+ const model = want && want.source !== "built-in" ? claudeAgentModel(want.model) : null;
18071
+ const effort = want?.effort?.toLowerCase();
18072
+ const file = label.startsWith("workit:") ? CLAUDE_AGENT_FILES[selector.role] : undefined;
18073
+ return model && (model !== file?.model || effort !== file.effort) ? [`${label} ${model}${effort ? `/${effort}` : ""}`] : [];
18074
18074
  });
18075
- return rows.length ? `Agent spawn model/effort (pass them, workers with run_in_background: true): ${rows.join(", ")}. Implementer prompt: \`workit fanout brief <slice>\` after \`workit fanout worktree create <slice>\`, even for one slice.` : null;
18075
+ return `Spawn Workit roles by name (workit:implementer, workit:verifier, workit:reviewer, workit:decider, workit:babysitter; search: Explore), workers with run_in_background: true, and pass no model or effort unless the user named one${rows.length ? `; configured here (pass them): ${rows.join(", ")}` : ""}. Implementer prompt: \`workit fanout brief <slice>\` after \`workit fanout worktree create <slice>\`, even for one slice.`;
18076
18076
  };
18077
18077
  var uniformImplementerModel = (cwd, host, dir) => {
18078
18078
  const tiers = MODEL_TIERS.map((tier) => resolveRoleModel(cwd, { role: "implementer", tier }, host, dir));
@@ -18080,7 +18080,7 @@ var uniformImplementerModel = (cwd, host, dir) => {
18080
18080
  return first && tiers.every((t) => t?.model === first.model && t.effort === first.effort) ? first : null;
18081
18081
  };
18082
18082
  var ROLE_SELECTORS = MODEL_ROLES.flatMap((role) => role === "implementer" ? MODEL_TIERS.map((tier) => ({ role, tier })) : [{ role }]);
18083
- var AGENT_ROLE = /^(?:workit[:-])?(decider|implementer|verifier|reviewer|explore|babysit)$/iu;
18083
+ var AGENT_ROLE = /^(?:workit[:-])?(decider|implementer|verifier|reviewer|explore|babysit)(?:(?<=babysit)ter)?$/iu;
18084
18084
  var ROLE_LINE = /^[ \t]*ROLE:[ \t]*(decider|implementer|verifier|reviewer|explore|babysit)\b/imu;
18085
18085
  var TIER_LINE = /^[ \t]*TIER:[ \t]*(mundane|standard|hard)\b/imu;
18086
18086
  var isBrief = (text) => TIER_LINE.test(text) && /^WORKTREE:/mu.test(text);
@@ -28592,11 +28592,12 @@ var inlineCallDeny = (fix) => `Run \`${fix}\` as its own call so the host can as
28592
28592
  var CLAUDE_CODE_DESCRIPTOR = {
28593
28593
  host: "claude_code",
28594
28594
  label: "Claude Code",
28595
- verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary)",
28595
+ verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary; SessionEnd: 2.1.327)",
28596
28596
  docs: ["https://code.claude.com/docs/en/hooks"],
28597
28597
  transport: "hook-process",
28598
28598
  events: {
28599
28599
  "session.start": { support: "native", native: "SessionStart" },
28600
+ "session.end": { support: "native", native: "SessionEnd" },
28600
28601
  "context.turn": { support: "native", native: "UserPromptSubmit" },
28601
28602
  "shell.pre": { support: "native", native: "PreToolUse" },
28602
28603
  "tool.pre": { support: "native", native: "PreToolUse" },
@@ -28706,6 +28707,7 @@ var CODEX_DESCRIPTOR = {
28706
28707
  transport: "hook-process",
28707
28708
  events: {
28708
28709
  "session.start": { support: "native", native: "SessionStart" },
28710
+ "session.end": { support: "none", native: null },
28709
28711
  "context.turn": { support: "native", native: "UserPromptSubmit" },
28710
28712
  "shell.pre": { support: "native", native: "PreToolUse" },
28711
28713
  "tool.pre": { support: "native", native: "PreToolUse" },
@@ -28816,6 +28818,7 @@ var CURSOR_DESCRIPTOR = {
28816
28818
  transport: "hook-process",
28817
28819
  events: {
28818
28820
  "session.start": { support: "native", native: "sessionStart" },
28821
+ "session.end": { support: "native", native: "sessionEnd" },
28819
28822
  "context.turn": none,
28820
28823
  "shell.pre": { support: "native", native: "beforeShellExecution" },
28821
28824
  "tool.pre": { support: "native", native: "preToolUse" },
@@ -28922,6 +28925,7 @@ var OPENCODE_DESCRIPTOR = {
28922
28925
  transport: "in-process-plugin",
28923
28926
  events: {
28924
28927
  "session.start": { support: "none", native: null },
28928
+ "session.end": { support: "partial", native: 'event("session.deleted")' },
28925
28929
  "context.turn": { support: "native", native: 'session.hook("context")' },
28926
28930
  "shell.pre": { support: "native", native: 'permission.hook("evaluate")' },
28927
28931
  "tool.pre": { support: "native", native: 'tool.hook("execute.before")' },
@@ -28991,6 +28995,7 @@ var PI_DESCRIPTOR = {
28991
28995
  transport: "in-process-plugin",
28992
28996
  events: {
28993
28997
  "session.start": { support: "native", native: "session_start" },
28998
+ "session.end": { support: "native", native: "session_shutdown" },
28994
28999
  "context.turn": { support: "native", native: "before_agent_start" },
28995
29000
  "shell.pre": { support: "native", native: "tool_call" },
28996
29001
  "tool.pre": { support: "native", native: "tool_call" },
@@ -30401,11 +30406,12 @@ var respawn = (input, reasons, dropped, limits) => {
30401
30406
  return {
30402
30407
  kind: "deny",
30403
30408
  reason: [
30404
- `workit spawn args: spawn again with exactly ${args} (description and prompt as written${without}).`,
30405
- ...reasons,
30406
- "Workit denies instead of rewriting the spawn: Claude Code's auto mode refuses a hook-rewritten spawn.",
30409
+ `workit spawn args: ${reasons.join(" ")}`,
30410
+ `Retry as: Agent ${args} (description and prompt as written${without}).`,
30411
+ "Why: auto mode refuses a hook-rewritten spawn.",
30407
30412
  limits
30408
- ].filter(Boolean).join(" "),
30413
+ ].filter(Boolean).join(`
30414
+ `),
30409
30415
  unblock: args
30410
30416
  };
30411
30417
  };
@@ -30440,18 +30446,19 @@ var agentModelDecision = (cwd, tool, options = {}) => {
30440
30446
  if (!selector)
30441
30447
  return asWritten(null);
30442
30448
  const choice = chooseSpawnModel(cwd, selector, "claude_code", tool, claudeAgentModel);
30449
+ const file = String(tool.subagent_type).startsWith("workit:") ? CLAUDE_AGENT_FILES[selector.role] : undefined;
30443
30450
  const effort = choice.effort?.toLowerCase() ?? null;
30444
30451
  const input = { ...tool };
30445
- if (choice.model)
30452
+ if (choice.model && (given(tool.model) || choice.model !== file?.model))
30446
30453
  input.model = choice.model;
30447
- if (effort && CLAUDE_EFFORTS.has(effort) && !given(tool.effort))
30454
+ if (effort && CLAUDE_EFFORTS.has(effort) && !given(tool.effort) && effort !== file?.effort)
30448
30455
  input.effort = effort;
30449
30456
  const needs = [
30450
30457
  input.model === tool.model ? null : `model ${String(input.model)}`,
30451
30458
  input.effort === tool.effort ? null : `effort ${String(input.effort)}`
30452
30459
  ].filter(Boolean);
30453
30460
  if (!needs.length)
30454
- return asWritten(choice.note);
30461
+ return asWritten(choice.model ? null : choice.note);
30455
30462
  if (!auto) {
30456
30463
  const note = choice.note ?? `Workit set effort ${String(input.effort)} on this spawn: its role's configured effort.`;
30457
30464
  return {
@@ -30461,12 +30468,18 @@ var agentModelDecision = (cwd, tool, options = {}) => {
30461
30468
  `)
30462
30469
  };
30463
30470
  }
30471
+ if (enforceMode(cwd) === "advise") {
30472
+ if (changed)
30473
+ return respawn(tool, change.reasons, change.dropped, limits);
30474
+ const ran = file ? `${file.model}${file.effort ? `/${file.effort}` : ""}` : "its default model";
30475
+ const pass = spawnArgsText({ model: input.model, effort: input.effort });
30476
+ return asWritten(`Workit: this ${String(tool.subagent_type || "general-purpose")} spawn runs on ${ran}; ${choice.basis} sets ${needs.join(" and ")}. To use it, pass ${pass} on the spawn.`);
30477
+ }
30464
30478
  const replaced = given(tool.model) && input.model !== tool.model;
30465
30479
  return respawn(input, [
30466
30480
  ...change.reasons,
30467
- `It needs ${needs.join(" and ")}: ${choice.basis ?? "its role"}.`,
30468
- replaced ? `That replaces model ${String(tool.model)}: a configured role model wins unless "allowLeadOverride": true is set under models in workspaces.json.` : ""
30469
- ].filter(Boolean), change.dropped, limits);
30481
+ `It needs ${needs.join(" and ")} (${choice.basis}, models.enforce strict)${replaced ? `, not ${String(tool.model)}` : ""}.`
30482
+ ], change.dropped, limits);
30470
30483
  };
30471
30484
 
30472
30485
  // packages/workit-core/src/hooks/spawn-gate.ts
@@ -30544,6 +30557,239 @@ function takeProcNotice(session, env = process.env) {
30544
30557
  }
30545
30558
  }
30546
30559
 
30560
+ // packages/workit-core/src/hooks/teardown.ts
30561
+ import { spawn } from "node:child_process";
30562
+ import fs32 from "node:fs";
30563
+ import path52 from "node:path";
30564
+
30565
+ // packages/workit-core/src/core/cli-locate.ts
30566
+ import { closeSync as closeSync5, existsSync as existsSync17, openSync as openSync5, readSync as readSync2 } from "node:fs";
30567
+ import path51 from "node:path";
30568
+ var LAUNCHER_MARKER = "workit-owned-launcher";
30569
+ var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
30570
+ var installRoot = (env, platform = process.platform) => {
30571
+ if (env.WORKIT_INSTALL_ROOT)
30572
+ return env.WORKIT_INSTALL_ROOT;
30573
+ const data = dataDir(env, platform);
30574
+ return platform === "win32" ? path51.join(data, "install") : data;
30575
+ };
30576
+ var ownedLauncherPath = (env, platform = process.platform) => path51.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
30577
+ var ownedCurrentEntry = (env, platform = process.platform) => path51.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
30578
+ var head = (file) => {
30579
+ let fd;
30580
+ try {
30581
+ fd = openSync5(file, "r");
30582
+ const buffer = Buffer.alloc(256);
30583
+ const read = readSync2(fd, buffer, 0, buffer.length, 0);
30584
+ return buffer.subarray(0, read).toString("utf8");
30585
+ } catch {
30586
+ return "";
30587
+ } finally {
30588
+ if (fd !== undefined)
30589
+ closeSync5(fd);
30590
+ }
30591
+ };
30592
+ var locateWorkitCli = (options = {}) => {
30593
+ const env = options.env ?? process.env;
30594
+ const platform = options.platform ?? process.platform;
30595
+ const exists = options.exists ?? existsSync17;
30596
+ const read = options.read ?? head;
30597
+ const node = options.node ?? process.execPath;
30598
+ const launcher = ownedLauncherPath(env, platform);
30599
+ if (exists(launcher) && read(launcher).includes(LAUNCHER_MARKER))
30600
+ return {
30601
+ source: "owned-launcher",
30602
+ command: launcher,
30603
+ args: [],
30604
+ binDir: path51.dirname(launcher)
30605
+ };
30606
+ const current = ownedCurrentEntry(env, platform);
30607
+ if (exists(current))
30608
+ return {
30609
+ source: "owned-current",
30610
+ command: node,
30611
+ args: [current],
30612
+ binDir: null
30613
+ };
30614
+ if (options.bundled && exists(options.bundled))
30615
+ return {
30616
+ source: "bundled",
30617
+ command: node,
30618
+ args: [options.bundled],
30619
+ binDir: null
30620
+ };
30621
+ return { source: "path", command: "workit", args: [], binDir: null };
30622
+ };
30623
+ var pathKey = (env) => Object.keys(env).find((key) => key.toUpperCase() === "PATH") ?? "PATH";
30624
+ var workitCliEnv = (located, env = process.env, platform = process.platform) => {
30625
+ if (located.source === "path")
30626
+ return {};
30627
+ const patch = {
30628
+ WORKIT_CLI: [located.command, ...located.args].join(" ")
30629
+ };
30630
+ if (located.binDir) {
30631
+ const key = pathKey(env);
30632
+ const delimiter = platform === "win32" ? ";" : ":";
30633
+ const same = (dir) => platform === "win32" ? path51.win32.normalize(dir).toLowerCase() === path51.win32.normalize(located.binDir).toLowerCase() : path51.posix.normalize(dir) === path51.posix.normalize(located.binDir);
30634
+ const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
30635
+ patch[key] = [located.binDir, ...rest].join(delimiter);
30636
+ }
30637
+ return patch;
30638
+ };
30639
+ var useOwnedWorkitCli = (options = {}) => {
30640
+ const env = options.env ?? process.env;
30641
+ const located = locateWorkitCli({ ...options, env });
30642
+ Object.assign(env, workitCliEnv(located, env, options.platform));
30643
+ return located;
30644
+ };
30645
+
30646
+ // packages/workit-core/src/hooks/teardown.ts
30647
+ var REAP_INTERVAL_MS = 10 * 60000;
30648
+ var LOG_MAX_BYTES = 1 << 20;
30649
+ var ENDS = {
30650
+ claude_code: new Set(["logout", "prompt_input_exit", "other"]),
30651
+ cursor: new Set(["completed", "aborted", "error", "window_close", "user_close"]),
30652
+ pi: new Set(["quit"]),
30653
+ opencode: new Set(["deleted"])
30654
+ };
30655
+ var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
30656
+ var HOST_SESSION_VARS2 = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
30657
+ var teardownDir = (env) => path52.join(stateDir(env), "procs");
30658
+ var teardownLog = (env) => path52.join(teardownDir(env), "teardown.log");
30659
+ var reapStamp = (env) => path52.join(teardownDir(env), "reap-at-start.stamp");
30660
+ function spawnDetached(request) {
30661
+ try {
30662
+ const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
30663
+ const line = [`"${request.command}"`, ...request.args].join(" ");
30664
+ const child = spawn(shell ? line : request.command, shell ? [] : request.args, {
30665
+ cwd: request.cwd,
30666
+ env: request.env,
30667
+ detached: true,
30668
+ shell,
30669
+ stdio: ["ignore", request.log ?? "ignore", request.log ?? "ignore"],
30670
+ windowsHide: true
30671
+ });
30672
+ child.on("error", () => {});
30673
+ child.unref();
30674
+ return child.pid !== undefined;
30675
+ } catch {
30676
+ return false;
30677
+ }
30678
+ }
30679
+ var teardownDeps = {
30680
+ spawn: (request) => request.env.WORKIT_TEST_RUN === undefined && spawnDetached(request),
30681
+ now: () => Date.now()
30682
+ };
30683
+ var openLog = (env, args) => {
30684
+ try {
30685
+ const file = teardownLog(env);
30686
+ fs32.mkdirSync(path52.dirname(file), { recursive: true });
30687
+ let size = 0;
30688
+ try {
30689
+ size = fs32.statSync(file).size;
30690
+ } catch {}
30691
+ const fd = fs32.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
30692
+ fs32.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
30693
+ `);
30694
+ return fd;
30695
+ } catch {
30696
+ return null;
30697
+ }
30698
+ };
30699
+ function runCli(args, env, cwd) {
30700
+ let log = null;
30701
+ try {
30702
+ const cli = locateWorkitCli({ env });
30703
+ log = openLog(env, args);
30704
+ const started = teardownDeps.spawn({
30705
+ command: cli.command,
30706
+ args: [...cli.args, ...args],
30707
+ env,
30708
+ cwd: fs32.existsSync(cwd) ? cwd : teardownDir(env),
30709
+ log
30710
+ });
30711
+ if (!started && log !== null)
30712
+ fs32.writeSync(log, ` not started
30713
+ `);
30714
+ return started;
30715
+ } catch {
30716
+ return false;
30717
+ } finally {
30718
+ if (log !== null)
30719
+ try {
30720
+ fs32.closeSync(log);
30721
+ } catch {}
30722
+ }
30723
+ }
30724
+ function endSession(end, env = process.env) {
30725
+ const session = end.session?.trim() ?? "";
30726
+ if (!SAFE_SESSION.test(session) || !ENDS[end.host]?.has(end.reason ?? ""))
30727
+ return false;
30728
+ const outer = env.WORKIT_SESSION_ID?.trim();
30729
+ if (end.agentId || env.WORKIT_PI_WORKER_SESSION || leadOf(session) !== session || outer && leadOf(outer) !== outer)
30730
+ return false;
30731
+ const child = { ...env, WORKIT_SESSION_ID: session, WORKIT_HOST: end.host };
30732
+ for (const key of HOST_SESSION_VARS2)
30733
+ delete child[key];
30734
+ return runCli(["stop", "--session", session, "--reason", "session-end"], child, end.cwd);
30735
+ }
30736
+ var claim2 = (file, now) => {
30737
+ for (let attempt = 0;attempt < 2; attempt += 1)
30738
+ try {
30739
+ fs32.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
30740
+ return true;
30741
+ } catch (error) {
30742
+ if (error.code !== "EEXIST")
30743
+ return false;
30744
+ let held = Number.NaN;
30745
+ try {
30746
+ held = Number(fs32.readFileSync(file, "utf8"));
30747
+ } catch {}
30748
+ if (now - held < REAP_INTERVAL_MS)
30749
+ return false;
30750
+ fs32.rmSync(file, { force: true });
30751
+ }
30752
+ return false;
30753
+ };
30754
+ var fresh = (stamp, now) => {
30755
+ try {
30756
+ const last = Number(fs32.readFileSync(stamp, "utf8"));
30757
+ return now - last < REAP_INTERVAL_MS && last <= now;
30758
+ } catch {
30759
+ return false;
30760
+ }
30761
+ };
30762
+ function reapAtStart(cwd, env = process.env) {
30763
+ const stamp = reapStamp(env);
30764
+ const lock = `${stamp}.claim`;
30765
+ const now = teardownDeps.now();
30766
+ try {
30767
+ if (fresh(stamp, now))
30768
+ return false;
30769
+ fs32.mkdirSync(path52.dirname(stamp), { recursive: true });
30770
+ if (!claim2(lock, now))
30771
+ return false;
30772
+ } catch {
30773
+ return false;
30774
+ }
30775
+ let started = false;
30776
+ try {
30777
+ if (fresh(stamp, now))
30778
+ return false;
30779
+ started = runCli(["stop", "--orphans", "--reason", "session-start"], env, cwd);
30780
+ if (started) {
30781
+ const temp = `${stamp}.${process.pid}`;
30782
+ fs32.writeFileSync(temp, String(now), { mode: 384 });
30783
+ fs32.renameSync(temp, stamp);
30784
+ }
30785
+ } catch {} finally {
30786
+ try {
30787
+ fs32.rmSync(lock, { force: true });
30788
+ } catch {}
30789
+ }
30790
+ return started;
30791
+ }
30792
+
30547
30793
  // packages/workit-core/src/hooks/ytrack-word.ts
30548
30794
  var YTRACK_WORD = /ytrack(?![\w/-]|\.(?!exe|cmd))/i;
30549
30795
  var namesYtrack = (text) => {
@@ -31106,6 +31352,7 @@ function decide(input, deps) {
31106
31352
  const event = input.event;
31107
31353
  switch (event.kind) {
31108
31354
  case "session.start": {
31355
+ reapAtStart(input.cwd);
31109
31356
  if (!usable2(descriptor.context.sessionStart))
31110
31357
  return NONE6;
31111
31358
  const key = input.session.id ? `${input.host}\x00${input.session.id}` : null;
@@ -31120,6 +31367,15 @@ function decide(input, deps) {
31120
31367
  seedTurnContext(input, descriptor);
31121
31368
  return { kind: "context", text };
31122
31369
  }
31370
+ case "session.end":
31371
+ endSession({
31372
+ host: input.host,
31373
+ session: input.session.id,
31374
+ agentId: input.session.agentId,
31375
+ reason: event.reason,
31376
+ cwd: input.cwd
31377
+ });
31378
+ return NONE6;
31123
31379
  case "context.turn": {
31124
31380
  if (!usable2(descriptor.context.perTurn))
31125
31381
  return NONE6;
@@ -31324,11 +31580,11 @@ var modelKey = (model) => {
31324
31580
 
31325
31581
  // packages/workit-core/src/hooks/budget-signal.ts
31326
31582
  import { createHash as createHash23 } from "node:crypto";
31327
- import fs32 from "node:fs";
31328
- import path51 from "node:path";
31583
+ import fs33 from "node:fs";
31584
+ import path53 from "node:path";
31329
31585
  var hash2 = (text) => createHash23("sha256").update(text).digest("hex").slice(0, 32);
31330
- var budgetDir = (store) => path51.join(store, "budget");
31331
- var agentBase = (store, session, agentId) => path51.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
31586
+ var budgetDir = (store) => path53.join(store, "budget");
31587
+ var agentBase = (store, session, agentId) => path53.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
31332
31588
  var spawnBudget = (prompt) => {
31333
31589
  const found = /^TIMEBOX:[^\n]*?\b(\d+)\s+tool calls\b/mu.exec(prompt);
31334
31590
  const n = found ? Number(found[1]) : NaN;
@@ -31336,7 +31592,7 @@ var spawnBudget = (prompt) => {
31336
31592
  };
31337
31593
  var readBudget = (file) => {
31338
31594
  try {
31339
- const { limit, told } = JSON.parse(fs32.readFileSync(file, "utf8"));
31595
+ const { limit, told } = JSON.parse(fs33.readFileSync(file, "utf8"));
31340
31596
  return typeof limit === "number" && limit > 0 ? { limit, told: Number(told) || 0 } : null;
31341
31597
  } catch {
31342
31598
  return null;
@@ -31344,16 +31600,16 @@ var readBudget = (file) => {
31344
31600
  };
31345
31601
  var startBudget = (store, session, agentId, n) => {
31346
31602
  const dir = budgetDir(store);
31347
- fs32.mkdirSync(dir, { recursive: true });
31603
+ fs33.mkdirSync(dir, { recursive: true });
31348
31604
  const cutoff = Date.now() - 604800000;
31349
- for (const name of fs32.readdirSync(dir))
31605
+ for (const name of fs33.readdirSync(dir))
31350
31606
  try {
31351
- if (fs32.statSync(path51.join(dir, name)).mtimeMs < cutoff)
31352
- fs32.rmSync(path51.join(dir, name));
31607
+ if (fs33.statSync(path53.join(dir, name)).mtimeMs < cutoff)
31608
+ fs33.rmSync(path53.join(dir, name));
31353
31609
  } catch {}
31354
31610
  const base = agentBase(store, session, agentId);
31355
- fs32.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
31356
- fs32.rmSync(`${base}.calls`, { force: true });
31611
+ fs33.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
31612
+ fs33.rmSync(`${base}.calls`, { force: true });
31357
31613
  };
31358
31614
  var bindBudget = (cwd, session, agentId, prompt) => {
31359
31615
  try {
@@ -31376,8 +31632,8 @@ var tickBudget = (cwd, session, agentId) => {
31376
31632
  const budget = readBudget(`${base}.json`);
31377
31633
  if (!budget)
31378
31634
  return false;
31379
- fs32.appendFileSync(`${base}.calls`, ".");
31380
- return fs32.statSync(`${base}.calls`).size >= budget.limit * (budget.told + 1);
31635
+ fs33.appendFileSync(`${base}.calls`, ".");
31636
+ return fs33.statSync(`${base}.calls`).size >= budget.limit * (budget.told + 1);
31381
31637
  } catch {
31382
31638
  return false;
31383
31639
  }
@@ -31389,14 +31645,14 @@ var reachedOf = (cwd, session, agentId) => {
31389
31645
  const budget = base && readBudget(`${base}.json`);
31390
31646
  if (!budget)
31391
31647
  return null;
31392
- return { base, budget, reached: Math.floor(fs32.statSync(`${base}.calls`).size / budget.limit) };
31648
+ return { base, budget, reached: Math.floor(fs33.statSync(`${base}.calls`).size / budget.limit) };
31393
31649
  };
31394
31650
  var budgetLine = (cwd, session, agentId) => {
31395
31651
  try {
31396
31652
  const at = reachedOf(cwd, session, agentId);
31397
31653
  if (!at || at.reached <= at.budget.told)
31398
31654
  return null;
31399
- fs32.writeFileSync(`${at.base}.json`, JSON.stringify({ ...at.budget, told: at.reached }));
31655
+ fs33.writeFileSync(`${at.base}.json`, JSON.stringify({ ...at.budget, told: at.reached }));
31400
31656
  return lineFor(at.budget.limit * at.reached);
31401
31657
  } catch {
31402
31658
  return null;
@@ -31804,12 +32060,12 @@ var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? n
31804
32060
  // packages/workit-pi/src/launches.ts
31805
32061
  import { mkdirSync as mkdirSync7, readFileSync as readFileSync16, readdirSync as readdirSync8, rmSync as rmSync4, writeFileSync as writeFileSync6 } from "node:fs";
31806
32062
  import os12 from "node:os";
31807
- import path52 from "node:path";
32063
+ import path54 from "node:path";
31808
32064
  var launchDir = (root) => {
31809
32065
  const location = resolveStore(root);
31810
- return location instanceof Error ? null : path52.join(location.dir, "pi-launches");
32066
+ return location instanceof Error ? null : path54.join(location.dir, "pi-launches");
31811
32067
  };
31812
- var fileFor = (dir, workerId) => path52.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
32068
+ var fileFor = (dir, workerId) => path54.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
31813
32069
  var recordLaunch = (root, attempt) => {
31814
32070
  const dir = launchDir(root);
31815
32071
  if (!dir)
@@ -31855,7 +32111,7 @@ var abandonedLaunches = (root) => {
31855
32111
  const found = [];
31856
32112
  for (const name of names) {
31857
32113
  try {
31858
- const attempt = JSON.parse(readFileSync16(path52.join(dir, name), "utf8"));
32114
+ const attempt = JSON.parse(readFileSync16(path54.join(dir, name), "utf8"));
31859
32115
  if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
31860
32116
  if (!alive(attempt))
31861
32117
  found.push(attempt);
@@ -31866,87 +32122,6 @@ var abandonedLaunches = (root) => {
31866
32122
  };
31867
32123
  var cancelHint = (workerId) => `cancel it first: workit_worker {"action":"cancel","workerId":"${workerId}","reason":"launch outcome unknown"} (CLI: workit worker cancel --payload '{"workerId":"${workerId}","reason":"launch outcome unknown"}')`;
31868
32124
 
31869
- // packages/workit-core/src/core/cli-locate.ts
31870
- import { closeSync as closeSync5, existsSync as existsSync17, openSync as openSync5, readSync as readSync2 } from "node:fs";
31871
- import path53 from "node:path";
31872
- var LAUNCHER_MARKER = "workit-owned-launcher";
31873
- var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
31874
- var installRoot = (env, platform = process.platform) => {
31875
- if (env.WORKIT_INSTALL_ROOT)
31876
- return env.WORKIT_INSTALL_ROOT;
31877
- const data = dataDir(env, platform);
31878
- return platform === "win32" ? path53.join(data, "install") : data;
31879
- };
31880
- var ownedLauncherPath = (env, platform = process.platform) => path53.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
31881
- var ownedCurrentEntry = (env, platform = process.platform) => path53.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
31882
- var head = (file) => {
31883
- let fd;
31884
- try {
31885
- fd = openSync5(file, "r");
31886
- const buffer = Buffer.alloc(256);
31887
- const read = readSync2(fd, buffer, 0, buffer.length, 0);
31888
- return buffer.subarray(0, read).toString("utf8");
31889
- } catch {
31890
- return "";
31891
- } finally {
31892
- if (fd !== undefined)
31893
- closeSync5(fd);
31894
- }
31895
- };
31896
- var locateWorkitCli = (options = {}) => {
31897
- const env = options.env ?? process.env;
31898
- const platform = options.platform ?? process.platform;
31899
- const exists = options.exists ?? existsSync17;
31900
- const read = options.read ?? head;
31901
- const node = options.node ?? process.execPath;
31902
- const launcher = ownedLauncherPath(env, platform);
31903
- if (exists(launcher) && read(launcher).includes(LAUNCHER_MARKER))
31904
- return {
31905
- source: "owned-launcher",
31906
- command: launcher,
31907
- args: [],
31908
- binDir: path53.dirname(launcher)
31909
- };
31910
- const current = ownedCurrentEntry(env, platform);
31911
- if (exists(current))
31912
- return {
31913
- source: "owned-current",
31914
- command: node,
31915
- args: [current],
31916
- binDir: null
31917
- };
31918
- if (options.bundled && exists(options.bundled))
31919
- return {
31920
- source: "bundled",
31921
- command: node,
31922
- args: [options.bundled],
31923
- binDir: null
31924
- };
31925
- return { source: "path", command: "workit", args: [], binDir: null };
31926
- };
31927
- var pathKey = (env) => Object.keys(env).find((key) => key.toUpperCase() === "PATH") ?? "PATH";
31928
- var workitCliEnv = (located, env = process.env, platform = process.platform) => {
31929
- if (located.source === "path")
31930
- return {};
31931
- const patch = {
31932
- WORKIT_CLI: [located.command, ...located.args].join(" ")
31933
- };
31934
- if (located.binDir) {
31935
- const key = pathKey(env);
31936
- const delimiter = platform === "win32" ? ";" : ":";
31937
- const same = (dir) => platform === "win32" ? path53.win32.normalize(dir).toLowerCase() === path53.win32.normalize(located.binDir).toLowerCase() : path53.posix.normalize(dir) === path53.posix.normalize(located.binDir);
31938
- const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
31939
- patch[key] = [located.binDir, ...rest].join(delimiter);
31940
- }
31941
- return patch;
31942
- };
31943
- var useOwnedWorkitCli = (options = {}) => {
31944
- const env = options.env ?? process.env;
31945
- const located = locateWorkitCli({ ...options, env });
31946
- Object.assign(env, workitCliEnv(located, env, options.platform));
31947
- return located;
31948
- };
31949
-
31950
32125
  // packages/workit-pi/src/cli-path.ts
31951
32126
  var useOwnedCliInPi = (env = process.env) => useOwnedWorkitCli({ env });
31952
32127
 
@@ -32803,6 +32978,7 @@ function extension(pi) {
32803
32978
  }) + `
32804
32979
  `);
32805
32980
  sessions.delete(ctx.sessionManager.getSessionId());
32981
+ reapAtStart(ctx.cwd);
32806
32982
  reconcileLostWorkers(ctx);
32807
32983
  });
32808
32984
  const procNotice = (ctx) => {
@@ -32925,8 +33101,15 @@ ${nudge}` : content) };
32925
33101
  });
32926
33102
  return observeToolResult(event, ctx);
32927
33103
  };
32928
- pi.on("session_shutdown", (_event, ctx) => {
33104
+ pi.on("session_shutdown", (event, ctx) => {
32929
33105
  sessions.delete(ctx.sessionManager.getSessionId());
33106
+ endSession({
33107
+ host: "pi",
33108
+ session: ctx.sessionManager.getSessionId(),
33109
+ agentId: null,
33110
+ reason: typeof event?.reason === "string" ? event.reason : null,
33111
+ cwd: ctx.cwd
33112
+ });
32930
33113
  });
32931
33114
  }
32932
33115
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/pi",
3
- "version": "2.13.0",
3
+ "version": "2.15.0",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",
@@ -39,7 +39,7 @@ units of ~100+ lines each. Coupled work stays with one owner. Workit never spawn
39
39
  6. **Retry once, then escalate.** A stuck or failed slice gets one retry with
40
40
  a fresh brief (`workit fanout brief <slice> --mode resume`, same branch);
41
41
  if that fails too, re-slice it, take it over, or report the gap. Never
42
- chain resumes. A fix round and recheck that both fail: a decider, not a
42
+ chain resumes. A fix round and recheck that both fail: the decider agent, not a
43
43
  third round; product choices go to the user (`references/orchestration.md`).
44
44
  7. **Verify by the workspace `verification` setting** (`workit grant show`).
45
45
  A report is a pointer, never evidence. `proportional` (default): each slice's lane (`workit pr status`) decides; none needs no verdict, self the author's `--self`, focused and full a verifier (Claude Code: the `model` and `effort` of `workit models show --role verifier`) after the last push; one verdict at a stack's top covers its unchanged lower PRs, and a stale one with `reverify: focused` re-checks only the new diff, reusing green CI. `self`: a verifier that wrote none
@@ -5,35 +5,37 @@ and fans in. Workit records and checks; the host's own subagents run the work.
5
5
 
6
6
  ## TIER to model
7
7
 
8
- TIER is a field of each slice and of its brief. Role models come from the
9
- workspace (`models.roles`; `fanout.tierModels` still feeds the implementer
10
- tiers) and, on Claude Code, built-in defaults: the brief has a `model:` line
11
- (with `effort:` when set) under TIER and a `verifier:` line; `workit fanout
12
- status` names the model next to each spawnable slice; `workit models show
13
- [--role r] [--host h] --json` lists every role (decider, implementer tiers,
14
- verifier, reviewer, explore, babysit). Pass exactly that `model` (and `effort`
15
- where the host's spawn call takes one) on the spawn call: a subagent that
16
- passes none inherits your model. Scouting and PR babysitting use the `explore`
17
- and `babysit` roles. A role with no model (other hosts without config) runs
18
- on the host's model, and TIER only sizes the timebox and decides whether to
19
- race. Claude Code's built-in defaults, when nothing is configured:
20
-
21
- | Role or TIER | `model` on the Agent call |
8
+ TIER is a field of each slice and of its brief. Each Workit role is a host
9
+ agent that carries its own model: spawn it by name and pass no `model` or
10
+ `effort` unless the user named one (a named model always wins).
11
+
12
+ | Host | Spawn by name |
13
+ | --- | --- |
14
+ | Claude Code | `workit:implementer`, `workit:verifier`, `workit:reviewer`, `workit:decider`, `workit:babysitter`; search: `Explore` |
15
+ | OpenCode | `workit-implementer`, `workit-verifier`, `workit-reviewer`, `workit-decider`, `workit-babysitter` |
16
+ | Codex | the same `workit-*` names |
17
+ | Cursor | `workit-verifier`, `workit-reviewer`, `workit-decider`, `workit-babysitter` |
18
+
19
+ Claude Code, with nothing configured (pass a brief's `SPAWN:` line as printed):
20
+
21
+ | Role or TIER | Model |
22
22
  | --- | --- |
23
- | decider | `fable`, effort `high` |
24
- | hard | `opus` |
25
- | standard | `sonnet` |
26
- | mundane | `haiku` |
27
- | verifier | `sonnet` |
28
- | reviewer | `opus` |
29
- | explore, babysit | `haiku` |
30
-
31
- Claude Code and OpenCode also get the role's model set on the spawn by
32
- Workit; a configured one beats a `model` you pass unless
33
- `models.allowLeadOverride` is true. A general spawn takes
34
- `models.roles.default`, or the role its prompt's `ROLE: <role>` line names.
35
- `models.lead` (your own model) is advisory. `workit models show` marks each
36
- role `enforced` or `advisory` per host: on advisory, pass the model.
23
+ | decider | `fable`, effort `high` (agent file) |
24
+ | hard | `opus` (the brief's SPAWN line) |
25
+ | standard, verifier | `sonnet` (agent file) |
26
+ | mundane | `haiku` (the brief's SPAWN line) |
27
+ | reviewer | `opus` (agent file) |
28
+ | babysitter | `haiku` (agent file) |
29
+
30
+ A role
31
+ configured in `models.roles` to another model is listed in your session
32
+ contract (Claude Code) or set on the host's agent (OpenCode, Codex); `workit
33
+ models show [--role r] [--host h]` prints per host whether it comes from the
34
+ `agent file`, a `spawn fill` or is `advisory` (pass it yourself), and the
35
+ `models.enforce` mode. Under `strict` a configured role model beats a named
36
+ one and Claude Code's auto mode denies a spawn that lacks it. A role with no
37
+ model runs on the host's model, and TIER only sizes the timebox and decides
38
+ whether to race. `models.lead` (your own model) is advisory.
37
39
 
38
40
  ## Rolling window
39
41
 
@@ -66,10 +68,9 @@ reversibility (the option cheapest to undo wins a tie), and the exact change
66
68
  list. The fixer applies that list once, then one focused recheck follows.
67
69
 
68
70
  - Hard call (shared contract, security, migration): two deciders on different
69
- models (Claude Code, OpenCode, Cursor: the `decider` role model and a
70
- different `model` on the spawn, kept on a configured decider role only with
71
- `models.allowLeadOverride`; Codex and Pi: one decider). If they disagree, you take the
72
- more reversible option.
71
+ models (Claude Code, OpenCode, Cursor: one bare decider spawn and one that
72
+ names another `model`; Codex and Pi: one decider). If they disagree, you
73
+ take the more reversible option.
73
74
  - Record it: `workit ledger decision "<pick>" --by decider --why "<why it is
74
75
  the more reversible>" --view "<decider A: view>" --view "<decider B: view>"`.
75
76
  The row is listed as a decider call; it is never the user's answer to a
@@ -45,7 +45,7 @@ those files since the judged head and reuse green CI there (no fresh install, no
45
45
  under your own session (the one the lead or the hook gave you).
46
46
  8. **Bound the loop.** A failed verdict gets one fix round and one recheck of
47
47
  the changed hunks. Still failing, or stuck: no third round; the lead spawns
48
- a decider (read the `workit-fanout` skill's SKILL.md and follow it). A product choice goes to the user.
48
+ the decider agent by name, no model (read the `workit-fanout` skill's SKILL.md and follow it). A product choice: the user.
49
49
  9. **Harness note** (optional): friction caused by the repo or harness, not
50
50
  the change (a flaky fixture, a missing check, a misleading doc or skill
51
51
  line), goes on its own `Harness note:` line in the report and any PR
@@ -29,7 +29,7 @@ once the verdict is accepted. `merged`: step 7. `null` (closed, not merged):
29
29
  stop and report. Stop early only for a new consequential choice, a host
30
30
  denial, a review comment that needs a product decision, a required update
31
31
  that repeats because the base keeps moving, or after 3 failed fix attempts on
32
- the same check. Fix round and recheck both failed: a decider (read the `workit-fanout` skill's SKILL.md and follow it).
32
+ the same check. Fix round and recheck both failed: the decider agent (read the `workit-fanout` skill's SKILL.md and follow it).
33
33
 
34
34
  1. **Open.** Last before the PR, if `workit grant show` has `changelog: update|create`: write the Unreleased entry with `workit changelog apply`, commit it; with `docs: when-user-facing` fix only docs the diff made false (`references/changelog.md`).
35
35
  Full local check (`workit check ci` when `.workit/checks.json` has a `ci` group), push once: `workit git push`, then `workit pr template` and fill the template it prints: every heading, each `<!-- -->` replaced (Workit's: `references/pr-body.md`).