gestalt-mobile 0.72.0 → 0.72.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -141,6 +141,18 @@ server revision. Child `modelPolicy.catalogRevision:null` does not mean the
141
141
  prelaunch catalog is unavailable. `CHILD_NOT_LAUNCHED` is expected before dispatch.
142
142
  Actual missing/incompatible catalogs retain explicit failure codes.
143
143
 
144
+ When the user explicitly requests a replacement in the current supervisor
145
+ session, call `gestalt_org_plan_replace_executor` with `version:1`,
146
+ `reason:"userDirectedReplacement"` and the canonical `canonicalTaskName`
147
+ (for example `l3`). That instruction supplies permission. Mobile checks the
148
+ current plan, root ownership and stopped writer/processes, then persists and
149
+ returns the exact physical identity. Retrying returns the same pending identity;
150
+ resume it if already present in this root, otherwise spawn it once. Full and
151
+ compact `gestalt_org_plan_health` expose it as `executorReplacement` until
152
+ adoption or invalidation. Manual Off and unresolved attention remain independent
153
+ gates. Use the attention tool's `executorReplacement` metadata only when user
154
+ permission is still needed; use takeover only for a new supervisor session.
155
+
144
156
  Health retains `runtimeEnforcement:false`. Its `modelPolicy` evidence separately
145
157
  reports `admissionScope: runtime-attestation`, `admitted:false`, `attested:false`,
146
158
  requested values and observed configured thread settings. Unknown values remain
@@ -71,7 +71,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
71
71
  completed · ${W(t).failedCalls??``} failed`),J(v,r),J(b,o),J(w,s),J(E,`${c??``} · ${l??``}`)},[()=>s(W(t)),()=>W(o).indexOf(W(t).runtimeId)+1,()=>c(W(t).durationMs,`ms`),()=>l(W(t).durationMs,W(t).calls),()=>c(W(t).deliveredBytes,`B`),()=>u(W(t)),()=>l(W(t).deliveredBytes,W(t).calls)]),q(e,n)}),N(n),P(2),q(e,t)},w=e=>{q(e,uh())};Y(S,e=>{W(i)?.groups.length?e(C):e(w,-1)});var T=H(S,2),E=e=>{var t=dh(),n=H(B(t)),r=B(n,!0);N(n),N(t),U(e=>{Z(n,`datetime`,W(i).observedAt),J(r,e)},[()=>new Date(W(i).observedAt).toLocaleString()]),q(e,t)};Y(T,e=>{W(i)?.observedAt&&e(E)}),N(_),N(p),N(f),U(()=>J(g,W(i)?.coverage===`partial`?`Partial coverage`:`No measurements yet`)),q(e,f),et()}Ze();var mh=K(`<main class="svelte-iw6wrs"><h1 class="svelte-iw6wrs">Activity evidence</h1> <!><!></main>`);function hh(e){let t={sessionId:`evidence`,confidence:`reconciling`,aggregateSubagents:`working`,root:{state:`awaitingAgent`,observedAt:`2026-01-01T00:00:00.000Z`,lastActivityAt:`2026-01-01T00:00:00.000Z`},subagents:[{id:`α-worker`,nickname:`α worker`,role:`research`,state:`working`,observedAt:`2026-01-01T00:00:00.000Z`,lastActivityAt:`2026-01-01T00:00:00.000Z`,latestProgress:{text:`Checking the focused tests and reviewing the changed files before the next milestone report.`,occurredAt:`2026-01-01T00:00:00.000Z`}}]},n=[`working`,`awaitingAgent`,`awaitingHuman`,`blocked`,`idle`,`disconnected`];var r=mh(),i=H(B(r),2);rh(i,{get activity(){return t}}),X(H(i),1,()=>n,e=>e,(e,n)=>{{let r=Et(()=>({...t,sessionId:W(n),confidence:W(n)===`blocked`?`stale`:`fresh`,root:{...t.root,state:W(n)},aggregateSubagents:W(n)}));rh(e,{get activity(){return W(r)}})}}),N(r),q(e,r)}function gh(e,t){if(!e||typeof e!=`object`)return!1;let n=e,r=new Set([`working`,`idle`,`awaitingAgent`,`awaitingHuman`,`blocked`,`disconnected`]),i=(e,t=256)=>typeof e==`string`&&e.length<=t,a=e=>Array.isArray(e)&&e.length<=64&&e.every(e=>{let t=e;return t&&typeof t==`object`&&[`running`,`detached-active`,`exited-awaiting-result`,`result-consumed`,`terminated-for-budget`].includes(t.state)&&[`executor`,`supervisor`].includes(t.ownership)&&i(t.observedAt,64)&&!Number.isNaN(Date.parse(t.observedAt))}),o=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return i(t.state,32)&&r.has(t.state)&&i(t.observedAt,64)&&i(t.lastActivityAt,64)&&!Number.isNaN(Date.parse(t.observedAt))&&!Number.isNaN(Date.parse(t.lastActivityAt))&&(t.reason===void 0||i(t.reason,64))&&(t.latestProgress===void 0||t.latestProgress!==null&&typeof t.latestProgress==`object`&&i(t.latestProgress.text,512)&&!!t.latestProgress.text.trim()&&i(t.latestProgress.occurredAt,64)&&!Number.isNaN(Date.parse(t.latestProgress.occurredAt)))&&(t.contextUsedPercent===void 0||Number.isInteger(t.contextUsedPercent)&&t.contextUsedPercent>=0&&t.contextUsedPercent<=100)};return i(n.sessionId)&&(!t||n.sessionId===t)&&o(n.root)&&Array.isArray(n.subagents)&&n.subagents.length<=64&&n.subagents.every(e=>o(e)&&i(e.id)&&(e.nickname===void 0||i(e.nickname))&&(e.role===void 0||i(e.role))&&(e.model===void 0||i(e.model))&&(e.canonicalTaskName===void 0||i(e.canonicalTaskName))&&(e.canonicalPosition===void 0||i(e.canonicalPosition,32))&&(e.continuationGeneration===void 0||Number.isInteger(e.continuationGeneration)&&e.continuationGeneration>0)&&(e.outcome===void 0||[`partial`,`cancelled`,`failed`].includes(e.outcome))&&(e.ownedProcesses===void 0||a(e.ownedProcesses)))&&i(n.aggregateSubagents,32)&&r.has(n.aggregateSubagents)&&(n.confidence===`fresh`||n.confidence===`stale`||n.confidence===`reconciling`)}function _h(e,t){let n=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null,r=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=0,i=e=>typeof e==`string`&&/^[a-zA-Z0-9_.:/-]{1,256}$/.test(e),a=n(e);if(!a||!i(a.sessionId)||a.sessionId!==t||!r(a.revision)||a.scope!==`observedCallsOnly`||![`partial`,`unknown`].includes(String(a.coverage))||typeof a.missingCorrelation!=`boolean`||typeof a.retentionLimited!=`boolean`||!Array.isArray(a.groups)||a.groups.length>64||!(a.observedAt===null||typeof a.observedAt==`string`&&a.observedAt.length<=64&&Number.isFinite(Date.parse(a.observedAt))))return null;let o=[],s=new Set;for(let e of a.groups){let t=n(e);if(!t||!i(t.runtimeId)||!i(t.threadId)||![`root`,`child`,`unknown`].includes(String(t.actor))||![`command`,`mcp`,`contextMode`,`executionWrapper`,`dynamic`,`collaboration`].includes(String(t.family))||t.layer!==(t.family===`executionWrapper`?`wrapper`:`tool`)||!r(t.calls)||t.calls<1||t.calls>1024||!r(t.completedCalls)||t.completedCalls>t.calls||!r(t.failedCalls)||t.failedCalls>t.calls||!(t.deliveredScope===null||typeof t.deliveredScope==`string`&&[`commandOutputUtf8`,`serializedMcpContent`,`serializedDynamicContent`].includes(t.deliveredScope)))return null;let a=JSON.stringify([t.runtimeId,t.threadId,t.actor,t.family]);if(s.has(a))return null;s.add(a);let c={};for(let e of[`durationMs`,`deliveredBytes`,`rawBytes`,`processedBytes`,`retries`,`reusedCalls`,`truncatedCalls`]){let i=n(t[e]);if(!i||!(i.value===null||r(i.value))||!r(i.measuredCalls)||i.measuredCalls>t.calls||i.value!==null&&i.measuredCalls===0||![`complete`,`partial`,`unknown`].includes(String(i.coverage))||i.coverage===`complete`&&(i.value===null||i.measuredCalls!==t.calls)||i.coverage===`unknown`&&(i.value!==null||i.measuredCalls!==0))return null;c[e]={value:i.value,measuredCalls:i.measuredCalls,coverage:i.coverage}}let l=n(t.completeness),u={};for(let e of[`capture`,`display`,`evidence`]){let i=n(l?.[e]);if(!i||!r(i.complete)||!r(i.partial)||!r(i.unknown)||!r(i.missing)||i.complete+i.partial+i.unknown+i.missing!==t.calls)return null;u[e]={complete:i.complete,partial:i.partial,unknown:i.unknown,missing:i.missing}}o.push({runtimeId:t.runtimeId,threadId:t.threadId,actor:t.actor,family:t.family,layer:t.layer,calls:t.calls,completedCalls:t.completedCalls,failedCalls:t.failedCalls,...c,deliveredScope:t.deliveredScope,completeness:u})}return o.reduce((e,t)=>e+t.calls,0)>1024?null:{sessionId:t,revision:a.revision,observedAt:a.observedAt,scope:`observedCallsOnly`,coverage:a.coverage,missingCorrelation:a.missingCorrelation,retentionLimited:a.retentionLimited,groups:o}}var vh=class{#e=new Map;#t=new Map;#n=new Map;#r=new Set;#i=new Map;#a=new Map;#o=new Map;#s=new Map;#c=new Map;#l=null;#u=!1;#d;constructor(e){this.#d={...e,websocket:e.websocket??(e=>new WebSocket(e)),location:e.location??location,setTimeout:e.setTimeout??setTimeout,clearTimeout:e.clearTimeout??clearTimeout}}get(e){return e?this.#e.get(e)??null:null}getEfficiency(e){return e?this.#t.get(e)??null:null}bootstrap(e,t){for(let t of e)!this.#e.has(t.id)&&gh(t.agentActivity,t.id)&&this.#m(t.id,this.#n.get(t.id)??0,t.agentActivity);this.sync(e.map(e=>e.id),t)}sync(e,t){if(!this.#u){this.#l=t,this.#r=new Set(e);for(let e of this.#r)this.#a.has(e)||this.#a.set(e,0);for(let e of[...this.#a.keys()])this.#r.has(e)||this.remove(e);for(let[e,n]of this.#i)(e===t||!this.#r.has(e))&&(n.close(),this.#i.delete(e));for(let e of this.#r)this.hydrate(e),e!==t&&!this.#i.has(e)&&this.#p(e)}}select(e){this.sync([...this.#r],e)}remove(e){this.#r.delete(e),this.#a.set(e,(this.#a.get(e)??0)+1),this.#i.get(e)?.close(),this.#i.delete(e);let t=this.#o.get(e);t&&this.#d.clearTimeout(t),this.#o.delete(e),this.#s.delete(e),this.#c.delete(e),this.#e.delete(e),this.#t.delete(e),this.#d.publishEfficiency?.(this.#t),this.#n.delete(e),this.#d.publish(this.#e)}observe(e,t){if(this.#u||!this.#r.has(e)||!Number.isSafeInteger(t.sequence)||t.sequence<1||t.sessionId!==void 0&&t.sessionId!==e)return;let n=this.#n.get(e)??0;t.sequence<=n||(t.sequence>n+1&&(this.#n.set(e,t.sequence-1),this.resync(e)),this.#n.set(e,t.sequence),this.#d.onEvent?.(e,t),t.type===`agent.activity.updated`&&gh(t.payload,e)&&this.#m(e,t.sequence,t.payload),t.type===`tool.efficiency.updated`&&this.#h(e,t.payload))}async hydrate(e){let t=this.#a.get(e)??0,n=this.#n.get(e)??0;try{let r=await this.#d.relay.getSession(e);if(!this.#f(e,t))return;let i=this.#n.get(e)??0,a=r.currentSequence;if(Number.isSafeInteger(a)&&a>=0){if(a<i)return;this.#n.set(e,a),gh(r.agentActivity,e)&&this.#m(e,a,r.agentActivity),this.#h(e,r.toolEfficiency),this.#d.onAuthoritativeSnapshot?.(e,r)}else i===n&&(gh(r.agentActivity,e)&&(this.#m(e,i,r.agentActivity),this.#d.onAuthoritativeSnapshot?.(e,r)),this.#h(e,r.toolEfficiency))}catch{this.#g(e)}}async resync(e){let t=this.#s.get(e);if(t)return t;let n=this.#a.get(e)??0;this.#g(e);let r;return r=(async()=>{try{await this.#d.relay.refreshActivity(e),this.#f(e,n)&&await this.hydrate(e)}catch{}finally{this.#s.get(e)===r&&this.#s.delete(e)}})(),this.#s.set(e,r),r}dispose(){this.#u=!0;for(let e of[...this.#r])this.remove(e)}#f(e,t){return!this.#u&&this.#r.has(e)&&this.#a.get(e)===t}#p(e){let t=this.#a.get(e)??0,n=this.#d.location.protocol===`https:`?`wss:`:`ws:`,r=this.#d.websocket(`${n}//${this.#d.location.host}/api/sessions/${encodeURIComponent(e)}/events?after=${this.#n.get(e)??0}`);this.#i.set(e,r),r.onmessage=n=>{if(!(!this.#f(e,t)||this.#i.get(e)!==r))try{this.#c.delete(e);let t=JSON.parse(String(n.data));t.type===`relay.resyncRequired`?this.resync(e):t.type===`relay.event`&&t.event&&this.observe(e,t.event)}catch{}},r.onclose=()=>{if(!this.#f(e,t)||this.#l===e)return;this.#i.delete(e),this.#g(e);let n=this.#c.get(e)??0,r=(this.#d.reconnectDelaysMs??[250,1e3,5e3])[n];r!==void 0&&(this.#c.set(e,n+1),this.#o.set(e,this.#d.setTimeout(()=>{this.#o.delete(e),this.#f(e,t)&&e!==this.#l&&this.#p(e)},r)))}}#m(e,t,n){let r=this.#e.get(e);this.#n.set(e,Math.max(t,this.#n.get(e)??0)),JSON.stringify(r)!==JSON.stringify(n)&&(this.#e.set(e,n),this.#d.publish(this.#e))}#h(e,t){let n=_h(t,e);!n||n.revision<=(this.#t.get(e)?.revision??-1)||(this.#t.set(e,n),this.#d.publishEfficiency?.(this.#t))}#g(e){let t=this.#e.get(e);t&&t.confidence===`fresh`&&(this.#e.set(e,{...t,confidence:`stale`}),this.#d.publish(this.#e))}};function yh(e=globalThis.crypto,t=Date.now,n=Math.random){return typeof e?.randomUUID==`function`?e.randomUUID():`k-${t().toString(36)}-${Math.floor(n()*4294967296).toString(36)}`}var bh={contextWindowExceeded:`The conversation exceeds the model context window. Compact it or start a new session.`,sessionBudgetExceeded:`The Codex session budget is exhausted. Review its budget before continuing.`,usageLimitExceeded:`Codex usage limit reached. Restore available usage or wait for the limit to reset, then resume Autopilot.`,rateLimitExceeded:`The request rate limit was reached. Wait before retrying.`,flexUnavailable:`Flex processing is unavailable. Retry later or select another service tier.`,serverOverloaded:`The model service is overloaded. Retry later.`,cyberPolicy:`Codex blocked the request under its cybersecurity policy.`,misalignmentPolicyViolation:`Codex blocked the request under its safety policy.`,tooManyDenials:`Execution stopped after too many denied requests. Review the requested actions.`,httpConnectionFailed:`The provider HTTP connection failed. Check connectivity and provider availability.`,responseStreamConnectionFailed:`Codex could not connect to the response stream.`,responseStreamDisconnected:`The provider response stream disconnected before completion.`,responseTooManyFailedAttempts:`The provider response failed after repeated attempts.`,internalServerError:`Codex encountered an internal server error. Retry later.`,unauthorized:`Provider authorization failed. Check the account sign-in or credentials.`,badRequest:`The provider rejected the request. Check the selected model and request settings.`,threadRollbackFailed:`Codex could not roll back the thread.`,sandboxError:`Codex could not execute an action in its sandbox. Review the execution policy.`,activeTurnNotSteerable:`The active turn cannot accept steering. Wait for it to finish.`,other:`Codex reported an unclassified execution failure.`};function xh(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let{code:t,httpStatusCode:n}=e;if(!(typeof t!=`string`||!/^[A-Za-z][A-Za-z0-9_]{0,79}$/.test(t))&&!(n!==void 0&&(typeof n!=`number`||!Number.isInteger(n)||n<100||n>599)))return{code:t,...n===void 0?{}:{httpStatusCode:n}}}function Sh(e){let t=Object.hasOwn(bh,e.code)?bh[e.code]:`Codex reported an execution failure with no known description.`;return`${e.code}${e.httpStatusCode?` (HTTP ${e.httpStatusCode})`:``}: ${t}`}function Ch(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e;if(!(typeof t.turnId!=`string`||!t.turnId||t.turnId.length>256||!Number.isInteger(t.attempt)||Number(t.attempt)<1||Number(t.attempt)>2||typeof t.notBefore!=`string`||!Number.isFinite(Date.parse(t.notBefore))||typeof t.settled!=`boolean`||typeof t.pending!=`boolean`||typeof t.resumeRoot!=`boolean`))return{turnId:t.turnId,attempt:t.attempt,notBefore:t.notBefore,settled:t.settled,pending:t.pending,resumeRoot:t.resumeRoot}}function wh(e){if(typeof e!=`string`||!e.trim())return;let t=e.trim();return t.length<=4e3?t:`${t.slice(0,3999)}…`}var Th=`Checkpoint handoff failed. Autopilot is reconnecting this session automatically. If it cannot recover, restore or reopen the session.`,Eh=`Autopilot is recovering after a continuation or agent status check failed. It will retry automatically. If recovery persists, retry Autopilot or restore the session.`;function Dh(e){return!!(e?.enabled&&e.state===`monitoring`&&e.reason===`reconcileFailed`&&e.health?.healthy!==!0)}var Oh=(e,t=600)=>typeof e==`string`&&e.length<=t,kh=e=>Oh(e,64)&&!Number.isNaN(Date.parse(e));function Ah(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.enabled==`boolean`&&typeof t.state==`string`&&[`disabled`,`monitoring`,`backoff`,`attentionRequired`,`completed`,`safetyPaused`].includes(t.state)&&!!t.retry&&typeof t.retry==`object`&&Number.isInteger(t.retry.position)&&Number.isInteger(t.retry.limit)&&Oh(t.updatedAt,64)&&(t.reason===void 0||Oh(t.reason,80))&&(t.providerFailure===void 0||!!xh(t.providerFailure))&&(t.providerRetry===void 0||!!Ch(t.providerRetry))&&(t.nextEvaluationAt===void 0||Oh(t.nextEvaluationAt,64))&&(t.health===void 0||jh(t.health))}function jh(e){if(!e||typeof e!=`object`)return!1;let t=e;if(!t.wait||typeof t.wait!=`object`)return!1;let n=t.wait;return typeof t.healthy==`boolean`&&typeof t.phase==`string`&&[`off`,`rootWorking`,`continuationScheduled`,`waitingForAgentEvent`,`checkingState`,`needsYou`,`safetyPaused`,`complete`,`checkpointRecovery`,`degraded`].includes(t.phase)&&[`active`,`probeRequired`,`parked`,`retrying`,`attentionRequired`,`safetyPaused`,`none`].includes(t.supervision)&&typeof n.present==`boolean`&&Array.isArray(n.wakeCategories)&&n.wakeCategories.length<=9&&new Set(n.wakeCategories).size===n.wakeCategories.length&&n.wakeCategories.every(e=>[`planChanged`,`reviewChanged`,`checkpointChanged`,`interactionChanged`,`executorChanged`,`processExited`,`processResultAvailable`,`processLimitBreached`,`agentActivityChanged`].includes(e))&&(n.resumeAt===void 0||kh(n.resumeAt))&&kh(t.observedAt)&&kh(t.lastTransitionAt)&&Oh(t.nextExpectedAction)&&(t.degradationReason===void 0||[`missingContinuation`,`invalidWaitLease`,`controllerUnavailable`,`staleTransition`,`planMismatch`].includes(t.degradationReason))}function Mh(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t.attention;if(!n||typeof n!=`object`)return!1;let r=n;return Oh(t.requestId,256)&&(t.turnId===null||Oh(t.turnId,256))&&(t.requestedAt===null||Oh(t.requestedAt,64))&&(t.supervisorReport===void 0||Oh(t.supervisorReport,4e3))&&Oh(r.reason,64)&&Oh(r.summary)&&Oh(r.requestedAction)&&Oh(r.resumeCondition,64)&&(r.executorReplacement===void 0||Nh(r.executorReplacement))}function Nh(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return Object.keys(t).length===1&&typeof t.canonicalTaskName==`string`&&/^l[1-9][0-9]*$/.test(t.canonicalTaskName)}function Ph(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`orgPlanAttention`&&Mh({requestId:t.requestId,turnId:t.turnId??null,requestedAt:t.requestedAt??null,attention:t.payload,supervisorReport:t.supervisorReport})}function Fh(e){return{requestId:e.requestId,turnId:e.turnId,requestedAt:e.requestedAt,attention:e.payload,...e.supervisorReport?{supervisorReport:e.supervisorReport}:{}}}var Ih=e=>{let t=e&&typeof e==`object`?e.code:void 0;return t===`AUTOPILOT_PLAN_REQUIRED`?`An incomplete supervised plan is required before Autopilot can start.`:t===`AUTOPILOT_PLAN_COMPLETE`?`This plan is complete, so Autopilot is unavailable.`:t===`AUTOPILOT_MODEL_POLICY_UNAVAILABLE`?`Autopilot cannot verify this plan’s executor settings. Automatic execution is unavailable; manual review and repair remain available.`:t===`AUTOPILOT_SESSION_UNAVAILABLE`?`This session is unavailable for Autopilot.`:e instanceof Error?e.message:`Could not update Autopilot.`},Lh=class{relay;publish;createKey;#e=new Map;#t=new Map;#n=new Set;#r=new Map;#i=new Map;#a=new Map;#o=new Map;#s=new Map;#c=new Map;#l=new Map;#u=new Map;#d=new Map;#f=new Set;#p=!1;constructor(e,t,n=yh){this.relay=e,this.publish=t,this.createKey=n}bootstrap(e){if(this.#p)return;let t=new Set(e.map(e=>e.id));for(let e of this.#f)t.has(e)||this.remove(e);this.#f=t;for(let t of e){this.#a.has(t.id)||this.#a.set(t.id,0),this.#o.has(t.id)||this.#o.set(t.id,0);let e=this.#d.get(t.id)??0,n=typeof t.currentSequence==`number`&&Number.isInteger(t.currentSequence)?t.currentSequence:null,r=this.#l.get(t.id);!this.#n.has(t.id)&&(r===void 0||n!==null&&n>r)&&(n!==null&&n>e||!this.#e.has(t.id)&&e===0)&&(n!==null&&(this.#d.set(t.id,n),r!==void 0&&n>r&&this.#l.delete(t.id)),this.#_(t.id,t))}this.#v()}observe(e,t){if(this.#p||!this.#f.has(e)||!Number.isInteger(t.sequence))return;let n=this.#d.get(e)??0;if(!(t.sequence<=n)){if(this.#d.set(e,t.sequence),this.#o.set(e,(this.#o.get(e)??0)+1),t.type===`autopilot.updated`&&this.#h(e,t.payload),t.type===`org-plan.attention-required`&&this.#g(e,t.payload),t.type===`agentMessageCompleted`&&t.payload&&typeof t.payload==`object`){let n=t.payload,r=this.#t.get(e),i=wh(n.text);r?.turnId&&r.turnId===n.turnId&&n.phase===`final_answer`&&i&&this.#t.set(e,{...r,supervisorReport:i})}t.type===`org-plan.attention-resolved`&&(t.payload&&typeof t.payload==`object`&&t.payload.outcome,this.#t.delete(e)),this.#v()}}async hydrate(e,t){let n=this.#a.get(e)??0,r=(this.#u.get(e)??0)+1;this.#u.set(e,r);let i=t??this.#d.get(e)??0,a=this.#s.get(e),o=this.#c.get(e)??0;try{let t=await this.relay.getSession(e);if(!this.#m(e,n)||this.#u.get(e)!==r||(this.#c.get(e)??0)!==o||this.#s.has(e)&&this.#s.get(e)!==a)return;let s=this.#d.get(e)??0,c=typeof t.currentSequence==`number`&&Number.isInteger(t.currentSequence)?t.currentSequence:null;c!==null&&c>s?(this.#d.set(e,c),this.#_(e,t)):c===null&&s===i&&this.#_(e,t),this.#v()}catch{}}async toggle(e,t){if(this.#p||!this.#f.has(e)||this.#n.has(e))return;let n=this.#a.get(e)??0,r=this.#o.get(e)??0;this.#s.set(e,(this.#s.get(e)??0)+1),this.#c.set(e,(this.#c.get(e)??0)+1),this.#n.add(e),this.#r.delete(e),this.#i.delete(e),this.#v();try{let i=await this.relay.setAutopilot(e,t,this.createKey());this.#m(e,n)&&this.#o.get(e)===r&&(this.#h(e,i.autopilot),this.#o.set(e,r+1),this.#l.set(e,this.#d.get(e)??0),Ah(i.autopilot)&&!i.autopilot.enabled&&this.#t.delete(e))}catch(t){this.#m(e,n)&&this.#o.get(e)===r&&this.#r.set(e,Ih(t))}finally{this.#m(e,n)&&(this.#n.delete(e),this.#c.set(e,(this.#c.get(e)??0)+1)),this.#v()}}async resolve(e,t,n){let r=this.#t.get(e);if(!r||this.#n.has(e)||this.#p)return;let i=n?.trim();if(i&&i.length>600){this.#r.set(e,`Guidance must be 600 characters or fewer.`),this.#v();return}let a=this.#a.get(e)??0,o=this.#o.get(e)??0;this.#c.set(e,(this.#c.get(e)??0)+1),this.#n.add(e),this.#r.delete(e),this.#v();try{await this.relay.resolveAttention(e,r.requestId,{operationKey:this.createKey(),action:t,...i?{guidance:i}:{}}),this.#m(e,a)&&this.#o.get(e)===o&&await this.hydrate(e)}catch(t){this.#m(e,a)&&this.#o.get(e)===o&&this.#r.set(e,t instanceof Error?t.message:`Could not resolve attention.`)}finally{this.#m(e,a)&&(this.#n.delete(e),this.#c.set(e,(this.#c.get(e)??0)+1)),this.#v()}}remove(e){this.#a.set(e,(this.#a.get(e)??0)+1),this.#f.delete(e),this.#e.delete(e),this.#i.delete(e),this.#t.delete(e),this.#n.delete(e),this.#r.delete(e),this.#d.delete(e),this.#o.delete(e),this.#s.delete(e),this.#c.delete(e),this.#l.delete(e),this.#u.delete(e),this.#v()}dispose(){this.#p=!0,this.#f.clear(),this.#e.clear(),this.#t.clear(),this.#n.clear(),this.#r.clear(),this.#i.clear(),this.#u.clear(),this.#o.clear(),this.#s.clear(),this.#c.clear(),this.#l.clear(),this.#v()}#m(e,t){return!this.#p&&this.#f.has(e)&&this.#a.get(e)===t}#h(e,t){Ah(t)&&(this.#e.set(e,t),t.providerFailure?this.#i.set(e,Sh(t.providerFailure)):t.health?.phase===`checkpointRecovery`?this.#i.set(e,Th):Dh(t)?this.#i.set(e,Eh):t.state===`safetyPaused`&&t.reason===`usageLimitExceeded`?this.#i.set(e,`Codex usage limit reached. Restore available usage or wait for the limit to reset, then resume Autopilot.`):this.#i.delete(e))}#g(e,t){if(Mh(t))this.#t.set(e,t);else if(Ph(t))this.#t.set(e,Fh(t));else if(Array.isArray(t)){let n=t.find(Ph);n?this.#t.set(e,Fh(n)):this.#t.delete(e)}}applyAuthoritative(e,t){if(this.#p||!this.#f.has(e)||this.#n.has(e))return;let n=typeof t.currentSequence==`number`&&Number.isInteger(t.currentSequence)?t.currentSequence:null,r=this.#d.get(e)??0,i=this.#l.get(e);i!==void 0&&(n===null||n<=i)||n!==null&&n<r||(n!==null&&(this.#d.set(e,n),i!==void 0&&n>i&&this.#l.delete(e)),this.#_(e,t),this.#v())}#_(e,t){this.#o.set(e,(this.#o.get(e)??0)+1),this.#h(e,t.autopilot),this.#g(e,t.pendingInteractions)}#v(){this.publish({snapshots:new Map(this.#e),attention:new Map(this.#t),pending:new Set(this.#n),errors:new Map([...this.#r,...this.#i])})}},Rh=K(`<span aria-hidden="true" class="svelte-1qf1ppf"> </span> `,1),zh=K(`<div class="control-row svelte-1qf1ppf"><span class="status svelte-1qf1ppf"><span aria-hidden="true" class="svelte-1qf1ppf"> </span> </span> <!></div>`),Bh=K(`<section aria-label="Autopilot"><p class="visually-hidden svelte-1qf1ppf" data-testid="autopilot-live-status" aria-live="polite" aria-atomic="true"> </p> <!> <p> </p></section>`);function Vh(e,t){F(t,!0);let n=Q(t,`controlId`,3,`autopilot-control`),r=Q(t,`compact`,3,!1),i=Q(t,`indicatorOnly`,3,!1),a=Q(t,`pending`,3,!1),o=Q(t,`ontoggle`,3,()=>{}),s={disabled:`Off`,monitoring:`Monitoring`,backoff:`Waiting to continue`,attentionRequired:`Paused for attention`,completed:`Complete`,safetyPaused:`Safety paused`},c={off:`Off`,rootWorking:`On · root working`,continuationScheduled:`On · continuation scheduled`,waitingForAgentEvent:`On · waiting for agent event`,checkingState:`On · checking state`,needsYou:`Paused · needs you`,safetyPaused:`Safety paused`,complete:`Complete`,checkpointRecovery:`Recovering checkpoint handoff`,degraded:`On · continuation unavailable`},l={planRequired:`An incomplete supervised plan is required before Autopilot can start.`,planComplete:`This plan is complete, so Autopilot is unavailable.`,sessionUnavailable:`This session is unavailable for Autopilot.`,attentionRequired:`Autopilot is paused because an agent is waiting for human input.`,noPlanProgress:`Autopilot paused because the plan did not make durable progress.`,reconcileFailed:`Autopilot paused because it could not safely confirm session state.`,startUnavailable:`Automatic continuation could not start because the session runtime is unavailable. Restore or reopen the session, then retry Autopilot.`,actionRateExceeded:`Autopilot paused after too many automatic actions in ten minutes. Wait for the safety window to clear, or continue manually.`,planRemoved:`The retained plan was removed.`,planReplaced:`The retained plan changed. Enable Autopilot again after reviewing it.`,sessionEnded:`This session ended.`,manualDisabled:`Autopilot is off.`,safetyPaused:`Autopilot paused after a repeated or invalid automatic continuation. Resume manually when ready.`,checkpointHandoffFailed:Th},u=I(()=>t.autopilot?t.autopilot.health?c[t.autopilot.health.phase]:s[t.autopilot.state]:`Unavailable`),d=I(()=>t.autopilot?.state===`backoff`&&t.autopilot.retry.position>0&&t.autopilot.retry.limit>0?`Retry ${t.autopilot.retry.position} of ${t.autopilot.retry.limit}.`:null),f=I(()=>(t.autopilot?.reason?l[t.autopilot.reason]:null)??W(d)??t.autopilot?.health?.nextExpectedAction??(t.autopilot?.state===`monitoring`?`Autopilot is monitoring this supervised plan.`:t.autopilot?.state===`attentionRequired`?`Autopilot is paused because human attention is required.`:`Autopilot state is loading from the relay.`)),p=I(()=>`Autopilot status: ${W(u)}. ${W(f)}`),m=I(()=>t.autopilot?.enabled??!1),h=I(()=>t.autopilot?.state===`safetyPaused`||t.autopilot?.health?.phase===`degraded`);var g=Bh();let _;var v=B(g),y=B(v,!0);N(v);var b=H(v,2),x=e=>{{let t=I(()=>`${n()}-button`),r=I(()=>i()?`Autopilot: ${a()?`Updating`:W(u)}`:void 0),s=I(()=>`${n()}-help`);Wm(e,{get id(){return W(t)},compact:!0,full:!0,get pressed(){return W(m)},get accentPressed(){return i()},get label(){return W(r)},get describedby(){return W(s)},get ariaDisabled(){return a()},onclick:()=>{a()||o()(!W(m))},children:(e,t)=>{var n=Yr(),r=V(n),o=e=>{q(e,Jr(`Autopilot`))},s=e=>{var t=Rh(),n=V(t),r=B(n,!0);N(n);var i=H(n);U(()=>{J(r,W(m)?`●`:`○`),J(i,` Autopilot: ${(a()?`Updating…`:W(u))??``}`)}),q(e,t)};Y(r,e=>{i()?e(o):e(s,-1)}),q(e,n)},$$slots:{default:!0}})}},S=e=>{var r=zh(),i=B(r),s=B(i),c=B(s,!0);N(s);var l=H(s);N(i);var d=H(i,2);{let e=I(()=>`${n()}-button`),t=I(()=>`${n()}-help`);Wm(d,{get id(){return W(e)},get pressed(){return W(m)},get describedby(){return W(t)},get ariaDisabled(){return a()},onclick:()=>{a()||o()(!W(m))},children:(e,t)=>{P();var n=Jr();U(()=>J(n,a()?`Updating…`:W(m)?`Pause`:`Enable`)),q(e,n)},$$slots:{default:!0}})}N(r),U(()=>{Z(i,`data-state`,t.autopilot?.state??`unavailable`),J(c,W(m)?`●`:`○`),J(l,` Autopilot: ${W(u)??``}`)}),q(e,r)};Y(b,e=>{r()?e(x):e(S,-1)});var C=H(b,2);let w;var T=B(C,!0);N(C),N(g),U(()=>{_=Ei(g,1,`autopilot-control svelte-1qf1ppf`,null,_,{compact:r(),"has-error":i()&&W(h)}),J(y,W(p)),Z(C,`id`,`${n()}-help`),w=Ei(C,1,`svelte-1qf1ppf`,null,w,{"visually-hidden":r()}),J(T,W(f))}),q(e,g),et()}var Hh=K(`<p class="svelte-yp6bgs"> </p>`),Uh=K(`<p class="svelte-yp6bgs"> </p> <p class="svelte-yp6bgs"> </p>`,1),Wh=K(`<button type="button" class="svelte-yp6bgs"> </button>`),Gh=K(`<section role="alert"><h3 class="svelte-yp6bgs"> </h3> <!> <div class="actions svelte-yp6bgs"><!> <button type="button" class="svelte-yp6bgs"> </button></div></section>`);function Kh(e,t){F(t,!0);let n=Q(t,`controlId`,3,`autopilot-safety-stop`),r=Q(t,`pending`,3,!1),i=Q(t,`onrecover`,3,()=>{}),a=Q(t,`ondisable`,3,()=>{}),o={attentionRequired:`The coordinator stopped because it needs a human safety decision, but no actionable agent request is available.`,noPlanProgress:`The coordinator stopped because recent automatic turns made no durable plan progress.`,reconcileFailed:`The coordinator stopped because it could not safely confirm the session state.`,startUnavailable:`The coordinator stopped because the session runtime was unavailable when it tried to start an automatic turn.`,actionRateExceeded:`The coordinator stopped because it reached the automatic-action safety limit.`},s=I(()=>t.autopilot?.providerFailure),c=I(()=>!!(W(s)&&[`disabled`,`completed`].includes(t.autopilot?.state??``))),l=I(()=>t.autopilot?.providerRetry?.pending??!1),u=I(()=>W(s)?Sh(W(s)):t.autopilot?.reason&&!t.attention?o[t.autopilot.reason]??null:null),d=I(()=>Dh(t.autopilot)),f=I(()=>W(c)?`Automatic supervision was not running. Retry your message when the provider is available.`:W(l)?`A delayed retry is scheduled (attempt ${t.autopilot?.providerRetry?.attempt} of 2). It will proceed only after the failed turn has ended and the session is idle.`:W(s)?`Address this failure, then retry Autopilot when ready.`:t.autopilot?.reason===`startUnavailable`?`There is no pending agent attention request to answer. Restore or reopen this session, then retry Autopilot.`:t.autopilot?.reason===`actionRateExceeded`?`There is no pending agent attention request to answer. Wait for the ten-minute safety window to clear, or continue manually.`:`There is no pending agent attention request to answer. Retry the supported Autopilot coordinator after addressing the cause, or disable it.`);var p=Yr(),m=V(p),h=e=>{var t=Gh();let o;var p=B(t),m=B(p,!0);N(p);var h=H(p,2),g=e=>{var t=Hh(),n=B(t,!0);N(t),U(()=>J(n,Eh)),q(e,t)},_=e=>{var t=Uh(),n=V(t),r=B(n,!0);N(n);var i=H(n,2),a=B(i,!0);N(i),U(()=>{J(r,W(u)),J(a,W(f))}),q(e,t)};Y(h,e=>{W(d)?e(g):e(_,-1)});var v=H(h,2),y=B(v),b=e=>{var t=Wh(),n=B(t,!0);N(t),U(()=>{t.disabled=r()||W(l),J(n,r()?`Updating…`:`Retry Autopilot`)}),G(`click`,t,function(...e){i()?.apply(this,e)}),q(e,t)};Y(y,e=>{W(c)||e(b)});var x=H(y,2),S=B(x,!0);N(x),N(v),N(t),U(e=>{o=Ei(t,1,`safety-stop svelte-yp6bgs`,null,o,e),Z(t,`aria-labelledby`,`${n()}-title`),Z(p,`id`,`${n()}-title`),J(m,W(s)?W(c)?`Codex request failed`:`Codex execution paused`:W(d)?`Autopilot recovery warning`:`Autopilot safety stop`),x.disabled=r(),J(S,W(c)?`Dismiss`:`Disable Autopilot`)},[()=>({recovering:W(d)||!!W(s)})]),G(`click`,x,function(...e){a()?.apply(this,e)}),q(e,t)};Y(m,e=>{!t.attention&&(W(s)||W(d)||t.autopilot?.state===`attentionRequired`&&W(u))&&e(h)}),q(e,p),et()}Vr([`click`]);function qh(e,t=`gestalt-mobile.autopilot-attention-toasts.v1`,n=100){let r=Jh(e,t,n);return{claim(i){if(r.has(i))return!1;r=new Set([...r,i].slice(-n));try{e?.setItem(t,JSON.stringify([...r]))}catch{}return!0}}}function Jh(e,t,n){try{let r=JSON.parse(e?.getItem(t)??`[]`);return new Set(Array.isArray(r)?r.filter(e=>typeof e==`string`).slice(-n):[])}catch{return new Set}}var Yh=100*1024*1024,Xh=[{name:`model`,description:`Choose the model for the next turn`,argumentPicker:`models`},{name:`reasoning`,description:`Choose reasoning effort for the next turn`,argumentPicker:`reasoning`}];function Zh(e){let t=e.match(/^\/([^\s]*)$/);return t?t[1].toLowerCase():null}function Qh(e){let t=Zh(e);return t===null?[]:Xh.filter(e=>e.name.startsWith(t))}function $h(e){let t=e.match(/^\/([^\s]+)\s*$/)?.[1]?.toLowerCase();return Xh.find(e=>e.name===t)?.argumentPicker}function eg(e){return[...e].sort((e,t)=>tg(t,e)||t.localeCompare(e))}function tg(e,t){let n=e.match(/\d+(?:\.\d+)*/)?.[0].split(`.`).map(Number)??[],r=t.match(/\d+(?:\.\d+)*/)?.[0].split(`.`).map(Number)??[];for(let e=0;e<Math.max(n.length,r.length);e+=1){let t=(n[e]??0)-(r[e]??0);if(t)return t}return 0}var ng=K(` <span class="block-cursor svelte-1264sfg" aria-hidden="true"></span>`,1),rg=K(`<input type="file" multiple="" hidden="" aria-label="Choose files to upload" class="svelte-1264sfg"/> <p class="upload-hint svelte-1264sfg" aria-live="polite" aria-atomic="true"><!></p> <p class="upload-hint svelte-1264sfg">Org files go to .gestalt/; other files go to the workspace root.</p>`,1),ig=K(`<p id="writer-hint" class="writer-hint svelte-1264sfg"> </p>`),ag=K(`<button type="button" class="svelte-1264sfg">Retry send</button>`),og=K(`<div class="writer-feedback svelte-1264sfg" role="alert" aria-atomic="true"><p class="svelte-1264sfg"> </p> <!></div>`),sg=K(`<li><button type="button" class="svelte-1264sfg"><code class="svelte-1264sfg"> </code> <small class="svelte-1264sfg"> </small></button></li>`),cg=K(`<ul id="chat-command-completion" class="command-menu svelte-1264sfg" aria-label="Chat commands"></ul>`),lg=K(`<li class="svelte-1264sfg"><button type="button" class="svelte-1264sfg"><code class="svelte-1264sfg"> </code></button></li>`),ug=K(`<ul class="command-menu svelte-1264sfg" aria-label="Available models"></ul>`),dg=K(`<ul class="command-menu svelte-1264sfg" aria-label="Reasoning efforts"></ul>`),fg=K(`<button type="button" class="svelte-1264sfg">Upload files</button>`),pg=K(`<button type="button" class="svelte-1264sfg">Queue message</button> <button type="button" class="svelte-1264sfg">Interrupt and send</button>`,1),mg=K(`<button type="button" class="svelte-1264sfg">Interrupt</button>`),hg=K(`<div id="prompt-action-panel" class="action-panel svelte-1264sfg" aria-label="Prompt actions"><!> <!></div>`),gg=K(`<div class="prompt-action svelte-1264sfg"><button type="button" aria-label="Choose prompt action" aria-controls="prompt-action-panel" class="svelte-1264sfg"><svg aria-hidden="true" viewBox="0 0 24 24" class="svelte-1264sfg"><circle cx="6" cy="12" r="1.5" class="svelte-1264sfg"></circle><circle cx="12" cy="12" r="1.5" class="svelte-1264sfg"></circle><circle cx="18" cy="12" r="1.5" class="svelte-1264sfg"></circle></svg></button> <!></div>`),_g=K(`<button type="button" aria-label="Upload files" title="Upload files" class="svelte-1264sfg"><svg aria-hidden="true" viewBox="0 0 24 24" class="svelte-1264sfg"><path d="M12 16V4m-4 4 4-4 4 4M4 16v4h16v-4" class="svelte-1264sfg"></path></svg></button>`),vg=K(`<button type="button" class="svelte-1264sfg"><svg aria-hidden="true" viewBox="0 0 24 24" class="svelte-1264sfg"><path d="M9 10 5 14l4 4M5 14h8a6 6 0 0 0 6-6V6" class="svelte-1264sfg"></path></svg></button>`),yg=K(`<form><p role="status" aria-live="polite" aria-atomic="true" class="svelte-1264sfg"><!></p> <!> <!> <!> <!> <!> <!> <div class="prompt-row svelte-1264sfg"><textarea id="message" aria-label="Prompt" placeholder="Prompt" rows="1" required=""></textarea> <!></div></form>`);function bg(e,t){F(t,!0);let n=Q(t,`readySince`,3,null),r=Q(t,`newEmpty`,3,!1),i=Q(t,`detached`,3,!1),a=Q(t,`retryMessage`,3,null),o=Q(t,`retryable`,3,!1),s=Q(t,`models`,19,()=>[]),c=Q(t,`provider`,3,`codex`),l=Q(t,`onrevealprompt`,3,()=>{}),u=Q(t,`onmodelselect`,3,()=>{}),d=Q(t,`onqueue`,3,()=>{}),f=Q(t,`oninterruptsend`,3,()=>{}),p=Q(t,`onretry`,3,()=>{}),m=R(cn(Date.now())),h=R(!1),g=R(0),_=R(null);function v(){W(h)||!t.onuploadfiles||(z(ee,!1),W(_)?.click())}function y(e){let t=e.currentTarget,n=Array.from(t.files??[]);t.value=``,b(n)}async function b(e){if(!(W(h)||!t.onuploadfiles||e.length===0)){z(h,!0);try{await t.onuploadfiles(e)}finally{z(h,!1)}}}function x(e){return!!(t.onuploadfiles&&e.dataTransfer?.types.includes(`Files`))}function S(e){x(e)&&(e.preventDefault(),W(h)||z(g,W(g)+1))}function C(e){x(e)&&(e.preventDefault(),e.dataTransfer.dropEffect=W(h)?`none`:`copy`)}function w(e){x(e)&&z(g,Math.max(0,W(g)-1),!0)}async function T(e){x(e)&&(e.preventDefault(),z(g,0),await b(Array.from(e.dataTransfer.files)))}let E=I(()=>{if(n()==null)return`Ready`;let e=Math.floor(Math.max(0,W(m)-n())/6e4);if(e===0)return`Ready since less than a minute ago`;let t=Math.floor(e/1440),r=Math.floor(e%1440/60),i=e%60,a=[];return t&&a.push(`${t} ${t===1?`day`:`days`}`),r&&a.push(`${r} ${r===1?`hour`:`hours`}`),i&&a.push(`${i} ${i===1?`minute`:`minutes`}`),`Ready since ${a.join(` `)} ago`});Yi(()=>{let e=setInterval(()=>{z(m,Date.now(),!0)},3e4);return()=>clearInterval(e)});let D=R(0),O=R(null),ee=R(!1),te=I(()=>Qh(t.message)),ne=I(()=>Zh(t.message)),re=I(()=>W(ne)!==null&&W(ne)!==W(O)&&W(te).length>0),ie=I(()=>$h(t.message)),ae=I(()=>W(ie)===`models`),oe=I(()=>eg(s())),se=I(()=>W(ie)===`reasoning`),ce=I(()=>!t.activeTurnId&&!t.starting&&!W(h)&&!!t.message.trim()),le=I(()=>!!t.message.trim()),ue=I(()=>o()&&!a());function de(e){t.starting||W(h)||(z(ee,!1),e===`queue`?d()():e===`interrupt`?t.oninterrupt():f()())}function fe(e,n=!1){z(O,null),z(D,0),t.onchange(e),n&&l()()}function k(e=W(D)){let t=W(te)[e];t&&fe(`/${t.name} `,!0)}function pe(e){if(e.key===`Enter`&&e.ctrlKey&&!e.isComposing){if(t.activeTurnId&&!t.starting&&W(le)){e.preventDefault(),de(`queue`);return}if(W(ce)){e.preventDefault(),t.onsend();return}}if(W(re)){if(e.key===`ArrowDown`){e.preventDefault(),z(D,(W(D)+1)%W(te).length);return}if(e.key===`ArrowUp`){e.preventDefault(),z(D,(W(D)-1+W(te).length)%W(te).length);return}if(e.key===`Escape`){e.preventDefault(),z(O,W(ne),!0);return}if(e.key===`Tab`){e.preventDefault(),k();return}}}var me=yg();let he;var ge=B(me),_e=B(ge),ve=e=>{var t=ng(),n=V(t);P(),U(()=>J(n,`${W(E)??``} `)),q(e,t)},ye=e=>{var n=Jr();U(()=>J(n,t.status)),q(e,n)};Y(_e,e=>{t.status===`Ready.`?e(ve):e(ye,-1)}),N(ge);var be=H(ge,2),xe=e=>{var t=rg(),n=V(t);qi(n,e=>z(_,e),()=>W(_));var r=H(n,2),i=B(r),a=e=>{q(e,Jr(`Uploading files…`))},o=e=>{var t=Jr();U(()=>J(t,`Drop files to upload · ${Yh/1024/1024} MiB per file`)),q(e,t)},s=e=>{var t=Jr();U(()=>J(t,`Upload or drop files · ${Yh/1024/1024} MiB per file`)),q(e,t)};Y(i,e=>{W(h)?e(a):W(g)>0?e(o,1):e(s,-1)}),N(r),P(2),U(()=>n.disabled=W(h)),G(`change`,n,y),q(e,t)};Y(be,e=>{t.onuploadfiles&&e(xe)});var A=H(be,2),Se=e=>{var t=ig(),n=B(t);N(t),U(()=>J(n,`You can read this conversation. Sending will connect to ${c()===`kimi`?`Kimi`:`Codex`}.`)),q(e,t)};Y(A,e=>{i()&&e(Se)});var Ce=H(A,2),we=e=>{var n=og(),r=B(n),i=B(r,!0);N(r);var s=H(r,2),c=e=>{var n=ag();U(()=>n.disabled=t.starting||W(h)),G(`click`,n,function(...e){p()?.apply(this,e)}),q(e,n)};Y(s,e=>{o()&&e(c)}),N(n),U(()=>J(i,a())),q(e,n)};Y(Ce,e=>{a()&&e(we)});var Te=H(Ce,2),Ee=e=>{var t=cg();X(t,23,()=>W(te),e=>e.name,(e,t,n)=>{var r=sg(),i=B(r),a=B(i),o=B(a);N(a);var s=H(a,2),c=B(s,!0);N(s),N(i),N(r),U(()=>{Ei(r,1,bi(W(n)===W(D)?`command-selected`:void 0),`svelte-1264sfg`),J(o,`/${W(t).name??``}`),J(c,W(t).description)}),G(`click`,i,()=>k(W(n))),q(e,r)}),N(t),q(e,t)};Y(Te,e=>{W(re)&&e(Ee)});var De=H(Te,2),Oe=e=>{var t=ug();X(t,20,()=>W(oe),e=>e,(e,t)=>{var n=lg(),r=B(n),i=B(r),a=B(i,!0);N(i),N(r),N(n),U(()=>J(a,t)),G(`click`,r,()=>{u()(t),l()()}),q(e,n)}),N(t),q(e,t)};Y(De,e=>{W(ae)&&e(Oe)});var ke=H(De,2),Ae=e=>{var t=dg();X(t,20,()=>[`low`,`medium`,`high`],e=>e,(e,t)=>{var n=lg(),r=B(n),i=B(r),a=B(i,!0);N(i),N(r),N(n),U(()=>J(a,t)),G(`click`,r,()=>fe(`/reasoning ${t} `,!0)),q(e,n)}),N(t),q(e,t)};Y(ke,e=>{W(se)&&e(Ae)});var je=H(ke,2),Me=B(je);wn(Me);let Ne;var Pe=H(Me,2),Fe=e=>{var n=gg(),r=B(n),i=H(r,2),a=e=>{var n=hg(),r=B(n),i=e=>{var t=fg();U(()=>t.disabled=W(h)),G(`click`,t,v),q(e,t)};Y(r,e=>{t.onuploadfiles&&e(i)});var a=H(r,2),o=e=>{var n=pg(),r=V(n),i=H(r,2);U(()=>{r.disabled=t.starting||W(h),i.disabled=t.starting||W(h)}),G(`click`,r,()=>de(`queue`)),G(`click`,i,()=>de(`interrupt-send`)),q(e,n)},s=e=>{var n=mg();U(()=>n.disabled=t.starting||W(h)),G(`click`,n,()=>de(`interrupt`)),q(e,n)};Y(a,e=>{W(le)?e(o):e(s,-1)}),N(n),q(e,n)};Y(i,e=>{W(ee)&&e(a)}),N(n),U(()=>{r.disabled=t.starting||W(h),Z(r,`aria-expanded`,W(ee))}),G(`click`,r,()=>z(ee,!W(ee))),q(e,n)},Ie=e=>{var t=_g();U(()=>t.disabled=W(h)),G(`click`,t,v),q(e,t)},Le=e=>{var n=vg();U(()=>{Z(n,`aria-label`,W(ue)?`Retry send`:`Send prompt`),n.disabled=!W(ce)}),G(`click`,n,function(...e){(W(ue)?p():t.onsend)?.apply(this,e)}),q(e,n)};Y(Pe,e=>{t.activeTurnId?e(Fe):!W(le)&&t.onuploadfiles?e(Ie,1):e(Le,-1)}),N(je),N(me),U(()=>{Z(me,`aria-busy`,t.starting||W(h)),he=Ei(me,1,`svelte-1264sfg`,null,he,{"drag-over":W(g)>0}),Z(ge,`aria-label`,t.status===`Ready.`&&n()!=null?W(E):t.status),Ri(Me,t.message),Z(Me,`aria-describedby`,i()?`writer-hint`:void 0),Ne=Ei(Me,1,`svelte-1264sfg`,null,Ne,{"new-empty":r()})}),Br(`dragenter`,me,S),Br(`dragover`,me,C),Br(`dragleave`,me,w),Br(`drop`,me,T),G(`input`,Me,e=>fe(e.currentTarget.value)),G(`keydown`,Me,pe),q(e,me),et()}Vr([`change`,`click`,`input`,`keydown`]);function xg(e){return[...e].map(e=>({file:e,status:e.size>104857600?`too-large`:`queued`}))}function Sg(e){return e.findIndex(e=>e.status===`queued`)}function Cg(e){let t=[],n=/```[^\n]*\n([\s\S]*?)```/g,r=0;for(let i of e.matchAll(n)){let n=e.slice(r,i.index);n&&t.push(...wg(n)),t.push({kind:`code`,text:i[1]??``}),r=(i.index??0)+i[0].length}let i=e.slice(r);return(i||!t.length)&&t.push(...wg(i)),t}function wg(e){let t=[],n=e.split(`
72
72
  `),r=0,i=e=>{let i=n.slice(r,e).join(`
73
73
  `);i&&t.push({kind:`text`,parts:Og(i)})};for(let e=0;e<n.length;e+=1){let a=Tg(n[e]??``);if(a){i(e),t.push({kind:`heading`,level:a.level,parts:Og(a.text)}),r=e+1;continue}if(e===n.length-1)continue;let o=Eg(n[e]??``),s=Eg(n[e+1]??``);if(!o||!s||o.length!==s.length||!s.every(Dg))continue;i(e),e+=2;let c=[];for(;e<n.length;){let t=Eg(n[e]??``);if(!t||t.length!==o.length)break;c.push(t),e+=1}t.push({kind:`table`,headers:o.map(Og),rows:c.map(e=>e.map(Og))}),r=e,--e}return i(n.length),t.length?t:[{kind:`text`,parts:Og(e)}]}function Tg(e){let t=/^ {0,3}(#{1,6})[ \t]+(.+?)[ \t]*#*[ \t]*$/.exec(e);return t?{level:t[1].length,text:t[2]??``}:null}function Eg(e){let t=e.trim();if(!t.includes(`|`))return null;let n=t.replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim());return n.length>1&&n.every(Boolean)?n:null}function Dg(e){return/^:?-{3,}:?$/.test(e)}function Og(e){let t=[],n=/\[([^\]]+)\]\((https?:\/\/[^\s)]+|codex:\/\/[^\s)]+|file:\/\/[^\s)]+|\/[^\s)]+|\.{1,2}\/[^\s)]+|[^\s:()]+\.[a-zA-Z\d]+(?::\d+(?::\d+)?)?(?:#L\d+(?:C\d+)?)?|<(?:https?:\/\/|codex:\/\/|file:\/\/|\/|\.{1,2}\/)[^>\n]+>)\)|`([^`]+)`|\*\*([^*\n]+)\*\*/g,r=0;for(let i of e.matchAll(n)){let n=e.slice(r,i.index);n&&t.push({kind:`text`,text:n}),t.push(i[3]?{kind:`code`,text:i[3]}:i[4]?{kind:`strong`,parts:Og(i[4])}:{kind:`link`,text:i[1]??``,href:(i[2]??``).replace(/^<|>$/g,``)}),r=(i.index??0)+i[0].length}let i=e.slice(r);return i&&t.push({kind:`text`,text:i}),t}function kg(e){let t=/(?::(\d+)(?::\d+)?|#L(\d+)(?:C\d+)?)$/.exec(e);if(!t)return{path:e};let n=Number(t[1]??t[2]);return{path:e.slice(0,t.index),...Number.isSafeInteger(n)&&n>0?{line:n}:{}}}function Ag(e,t=!0){let n;try{n=t?decodeURIComponent(e):e}catch{return null}if(n.startsWith(`file://`))try{let e=new URL(n);if(e.hostname&&e.hostname!==`localhost`)return null;n=decodeURIComponent(e.pathname+e.hash)}catch{return null}let r=kg(n);return n=r.path,/^[a-z][a-z\d+.-]*:/i.test(n)||n.startsWith(`//`)||/[\u0000-\u001f\\]/.test(n)||!n||n.startsWith(`#`)||n.includes(`?`)||n.includes(`#`)||!n.startsWith(`/`)&&!n.startsWith(`./`)&&!n.startsWith(`../`)&&!/\.[a-z\d]+$/i.test(n)?null:r}function jg(e,t=!0){return Ag(e,t)?.path??null}var Mg=/^(.*\.org)(?::\d+(?::\d+)?)?(?:#L\d+(?:C\d+)?)?$/;function Ng(e){try{return decodeURIComponent(e)}catch{return null}}function Pg(e){if(!e.startsWith(`/`)||e.includes(`\0`))return null;let t=[];for(let n of e.split(`/`))if(!(!n||n===`.`)){if(n===`..`){if(t.length===0)return null;t.pop();continue}t.push(n)}return t}function Fg(e,t){let n=Ng(e),r=Ng(t),i=n?Mg.exec(n):null;if(!i||!r)return null;let a=Pg(i[1]??``),o=Pg(r);if(!a||!o||a.length<=o.length||o.some((e,t)=>a[t]!==e))return null;let s=a.slice(o.length).join(`/`);return s.endsWith(`.org`)&&s!==`.org`?s:null}function Ig(e){let t=Ng(e);if(!t)return!1;let n=Mg.exec(t);return!!(n&&Pg(n[1]??``))}async function Lg(e,t=globalThis.navigator?.clipboard,n=zg){if(!t)return Rg(e,n);try{return await t.writeText(e),!0}catch{return Rg(e,n)}}function Rg(e,t){try{return t(e)}catch{return!1}}function zg(e){if(typeof document>`u`||!document.body)return!1;let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.cssText=`position:fixed;opacity:0`,document.body.append(t),t.select();let n=document.execCommand(`copy`);return t.remove(),n}var Bg=K(`<a class="svelte-1p5tlta"> </a>`),Vg=K(`<a target="_blank" rel="noreferrer" class="svelte-1p5tlta"> </a>`),Hg=K(`<code class="svelte-1p5tlta"> </code>`),Ug=K(`<strong class="svelte-1p5tlta"><!></strong>`),Wg=K(`<div class="code-block svelte-1p5tlta"><button class="code-copy svelte-1p5tlta" type="button" title="Copy code"><svg aria-hidden="true" viewBox="0 0 24 24" class="svelte-1p5tlta"><rect x="9" y="9" width="10" height="10" rx="2"></rect><path d="M15 9V7a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2"></path></svg></button> <pre class="svelte-1p5tlta"><code class="svelte-1p5tlta"> </code></pre></div>`),Gg=K(`<th scope="col" class="svelte-1p5tlta"><!></th>`),Kg=K(`<td class="svelte-1p5tlta"><!></td>`),qg=K(`<tr></tr>`),Jg=K(`<div class="table-scroll svelte-1p5tlta"><table class="svelte-1p5tlta"><thead><tr></tr></thead><tbody></tbody></table></div>`),Yg=K(`<h1 class="svelte-1p5tlta"><!></h1>`),Xg=K(`<h2 class="svelte-1p5tlta"><!></h2>`),Zg=K(`<h3 class="svelte-1p5tlta"><!></h3>`),Qg=K(`<h4 class="svelte-1p5tlta"><!></h4>`),$g=K(`<h5 class="svelte-1p5tlta"><!></h5>`),e_=K(`<h6 class="svelte-1p5tlta"><!></h6>`),t_=K(`<div class="svelte-1p5tlta"><!></div>`),n_=K(`<div class="message-content svelte-1p5tlta"></div>`);function r_(e,t){F(t,!0);let n=(e,r=b)=>{var i=Yr();X(V(i),17,r,ii,(e,r)=>{var i=Yr(),o=V(i),s=e=>{var n=Yr(),i=V(n),o=e=>{var t=Bg(),n=B(t,!0);N(t),U(()=>{Z(t,`href`,W(r).href),J(n,W(r).text)}),G(`click`,t,e=>a(e,W(r).href)),q(e,t)},s=I(()=>t.onopenorg&&Ig(W(r).href)),c=e=>{var n=Bg(),i=B(n,!0);N(n),U(()=>{Z(n,`href`,W(r).href),J(i,W(r).text)}),G(`click`,n,e=>{e.preventDefault();let n=Ag(W(r).href);n.line?t.onopenfile?.(n.path,n.line):t.onopenfile?.(n.path)}),q(e,n)},l=I(()=>t.onopenfile&&jg(W(r).href)),u=e=>{var t=Vg(),n=B(t,!0);N(t),U(()=>{Z(t,`href`,W(r).href),J(n,W(r).text)}),q(e,t)};Y(i,e=>{W(s)?e(o):W(l)?e(c,1):e(u,-1)}),q(e,n)},c=e=>{var t=Hg(),n=B(t,!0);N(t),U(()=>J(n,W(r).text)),q(e,t)},l=e=>{var t=Ug(),i=B(t);n(i,()=>W(r).parts),N(t),q(e,t)},u=e=>{var t=Jr();U(()=>J(t,W(r).text)),q(e,t)};Y(o,e=>{W(r).kind===`link`?e(s):W(r).kind===`code`?e(c,1):W(r).kind===`strong`?e(l,2):e(u,-1)}),q(e,i)}),q(e,i)},r=Q(t,`oncopyresult`,3,()=>{}),i=Q(t,`clipboard`,19,()=>globalThis.navigator?.clipboard);function a(e,n){!t.onopenorg||!Ig(n)||(e.preventDefault(),t.onopenorg(n))}function o(e){return`Copy code block: ${(e.trim().split(`
74
- `)[0]?.trim()||`empty block`).slice(0,48)}`}async function s(e){r()(await Lg(e,i()))}var c=n_();X(c,21,()=>Cg(t.text),ii,(e,t)=>{var r=Yr(),i=V(r),a=e=>{var n=Wg(),r=B(n),i=H(r,2),a=B(i),c=B(a,!0);N(a),N(i),N(n),U(e=>{Z(r,`aria-label`,e),J(c,W(t).text)},[()=>o(W(t).text)]),G(`click`,r,()=>void s(W(t).text)),q(e,n)},c=e=>{var r=Jg(),i=B(r),a=B(i),o=B(a);X(o,21,()=>W(t).headers,ii,(e,t)=>{var r=Gg(),i=B(r);n(i,()=>W(t)),N(r),q(e,r)}),N(o),N(a);var s=H(a);X(s,21,()=>W(t).rows,ii,(e,t)=>{var r=qg();X(r,21,()=>W(t),ii,(e,t)=>{var r=Kg(),i=B(r);n(i,()=>W(t)),N(r),q(e,r)}),N(r),q(e,r)}),N(s),N(i),N(r),q(e,r)},l=e=>{var r=Yr(),i=V(r),a=e=>{var r=Yg(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)},o=e=>{var r=Xg(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)},s=e=>{var r=Zg(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)},c=e=>{var r=Qg(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)},l=e=>{var r=$g(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)},u=e=>{var r=e_(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)};Y(i,e=>{W(t).level===1?e(a):W(t).level===2?e(o,1):W(t).level===3?e(s,2):W(t).level===4?e(c,3):W(t).level===5?e(l,4):e(u,-1)}),q(e,r)},u=e=>{var r=t_(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)};Y(i,e=>{W(t).kind===`code`?e(a):W(t).kind===`table`?e(c,1):W(t).kind===`heading`?e(l,2):e(u,-1)}),q(e,r)}),N(c),q(e,c),et()}Vr([`click`]);var i_=K(`<time> </time>`),a_=K(`<div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">Supervisor explanation</dt> <dd class="supervisor-report svelte-1hnxk0w"><!></dd></div>`),o_=K(`<div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">Supervisor explanation</dt> <dd class="svelte-1hnxk0w"> </dd></div>`),s_=K(`<button type="button" class="svelte-1hnxk0w"> </button>`),c_=K(`<label>Optional guidance for the resumed work</label> <textarea maxlength="600" class="svelte-1hnxk0w"></textarea> <p class="guidance-help svelte-1hnxk0w"> </p> <div class="actions svelte-1hnxk0w"><button type="button" class="svelte-1hnxk0w"> </button> <button type="button" class="svelte-1hnxk0w">Disable Autopilot</button> <!></div>`,1),l_=K(`<p>This request is no longer pending.</p>`),u_=K(`<section tabindex="-1" class="attention svelte-1hnxk0w"><h3 class="svelte-1hnxk0w"> </h3> <!> <dl class="svelte-1hnxk0w"><div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">Reason</dt> <dd class="svelte-1hnxk0w"> </dd></div> <div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">What happened</dt> <dd class="svelte-1hnxk0w"><!></dd></div> <!> <div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">Requested action</dt> <dd class="svelte-1hnxk0w"><!></dd></div> <div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">Resume when</dt> <dd class="svelte-1hnxk0w"> </dd></div></dl> <!></section>`);function d_(e,t){F(t,!0);let n=Q(t,`controlId`,3,`autopilot-attention`),r=Q(t,`pending`,3,!1),i=Q(t,`historical`,3,!1),a=Q(t,`onresolve`,3,()=>{}),o=Q(t,`debugPending`,3,!1),s=R(``),c={planChange:`Plan change needs approval`,hardBlock:`Work is blocked`,missingDependency:`A required capability is missing`,permissionRequired:`Permission is needed`,externalState:`An external condition changed`,materialAmbiguity:`A decision is needed`},l={userGuidance:`You have provided the decision or guidance below.`,planRevision:`You have approved or revised the plan.`,dependencyInstalled:`The required capability is available.`,permissionGranted:`The required permission has been granted.`,externalStateChanged:`The blocker has been resolved, or you have provided a way forward below.`},u=I(()=>t.attention?.attention.summary.startsWith(`Supervised execution requires human attention (`)),d=I(()=>W(s).trim().length>600?`Guidance must be 600 characters or fewer.`:``);var f=Yr(),p=V(f),m=e=>{var f=u_(),p=B(f),m=B(p,!0);N(p);var h=H(p,2),g=e=>{var n=i_(),r=B(n);N(n),U((e,t)=>{Z(n,`datetime`,e),J(r,`Resolved ${t??``}`)},[()=>new Date(t.resolvedAt).toISOString(),()=>new Date(t.resolvedAt).toLocaleString()]),q(e,n)},_=e=>{var n=i_(),r=B(n,!0);N(n),U(e=>{Z(n,`datetime`,t.attention.requestedAt),J(r,e)},[()=>new Date(t.attention.requestedAt).toLocaleString()]),q(e,n)};Y(h,e=>{i()&&t.resolvedAt!==void 0?e(g):t.attention.requestedAt&&e(_,1)});var v=H(h,2),y=B(v),b=H(B(y),2),x=B(b,!0);N(b),N(y);var S=H(y,2),C=H(B(S),2),w=B(C);{let e=I(()=>W(u)?`The supervisor has paused work and needs your help to continue.`:t.attention.attention.summary);r_(w,{get text(){return W(e)},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}})}N(C),N(S);var T=H(S,2),E=e=>{var n=a_(),r=H(B(n),2);r_(B(r),{get text(){return t.attention.supervisorReport},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}}),N(r),N(n),q(e,n)},D=e=>{var t=o_(),n=H(B(t),2),r=B(n,!0);N(n),N(t),U(()=>J(r,i()?`No supervisor explanation was retained for this request.`:`The supervisor has not supplied an explanation yet. You can ask for details in the guidance below.`)),q(e,t)};Y(T,e=>{t.attention.supervisorReport?e(E):W(u)&&e(D,1)});var O=H(T,2),ee=H(B(O),2),te=B(ee);{let e=I(()=>W(u)?`Resolve the blocker or describe a way forward below, then choose Resume. You can also disable Autopilot.`:t.attention.attention.requestedAction);r_(te,{get text(){return W(e)},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}})}N(ee),N(O);var ne=H(O,2),re=H(B(ne),2),ie=B(re,!0);N(re),N(ne),N(v);var ae=H(v,2),oe=e=>{var i=c_(),c=V(i),l=H(c,2);wn(l);var u=H(l,2),f=B(u,!0);N(u);var p=H(u,2),m=B(p),h=B(m,!0);N(m);var g=H(m,2),_=H(g,2),v=e=>{var n=s_(),i=B(n,!0);N(n),U(()=>{n.disabled=r()||o(),J(i,o()?`Preparing DEBUG…`:`DEBUG`)}),G(`click`,n,e=>t.ondebug?.(t.attention.requestId,e.currentTarget)),q(e,n)};Y(_,e=>{t.ondebug&&e(v)}),N(p),U((e,i)=>{Z(c,`for`,`${n()}-guidance`),Z(l,`id`,`${n()}-guidance`),Z(l,`aria-describedby`,`${n()}-guidance-help`),Z(l,`aria-invalid`,e),Z(u,`id`,`${n()}-guidance-help`),J(f,W(d)||`Up to 600 characters. Do not include secrets.`),m.disabled=i,J(h,r()?`Updating…`:t.attention.attention.executorReplacement?`Authorize replacement`:`Resume`),g.disabled=r()},[()=>!!W(d),()=>r()||!!W(d)]),Ui(l,()=>W(s),e=>z(s,e)),G(`click`,m,()=>W(s).trim()?a()(`resume`,W(s)):a()(`resume`)),G(`click`,g,()=>a()(`disableAutopilot`)),q(e,i)},se=e=>{q(e,l_())};Y(ae,e=>{i()?e(se,-1):e(oe)}),N(f),U(()=>{Z(f,`id`,n()),Z(f,`role`,i()?`region`:`alert`),Z(f,`aria-labelledby`,`${n()}-title`),Z(p,`id`,`${n()}-title`),J(m,i()?`Autopilot attention request`:`Autopilot needs your attention`),J(x,c[t.attention.attention.reason]??`Supervised work needs attention`),J(ie,l[t.attention.attention.resumeCondition]??`You are ready for the supervisor to continue.`)}),q(e,f)};Y(p,e=>{t.attention&&e(m)}),q(e,f),et()}Vr([`click`]);var f_=[`planChange`,`hardBlock`,`missingDependency`,`permissionRequired`,`externalState`,`materialAmbiguity`],p_=[`userGuidance`,`planRevision`,`dependencyInstalled`,`permissionGranted`,`externalStateChanged`],m_={planChange:`planRevision`,hardBlock:`externalStateChanged`,missingDependency:`dependencyInstalled`,permissionRequired:`permissionGranted`,externalState:`externalStateChanged`,materialAmbiguity:`userGuidance`};f_.map(e=>({properties:{reason:{const:e},resumeCondition:{const:m_[e]}},required:[`reason`,`resumeCondition`]}));function h_(e){if(!b_(e))return null;let t=Object.keys(e);if(t.length===2&&t.every(e=>e===`reason`||e===`resumeCondition`)&&__(e.reason)&&v_(e.resumeCondition)&&m_[e.reason]===e.resumeCondition)return{reason:e.reason,summary:`Supervised execution requires human attention (${e.reason}).`,requestedAction:`Satisfy the ${e.resumeCondition} resume condition, then resume or disable Autopilot.`,resumeCondition:e.resumeCondition};if(t.length!==4&&t.length!==5||t.some(e=>![`reason`,`summary`,`requestedAction`,`resumeCondition`,`executorReplacement`].includes(e)))return null;let n=g_(e.executorReplacement);return!__(e.reason)||!y_(e.summary,600)||!y_(e.requestedAction,600)||!v_(e.resumeCondition)||m_[e.reason]!==e.resumeCondition||e.executorReplacement!==void 0&&!n||n&&e.reason!==`permissionRequired`?null:{reason:e.reason,summary:e.summary,requestedAction:e.requestedAction,resumeCondition:e.resumeCondition,...n?{executorReplacement:n}:{}}}function g_(e){return!b_(e)||Object.keys(e).length!==1?null:typeof e.canonicalTaskName==`string`&&/^l[1-9][0-9]*$/.test(e.canonicalTaskName)?{canonicalTaskName:e.canonicalTaskName}:null}function __(e){return typeof e==`string`&&f_.includes(e)}function v_(e){return typeof e==`string`&&p_.includes(e)}function y_(e,t){return typeof e==`string`&&e.trim().length>0&&e.length<=t}function b_(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function x_(e){let t=new Map;for(let n of e){if(!n.label.toLowerCase().replaceAll(` `,``).startsWith(`filechange`))continue;let e=n.changes?.length?n.changes:n.detail.split(`
74
+ `)[0]?.trim()||`empty block`).slice(0,48)}`}async function s(e){r()(await Lg(e,i()))}var c=n_();X(c,21,()=>Cg(t.text),ii,(e,t)=>{var r=Yr(),i=V(r),a=e=>{var n=Wg(),r=B(n),i=H(r,2),a=B(i),c=B(a,!0);N(a),N(i),N(n),U(e=>{Z(r,`aria-label`,e),J(c,W(t).text)},[()=>o(W(t).text)]),G(`click`,r,()=>void s(W(t).text)),q(e,n)},c=e=>{var r=Jg(),i=B(r),a=B(i),o=B(a);X(o,21,()=>W(t).headers,ii,(e,t)=>{var r=Gg(),i=B(r);n(i,()=>W(t)),N(r),q(e,r)}),N(o),N(a);var s=H(a);X(s,21,()=>W(t).rows,ii,(e,t)=>{var r=qg();X(r,21,()=>W(t),ii,(e,t)=>{var r=Kg(),i=B(r);n(i,()=>W(t)),N(r),q(e,r)}),N(r),q(e,r)}),N(s),N(i),N(r),q(e,r)},l=e=>{var r=Yr(),i=V(r),a=e=>{var r=Yg(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)},o=e=>{var r=Xg(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)},s=e=>{var r=Zg(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)},c=e=>{var r=Qg(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)},l=e=>{var r=$g(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)},u=e=>{var r=e_(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)};Y(i,e=>{W(t).level===1?e(a):W(t).level===2?e(o,1):W(t).level===3?e(s,2):W(t).level===4?e(c,3):W(t).level===5?e(l,4):e(u,-1)}),q(e,r)},u=e=>{var r=t_(),i=B(r);n(i,()=>W(t).parts),N(r),q(e,r)};Y(i,e=>{W(t).kind===`code`?e(a):W(t).kind===`table`?e(c,1):W(t).kind===`heading`?e(l,2):e(u,-1)}),q(e,r)}),N(c),q(e,c),et()}Vr([`click`]);var i_=K(`<time> </time>`),a_=K(`<div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">Supervisor explanation</dt> <dd class="supervisor-report svelte-1hnxk0w"><!></dd></div>`),o_=K(`<div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">Supervisor explanation</dt> <dd class="svelte-1hnxk0w"> </dd></div>`),s_=K(`<button type="button" class="svelte-1hnxk0w"> </button>`),c_=K(`<label>Optional guidance for the resumed work</label> <textarea maxlength="600" class="svelte-1hnxk0w"></textarea> <p class="guidance-help svelte-1hnxk0w"> </p> <div class="actions svelte-1hnxk0w"><button type="button" class="svelte-1hnxk0w"> </button> <button type="button" class="svelte-1hnxk0w">Disable Autopilot</button> <!></div>`,1),l_=K(`<p>This request is no longer pending.</p>`),u_=K(`<section tabindex="-1" class="attention svelte-1hnxk0w"><h3 class="svelte-1hnxk0w"> </h3> <!> <dl class="svelte-1hnxk0w"><div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">Reason</dt> <dd class="svelte-1hnxk0w"> </dd></div> <div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">What happened</dt> <dd class="svelte-1hnxk0w"><!></dd></div> <!> <div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">Requested action</dt> <dd class="svelte-1hnxk0w"><!></dd></div> <div class="svelte-1hnxk0w"><dt class="svelte-1hnxk0w">Resume when</dt> <dd class="svelte-1hnxk0w"> </dd></div></dl> <!></section>`);function d_(e,t){F(t,!0);let n=Q(t,`controlId`,3,`autopilot-attention`),r=Q(t,`pending`,3,!1),i=Q(t,`historical`,3,!1),a=Q(t,`onresolve`,3,()=>{}),o=Q(t,`debugPending`,3,!1),s=R(``),c={planChange:`Plan change needs approval`,hardBlock:`Work is blocked`,missingDependency:`A required capability is missing`,permissionRequired:`Permission is needed`,externalState:`An external condition changed`,materialAmbiguity:`A decision is needed`},l={userGuidance:`You have provided the decision or guidance below.`,planRevision:`You have approved or revised the plan.`,dependencyInstalled:`The required capability is available.`,permissionGranted:`The required permission has been granted.`,externalStateChanged:`The blocker has been resolved, or you have provided a way forward below.`},u=I(()=>t.attention?.attention.summary.startsWith(`Supervised execution requires human attention (`)),d=I(()=>W(s).trim().length>600?`Guidance must be 600 characters or fewer.`:``);var f=Yr(),p=V(f),m=e=>{var f=u_(),p=B(f),m=B(p,!0);N(p);var h=H(p,2),g=e=>{var n=i_(),r=B(n);N(n),U((e,t)=>{Z(n,`datetime`,e),J(r,`Resolved ${t??``}`)},[()=>new Date(t.resolvedAt).toISOString(),()=>new Date(t.resolvedAt).toLocaleString()]),q(e,n)},_=e=>{var n=i_(),r=B(n,!0);N(n),U(e=>{Z(n,`datetime`,t.attention.requestedAt),J(r,e)},[()=>new Date(t.attention.requestedAt).toLocaleString()]),q(e,n)};Y(h,e=>{i()&&t.resolvedAt!==void 0?e(g):t.attention.requestedAt&&e(_,1)});var v=H(h,2),y=B(v),b=H(B(y),2),x=B(b,!0);N(b),N(y);var S=H(y,2),C=H(B(S),2),w=B(C);{let e=I(()=>W(u)?`The supervisor has paused work and needs your help to continue.`:t.attention.attention.summary);r_(w,{get text(){return W(e)},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}})}N(C),N(S);var T=H(S,2),E=e=>{var n=a_(),r=H(B(n),2);r_(B(r),{get text(){return t.attention.supervisorReport},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}}),N(r),N(n),q(e,n)},D=e=>{var t=o_(),n=H(B(t),2),r=B(n,!0);N(n),N(t),U(()=>J(r,i()?`No supervisor explanation was retained for this request.`:`The supervisor has not supplied an explanation yet. You can ask for details in the guidance below.`)),q(e,t)};Y(T,e=>{t.attention.supervisorReport?e(E):W(u)&&e(D,1)});var O=H(T,2),ee=H(B(O),2),te=B(ee);{let e=I(()=>W(u)?`Resolve the blocker or describe a way forward below, then choose Resume. You can also disable Autopilot.`:t.attention.attention.requestedAction);r_(te,{get text(){return W(e)},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}})}N(ee),N(O);var ne=H(O,2),re=H(B(ne),2),ie=B(re,!0);N(re),N(ne),N(v);var ae=H(v,2),oe=e=>{var i=c_(),c=V(i),l=H(c,2);wn(l);var u=H(l,2),f=B(u,!0);N(u);var p=H(u,2),m=B(p),h=B(m,!0);N(m);var g=H(m,2),_=H(g,2),v=e=>{var n=s_(),i=B(n,!0);N(n),U(()=>{n.disabled=r()||o(),J(i,o()?`Preparing DEBUG…`:`DEBUG`)}),G(`click`,n,e=>t.ondebug?.(t.attention.requestId,e.currentTarget)),q(e,n)};Y(_,e=>{t.ondebug&&e(v)}),N(p),U((e,i)=>{Z(c,`for`,`${n()}-guidance`),Z(l,`id`,`${n()}-guidance`),Z(l,`aria-describedby`,`${n()}-guidance-help`),Z(l,`aria-invalid`,e),Z(u,`id`,`${n()}-guidance-help`),J(f,W(d)||`Up to 600 characters. Do not include secrets.`),m.disabled=i,J(h,r()?`Updating…`:t.attention.attention.executorReplacement?`Authorize replacement`:`Resume`),g.disabled=r()},[()=>!!W(d),()=>r()||!!W(d)]),Ui(l,()=>W(s),e=>z(s,e)),G(`click`,m,()=>W(s).trim()?a()(`resume`,W(s)):a()(`resume`)),G(`click`,g,()=>a()(`disableAutopilot`)),q(e,i)},se=e=>{q(e,l_())};Y(ae,e=>{i()?e(se,-1):e(oe)}),N(f),U(()=>{Z(f,`id`,n()),Z(f,`role`,i()?`region`:`alert`),Z(f,`aria-labelledby`,`${n()}-title`),Z(p,`id`,`${n()}-title`),J(m,i()?`Autopilot attention request`:`Autopilot needs your attention`),J(x,c[t.attention.attention.reason]??`Supervised work needs attention`),J(ie,l[t.attention.attention.resumeCondition]??`You are ready for the supervisor to continue.`)}),q(e,f)};Y(p,e=>{t.attention&&e(m)}),q(e,f),et()}Vr([`click`]);var f_=[`planChange`,`hardBlock`,`missingDependency`,`permissionRequired`,`externalState`,`materialAmbiguity`],p_=[`userGuidance`,`planRevision`,`dependencyInstalled`,`permissionGranted`,`externalStateChanged`],m_={planChange:`planRevision`,hardBlock:`externalStateChanged`,missingDependency:`dependencyInstalled`,permissionRequired:`permissionGranted`,externalState:`externalStateChanged`,materialAmbiguity:`userGuidance`};function h_(e){if(!b_(e))return null;let t=Object.keys(e);if(t.length===2&&t.every(e=>e===`reason`||e===`resumeCondition`)&&__(e.reason)&&v_(e.resumeCondition)&&m_[e.reason]===e.resumeCondition)return{reason:e.reason,summary:`Supervised execution requires human attention (${e.reason}).`,requestedAction:`Satisfy the ${e.resumeCondition} resume condition, then resume or disable Autopilot.`,resumeCondition:e.resumeCondition};if(t.length!==4&&t.length!==5||t.some(e=>![`reason`,`summary`,`requestedAction`,`resumeCondition`,`executorReplacement`].includes(e)))return null;let n=g_(e.executorReplacement);return!__(e.reason)||!y_(e.summary,600)||!y_(e.requestedAction,600)||!v_(e.resumeCondition)||m_[e.reason]!==e.resumeCondition||e.executorReplacement!==void 0&&!n||n&&e.reason!==`permissionRequired`?null:{reason:e.reason,summary:e.summary,requestedAction:e.requestedAction,resumeCondition:e.resumeCondition,...n?{executorReplacement:n}:{}}}function g_(e){return!b_(e)||Object.keys(e).length!==1?null:typeof e.canonicalTaskName==`string`&&/^l[1-9][0-9]*$/.test(e.canonicalTaskName)?{canonicalTaskName:e.canonicalTaskName}:null}function __(e){return typeof e==`string`&&f_.includes(e)}function v_(e){return typeof e==`string`&&p_.includes(e)}function y_(e,t){return typeof e==`string`&&e.trim().length>0&&e.length<=t}function b_(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function x_(e){let t=new Map;for(let n of e){if(!n.label.toLowerCase().replaceAll(` `,``).startsWith(`filechange`))continue;let e=n.changes?.length?n.changes:n.detail.split(`
75
75
  `).filter(Boolean).map(e=>({path:e,additions:null,deletions:null}));for(let r of e){let e=t.get(r.path),i=typeof r.additions==`number`&&typeof r.deletions==`number`;t.set(r.path,{path:r.path,additions:i&&e?.additions!==null?(e?.additions??0)+r.additions:null,deletions:i&&e?.deletions!==null?(e?.deletions??0)+r.deletions:null,...n.occurredAt===void 0?e?.touchedAt===void 0?{}:{touchedAt:e.touchedAt}:{touchedAt:Math.max(e?.touchedAt??0,n.occurredAt)}})}}return[...t.values()]}function S_(e){return{files:e.length,additions:e.every(e=>e.additions!==null)?e.reduce((e,t)=>e+t.additions,0):null,deletions:e.every(e=>e.deletions!==null)?e.reduce((e,t)=>e+t.deletions,0):null}}function C_(e,t){if(e===void 0||t===void 0||!Number.isFinite(e)||!Number.isFinite(t))return null;let n=Math.floor(Math.max(0,t-e)/6e4);if(n<1)return`moments later`;if(n<60)return`${n} minute${n===1?``:`s`} later`;let r=Math.floor(n/60);if(r<24)return`${r} hour${r===1?``:`s`} later`;let i=Math.floor(r/24);return`${i} day${i===1?``:`s`} later`}function w_(e){return new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`}).format(e)}function T_(e,t){let n=Math.floor(Math.max(0,t-e)/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}var E_=K(`<dl class="command-counts svelte-11ye6aj"><div class="svelte-11ye6aj"><dt class="svelte-11ye6aj">Successful commands</dt> <dd class="svelte-11ye6aj"> </dd></div> <div class="svelte-11ye6aj"><dt class="svelte-11ye6aj">Failed commands</dt> <dd class="svelte-11ye6aj"> </dd></div></dl>`),D_=K(`<li data-status="failed" class="svelte-11ye6aj"><code class="svelte-11ye6aj"> </code></li>`),O_=K(`<section aria-label="Failed commands"><strong>Failed commands</strong> <ul class="activity-list svelte-11ye6aj"></ul></section>`),k_=K(`<span class="svelte-11ye6aj"> </span>`),A_=K(`<li class="svelte-11ye6aj"><small class="svelte-11ye6aj"> </small> <!></li>`),j_=K(`<ul class="activity-list svelte-11ye6aj" aria-label="Work activity"></ul>`),M_=K(`<time class="svelte-11ye6aj"> </time>`),N_=K(`<span class="svelte-11ye6aj">time unknown</span>`),P_=K(`<li class="svelte-11ye6aj"><code class="svelte-11ye6aj"> </code> <span class="file-counts svelte-11ye6aj" aria-label="Line changes"><span class="svelte-11ye6aj"> </span><span class="svelte-11ye6aj"> </span></span> <!></li>`),F_=K(`<section aria-label="Files changed"><strong>Files changed</strong> <ul class="file-list svelte-11ye6aj"></ul></section>`),I_=K(`<details class="work-details svelte-11ye6aj"><summary class="svelte-11ye6aj"> </summary> <div class="work-details-content svelte-11ye6aj"><!> <!> <!> <!></div></details>`);function L_(e,t){F(t,!0);let n=Q(t,`now`,19,()=>Date.now()),r=I(()=>Cm(t.activities)),i=I(()=>t.activities.flatMap(e=>{let t=wm(e);return t?.kind===`Command`&&t.status===`failed`?[{id:e.id,command:t.content}]:[]})),a=I(()=>x_(t.activities)),o=I(()=>S_(W(a))),s=I(()=>t.activities.flatMap(e=>{let t=wm(e);return t&&t.kind!==`Command`&&t.kind!==`File change`?[{id:e.id,...t}]:[]})),c=I(()=>t.activities.length),l=I(()=>W(a).length?`${W(o).files} ${W(o).files===1?`file`:`files`} changed · +${W(o).additions??`?`} −${W(o).deletions??`?`}`:`Work details · ${W(c)} ${W(c)===1?`activity`:`activities`}`);var u=Yr(),d=V(u),f=e=>{var t=I_(),o=B(t),c=B(o,!0);N(o);var u=H(o,2),d=B(u),f=e=>{var t=E_(),n=B(t),i=H(B(n),2),a=B(i,!0);N(i),N(n);var o=H(n,2),s=H(B(o),2),c=B(s,!0);N(s),N(o),N(t),U(()=>{J(a,W(r).successful),J(c,W(r).failed)}),q(e,t)};Y(d,e=>{(W(r).successful||W(r).failed)&&e(f)});var p=H(d,2),m=e=>{var t=O_(),n=H(B(t),2);X(n,21,()=>W(i),e=>e.id,(e,t)=>{var n=D_(),r=B(n),i=B(r,!0);N(r),N(n),U(()=>J(i,W(t).command)),q(e,n)}),N(n),N(t),q(e,t)};Y(p,e=>{W(i).length&&e(m)});var h=H(p,2),g=e=>{var t=j_();X(t,21,()=>W(s),e=>e.id,(e,t)=>{var n=A_(),r=B(n),i=B(r);N(r);var a=H(r,2),o=e=>{Pm(e,{get startup(){return W(t).startup}})},s=e=>{var n=k_(),r=B(n,!0);N(n),U(()=>J(r,W(t).content)),q(e,n)};Y(a,e=>{W(t).startup?e(o):e(s,-1)}),N(n),U(()=>{Z(n,`data-status`,W(t).status),J(i,`${W(t).kind??``}${W(t).status?` · ${W(t).status}`:``}`)}),q(e,n)}),N(t),q(e,t)};Y(h,e=>{W(s).length&&e(g)});var _=H(h,2),v=e=>{var t=F_(),r=H(B(t),2);X(r,21,()=>W(a),e=>e.path,(e,t)=>{var r=P_(),i=B(r),a=B(i,!0);N(i);var o=H(i,2),s=B(o),c=B(s);N(s);var l=H(s),u=B(l);N(l),N(o);var d=H(o,2),f=e=>{var r=M_(),i=B(r,!0);N(r),U((e,t)=>{Z(r,`datetime`,e),J(i,t)},[()=>new Date(W(t).touchedAt).toISOString(),()=>T_(W(t).touchedAt,n())]),q(e,r)},p=e=>{q(e,N_())};Y(d,e=>{W(t).touchedAt===void 0?e(p,-1):e(f)}),N(r),U(()=>{J(a,W(t).path),J(c,`+${W(t).additions??`?`??``}`),J(u,`-${W(t).deletions??`?`??``}`)}),q(e,r)}),N(r),N(t),q(e,t)};Y(_,e=>{W(a).length&&e(v)}),N(u),N(t),U(()=>J(c,W(l))),q(e,t)};Y(d,e=>{W(c)&&e(f)}),q(e,u),et()}function R_(e){if(!e||typeof e!=`object`)return null;let t=e.command;return typeof t==`string`&&t.trim()?t:null}function z_(e){if(!B_(e))return null;let t=e.changes;if(!Array.isArray(t))return null;let n=t.map(e=>B_(e)&&typeof e.path==`string`&&e.path.trim()?e.path:null).filter(e=>e!==null);return n.length===t.length&&n.length>0?n:null}function B_(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var V_=K(`<div class="choice svelte-77f3gb"><input type="radio" class="svelte-77f3gb"/> <label class="svelte-77f3gb"><strong> </strong></label> <div class="choice-description svelte-77f3gb"><!></div></div>`),H_=K(`<label class="custom svelte-77f3gb">Your custom answer <input required="" class="svelte-77f3gb"/></label>`),U_=K(`<div class="choice svelte-77f3gb"><input type="radio" class="svelte-77f3gb"/> <label class="svelte-77f3gb"><strong>Custom answer</strong><span class="svelte-77f3gb">Provide your own response.</span></label></div> <!>`,1),W_=K(`<fieldset class="svelte-77f3gb"><legend class="svelte-77f3gb"><strong> </strong></legend> <!> <div class="choices svelte-77f3gb"><!> <!></div></fieldset>`),G_=K(`<form class="quiz-form svelte-77f3gb"><fieldset class="questions svelte-77f3gb"></fieldset> <button type="submit">Send answers</button></form>`);function K_(e,t){F(t,!0);let n=Q(t,`disabled`,3,!1),r=cn({}),i=cn({}),a=I(()=>t.quiz.questions.every(e=>!!t.answers[e.id]?.trim()));async function o(e){i[e]=!0,t.onanswer(e,t.answers[e]??``),await Or(),r[e]?.focus()}var s=G_(),c=B(s);X(c,21,()=>t.quiz.questions,e=>e.id,(e,n)=>{let a=I(()=>`${t.requestId}-${W(n).id}-custom`),s=I(()=>W(n).choices.some(e=>e.label===t.answers[W(n).id]));var c=W_(),l=B(c),u=B(l),d=B(u,!0);N(u),N(l);var f=H(l,2);r_(f,{get text(){return W(n).question},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}});var p=H(f,2),m=B(p);X(m,17,()=>W(n).choices,e=>`${W(n).id}-${e.label}`,(e,r)=>{let a=I(()=>`${t.requestId}-${W(n).id}-${W(r).label}`);var o=V_(),s=B(o);Li(s);var c=H(s,2),l=B(c),u=B(l,!0);N(l),N(c);var d=H(c,2);r_(B(d),{get text(){return W(r).description},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}}),N(d),N(o),U(()=>{Z(s,`id`,W(a)),Z(s,`name`,`${t.requestId}-${W(n).id}`),Z(s,`aria-describedby`,`${W(a)}-description`),zi(s,t.answers[W(n).id]===W(r).label),Z(c,`for`,W(a)),J(u,W(r).label),Z(d,`id`,`${W(a)}-description`)}),G(`change`,s,()=>{i[W(n).id]=!1,t.onanswer(W(n).id,W(r).label)}),q(e,o)});var h=H(m,2),g=e=>{var c=U_(),l=V(c),u=B(l);Li(u);var d=H(u,2);N(l);var f=H(l,2),p=e=>{var i=H_(),o=H(B(i));Li(o),qi(o,(e,t)=>r[t.id]=e,e=>r?.[e.id],()=>[W(n)]),N(i),U(()=>{Z(i,`for`,`${W(a)}-text`),Z(o,`id`,`${W(a)}-text`),Z(o,`type`,W(n).isSecret?`password`:`text`),Ri(o,t.answers[W(n).id])}),G(`input`,o,e=>t.onanswer(W(n).id,e.currentTarget.value)),q(e,i)},m=I(()=>i[W(n).id]||!!t.answers[W(n).id]&&!W(s));Y(f,e=>{W(m)&&e(p)}),U(e=>{Z(u,`id`,W(a)),Z(u,`name`,`${t.requestId}-${W(n).id}`),zi(u,e),Z(d,`for`,W(a))},[()=>i[W(n).id]||!!t.answers[W(n).id]&&!W(s)]),G(`change`,u,()=>o(W(n).id)),G(`click`,u,()=>{i[W(n).id]&&o(W(n).id)}),q(e,c)};Y(h,e=>{W(n).allowCustom&&e(g)}),N(p),N(c),U(()=>J(d,W(n).header)),q(e,c)}),N(c);var l=H(c,2);N(s),U(()=>{c.disabled=n(),l.disabled=n()||!W(a)}),Br(`submit`,s,e=>{e.preventDefault(),W(a)&&t.onsubmit()}),q(e,s),et()}Vr([`change`,`click`,`input`]);function q_(e,t=2){if(!ev(e)||!Array.isArray(e.questions)||e.questions.length<1||e.questions.length>8)return null;let n=e.questions.map(e=>X_(e,t));if(n.some(e=>e===null))return null;let r=n;return new Set(r.map(e=>e.id)).size===r.length?{questions:r}:null}function J_(e){return!ev(e)||!Array.isArray(e.questions)||e.questions.length>3?null:q_({questions:e.questions.map(e=>ev(e)?{id:e.id,header:e.header,question:e.question,choices:e.options,allowCustom:e.isOther===!0,isSecret:e.isSecret===!0}:e)},1)}function Y_(e){return{contentItems:[{type:`inputText`,text:JSON.stringify({answers:Object.fromEntries(e.filter(e=>e.answer.trim()).map(e=>[e.id,e.answer]))})}],success:!0}}function X_(e,t){if(!ev(e)||!Array.isArray(e.choices)||e.choices.length<t||e.choices.length>5||!Q_(e.id)||!$_(e.header,120)||!$_(e.question,600)||typeof e.allowCustom!=`boolean`)return null;let n=e.choices.map(Z_);return n.some(e=>e===null)?null:{id:e.id,header:e.header,question:e.question,choices:n,allowCustom:e.allowCustom,isSecret:e.isSecret===!0}}function Z_(e){return!ev(e)||!$_(e.label,160)||!$_(e.description,600)?null:{label:e.label,description:e.description}}function Q_(e){return typeof e==`string`&&/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(e)}function $_(e,t){return typeof e==`string`&&e.trim().length>0&&e.length<=t}function ev(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var tv=K(`<time> </time>`),nv=K(`<!> <p class="interaction-result svelte-ajsqcq" data-interaction-state="resolved" tabindex="-1"> </p> <!>`,1),rv=K(`<p class="interaction-submitting svelte-ajsqcq" data-interaction-state="submitting">Submitting…</p>`),iv=K(`<p>Codex sent an invalid quiz request.</p>`),av=K(`<p>Grant the requested permissions for this turn only.</p> <button type="button">Approve</button>`,1),ov=K(`<pre class="command-approval-command svelte-ajsqcq"><code> </code></pre>`),sv=K(`<p class="command-approval-missing svelte-ajsqcq">Command details were not provided.</p>`),cv=K(`<p>Approve this command?</p> <!> <div class="approval-actions svelte-ajsqcq"><button type="button">Approve</button> <button type="button">Deny</button></div>`,1),lv=K(`<li><code> </code></li>`),uv=K(`<ul class="file-change-approval-targets svelte-ajsqcq" aria-label="Files to change"></ul>`),dv=K(`<p class="file-change-approval-missing svelte-ajsqcq">File details were not provided.</p>`),fv=K(`<p>Approve changes to these files?</p> <!> <div class="approval-actions svelte-ajsqcq"><button type="button">Approve</button> <button type="button">Deny</button></div>`,1),pv=K(`<button type="button">Approve</button><button type="button">Deny</button>`,1),mv=K(`<p class="interaction-failed svelte-ajsqcq" data-interaction-state="failed">Could not send. Try again.</p> <button type="button">Retry</button>`,1),hv=K(`<!> <!> <!>`,1),gv=K(`<li class="svelte-ajsqcq"><div class="submitted-question svelte-ajsqcq"><strong> </strong> <!></div> <div class="submitted-answer svelte-ajsqcq"><!></div></li>`),_v=K(`<section class="submitted-answers svelte-ajsqcq" aria-label="Submitted answers" aria-live="polite"><p class="svelte-ajsqcq"><strong>Submitted answers</strong></p> <ol class="svelte-ajsqcq"></ol> <p class="submitted-note svelte-ajsqcq">Recorded in this chat view before delivery.</p></section>`),vv=K(`<article tabindex="-1"><p class="interaction-kind svelte-ajsqcq"> </p> <!> <!></article>`);function yv(e,t){F(t,!0);let n=Q(t,`submittedAnswers`,19,()=>({})),r=Q(t,`onretry`,3,()=>{}),i=R(null),a=cn({}),o=e=>Object.fromEntries(Object.entries(t.answers).filter(([t])=>t.startsWith(`${e}:`)).map(([t,n])=>[t.slice(e.length+1),n]));function s(e,t){z(i,e.requestId,!0),t()}Pn(()=>{let e=t.interactions.find(e=>e.requestId===W(i));e?.state===`resolved`&&(Or().then(()=>a[e.requestId]?.focus()),z(i,null))});var c=Yr();X(V(c),17,()=>t.interactions,e=>e.key??e.requestId,(e,i)=>{let c=I(()=>W(i).state===`submitting`);var l=vv();let u;var d=B(l),f=B(d,!0);N(d);var p=H(d,2),m=e=>{var r=nv(),o=V(r),s=e=>{var t=tv(),n=B(t);N(t),U((e,r)=>{Z(t,`datetime`,e),J(n,`Resolved ${r??``}`)},[()=>new Date(W(i).resolvedAt).toISOString(),()=>new Date(W(i).resolvedAt).toLocaleString()]),q(e,t)};Y(o,e=>{W(i).resolvedAt!==void 0&&e(s)});var c=H(o,2),l=B(c,!0);N(c),qi(c,(e,t)=>a[t.requestId]=e,e=>a?.[e.requestId],()=>[W(i)]);var u=H(c,2),d=e=>{let n=I(()=>W(i).kind===`quiz`?q_(W(i).payload):W(i).kind===`userInput`?J_(W(i).payload):null);var r=Yr();X(V(r),17,()=>W(n)?.questions??[],e=>e.id,(e,n)=>{r_(e,{get text(){return W(n).question},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}})}),q(e,r)};Y(u,e=>{n()[W(i).requestId]?.length||e(d)}),U(()=>J(l,W(i).attemptedOutcome===`denied`?`Denied`:W(i).attemptedOutcome===`dismissed`?`No longer awaiting a response`:W(i).attemptedOutcome===`answered`?`Answers sent`:`Approved`)),q(e,r)},h=e=>{var a=hv(),l=V(a),u=e=>{q(e,rv())};Y(l,e=>{W(c)&&e(u)});var d=H(l,2),f=e=>{let r=I(()=>W(i).kind===`quiz`?q_(W(i).payload):J_(W(i).payload));var a=Yr(),l=V(a),u=e=>{},d=e=>{{let n=I(()=>o(W(i).requestId));K_(e,{get requestId(){return W(i).requestId},get quiz(){return W(r)},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult},get answers(){return W(n)},get disabled(){return W(c)},onanswer:(e,n)=>t.onanswer(W(i).requestId,e,n),onsubmit:()=>s(W(i),()=>t.onquiz(W(i)))})}},f=e=>{q(e,iv())};Y(l,e=>{W(c)&&n()[W(i).requestId]?.length?e(u):W(r)?e(d,1):e(f,-1)}),q(e,a)},p=e=>{var n=av(),r=H(V(n),2);U(()=>r.disabled=W(c)),G(`click`,r,()=>s(W(i),()=>t.onpermission(W(i)))),q(e,n)},m=e=>{let n=I(()=>R_(W(i).payload));var r=cv(),a=H(V(r),2),o=e=>{var t=ov(),r=B(t),i=B(r,!0);N(r),N(t),U(()=>J(i,W(n))),q(e,t)},l=e=>{q(e,sv())};Y(a,e=>{W(n)?e(o):e(l,-1)});var u=H(a,2),d=B(u),f=H(d,2);N(u),U(()=>{d.disabled=W(c),f.disabled=W(c)}),G(`click`,d,()=>s(W(i),()=>t.ondecision(W(i).requestId,`accept`))),G(`click`,f,()=>s(W(i),()=>t.ondecision(W(i).requestId,`decline`))),q(e,r)},h=e=>{let n=I(()=>z_(W(i).payload));var r=fv(),a=H(V(r),2),o=e=>{var t=uv();X(t,20,()=>W(n),e=>e,(e,t)=>{var n=lv(),r=B(n),i=B(r,!0);N(r),N(n),U(()=>J(i,t)),q(e,n)}),N(t),q(e,t)},l=e=>{q(e,dv())};Y(a,e=>{W(n)?e(o):e(l,-1)});var u=H(a,2),d=B(u),f=H(d,2);N(u),U(()=>{d.disabled=W(c),f.disabled=W(c)}),G(`click`,d,()=>s(W(i),()=>t.ondecision(W(i).requestId,`accept`))),G(`click`,f,()=>s(W(i),()=>t.ondecision(W(i).requestId,`decline`))),q(e,r)},g=e=>{var n=pv(),r=V(n),a=H(r);U(()=>{r.disabled=W(c),a.disabled=W(c)}),G(`click`,r,()=>s(W(i),()=>t.ondecision(W(i).requestId,`accept`))),G(`click`,a,()=>s(W(i),()=>t.ondecision(W(i).requestId,`decline`))),q(e,n)};Y(d,e=>{W(i).kind===`userInput`||W(i).kind===`quiz`?e(f):W(i).kind===`permissionsApproval`?e(p,1):W(i).kind===`commandApproval`?e(m,2):W(i).kind===`fileChangeApproval`?e(h,3):e(g,-1)});var _=H(d,2),v=e=>{var t=mv();G(`click`,H(V(t),2),()=>r()(W(i))),q(e,t)};Y(_,e=>{W(i).state===`failed`&&e(v)}),q(e,a)};Y(p,e=>{W(i).state===`resolved`?e(m):e(h,-1)});var g=H(p,2),_=e=>{var r=_v(),a=H(B(r),2);X(a,21,()=>n()[W(i).requestId],e=>e.id,(e,n)=>{var r=gv(),i=B(r),a=B(i),o=B(a,!0);N(a),r_(H(a,2),{get text(){return W(n).question},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}}),N(i);var s=H(i,2);r_(B(s),{get text(){return W(n).answer},get onopenorg(){return t.onopenorg},get onopenfile(){return t.onopenfile},get oncopyresult(){return t.oncopyresult}}),N(s),N(r),U(()=>J(o,W(n).header)),q(e,r)}),N(a),P(2),N(r),q(e,r)};Y(g,e=>{n()[W(i).requestId]?.length&&(W(c)||W(i).state===`resolved`)&&e(_)}),N(l),U(()=>{Z(l,`id`,`chat-request-${W(i).requestId}`),u=Ei(l,1,`svelte-ajsqcq`,null,u,{resolved:W(i).state===`resolved`}),J(f,W(i).kind)}),q(e,l)}),q(e,c),et()}Vr([`click`]);var bv=K(`<aside class="pending-requests pending-dialogues svelte-10cj0sh" aria-label="Pending chat requests"><!></aside>`);function xv(e,t){var n=bv();mi(B(n),()=>t.children),N(n),q(e,n)}function Sv(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return t.id===`gestalt-xerj-availability`||t.mcpStartup?.serverName===`gestalt-xerj`||typeof t.id==`string`&&t.id.startsWith(`mcp-startup:`)&&t.id.endsWith(`:gestalt-xerj`)}function Cv(e){return e.mcpStartup!==void 0||e.id.startsWith(`mcp-startup:`)||e.id===`gestalt-serena-availability`||e.id===`gestalt-xerj-availability`||e.id.startsWith(`gestalt-retrieval-`)}function wv(e){return Array.isArray(e)?e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;return typeof t.path==`string`&&Number.isInteger(t.additions)&&t.additions>=0&&Number.isInteger(t.deletions)&&t.deletions>=0?[{path:t.path,additions:t.additions,deletions:t.deletions}]:[]}):[]}function Tv(e){if(typeof e.id!=`string`)return null;let t={...typeof e.turnId==`string`?{turnId:e.turnId}:{},...typeof e.actorTurnId==`string`?{actorTurnId:e.actorTurnId}:{},...typeof e.occurredAt==`number`&&Number.isFinite(e.occurredAt)?{occurredAt:e.occurredAt}:{}};if(e.kind===`reasoning`&&Array.isArray(e.summary)){let n=e.summary.filter(e=>typeof e==`string`).join(`
76
76
  `);return n?{id:e.id,label:`Reasoning summary`,detail:n,...t}:null}if(e.kind===`plan`&&typeof e.text==`string`)return{id:e.id,label:`Plan`,detail:e.text,...t};if(e.kind===`command`&&typeof e.command==`string`)return{id:e.id,label:`Command · ${String(e.status??`unknown`)}`,detail:e.command,...t};if(e.kind===`fileChange`&&Array.isArray(e.paths)){let n=wv(e.changes);return{id:e.id,label:`File change · ${String(e.status??`unknown`)}`,detail:e.paths.join(`
77
77
  `),...n.length?{changes:n}:{},...t}}return e.kind===`tool`&&typeof e.name==`string`?{id:e.id,label:`Tool · ${String(e.status??`unknown`)}`,detail:e.name,...t}:null}function Ev(e){return[`Submitted quiz answers:`,...e.map(e=>`- ${e.header} — ${e.question}\n ${e.answer.trim().replaceAll(`
@@ -16,7 +16,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
16
16
  <link rel="icon" href="/icons/gestalt-mobile-192.png" />
17
17
  <link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
18
18
  <title>Gestalt Mobile</title>
19
- <script type="module" crossorigin src="/assets/index-ME1MRi_3.js"></script>
19
+ <script type="module" crossorigin src="/assets/index-C--Oj-7W.js"></script>
20
20
  <link rel="stylesheet" crossorigin href="/assets/index-CwgSPgbi.css">
21
21
  </head>
22
22
  <body>
@@ -2567,6 +2567,101 @@ describe('production composition', () => {
2567
2567
  expect(accepted.handles.flatMap((handle) => handle.calls)).not.toContain('turn/start');
2568
2568
  await accepted.app.close();
2569
2569
  });
2570
+ it('replaces a stopped executor in the current root on explicit user instruction and exposes one durable identity through health', async () => {
2571
+ let rootThreadId = 'thread-1';
2572
+ const fixture = await createProductionAutopilotFixture({
2573
+ activitySchedule: () => () => { },
2574
+ autopilotSchedule: () => () => { },
2575
+ autopilotActivity: (sessionId) => {
2576
+ const now = new Date().toISOString();
2577
+ return {
2578
+ sessionId,
2579
+ rootThreadId,
2580
+ confidence: 'fresh',
2581
+ aggregateSubagents: 'idle',
2582
+ root: { state: 'working', reason: 'turnActive', observedAt: now, lastActivityAt: now },
2583
+ subagents: [
2584
+ {
2585
+ id: 'child',
2586
+ threadId: 'child',
2587
+ taskPath: '/root/l1',
2588
+ canonicalTaskName: 'l1',
2589
+ canonicalPosition: 'L1',
2590
+ continuationGeneration: 1,
2591
+ state: 'idle',
2592
+ reason: 'turnCompleted',
2593
+ observedAt: now,
2594
+ lastActivityAt: now,
2595
+ ownedProcesses: [],
2596
+ },
2597
+ ],
2598
+ };
2599
+ },
2600
+ });
2601
+ onTestFinished(() => fixture.app.close());
2602
+ await fixture.app.inject({
2603
+ method: 'POST',
2604
+ url: `/api/sessions/${fixture.sessionId}/turns`,
2605
+ payload: { text: 'Replace the current executor.', clientUserMessageId: 'replace-test' },
2606
+ });
2607
+ const current = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json();
2608
+ rootThreadId = current.threadId;
2609
+ const { SqliteAutopilotStore } = await import('./platform/persistence/sqlite-autopilot-store.js');
2610
+ const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
2611
+ onTestFinished(() => database.close());
2612
+ const store = new SqliteAutopilotStore(database);
2613
+ store.save({
2614
+ ...store.find(fixture.sessionId),
2615
+ executor: {
2616
+ canonicalPosition: 'L1',
2617
+ canonicalTaskName: 'l1',
2618
+ taskPath: '/root/l1',
2619
+ threadId: 'child',
2620
+ l1State: 'WIP',
2621
+ lastActivityAt: new Date().toISOString(),
2622
+ ownedProcesses: [],
2623
+ outcome: 'partial',
2624
+ continuationGeneration: 1,
2625
+ continuationCount: 0,
2626
+ },
2627
+ });
2628
+ const handle = fixture.handles.find((h) => h.requests.some((r) => r.method === 'turn/start' &&
2629
+ r.params.threadId === current.threadId));
2630
+ const request = async (id, tool, args, turnId = current.activeTurnId) => {
2631
+ const result = (await handle.request({
2632
+ id,
2633
+ method: 'item/tool/call',
2634
+ params: { threadId: current.threadId, turnId, tool, arguments: args },
2635
+ }));
2636
+ return JSON.parse(result.contentItems[0].text);
2637
+ };
2638
+ const args = { version: 1, reason: 'userDirectedReplacement', canonicalTaskName: 'l1' };
2639
+ expect(await request(9900, 'gestalt_org_plan_replace_executor', args, 'stale-turn')).toMatchObject({ accepted: false });
2640
+ const expected = {
2641
+ accepted: true,
2642
+ identity: {
2643
+ canonicalPosition: 'L1',
2644
+ canonicalTaskName: 'l1',
2645
+ taskName: 'l1_g2',
2646
+ generation: 2,
2647
+ },
2648
+ };
2649
+ expect(await request(9901, 'gestalt_org_plan_replace_executor', args)).toEqual(expected);
2650
+ expect(await request(9902, 'gestalt_org_plan_replace_executor', args)).toEqual(expected);
2651
+ expect(await request(9903, 'gestalt_org_plan_health', {})).toMatchObject({
2652
+ executorReplacement: expected.identity,
2653
+ });
2654
+ expect(await request(9904, 'gestalt_org_plan_health', { view: 'compact' })).toMatchObject({
2655
+ snapshot: { executorReplacement: expected.identity },
2656
+ });
2657
+ expect(database
2658
+ .prepare("SELECT count(*) AS n FROM session_events WHERE session_id = ? AND type = 'autopilot.executor-replacement-authorized'")
2659
+ .get(fixture.sessionId)).toEqual({ n: 1 });
2660
+ expect(database
2661
+ .prepare("SELECT count(*) AS n FROM pending_interactions WHERE session_id = ? AND kind = 'orgPlanAttention'")
2662
+ .get(fixture.sessionId)).toEqual({ n: 0 });
2663
+ expect(store.find(fixture.sessionId)?.executor?.replacement?.taskName).toBe('l1_g2');
2664
+ });
2570
2665
  it.each(['Close', 'Forget'])('lets a user-directed new session take over after %s without an approval or an unreachable old-root executor', async (operation) => {
2571
2666
  const handles = [];
2572
2667
  let previousRoot = '';
@@ -75,6 +75,7 @@ import { SupervisionTakeover } from './features/autopilot/application/takeover-s
75
75
  import { SqliteSupervisionTakeoverStore } from './platform/persistence/sqlite-supervision-takeover-store.js';
76
76
  import { SqliteRuntimeReleaseStore } from './platform/persistence/sqlite-runtime-release-store.js';
77
77
  import { isOrgPlanTakeoverCall } from '../shared/contracts/org-plan-takeover.js';
78
+ import { parseOrgPlanReplaceExecutorCall } from '../shared/contracts/org-plan-replace-executor.js';
78
79
  import { WriterAcquisitionError } from './features/sessions/application/writer-acquisition.js';
79
80
  import { toAgentActivityDto } from './features/agent-activity/activity-dto.js';
80
81
  import { decodeAgentActivityFacts, decodeToolEfficiencyFacts, } from './platform/codex/activity-facts.js';
@@ -1252,6 +1253,7 @@ export async function composeRelayApp(options) {
1252
1253
  executorLaunchValidation.read(sessionId),
1253
1254
  ]);
1254
1255
  const snapshot = autopilot.snapshot(sessionId);
1256
+ const executorReplacement = autopilot.executorReplacement(sessionId, snapshot);
1255
1257
  const args = parseOrgPlanHealthArguments(toolCall?.arguments);
1256
1258
  const healthReport = args.view === 'compact'
1257
1259
  ? supervisionSnapshots.read(sessionId, compactSupervisionSnapshot({
@@ -1273,12 +1275,14 @@ export async function composeRelayApp(options) {
1273
1275
  : null,
1274
1276
  modelPolicy,
1275
1277
  launch: executorLaunch,
1278
+ executorReplacement,
1276
1279
  }), args.sinceRevision)
1277
1280
  : {
1278
1281
  state: snapshot.state,
1279
1282
  enabled: snapshot.enabled,
1280
1283
  health: snapshot.health,
1281
1284
  reason: snapshot.reason,
1285
+ executorReplacement,
1282
1286
  ...(snapshot.executionAdmission
1283
1287
  ? { executionAdmission: snapshot.executionAdmission }
1284
1288
  : {}),
@@ -1302,6 +1306,16 @@ export async function composeRelayApp(options) {
1302
1306
  return expanded.handled;
1303
1307
  rawInteraction = expanded.interaction;
1304
1308
  }
1309
+ const replacement = parseOrgPlanReplaceExecutorCall(request);
1310
+ if (!rawInteraction && replacement) {
1311
+ const result = origin.kind === 'root' && origin.physicalTurnId === session.activeTurnId
1312
+ ? autopilot.authorizeExecutorReplacement(sessionId, replacement.canonicalTaskName, 'userInstruction')
1313
+ : { accepted: false, reason: 'CURRENT_ROOT_REQUIRED' };
1314
+ return (runtime?.resolveServerRequest(sessionId, String(request.id), {
1315
+ success: true,
1316
+ contentItems: [{ type: 'inputText', text: JSON.stringify(result) }],
1317
+ }) === true);
1318
+ }
1305
1319
  if (!rawInteraction && isOrgPlanTakeoverCall(request)) {
1306
1320
  const result = origin.kind === 'root' &&
1307
1321
  origin.physicalTurnId === session.activeTurnId &&
@@ -636,12 +636,32 @@ export class AutopilotCoordinator {
636
636
  this.evaluate(sessionId);
637
637
  return this.snapshot(sessionId);
638
638
  }
639
+ /** Exposes only current, durable replacement authority, never a guessed generation. */
640
+ executorReplacement(sessionId, snapshot = this.snapshot(sessionId)) {
641
+ const replacement = snapshot.executor?.replacement;
642
+ if (!replacement || !this.validReplacement(sessionId, replacement))
643
+ return null;
644
+ const { canonicalPosition, canonicalTaskName, taskName, generation } = replacement;
645
+ return { canonicalPosition, canonicalTaskName, taskName, generation };
646
+ }
639
647
  /** Converts one typed human permission into one exact durable physical replacement. */
640
- authorizeExecutorReplacement(sessionId, canonicalTaskName) {
648
+ authorizeExecutorReplacement(sessionId, canonicalTaskName, authorization = 'attention') {
641
649
  const state = this.deps.store.find(sessionId);
642
650
  const retained = this.deps.plan(sessionId);
643
- if (!state ||
644
- state.state !== 'attentionRequired' ||
651
+ if (!state)
652
+ return { accepted: false, reason: 'attentionRequired' };
653
+ if (authorization === 'userInstruction') {
654
+ const session = this.deps.session(sessionId);
655
+ if (!state.requestedEnabled ||
656
+ !['monitoring', 'backoff'].includes(state.state) ||
657
+ state.blocking ||
658
+ this.deps.pendingInteraction(sessionId) ||
659
+ !session?.activeTurnId ||
660
+ session.state !== 'turnActive' ||
661
+ (this.deps.supervisorOwnership?.(sessionId) ?? 'owned') !== 'owned')
662
+ return { accepted: false, reason: 'controlBlocked' };
663
+ }
664
+ else if (state.state !== 'attentionRequired' ||
645
665
  state.blocking?.reason !== 'permissionRequired')
646
666
  return { accepted: false, reason: 'attentionRequired' };
647
667
  if (!retained ||
@@ -651,11 +671,26 @@ export class AutopilotCoordinator {
651
671
  const executor = state.executor;
652
672
  if (!executor || executor.canonicalTaskName !== canonicalTaskName || executor.l1State !== 'WIP')
653
673
  return { accepted: false, reason: 'executorNotAssigned' };
674
+ const position = currentExecutableL1Index(retained.plan);
675
+ if (position < 0 ||
676
+ executor.canonicalPosition !== `L${position + 1}` ||
677
+ retained.plan.steps[position]?.state !== 'WIP')
678
+ return { accepted: false, reason: 'planMismatch' };
654
679
  if (executor.replacement && this.validReplacement(sessionId, executor.replacement))
655
- return { accepted: true, identity: executor.replacement };
680
+ return { accepted: true, identity: this.executorReplacement(sessionId) };
656
681
  const activity = this.deps.activity(sessionId);
657
682
  if (activity?.confidence !== 'fresh' || this.executorTurnActive(executor, activity))
658
683
  return { accepted: false, reason: 'executorStillActive' };
684
+ if (authorization === 'userInstruction' &&
685
+ (activity.rootThreadId !== this.deps.session(sessionId)?.threadId ||
686
+ activity.subagents.filter((child) => (child.threadId ?? child.id) === executor.threadId &&
687
+ child.taskPath === executor.taskPath &&
688
+ (child.continuationGeneration ?? 1) === executor.continuationGeneration).length !== 1))
689
+ return { accepted: false, reason: 'executorNotAssigned' };
690
+ if (executor.ownedProcesses.some((process) => ['running', 'detached-active', 'exited-awaiting-result'].includes(process.state)) ||
691
+ activity.subagents.some((child) => ['working', 'awaitingAgent', 'awaitingHuman', 'blocked'].includes(child.state) ||
692
+ child.ownedProcesses?.some((process) => ['running', 'detached-active', 'exited-awaiting-result'].includes(process.state))))
693
+ return { accepted: false, reason: 'executorStillActive' };
659
694
  const previous = executor.assignment ?? executorAssignment(executor);
660
695
  const identity = executorIdentity(canonicalTaskName, previous.generation + 1);
661
696
  const now = this.deps.now();
@@ -671,7 +706,9 @@ export class AutopilotCoordinator {
671
706
  planFingerprint: fingerprint(retained.plan),
672
707
  previous: { ...previous, state: 'unavailable' },
673
708
  reason: 'humanPermissionGranted',
674
- evidence: 'typed-attention-approval',
709
+ evidence: authorization === 'userInstruction'
710
+ ? 'explicit-user-replacement'
711
+ : 'typed-attention-approval',
675
712
  },
676
713
  commands: executor.commands?.map((command) => ['scheduled', 'issued'].includes(command.status)
677
714
  ? { ...command, status: 'superseded', updatedAt: now }
@@ -687,7 +724,9 @@ export class AutopilotCoordinator {
687
724
  previousTaskName: previous.taskName,
688
725
  taskName: identity.taskName,
689
726
  generation: identity.generation,
690
- evidence: 'typed-attention-approval',
727
+ evidence: authorization === 'userInstruction'
728
+ ? 'explicit-user-replacement'
729
+ : 'typed-attention-approval',
691
730
  },
692
731
  occurredAt: now,
693
732
  },
@@ -78,6 +78,7 @@ export function compactSupervisionSnapshot(input) {
78
78
  outcome: a.executor.outcome,
79
79
  }
80
80
  : null,
81
+ executorReplacement: input.executorReplacement ?? null,
81
82
  activity: {
82
83
  confidence: activity.confidence,
83
84
  root: activity.root.state,
@@ -44,6 +44,7 @@ export class ForgetSession {
44
44
  return operation;
45
45
  };
46
46
  let failureCode = 'SESSION_RELEASE_UNCONFIRMED';
47
+ let releaseCleanup;
47
48
  try {
48
49
  const session = this.deps.find(id);
49
50
  if (!session)
@@ -56,6 +57,8 @@ export class ForgetSession {
56
57
  if (advance('cleaning').phase === 'completed')
57
58
  return operation;
58
59
  const cleanup = await this.deps.clean(session, operation.operationId);
60
+ if (cleanup && typeof cleanup === 'object')
61
+ releaseCleanup = () => cleanup.release();
59
62
  operation = { ...operation, scratchRetained: cleanup === 'retained' ? true : undefined };
60
63
  failureCode = 'SESSION_FORGET_FAILED';
61
64
  if (advance('finalizing').phase === 'completed')
@@ -77,5 +80,8 @@ export class ForgetSession {
77
80
  this.deps.changed(operation);
78
81
  return operation;
79
82
  }
83
+ finally {
84
+ await releaseCleanup?.();
85
+ }
80
86
  }
81
87
  }
@@ -19,6 +19,7 @@ import { gestaltTestRunnerDynamicTool } from '../../../shared/contracts/host-tes
19
19
  import { gestaltAutopilotWaitLeaseDynamicTool } from '../../../shared/contracts/autopilot-wait-lease.js';
20
20
  import { gestaltAgentCapacityRecoveryDynamicTool } from '../../../shared/contracts/agent-capacity-recovery.js';
21
21
  import { gestaltOrgPlanTakeoverDynamicTool } from '../../../shared/contracts/org-plan-takeover.js';
22
+ import { gestaltOrgPlanReplaceExecutorDynamicTool } from '../../../shared/contracts/org-plan-replace-executor.js';
22
23
  import { gestaltManagedPlaywrightDynamicTool } from '../../../shared/contracts/managed-playwright.js';
23
24
  import { countDiffLines } from '../../../shared/contracts/file-change.js';
24
25
  import { threadPlanName } from './thread-plan-name.js';
@@ -1417,6 +1418,7 @@ export class CodexSessionRuntime {
1417
1418
  gestaltAutopilotWaitLeaseDynamicTool,
1418
1419
  gestaltAgentCapacityRecoveryDynamicTool,
1419
1420
  gestaltOrgPlanTakeoverDynamicTool,
1421
+ gestaltOrgPlanReplaceExecutorDynamicTool,
1420
1422
  gestaltManagedPlaywrightDynamicTool,
1421
1423
  ],
1422
1424
  });
@@ -1535,6 +1537,7 @@ export class CodexSessionRuntime {
1535
1537
  gestaltAutopilotWaitLeaseDynamicTool,
1536
1538
  gestaltAgentCapacityRecoveryDynamicTool,
1537
1539
  gestaltOrgPlanTakeoverDynamicTool,
1540
+ gestaltOrgPlanReplaceExecutorDynamicTool,
1538
1541
  gestaltManagedPlaywrightDynamicTool,
1539
1542
  ],
1540
1543
  ...(session.model ? { model: session.model } : {}),