@ordewell/core 0.13.2 → 0.13.3

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 (45) hide show
  1. package/dist/{ModeResolver-BmG9O08A.d.ts → ModeResolver-CXGnEhbN.d.ts} +1 -1
  2. package/dist/{ModeResolver-CNKcOksr.d.mts → ModeResolver-DqpwKbfJ.d.mts} +1 -1
  3. package/dist/{Task-CH1z4L3h.d.mts → Task-TFPWtKoz.d.mts} +2 -0
  4. package/dist/{Task-CH1z4L3h.d.ts → Task-TFPWtKoz.d.ts} +2 -0
  5. package/dist/{chunk-7ACNW5CD.mjs → chunk-4OARA73Z.mjs} +2 -2
  6. package/dist/{chunk-3P5UIXTR.mjs → chunk-5ETS2NIB.mjs} +13 -3
  7. package/dist/{chunk-3P5UIXTR.mjs.map → chunk-5ETS2NIB.mjs.map} +1 -1
  8. package/dist/{chunk-I436RXQT.mjs → chunk-62MSJNOG.mjs} +3 -3
  9. package/dist/{chunk-I436RXQT.mjs.map → chunk-62MSJNOG.mjs.map} +1 -1
  10. package/dist/{chunk-MGMQKUIJ.mjs → chunk-DFRDXOEG.mjs} +15 -5
  11. package/dist/chunk-DFRDXOEG.mjs.map +1 -0
  12. package/dist/{chunk-O52PN7P2.mjs → chunk-FOGPFLRO.mjs} +4 -4
  13. package/dist/chunk-FOGPFLRO.mjs.map +1 -0
  14. package/dist/daemon-client.js +14 -4
  15. package/dist/daemon-client.js.map +1 -1
  16. package/dist/daemon-client.mjs +1 -1
  17. package/dist/{eventStore-ClHaWY9b.d.mts → eventStore-D9Kv5dTu.d.mts} +27 -2
  18. package/dist/{eventStore-s1fpKwFe.d.ts → eventStore-DeuZxnKm.d.ts} +27 -2
  19. package/dist/index.d.mts +21 -12
  20. package/dist/index.d.ts +21 -12
  21. package/dist/index.js +1487 -1362
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +1104 -1002
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/{maxParallel-fSAdLIMh.d.mts → maxParallel-CSTmqKeu.d.mts} +44 -8
  26. package/dist/{maxParallel-DXvhdlD5.d.ts → maxParallel-Ds9VI1KO.d.ts} +44 -8
  27. package/dist/parsing.d.mts +2 -2
  28. package/dist/parsing.d.ts +2 -2
  29. package/dist/parsing.js +1 -1
  30. package/dist/parsing.js.map +1 -1
  31. package/dist/parsing.mjs +3 -3
  32. package/dist/plan-utils.d.mts +4 -4
  33. package/dist/plan-utils.d.ts +4 -4
  34. package/dist/plan-utils.js.map +1 -1
  35. package/dist/plan-utils.mjs +3 -3
  36. package/dist/testing.d.mts +4 -2
  37. package/dist/testing.d.ts +4 -2
  38. package/dist/testing.js +2 -0
  39. package/dist/testing.js.map +1 -1
  40. package/dist/testing.mjs +3 -1
  41. package/dist/testing.mjs.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/chunk-MGMQKUIJ.mjs.map +0 -1
  44. package/dist/chunk-O52PN7P2.mjs.map +0 -1
  45. /package/dist/{chunk-7ACNW5CD.mjs.map → chunk-4OARA73Z.mjs.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/services/JsonExtractor.ts","../src/services/ModeResolver.ts","../src/services/Mandate.ts","../src/models/Delegation.ts","../src/services/PlannedTask.ts","../src/services/TaskAssignment.ts","../src/services/TaskSpec.ts","../src/services/PlanValidator.ts"],"sourcesContent":["/** The envelope key a full plan reply is keyed by: `{\"tasks\":[...]}`. */\nexport const PLAN_ENVELOPE_KEY = 'tasks';\n/** The envelope key a targeted-edits reply is keyed by: `{\"taskOps\":[...]}`. */\nexport const TASK_OPS_ENVELOPE_KEY = 'taskOps';\n/** The envelope key a read-only detail request is keyed by: `{\"taskQuery\":{...}}`. */\nexport const TASK_QUERY_ENVELOPE_KEY = 'taskQuery';\n\n/** Thrown when an LLM plan response cannot be parsed into a valid plan. Carries the raw text so callers can log it or retry. */\nexport class PlanParseError extends Error {\n readonly raw: string;\n /**\n * True when the reply was cut off mid-object (output-token limit) rather\n * than malformed — the two need different repairs: a truncated emission will\n * be cut at the same point again unless the retry frees context or asks for\n * terser output.\n */\n readonly truncated: boolean;\n /**\n * True when the JSON parsed fine and a *shape* rule rejected it. The generic\n * \"could not be parsed as JSON\" corrective is a lie for these, so the model\n * re-sends the same object; a semantic rejection must be repaired by naming\n * the rule it broke.\n */\n readonly semantic: boolean;\n constructor(message: string, raw: string, opts?: { truncated?: boolean; semantic?: boolean }) {\n super(message);\n this.name = 'PlanParseError';\n this.raw = raw;\n this.truncated = opts?.truncated ?? false;\n this.semantic = opts?.semantic ?? false;\n }\n}\n/**\n * Strip the noise reasoning models wrap around their answer: markdown code\n * fences and `<think>…</think>` chain-of-thought blocks (which routinely contain\n * stray braces that would otherwise derail brace-balancing). Reasoning captured\n * out-of-band by the service never reaches here, but a model that inlines its\n * thinking in the content channel still must not corrupt parsing.\n */\nexport function stripModelNoise(raw: string): string {\n return raw\n .replace(/<think>[\\s\\S]*?<\\/think>/gi, '')\n .replace(/```json\\s*/gi, '')\n .replace(/```\\s*/g, '')\n .trim();\n}\n\nconst THINK_OPEN = '<think>';\nconst THINK_CLOSE = '</think>';\nconst FENCE = '```';\nconst FENCE_JSON_TAG = 'json';\n\n/**\n * Whether a reply that begins with `prefix` opens with a JSON object once the\n * noise {@link stripModelNoise} removes is skipped — the streaming counterpart\n * of it, answering from the start of a reply that has not finished arriving.\n * Undefined while the prefix cannot tell yet: blank, inside an unclosed think\n * block, or partway through a fence or a tag.\n */\nexport function opensWithJsonObject(prefix: string): boolean | undefined {\n let rest = prefix;\n for (;;) {\n rest = rest.trimStart();\n if (!rest) return undefined;\n const head = rest.slice(0, THINK_OPEN.length).toLowerCase();\n if (head === THINK_OPEN) {\n const close = rest.toLowerCase().indexOf(THINK_CLOSE);\n if (close < 0) return undefined;\n rest = rest.slice(close + THINK_CLOSE.length);\n continue;\n }\n if (rest.startsWith(FENCE)) {\n rest = rest.slice(FENCE.length);\n const tag = rest.slice(0, FENCE_JSON_TAG.length).toLowerCase();\n if (tag === FENCE_JSON_TAG) rest = rest.slice(FENCE_JSON_TAG.length);\n else if (tag === rest.toLowerCase() && FENCE_JSON_TAG.startsWith(tag)) return undefined;\n continue;\n }\n if (THINK_OPEN.startsWith(head) || FENCE.startsWith(rest)) return undefined;\n return rest.startsWith('{');\n }\n}\n\n/**\n * Scan from `start` (which must point at a `{`) for the matching balanced close,\n * ignoring braces inside strings. Returns the object substring and whether it was\n * balanced; an unbalanced result means the input was truncated mid-object.\n */\nfunction balancedObjectAt(text: string, start: number): { json: string; balanced: boolean } {\n let depth = 0;\n let inString = false;\n let escaped = false;\n for (let i = start; i < text.length; i++) {\n const ch = text[i];\n if (inString) {\n if (escaped) escaped = false;\n else if (ch === '\\\\') escaped = true;\n else if (ch === '\"') inString = false;\n continue;\n }\n if (ch === '\"') inString = true;\n else if (ch === '{') depth++;\n else if (ch === '}') {\n depth--;\n if (depth === 0) return { json: text.slice(start, i + 1), balanced: true };\n }\n }\n return { json: text.slice(start), balanced: false };\n}\n\n/**\n * Scan an LLM response for every balanced `{…}` object carrying a `\"<key>\":`\n * entry. Strips fences and `<think>` blocks first. A matching object is\n * skipped over wholesale, so its nested braces don't produce fragment\n * candidates; non-matching objects are descended into, so a match wrapped in\n * an unrelated outer object is still found. `fallback` preserves the legacy\n * behavior for callers with no keyed match: the first balanced object, else\n * the stripped text so a JSON.parse error still surfaces.\n */\nexport function extractObjectsWithKey(raw: string, key: string): {\n matches: string[];\n fallback: { json: string; balanced: boolean };\n sawBrace: boolean;\n /** An object ran to EOF unclosed — the classic signature of truncated output. */\n sawUnbalanced: boolean;\n} {\n const stripped = stripModelNoise(raw);\n const keyRe = new RegExp(`\"${key}\"\\\\s*:`);\n\n const matches: string[] = [];\n let firstObject: string | null = null;\n let sawBrace = false;\n let sawUnbalanced = false;\n let inString = false;\n let escaped = false;\n for (let i = 0; i < stripped.length; i++) {\n const ch = stripped[i];\n if (inString) {\n if (escaped) escaped = false;\n else if (ch === '\\\\') escaped = true;\n else if (ch === '\"') inString = false;\n continue;\n }\n if (ch === '\"') { inString = true; continue; }\n if (ch !== '{') continue;\n\n sawBrace = true;\n const obj = balancedObjectAt(stripped, i);\n // A stray brace in a reasoning preamble produces an unbalanced candidate,\n // which we skip so it can't swallow the real object that follows.\n if (obj.balanced && keyRe.test(obj.json)) {\n matches.push(obj.json);\n i += obj.json.length - 1;\n continue;\n }\n if (!obj.balanced) sawUnbalanced = true;\n if (!firstObject && obj.balanced) firstObject = obj.json;\n }\n\n return {\n matches,\n fallback: firstObject !== null ? { json: firstObject, balanced: true } : { json: stripped, balanced: false },\n sawBrace,\n sawUnbalanced,\n };\n}\n\n/**\n * Pull the JSON object out of an LLM response and report whether it was balanced.\n * Strips fences and `<think>` blocks, then walks every top-level `{…}` and\n * returns the FIRST one that contains a `\"tasks\"` key — so a brace appearing\n * earlier in reasoning (or an unrelated preamble object) can't make us parse the\n * wrong thing. Falls back to the first balanced object and, failing that, the\n * first `{` onwards so a genuine `JSON.parse` error still surfaces.\n */\nexport function extractObjectWithBalance(raw: string): { json: string; balanced: boolean; sawBrace: boolean } {\n const { matches, fallback, sawBrace } = extractObjectsWithKey(raw, PLAN_ENVELOPE_KEY);\n if (matches.length > 0) return { json: matches[0], balanced: true, sawBrace };\n return { ...fallback, sawBrace };\n}\n\n/**\n * Pull the JSON object out of an LLM response. Strips markdown code fences and\n * `<think>` blocks, prefers the object containing a `tasks` key, and tolerates a\n * prose preamble and trailing prose. Returns the fence-stripped text unchanged\n * if no `{` is present so the caller's JSON.parse produces a clear failure.\n */\nexport function extractJsonObject(raw: string): string {\n return extractObjectWithBalance(raw).json;\n}\n\n/** Drop trailing commas before a closing `}` or `]` — a common model quirk. */\nexport function stripTrailingCommas(json: string): string {\n return json.replace(/,(\\s*[}\\]])/g, '$1');\n}\n\n/**\n * Escape raw control characters that appear INSIDE string literals — budget\n * models routinely emit multi-line `prompt` strings with literal newlines,\n * which strict JSON.parse rejects (\"bad control character\"). Characters\n * outside strings (formatting whitespace) are left untouched.\n */\nexport function escapeControlCharsInStrings(json: string): string {\n let out = '';\n let inString = false;\n let escaped = false;\n for (const ch of json) {\n if (inString) {\n if (escaped) { out += ch; escaped = false; continue; }\n if (ch === '\\\\') { out += ch; escaped = true; continue; }\n if (ch === '\"') { out += ch; inString = false; continue; }\n if (ch === '\\n') { out += '\\\\n'; continue; }\n if (ch === '\\r') { out += '\\\\r'; continue; }\n if (ch === '\\t') { out += '\\\\t'; continue; }\n out += ch;\n continue;\n }\n if (ch === '\"') inString = true;\n out += ch;\n }\n return out;\n}\n","import { flattenTasks, type RunnerId, type Task } from '../models/Task';\n\nexport interface RunnerModeInfo {\n id: string;\n label: string;\n description: string;\n autonomous?: boolean;\n safe?: boolean;\n readOnly?: boolean;\n sandboxed?: boolean;\n /** Why this mode cannot be used on this host (a failed probe); such a mode is shown, never assigned. */\n unavailable?: string;\n}\n\n/** The slice of RunnerRegistry this module needs — structural, so nothing here depends on the manifest layer. */\nexport interface ManifestLookup {\n getManifest(runner: RunnerId): { modes?: RunnerModeInfo[] } | undefined;\n}\n\n/**\n * A runner's modes are declared only in its manifest, never through a service,\n * so every caller that needs them fuses registry and runner list by hand. This\n * is that fusion, in one place: the planner prompt, the mode pickers on each\n * surface, and the runner-change retarget all read modes the same way.\n *\n * A runner with no modes maps to `[]` rather than being dropped — callers\n * distinguish \"declares no modes\" from \"not asked about\".\n */\nexport function runnerModesFrom(registry: ManifestLookup, runners: RunnerId[]): Record<RunnerId, RunnerModeInfo[]> {\n return Object.fromEntries(runners.map((r) => [r, registry.getManifest(r)?.modes ?? []] as const));\n}\n\n/**\n * Find the mode ID a runner resolves to under the given toggle state.\n * Tag-based first (autonomous/safe); falls back to positional last non-plan\n * if no tag is present on any mode (degrades gracefully on untagged manifests).\n * Returns undefined if `modes` is empty or undefined.\n */\nexport function resolveDefaultMode(\n modes: readonly RunnerModeInfo[] | undefined,\n autonomousDefault = false,\n): string | undefined {\n if (!modes || modes.length === 0) return undefined;\n const tag: 'autonomous' | 'safe' = autonomousDefault ? 'autonomous' : 'safe';\n const tagged = modes.find((m) => m[tag]);\n if (tagged) return tagged.id;\n for (let i = modes.length - 1; i >= 0; i--) {\n if (!modes[i].readOnly && modes[i].id !== 'plan') return modes[i].id;\n }\n return undefined;\n}\n\n/** The user-facing name of the `autonomousMode` boolean's two states. */\nexport function autonomyLevelLabel(autonomous: boolean): 'Full' | 'Guarded' {\n return autonomous ? 'Full' : 'Guarded';\n}\n\n/** `full`/`guarded` name the levels; `on`/`off` and `auto` are older words for them. Null for anything else. */\nexport function parseAutonomyLevel(arg: string | undefined): boolean | null {\n switch (arg?.trim().toLowerCase()) {\n case 'full': case 'on': return true;\n case 'guarded': case 'auto': case 'off': return false;\n default: return null;\n }\n}\n\n/**\n * The level a flag or `ORDEWELL_AUTONOMOUS_MODE` names: the level names above,\n * plus the boolean spellings (`true`/`false`, `1`/`0`), case and surrounding\n * space aside. Undefined for anything else — a typo must never raise autonomy,\n * and the `.env` migration and the runtime override must read a value alike.\n */\nexport function parseAutonomyFlag(value: string | undefined): boolean | undefined {\n const normalized = value?.trim().toLowerCase();\n if (!normalized) return undefined;\n if (normalized === 'true' || normalized === '1') return true;\n if (normalized === 'false' || normalized === '0') return false;\n return parseAutonomyLevel(normalized) ?? undefined;\n}\n\n/**\n * The profile a manifest tags `readOnly` (ADR-0046) — never found by id, so a runner with no\n * tag has none. A mode this host cannot run is still the runner's read-only\n * mode: it is how a task already on it is recognized, and why a move of that\n * task is refused rather than made writable.\n */\nexport function taggedReadOnlyMode(modes: readonly RunnerModeInfo[] | undefined): string | undefined {\n return modes?.find((m) => m.readOnly)?.id;\n}\n\n/** The read-only profile a task can be given here; built-ins do not need the runner's native sandbox (ADR-0046). */\nexport function readOnlyMode(modes: readonly RunnerModeInfo[] | undefined): string | undefined {\n const mode = modes?.find((m) => m.readOnly);\n return mode && !mode.unavailable ? mode.id : undefined;\n}\n\n/** Why a mode cannot be used on this host, when it cannot. */\nexport function unavailableModeReason(modes: readonly RunnerModeInfo[] | undefined, id: string | undefined): string | undefined {\n return id === undefined ? undefined : modes?.find((m) => m.id === id)?.unavailable;\n}\n\nfunction unavailableModeError(runner: RunnerId, id: string, reason: string): string {\n return `Mode \"${id}\" of runner \"${runner}\" is unavailable on this host: ${reason}`;\n}\n\n/** What a task fails with at spawn when its planned mode is one this host cannot run; undefined when it can. */\nexport function unavailableTaskModeMessage(\n manifest: { displayName: string; modes?: readonly RunnerModeInfo[] },\n mode: string | undefined,\n): string | undefined {\n const reason = unavailableModeReason(manifest.modes, mode);\n return reason ? `Mode \"${mode}\" of ${manifest.displayName} is unavailable on this host: ${reason}` : undefined;\n}\n\n/** What the planner says about a task's mode (ADR-0031): read-only or not, and the mode the task has now, if any. */\nexport interface ModeRequest {\n readOnly?: boolean;\n current?: string;\n}\n\nexport type PlannedMode = { ok: true; mode: string | undefined } | { ok: false; error: string };\n\n/**\n * The mode a task the planner writes lands on (ADR-0031). The planner names no\n * mode: a read-only task gets its runner's read-only mode; any other keeps the\n * mode it has when the runner offers it — a mode the user picked survives an\n * edit that does not ask for a change — and otherwise gets the runner's mode\n * for the level. `readOnly: false` is the one request that moves a task off\n * its read-only mode. Undefined mode when the runner's modes are unknown.\n */\nexport function plannedMode(\n runner: RunnerId,\n runnerModes: Partial<Record<RunnerId, readonly RunnerModeInfo[]>> | undefined,\n { readOnly, current }: ModeRequest,\n autonomousDefault = false,\n): PlannedMode {\n if (!runnerModes) return { ok: true, mode: undefined };\n const modes = runnerModes[runner] ?? [];\n const readOnlyId = readOnlyMode(modes);\n if (readOnly === true) {\n if (readOnlyId) return { ok: true, mode: readOnlyId };\n const able = readOnlyRunners(runnerModes);\n const reason = unavailableModeReason(modes, taggedReadOnlyMode(modes));\n return {\n ok: false,\n error: `Runner \"${runner}\" has no read-only mode${reason ? ' available on this host' : ''}: assign a read-only task to ${able.length > 0 ? `one of: ${able.join(', ')}` : 'no runner: none of the enabled runners has one'}, or drop \"readOnly\"${reason ? `. ${reason}` : ''}`,\n };\n }\n const keep = current !== undefined && modes.some((m) => m.id === current) && !(readOnly === false && current === taggedReadOnlyMode(modes));\n const mode = keep ? current : resolveDefaultMode(modes, autonomousDefault);\n // Refused, never swapped for another mode: that would hand a task the\n // planner or user meant to be sandboxed a level of access nobody chose (ADR-0001).\n const reason = unavailableModeReason(modes, mode);\n if (mode !== undefined && reason) return { ok: false, error: unavailableModeError(runner, mode, reason) };\n return { ok: true, mode };\n}\n\n/**\n * A plan the planner restates over an existing one comes back with every mode\n * decided afresh. A restatement says read-only or not for each task, so that\n * answer stands; what it cannot say is a mode the user picked. So where a\n * task it names was planned before and is not read-only now, the earlier mode\n * is kept when its runner offers it — the rule an edit follows.\n */\nexport function carryPlannedModes(\n before: readonly Task[],\n rewrite: Task[],\n catalog: { runnerModes: Partial<Record<RunnerId, readonly RunnerModeInfo[]>>; autonomousDefault?: boolean },\n): Task[] {\n const prior = new Map(flattenTasks(before).map((t) => [t.id, t]));\n const carry = (t: Task): Task => {\n const subtasks = (t.subtasks ?? []).map(carry);\n const was = prior.get(t.id);\n if (t.type !== 'ai' || !was || was.type !== 'ai' || t.taskMode === taggedReadOnlyMode(catalog.runnerModes[t.assignedRunner])) return { ...t, subtasks };\n const mode = plannedMode(t.assignedRunner, catalog.runnerModes, { readOnly: false, current: was.taskMode }, catalog.autonomousDefault ?? false);\n return { ...t, subtasks, ...(mode.ok && mode.mode !== undefined ? { taskMode: mode.mode } : {}) };\n };\n return rewrite.map(carry);\n}\n\n/** The runners a read-only task may go to, as the planner's prompt names them. */\nexport function readOnlyRunners(runnerModes: Partial<Record<RunnerId, readonly RunnerModeInfo[]>>): RunnerId[] {\n return Object.entries(runnerModes).filter(([, ms]) => readOnlyMode(ms)).map(([id]) => id);\n}\n","import type { ExecutionCommandName, SupervisorLevel } from '../models/Execution';\nimport type { RunnerId, Task } from '../models/Task';\nimport type { EffectRules } from './effectAllowlist';\nimport { SHAPE_LIMITS, type TreeShape } from './runSettingsDefaults';\n\nexport { SHAPE_LIMITS, type TreeShape };\n\n/**\n * The mandate (ADR-0056): what a node may do without a person, and within what\n * limits. The root's is derived on each read from today's settings and never\n * saved; a child's is one pure function of its parent's and its request, which\n * can only narrow what the parent may hand on. Authority only: capability stays\n * at the boundary a session runs in, and a prompt enforces nothing.\n */\n\nexport const GRANTS = ['observe', 'steer', 'control', 'replan', 'approve', 'delegate', 'effect', 'research', 'merge'] as const;\n\n/** Each is a set of things a node may do unasked (M2). */\nexport type Grant = (typeof GRANTS)[number];\n\n/** What a mandate could not finish without: a child holds these unasked, and `narrow` refuses one that would lack any (M2). */\nexport const FLOOR_GRANTS: readonly Grant[] = ['observe', 'steer', 'control', 'replan', 'approve', 'merge'];\n\n/** What a child is given to run in when its task states no time (M3). */\nexport const DEFAULT_CHILD_WALL_CLOCK_MS = 24 * 60 * 60 * 1000;\n\nexport interface MandateLimits {\n /** The node's token budget; the root's is the tree's, from the delegation setting (M3, M5). */\n tokens: number;\n /** Null: no limit, which only the root has. */\n wallClockMs: number | null;\n /** How many levels may still open below this node. */\n depth: number;\n delegatedTasks: number;\n tasksPerPlan: number;\n runners: readonly RunnerId[];\n /** The models a runner is held to; a runner not named may use any it offers, as the user's allowlist reads. */\n models: Readonly<Record<RunnerId, readonly string[]>>;\n}\n\nexport interface MandateExclusions {\n protectedPaths: readonly string[];\n}\n\nexport interface Mandate {\n /** What this node may do. */\n grants: ReadonlySet<Grant>;\n /** What it may hand a child. */\n grantable: ReadonlySet<Grant>;\n /** Read in place of the global level. */\n autonomy: 'full' | 'guarded';\n limits: MandateLimits;\n /** These only accumulate. */\n exclusions: MandateExclusions;\n /** One per level, each with its own `!` rules: a command must match at every level (M4). */\n effectRules: readonly EffectRules[];\n /** The level of `effectRules` this node's own request added: all of it a node keeps, the levels above being read as they stand (M1). */\n ownEffectRules: readonly EffectRules[];\n}\n\n/** What the root's mandate is read from, each where it lives today (M1). */\nexport interface RootSettings {\n /** The run's own copy: where a guard or a failure lowers it, and the user's change lands. */\n level: SupervisorLevel;\n autorun: boolean;\n autonomous: boolean;\n /** The tree's budget; 0 is delegation off (ADR-0055 D21). */\n delegationTokens: number;\n /** The tree's shape as the user set it; what it leaves out is at its default (ADR-0055 D19). */\n shape?: Partial<TreeShape>;\n /** The effect allowlist, absent where nothing was read. */\n effects?: EffectRules;\n runners: readonly RunnerId[];\n models: Readonly<Record<RunnerId, readonly string[]>>;\n}\n\n/** What a delegated task asks of the mandate it is given. `grants` names what it asks for past the floor; absent asks for nothing. */\nexport interface MandateRequest {\n /** The level of the node narrowing, the root being 0: the one a refusal names. */\n level: number;\n grants?: readonly Grant[];\n autonomy?: Mandate['autonomy'];\n /** A delegated task must carry one (M5). */\n tokens?: number;\n wallClockMs?: number;\n depth?: number;\n delegatedTasks?: number;\n tasksPerPlan?: number;\n runners?: readonly RunnerId[];\n models?: Readonly<Record<RunnerId, readonly string[]>>;\n protectedPaths?: readonly string[];\n effectRules?: EffectRules;\n}\n\nexport interface MandateRefusal {\n level: number;\n field: string;\n asked: string;\n there: string;\n}\n\nexport type Narrowed = { ok: true; mandate: Mandate } | { ok: false; refusal: MandateRefusal };\n\nexport function mandateRefusalText({ level, field, asked, there }: MandateRefusal): string {\n return `Level ${level} refused ${field}: asked ${asked}, and there is ${there}.`;\n}\n\n/** By the level alone: autorun, autonomy, the effect allowlist and delegation are settings of their own (M2). */\nconst LEVEL_GRANTS: Record<SupervisorLevel, readonly Grant[]> = {\n off: ['research'],\n watch: ['observe', 'research'],\n act: ['observe', 'steer', 'control', 'replan', 'research', 'merge'],\n};\n\n/** What delegation on lets a subplanner hold, whatever the root's level: the level is what the root planner does in its own turns (M2). */\nconst DELEGATED_GRANTS: readonly Grant[] = [...FLOOR_GRANTS, 'research', 'delegate'];\n\n/** A root's shape limit: the user's, held within 1 and D19's hard cap, as a child's is held within its parent's (ADR-0055 D19). */\nfunction rootShape(shape: Partial<TreeShape> | undefined, limit: keyof TreeShape): number {\n const { default: fallback, hard } = SHAPE_LIMITS[limit];\n const set = shape?.[limit];\n return set === undefined || !Number.isFinite(set) ? fallback : Math.min(hard, Math.max(1, Math.floor(set)));\n}\n\n/**\n * The root's mandate, as it stands now (M1): built afresh on each read, so an\n * Act that a guard lowered reads Watch at the next check, and nothing saved\n * could disagree with the settings.\n */\nexport function rootMandate(settings: RootSettings): Mandate {\n const effect = (settings.effects?.rules.length ?? 0) > 0;\n const delegation = settings.delegationTokens > 0;\n const effectRules = settings.effects ? [settings.effects] : [];\n return {\n grants: new Set<Grant>([\n ...LEVEL_GRANTS[settings.level],\n ...(settings.autorun ? ['approve' as const] : []),\n ...(effect ? ['effect' as const] : []),\n ...(delegation ? ['delegate' as const] : []),\n ]),\n grantable: new Set<Grant>(delegation ? [...DELEGATED_GRANTS, ...(effect ? ['effect' as const] : [])] : []),\n autonomy: settings.autonomous ? 'full' : 'guarded',\n limits: {\n tokens: settings.delegationTokens,\n wallClockMs: null,\n depth: rootShape(settings.shape, 'depth'),\n delegatedTasks: rootShape(settings.shape, 'delegatedTasks'),\n tasksPerPlan: rootShape(settings.shape, 'tasksPerPlan'),\n runners: settings.runners,\n models: settings.models,\n },\n exclusions: { protectedPaths: [] },\n effectRules,\n ownEffectRules: effectRules,\n };\n}\n\n/**\n * What holds at a node now (M1): its saved mandate within every ancestor's\n * `grantable` as it stands, under every ancestor's effect rules as they stand,\n * so a change at the root reaches the subtree at the next check. This reading\n * intersects and refuses nothing: the floor binds {@link narrow}, which writes\n * a new child, not this.\n */\nexport function heldMandate(saved: Mandate, ancestors: readonly Mandate[]): Mandate {\n const within = (grants: ReadonlySet<Grant>) => new Set([...grants].filter((grant) => ancestors.every((ancestor) => ancestor.grantable.has(grant))));\n const effectRules = [...ancestors.flatMap((ancestor) => ancestor.effectRules), ...saved.ownEffectRules];\n return { ...saved, grants: within(saved.grants), grantable: within(saved.grantable), effectRules };\n}\n\ntype Ruled<T> = { value: T } | { refused: Omit<MandateRefusal, 'level'> };\n\ntype Rules<Of, From> = { [K in keyof Of]-?: (parent: From, request: MandateRequest) => Ruled<Of[K]> };\n\nconst listed = (grants: Iterable<Grant>): string => [...grants].sort().join(', ') || 'nothing';\n\nconst lesser = (limit: 'delegatedTasks' | 'tasksPerPlan') => (parent: MandateLimits, request: MandateRequest): Ruled<number> => {\n const { hard } = SHAPE_LIMITS[limit];\n const asked = request[limit];\n if (asked !== undefined && asked > hard) return { refused: { field: `limits.${limit}`, asked: String(asked), there: `a hard limit of ${hard}` } };\n return { value: Math.min(parent[limit], asked ?? parent[limit]) };\n};\n\n/**\n * An empty list allows any model, as the user's allowlist reads, so a set that\n * keeps nothing is refused here: written down, it would be the widest answer.\n */\nfunction intersectModels(parent: MandateLimits['models'], asked: MandateLimits['models'] = {}): Ruled<MandateLimits['models']> {\n const models: Record<RunnerId, readonly string[]> = { ...parent };\n for (const [runner, wanted] of Object.entries(asked)) {\n const held = parent[runner] ?? [];\n const kept = held.length > 0 ? held.filter((model) => wanted.includes(model)) : wanted;\n if (kept.length === 0) return { refused: { field: 'limits.models', asked: `${runner}: ${wanted.join(', ') || 'nothing'}`, there: `${runner}: ${held.join(', ') || 'any'}` } };\n models[runner] = kept;\n }\n return { value: models };\n}\n\nconst LIMIT_RULES: Rules<MandateLimits, MandateLimits> = {\n tokens: ({ tokens }, { tokens: asked }) => {\n if (asked === undefined || asked <= 0 || asked > tokens) return { refused: { field: 'limits.tokens', asked: asked === undefined ? 'none' : String(asked), there: String(tokens) } };\n return { value: asked };\n },\n wallClockMs: ({ wallClockMs: left }, { wallClockMs: asked }) => {\n if (asked === undefined) return { value: left === null ? DEFAULT_CHILD_WALL_CLOCK_MS : Math.min(left, DEFAULT_CHILD_WALL_CLOCK_MS) };\n if (asked <= 0 || (left !== null && asked > left)) return { refused: { field: 'limits.wallClockMs', asked: String(asked), there: left === null ? 'no limit' : String(left) } };\n return { value: asked };\n },\n depth: ({ depth }, { depth: asked }) => {\n if (depth <= 0) return { refused: { field: 'limits.depth', asked: 'a child', there: 'no depth left' } };\n const { hard } = SHAPE_LIMITS.depth;\n if (asked !== undefined && asked > hard) return { refused: { field: 'limits.depth', asked: String(asked), there: `a hard limit of ${hard}` } };\n return { value: Math.min(depth - 1, asked ?? depth - 1) };\n },\n delegatedTasks: lesser('delegatedTasks'),\n tasksPerPlan: lesser('tasksPerPlan'),\n runners: ({ runners }, { runners: asked }) => {\n if (!asked) return { value: runners };\n const kept = runners.filter((runner) => asked.includes(runner));\n return kept.length > 0 ? { value: kept } : { refused: { field: 'limits.runners', asked: asked.join(', ') || 'nothing', there: runners.join(', ') || 'nothing' } };\n },\n models: ({ models }, { models: asked }) => intersectModels(models, asked),\n};\n\n/** Both `grants` and `grantable`: a child hands on what it holds. `research`, `delegate` and `effect` come only by name (M2). */\nfunction handedOn(parent: Mandate, request: MandateRequest): Ruled<ReadonlySet<Grant>> {\n const asked = new Set<Grant>([...FLOOR_GRANTS, ...(request.grants ?? [])]);\n const lost = FLOOR_GRANTS.some((grant) => !parent.grantable.has(grant));\n if (lost) return { refused: { field: 'grants', asked: listed(asked), there: listed(parent.grantable) } };\n return { value: new Set([...asked].filter((grant) => parent.grantable.has(grant))) };\n}\n\n/** Each field's rule. Mapped over the keys, so a new field or limit fails to compile until it has one. */\nconst MANDATE_RULES: Rules<Mandate, Mandate> = {\n grants: handedOn,\n grantable: handedOn,\n autonomy: ({ autonomy }, { autonomy: asked }) => ({ value: autonomy === 'guarded' || asked === 'guarded' ? 'guarded' : 'full' }),\n limits: ({ limits }, request) => applyRules<MandateLimits, MandateLimits>(LIMIT_RULES, limits, request),\n exclusions: ({ exclusions }, { protectedPaths }) => ({ value: { protectedPaths: [...new Set([...exclusions.protectedPaths, ...(protectedPaths ?? [])])] } }),\n effectRules: ({ effectRules }, { effectRules: asked }) => ({ value: asked ? [...effectRules, asked] : effectRules }),\n ownEffectRules: (_parent, { effectRules: asked }) => ({ value: asked ? [asked] : [] }),\n};\n\nfunction applyRules<Of extends object, From>(rules: Rules<Of, From>, parent: From, request: MandateRequest): Ruled<Of> {\n const value = {} as Of;\n for (const key of Object.keys(rules) as (keyof Of)[]) {\n const ruled = rules[key](parent, request);\n if ('refused' in ruled) return ruled;\n value[key] = ruled.value;\n }\n return { value };\n}\n\n/**\n * A child's mandate (M4), or the refusal that names the level that refused,\n * the field, what was asked and what is there. Pure, and written to be proved:\n * no result is wider than its parent. `parent.limits.tokens` and `wallClockMs`\n * are what the parent has left, which is the caller's to read.\n */\nexport function narrow(parent: Mandate, request: MandateRequest): Narrowed {\n const ruled = applyRules<Mandate, Mandate>(MANDATE_RULES, parent, request);\n return 'refused' in ruled\n ? { ok: false, refusal: { level: request.level, ...ruled.refused } }\n : { ok: true, mandate: ruled.value };\n}\n\n/** What a delegated task asks of the mandate it is given (M4), written the one way plan time and the carve both read. */\nexport function delegatedRequest(task: Pick<Task, 'grants' | 'budget' | 'protectedPaths'>, level: number): MandateRequest {\n return {\n level,\n ...(task.grants ? { grants: task.grants } : {}),\n ...(task.budget?.tokens !== undefined ? { tokens: task.budget.tokens } : {}),\n ...(task.budget?.wallClockMs !== undefined ? { wallClockMs: task.budget.wallClockMs } : {}),\n ...(task.protectedPaths ? { protectedPaths: task.protectedPaths } : {}),\n };\n}\n\n/**\n * What live settings leave of what a child's limits hold (M3): the settings can\n * take a runner or a model away from a running child and never hand one back,\n * so limits carved with a list stay a list when the user clears theirs. A\n * runner the two lists share no model on is taken away, for an empty list\n * would allow it any.\n */\nexport function withinLimits(limits: Pick<MandateLimits, 'runners' | 'models'>, enabled: readonly RunnerId[], allowlist: Readonly<Record<string, string[]>>): { runners: RunnerId[]; allowlist: Record<string, string[]> } {\n const models = { ...allowlist };\n const noneLeft = new Set<RunnerId>();\n for (const [runner, held] of Object.entries(limits.models)) {\n if (held.length === 0) continue;\n const live = allowlist[runner] ?? [];\n const kept = live.length > 0 ? held.filter((model) => live.includes(model)) : [...held];\n if (kept.length === 0) noneLeft.add(runner);\n models[runner] = kept.length > 0 ? kept : [...held];\n }\n return { runners: enabled.filter((runner) => limits.runners.includes(runner) && !noneLeft.has(runner)), allowlist: models };\n}\n\n/** The grant each command needs (M2); null for the user's own controls, which no grant reaches. */\nexport const COMMAND_GRANTS: Readonly<Record<ExecutionCommandName, Grant | null>> = {\n run_plan: 'control',\n run_task: 'control',\n stop_task: 'control',\n stop_run: 'control',\n retry_task: 'control',\n message_task: 'steer',\n answer_approval: 'steer',\n merge_all: 'merge',\n skip_task: 'control',\n force_start: null,\n mark_complete: null,\n mark_not_done: null,\n revert_task: null,\n interrupt_task: null,\n force_send_queued: null,\n remove_queued: null,\n cancel_resume: null,\n answer_checkpoint: 'steer',\n approve_review: null,\n run_script: 'control',\n};\n\n/** Whether a mandate lets a node run `command` unasked. */\nexport function allowsCommand(mandate: Mandate, command: ExecutionCommandName): boolean {\n const grant = COMMAND_GRANTS[command];\n return grant !== null && mandate.grants.has(grant);\n}\n\n/** Why a node refuses what its mandate leaves out, naming the level that refused (M4). */\nexport function missingGrant(depth: number, mandate: Mandate, needed: string): string {\n return `Level ${depth} refused this: it needs the ${needed} grant, and this node holds ${listed(mandate.grants)}.`;\n}\n\n/** Why a child's script may not run as it stands (M9). */\nexport const SCRIPT_PAST_THE_RULES = 'its body is not covered at every level of the effect rules, and it would run unsealed';\n\n/** A planner tool no grant reaches is a read, offered to every node. */\nconst TOOL_GRANTS: readonly (readonly [string, Grant])[] = [\n ...Object.entries(COMMAND_GRANTS).flatMap(([tool, grant]) => (grant ? [[tool, grant] as const] : [])),\n ['submit_plan', 'replan'],\n ['edit_plan', 'replan'],\n];\n\n/**\n * The planner tools a child's token leaves out (M6), in one order so the list\n * it is served is the same list on every start: a changed list breaks the\n * prompt cache. A courtesy, read as its session starts: what stops a call is\n * the seam, so a grant lost mid-session is refused with the list unchanged.\n */\nexport function withheldPlannerTools(mandate: Mandate): string[] {\n return TOOL_GRANTS.filter(([, grant]) => !mandate.grants.has(grant)).map(([tool]) => tool);\n}\n\n/** What a node reads of its own authority, at each check (M1). */\nexport interface NodeAuthority {\n /** How far below the root, which is 0 and where a person remains. */\n readonly depth: number;\n /** The mandate that holds now. `level` is what the root's is read at; a child's does not depend on it. */\n mandate(level: SupervisorLevel): Mandate;\n}\n\n/** The root: its settings read as each check asks, the level included, which each caller names. */\nexport function rootAuthority(settings: () => Omit<RootSettings, 'level'>): NodeAuthority {\n return { depth: 0, mandate: (level) => rootMandate({ ...settings(), level }) };\n}\n","import type { Task } from './Task';\nimport { GRANTS, type Grant } from '../services/Mandate';\nimport { flattenTasks } from './Task';\nimport { ONE_LINE, splitLines } from './lineBreaks';\nimport { taggedReadOnlyMode, type RunnerModeInfo } from '../services/ModeResolver';\n\n/** A delegated task's budget: tokens, and optionally wall-clock time (ADR-0056 M5). */\nexport interface DelegatedBudget {\n tokens: number;\n wallClockMs?: number;\n}\n\n/** Where a child plan's tasks stand now: the counts a delegated task's row shows while its child runs (ADR-0055 D20). */\nexport interface ChildTaskCounts {\n completed: number;\n running: number;\n /** Waiting on a person, a checkpoint among them. */\n waiting: number;\n pending: number;\n failed: number;\n skipped: number;\n}\n\n/**\n * What a delegated task's row says beyond any task's (ADR-0055 D16, D20): all of\n * it derived where it is read, from the child's plan, the tree's ledger and the\n * Stop, never kept. Every part is absent when there is nothing to say.\n */\nexport interface DelegatedRow {\n /** The child's tasks by where they stand; absent with no child session open. */\n tasks?: ChildTaskCounts;\n /** The task's token budget, and what the tree has not yet spent of it, across every child it has had (ADR-0056 M10). */\n tokens?: { budget: number; left: number };\n /** A Stop is still winding the subtree down, though the task already reads as not started (D16). */\n stopping?: true;\n}\n\nexport function countChildTasks(statuses: readonly Task['status'][]): ChildTaskCounts {\n const counts: ChildTaskCounts = { completed: 0, running: 0, waiting: 0, pending: 0, failed: 0, skipped: 0 };\n for (const status of statuses) {\n if (status === 'completed') counts.completed += 1;\n else if (status === 'in_progress') counts.running += 1;\n else if (status === 'awaiting_user') counts.waiting += 1;\n else if (status === 'failed') counts.failed += 1;\n else if (status === 'skipped') counts.skipped += 1;\n else counts.pending += 1;\n }\n return counts;\n}\n\n/** What a task declares it works on (ADR-0057 R6). Advisory: nothing gates on it. */\nexport interface TaskScope {\n paths?: string[];\n provides?: string[];\n consumes?: string[];\n}\n\n/** How long a scope's item is, and how many of each it holds: each can reach a line Ordewell writes (ADR-0057 R6). */\nexport const SCOPE_LIMITS = { item: 200, items: 50 } as const;\n\n/** The fields only a delegated task has. */\nexport const DELEGATED_FIELDS = ['goal', 'budget', 'grants', 'protectedPaths', 'scope'] as const satisfies readonly (keyof Task)[];\n\n/** Refused until something asks for it by name: a planner with no node behind it has no mandate to read. */\nexport const DELEGATION_UNAVAILABLE = 'delegation is not available in this session';\n\nexport function notOnADelegatedMessage(fields: readonly string[]): string {\n return `is a delegated task, which holds a goal for a child plan: leave out ${fields.map((f) => `\"${f}\"`).join(', ')}`;\n}\n\nexport interface DelegationError {\n taskId: string;\n field: string;\n message: string;\n}\n\nexport interface DelegationRules {\n /** The modes of each runner, for what makes an AI task read-only (ADR-0031). */\n runnerModes?: Partial<Record<string, readonly RunnerModeInfo[]>>;\n /** Whether a script can run sealed on this host (ADR-0036 S6); unknown reads as yes, since `checkPlanInvariants` is pure. */\n canSeal?: boolean;\n}\n\nfunction isBudget(value: unknown): value is DelegatedBudget {\n if (typeof value !== 'object' || value === null) return false;\n const { tokens } = value as { tokens?: unknown };\n return typeof tokens === 'number' && Number.isInteger(tokens) && tokens > 0;\n}\n\n/** A positive whole number of milliseconds, or none at all. */\nfunction wallClockOk(budget: DelegatedBudget): boolean {\n const { wallClockMs } = budget;\n return wallClockMs === undefined || (Number.isInteger(wallClockMs) && wallClockMs > 0);\n}\n\n/** Whether `task` is an AI task that runs read-only, as its mode says (ADR-0031). */\nfunction readsOnly(task: Task, runnerModes: DelegationRules['runnerModes']): boolean {\n if (task.type !== 'ai') return false;\n const mode = runnerModes ? taggedReadOnlyMode(runnerModes[task.assignedRunner]) : 'plan';\n return mode !== undefined && task.taskMode === mode;\n}\n\n/** Whether nothing here can say what mode `task` runs in: its runner was switched off since, removed, or belongs to another machine. */\nfunction runnerUnread(task: Task, runnerModes: DelegationRules['runnerModes']): boolean {\n return task.type === 'ai' && runnerModes !== undefined && runnerModes[task.assignedRunner] === undefined;\n}\n\n/** Whether a task runs at the workspace root behind a merge gate, so it cannot be cut from the integration tip. */\nfunction atAGate(task: Task): boolean {\n return (task.type === 'script' && !task.readOnly) || task.ops === true;\n}\n\n/** Everything `taskId` depends on, directly or through other tasks. */\nfunction reaches(tasks: readonly Task[], from: Task, target: (task: Task) => boolean): boolean {\n const byId = new Map(tasks.map((t) => [t.id, t]));\n const seen = new Set<string>();\n const walk = (task: Task): boolean => task.dependencies.some((id) => {\n if (seen.has(id)) return false;\n seen.add(id);\n const dep = byId.get(id);\n return dep !== undefined && (target(dep) || walk(dep));\n });\n return walk(from);\n}\n\n/**\n * The rules a delegated task is held to on every route (ADR-0055 D1, D7, D8),\n * as `loopErrors` holds a loop: what it must carry, and its check. A check is a\n * task that directly depends on it, a read-only AI task or a script marked\n * `readOnly`, and on a `readOnly` delegated task only the first: it never lands,\n * so a script there would judge the unchanged baseline. Passing proves a list\n * of paths was written, not that it is whole (D7).\n */\nexport function delegationErrors(tasks: readonly Task[], rules: DelegationRules = {}): DelegationError[] {\n const errors: DelegationError[] = [];\n const delegated = tasks.filter((t) => t.type === 'delegated');\n const fail = (task: Task, field: string, message: string) => errors.push({ taskId: task.id, field, message });\n\n for (const task of delegated) {\n const where = `Task \"${task.title}\"`;\n if (typeof task.goal !== 'string' || !task.goal.trim()) fail(task, 'goal', `${where} is a delegated task with no \"goal\": say what its child plan must achieve`);\n if (!isBudget(task.budget)) fail(task, 'budget', `${where} is a delegated task with no \"budget\": give it {\"tokens\": <a whole number>}, and \"wallClockMs\" if it has a time limit`);\n else if (!wallClockOk(task.budget)) fail(task, 'budget', `${where} has a \"wallClockMs\" that is not a whole number of milliseconds above 0`);\n const paths = task.protectedPaths;\n if (!task.readOnly && (!Array.isArray(paths) || paths.length === 0 || !paths.every((p) => typeof p === 'string' && p.trim()))) {\n fail(task, 'protectedPaths', `${where} is a delegated task that lands, with no \"protectedPaths\": name the paths its child may not change, what its check runs and the configuration that runs it`);\n } else if (!task.readOnly) {\n for (const rule of paths ?? []) {\n const fault = protectedPathFault(rule);\n if (fault) fail(task, 'protectedPaths', `${where} protects \"${rule}\", which ${fault}`);\n }\n }\n if (task.scope !== undefined && !scopeOk(task.scope)) fail(task, 'scope', `${where} has a \"scope\" that is not lists of text: \"paths\", \"provides\" and \"consumes\", at most ${SCOPE_LIMITS.items} items of one line and ${SCOPE_LIMITS.item} characters each`);\n const unknown = (task.grants ?? []).filter((grant) => !GRANTS.includes(grant as Grant));\n if (unknown.length > 0) fail(task, 'grants', `${where} asks in \"grants\" for ${unknown.map((g) => `\"${g}\"`).join(', ')}, which no grant is: one of ${GRANTS.join(', ')}`);\n\n const dependents = tasks.filter((t) => t.dependencies.includes(task.id));\n if (task.readOnly) {\n for (const script of dependents.filter((t) => t.type === 'script')) {\n fail(script, 'dependencies', `Task \"${script.title}\" depends on \"${task.title}\", which is a read-only delegated task, which lands nothing, so a script has nothing to run on: make the check a read-only AI task, which reads its handoff`);\n }\n }\n if (!dependents.some((t) => judges(t, task, rules.runnerModes))) {\n fail(task, 'dependencies', `${where} is a delegated task with no check: add a read-only AI task${task.readOnly ? ', which reads its handoff,' : ', or a script task marked \"readOnly\",'} that depends on it directly`);\n }\n }\n\n for (const task of tasks.filter((t) => t.type === 'script' && t.readOnly)) {\n if (rules.canSeal === false) fail(task, 'readOnly', `Task \"${task.title}\" is a read-only script task, and this machine has no sandbox to seal one in: make the check a read-only AI task`);\n }\n\n // A body at a gate waits for a merge the delegated task's hold keeps back (D9), and the check waits on that body.\n for (const check of tasks.filter((t) => t.loop)) {\n if (!reaches(tasks, check, (t) => t.type === 'delegated')) continue;\n for (const id of check.loop?.body ?? []) {\n const body = tasks.find((t) => t.id === id);\n if (body && atAGate(body)) {\n fail(body, 'loop', `Task \"${check.title}\" names \"${body.title}\" in its loop's \"body\", which waits at a merge gate for work a delegated task's check holds back: make the fix a change task, cut from the integration tip`);\n }\n }\n }\n return errors;\n}\n\nfunction scopeOk(scope: unknown): boolean {\n if (typeof scope !== 'object' || scope === null) return false;\n const { paths, provides, consumes } = scope as Record<string, unknown>;\n const itemOk = (item: unknown) => typeof item === 'string' && item.trim().length > 0 && item.length <= SCOPE_LIMITS.item && ONE_LINE.test(item);\n return [paths, provides, consumes].every((list) => list === undefined || (Array.isArray(list) && list.length <= SCOPE_LIMITS.items && list.every(itemOk)));\n}\n\n/** Whether `task` can judge `delegated`: a read-only AI task, or a read-only script of one that lands (D8). */\nfunction judges(task: Task, delegated: Task, runnerModes: DelegationRules['runnerModes']): boolean {\n return readsOnly(task, runnerModes) || (!delegated.readOnly && task.type === 'script' && task.readOnly === true);\n}\n\n/**\n * The checks of a delegated task: what depends on it directly and can judge it\n * (D8). One whose runner cannot be read may be its only check, so it counts,\n * and the hold fails closed (D9). Only a plan being written is held to\n * `judges` alone: a task nothing can read is no check to accept one on.\n */\nexport function checksOf(tasks: readonly Task[], delegated: Task, rules: Pick<DelegationRules, 'runnerModes'> = {}): Task[] {\n return tasks.filter((t) => t.dependencies.includes(delegated.id) && (judges(t, delegated, rules.runnerModes) || runnerUnread(t, rules.runnerModes)));\n}\n\n/**\n * The checks that hold every merge but the user's (ADR-0055 D9): each of a\n * delegated task with landed work not yet merged that has neither passed nor\n * been skipped. Work that has not landed holds nothing, and a read-only task\n * never lands.\n */\nexport function checksHoldingMerge(tasks: readonly Task[], awaitsMerge: (taskId: string) => boolean, rules: Pick<DelegationRules, 'runnerModes'> = {}): Task[] {\n return tasks\n .filter((t) => t.type === 'delegated' && awaitsMerge(t.id))\n .flatMap((t) => checksOf(tasks, t, rules))\n .filter((check) => check.status !== 'completed' && check.status !== 'skipped');\n}\n\n/** Something a check is made of. A `command` is the check itself at any length, where prose says little until it has some. */\nexport interface CheckWord {\n text: string;\n command: boolean;\n}\n\n/** The commands a check runs, a script's one by one: holding any of them is holding the check. */\nfunction commandsOf({ script, commands }: Task): string[] {\n const written = splitLines(script ?? '').flatMap((line) => line.split(/[;|&]+/)).map((command) => command.trim()).filter((command) => !command.startsWith('#'));\n return [...written, ...(commands ?? []).map((argv) => argv.join(' '))].filter(Boolean);\n}\n\n/**\n * What this plan's checks are made of (ADR-0057 R10): the words of whatever\n * depends directly on a delegated task, which is all a pure reader of the plan\n * can tell a check by. A pin may hold none of them whole.\n */\nexport function checkWords(tasks: readonly Task[]): CheckWord[] {\n const delegated = new Set(tasks.filter((t) => t.type === 'delegated').map((t) => t.id));\n return tasks.filter((t) => t.dependencies.some((id) => delegated.has(id))).flatMap((t) => [\n ...[t.title, t.prompt ?? ''].map((text) => ({ text, command: false })),\n ...commandsOf(t).map((text) => ({ text, command: true })),\n ]);\n}\n\n/** Whether `task` is the check of a delegated task of `tasks`: what a model may not skip past, since that lets the work past its only check (D8). */\nexport function checksDelegatedTask(tasks: readonly Task[], task: Task, rules: Pick<DelegationRules, 'runnerModes'> = {}): boolean {\n if (!readsOnly(task, rules.runnerModes) && !runnerUnread(task, rules.runnerModes) && !(task.type === 'script' && task.readOnly)) return false;\n return tasks.some((t) => t.type === 'delegated' && task.dependencies.includes(t.id));\n}\n\n/** The tasks a child's plan counts: its whole list, subtasks included. */\nexport function planSize(tasks: readonly Task[]): number {\n return flattenTasks(tasks).length;\n}\n\n/** A path's steps, as both ends of a comparison read them: separators and `.` steps say nothing. */\nfunction pathSteps(path: string): string[] {\n return path.trim().replace(/\\\\/g, '/').split('/').filter((step) => step !== '' && step !== '.');\n}\n\n/**\n * A path as it is compared (ADR-0055 D7). A case-insensitive checkout holds\n * `Tests/a.ts` and `tests/a.ts` as one file, and git prints the name the branch\n * wrote, so the check ignores case and composition everywhere: on a\n * case-sensitive repository it refuses too much, which is the side to err on.\n * Upper then lower folds what lower alone leaves apart (`ß`, `ſ`, a final `ς`).\n */\nfunction foldedPath(path: string): string {\n return pathSteps(path).join('/').normalize('NFC').toUpperCase().toLowerCase();\n}\n\n/**\n * Why a planner may not write `rule` as a protected path, or null where it may\n * (ADR-0055 D7): each of these would pass a list that protects nothing, or\n * leave a task that can never land.\n */\nexport function protectedPathFault(rule: string): string | null {\n const path = rule.trim().replace(/\\\\/g, '/');\n if (path.startsWith('/') || /^[a-z]:\\//i.test(path)) return 'is not relative to the repository, and a diff lists nothing else: name it from the repository\\'s root';\n const steps = pathSteps(path);\n if (steps.includes('..')) return 'is outside the repository: name a path inside it';\n if (steps.every((step) => /^\\*+$/.test(step))) return 'covers the whole repository, so its child could land nothing: name what it may not change, or make the task \"readOnly\"';\n if (/[?{}]|^!/.test(path) || (path.includes('*') && /[[\\]]/.test(path))) return 'reads as a wildcard, and only `*` is a wildcard here, with `**` for any depth: name each path';\n return null;\n}\n\n/**\n * Whether one path of a repository falls under a protected path: a file it\n * names, a directory it names with or without a trailing slash, or a `*`\n * pattern, in which `**` crosses directories and one with no slash reads a name\n * at any depth. Nothing resolves a link, since a diff lists what the branch\n * changed by name. A rule {@link protectedPathFault} refuses can still reach\n * here from a saved plan, so one for the whole repository holds all of it.\n */\nexport function underProtectedPath(file: string, protectedPath: string): boolean {\n if (!protectedPath.trim()) return false;\n const rule = foldedPath(protectedPath).replace(/(?:\\/\\*\\*)+$/, '');\n const path = foldedPath(file);\n if (rule.includes('*')) return globRegExp(rule).test(path);\n return !rule || path === rule || path.startsWith(`${rule}/`);\n}\n\n/** What comes before a rule's first `*`: all two patterns can be told apart by without matching one against the other. */\nfunction fixedStart(rule: string): string {\n const bare = foldedPath(rule);\n const star = bare.indexOf('*');\n return star === -1 ? bare : bare.slice(0, star);\n}\n\n/** Whether two declared paths can name one file. Advisory, so two patterns are read generously: what they start with decides it. */\nexport function pathsMeet(a: string, b: string): boolean {\n if (underProtectedPath(a, b) || underProtectedPath(b, a)) return true;\n if (!a.includes('*') || !b.includes('*')) return false;\n const [one, other] = [fixedStart(a), fixedStart(b)];\n return one.startsWith(other) || other.startsWith(one);\n}\n\n/** The narrower of two declared paths that meet: what a planner reads the overlap as. */\nfunction narrower(a: string, b: string): string {\n return b.includes('*') || (!a.includes('*') && a.length >= b.length) ? a : b;\n}\n\n/** Whether an edge of the plan puts one of two tasks after the other. */\nfunction ordered(tasks: readonly Task[], a: Task, b: Task): boolean {\n return reaches(tasks, a, (t) => t.id === b.id) || reaches(tasks, b, (t) => t.id === a.id);\n}\n\n/**\n * What a plan's scopes leave for its planner to settle (ADR-0057 R6), a\n * sentence each. It refuses nothing, since a scope is advisory: this is the\n * answer the tool gives, and two tasks an edge orders have nothing to settle.\n */\nexport function scopeOverlaps(tasks: readonly Task[]): string[] {\n const scoped = tasks.filter((t) => t.type === 'delegated' && t.scope);\n const said: string[] = [];\n scoped.forEach((a, i) => {\n for (const b of scoped.slice(i + 1)) {\n if (ordered(tasks, a, b)) continue;\n const declared = (a.scope?.paths ?? []).flatMap((one) => (b.scope?.paths ?? []).filter((other) => pathsMeet(one, other)).map((other) => narrower(one, other)));\n if (declared.length > 0) said.push(`Tasks \"${a.title}\" and \"${b.title}\" both declare ${[...new Set(declared)].join(', ')}, and nothing orders them: give one a dependency on the other, or name an owner.`);\n for (const name of a.scope?.provides ?? []) {\n if (b.scope?.provides?.includes(name)) said.push(`Tasks \"${a.title}\" and \"${b.title}\" both provide \"${name}\", and nothing orders them: name one owner.`);\n }\n for (const [producer, consumer] of [[a, b], [b, a]] as const) {\n for (const name of producer.scope?.provides ?? []) {\n if (consumer.scope?.consumes?.includes(name)) said.push(`Task \"${consumer.title}\" consumes \"${name}\", which \"${producer.title}\" provides, and nothing orders them: a dependency puts the producer first; without one it gets a line when \"${producer.title}\" lands.`);\n }\n }\n }\n });\n return said;\n}\n\nconst GLOB_STARS: Record<string, string> = { '*': '[^/]*', '**': '.*', '**/': '(?:.*/)?' };\n\nfunction globRegExp(rule: string): RegExp {\n const pattern = rule.replace(/[.+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\*\\*\\/|\\*\\*|\\*/g, (star) => GLOB_STARS[star]);\n // `s`: a line break is a legal character of a file name, and `.` must walk over it.\n return new RegExp(`^${rule.includes('/') ? '' : '(?:.*/)?'}${pattern}(?:/.*)?$`, 's');\n}\n","import { presentForbiddenFields, TASK_KINDS, writtenForbiddenFields } from '../models/TaskKind';\nimport { dependencyTargetErrors, findDependencyCycle } from './PlanTree';\nimport { v4 as uuidv4 } from 'uuid';\nimport { Task, RunnerId, TaskModelAssignment, DEFAULT_RUNNERS, createTask, flattenTasksWithParents, inheritedSkills, skillNames } from '../models/Task';\nimport { taggedReadOnlyMode, type RunnerModeInfo } from './ModeResolver';\nimport { resolveAssignment, type AssignmentAdjustment, type AssignmentCatalog } from './TaskAssignment';\nimport { scriptBodyErrors } from '../models/ScriptTask';\nimport { readSpec } from './TaskSpec';\nimport { loopErrors, loopSpec } from '../models/Loop';\nimport { DELEGATION_UNAVAILABLE, delegationErrors, notOnADelegatedMessage, type DelegatedBudget, type DelegationRules, type TaskScope } from '../models/Delegation';\n\n/** One reason a planned task was refused, pinned to the task and field it is about. */\nexport interface PlanTaskError {\n /** Absent when the envelope itself is wrong rather than one of its tasks. */\n taskId?: string;\n field: string;\n message: string;\n}\n\n/** What a planned task may be given: the runners it may run on and their modes. */\nexport interface IntakeCatalog {\n runners: readonly RunnerId[];\n /** Absent when no runner's modes are known: the mode is then guessed (ADR-0031). */\n runnerModes?: Partial<Record<RunnerId, readonly RunnerModeInfo[]>>;\n autonomousDefault?: boolean;\n /**\n * An edit's assignments are resolved against the catalog as it is planned,\n * and a model it names that the runner does not offer is refused; a\n * submitted plan's models are resolved as it lands instead (ADR-0003).\n */\n models?: AssignmentCatalog;\n /**\n * Why this planner may not write a delegated task or a read-only script\n * (ADR-0055 D1, D8), or null when it may. Absent, there is no node to read:\n * a one-shot planner, or a route that holds no mandate.\n */\n delegationRefusal?: string | null;\n /** Which of a child's script tasks run sealed (ADR-0056 M9): each such lands read-only, on every route. */\n sealsScripts?: (task: Pick<Task, 'commands' | 'script' | 'timeoutMs'>) => boolean;\n}\n\n/** Where a planned task lands, which decides what it inherits. */\nexport interface Placement {\n /** The task it is a subtask of. */\n parent?: Pick<Task, 'title' | 'sliceType' | 'autonomy'> & { readOnly: boolean };\n /**\n * A task made from others — a merge, or a split part: what the planner\n * leaves out comes from these fields, and it stays read-only when they were.\n */\n from?: { fields: Partial<Task>; readOnly: boolean };\n /**\n * An edit's tasks get ids of their own, so a planner cannot name one after\n * a task already in the plan. A submitted plan keeps the planner's, which\n * its dependencies are written against; one it left out is made up.\n */\n freshIds?: boolean;\n /** Where a made-up id comes from: a new one each time, unless the caller keeps them. */\n newId?: () => string;\n}\n\nexport interface PlannedTask {\n task: Task;\n /** Rules the task, or one of its subtasks, breaks on its own. */\n errors: PlanTaskError[];\n /**\n * What the planner asked for that is not its to set — a mode, or read-only\n * on a manual task (ADR-0031). A whole plan lands without it; an edit is\n * refused.\n */\n ignored: PlanTaskError[];\n /** The planner's id for each task of the tree that was given a fresh one. */\n renamed: Map<string, string>;\n /** What the tree's assignments were adjusted to beyond what the planner wrote, for the planner to be told. */\n adjustments: AssignmentAdjustment[];\n}\n\n/** The planner names no mode (ADR-0031): it says read-only, and the mode follows. */\nexport const MODE_NOT_THE_PLANNERS = '\"taskMode\" is the user\\'s to choose: set \"readOnly\": true on a task that must not change files, and leave it out otherwise';\n\n/** A manual task runs in no mode, so it cannot be read-only. */\nexport const MANUAL_NOT_READ_ONLY = '\"readOnly\" is for AI tasks: a manual task runs in no mode';\n\n/** An ops task acts in the workspace (ADR-0020); a read-only task lands nothing (ADR-0046). */\nexport const OPS_NOT_READ_ONLY = '\"readOnly\" is not for an ops task: it acts in the workspace, while a read-only task lands nothing';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction text(value: unknown): string | undefined {\n return typeof value === 'string' || typeof value === 'number' ? String(value) : undefined;\n}\n\n/** A planner's fields, as untyped as the rest of its JSON; a rule refuses what is wrong with a value that reached the task. */\nfunction delegatedFields(raw: Record<string, unknown>, base: Partial<Task>): Pick<Task, 'goal' | 'budget' | 'grants' | 'protectedPaths' | 'scope'> & { readOnly?: true } {\n const list = (value: unknown): string[] | undefined => (Array.isArray(value) ? value.map(String) : undefined);\n const goal = text(raw.goal) ?? base.goal;\n const budget = (isRecord(raw.budget) ? raw.budget as unknown as DelegatedBudget : undefined) ?? base.budget;\n const grants = (list(raw.grants) ?? base.grants) as Task['grants'];\n const protectedPaths = list(raw.protectedPaths) ?? base.protectedPaths;\n const scope = (isRecord(raw.scope) ? raw.scope as TaskScope : undefined) ?? base.scope;\n return {\n ...(goal !== undefined ? { goal } : {}),\n ...(budget ? { budget } : {}),\n ...(grants ? { grants } : {}),\n ...(protectedPaths ? { protectedPaths } : {}),\n ...(scope ? { scope } : {}),\n ...(raw.readOnly === true || (raw.readOnly === undefined && base.readOnly) ? { readOnly: true as const } : {}),\n };\n}\n\n/** The refusal of those fields, worded for the planner. */\nexport function notOnAScriptMessage(fields: readonly string[]): string {\n return `is a script task, which runs its \"commands\" or \"script\" with no model: leave out ${fields.map((f) => `\"${f}\"`).join(', ')}`;\n}\n\n/**\n * Why a task may not be an ops task (ADR-0020), or null when it may: the flag\n * decides where the task runs, and a manual task runs nowhere, a subtask\n * where its parent does.\n */\nexport function opsPlacementRefusal(type: Task['type'], isSubtask: boolean): string | null {\n if (type === 'script') return 'is a script task, which is an ops task by nature: leave \"ops\" out';\n if (!TASK_KINDS[type].mayBeOps) return 'is a manual task: only an AI task can be an ops task';\n if (isSubtask) return 'is a subtask, which runs with its parent: only a top-level task can be an ops task';\n return null;\n}\n\n/** How an error names a task, so the planner can find the object it wrote. */\nexport function taskWhere(title: string, parentTitle?: string): string {\n return parentTitle !== undefined ? `subtask \"${title}\" of \"${parentTitle}\"` : `Task \"${title}\"`;\n}\n\n/**\n * What each planned task asked to attach, as the planner wrote it. Kept beside\n * the task rather than on it: {@link skillNames} drops a name no skill could\n * have, and the plan's skill check still owes a warning for it. A copy of the\n * task (assignment coercion) does not carry it, so check what was planned.\n */\nconst skillsAsked = new WeakMap<Task, unknown[]>();\n\n/** The `skills` a planned task was submitted with, before normalization; undefined for a task not planned here. */\nexport function requestedSkills(task: Task): readonly unknown[] | undefined {\n return skillsAsked.get(task);\n}\n\n/** The model as a task stores it; a top-level `thinkingEffort` is the model's, as the effort has one home. */\nfunction modelOf(raw: Record<string, unknown>, from: TaskModelAssignment | undefined): TaskModelAssignment | undefined {\n const effort = text(raw.thinkingEffort);\n if (isRecord(raw.assignedModel)) {\n const m = raw.assignedModel;\n return {\n modelId: text(m.modelId) ?? '',\n modelLabel: text(m.modelLabel) ?? '',\n thinkingEffort: text(m.thinkingEffort) ?? effort,\n };\n }\n return from && effort !== undefined ? { ...from, thinkingEffort: effort } : from;\n}\n\n/**\n * A planned task's body fields (ADR-0035): what the planner wrote, else what\n * the task it is made from had. Only a well-formed value is kept on the task;\n * `malformed` names the fields that were not, for their refusal, and `raw` is\n * what was judged.\n */\nfunction bodyFields(raw: Record<string, unknown>, base: Partial<Task>): {\n fields: Pick<Task, 'commands' | 'script' | 'timeoutMs'>;\n raw: Record<'commands' | 'script' | 'timeoutMs', unknown>;\n malformed: Set<string>;\n} {\n const pick = (field: 'commands' | 'script' | 'timeoutMs'): unknown => (raw[field] !== undefined && raw[field] !== null ? raw[field] : base[field]);\n const judged = { commands: pick('commands'), script: pick('script'), timeoutMs: pick('timeoutMs') };\n const malformed = new Set<string>();\n const commands = isCommands(judged.commands) ? judged.commands : undefined;\n if (judged.commands !== undefined && !commands) malformed.add('commands');\n const script = typeof judged.script === 'string' ? judged.script : undefined;\n if (judged.script !== undefined && script === undefined) malformed.add('script');\n const timeoutMs = typeof judged.timeoutMs === 'number' ? judged.timeoutMs : undefined;\n if (judged.timeoutMs !== undefined && timeoutMs === undefined) malformed.add('timeoutMs');\n return {\n fields: { ...(commands ? { commands } : {}), ...(script !== undefined ? { script } : {}), ...(timeoutMs !== undefined ? { timeoutMs } : {}) },\n raw: judged,\n malformed,\n };\n}\n\nfunction isCommands(value: unknown): value is string[][] {\n return Array.isArray(value) && value.every((argv) => Array.isArray(argv) && argv.every((word) => typeof word === 'string'));\n}\n\n/**\n * Build a task from what a planner wrote, by whichever route it arrived: a\n * submitted plan, or an edit that adds, merges or splits. Every fallback a\n * planner's omission meets is here, so the routes cannot drift apart:\n *\n * - the runner is the one named, else the task's it is made from, else the\n * first one allowed — never a substitute for one named but unknown, which\n * {@link checkPlanInvariants} refuses;\n * - an AI task's prompt is its own, else its description, else its title, so\n * it is never unschedulable;\n * - the assignment — model, effort, and the mode decided from read-only or\n * not, never named (ADR-0031) — is the resolver's (`resolveAssignment`),\n * as it is for every writer: a model a merge or split carries is read as\n * what the task was made from, so a part moved to another runner gets that\n * runner's;\n * - an AI subtask with no slice classification takes its parent's: an `ai`\n * sub-step of an AFK slice is AFK. Not a blanket default, which would strip\n * a human gate the planner intended; a manual subtask must still say HITL.\n */\nexport function plannedTask(spec: unknown, catalog: IntakeCatalog, at: Placement = {}): PlannedTask {\n const raw = isRecord(spec) ? spec : {};\n const { parent, from, freshIds, newId = uuidv4 } = at;\n const base = from?.fields ?? {};\n const errors: PlanTaskError[] = [];\n const ignored: PlanTaskError[] = [];\n const renamed = new Map<string, string>();\n const adjustments: AssignmentAdjustment[] = [];\n\n const title = text(raw.title) ?? '';\n const where = taskWhere(title, parent?.title);\n const plannerId = text(raw.id);\n const id = freshIds || !plannerId ? newId() : plannerId;\n if (freshIds && plannerId) renamed.set(plannerId, id);\n // A field in a shape it cannot hold is refused before anything reads it: read loosely, a string of dependencies was no list, and planned none.\n for (const e of readSpec(spec, 'new')) errors.push({ taskId: id, field: e.field, message: `${where} ${e.message}` });\n\n const delegating = catalog.delegationRefusal === null;\n const type: Task['type'] = raw.type === 'user' || raw.type === 'ai' || raw.type === 'script' || raw.type === 'delegated' ? raw.type : base.type ?? 'ai';\n const ai = type === 'ai';\n const script = type === 'script';\n const delegated = type === 'delegated';\n // A read-only script exists for a delegated task's check (ADR-0055 D8), so where nothing can delegate it reads as it always did.\n const sealedScript = script && (catalog.sealsScripts?.({ ...(Array.isArray(raw.commands) ? { commands: raw.commands as string[][] } : {}), ...(typeof raw.script === 'string' ? { script: raw.script } : {}), ...(typeof raw.timeoutMs === 'number' ? { timeoutMs: raw.timeoutMs } : {}) }) === true || (delegating && raw.readOnly === true));\n const assignedRunner = text(raw.assignedRunner) ?? base.assignedRunner ?? catalog.runners[0] ?? DEFAULT_RUNNERS[0];\n const description = text(raw.description) ?? base.description ?? title;\n\n // What it may not have is refused rather than dropped: a prompt left on a\n // script, or a runner named for it, says the planner meant something else.\n const notScripts = script ? writtenForbiddenFields('script', raw).filter((f) => !(sealedScript && f === 'readOnly')) : [];\n if (notScripts.length > 0) errors.push({ taskId: id, field: notScripts[0], message: `${where} ${notOnAScriptMessage(notScripts)}` });\n if (delegated) {\n if (!delegating) errors.push({ taskId: id, field: 'type', message: catalog.delegationRefusal ?? `${where} is a delegated task, and ${DELEGATION_UNAVAILABLE}.` });\n const extra = writtenForbiddenFields('delegated', raw);\n if (extra.length > 0) errors.push({ taskId: id, field: extra[0], message: `${where} ${notOnADelegatedMessage(extra)}` });\n }\n // A body's shape is judged here, where it is still what the planner wrote: a Task holds only a well-formed one.\n const body = bodyFields(raw, base);\n const shapeErrors = scriptBodyErrors({ type, ...body.raw }).filter((e) => body.malformed.has(e.field));\n for (const e of shapeErrors) errors.push({ taskId: id, field: e.field, message: `${where} ${e.message}` });\n // Its body's references are kept as written: an edit resolves them against the plan, a submitted plan names its own ids.\n const loop = loopSpec(raw.loop);\n if ('error' in loop) errors.push({ taskId: id, field: 'loop', message: `${where} ${loop.error}` });\n // A manual task stores no ops flag, so this is the one place it can still be seen.\n if (raw.ops === true && !ai && !script) errors.push({ taskId: id, field: 'ops', message: `${where} ${opsPlacementRefusal(type, !!parent)}` });\n if (raw.taskMode !== undefined && !script && !delegated) ignored.push({ taskId: id, field: 'taskMode', message: `${where}: ${MODE_NOT_THE_PLANNERS}` });\n if (type === 'user' && raw.readOnly === true) ignored.push({ taskId: id, field: 'readOnly', message: `${where}: ${MANUAL_NOT_READ_ONLY}` });\n const ops = raw.ops !== undefined ? raw.ops === true : base.ops;\n if (ai && ops && raw.readOnly === true) ignored.push({ taskId: id, field: 'readOnly', message: `${where}: ${OPS_NOT_READ_ONLY}` });\n // A read-only task's subtasks run as tasks of their own, so they would\n // otherwise get write access the planner said the work must not have.\n const asked = typeof raw.readOnly === 'boolean' ? raw.readOnly : undefined;\n const readOnly = ai && !ops && (asked ?? from?.readOnly ?? parent?.readOnly ?? false);\n\n const assignedModel = ai || delegated ? modelOf(raw, base.assignedModel) : undefined;\n const slice = (value: unknown): 'AFK' | 'HITL' | undefined => (value === 'AFK' || value === 'HITL' ? value : undefined);\n // Explicit child values always win; inheritance only fills a gap, and only for `ai` tasks.\n const autonomy = ai ? slice(raw.autonomy) ?? base.autonomy ?? parent?.autonomy : undefined;\n const sliceType = slice(raw.sliceType) ?? base.sliceType ?? (ai ? parent?.sliceType : undefined);\n\n const subtasks: Task[] = [];\n if (Array.isArray(raw.subtasks)) {\n for (const s of raw.subtasks) {\n const child = plannedTask(s, catalog, { parent: { title, sliceType, autonomy, readOnly }, freshIds, newId });\n subtasks.push(child.task);\n errors.push(...child.errors);\n ignored.push(...child.ignored);\n adjustments.push(...child.adjustments);\n for (const [was, now] of child.renamed) renamed.set(was, now);\n }\n }\n\n const fields = {\n id,\n order: Number(raw.order ?? 0),\n title,\n description,\n type,\n dependencies: Array.isArray(raw.dependencies) ? raw.dependencies.map(String) : base.dependencies ?? [],\n // What a merge or split carries over for a runner is nothing a script runs.\n prompt: script || delegated ? undefined : text(raw.prompt) || base.prompt || (ai ? description || title || undefined : undefined),\n userSteps: Array.isArray(raw.userSteps)\n ? raw.userSteps.map((s) => (isRecord(s) ? s : {})).map((s) => ({ order: Number(s.order ?? 0), instruction: String(s.instruction ?? ''), completed: false }))\n : base.userSteps,\n subtasks,\n assignedModel,\n assignedRunner,\n autonomy,\n sliceType,\n userStoriesCovered: Array.isArray(raw.userStoriesCovered) ? raw.userStoriesCovered.map(String) : base.userStoriesCovered,\n ops: script || delegated ? undefined : ops,\n research: typeof raw.research === 'boolean' ? raw.research : base.research,\n skills: script || delegated ? undefined : from ? inheritedSkills(raw.skills, base.skills) : skillNames(raw.skills),\n ...body.fields,\n ...('loop' in loop && loop.loop ? { loop: loop.loop } : {}),\n ...(delegated ? delegatedFields(raw, base) : {}),\n ...(sealedScript ? { readOnly: true as const } : {}),\n };\n let taskMode = (TASK_KINDS[type].runsInMode || type === 'user') ? base.taskMode : undefined;\n let landedModel = assignedModel;\n if ((ai || delegated) && catalog.runners.includes(assignedRunner)) {\n const resolved = resolveAssignment({\n writer: catalog.models ? 'edit' : 'plan',\n task: { ...createTask(fields), taskMode },\n from: from ? { assignedRunner: base.assignedRunner ?? assignedRunner, assignedModel: base.assignedModel, taskMode: base.taskMode } : undefined,\n readOnly,\n catalog: { modelsByRunner: {}, ...catalog.models, runnerModes: catalog.runnerModes, autonomousDefault: catalog.autonomousDefault },\n });\n if (!resolved.ok) {\n // The planner names no mode: one it cannot have is about the read-only answer it gave (ADR-0031).\n errors.push({ taskId: id, field: resolved.field === 'taskMode' ? 'readOnly' : resolved.field, message: `${where}: ${resolved.error}` });\n } else {\n // A delegated task has no mode on the plan: a subplanner's is the planner's, and a repair's comes from its mandate (ADR-0055 D14).\n taskMode = delegated ? undefined : resolved.task.taskMode;\n landedModel = resolved.task.assignedModel;\n adjustments.push(...resolved.adjustments);\n }\n }\n // With no runner modes to read, `plan` is the guess that keeps a read-only task from writing.\n if (taskMode === undefined && readOnly && !catalog.runnerModes) taskMode = 'plan';\n\n const task = createTask({ ...fields, assignedModel: landedModel, taskMode });\n if (Array.isArray(raw.skills)) skillsAsked.set(task, raw.skills);\n return { task, errors, ignored, renamed, adjustments };\n}\n\n/** An AI task on a runner outside `runners`: what a plan accepted earlier is held to again where it lands, the runners enabled then being the ones that count. */\nexport function checkPlanRunners(tasks: readonly Task[], runners: readonly RunnerId[] | undefined): PlanTaskError[] {\n if (!runners) return [];\n return flattenTasksWithParents(tasks)\n .filter(({ task: t }) => TASK_KINDS[t.type].hasRunner && !runners.includes(t.assignedRunner))\n .map(({ task: t, parent }) => ({\n taskId: t.id,\n field: 'assignedRunner',\n message: `${taskWhere(t.title, parent?.title)} has invalid assignedRunner \"${t.assignedRunner}\". Expected one of: ${runners.join(', ')}`,\n }));\n}\n\n/**\n * The rules a plan's tasks are held to together, subtasks included, whichever\n * route they arrived by and whoever wrote them, the planner or the user.\n * `runners` are the ones the writer may put a task on (`assignableRunners`),\n * any when undefined; with `runnerModes`, an ops task is held off its\n * runner's read-only mode. A script task (ADR-0035) runs exactly one\n * well-formed body, at the top level, and carries nothing a runner would read.\n * A loop (ADR-0045) keeps its body for its check alone, on an acyclic graph.\n */\nexport function checkPlanInvariants(\n tasks: readonly Task[],\n runners: readonly RunnerId[] | undefined,\n runnerModes?: Partial<Record<RunnerId, readonly RunnerModeInfo[]>>,\n delegation: Pick<DelegationRules, 'canSeal'> = {},\n): PlanTaskError[] {\n const rows = flattenTasksWithParents(tasks);\n const errors: PlanTaskError[] = [];\n const seen = new Set<string>();\n const body = new Set(tasks.flatMap((t) => t.loop?.body ?? []));\n for (const { task: t, parent } of rows) {\n const where = taskWhere(t.title, parent?.title);\n const fail = (field: string, message: string) => errors.push({ taskId: t.id, field, message });\n if (seen.has(t.id)) fail('id', `${where} has id \"${t.id}\", which another task in the plan has too: every task, subtasks included, needs an id of its own`);\n seen.add(t.id);\n if (t.research !== undefined && typeof t.research !== 'boolean') fail('research', `${where}: \"research\" must be a boolean`);\n // Research's approval exception is safe only under the shared read-only profile (ADR-0037 R1, R4).\n const readOnly = runnerModes ? taggedReadOnlyMode(runnerModes[t.assignedRunner]) : 'plan';\n if (t.research && (!TASK_KINDS[t.type].mayBeResearch || parent !== null || t.ops || body.has(t.id)\n || readOnly === undefined || t.taskMode !== readOnly)) {\n fail('research', `${where}: research is only for top-level read-only AI tasks, never a loop's body`);\n }\n if (t.autonomy === 'AFK' && t.userSteps && t.userSteps.length > 0) {\n fail('userSteps', `${where} has autonomy \"AFK\" but contains userSteps. AFK tasks must not have user touchpoints.`);\n }\n if (t.type === 'user' && t.sliceType && t.sliceType !== 'HITL') {\n fail('sliceType', `User ${where} has sliceType \"${t.sliceType}\". User tasks must have sliceType \"HITL\".`);\n }\n const opsRefused = t.ops && t.type !== 'script' ? opsPlacementRefusal(t.type, parent !== null) : null;\n if (opsRefused) fail('ops', `${where} ${opsRefused}`);\n if (t.type === 'script') {\n // It runs at the workspace root on its own (ADR-0035): nothing hangs under it, and it hangs under nothing.\n if (TASK_KINDS[t.type].topLevelOnly && parent !== null) fail('type', `${where} is a script task: only a top-level task can be one, as only a top-level task can be an ops task`);\n if (!TASK_KINDS[t.type].mayHaveSubtasks && t.subtasks?.length) fail('subtasks', `${where} is a script task, which has no subtasks: make each step a command of its own, or a task of its own`);\n const extra = presentForbiddenFields('script', t, ['assignedRunner', 'readOnly', 'subtasks']);\n if (extra.length > 0) fail(extra[0], `${where} ${notOnAScriptMessage(extra)}`);\n }\n if (t.type === 'delegated') {\n // Top-level like a script task, and its child plan's tasks are the child's own (ADR-0055 D1).\n if (TASK_KINDS[t.type].topLevelOnly && parent !== null) fail('type', `${where} is a delegated task: only a top-level task can be delegated`);\n if (!TASK_KINDS[t.type].mayHaveSubtasks && t.subtasks?.length) fail('subtasks', `${where} is a delegated task, which has no subtasks: its child plan's tasks are its child's own`);\n }\n for (const e of scriptBodyErrors(t)) fail(e.field, `${where} ${e.message}`);\n if (t.ops && t.taskMode !== undefined && t.taskMode === taggedReadOnlyMode(runnerModes?.[t.assignedRunner])) {\n fail('taskMode', `${where} is an ops task, which acts in the workspace, so it cannot use the read-only profile`);\n }\n }\n errors.push(...checkPlanRunners(tasks, runners));\n errors.push(...loopErrors(tasks));\n errors.push(...delegationErrors(tasks, { ...(runnerModes ? { runnerModes } : {}), ...delegation }));\n for (const { task: t, parent } of rows) {\n // Self-dependencies are reported with the cycle below, including its full path.\n for (const error of dependencyTargetErrors(tasks, t.id, t.dependencies.filter((id) => id !== t.id))) {\n errors.push({ taskId: t.id, field: 'dependencies', message: `${taskWhere(t.title, parent?.title)}: ${error}` });\n }\n }\n const cycle = findDependencyCycle(rows.map((r) => r.task));\n // Pinned to a task on the cycle: a plan whose only fault is a rule a task\n // breaks is worth naming back to the planner, not re-asking for as JSON.\n if (cycle) errors.push({ taskId: cycle[0].id, field: 'dependencies', message: `Dependency cycle detected: ${[...cycle, cycle[0]].map((t) => `\"${t.title}\"`).join(' → ')}` });\n return errors;\n}\n\n/** A rule `after` breaks, with what tells it apart from another breach. */\nexport interface PlanBreach {\n error: PlanTaskError;\n key: string;\n}\n\n/**\n * The rules `after` breaks that `before` did not, for either route of an edit:\n * what the plan already broke, a task on a runner switched off since, say,\n * never blocks an unrelated edit. A breach is told by its task and rule, not\n * its wording, which carries the title an edit may change; a runner's breach\n * by the runner too, as moving a task from one runner switched off to another\n * is the edit's own.\n */\nexport function newBreaches(\n before: readonly Task[],\n after: readonly Task[],\n runners: readonly RunnerId[] | undefined,\n runnerModes?: Partial<Record<RunnerId, readonly RunnerModeInfo[]>>,\n): PlanBreach[] {\n const breaches = (tasks: readonly Task[]): PlanBreach[] => {\n const runnerOf = new Map(flattenTasksWithParents(tasks).map(({ task }) => [task.id, task.assignedRunner]));\n return checkPlanInvariants(tasks, runners, runnerModes).map((error) => {\n const runner = error.field === 'assignedRunner' ? `\\u0000${runnerOf.get(error.taskId ?? '') ?? ''}` : '';\n return { error, key: `${error.taskId ?? ''}\\u0000${error.field}${runner}` };\n });\n };\n const standing = new Set(breaches(before).map((b) => b.key));\n return breaches(after).filter((b) => !standing.has(b.key));\n}\n","import type { DiscoveredModel, RunnerId, Task, TaskModelAssignment } from '../models/Task';\nimport { clampThinkingEffort, effectiveAllowlist } from './ModelAllowlistResolver';\nimport { plannedMode, readOnlyMode, readOnlyRunners, taggedReadOnlyMode, unavailableModeReason, type RunnerModeInfo } from './ModeResolver';\n\n/**\n * Who writes a task's assignment. It decides what a model the writer names\n * meets where the task's runner does not offer it or the allowlist excludes it\n * (ADR-0003), which runners it may put a task on, and whether a live runner's\n * hold applies (ADR-0041):\n *\n * - `plan`: a whole plan the planner submitted, and every planner task as it\n * lands. A stray model is replaced, and the planner is told what moved.\n * - `edit`: the planner's edit. A stray model is refused, which the planner\n * answers in the same reply.\n * - `user`: a user's direct edit. A stray model is refused, with the reason.\n * - `userAdd`: a task the user adds. A stray model is replaced, and the user\n * is told what moved.\n * - `runner`: a switch made with the runner's own `/model`, written as the\n * user's edit. The runner already runs it, so neither the allowlist nor the\n * live runner's hold applies.\n */\nexport type AssignmentWriter = 'plan' | 'edit' | 'user' | 'userAdd' | 'runner';\n\n/**\n * What an assignment is resolved against: the discovered models, the manifest\n * modes and the allowlist, as the session holds them when the write lands —\n * the same catalog the planner's per-turn block shows, so nothing is refused\n * that the planner was never told about.\n */\nexport interface AssignmentCatalog {\n /** A runner absent, or listed with nothing, has models discovery could not find, not none. */\n modelsByRunner: Partial<Record<RunnerId, DiscoveredModel[]>>;\n /** Absent when no runner's modes are known: no mode is then derived. */\n runnerModes?: Partial<Record<RunnerId, readonly RunnerModeInfo[]>>;\n /** Raw (unfiltered) allowlist, keyed by runner; read through {@link effectiveAllowlist}. */\n perRunnerAllowlist?: Partial<Record<RunnerId, string[]>>;\n /** Full (true) or Guarded: the mode a derived task lands on unless it is read-only (ADR-0001). Full when absent. */\n autonomousDefault?: boolean;\n /**\n * Whether a task's runner is live: an attempt of it is claimed, running,\n * quiet or waiting on someone. Its model, effort and runner are then that\n * runner's (ADR-0041): the process was started on them, and only the\n * runner's own command moves them. Absent means none is.\n */\n liveRunner?: (taskId: string) => boolean;\n}\n\n/** What a runner offers a task, as discovery and its manifest have it. */\nexport interface RunnerCatalog {\n models: DiscoveredModel[];\n modes: RunnerModeInfo[];\n}\n\n/** A change the resolver made to what was written, named so it is never silent (ADR-0001). */\nexport interface AssignmentAdjustment {\n taskId: string;\n title: string;\n field: 'assignedModel' | 'thinkingEffort';\n from: string | null;\n to: string | null;\n}\n\nexport interface AssignmentWrite {\n writer: AssignmentWriter;\n /** The task as written: the plan's task with the edit laid over it, or a new task. Its subtasks are not read. */\n task: Task;\n /** The task as the plan holds it; absent for a new task. */\n before?: Task;\n /**\n * What a new task is made from — the task a split part or merge starts\n * as. Its runner and model are read as `before`'s are: a part moved to\n * another runner carries a model chosen for the old one.\n */\n from?: Pick<Task, 'assignedRunner' | 'assignedModel' | 'taskMode'>;\n /** The planner's answer to read-only or not (ADR-0001). Absent, the task stays as it was. */\n readOnly?: boolean;\n catalog: AssignmentCatalog;\n}\n\nexport type AssignmentOutcome =\n | { ok: true; task: Task; adjustments: AssignmentAdjustment[] }\n | { ok: false; field: 'assignedRunner' | 'assignedModel' | 'taskMode'; error: string };\n\n/**\n * Why a task's model or effort cannot change while its runner is live, for\n * every writer but the runner itself. The plan follows a switch made with the\n * runner's own command instead (ADR-0041), so that is offered beside stopping it.\n */\nexport function liveModelRefusal(task: Pick<Task, 'title'>): string {\n return `\"${task.title}\" has a live runner, so its model and effort cannot change now: stop the task first, or use the runner's own /model`;\n}\n\n/**\n * Why a task cannot move to another runner while its runner is live: the move\n * re-derives the model from the new runner, under the same hold as\n * {@link liveModelRefusal}, and no runner's own command can make it.\n */\nexport function liveRunnerRefusal(task: Pick<Task, 'title'>): string {\n return `\"${task.title}\" has a live runner, so its runner cannot change now: stop the task first`;\n}\n\n/**\n * The runners a writer may put a task on (ADR-0003, V1): the planner's, a\n * submitted plan or an edit, the runners enabled now; a user any runner.\n * Undefined means any. A task an edit leaves on a runner switched off since is\n * not put there by the edit, so it stands (`applyTaskOps`, ADR-0043).\n */\nexport function assignableRunners(writer: AssignmentWriter, enabled: readonly RunnerId[]): RunnerId[] | undefined {\n if (writer === 'plan' || writer === 'edit') return [...enabled];\n return undefined;\n}\n\nfunction sameAssignment(a: TaskModelAssignment | undefined, b: TaskModelAssignment | undefined): boolean {\n return a?.modelId === b?.modelId && a?.thinkingEffort === b?.thinkingEffort;\n}\n\n/** Whether `mode` selects Ordewell's read-only profile on this runner (ADR-0046). */\nfunction readOnlyOn(mode: string | undefined, runner: RunnerId, catalog: AssignmentCatalog): boolean {\n return mode !== undefined && mode === taggedReadOnlyMode(catalog.runnerModes?.[runner]);\n}\n\n/**\n * The task's mode as written. The writer's own pick stands where the runner\n * offers it; otherwise a task the writer creates, moves, turns into an AI task\n * or says read-only or not of gets the mode the planner path gives it\n * (ADR-0001's fill-in table): its read-only mode, else the mode it has when\n * the runner offers it, else the runner's mode for the level. Silence keeps\n * what is, so a mode the user picked by hand survives every other edit.\n */\nfunction modeFor(write: AssignmentWrite, task: Task, moved: boolean): { ok: true; mode: string | undefined } | { ok: false; error: string } {\n const { writer, before, catalog } = write;\n const prior = before ?? write.from;\n const runner = task.assignedRunner;\n const modes = catalog.runnerModes?.[runner];\n const picked = (writer === 'user' || writer === 'userAdd') && task.taskMode !== undefined && task.taskMode !== prior?.taskMode;\n if (picked) {\n if (modes && modes.length > 0 && !modes.some((m) => m.id === task.taskMode)) {\n return { ok: false, error: `Runner \"${runner}\" has no task mode \"${task.taskMode}\": valid modes: ${modes.map((m) => m.id).join(', ')}` };\n }\n const unavailable = unavailableModeReason(modes, task.taskMode);\n if (unavailable) return { ok: false, error: `Mode \"${task.taskMode}\" of runner \"${runner}\" is unavailable on this host: ${unavailable}` };\n return { ok: true, mode: task.taskMode };\n }\n const becameAi = before !== undefined && before.type !== 'ai';\n if (writer === 'runner' || !catalog.runnerModes || (before && !moved && !becameAi && write.readOnly === undefined)) return { ok: true, mode: task.taskMode };\n // A move carries the old runner's mode id, which says read-only only on that runner.\n const carried = prior !== undefined && task.taskMode === prior.taskMode && readOnlyOn(prior.taskMode, prior.assignedRunner, catalog);\n const readOnly = write.readOnly ?? (carried || readOnlyOn(task.taskMode, runner, catalog));\n if (readOnly && !readOnlyMode(modes) && writer !== 'plan' && writer !== 'edit') {\n const reason = unavailableModeReason(modes, taggedReadOnlyMode(modes));\n const able = readOnlyRunners(catalog.runnerModes).filter((r) => r !== runner);\n return {\n ok: false,\n error: `\"${task.title}\" is read-only, and runner \"${runner}\" has no read-only mode${reason ? ' available on this host' : ''}: give it another mode first${able.length > 0 ? `, or move it to one of: ${able.join(', ')}` : ''}${reason ? `. ${reason}` : ''}`,\n };\n }\n const mode = plannedMode(runner, catalog.runnerModes, { readOnly, current: task.taskMode }, catalog.autonomousDefault ?? false);\n return mode.ok ? { ok: true, mode: mode.mode ?? task.taskMode } : mode;\n}\n\n/**\n * Resolve what one task runs on — its runner, model, thinking effort and mode\n * — for whichever writer wrote it. Every writer calls this, so they cannot\n * disagree. Returns the task with what it resolved, and each change made to\n * what was written, named; or a refusal.\n *\n * - **The live runner's hold.** While its runner is live a task's runner,\n * model and effort are that runner's (ADR-0041): any other writer is\n * refused a change, a model cleared as much as one replaced.\n * - **A model is its runner's.** A model the writer left alone stays, even off\n * the allowlist: the allowlist shapes what is written, not a model the user\n * switched to (ADR-0043). A model the task carries from another runner — a\n * move, or a part made from a task on another one — stays only where its new\n * runner lists it, or nothing is known against it, and the allowlist admits\n * it. A model the writer names is held to the runner and the allowlist as\n * its {@link AssignmentWriter} row says: the runner already runs it\n * (`runner`), or it is refused (`edit`, `user`), or replaced (`plan`,\n * `userAdd`) when only another runner lists it (it provably cannot run here)\n * or the allowlist excludes it. A model listed by no runner is not one any\n * runner disowns, so it stands, and the runner validates last.\n * - **Filling a model.** A missing, carried-off or replaced model is refilled\n * from the runner: the allowlist's first model the runner lists, else the\n * allowlist's first, else the runner's own first, else none, which the\n * runner fills with its own default.\n * - **Effort follows its model.** Whenever the model is listed, its effort is\n * held to what it offers ({@link clampThinkingEffort}, the one mapping rule:\n * the nearest level the model has, none when it has none); a model put in\n * here that discovery does not list gets none. A model discovery does not\n * list keeps the effort written with it, which the runner validates.\n * - **The mode** is the writer's pick where it has one, else derived as\n * {@link modeFor} says.\n *\n * Which runners a writer may use is the plan's rule ({@link assignableRunners},\n * `checkPlanInvariants`); this never moves a task to another runner.\n */\nexport function resolveAssignment(write: AssignmentWrite): AssignmentOutcome {\n const { writer, before, catalog } = write;\n const written = write.task;\n const prior = before ?? write.from;\n const moved = prior !== undefined && prior.assignedRunner !== written.assignedRunner;\n const title = (before ?? written).title;\n\n const live = writer !== 'runner' && !!before && !!catalog.liveRunner?.(before.id);\n if (live && moved) return { ok: false, field: 'assignedRunner', error: liveRunnerRefusal({ title }) };\n if (live && !sameAssignment(before?.assignedModel, written.assignedModel)) return { ok: false, field: 'assignedModel', error: liveModelRefusal({ title }) };\n // A manual task runs on nothing, and a script task on no runner (ADR-0035).\n if (written.type !== 'ai' && written.type !== 'delegated') return { ok: true, task: written, adjustments: [] };\n\n // A delegated task's runner runs a planner, in no mode the plan holds (ADR-0055 D14).\n const mode = written.type === 'delegated' ? { ok: true as const, mode: undefined } : modeFor(write, written, moved);\n if (!mode.ok) return { ok: false, field: 'taskMode', error: mode.error };\n\n // A live runner holds its model and effort as they are, even where its model's levels have changed since.\n const model: ModelResult = live ? { ok: true, assignment: written.assignedModel } : modelFor(write, moved);\n if (!model.ok) return { ok: false, field: 'assignedModel', error: model.error };\n\n const task = model.assignment === written.assignedModel && mode.mode === written.taskMode\n ? written\n : { ...written, assignedModel: model.assignment, taskMode: mode.mode };\n const adjustments: AssignmentAdjustment[] = [];\n const note = (field: AssignmentAdjustment['field'], from: string | undefined, to: string | undefined) => {\n if ((from ?? null) !== (to ?? null)) adjustments.push({ taskId: written.id, title: written.title, field, from: from ?? null, to: to ?? null });\n };\n note('assignedModel', written.assignedModel?.modelId, task.assignedModel?.modelId);\n note('thinkingEffort', written.assignedModel?.thinkingEffort, task.assignedModel?.thinkingEffort);\n return { ok: true, task, adjustments };\n}\n\ntype ModelResult = { ok: true; assignment: TaskModelAssignment | undefined } | { ok: false; error: string };\n\n/** The model half of {@link resolveAssignment}. */\nfunction modelFor(write: AssignmentWrite, moved: boolean): ModelResult {\n const { writer, before, catalog } = write;\n const prior = before ?? write.from;\n const written = write.task.assignedModel;\n const runner = write.task.assignedRunner;\n const models = catalog.modelsByRunner;\n const own = models[runner] ?? [];\n const listing = (id: string) => own.find((m) => m.modelId === id);\n // A model the task ran with on another runner is evidence that runner lists it, which the allowlist is read with (R1).\n const carriedFrom = moved && written && prior?.assignedModel?.modelId === written.modelId ? prior.assignedRunner : undefined;\n const seen = carriedFrom && written && !models[carriedFrom]?.some((m) => m.modelId === written.modelId)\n ? { ...models, [carriedFrom]: [...(models[carriedFrom] ?? []), { modelId: written.modelId, modelLabel: written.modelLabel, variants: [] }] }\n : models;\n const allowed = effectiveAllowlist(catalog.perRunnerAllowlist?.[runner], runner, seen);\n const allows = (id: string) => !allowed || allowed.includes(id);\n\n // Held to what its model offers, unless that model is one discovery does not list.\n const settled = (assignment: TaskModelAssignment): TaskModelAssignment => {\n const known = listing(assignment.modelId);\n if (!known) return assignment;\n const thinkingEffort = clampThinkingEffort(assignment.thinkingEffort, known.variants);\n const availableVariants = known.variants.map((v) => v.id);\n if (thinkingEffort === assignment.thinkingEffort && assignment.availableVariants?.join() === availableVariants.join()) return assignment;\n const next: TaskModelAssignment = { ...assignment, availableVariants };\n if (thinkingEffort === undefined) delete next.thinkingEffort;\n else next.thinkingEffort = thinkingEffort;\n return next;\n };\n // The allowlist's order is its priority, among the models the runner lists\n // first; an allowlisted id discovery does not list still beats one the user excluded (R1).\n const refill = (effort: string | undefined): TaskModelAssignment | undefined => {\n const id = allowed?.find((a) => listing(a)) ?? allowed?.[0] ?? own[0]?.modelId;\n if (id === undefined) return undefined;\n const known = listing(id);\n const thinkingEffort = clampThinkingEffort(effort, known?.variants ?? []);\n return {\n modelId: id,\n modelLabel: known?.modelLabel ?? id,\n ...(thinkingEffort !== undefined ? { thinkingEffort } : {}),\n ...(known ? { availableVariants: known.variants.map((v) => v.id) } : {}),\n };\n };\n\n if (!written) return { ok: true, assignment: writer === 'runner' ? undefined : refill(undefined) };\n if (writer === 'runner') return { ok: true, assignment: settled(written) };\n\n const id = written.modelId;\n const same = prior?.assignedModel?.modelId === id;\n if (before && same && !moved) return { ok: true, assignment: settled(written) };\n\n const listedElsewhere = Object.entries(models).some(([other, list]) => other !== runner && list?.some((m) => m.modelId === id));\n if (same) {\n // Carried from a task on another runner, it was chosen for that one: it\n // needs this one's listing, or nothing known against it.\n const fits = !moved || !!listing(id) || (own.length === 0 && !listedElsewhere);\n return { ok: true, assignment: fits && allows(id) ? settled(written) : refill(written.thinkingEffort) };\n }\n\n if (writer === 'edit' || writer === 'user') {\n // Allowlisted ids are kept even unlisted (ADR-0003, R1); an empty list is discovery that found nothing.\n const offered = own.length === 0 || !!listing(id) || !!allowed?.includes(id);\n if (!offered) return { ok: false, error: `Runner \"${runner}\" does not offer model \"${id}\"` };\n if (!allows(id)) return { ok: false, error: `Model \"${id}\" is excluded by the allowlist for runner \"${runner}\"` };\n return { ok: true, assignment: settled(written) };\n }\n // Only another runner lists it: it provably cannot run here.\n const disowned = !listing(id) && listedElsewhere;\n return { ok: true, assignment: disowned || !allows(id) ? refill(written.thinkingEffort) : settled(written) };\n}\n\n/**\n * The planner's tasks as they land, subtasks included: each resolved as the\n * planner's ({@link resolveAssignment}, `plan`) against the catalog read now\n * and against the plan's task of the same id, so a model or allowlist that\n * changed since the write was checked is applied and named. A task the\n * planner left alone keeps its model; one whose runner is live keeps all of\n * its assignment. Modes were decided when the task was written, and are not\n * revisited. Nothing is refused here: a write the catalog no longer allows is\n * kept as it was written, and the runner validates last.\n */\nexport function resolveAssignments(\n tasks: readonly Task[],\n planned: readonly Task[],\n catalog: AssignmentCatalog,\n): { tasks: Task[]; adjustments: AssignmentAdjustment[] } {\n const prior = new Map<string, Task>();\n const index = (list: readonly Task[]) => list.forEach((t) => { prior.set(t.id, t); index(t.subtasks ?? []); });\n index(planned);\n const models = { ...catalog, runnerModes: undefined };\n const adjustments: AssignmentAdjustment[] = [];\n const walk = (list: readonly Task[]): Task[] => list.map((task) => {\n const outcome = resolveAssignment({ writer: 'plan', task, before: prior.get(task.id), catalog: models });\n const resolved = outcome.ok ? outcome.task : task;\n if (outcome.ok) adjustments.push(...outcome.adjustments);\n return { ...resolved, subtasks: walk(task.subtasks ?? []) };\n });\n return { tasks: walk(tasks), adjustments };\n}\n","import { z } from 'zod/v4';\nimport { taskKinds, unknownTypeRefusal } from '../models/TaskKind';\n\n/**\n * A task as the planner writes it, by any route: the fields `submit_plan`\n * takes, an `edit_plan` op's or a text reply's `changes`, `task`, `merged` and\n * `parts`. One table holds each field's shape, so the tools' schemas, the text\n * route's parse and the intake ({@link readSpec}) cannot disagree about what a\n * field holds (ADR-0022 P2). What a field means, and which writer may set it,\n * stays with the rules that judge it: this table judges only the shape.\n */\n\n/** A task reference, as every tool and op takes one. */\nexport const taskRef = z.union([z.string().min(1), z.number().int().min(0)]).describe('A task id, \"#order\" (\"#2.1\" for a subtask), a bare order, or a title.');\n\ninterface TaskField {\n schema: z.ZodType;\n /** Where the planner may delegate, if the field reads otherwise there (ADR-0055 D1). */\n delegating?: z.ZodType;\n /** Only a task being made has it: an edit's copy is never read. */\n newOnly?: true;\n /** Only where the planner may delegate is the field listed at all. */\n delegatedOnly?: true;\n /**\n * What a value must be, for {@link readSpec}'s refusal. Absent where a rule\n * of its own judges the shape with a message of its own: a script's body\n * (`scriptBodyErrors`), a loop (`loopSpec`), a delegated task's fields\n * (`delegationErrors`).\n */\n must?: string;\n}\n\nconst ref = z.union([z.string(), z.number()]);\nconst slice = z.enum(['AFK', 'HITL']);\nconst names = z.array(z.string());\nconst REFS = 'a list of task refs, as [\"<id or #order>\"]';\n\nconst modelAssignment = z.looseObject({\n modelId: z.string(),\n modelLabel: z.string().optional(),\n thinkingEffort: z.string().optional().describe(\"A variant id from that model's variants list.\"),\n});\n\n/** Every field, in the order `submit_plan` lists them. */\nconst TASK_FIELDS: Record<string, TaskField> = {\n id: { schema: ref, newOnly: true, must: 'text or a number' },\n order: { schema: z.number(), newOnly: true, must: 'a number' },\n title: { schema: z.string(), must: 'text' },\n description: { schema: z.string(), must: 'text' },\n type: { schema: z.enum(taskKinds(false)), delegating: z.enum(taskKinds(true)), must: 'a kind of task' },\n dependencies: { schema: z.array(ref), must: REFS },\n prompt: { schema: z.string(), must: 'text' },\n userSteps: { schema: z.array(z.looseObject({ order: z.number().optional(), instruction: z.string() })), must: 'a list of steps, as [{\"instruction\": \"...\"}]' },\n assignedRunner: { schema: z.string(), must: 'a runner id' },\n assignedModel: { schema: modelAssignment, must: 'a model, as {\"modelId\": \"...\", \"modelLabel\": \"...\"}' },\n readOnly: { schema: z.boolean().describe('True for a task that must not change any file. Ordewell picks every mode; there is no taskMode.'), must: 'true or false' },\n // Null as well as left out, on a new task too: a model with no variants has none to name.\n thinkingEffort: { schema: z.string().nullable(), must: 'a variant id of the assigned model, or null' },\n autonomy: { schema: slice, must: '\"AFK\" or \"HITL\"' },\n sliceType: { schema: slice, must: '\"AFK\" or \"HITL\"' },\n // Read as any value by design, so judged by no shape: anything but a literal true is a change task (`opsFlag`).\n ops: { schema: z.boolean() },\n userStoriesCovered: { schema: names, newOnly: true, must: 'a list of story names' },\n skills: { schema: names.describe('Task skills (applies-to: task) by name; their bodies go in the runner\\'s prompt. A subtask lists its own.') },\n subtasks: { schema: z.array(z.record(z.string(), z.unknown())), newOnly: true, must: 'a list of tasks' },\n // ADR-0035.\n commands: { schema: z.array(z.array(z.string())).describe('A script task\\'s argument vectors, run in order with no shell, stopping at the first that fails. Exactly one of commands or script.') },\n script: { schema: z.string().describe('A script task\\'s script, run by the research shell. Exactly one of commands or script.') },\n timeoutMs: { schema: z.number().describe('A script task\\'s time limit in milliseconds; ten minutes when left out.') },\n research: { schema: z.boolean().describe('A top-level read-only AI task whose report wakes the planner (ADR-0037 R1). Never in a loop body.'), must: 'true or false' },\n // ADR-0045.\n loop: {\n schema: z.looseObject({\n body: z.array(ref).describe('The ids of the top-level tasks that fix what this check finds; each depends on this task.'),\n maxRounds: z.number().optional().describe('The most times this check runs, 1 to 10; 3 when left out.'),\n }).describe('Makes this task a loop\\'s check: while it fails with rounds left, Ordewell runs the body with its report, then runs it again.'),\n },\n // ADR-0055 D1, judged by `delegationErrors` once the task lands.\n goal: { schema: z.string().describe('A delegated task\\'s goal: what its child plan must achieve, in place of a prompt.'), delegatedOnly: true },\n budget: {\n schema: z.looseObject({ tokens: z.number(), wallClockMs: z.number().optional() })\n .describe('A delegated task\\'s budget, required: tokens, and a time limit in milliseconds if it has one. Carved from what this plan has left.'),\n delegatedOnly: true,\n },\n protectedPaths: {\n schema: names.describe('The paths a delegated task\\'s child may not change: what its check runs and the configuration that runs it. Relative to the repository; `*` is the one wildcard. Required unless it is readOnly.'),\n delegatedOnly: true,\n },\n grants: { schema: names.describe('What a delegated task asks for past the floor, by name: research, delegate or effect.'), delegatedOnly: true },\n scope: {\n schema: z.looseObject({ paths: names.optional(), provides: names.optional(), consumes: names.optional() }).describe('What a delegated task declares it works on. Advisory.'),\n delegatedOnly: true,\n },\n};\n\n/** The fields a task's spec documents: what the prompts may name, and nothing else. */\nexport const TASK_SPEC_FIELDS: readonly string[] = Object.keys(TASK_FIELDS);\n\n/** Whether a task being made (`new`) or an edit's `changes` (`patch`) is read. */\nexport type SpecKind = 'new' | 'patch';\n\nfunction fieldSchema(field: TaskField, delegates: boolean, nullable = false): z.ZodType {\n const schema = (delegates && field.delegating) || field.schema;\n return nullable ? schema.nullable() : schema;\n}\n\n/**\n * A task as `submit_plan` lists and takes it: a title, and every other field\n * optional. Loose, as a field it does not list is the intake's to refuse or\n * ignore (a `taskMode`, say), by the message that says why.\n */\nexport function taskSpecSchema({ delegates = false }: { delegates?: boolean } = {}) {\n const shape: Record<string, z.ZodType> = {};\n for (const [name, field] of Object.entries(TASK_FIELDS)) {\n if (!delegates && field.delegatedOnly) continue;\n const schema = fieldSchema(field, delegates);\n shape[name] = name === 'title' ? schema : schema.optional();\n }\n return z.looseObject(shape);\n}\n\n/**\n * What the table judges of one task's fields: those with a `must`, any kind\n * of task taken for `type`, the rest left to the rule that reads them, so its\n * message is the one the planner gets. A patch takes `null` in every field:\n * what a null means on that task (a script's `prompt` nulled is still a prompt\n * written) is the edit's rules to say. It refuses what {@link readSpec} does.\n */\nfunction judgedSpec(kind: SpecKind) {\n const shape: Record<string, z.ZodType> = {};\n for (const [name, field] of Object.entries(TASK_FIELDS)) {\n if (field.must && !(kind === 'patch' && field.newOnly)) shape[name] = fieldSchema(field, true, kind === 'patch').optional();\n }\n return z.record(z.string(), z.unknown()).pipe(z.looseObject(shape));\n}\n\n/**\n * One op of an `edit_plan` call or a `taskOps` reply, its tasks' fields\n * judged by the table. Each is listed to the planner as an object of task\n * fields: they are `submit_plan`'s, in the same list, and spelling them out\n * four times again would cost every planner turn. One schema serves every\n * planner, delegating or not: which kinds a planner may make is the intake's.\n */\nexport function taskOpSchema() {\n const patch = judgedSpec('patch');\n const made = judgedSpec('new');\n const handle = z.string().optional();\n return z.discriminatedUnion('op', [\n z.object({ op: z.literal('update'), taskId: taskRef, changes: patch }),\n z.object({ op: z.literal('add'), task: made, handle }),\n z.object({ op: z.literal('remove'), taskId: taskRef }),\n z.object({ op: z.literal('reorder'), taskIds: z.array(taskRef) }),\n z.object({ op: z.literal('merge'), taskIds: z.array(taskRef), merged: made, handle }),\n z.object({ op: z.literal('split'), taskId: taskRef, parts: z.array(made), handle }),\n z.object({ op: z.literal('rearm'), taskId: taskRef, changes: patch.optional() }),\n ]);\n}\n\n/** A value as a refusal quotes it, cut short so one long field does not drown the message. */\nfunction shown(value: unknown): string {\n const json = JSON.stringify(value) ?? String(value);\n return json.length > 60 ? `${json.slice(0, 57)}...` : json;\n}\n\n/** One field the spec holds in a shape the table refuses, and why, completing a sentence after the task's name. */\nexport interface SpecError {\n field: string;\n message: string;\n}\n\n/**\n * The fields of `raw` whose shape the table refuses, never coerced to\n * something else: a string where a list belongs once read as no list, and\n * cleared what it named. Each message completes a sentence after the task's\n * name. What another rule judges, and a field the table does not list, is\n * left to that rule; `type` takes every kind, delegated too, so the intake's\n * refusal of a delegated task where none may be is the one that says why; a\n * patch's `null` is the edit's rules' to read, as {@link taskOpSchema}'s is.\n */\nexport function readSpec(raw: unknown, kind: SpecKind): SpecError[] {\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n return [{ field: kind === 'patch' ? 'changes' : 'task', message: `is ${shown(raw)}, which must be an object of task fields` }];\n }\n const errors: SpecError[] = [];\n for (const [name, value] of Object.entries(raw)) {\n const field = Object.hasOwn(TASK_FIELDS, name) ? TASK_FIELDS[name] : undefined;\n if (!field?.must || (kind === 'patch' && field.newOnly) || value === undefined) continue;\n if (fieldSchema(field, true, kind === 'patch').safeParse(value).success) continue;\n errors.push({ field: name, message: name === 'type' ? unknownTypeRefusal(value) : `has \"${name}\" ${shown(value)}, which must be ${field.must}` });\n }\n return errors;\n}\n\n/**\n * Why an op cannot be read, naming the op and the slot, or null when it can:\n * the text route's reading of what `edit_plan`'s schema refuses, so a reply\n * the planner can fix is asked again rather than thrown.\n */\nexport function opShapeRefusal(op: unknown, index: number): string | null {\n const parsed = taskOpSchema().safeParse(op);\n if (parsed.success) return null;\n const kind = typeof op === 'object' && op !== null && typeof (op as { op?: unknown }).op === 'string' ? (op as { op: string }).op : undefined;\n const label = `op ${index + 1}${kind ? ` (${kind})` : ''}`;\n if (!kind || !['update', 'add', 'remove', 'reorder', 'merge', 'split', 'rearm'].includes(kind)) {\n return `${label} needs an \"op\" field: update | add | remove | reorder | merge | split | rearm`;\n }\n const issue = parsed.error.issues[0];\n const path = issue.path.map(String);\n const name = path.find((p) => Object.hasOwn(TASK_FIELDS, p));\n const slot = path.join('.');\n const value = path.reduce<unknown>((at, key) => (typeof at === 'object' && at !== null ? (at as Record<string, unknown>)[key] : undefined), op);\n const must = name && path.at(-1) === name ? TASK_FIELDS[name].must : undefined;\n if (must && name === 'type') return `${label}: \"${slot}\" ${unknownTypeRefusal(value).replace(/^has \"type\" /, 'is ')}`;\n if (must) return `${label}: \"${slot}\" is ${shown(value)}, which must be ${must}`;\n return `${label}: \"${slot}\" is ${value === undefined ? 'missing' : shown(value)}: ${issue.message}`;\n}\n","import { Task, RunnerId, flattenTasksWithParents } from '../models/Task';\nimport { extractObjectsWithKey, stripTrailingCommas, escapeControlCharsInStrings, PlanParseError, PLAN_ENVELOPE_KEY } from './JsonExtractor';\nimport type { RunnerModeInfo } from './ModeResolver';\nimport { scopeOverlaps } from '../models/Delegation';\nimport { plannedTask, checkPlanInvariants, taskWhere, type IntakeCatalog, type PlanTaskError } from './PlannedTask';\n\nexport function parsePlanJson(\n raw: string,\n runners: RunnerId[],\n runnerModes?: Record<RunnerId, RunnerModeInfo[]>,\n autonomousDefault = false,\n): Task[] {\n const { matches, fallback, sawUnbalanced } = extractObjectsWithKey(raw, PLAN_ENVELOPE_KEY);\n\n // A reply can carry several tasks-keyed objects — a schema echo from the\n // prompt, an inline draft, then the real plan. The model's LAST emission is\n // its final answer, so candidates are tried back to front and the first one\n // that fully parses and validates wins.\n const candidates = matches.length > 0 ? [...matches].reverse() : [fallback.json];\n\n let lastError: PlanParseError | null = null;\n for (const json of candidates) {\n try {\n return parsePlanObject(json, raw, runners, runnerModes, autonomousDefault);\n } catch (err) {\n if (!(err instanceof PlanParseError)) throw err;\n // Prefer surfacing the error from the most plan-like candidate: the\n // last one carrying a tasks key (tried first).\n if (!lastError) lastError = err;\n }\n }\n\n // No usable tasks object anywhere, but an object ran off the end of the\n // text: the plan was almost certainly cut off mid-stream.\n if (matches.length === 0 && sawUnbalanced) {\n throw new PlanParseError(\n 'Plan response appears truncated: the model likely hit its output length limit before finishing the JSON.',\n raw,\n { truncated: true },\n );\n }\n throw lastError ?? new PlanParseError('Invalid plan: missing tasks array', raw);\n}\n\nfunction parsePlanObject(\n json: string,\n raw: string,\n runners: RunnerId[],\n runnerModes?: Record<RunnerId, RunnerModeInfo[]>,\n autonomousDefault = false,\n): Task[] {\n const cleaned = stripTrailingCommas(escapeControlCharsInStrings(json));\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(cleaned);\n } catch (err) {\n const detail = err instanceof Error ? err.message : String(err);\n throw new PlanParseError(`Plan response was not valid JSON: ${detail}`, raw);\n }\n\n const result = validatePlanTasks(parsed, runners, runnerModes, autonomousDefault);\n if (result.ok) return result.tasks;\n const [first] = result.errors;\n // An envelope problem (no tasks array, an empty one) keeps the generic\n // re-emit; only a rule broken by a task is worth naming in the corrective.\n throw new PlanParseError(first.message, raw, { semantic: first.taskId !== undefined });\n}\n\nexport type { PlanTaskError } from './PlannedTask';\nexport { requestedSkills } from './PlannedTask';\n\n/** `warnings` name what was accepted but not used, for a channel that can tell the planner. */\nexport type PlanTasksResult = { ok: true; tasks: Task[]; warnings?: string[] } | { ok: false; errors: PlanTaskError[] };\n\n/**\n * Every check a plan's tasks must pass, on an already-parsed `{ tasks }`\n * object — what a plan is held to whichever channel it arrived on. All\n * problems are reported, the slice classification first, so the first is the\n * one the text path's corrective names.\n */\nexport function validatePlanTasks(\n obj: unknown,\n runners: RunnerId[],\n runnerModes?: Record<RunnerId, RunnerModeInfo[]>,\n autonomousDefault = false,\n delegation: Pick<IntakeCatalog, 'delegationRefusal' | 'sealsScripts'> = {},\n): PlanTasksResult {\n const rawTasks = isRecord(obj) ? obj.tasks : undefined;\n if (!Array.isArray(rawTasks)) {\n return { ok: false, errors: [{ field: 'tasks', message: 'Invalid plan: missing tasks array' }] };\n }\n if (rawTasks.length === 0) {\n return { ok: false, errors: [{ field: 'tasks', message: 'Plan contained no tasks' }] };\n }\n\n const planned = rawTasks.map((t) => plannedTask(t, { runners, runnerModes, autonomousDefault, ...delegation }));\n const tasks = planned.map((p) => p.task);\n const errors = [\n ...sliceRequired(tasks),\n ...planned.flatMap((p) => p.errors),\n ...checkPlanInvariants(tasks, runners, runnerModes),\n ];\n\n if (errors.length > 0) return { ok: false, errors };\n const ignored = planned.flatMap((p) => p.ignored);\n const warnings = [\n ...(ignored.some((i) => i.field === 'taskMode')\n ? ['\"taskMode\" is not yours to set and was ignored: each task runs in its runner\\'s mode for the user\\'s autonomy level, or its read-only mode when you set \"readOnly\": true.']\n : []),\n ...ignored.filter((i) => i.field === 'readOnly').map((i) => `${i.message}: it was ignored.`),\n ...scopeOverlaps(tasks),\n ];\n return warnings.length > 0 ? { ok: true, tasks, warnings } : { ok: true, tasks };\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Whether a reply that failed {@link parsePlanJson} actually LOOKED like a\n * plan attempt — a balanced tasks-keyed object, or JSON that got cut off.\n * Distinguishes \"the model tried to emit a plan and botched it\" (worth a\n * corrective retry) from prose that merely mentions `\"tasks\"` (leave alone).\n */\nexport function looksLikePlanAttempt(raw: string): boolean {\n const { matches, sawUnbalanced } = extractObjectsWithKey(raw, PLAN_ENVELOPE_KEY);\n if (matches.length > 0) return true;\n return sawUnbalanced && raw.includes(`\"${PLAN_ENVELOPE_KEY}\"`);\n}\n\n/**\n * A whole plan says how each task is sliced: an edit may leave it to the\n * task's parent or the tasks it was made from, a submitted plan may not.\n */\nfunction sliceRequired(tasks: readonly Task[]): PlanTaskError[] {\n return flattenTasksWithParents(tasks).flatMap(({ task: t, parent }) => {\n const where = taskWhere(t.title, parent?.title);\n const errors: PlanTaskError[] = [];\n if (!t.sliceType) errors.push({ taskId: t.id, field: 'sliceType', message: `${where} is missing sliceType. Every task must specify sliceType (\"AFK\" or \"HITL\").` });\n if (t.type === 'ai' && !t.autonomy) errors.push({ taskId: t.id, field: 'autonomy', message: `AI ${where} is missing autonomy. Every AI task must specify autonomy (\"AFK\" or \"HITL\").` });\n return errors;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACO,IAAM,oBAAoB;AAE1B,IAAM,wBAAwB;AAE9B,IAAM,0BAA0B;AAGhC,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA;AAAA,EACT,YAAY,SAAiB,KAA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