dal-code 1.0.42 → 1.0.43
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/CHANGELOG.md +7 -0
- package/dist/core/agent-session.js +9 -9
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/types.d.ts +17 -0
- package/dist/core/sandbox/shell-sandbox.js +7 -5
- package/dist/core/tools/bash.d.ts +1 -0
- package/dist/core/tools/bash.js +13 -13
- package/dist/core/tools/index.d.ts +1 -1
- package/dist/core/tools/index.js +1 -1
- package/dist/dal/manifest.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/main.js +3 -3
- package/dist/modes/rpc/approvals.js +1 -0
- package/dist/modes/rpc/message-meta.js +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +15 -1
- package/dist/modes/rpc/rpc-client.js +3 -3
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +55 -1
- package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-guard/src/index.js +2 -1
- package/dist/node_modules/@dalcode/dal-guard/src/workspace.js +2 -2
- package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-learn/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lsp/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-mcp/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +1 -1
- package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-remote/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-remote/package.json +32 -0
- package/dist/node_modules/@dalcode/dal-remote/src/cli.js +10 -0
- package/dist/node_modules/@dalcode/dal-remote/src/index.js +1 -0
- package/dist/node_modules/@dalcode/dal-remote/src/install.js +8 -0
- package/dist/node_modules/@dalcode/dal-remote/src/paths.js +1 -0
- package/dist/node_modules/@dalcode/dal-remote/src/service.js +8 -0
- package/dist/node_modules/@dalcode/dal-remote/src/spec.js +1 -0
- package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-router/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-subagent/src/background.js +8 -8
- package/dist/node_modules/@dalcode/dal-subagent/src/index.js +19 -19
- package/dist/node_modules/@dalcode/dal-subagent/src/progress.js +1 -0
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@earendil-works/chord/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-server/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
`);return e.length>
|
|
1
|
+
var w=Object.defineProperty;var h=(p,t)=>w(p,"name",{value:t,configurable:!0});import{spawn as _}from"node:child_process";import{attachJsonlLineReader as f,serializeJsonLine as d}from"./jsonl.js";const m=20,u=2e3;function E(p){const e=p.split(/\r?\n/u).filter(s=>s.trim().length>0).slice(-m).join(`
|
|
2
|
+
`);return e.length>u?e.slice(-u):e}h(E,"rpcStderrTail");const x=new Set(["select","confirm","input","editor","requestInput","requestChoice"]);class S{static{h(this,"RpcClient")}process=null;stopReadingStdout=null;eventListeners=[];pendingRequests=new Map;requestId=0;extensionUIHandler=null;approvalHandler=null;hostRequestHandler=null;stderr="";exitError=null;options;exitListeners=new Set;exitInfo;stopping=!1;turnInFlight=!1;constructor(t={}){this.options=t}async start(){if(this.process)throw new Error("Client already started");this.exitError=null,this.exitInfo=void 0,this.stopping=!1,this.turnInFlight=!1;const t=this.options.cliPath??"dist/cli.js",e=["--mode","rpc"];this.options.provider&&e.push("--provider",this.options.provider),this.options.model&&e.push("--model",this.options.model),this.options.args&&e.push(...this.options.args);const s=_(process.execPath,[t,...e],{cwd:this.options.cwd,env:{...this.options.inheritEnv===!1?{}:process.env,...this.options.env},stdio:["pipe","pipe","pipe"]});if(this.process=s,s.stderr?.on("data",r=>{this.stderr+=r.toString(),process.stderr.write(r)}),s.once("exit",(r,n)=>{if(this.process!==s)return;this.reportExit({code:r,signal:n});const o=this.createProcessExitError(r,n);this.exitError=o,this.rejectPendingRequests(o)}),s.once("error",r=>{if(this.process!==s)return;const n=new Error(`Agent process error: ${r.message}. Stderr: ${this.stderr}`);s.exitCode===null&&s.signalCode===null&&this.reportExit({code:null,signal:null,error:r.message}),this.exitError=n,this.rejectPendingRequests(n)}),s.stdin?.on("error",r=>{if(this.process!==s)return;const n=this.exitError??new Error(`Agent process stdin error: ${r.message}. Stderr: ${this.stderr}`);this.exitError=n,this.rejectPendingRequests(n)}),this.stopReadingStdout=f(s.stdout,r=>{this.handleLine(r)}),await new Promise(r=>setTimeout(r,100)),this.process.exitCode!==null){const r=this.exitError??this.createProcessExitError(this.process.exitCode,this.process.signalCode);throw this.exitError=r,r}}async stop(){this.process&&(this.stopReadingStdout?.(),this.stopReadingStdout=null,this.stopping=!0,this.process.kill("SIGTERM"),await new Promise(t=>{const e=setTimeout(()=>{this.process?.kill("SIGKILL"),t()},1e3);this.process?.on("exit",()=>{clearTimeout(e),t()})}),this.process=null,this.pendingRequests.clear())}onExit(t){const e=this.exitInfo;return e?(queueMicrotask(()=>t(e)),()=>{}):(this.exitListeners.add(t),()=>{this.exitListeners.delete(t)})}getExit(){return this.exitInfo}onEvent(t){return this.eventListeners.push(t),()=>{const e=this.eventListeners.indexOf(t);e!==-1&&this.eventListeners.splice(e,1)}}setExtensionUIHandler(t){this.extensionUIHandler=t}setApprovalHandler(t){this.approvalHandler=t}getStderr(){return this.stderr}async prompt(t,e,s){const r=await this.send({type:"prompt",message:t,images:e,streamingBehavior:s}),{disposition:n}=this.getData(r);return n!=="handled"&&(this.turnInFlight=!0),n}async steer(t,e){const s=await this.send({type:"steer",message:t,images:e});return this.getData(s).disposition}async followUp(t,e){const s=await this.send({type:"follow_up",message:t,images:e});return this.getData(s).disposition}async abort(){await this.send({type:"abort"})}async clearQueue(){const t=await this.send({type:"clear_queue"});return this.getData(t)}async newSession(t){const e=await this.send({type:"new_session",parentSession:t});return this.getData(e)}async getState(){const t=await this.send({type:"get_state"});return this.getData(t)}async setModel(t,e){const s=await this.send({type:"set_model",provider:t,modelId:e});return this.getData(s)}async cycleModel(){const t=await this.send({type:"cycle_model"});return this.getData(t)}async getAvailableModels(){const t=await this.send({type:"get_available_models"});return this.getData(t).models}async setThinkingLevel(t){await this.send({type:"set_thinking_level",level:t})}async cycleThinkingLevel(){const t=await this.send({type:"cycle_thinking_level"});return this.getData(t)}async getAvailableThinkingLevels(){const t=await this.send({type:"get_available_thinking_levels"});return this.getData(t).levels}async setSteeringMode(t){await this.send({type:"set_steering_mode",mode:t})}async setFollowUpMode(t){await this.send({type:"set_follow_up_mode",mode:t})}async compact(t){const e=await this.send({type:"compact",customInstructions:t});return this.getData(e)}async setAutoCompaction(t){await this.send({type:"set_auto_compaction",enabled:t})}async setAutoRetry(t){await this.send({type:"set_auto_retry",enabled:t})}async abortRetry(){await this.send({type:"abort_retry"})}async bash(t){const e=await this.send({type:"bash",command:t});return this.getData(e)}async abortBash(){await this.send({type:"abort_bash"})}async getSandboxStatus(){const t=await this.send({type:"get_sandbox_status"});return this.getData(t)}async listBackgroundProcesses(){const t=await this.send({type:"list_background_processes"});return this.getData(t).processes}async readBackgroundProcess(t,e){const s=await this.send({type:"read_background_process",processId:t,...e!==void 0?{tail:e}:{}});return this.getData(s)}async stopBackgroundProcess(t){const e=await this.send({type:"stop_background_process",processId:t});return this.getData(e).process}async setEnvironment(t){const e=await this.send({type:"set_environment",...t});return this.getData(e).changed}async setTelemetryConsent(t){const e=await this.send({type:"set_telemetry_consent",usage:t.usage,...t.failures!==void 0?{failures:t.failures}:{}});return this.getData(e)}async getSessionStats(){const t=await this.send({type:"get_session_stats"});return this.getData(t)}async exportHtml(t){const e=await this.send({type:"export_html",outputPath:t});return this.getData(e)}async switchSession(t){const e=await this.send({type:"switch_session",sessionPath:t});return this.getData(e)}async fork(t){const e=await this.send({type:"fork",entryId:t});return this.getData(e)}async clone(){const t=await this.send({type:"clone"});return this.getData(t)}async getForkMessages(){const t=await this.send({type:"get_fork_messages"});return this.getData(t).messages}async getEntries(t){const e=await this.send({type:"get_entries",since:t});return this.getData(e)}async getTree(){const t=await this.send({type:"get_tree"});return this.getData(t)}async getLastAssistantText(){const t=await this.send({type:"get_last_assistant_text"});return this.getData(t).text}async setSessionName(t){await this.send({type:"set_session_name",name:t})}async getMessages(){const t=await this.send({type:"get_messages"});return this.getData(t).messages}async getMessagesWithMeta(){const t=await this.send({type:"get_messages"});return this.getData(t)}async respondToApproval(t,e){const s=await this.send({type:"approval_response",optionId:e},t);return this.getData(s)}async getCommands(){const t=await this.send({type:"get_commands"});return this.getData(t).commands}async setHostCapabilities(t,e){this.hostRequestHandler=e;const s=await this.send({type:"set_host_capabilities",capabilities:t});return this.getData(s).capabilities}waitForIdle(t=6e4){return new Promise((e,s)=>{const r=setTimeout(()=>{n(),o(),s(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`))},t),n=this.onEvent(i=>{i.type==="agent_settled"&&(clearTimeout(r),n(),o(),e())}),o=this.onExit(i=>{clearTimeout(r),n(),s(this.createExitWhileWaitingError(i))})})}collectEvents(t=6e4){return new Promise((e,s)=>{const r=[],n=setTimeout(()=>{o(),i(),s(new Error(`Timeout collecting events. Stderr: ${this.stderr}`))},t),o=this.onEvent(a=>{r.push(a),a.type==="agent_settled"&&(clearTimeout(n),o(),i(),e(r))}),i=this.onExit(a=>{clearTimeout(n),o(),s(this.createExitWhileWaitingError(a))})})}async promptAndWait(t,e,s=6e4){const r=this.collectEvents(s);return await this.prompt(t,e),r}handleLine(t){try{const e=JSON.parse(t);if(e.type==="agent_start"?this.turnInFlight=!0:e.type==="agent_settled"&&(this.turnInFlight=!1),e.type==="response"&&e.id&&this.pendingRequests.has(e.id)){const s=this.pendingRequests.get(e.id);this.pendingRequests.delete(e.id),s.resolve(e);return}if(e.type==="approval_request"&&this.approvalHandler&&this.answerApprovalRequest(e),e.type==="extension_ui_request"&&x.has(e.method)&&!(e.approval===!0&&this.approvalHandler)&&this.answerExtensionUIRequest(e),e.type==="host_request"){this.answerHostRequest(e);return}for(const s of[...this.eventListeners])s(e)}catch{}}async answerExtensionUIRequest(t){const e={type:"extension_ui_response",id:t.id,cancelled:!0};let s=e;if(this.extensionUIHandler)try{s=await this.extensionUIHandler(t)??e}catch{s=e}const r=this.process?.stdin;if(!(!r||r.destroyed||!r.writable))try{r.write(d({...s,id:t.id}))}catch{}}async answerApprovalRequest(t){let e="deny";try{e=await this.approvalHandler?.(t)??"deny"}catch{e="deny"}try{await this.respondToApproval(t.id,e)}catch{}}async answerHostRequest(t){let e;if(!this.hostRequestHandler)e={type:"host_response",id:t.id,error:"host has no handler for host requests"};else try{const r=await this.hostRequestHandler(t);e={type:"host_response",id:t.id,result:r??null}}catch(r){e={type:"host_response",id:t.id,error:r instanceof Error?r.message:String(r)}}const s=this.process?.stdin;if(!(!s||s.destroyed||!s.writable))try{s.write(d(e))}catch{}}reportExit(t){if(this.exitInfo)return;const e={code:t.code,signal:t.signal,stderrTail:E(this.stderr),expected:this.stopping,turnInFlight:this.turnInFlight,...t.error?{error:t.error}:{}};this.exitInfo=e,this.turnInFlight=!1;const s=[...this.exitListeners];this.exitListeners.clear();for(const r of s)try{r(e)}catch{}}createExitWhileWaitingError(t){const e=t.signal?`signal ${t.signal}`:`code ${t.code??"unknown"}`,s=t.stderrTail?`
|
|
3
3
|
Last stderr output:
|
|
4
|
-
${t.stderrTail}`:"";return new Error(`Agent process exited (${e}) before the turn finished.${s}`)}createProcessExitError(t,e){return new Error(`Agent process exited (code=${t} signal=${e}). Stderr: ${this.stderr}`)}rejectPendingRequests(t){for(const e of this.pendingRequests.values())e.reject(t);this.pendingRequests.clear()}async send(t){const
|
|
4
|
+
${t.stderrTail}`:"";return new Error(`Agent process exited (${e}) before the turn finished.${s}`)}createProcessExitError(t,e){return new Error(`Agent process exited (code=${t} signal=${e}). Stderr: ${this.stderr}`)}rejectPendingRequests(t){for(const e of this.pendingRequests.values())e.reject(t);this.pendingRequests.clear()}async send(t,e){const s=this.process,r=s?.stdin;if(!s||!r)throw new Error("Client not started");if(this.exitError)throw this.exitError;if(s.exitCode!==null){const i=this.createProcessExitError(s.exitCode,s.signalCode);throw this.exitError=i,i}if(r.destroyed||!r.writable){const i=new Error(`Agent process stdin is not writable. Stderr: ${this.stderr}`);throw this.exitError=i,i}const n=e??`req_${++this.requestId}`,o={...t,id:n};return new Promise((i,a)=>{const l=setTimeout(()=>{this.pendingRequests.delete(n),a(new Error(`Timeout waiting for response to ${t.type}. Stderr: ${this.stderr}`))},this.options.requestTimeoutMs??3e4);this.pendingRequests.set(n,{resolve:h(c=>{clearTimeout(l),i(c)},"resolve"),reject:h(c=>{clearTimeout(l),a(c)},"reject")});try{r.write(d(o))}catch(c){const g=c instanceof Error?c:new Error(String(c)),y=this.pendingRequests.get(n);this.pendingRequests.delete(n),y?.reject(g)}})}getData(t){if(!t.success){const s=t;throw new Error(s.error)}return t.data}}export{S as RpcClient,E as rpcStderrTail};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var N=Object.defineProperty;var i=(u,o)=>N(u,"name",{value:o,configurable:!0});import*as p from"node:crypto";import{resolveExtensionNotify as O}from"../../core/extensions/index.js";import{DEFAULT_HOST_CALL_TIMEOUT_MS as G,getHostCapabilities as L,HostCallError as x,parseHostCapabilities as $}from"../../core/host-capabilities.js";import{flushRawStdout as J,takeOverStdout as W,waitForRawStdoutBackpressure as I,writeRawStdout as j}from"../../core/output-guard.js";import{killTrackedDetachedChildren as H}from"../../utils/shell.js";import{theme as z}from"../interactive/theme/theme.js";import{toJsonEvent as K}from"../json-event.js";import{applyEnvironmentUpdate as Q}from"./environment-update.js";import{attachJsonlLineReader as X,serializeJsonLine as Y}from"./jsonl.js";const Z="Prompt aborted before it started";async function ce(u){W();let o=u.session,k,S;const c=i(e=>{j(Y(e))},"output"),r=i((e,t,s)=>s===void 0?{id:e,type:"response",command:t,success:!0}:{id:e,type:"response",command:t,success:!0,data:s},"success"),d=i((e,t,s)=>({id:e,type:"response",command:t,success:!1,error:s}),"error"),m=new Map,y=new Map,q=i((e,t)=>{const s=p.randomUUID();return new Promise((n,a)=>{const l=i(()=>{clearTimeout(b),t.signal?.removeEventListener("abort",g),y.delete(s)},"cleanup"),w=i(_=>{l(),c({type:"host_request_cancelled",id:s}),a(_)},"giveUp"),g=i(()=>w(new x("aborted","host call aborted")),"onAbort"),b=setTimeout(()=>w(new x("timeout","host did not answer in time")),t.timeoutMs??G);t.signal?.addEventListener("abort",g,{once:!0}),y.set(s,{resolve:i(_=>{l(),n(_)},"resolve"),reject:i(_=>{l(),a(_)},"reject")});const v={type:"host_request",id:s,capability:e.capability,method:e.method,params:e.params};c(v)})},"rpcHostTransport");let E=!1,C=!1;const U=[];function h(e,t,s,n){if(e?.signal?.aborted)return Promise.resolve(t);const a=p.randomUUID();return new Promise((l,w)=>{let g;const b=i(()=>{g&&clearTimeout(g),e?.signal?.removeEventListener("abort",v),m.delete(a)},"cleanup"),v=i(()=>{b(),l(t)},"onAbort");e?.signal?.addEventListener("abort",v,{once:!0}),e?.timeout&&(g=setTimeout(()=>{b(),l(t)},e.timeout)),m.set(a,{resolve:i(_=>{b(),l(n(_))},"resolve"),reject:w}),c({type:"extension_ui_request",id:a,...s})})}i(h,"createDialogPromise");const A=i(()=>({select:i((e,t,s)=>h(s,void 0,{method:"select",title:e,options:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"select"),confirm:i((e,t,s)=>h(s,!1,{method:"confirm",title:e,message:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?!1:"confirmed"in n?n.confirmed:!1),"confirm"),input:i((e,t,s)=>h(s,void 0,{method:"input",title:e,placeholder:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"input"),notify(e,t){const s=O(e,t);c({type:"extension_ui_request",id:p.randomUUID(),method:"notify",message:s.message,notifyType:s.type})},setPanel(e,t){c({type:"extension_ui_request",id:p.randomUUID(),method:"setPanel",panelId:e,panel:t})},requestInput:i(e=>h(e,void 0,{method:"requestInput",title:e.title,placeholder:e.placeholder,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestInput"),requestChoice:i(e=>h(e,void 0,{method:"requestChoice",title:e.title,items:e.items,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestChoice"),onTerminalInput(){return()=>{}},setStatus(e,t){c({type:"extension_ui_request",id:p.randomUUID(),method:"setStatus",statusKey:e,statusText:t})},setWorkingMessage(e){},setWorkingVisible(e){},setWorkingIndicator(e){},setHiddenThinkingLabel(e){},setWidget(e,t,s){(t===void 0||Array.isArray(t))&&c({type:"extension_ui_request",id:p.randomUUID(),method:"setWidget",widgetKey:e,widgetLines:t,widgetPlacement:s?.placement})},setFooter(e){},setHeader(e){},setTitle(e){c({type:"extension_ui_request",id:p.randomUUID(),method:"setTitle",title:e})},async custom(){},pasteToEditor(e){this.setEditorText(e)},setEditorText(e){c({type:"extension_ui_request",id:p.randomUUID(),method:"set_editor_text",text:e})},getEditorText(){return""},async editor(e,t){const s=p.randomUUID();return new Promise((n,a)=>{m.set(s,{resolve:i(l=>{"cancelled"in l&&l.cancelled?n(void 0):"value"in l?n(l.value):n(void 0)},"resolve"),reject:a}),c({type:"extension_ui_request",id:s,method:"editor",title:e,prefill:t})})},addAutocompleteProvider(){},setEditorComponent(){},getEditorComponent(){},get theme(){return z},getAllThemes(){return[]},getTheme(e){},setTheme(e){return{success:!1,error:"Theme switching not supported in RPC mode"}},getToolsExpanded(){return!1},setToolsExpanded(e){}}),"createExtensionUIContext");u.setRebindSession(async()=>{await f()});const f=i(async()=>{o=u.session,k?.(),S?.(),k=o.subscribe(e=>{c(K(e)),e.type==="agent_settled"&&R()}),S=o.agent.subscribe(async()=>{await I()}),await o.bindExtensions({uiContext:A(),mode:"rpc",commandContextActions:{waitForIdle:i(()=>o.waitForIdle(),"waitForIdle"),newSession:i(async e=>u.newSession(e),"newSession"),fork:i(async(e,t)=>({cancelled:(await u.fork(e,t)).cancelled}),"fork"),navigateTree:i(async(e,t)=>({cancelled:(await o.navigateTree(e,{summarize:t?.summarize,customInstructions:t?.customInstructions,replaceInstructions:t?.replaceInstructions,label:t?.label})).cancelled}),"navigateTree"),switchSession:i(async(e,t)=>u.switchSession(e,t),"switchSession"),reload:i(async()=>{await o.reload()},"reload")},shutdownHandler:i(()=>{E=!0},"shutdownHandler"),onError:i(e=>{c({type:"extension_error",extensionPath:e.extensionPath,event:e.event,error:e.error})},"onError")})},"rebindSession"),F=i(()=>{const e=["SIGTERM","SIGINT"];process.platform!=="win32"&&e.push("SIGHUP");for(const t of e){const s=i(()=>{H(),T(t==="SIGHUP"?129:t==="SIGINT"?130:143,t)},"handler");process.on(t,s),U.push(()=>process.off(t,s))}},"registerSignalHandlers");await f(),F();const D=i(async e=>{const t=e.id;switch(e.type){case"prompt":{let s=!1,n=!1;o.prompt(e.message,{images:e.images,streamingBehavior:e.streamingBehavior,source:"rpc",preflightResult:i(a=>{if(a==="cancelled"){n=!0;return}s=!0,c(r(t,"prompt",{disposition:a}))},"preflightResult")}).then(()=>{n&&!s&&c(d(t,"prompt",Z))},a=>{s||c(d(t,"prompt",a.message))});return}case"steer":{const s=await o.steer(e.message,e.images,{source:"rpc"});return r(t,"steer",{disposition:s})}case"follow_up":{const s=await o.followUp(e.message,e.images,{source:"rpc"});return r(t,"follow_up",{disposition:s})}case"abort":return await o.abort(),r(t,"abort");case"clear_queue":return r(t,"clear_queue",o.clearQueue());case"new_session":{const s=e.parentSession?{parentSession:e.parentSession}:void 0,n=await u.newSession(s);return n.cancelled||await f(),r(t,"new_session",n)}case"get_state":{const s={model:o.model,thinkingLevel:o.thinkingLevel,isStreaming:o.isStreaming,isCompacting:o.isCompacting,steeringMode:o.steeringMode,followUpMode:o.followUpMode,sessionFile:o.sessionFile,sessionId:o.sessionId,sessionName:o.sessionName,autoCompactionEnabled:o.autoCompactionEnabled,messageCount:o.messages.length,pendingMessageCount:o.pendingMessageCount};return r(t,"get_state",s)}case"set_model":{const n=o.modelRuntime.getAvailableSnapshot().find(a=>a.provider===e.provider&&a.id===e.modelId);return n?(await o.setModel(n),r(t,"set_model",n)):d(t,"set_model",`Model not found: ${e.provider}/${e.modelId}`)}case"cycle_model":{const s=await o.cycleModel();return s?r(t,"cycle_model",s):r(t,"cycle_model",null)}case"get_available_models":{const s=o.modelRuntime.getAvailableSnapshot();return r(t,"get_available_models",{models:s})}case"set_thinking_level":return o.setThinkingLevel(e.level),r(t,"set_thinking_level");case"cycle_thinking_level":{const s=o.cycleThinkingLevel();return s?r(t,"cycle_thinking_level",{level:s}):r(t,"cycle_thinking_level",null)}case"get_available_thinking_levels":{const s=o.getAvailableThinkingLevels();return r(t,"get_available_thinking_levels",{levels:s})}case"set_steering_mode":return o.setSteeringMode(e.mode),r(t,"set_steering_mode");case"set_follow_up_mode":return o.setFollowUpMode(e.mode),r(t,"set_follow_up_mode");case"compact":{const s=await o.compact(e.customInstructions);return r(t,"compact",s)}case"set_auto_compaction":return o.setAutoCompactionEnabled(e.enabled),r(t,"set_auto_compaction");case"set_auto_retry":return o.setAutoRetryEnabled(e.enabled),r(t,"set_auto_retry");case"abort_retry":return o.abortRetry(),r(t,"abort_retry");case"bash":{const s=await o.extensionRunner.emitUserBash({type:"user_bash",command:e.command,excludeFromContext:e.excludeFromContext??!1,cwd:o.sessionManager.getCwd()});if(s?.result)return o.recordBashResult(e.command,s.result,{excludeFromContext:e.excludeFromContext}),r(t,"bash",s.result);const n=await o.executeBash(e.command,void 0,{excludeFromContext:e.excludeFromContext,id:t,operations:s?.operations});return r(t,"bash",n)}case"abort_bash":return o.abortBash(),r(t,"abort_bash");case"get_sandbox_status":return r(t,"get_sandbox_status",o.getSandboxStatus()??null);case"list_background_processes":return r(t,"list_background_processes",{processes:o.backgroundProcesses.list()});case"read_background_process":{const{text:s,truncated:n,info:a}=o.backgroundProcesses.read(e.processId,e.tail!==void 0?{tail:e.tail}:{tail:200});return r(t,"read_background_process",{text:s,truncated:n,process:a})}case"stop_background_process":{const s=await o.backgroundProcesses.stop(e.processId);return r(t,"stop_background_process",{process:s})}case"get_session_stats":{const s=o.getSessionStats();return r(t,"get_session_stats",s)}case"export_html":{const s=await o.exportToHtml(e.outputPath);return r(t,"export_html",{path:s})}case"switch_session":{const s=await u.switchSession(e.sessionPath);return s.cancelled||await f(),r(t,"switch_session",s)}case"fork":{const s=await u.fork(e.entryId);return s.cancelled||await f(),r(t,"fork",{text:s.selectedText,cancelled:s.cancelled})}case"clone":{const s=o.sessionManager.getLeafId();if(!s)return d(t,"clone","Cannot clone session: no current entry selected");const n=await u.fork(s,{position:"at"});return n.cancelled||await f(),r(t,"clone",{cancelled:n.cancelled})}case"get_fork_messages":{const s=o.getUserMessagesForForking();return r(t,"get_fork_messages",{messages:s})}case"get_entries":{const s=o.sessionManager;let n=s.getEntries();if(e.since!==void 0){const a=n.findIndex(l=>l.id===e.since);if(a===-1)return d(t,"get_entries",`Entry not found: ${e.since}`);n=n.slice(a+1)}return r(t,"get_entries",{entries:n,leafId:s.getLeafId()})}case"get_tree":{const s=o.sessionManager;return r(t,"get_tree",{tree:s.getTree(),leafId:s.getLeafId()})}case"get_last_assistant_text":{const s=o.getLastAssistantText();return r(t,"get_last_assistant_text",{text:s})}case"set_session_name":{const s=e.name.trim();return s?(o.setSessionName(s),r(t,"set_session_name")):d(t,"set_session_name","Session name cannot be empty")}case"get_messages":return r(t,"get_messages",{messages:o.messages});case"get_commands":{const s=[];for(const n of o.extensionRunner.getRegisteredCommands())s.push({name:n.invocationName,description:n.description,source:"extension",sourceInfo:n.sourceInfo});for(const n of o.promptTemplates)s.push({name:n.name,description:n.description,source:"prompt",sourceInfo:n.sourceInfo});for(const n of o.resourceLoader.getSkills().skills)s.push({name:`skill:${n.name}`,description:n.description,source:"skill",sourceInfo:n.sourceInfo});return r(t,"get_commands",{commands:s})}case"set_host_capabilities":{const s=L();return s.set("rpc",$(e.capabilities),q),r(t,"set_host_capabilities",{capabilities:s.list()})}case"set_environment":{const s=Q({set:e.set,unset:e.unset});return r(t,"set_environment",{changed:s})}case"set_telemetry_consent":{const{usage:s,failures:n}=e;if(typeof s!="boolean"||n!==void 0&&typeof n!="boolean")return d(t,"set_telemetry_consent","set_telemetry_consent: usage must be a boolean, failures a boolean or omitted");const a=globalThis[Symbol.for("dalcode.telemetry.consentApi")];return a?r(t,"set_telemetry_consent",a.set({usage:s,failures:n})):d(t,"set_telemetry_consent","set_telemetry_consent: telemetry is not loaded in this engine")}default:{const s=e;return d(t,s.type,`Unknown command: ${s.type}`)}}},"handleCommand");let M=i(()=>{},"detachInput");async function T(e=0,t){C&&process.exit(e),C=!0;for(const s of U)s();k?.(),S?.(),L().clear("rpc");for(const s of y.values())s.reject(new x("unavailable","RPC host disconnected"));await u.dispose(),M(),process.stdin.pause(),t!=="SIGTERM"&&await J(),process.exit(e)}i(T,"shutdown");async function R(){E&&await T()}i(R,"checkShutdownRequested");const B=i(async e=>{let t;try{t=JSON.parse(e)}catch(n){c(d(void 0,"parse",`Failed to parse command: ${n instanceof Error?n.message:String(n)}`)),await I();return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="extension_ui_response"){const n=t,a=m.get(n.id);a&&(m.delete(n.id),a.resolve(n));return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="host_response"){const n=t,a=y.get(n.id);a&&("error"in n?a.reject(new x("host_error",String(n.error))):a.resolve(n.result));return}const s=t;try{const n=await D(s);n&&(c(n),await I()),await R()}catch(n){c(d(s.id,s.type,n instanceof Error?n.message:String(n))),await I()}},"handleInputLine"),P=i(()=>{T()},"onInputEnd");return process.stdin.on("end",P),M=(()=>{const e=X(process.stdin,t=>{B(t)});return()=>{e(),process.stdin.off("end",P)}})(),new Promise(()=>{})}i(ce,"runRpcMode");export{Z as PROMPT_ABORTED_BEFORE_START,ce as runRpcMode};
|
|
1
|
+
var z=Object.defineProperty;var i=(d,o)=>z(d,"name",{value:o,configurable:!0});import*as _ from"node:crypto";import{resolveExtensionNotify as K}from"../../core/extensions/index.js";import{DEFAULT_HOST_CALL_TIMEOUT_MS as Q,getHostCapabilities as N,HostCallError as k,parseHostCapabilities as V}from"../../core/host-capabilities.js";import{flushRawStdout as X,takeOverStdout as Y,waitForRawStdoutBackpressure as S,writeRawStdout as Z}from"../../core/output-guard.js";import{killTrackedDetachedChildren as ee}from"../../utils/shell.js";import{theme as te}from"../interactive/theme/theme.js";import{toJsonEvent as se}from"../json-event.js";import{openApproval as ne,ResolvedApprovals as oe}from"./approvals.js";import{applyEnvironmentUpdate as re}from"./environment-update.js";import{attachJsonlLineReader as ie,serializeJsonLine as ae}from"./jsonl.js";import{buildMessageMeta as le}from"./message-meta.js";const ce="Prompt aborted before it started";async function we(d){Y();let o=d.session,T,E;const l=i(e=>{Z(ae(e))},"output"),r=i((e,t,s)=>s===void 0?{id:e,type:"response",command:t,success:!0}:{id:e,type:"response",command:t,success:!0,data:s},"success"),u=i((e,t,s)=>({id:e,type:"response",command:t,success:!1,error:s}),"error"),g=new Map,R=new oe,w=new Map,O=i((e,t)=>{const s=_.randomUUID();return new Promise((n,a)=>{const c=i(()=>{clearTimeout(U),t.signal?.removeEventListener("abort",h),w.delete(s)},"cleanup"),p=i(f=>{c(),l({type:"host_request_cancelled",id:s}),a(f)},"giveUp"),h=i(()=>p(new k("aborted","host call aborted")),"onAbort"),U=setTimeout(()=>p(new k("timeout","host did not answer in time")),t.timeoutMs??Q);t.signal?.addEventListener("abort",h,{once:!0}),w.set(s,{resolve:i(f=>{c(),n(f)},"resolve"),reject:i(f=>{c(),a(f)},"reject")});const b={type:"host_request",id:s,capability:e.capability,method:e.method,params:e.params};l(b)})},"rpcHostTransport");let P=!1,A=!1;const L=[];function v(e,t,s,n){if(e?.signal?.aborted)return Promise.resolve(t);const a=_.randomUUID(),c=s.method,p=e?.approval&&(c==="select"||c==="confirm")?ne(a,c,e.approval,{options:Array.isArray(s.options)?s.options:void 0,timeout:e.timeout}):void 0;return new Promise((h,U)=>{let b;const f=i((y,x)=>{if(!p)return;const I=x?p.kindOf(x):void 0,$=y==="dialog"&&!I?"cancelled":y;R.remember(a,I,$);const H={type:"approval_resolved",id:a,...I?{optionId:I}:{},via:$};l(H)},"settleApproval"),M=i(()=>{b&&clearTimeout(b),e?.signal?.removeEventListener("abort",B),g.delete(a)},"cleanup"),B=i(()=>{M(),f("aborted"),h(t)},"onAbort");e?.signal?.addEventListener("abort",B,{once:!0}),e?.timeout&&(b=setTimeout(()=>{M(),f("timeout"),h(t)},e.timeout)),g.set(a,{resolve:i((y,x="dialog")=>{M(),f(x,y),h(n(y))},"resolve"),reject:U,...p?{approval:p}:{}}),p&&l(p.request),l({type:"extension_ui_request",id:a,...s,...p?{approval:!0}:{}})})}i(v,"createDialogPromise");const j=i(()=>({select:i((e,t,s)=>v(s,void 0,{method:"select",title:e,options:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"select"),confirm:i((e,t,s)=>v(s,!1,{method:"confirm",title:e,message:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?!1:"confirmed"in n?n.confirmed:!1),"confirm"),input:i((e,t,s)=>v(s,void 0,{method:"input",title:e,placeholder:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"input"),notify(e,t){const s=K(e,t);l({type:"extension_ui_request",id:_.randomUUID(),method:"notify",message:s.message,notifyType:s.type})},setPanel(e,t){l({type:"extension_ui_request",id:_.randomUUID(),method:"setPanel",panelId:e,panel:t})},requestInput:i(e=>v(e,void 0,{method:"requestInput",title:e.title,placeholder:e.placeholder,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestInput"),requestChoice:i(e=>v(e,void 0,{method:"requestChoice",title:e.title,items:e.items,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestChoice"),onTerminalInput(){return()=>{}},setStatus(e,t){l({type:"extension_ui_request",id:_.randomUUID(),method:"setStatus",statusKey:e,statusText:t})},setWorkingMessage(e){},setWorkingVisible(e){},setWorkingIndicator(e){},setHiddenThinkingLabel(e){},setWidget(e,t,s){(t===void 0||Array.isArray(t))&&l({type:"extension_ui_request",id:_.randomUUID(),method:"setWidget",widgetKey:e,widgetLines:t,widgetPlacement:s?.placement})},setFooter(e){},setHeader(e){},setTitle(e){l({type:"extension_ui_request",id:_.randomUUID(),method:"setTitle",title:e})},async custom(){},pasteToEditor(e){this.setEditorText(e)},setEditorText(e){l({type:"extension_ui_request",id:_.randomUUID(),method:"set_editor_text",text:e})},getEditorText(){return""},async editor(e,t){const s=_.randomUUID();return new Promise((n,a)=>{g.set(s,{resolve:i(c=>{"cancelled"in c&&c.cancelled?n(void 0):"value"in c?n(c.value):n(void 0)},"resolve"),reject:a}),l({type:"extension_ui_request",id:s,method:"editor",title:e,prefill:t})})},addAutocompleteProvider(){},setEditorComponent(){},getEditorComponent(){},get theme(){return te},getAllThemes(){return[]},getTheme(e){},setTheme(e){return{success:!1,error:"Theme switching not supported in RPC mode"}},getToolsExpanded(){return!1},setToolsExpanded(e){}}),"createExtensionUIContext");d.setRebindSession(async()=>{await m()});const m=i(async()=>{o=d.session,T?.(),E?.(),T=o.subscribe(e=>{l(se(e)),e.type==="agent_settled"&&q()}),E=o.agent.subscribe(async()=>{await S()}),await o.bindExtensions({uiContext:j(),mode:"rpc",commandContextActions:{waitForIdle:i(()=>o.waitForIdle(),"waitForIdle"),newSession:i(async e=>d.newSession(e),"newSession"),fork:i(async(e,t)=>({cancelled:(await d.fork(e,t)).cancelled}),"fork"),navigateTree:i(async(e,t)=>({cancelled:(await o.navigateTree(e,{summarize:t?.summarize,customInstructions:t?.customInstructions,replaceInstructions:t?.replaceInstructions,label:t?.label})).cancelled}),"navigateTree"),switchSession:i(async(e,t)=>d.switchSession(e,t),"switchSession"),reload:i(async()=>{await o.reload()},"reload")},shutdownHandler:i(()=>{P=!0},"shutdownHandler"),onError:i(e=>{l({type:"extension_error",extensionPath:e.extensionPath,event:e.event,error:e.error})},"onError")})},"rebindSession"),G=i(()=>{const e=["SIGTERM","SIGINT"];process.platform!=="win32"&&e.push("SIGHUP");for(const t of e){const s=i(()=>{ee(),C(t==="SIGHUP"?129:t==="SIGINT"?130:143,t)},"handler");process.on(t,s),L.push(()=>process.off(t,s))}},"registerSignalHandlers");await m(),G();const J=i(async e=>{const t=e.id;switch(e.type){case"prompt":{let s=!1,n=!1;o.prompt(e.message,{images:e.images,streamingBehavior:e.streamingBehavior,source:"rpc",preflightResult:i(a=>{if(a==="cancelled"){n=!0;return}s=!0,l(r(t,"prompt",{disposition:a}))},"preflightResult")}).then(()=>{n&&!s&&l(u(t,"prompt",ce))},a=>{s||l(u(t,"prompt",a.message))});return}case"steer":{const s=await o.steer(e.message,e.images,{source:"rpc"});return r(t,"steer",{disposition:s})}case"follow_up":{const s=await o.followUp(e.message,e.images,{source:"rpc"});return r(t,"follow_up",{disposition:s})}case"abort":return await o.abort(),r(t,"abort");case"clear_queue":return r(t,"clear_queue",o.clearQueue());case"new_session":{const s=e.parentSession?{parentSession:e.parentSession}:void 0,n=await d.newSession(s);return n.cancelled||await m(),r(t,"new_session",n)}case"get_state":{const s={model:o.model,thinkingLevel:o.thinkingLevel,isStreaming:o.isStreaming,isCompacting:o.isCompacting,steeringMode:o.steeringMode,followUpMode:o.followUpMode,sessionFile:o.sessionFile,sessionId:o.sessionId,sessionName:o.sessionName,autoCompactionEnabled:o.autoCompactionEnabled,messageCount:o.messages.length,pendingMessageCount:o.pendingMessageCount};return r(t,"get_state",s)}case"set_model":{const n=o.modelRuntime.getAvailableSnapshot().find(a=>a.provider===e.provider&&a.id===e.modelId);return n?(await o.setModel(n),r(t,"set_model",n)):u(t,"set_model",`Model not found: ${e.provider}/${e.modelId}`)}case"cycle_model":{const s=await o.cycleModel();return s?r(t,"cycle_model",s):r(t,"cycle_model",null)}case"get_available_models":{const s=o.modelRuntime.getAvailableSnapshot();return r(t,"get_available_models",{models:s})}case"set_thinking_level":return o.setThinkingLevel(e.level),r(t,"set_thinking_level");case"cycle_thinking_level":{const s=o.cycleThinkingLevel();return s?r(t,"cycle_thinking_level",{level:s}):r(t,"cycle_thinking_level",null)}case"get_available_thinking_levels":{const s=o.getAvailableThinkingLevels();return r(t,"get_available_thinking_levels",{levels:s})}case"set_steering_mode":return o.setSteeringMode(e.mode),r(t,"set_steering_mode");case"set_follow_up_mode":return o.setFollowUpMode(e.mode),r(t,"set_follow_up_mode");case"compact":{const s=await o.compact(e.customInstructions);return r(t,"compact",s)}case"set_auto_compaction":return o.setAutoCompactionEnabled(e.enabled),r(t,"set_auto_compaction");case"set_auto_retry":return o.setAutoRetryEnabled(e.enabled),r(t,"set_auto_retry");case"abort_retry":return o.abortRetry(),r(t,"abort_retry");case"bash":{const s=await o.extensionRunner.emitUserBash({type:"user_bash",command:e.command,excludeFromContext:e.excludeFromContext??!1,cwd:o.sessionManager.getCwd()});if(s?.result)return o.recordBashResult(e.command,s.result,{excludeFromContext:e.excludeFromContext}),r(t,"bash",s.result);const n=await o.executeBash(e.command,void 0,{excludeFromContext:e.excludeFromContext,id:t,operations:s?.operations});return r(t,"bash",n)}case"abort_bash":return o.abortBash(),r(t,"abort_bash");case"get_sandbox_status":return r(t,"get_sandbox_status",o.getSandboxStatus()??null);case"list_background_processes":return r(t,"list_background_processes",{processes:o.backgroundProcesses.list()});case"read_background_process":{const{text:s,truncated:n,info:a}=o.backgroundProcesses.read(e.processId,e.tail!==void 0?{tail:e.tail}:{tail:200});return r(t,"read_background_process",{text:s,truncated:n,process:a})}case"stop_background_process":{const s=await o.backgroundProcesses.stop(e.processId);return r(t,"stop_background_process",{process:s})}case"get_session_stats":{const s=o.getSessionStats();return r(t,"get_session_stats",s)}case"export_html":{const s=await o.exportToHtml(e.outputPath);return r(t,"export_html",{path:s})}case"switch_session":{const s=await d.switchSession(e.sessionPath);return s.cancelled||await m(),r(t,"switch_session",s)}case"fork":{const s=await d.fork(e.entryId);return s.cancelled||await m(),r(t,"fork",{text:s.selectedText,cancelled:s.cancelled})}case"clone":{const s=o.sessionManager.getLeafId();if(!s)return u(t,"clone","Cannot clone session: no current entry selected");const n=await d.fork(s,{position:"at"});return n.cancelled||await m(),r(t,"clone",{cancelled:n.cancelled})}case"get_fork_messages":{const s=o.getUserMessagesForForking();return r(t,"get_fork_messages",{messages:s})}case"get_entries":{const s=o.sessionManager;let n=s.getEntries();if(e.since!==void 0){const a=n.findIndex(c=>c.id===e.since);if(a===-1)return u(t,"get_entries",`Entry not found: ${e.since}`);n=n.slice(a+1)}return r(t,"get_entries",{entries:n,leafId:s.getLeafId()})}case"get_tree":{const s=o.sessionManager;return r(t,"get_tree",{tree:s.getTree(),leafId:s.getLeafId()})}case"get_last_assistant_text":{const s=o.getLastAssistantText();return r(t,"get_last_assistant_text",{text:s})}case"set_session_name":{const s=e.name.trim();return s?(o.setSessionName(s),r(t,"set_session_name")):u(t,"set_session_name","Session name cannot be empty")}case"get_messages":{const s=o.messages,n=le(s,o.sessionManager.buildSessionProjection());return r(t,"get_messages",{messages:s,meta:n})}case"get_commands":{const s=[];for(const n of o.extensionRunner.getRegisteredCommands())s.push({name:n.invocationName,description:n.description,source:"extension",sourceInfo:n.sourceInfo});for(const n of o.promptTemplates)s.push({name:n.name,description:n.description,source:"prompt",sourceInfo:n.sourceInfo});for(const n of o.resourceLoader.getSkills().skills)s.push({name:`skill:${n.name}`,description:n.description,source:"skill",sourceInfo:n.sourceInfo});return r(t,"get_commands",{commands:s})}case"set_host_capabilities":{const s=N();return s.set("rpc",V(e.capabilities),O),r(t,"set_host_capabilities",{capabilities:s.list()})}case"set_environment":{const s=re({set:e.set,unset:e.unset});return r(t,"set_environment",{changed:s})}case"set_telemetry_consent":{const{usage:s,failures:n}=e;if(typeof s!="boolean"||n!==void 0&&typeof n!="boolean")return u(t,"set_telemetry_consent","set_telemetry_consent: usage must be a boolean, failures a boolean or omitted");const a=globalThis[Symbol.for("dalcode.telemetry.consentApi")];return a?r(t,"set_telemetry_consent",a.set({usage:s,failures:n})):u(t,"set_telemetry_consent","set_telemetry_consent: telemetry is not loaded in this engine")}case"approval_response":{const s=g.get(e.id);if(s?.approval){const a=s.approval.request.options.find(c=>c.id===e.optionId);return a?(s.resolve(s.approval.responseFor(a.kind),"approval_response"),r(t,"approval_response",{accepted:!0,optionId:a.kind,via:"approval_response"})):u(t,"approval_response",`Unknown option ${String(e.optionId)} for approval ${e.id}; expected one of ${s.approval.request.options.map(c=>c.id).join(", ")}`)}const n=R.get(e.id);return n?r(t,"approval_response",{accepted:!1,...n}):u(t,"approval_response",`Unknown approval: ${e.id}`)}default:{const s=e;return u(t,s.type,`Unknown command: ${s.type}`)}}},"handleCommand");let F=i(()=>{},"detachInput");async function C(e=0,t){A&&process.exit(e),A=!0;for(const s of L)s();T?.(),E?.(),N().clear("rpc");for(const s of w.values())s.reject(new k("unavailable","RPC host disconnected"));await d.dispose(),F(),process.stdin.pause(),t!=="SIGTERM"&&await X(),process.exit(e)}i(C,"shutdown");async function q(){P&&await C()}i(q,"checkShutdownRequested");const W=i(async e=>{let t;try{t=JSON.parse(e)}catch(n){l(u(void 0,"parse",`Failed to parse command: ${n instanceof Error?n.message:String(n)}`)),await S();return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="extension_ui_response"){const n=t,a=g.get(n.id);a&&(g.delete(n.id),a.resolve(n));return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="host_response"){const n=t,a=w.get(n.id);a&&("error"in n?a.reject(new k("host_error",String(n.error))):a.resolve(n.result));return}const s=t;try{const n=await J(s);n&&(l(n),await S()),await q()}catch(n){l(u(s.id,s.type,n instanceof Error?n.message:String(n))),await S()}},"handleInputLine"),D=i(()=>{C()},"onInputEnd");return process.stdin.on("end",D),F=(()=>{const e=ie(process.stdin,t=>{W(t)});return()=>{e(),process.stdin.off("end",D)}})(),new Promise(()=>{})}i(we,"runRpcMode");export{ce as PROMPT_ABORTED_BEFORE_START,we as runRpcMode};
|
|
@@ -4,6 +4,7 @@ import type { PromptDisposition, QueuedInputDisposition, SessionStats } from "..
|
|
|
4
4
|
import type { BackgroundProcessInfo } from "../../core/background-processes.ts";
|
|
5
5
|
import type { BashResult } from "../../core/bash-executor.ts";
|
|
6
6
|
import type { CompactionResult } from "../../core/compaction/index.ts";
|
|
7
|
+
import type { ApprovalOptionKind, ApprovalSource } from "../../core/extensions/types.ts";
|
|
7
8
|
import type { HostCapability } from "../../core/host-capabilities.ts";
|
|
8
9
|
import type { SandboxStatus } from "../../core/sandbox/shell-sandbox.ts";
|
|
9
10
|
import type { SessionEntry, SessionTreeNode } from "../../core/session-manager.ts";
|
|
@@ -159,7 +160,7 @@ export type RpcCommand = {
|
|
|
159
160
|
type: "set_telemetry_consent";
|
|
160
161
|
usage: boolean;
|
|
161
162
|
failures?: boolean;
|
|
162
|
-
};
|
|
163
|
+
} | RpcApprovalResponse;
|
|
163
164
|
export interface TelemetryConsentStatus {
|
|
164
165
|
usage: {
|
|
165
166
|
decided: boolean;
|
|
@@ -453,6 +454,7 @@ export type RpcResponse = {
|
|
|
453
454
|
success: true;
|
|
454
455
|
data: {
|
|
455
456
|
messages: AgentMessage[];
|
|
457
|
+
meta: RpcMessageMeta[];
|
|
456
458
|
};
|
|
457
459
|
} | {
|
|
458
460
|
id?: string;
|
|
@@ -484,6 +486,16 @@ export type RpcResponse = {
|
|
|
484
486
|
command: "set_telemetry_consent";
|
|
485
487
|
success: true;
|
|
486
488
|
data: TelemetryConsentStatus;
|
|
489
|
+
} | {
|
|
490
|
+
id?: string;
|
|
491
|
+
type: "response";
|
|
492
|
+
command: "approval_response";
|
|
493
|
+
success: true;
|
|
494
|
+
data: {
|
|
495
|
+
accepted: boolean;
|
|
496
|
+
optionId?: ApprovalOptionKind;
|
|
497
|
+
via: RpcApprovalResolved["via"];
|
|
498
|
+
};
|
|
487
499
|
} | {
|
|
488
500
|
id?: string;
|
|
489
501
|
type: "response";
|
|
@@ -498,6 +510,7 @@ export type RpcExtensionUIRequest = {
|
|
|
498
510
|
title: string;
|
|
499
511
|
options: string[];
|
|
500
512
|
timeout?: number;
|
|
513
|
+
approval?: true;
|
|
501
514
|
} | {
|
|
502
515
|
type: "extension_ui_request";
|
|
503
516
|
id: string;
|
|
@@ -505,6 +518,7 @@ export type RpcExtensionUIRequest = {
|
|
|
505
518
|
title: string;
|
|
506
519
|
message: string;
|
|
507
520
|
timeout?: number;
|
|
521
|
+
approval?: true;
|
|
508
522
|
} | {
|
|
509
523
|
type: "extension_ui_request";
|
|
510
524
|
id: string;
|
|
@@ -589,6 +603,46 @@ export type RpcExtensionUIResponse = {
|
|
|
589
603
|
id: string;
|
|
590
604
|
cancelled: true;
|
|
591
605
|
};
|
|
606
|
+
export interface RpcApprovalOption {
|
|
607
|
+
id: ApprovalOptionKind;
|
|
608
|
+
kind: ApprovalOptionKind;
|
|
609
|
+
label: string;
|
|
610
|
+
}
|
|
611
|
+
export interface RpcApprovalRequest {
|
|
612
|
+
type: "approval_request";
|
|
613
|
+
id: string;
|
|
614
|
+
dialogMethod: "select" | "confirm";
|
|
615
|
+
source: ApprovalSource;
|
|
616
|
+
toolCallId?: string;
|
|
617
|
+
toolName?: string;
|
|
618
|
+
args?: Record<string, unknown>;
|
|
619
|
+
argsTruncated?: true;
|
|
620
|
+
risk?: {
|
|
621
|
+
level: "low" | "medium" | "high";
|
|
622
|
+
reason: string;
|
|
623
|
+
ruleId?: string;
|
|
624
|
+
};
|
|
625
|
+
title: string;
|
|
626
|
+
description?: string;
|
|
627
|
+
options: RpcApprovalOption[];
|
|
628
|
+
timeout?: number;
|
|
629
|
+
}
|
|
630
|
+
export interface RpcApprovalResponse {
|
|
631
|
+
type: "approval_response";
|
|
632
|
+
id: string;
|
|
633
|
+
optionId: ApprovalOptionKind;
|
|
634
|
+
}
|
|
635
|
+
export interface RpcApprovalResolved {
|
|
636
|
+
type: "approval_resolved";
|
|
637
|
+
id: string;
|
|
638
|
+
optionId?: ApprovalOptionKind;
|
|
639
|
+
via: "approval_response" | "dialog" | "cancelled" | "timeout" | "aborted";
|
|
640
|
+
}
|
|
641
|
+
export interface RpcMessageMeta {
|
|
642
|
+
timestamp?: number;
|
|
643
|
+
recordedAt?: number;
|
|
644
|
+
entryId?: string;
|
|
645
|
+
}
|
|
592
646
|
export interface RpcHostRequest {
|
|
593
647
|
type: "host_request";
|
|
594
648
|
id: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-advisor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "advisor: the model asks another strong model to review its current plan and point out risks. Adapted from @juicesharp/rpiv-advisor 2.13.8 (MIT).",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
]
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
24
|
-
"@dalcode/dal-router": "1.0.
|
|
23
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
24
|
+
"@dalcode/dal-router": "1.0.43",
|
|
25
25
|
"typebox": "1.3.27"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-awake",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Keeps the computer from going to sleep while a long agent run is in progress, and lets it sleep again when the run ends. Adapted from @narumitw/pi-caffeinate (MIT).",
|
|
6
6
|
"type": "module",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
+
"@dalcode/dal-pi-kit": "1.0.43"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-bridge",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
22
22
|
"typebox": "1.3.7"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-capabilities",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Capability center for DAL: switches on the reviewed MCP connectors, skills and engine packages a task needs (installed automatically from the signed DAL market), with /capabilities to list, disable and enable them.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@dalcode/dal-mcp": "1.0.
|
|
27
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
28
|
-
"@dalcode/deepailab": "1.0.
|
|
26
|
+
"@dalcode/dal-mcp": "1.0.43",
|
|
27
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
28
|
+
"@dalcode/deepailab": "1.0.43"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-compat",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Claude Code compatibility: the user's and project's .claude/rules/ and .claude/CLAUDE.md apply in DAL. Grown from the claude-rules extension example.",
|
|
6
6
|
"type": "module",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
22
22
|
"minimatch": "10.2.6"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-dap",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Debugger for DAL: breakpoints, stepping, call stacks and variables in Node.js and Python programs over the Debug Adapter Protocol, installing the adapter on first use. The DAP client is adapted from oh-my-pi's src/dap (MIT).",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
]
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
27
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
28
28
|
"typebox": "1.3.27"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-gateway",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@dalcode/deepailab": "1.0.
|
|
20
|
+
"@dalcode/deepailab": "1.0.43"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-goal",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Goal mode for DAL: /goal keeps the agent working on one objective until it is verified complete, with token and continuation limits. Adapted from @narumitw/pi-goal 0.54.11 (MIT, narumiruna); the independent completion check adapts pi-goal-x 0.32.3 (MIT, Lucas).",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
]
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
25
|
-
"@dalcode/dal-subagent": "1.0.
|
|
24
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
25
|
+
"@dalcode/dal-subagent": "1.0.43",
|
|
26
26
|
"typebox": "1.3.27"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-guard",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
]
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
24
|
-
"@dalcode/dal-bridge": "1.0.
|
|
25
|
-
"@dalcode/dal-halo": "1.0.
|
|
23
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
24
|
+
"@dalcode/dal-bridge": "1.0.43",
|
|
25
|
+
"@dalcode/dal-halo": "1.0.43"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
var V=Object.defineProperty;var l=(u,a)=>V(u,"name",{value:a,configurable:!0});var q=Object.defineProperty,n=l((u,a)=>q(u,"name",{value:a,configurable:!0}),"l");import{realpathSync as G}from"node:fs";import{basename as J,dirname as K,isAbsolute as Z,join as X,relative as Y,resolve as Q,sep as uu}from"node:path";import{readBridgeConfig as C}from"@dalcode/dal-bridge/client";import{getOwnTty as eu,requestHaloApproval as au}from"@dalcode/dal-halo";import{hasChosenLanguage as ou,t as e}from"@dalcode/dal-pi-kit";import{DAL_HOOK_NOTIFICATION_CHANNEL as tu,getAgentDir as D,registerSandboxEscalationHandler as su,resolveToCwd as ru}from"@earendil-works/pi-coding-agent";import{DAL_CO_AUTHOR as O,foreignAttributionInMessageFile as iu,rewriteCommitAttribution as nu}from"./attribution.js";import{credentialBlockReason as lu,namesDalCredential as du,readsDalSecretCopy as Fu,redactContent as cu,secretCopyBlockReason as Eu}from"./credentials.js";import{exportGuardMode as Au,saveGuardMode as N,shouldAskGuardMode as mu,startupGuardMode as fu}from"./mode.js";import{wrongPackageManager as Cu}from"./package-manager.js";import{reviewBashCommand as Du}from"./review.js";import{createWorkspaceGate as pu}from"./workspace.js";import{DAL_CO_AUTHOR as Bu,foreignAttributionInMessageFile as gu,foreignCoAuthors as hu,isGitCommit as bu,rewriteCommitAttribution as yu}from"./attribution.js";import{dalSecretValues as wu,fileHoldsDalSecret as vu,namesDalCredential as $u,REDACTED as ku,readsDalSecretCopy as _u,redactContent as Mu,redactDalSecrets as Iu,shellPathCandidates as Su}from"./credentials.js";import{GUARD_MODE_ENV as Gu,savedGuardMode as Ou,saveGuardMode as Nu,shouldAskGuardMode as Pu,startupGuardMode as Tu}from"./mode.js";import{installingManager as Uu,wrongPackageManager as Ru}from"./package-manager.js";import{reviewBashCommand as xu,suspicionFor as Hu}from"./review.js";import{createWorkspaceGate as Lu,modifiedDirectory as ju}from"./workspace.js";const P=new Set;function T(u,a){if(u.toolName!=="bash"&&u.toolName!=="powershell")return;const s=u.input;if(typeof s.command!="string")return;const r=iu(s.command,a);if(r)return{block:!0,reason:e("dal-guard\uFF1A\u63D0\u4EA4\u8BF4\u660E\u6587\u4EF6 {file} \u628A\u53E6\u4E00\u4E2A\u4EA7\u54C1\u7684\u52A9\u624B\uFF08Claude\u3001Codex\u3001Copilot \u7B49\uFF09\u5199\u6210\u4E86\u5171\u540C\u4F5C\u8005\u3002\u4F60\u662F DAL Code\uFF1A\u628A\u90A3\u884C\u6539\u6210 {trailer} \u6216\u5220\u6389\uFF0C\u518D\u63D0\u4EA4\u3002").replace("{file}",r).replace("{trailer}",O)};const o=nu(s.command);o!==void 0&&(s.command=o,P.add(u.toolCallId))}l(T,"de"),n(T,"checkCommitAttribution");function b(u){try{return G(u)}catch{try{return X(G(K(u)),J(u))}catch{return u}}}l(b,"v"),n(b,"realPathBestEffort");const E=n(u=>a=>u.test(a),"has"),zu=[{id:"sudo",label:e("\u7279\u6743\u6267\u884C\uFF08sudo/doas\uFF09"),test:E(/(^|[;&|\n]\s*)(sudo|doas)\s/)},{id:"force-push",label:e("\u5F3A\u5236\u63A8\u9001\u5C06\u6539\u5199\u8FDC\u7A0B\u5386\u53F2"),test:E(/git\s+push\b[^;&|]*(--force\b|--force-with-lease\b|\s-f\b)/)},{id:"hard-reset",label:e("\u786C\u91CD\u7F6E\u4F1A\u4E22\u5F03\u672C\u5730\u6539\u52A8"),test:E(/git\s+reset\b[^;&|]*--hard/)},{id:"git-clean",label:e("git clean \u4F1A\u5220\u9664\u672A\u8DDF\u8E2A\u6587\u4EF6"),test:E(/git\s+clean\b[^;&|]*(-[a-z]*f|--force)/)},{id:"pipe-to-shell",label:e("\u5C06\u4E0B\u8F7D\u5185\u5BB9\u76F4\u63A5\u7BA1\u9053\u6267\u884C"),test:E(/(curl|wget)\b[^;&|]*\|\s*(ba|z|da|fi)?sh\b/)},{id:"exec-download",label:e("\u6267\u884C\u4E0B\u8F7D\u7684\u811A\u672C"),test:E(/\b(ba|z|da|fi)?sh\s+<\(\s*(curl|wget)\b|eval\b[^;&|\n]*\$\(\s*(curl|wget)\b/)},{id:"recursive-perms",label:e("\u9012\u5F52\u4FEE\u6539\u6743\u9650/\u5C5E\u4E3B"),test:E(/(chmod|chown)\b[^;&|]*-[a-zA-Z]*R/)},{id:"publish",label:e("\u53D1\u5E03\u8F6F\u4EF6\u5305"),test:E(/(npm|pnpm|yarn)\s+publish\b/)},{id:"kill",label:e("\u6309\u540D\u79F0\u7ED3\u675F\u8FDB\u7A0B"),test:E(/(^|[;&|\n]\s*)(killall|pkill)\s/)},{id:"disk",label:e("\u5E95\u5C42\u78C1\u76D8\u64CD\u4F5C"),test:E(/(^|[;&|\n]\s*)(dd|mkfs\w*|diskutil|fdisk)\s/)}];function y(u){return zu.find(a=>a.test(u))}l(y,"ce"),n(y,"riskForBash");function w(u,a){const s=b(ru(u,a)),r=b(Q(a)),o=Y(r,s);return o===".."||o.startsWith(`..${uu}`)||Z(o)}l(w,"fe"),n(w,"pathOutsideProject");function v(u,a){if(u.toolName.startsWith("mcp__")){const s=u.toolName.split("__")[1]||"unknown",r=JSON.stringify(u.input??{});return{ruleId:`mcp:${s}`,title:`${e("\u7B2C\u4E09\u65B9 MCP \u5DE5\u5177\u8C03\u7528\uFF08")}${s}${e("\uFF09")}`,detail:`${u.toolName} ${r.length>200?`${r.slice(0,200)}\u2026`:r}`}}if(u.toolName==="bash"){const s=String(u.input.command??""),r=y(s);return r?{ruleId:`bash:${r.id}`,title:r.label,detail:s}:void 0}if(u.toolName==="edit"||u.toolName==="write"){const s=String(u.input.path??u.input.file_path??"");if(s&&w(s,a))return{ruleId:`${u.toolName}:outside-project`,title:e("\u9879\u76EE\u76EE\u5F55\u4E4B\u5916\u7684\u6587\u4EF6\u6539\u52A8"),detail:s}}}l(v,"me"),n(v,"classify");async function U(u,a){if(u.toolName!=="bash")return;const s=String(u.input.command??""),r=await Du(s,a);if(r)return{ruleId:`bash:jev-${r.suspicion.id}`,title:`${e("jev \u590D\u6838\u5224\u5B9A\u53EF\u7591")} (${Math.round(r.confidence*100)}%)`,detail:s}}l(U,"pe"),n(U,"secondOpinion");const Wu=n(()=>e("\u4EC5\u672C\u6B21\u5141\u8BB8"),"allowOnce"),Vu=n(()=>e("\u672C\u6B21\u4F1A\u8BDD\u5185\u5141\u8BB8\uFF08\u540C\u7C7B\u64CD\u4F5C\uFF09"),"allowSession"),qu=n(()=>e("\u62D2\u7EDD"),"deny"),R=Symbol.for("dalcode.guard.state"),x=globalThis;x[R]??={mode:"default",sessionAllows:new Set};const d=x[R];function p(u){d.mode=u,Au(u)}l(p,"k"),n(p,"setGuardMode");function H(){d.escalationApprover||(d.escalationApprover=su(()=>{if(!(d.mode!=="yolo"||C(process.env)))return{approved:!0,scope:"once"}}))}l(H,"ye"),n(H,"registerEscalationApprover");const B=d.sessionAllows;async function $(u,a,s,r,o,t=process.env,i){if(du(u,a))return{block:!0,reason:lu()};const F=Fu(u,a);if(F)return{block:!0,reason:Eu(F)};const c=T(u,a);if(c)return c;const m=Cu(u,a);if(m)return{block:!0,reason:m};if(d.mode==="yolo"||C(t))return;const A=v(u,a)??await U(u,a);if(!A||B.has(A.ruleId))return;if(!s||!r)return{block:!0,reason:`${e('dal-guard\uFF1A"')}${A.title}${e('"\u9700\u8981\u4EA4\u4E92\u5F0F\u5BA1\u6279\uFF08')}${A.detail}${e("\uFF09\u3002\u8BF7\u5728\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u91CD\u8BD5\uFF0C\u6216\u7528 /guard yolo \u5173\u95ED\u5BA1\u6279\u95E8\u3002")}`};const g=o?au({session_id:o.sessionId,cwd:a,event:"PermissionRequest",status:"waiting_for_approval",pid:process.pid,tty:eu(),tool:u.toolName,tool_input:{command:A.detail},tool_use_id:u.toolCallId,productName:"dal"}):void 0;i?.({type:"permission_prompt",message:`DAL needs your permission to use ${u.toolName}`});const k=new AbortController,[h,_,M]=[Wu(),Vu(),qu()],z=r.select(`${e("\u9700\u8981\u5BA1\u6279\uFF1A")}${A.title} \u2014 ${A.detail}`,[h,_,M],{signal:k.signal}).then(f=>({surface:"terminal",choice:f})),W=g?g.decision.then(f=>f===void 0?new Promise(()=>{}):{surface:"halo",choice:f==="allow"?h:M}):new Promise(()=>{}),I=await Promise.race([z,W]);I.surface==="halo"?k.abort():g?.cancel();const S=I.choice;if(S!==h){if(S===_){B.add(A.ruleId);return}return{block:!0,reason:`${e("dal-guard\uFF1A\u7528\u6237\u5DF2\u62D2\u7EDD\uFF08")}${A.title}${e("\uFF09\u3002")}`}}}l($,"Ce"),n($,"evaluateToolCall");async function L(u){const a=e("\u5168\u81EA\u52A8\uFF1A\u4E0D\u518D\u8BE2\u95EE\uFF0C\u53EA\u62E6\u622A\u7834\u574F\u6027\u547D\u4EE4\uFF08\u63A8\u8350\u719F\u6089\u7684\u7528\u6237\uFF09"),s=e("\u6BCF\u6B21\u8BE2\u95EE\uFF1A\u9AD8\u98CE\u9669\u64CD\u4F5C\u548C\u8D8A\u51FA\u6C99\u7BB1\u524D\u5148\u95EE\u6211"),r=await u.ui.select(e("\u9009\u62E9 dal \u7684\u5DE5\u4F5C\u65B9\u5F0F\uFF08\u4EE5\u540E\u53EF\u7528 /guard \u4FEE\u6539\uFF09"),[a,s]);if(r===void 0)return;const o=r===a?"yolo":"default";p(o);try{N(D(),o)}catch(t){u.ui.notify(`${e("\u4FDD\u5B58\u5931\u8D25\uFF1A")}${t instanceof Error?t.message:String(t)}`,"error");return}u.ui.notify(o==="yolo"?e("\u5DF2\u8BBE\u4E3A\u5168\u81EA\u52A8\u3002\u6539\u56DE\u6BCF\u6B21\u8BE2\u95EE\uFF1A/guard default save"):e("\u5DF2\u8BBE\u4E3A\u6BCF\u6B21\u8BE2\u95EE\u3002\u6539\u6210\u5168\u81EA\u52A8\uFF1A/guard yolo save"),"info")}l(L,"we"),n(L,"askGuardModeOnce");function j(u){u.registerFlag("yolo",{description:e("\u4EE5\u5168\u81EA\u52A8\u6A21\u5F0F\u542F\u52A8\uFF1A\u4E0D\u518D\u5F39\u51FA\u4EFB\u4F55\u5BA1\u6279\uFF08\u542B\u6C99\u7BB1\u8D8A\u6743\uFF09\uFF0C\u53EA\u62E6\u622A\u7834\u574F\u6027\u547D\u4EE4\u548C\u767B\u5F55\u51ED\u636E"),type:"boolean",default:!1}),H();let a="default";u.on("session_start",async(o,t)=>{if(a="default",d.started)return;d.started=!0;const i=u.getFlag("yolo")===!0;p(fu(D(),i)),o.reason==="startup"&&mu({agentDir:D(),mode:t.mode,hasUI:t.hasUI,flag:i,underDalCode:!!C(process.env),languageChosen:ou()})&&await L(t)}),u.on("before_agent_start",async()=>{if(!(d.mode===a||C(process.env)))return a=d.mode,{message:{customType:"dal-guard-mode",content:d.mode==="yolo"?e("[\u5168\u81EA\u52A8\u6A21\u5F0F] \u7528\u6237\u5F00\u542F\u4E86\u5168\u81EA\u52A8\uFF1A\u6240\u6709\u5BA1\u6279\uFF08\u5305\u62EC sandbox_escalation \u8D8A\u6743\uFF09\u90FD\u4F1A\u81EA\u52A8\u901A\u8FC7\uFF0C\u4E0D\u4F1A\u6709\u4EBA\u6765\u786E\u8BA4\u3002\u547D\u4EE4\u88AB\u6C99\u7BB1\u6321\u4F4F\u3001\u800C\u4EFB\u52A1\u786E\u5B9E\u9700\u8981\u65F6\uFF0C\u76F4\u63A5\u5E26 sandbox_escalation \u91CD\u8BD5\uFF0C\u4E0D\u8981\u505C\u4E0B\u6765\u95EE\u7528\u6237\u8981\u4E0D\u8981\u653E\u884C\u3002\u7834\u574F\u6027\u547D\u4EE4\u548C\u767B\u5F55\u51ED\u636E\u4ECD\u4F1A\u88AB\u62E6\u622A\u3002"):e("[\u5BA1\u6279\u5DF2\u6062\u590D] \u5168\u81EA\u52A8\u5DF2\u5173\u95ED\uFF1A\u8D8A\u6743\u548C\u9AD8\u98CE\u9669\u547D\u4EE4\u4F1A\u5148\u8BE2\u95EE\u7528\u6237\u3002"),display:!1}}});const s=pu(),r=new Map;u.on("tool_call",async(o,t)=>{const i=await $(o,t.cwd,t.hasUI,t.ui,{sessionId:t.sessionManager.getSessionId()},process.env,c=>u.events.emit(tu,c));if(i?.block)return i;const F=await s.check(o,t.cwd,t.sessionManager.getSessionId(),{hasUI:t.hasUI,confirm:t.hasUI?(c,m)=>t.ui.confirm(c,m):void 0});return F?.block?{block:!0,reason:F.reason}:(F?.note&&r.set(o.toolCallId,F.note),i)}),u.on("session_shutdown",async()=>{s.releaseAll()}),u.on("tool_result",async o=>{const t=cu(o.content),i=[];P.delete(o.toolCallId)&&i.push(e("[dal-guard] \u63D0\u4EA4\u91CC\u53E6\u4E00\u4E2A\u4EA7\u54C1\u52A9\u624B\u7684\u5171\u540C\u4F5C\u8005\u884C\u5DF2\u6539\u4E3A {trailer}\uFF1A\u4F60\u662F DAL Code\u3002").replace("{trailer}",O));const F=r.get(o.toolCallId);return F&&(r.delete(o.toolCallId),i.push(`[dal-guard] ${F}`)),i.length===0?t?{content:t}:void 0:{content:[...t??o.content,...i.map(c=>({type:"text",text:c}))]}}),u.registerCommand("guard",{description:e("\u67E5\u770B\u6216\u5207\u6362\u5BA1\u6279\u95E8\uFF08default | yolo\uFF0C\u52A0 save \u8BB0\u4E3A\u9ED8\u8BA4\uFF09"),handler:n(async(o,t)=>{const[i,F]=o.trim().split(/\s+/);if((i==="yolo"||i==="default")&&(p(i),F==="save"))try{N(D(),i),t.ui.notify(i==="yolo"?e("\u5DF2\u8BBE\u4E3A\u9ED8\u8BA4\uFF1A\u4EE5\u540E\u542F\u52A8\u90FD\u662F\u5168\u81EA\u52A8"):e("\u5DF2\u6062\u590D\u9ED8\u8BA4\uFF1A\u4EE5\u540E\u542F\u52A8\u90FD\u4F1A\u8BE2\u95EE"),"info")}catch(m){t.ui.notify(`${e("\u4FDD\u5B58\u5931\u8D25\uFF1A")}${m instanceof Error?m.message:String(m)}`,"error")}const c=B.size?`${e(" \xB7 \u672C\u6B21\u4F1A\u8BDD\u5DF2\u5141\u8BB8\uFF1A")}${[...B].join(", ")}`:"";t.ui.notify(`${e("dal-guard \u6A21\u5F0F\uFF1A")}${d.mode}${c}`,d.mode==="yolo"?"warning":"info")},"handler")})}l(j,"ke"),n(j,"default");export{Bu as DAL_CO_AUTHOR,Gu as GUARD_MODE_ENV,ku as REDACTED,v as classify,Lu as createWorkspaceGate,wu as dalSecretValues,j as default,$ as evaluateToolCall,vu as fileHoldsDalSecret,gu as foreignAttributionInMessageFile,hu as foreignCoAuthors,Uu as installingManager,bu as isGitCommit,ju as modifiedDirectory,$u as namesDalCredential,w as pathOutsideProject,_u as readsDalSecretCopy,Mu as redactContent,Iu as redactDalSecrets,xu as reviewBashCommand,yu as rewriteCommitAttribution,y as riskForBash,Nu as saveGuardMode,Ou as savedGuardMode,Su as shellPathCandidates,Pu as shouldAskGuardMode,Tu as startupGuardMode,Hu as suspicionFor,Ru as wrongPackageManager};
|
|
1
|
+
var J=Object.defineProperty;var d=(u,a)=>J(u,"name",{value:a,configurable:!0});var K=Object.defineProperty,i=d((u,a)=>K(u,"name",{value:a,configurable:!0}),"l");import{realpathSync as G}from"node:fs";import{basename as Z,dirname as Q,isAbsolute as X,join as Y,relative as uu,resolve as eu,sep as au}from"node:path";import{readBridgeConfig as p}from"@dalcode/dal-bridge/client";import{getOwnTty as ou,requestHaloApproval as tu}from"@dalcode/dal-halo";import{hasChosenLanguage as su,t as e}from"@dalcode/dal-pi-kit";import{DAL_HOOK_NOTIFICATION_CHANNEL as ru,getAgentDir as D,registerSandboxEscalationHandler as nu,resolveToCwd as iu,shellExecutionRefusal as lu}from"@earendil-works/pi-coding-agent";import{DAL_CO_AUTHOR as O,foreignAttributionInMessageFile as du,rewriteCommitAttribution as Fu}from"./attribution.js";import{credentialBlockReason as cu,namesDalCredential as Eu,readsDalSecretCopy as Au,redactContent as mu,secretCopyBlockReason as fu}from"./credentials.js";import{exportGuardMode as Cu,saveGuardMode as P,shouldAskGuardMode as pu,startupGuardMode as Du}from"./mode.js";import{wrongPackageManager as Bu}from"./package-manager.js";import{reviewBashCommand as gu}from"./review.js";import{createWorkspaceGate as hu}from"./workspace.js";import{DAL_CO_AUTHOR as bu,foreignAttributionInMessageFile as vu,foreignCoAuthors as yu,isGitCommit as wu,rewriteCommitAttribution as $u}from"./attribution.js";import{dalSecretValues as ku,fileHoldsDalSecret as _u,namesDalCredential as Iu,REDACTED as Mu,readsDalSecretCopy as Nu,redactContent as Su,redactDalSecrets as Gu,shellPathCandidates as Ou}from"./credentials.js";import{GUARD_MODE_ENV as Pu,savedGuardMode as Ru,saveGuardMode as Tu,shouldAskGuardMode as xu,startupGuardMode as Uu}from"./mode.js";import{installingManager as ju,wrongPackageManager as Hu}from"./package-manager.js";import{reviewBashCommand as Lu,suspicionFor as zu}from"./review.js";import{createWorkspaceGate as Wu,modifiedDirectory as Vu}from"./workspace.js";const R=new Set;function T(u,a){if(u.toolName!=="bash"&&u.toolName!=="powershell")return;const o=u.input;if(typeof o.command!="string")return;const t=du(o.command,a);if(t)return{block:!0,reason:e("dal-guard\uFF1A\u63D0\u4EA4\u8BF4\u660E\u6587\u4EF6 {file} \u628A\u53E6\u4E00\u4E2A\u4EA7\u54C1\u7684\u52A9\u624B\uFF08Claude\u3001Codex\u3001Copilot \u7B49\uFF09\u5199\u6210\u4E86\u5171\u540C\u4F5C\u8005\u3002\u4F60\u662F DAL Code\uFF1A\u628A\u90A3\u884C\u6539\u6210 {trailer} \u6216\u5220\u6389\uFF0C\u518D\u63D0\u4EA4\u3002").replace("{file}",t).replace("{trailer}",O)};const s=Fu(o.command);s!==void 0&&(o.command=s,R.add(u.toolCallId))}d(T,"ce"),i(T,"checkCommitAttribution");function v(u){try{return G(u)}catch{try{return Y(G(Q(u)),Z(u))}catch{return u}}}d(v,"G"),i(v,"realPathBestEffort");const A=i(u=>a=>u.test(a),"has"),qu=[{id:"sudo",level:"high",label:e("\u7279\u6743\u6267\u884C\uFF08sudo/doas\uFF09"),test:A(/(^|[;&|\n]\s*)(sudo|doas)\s/)},{id:"force-push",level:"high",label:e("\u5F3A\u5236\u63A8\u9001\u5C06\u6539\u5199\u8FDC\u7A0B\u5386\u53F2"),test:A(/git\s+push\b[^;&|]*(--force\b|--force-with-lease\b|\s-f\b)/)},{id:"hard-reset",level:"high",label:e("\u786C\u91CD\u7F6E\u4F1A\u4E22\u5F03\u672C\u5730\u6539\u52A8"),test:A(/git\s+reset\b[^;&|]*--hard/)},{id:"git-clean",level:"high",label:e("git clean \u4F1A\u5220\u9664\u672A\u8DDF\u8E2A\u6587\u4EF6"),test:A(/git\s+clean\b[^;&|]*(-[a-z]*f|--force)/)},{id:"pipe-to-shell",level:"high",label:e("\u5C06\u4E0B\u8F7D\u5185\u5BB9\u76F4\u63A5\u7BA1\u9053\u6267\u884C"),test:A(/(curl|wget)\b[^;&|]*\|\s*(ba|z|da|fi)?sh\b/)},{id:"exec-download",level:"high",label:e("\u6267\u884C\u4E0B\u8F7D\u7684\u811A\u672C"),test:A(/\b(ba|z|da|fi)?sh\s+<\(\s*(curl|wget)\b|eval\b[^;&|\n]*\$\(\s*(curl|wget)\b/)},{id:"recursive-perms",label:e("\u9012\u5F52\u4FEE\u6539\u6743\u9650/\u5C5E\u4E3B"),test:A(/(chmod|chown)\b[^;&|]*-[a-zA-Z]*R/)},{id:"publish",label:e("\u53D1\u5E03\u8F6F\u4EF6\u5305"),test:A(/(npm|pnpm|yarn)\s+publish\b/)},{id:"kill",label:e("\u6309\u540D\u79F0\u7ED3\u675F\u8FDB\u7A0B"),test:A(/(^|[;&|\n]\s*)(killall|pkill)\s/)},{id:"disk",level:"high",label:e("\u5E95\u5C42\u78C1\u76D8\u64CD\u4F5C"),test:A(/(^|[;&|\n]\s*)(dd|mkfs\w*|diskutil|fdisk)\s/)}];function y(u){return qu.find(a=>a.test(u))}d(y,"me"),i(y,"riskForBash");function w(u,a){const o=v(iu(u,a)),t=v(eu(a)),s=uu(t,o);return s===".."||s.startsWith(`..${au}`)||X(s)}d(w,"pe"),i(w,"pathOutsideProject");function $(u,a){if(u.toolName.startsWith("mcp__")){const o=u.toolName.split("__")[1]||"unknown",t=JSON.stringify(u.input??{});return{ruleId:`mcp:${o}`,title:`${e("\u7B2C\u4E09\u65B9 MCP \u5DE5\u5177\u8C03\u7528\uFF08")}${o}${e("\uFF09")}`,detail:`${u.toolName} ${t.length>200?`${t.slice(0,200)}\u2026`:t}`,level:"medium"}}if(u.toolName==="bash"){const o=String(u.input.command??""),t=y(o);return t?{ruleId:`bash:${t.id}`,title:t.label,detail:o,level:t.level??"medium"}:void 0}if(u.toolName==="edit"||u.toolName==="write"){const o=String(u.input.path??u.input.file_path??"");if(o&&w(o,a))return{ruleId:`${u.toolName}:outside-project`,title:e("\u9879\u76EE\u76EE\u5F55\u4E4B\u5916\u7684\u6587\u4EF6\u6539\u52A8"),detail:o,level:"medium"}}}d($,"ge"),i($,"classify");async function x(u,a){if(u.toolName!=="bash")return;const o=String(u.input.command??""),t=await gu(o,a);if(t)return{ruleId:`bash:jev-${t.suspicion.id}`,title:`${e("jev \u590D\u6838\u5224\u5B9A\u53EF\u7591")} (${Math.round(t.confidence*100)}%)`,detail:o,level:"medium"}}d(x,"he"),i(x,"secondOpinion");const Ju=i(()=>e("\u4EC5\u672C\u6B21\u5141\u8BB8"),"allowOnce"),Ku=i(()=>e("\u672C\u6B21\u4F1A\u8BDD\u5185\u5141\u8BB8\uFF08\u540C\u7C7B\u64CD\u4F5C\uFF09"),"allowSession"),Zu=i(()=>e("\u62D2\u7EDD"),"deny"),U=Symbol.for("dalcode.guard.state"),j=globalThis;j[U]??={mode:"default",sessionAllows:new Set};const F=j[U];function B(u){F.mode=u,Cu(u)}d(B,"A"),i(B,"setGuardMode");function H(){F.escalationApprover||(F.escalationApprover=nu(()=>{if(!(F.mode!=="yolo"||p(process.env)))return{approved:!0,scope:"once"}}))}d(H,"we"),i(H,"registerEscalationApprover");const g=F.sessionAllows;async function k(u,a,o,t,s,r=process.env,n){if(Eu(u,a))return{block:!0,reason:cu()};const c=Au(u,a);if(c)return{block:!0,reason:fu(c)};const E=T(u,a);if(E)return E;const m=Bu(u,a);if(m)return{block:!0,reason:m};const f=await L(u,a);if(f)return f;if(F.mode==="yolo"||p(r))return;const l=$(u,a)??await x(u,a);if(!l||g.has(l.ruleId))return;if(!o||!t)return{block:!0,reason:`${e('dal-guard\uFF1A"')}${l.title}${e('"\u9700\u8981\u4EA4\u4E92\u5F0F\u5BA1\u6279\uFF08')}${l.detail}${e("\uFF09\u3002\u8BF7\u5728\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u91CD\u8BD5\uFF0C\u6216\u7528 /guard yolo \u5173\u95ED\u5BA1\u6279\u95E8\u3002")}`};const h=s?tu({session_id:s.sessionId,cwd:a,event:"PermissionRequest",status:"waiting_for_approval",pid:process.pid,tty:ou(),tool:u.toolName,tool_input:{command:l.detail},tool_use_id:u.toolCallId,productName:"dal"}):void 0;n?.({type:"permission_prompt",message:`DAL needs your permission to use ${u.toolName}`});const _=new AbortController,[b,I,M]=[Ju(),Ku(),Zu()],V=t.select(`${e("\u9700\u8981\u5BA1\u6279\uFF1A")}${l.title} \u2014 ${l.detail}`,[b,I,M],{signal:_.signal,approval:{source:"guard",toolCallId:u.toolCallId,toolName:u.toolName,args:u.input,risk:{level:l.level,reason:l.title,ruleId:l.ruleId},title:l.title,description:l.detail,options:["allow_once","allow_session","deny"]}}).then(C=>({surface:"terminal",choice:C})),q=h?h.decision.then(C=>C===void 0?new Promise(()=>{}):{surface:"halo",choice:C==="allow"?b:M}):new Promise(()=>{}),N=await Promise.race([V,q]);N.surface==="halo"?_.abort():h?.cancel();const S=N.choice;if(S!==b){if(S===I){g.add(l.ruleId);return}return{block:!0,reason:`${e("dal-guard\uFF1A\u7528\u6237\u5DF2\u62D2\u7EDD\uFF08")}${l.title}${e("\uFF09\u3002")}`}}}d(k,"ke"),i(k,"evaluateToolCall");const Qu=new Set(["bash","powershell"]);async function L(u,a){if(!Qu.has(u.toolName))return;const o=u.input.command;if(typeof o!="string"||!o.trim())return;const t=await lu({toolName:u.toolName,command:o,cwd:a});if(t!==void 0)return{block:!0,reason:`${e("dal-guard\uFF1A\u8FD9\u6761\u547D\u4EE4\u4F1A\u88AB\u5371\u9669\u547D\u4EE4\u62E6\u622A\u6321\u4E0B\uFF0C\u6CA1\u6709\u8FD0\u884C\uFF0C\u4E5F\u4E0D\u518D\u8BF7\u4F60\u786E\u8BA4\u3002")}
|
|
2
|
+
${t}`}}d(L,"_e"),i(L,"destructiveCommandRefusal");async function z(u){const a=e("\u5168\u81EA\u52A8\uFF1A\u4E0D\u518D\u8BE2\u95EE\uFF0C\u53EA\u62E6\u622A\u7834\u574F\u6027\u547D\u4EE4\uFF08\u63A8\u8350\u719F\u6089\u7684\u7528\u6237\uFF09"),o=e("\u6BCF\u6B21\u8BE2\u95EE\uFF1A\u9AD8\u98CE\u9669\u64CD\u4F5C\u548C\u8D8A\u51FA\u6C99\u7BB1\u524D\u5148\u95EE\u6211"),t=await u.ui.select(e("\u9009\u62E9 dal \u7684\u5DE5\u4F5C\u65B9\u5F0F\uFF08\u4EE5\u540E\u53EF\u7528 /guard \u4FEE\u6539\uFF09"),[a,o]);if(t===void 0)return;const s=t===a?"yolo":"default";B(s);try{P(D(),s)}catch(r){u.ui.notify(`${e("\u4FDD\u5B58\u5931\u8D25\uFF1A")}${r instanceof Error?r.message:String(r)}`,"error");return}u.ui.notify(s==="yolo"?e("\u5DF2\u8BBE\u4E3A\u5168\u81EA\u52A8\u3002\u6539\u56DE\u6BCF\u6B21\u8BE2\u95EE\uFF1A/guard default save"):e("\u5DF2\u8BBE\u4E3A\u6BCF\u6B21\u8BE2\u95EE\u3002\u6539\u6210\u5168\u81EA\u52A8\uFF1A/guard yolo save"),"info")}d(z,"Ie"),i(z,"askGuardModeOnce");function W(u){u.registerFlag("yolo",{description:e("\u4EE5\u5168\u81EA\u52A8\u6A21\u5F0F\u542F\u52A8\uFF1A\u4E0D\u518D\u5F39\u51FA\u4EFB\u4F55\u5BA1\u6279\uFF08\u542B\u6C99\u7BB1\u8D8A\u6743\uFF09\uFF0C\u53EA\u62E6\u622A\u7834\u574F\u6027\u547D\u4EE4\u548C\u767B\u5F55\u51ED\u636E"),type:"boolean",default:!1}),H();let a="default";u.on("session_start",async(s,r)=>{if(a="default",F.started)return;F.started=!0;const n=u.getFlag("yolo")===!0;B(Du(D(),n)),s.reason==="startup"&&pu({agentDir:D(),mode:r.mode,hasUI:r.hasUI,flag:n,underDalCode:!!p(process.env),languageChosen:su()})&&await z(r)}),u.on("before_agent_start",async()=>{if(!(F.mode===a||p(process.env)))return a=F.mode,{message:{customType:"dal-guard-mode",content:F.mode==="yolo"?e("[\u5168\u81EA\u52A8\u6A21\u5F0F] \u7528\u6237\u5F00\u542F\u4E86\u5168\u81EA\u52A8\uFF1A\u6240\u6709\u5BA1\u6279\uFF08\u5305\u62EC sandbox_escalation \u8D8A\u6743\uFF09\u90FD\u4F1A\u81EA\u52A8\u901A\u8FC7\uFF0C\u4E0D\u4F1A\u6709\u4EBA\u6765\u786E\u8BA4\u3002\u547D\u4EE4\u88AB\u6C99\u7BB1\u6321\u4F4F\u3001\u800C\u4EFB\u52A1\u786E\u5B9E\u9700\u8981\u65F6\uFF0C\u76F4\u63A5\u5E26 sandbox_escalation \u91CD\u8BD5\uFF0C\u4E0D\u8981\u505C\u4E0B\u6765\u95EE\u7528\u6237\u8981\u4E0D\u8981\u653E\u884C\u3002\u7834\u574F\u6027\u547D\u4EE4\u548C\u767B\u5F55\u51ED\u636E\u4ECD\u4F1A\u88AB\u62E6\u622A\u3002"):e("[\u5BA1\u6279\u5DF2\u6062\u590D] \u5168\u81EA\u52A8\u5DF2\u5173\u95ED\uFF1A\u8D8A\u6743\u548C\u9AD8\u98CE\u9669\u547D\u4EE4\u4F1A\u5148\u8BE2\u95EE\u7528\u6237\u3002"),display:!1}}});const o=hu(),t=new Map;u.on("tool_call",async(s,r)=>{const n=await k(s,r.cwd,r.hasUI,r.ui,{sessionId:r.sessionManager.getSessionId()},process.env,E=>u.events.emit(ru,E));if(n?.block)return n;const c=await o.check(s,r.cwd,r.sessionManager.getSessionId(),{hasUI:r.hasUI,confirm:r.hasUI?(E,m,f)=>r.ui.confirm(E,m,f?{approval:f}:void 0):void 0});return c?.block?{block:!0,reason:c.reason}:(c?.note&&t.set(s.toolCallId,c.note),n)}),u.on("session_shutdown",async()=>{o.releaseAll()}),u.on("tool_result",async s=>{const r=mu(s.content),n=[];R.delete(s.toolCallId)&&n.push(e("[dal-guard] \u63D0\u4EA4\u91CC\u53E6\u4E00\u4E2A\u4EA7\u54C1\u52A9\u624B\u7684\u5171\u540C\u4F5C\u8005\u884C\u5DF2\u6539\u4E3A {trailer}\uFF1A\u4F60\u662F DAL Code\u3002").replace("{trailer}",O));const c=t.get(s.toolCallId);return c&&(t.delete(s.toolCallId),n.push(`[dal-guard] ${c}`)),n.length===0?r?{content:r}:void 0:{content:[...r??s.content,...n.map(E=>({type:"text",text:E}))]}}),u.registerCommand("guard",{description:e("\u67E5\u770B\u6216\u5207\u6362\u5BA1\u6279\u95E8\uFF08default | yolo\uFF0C\u52A0 save \u8BB0\u4E3A\u9ED8\u8BA4\uFF09"),handler:i(async(s,r)=>{const[n,c]=s.trim().split(/\s+/);if((n==="yolo"||n==="default")&&(B(n),c==="save"))try{P(D(),n),r.ui.notify(n==="yolo"?e("\u5DF2\u8BBE\u4E3A\u9ED8\u8BA4\uFF1A\u4EE5\u540E\u542F\u52A8\u90FD\u662F\u5168\u81EA\u52A8"):e("\u5DF2\u6062\u590D\u9ED8\u8BA4\uFF1A\u4EE5\u540E\u542F\u52A8\u90FD\u4F1A\u8BE2\u95EE"),"info")}catch(m){r.ui.notify(`${e("\u4FDD\u5B58\u5931\u8D25\uFF1A")}${m instanceof Error?m.message:String(m)}`,"error")}const E=g.size?`${e(" \xB7 \u672C\u6B21\u4F1A\u8BDD\u5DF2\u5141\u8BB8\uFF1A")}${[...g].join(", ")}`:"";r.ui.notify(`${e("dal-guard \u6A21\u5F0F\uFF1A")}${F.mode}${E}`,F.mode==="yolo"?"warning":"info")},"handler")})}d(W,"$e"),i(W,"default");export{bu as DAL_CO_AUTHOR,Pu as GUARD_MODE_ENV,Mu as REDACTED,$ as classify,Wu as createWorkspaceGate,ku as dalSecretValues,W as default,k as evaluateToolCall,_u as fileHoldsDalSecret,vu as foreignAttributionInMessageFile,yu as foreignCoAuthors,ju as installingManager,wu as isGitCommit,Vu as modifiedDirectory,Iu as namesDalCredential,w as pathOutsideProject,Nu as readsDalSecretCopy,Su as redactContent,Gu as redactDalSecrets,Lu as reviewBashCommand,$u as rewriteCommitAttribution,y as riskForBash,Tu as saveGuardMode,Ru as savedGuardMode,Ou as shellPathCandidates,xu as shouldAskGuardMode,Uu as startupGuardMode,zu as suspicionFor,Hu as wrongPackageManager};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var B=Object.defineProperty;var o=(u,
|
|
2
|
-
`),{note:`${
|
|
1
|
+
var B=Object.defineProperty;var o=(u,t)=>B(u,"name",{value:t,configurable:!0});var g=Object.defineProperty,c=o((u,t)=>g(u,"name",{value:t,configurable:!0}),"d");import{dirname as E}from"node:path";import{t as n}from"@dalcode/dal-pi-kit";import{claimWorkspace as k,releaseWorkspace as y,resolveToCwd as b,shellCommandDirectory as v}from"@earendil-works/pi-coding-agent";import{isGitCommit as $}from"./attribution.js";const N=new Set(["ls","cat","head","tail","wc","grep","rg","find","echo","pwd","stat","file","which","du","df","sort","uniq","jq","tree","less","diff","true","date","cd"]),W=new Set(["status","log","diff","show","branch","rev-parse","remote","blame","ls-files","describe","shortlog","reflog","fetch"]);function C(u){return u.trim().split(/\s+/).filter(Boolean)}o(C,"W"),c(C,"words");function A(u){if(/(^|[^>&0-9])>{1,2}(?!\s*\/dev\/null)/.test(u))return!1;const t=C(u).filter(e=>!/^\w+=/.test(e)),r=t[0];if(!r)return!0;if(r==="git"){const e=t.slice(1).find((i,d,l)=>!i.startsWith("-")&&l[d-1]!=="-C");return e==="worktree"?t.includes("list"):e==="stash"?t.includes("list")||t.includes("show"):e!==void 0&&W.has(e)}return r==="sed"?!t.some(e=>e.startsWith("-i")):N.has(r)}o(A,"$"),c(A,"segmentReadsOnly");function f(u,t){if(u.toolName==="write"||u.toolName==="edit"){const e=u.input,i=e.path??e.file_path;return typeof i=="string"&&i?E(b(i,t)):void 0}if(u.toolName!=="bash"&&u.toolName!=="powershell")return;const r=u.input.command;if(!(typeof r!="string"||!r.trim())&&!r.split(/&&|\|\||[;|\n]/).every(A))return v(r,t)}o(f,"A"),c(f,"modifiedDirectory");function p(u,t){return n("\u5DE5\u4F5C\u533A {worktree} \u6B63\u88AB\u53E6\u4E00\u4E2A dal \u4F1A\u8BDD\u4F7F\u7528\uFF08\u8FDB\u7A0B {pid}@{host}\uFF0C\u4F1A\u8BDD {session}\uFF0C{started} \u5F00\u59CB\uFF09\u3002").replace("{worktree}",t).replace("{pid}",String(u.pid)).replace("{host}",u.host).replace("{session}",u.sessionId.slice(0,8)).replace("{started}",u.startedAt)}o(p,"I"),c(p,"describeHolder");function h(){const u=new Set,t=new Set,r=new Set;return{async check(e,i,d,l){const m=f(e,i);if(!m)return;const s=k(m,d);if(!s)return;if(!s.heldBy){u.add(s.gitDir);return}if(t.has(s.gitDir))return;const a=p(s.heldBy,s.worktree??s.gitDir),F=e.input.command,w=typeof F=="string"&&$(F);if(l.hasUI&&l.confirm){const D=`${a}${n("\u4E24\u4E2A\u4F1A\u8BDD\u540C\u65F6\u6539\u52A8\u4F1A\u4E92\u76F8\u8986\u76D6\u3002\u4ECD\u8981\u5728\u8FD9\u91CC\u6539\u52A8\u5E76\u63D0\u4EA4\u5417\uFF1F")}`;if(await l.confirm(n("\u5DE5\u4F5C\u533A\u88AB\u5360\u7528"),D,{source:"workspace",toolCallId:e.toolCallId,toolName:e.toolName,args:e.input,risk:{level:"medium",reason:a,ruleId:"workspace:occupied"},title:n("\u5DE5\u4F5C\u533A\u88AB\u5360\u7528"),description:D,options:["allow_session","deny"]})){t.add(s.gitDir);return}return{block:!0,reason:`${a}${n("\u7528\u6237\u6CA1\u6709\u540C\u610F\u5728\u8FD9\u91CC\u6539\u52A8\u3002\u505C\u4E0B\u6765\u544A\u8BC9\u7528\u6237\u3002")}`}}if(w)return{block:!0,reason:`${a}${n("\u6CA1\u6709\u7528\u6237\u786E\u8BA4\uFF0C\u62D2\u7EDD\u5728\u8FD9\u91CC\u63D0\u4EA4\u3002\u505C\u4E0B\u6765\u544A\u8BC9\u7528\u6237\uFF0C\u7531\u7528\u6237\u51B3\u5B9A\u3002")}`};if(!r.has(s.gitDir))return r.add(s.gitDir),process.stderr.write(`dal: ${a}
|
|
2
|
+
`),{note:`${a}${n("\u8FD9\u6B21\u6539\u52A8\u5DF2\u6267\u884C\uFF1B\u544A\u8BC9\u7528\u6237\uFF0C\u63D0\u4EA4\u524D\u9700\u8981\u7528\u6237\u786E\u8BA4\u3002")}`}},releaseAll(){for(const e of u)y(e);u.clear()}}}o(h,"x"),c(h,"createWorkspaceGate");export{h as createWorkspaceGate,p as describeHolder,f as modifiedDirectory};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-interactive",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Terminal-UI conveniences adopted from pi's example extensions: the questionnaire tool (the model asks you questions), /handoff (carry context into a new session) and interactive ! commands (vim, git rebase -i, htop). Active only in the TUI; stands down under DAL Code.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
]
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
23
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
24
24
|
"typebox": "1.3.7"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-lang",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
-
"@dalcode/dal-bridge": "1.0.
|
|
20
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
21
|
+
"@dalcode/dal-bridge": "1.0.43"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-learn",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Self-evolution for DAL: lessons learned from earlier sessions (project and personal), a project map of verified commands and locations, effect tracking, and skill proposals for recurring procedures (/lessons).",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
]
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
28
|
+
"@dalcode/dal-pi-kit": "1.0.43"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-lsp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
]
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dalcode/dal-bridge": "1.0.
|
|
24
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
23
|
+
"@dalcode/dal-bridge": "1.0.43",
|
|
24
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
25
25
|
"cross-spawn": "7.0.6",
|
|
26
26
|
"typebox": "1.3.7",
|
|
27
27
|
"typescript": "5.9.3",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
]
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@dalcode/dal-bridge": "1.0.
|
|
31
|
-
"@dalcode/dal-guard": "1.0.
|
|
32
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
33
|
-
"@dalcode/deepailab": "1.0.
|
|
30
|
+
"@dalcode/dal-bridge": "1.0.43",
|
|
31
|
+
"@dalcode/dal-guard": "1.0.43",
|
|
32
|
+
"@dalcode/dal-pi-kit": "1.0.43",
|
|
33
|
+
"@dalcode/deepailab": "1.0.43",
|
|
34
34
|
"cross-spawn": "7.0.6"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|