pi-ptc-subagents 7.9.1 → 7.9.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/CHANGELOG.md +17 -0
- package/dist/index.js +7 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [7.9.2] - 2026-11-02
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **The upgrade notice now reaches the screen in the TUI** (pi extension): pi's
|
|
13
|
+
status slot is global, and every status line renders the same
|
|
14
|
+
`lastStatusMessage` field, so any extension that notifies afterwards — the
|
|
15
|
+
ponytail, session-title and tok-speed extensions all do — overwrote the
|
|
16
|
+
notice before it was ever drawn. In a captured terminal byte stream the
|
|
17
|
+
notice text appeared 0 times, while the sentinel recorded the version as
|
|
18
|
+
"seen". The TUI now delivers the notice through the keyed widget area above
|
|
19
|
+
the editor (`ctx.ui.setWidget("ptc-upgrade", …)`, at most 10 lines, pi's
|
|
20
|
+
`MAX_WIDGET_LINES`), which no other extension can overwrite; `notify` is
|
|
21
|
+
kept for the rpc and print modes, where the host renders the event itself.
|
|
22
|
+
Measured on a real pi 1.4.0 TUI: a later notification takes the status slot
|
|
23
|
+
while the widget lines stay on screen.
|
|
24
|
+
|
|
8
25
|
## [7.9.1] - 2026-11-02
|
|
9
26
|
|
|
10
27
|
### Fixed
|
package/dist/index.js
CHANGED
|
@@ -29,12 +29,13 @@ findings/files_touched/usage may be omitted when empty.
|
|
|
29
29
|
`)}async function yt(e,t){let n=t.textBudgetChars??12e3;if(e.kind===`search`){let r=Math.min(ct.max,Math.max(ct.min,e.count??10));if(!t.quota.tryAcquire())return{ok:!1,error:`搜索配额已用尽(每会话配额,0 = 不限)`};let i=await t.provider.search(e.query,{count:r});return i.ok?(t.quota.release(i.value.length>0),t.memory.remember(e.query,i.value),i.value.length===0?{ok:!0,text:`「${e.query}」没有命中。`}:{ok:!0,text:L(vt(i.value,n))}):(t.quota.release(!1),{ok:!1,error:`search 失败(HTTP ${i.status}):${i.error}`})}if(e.kind===`open`){let r=t.memory.lookup(e.url);if(r!==void 0)return{ok:!0,text:L(`(记忆命中,未发请求)\n${r.slice(0,n)}`)};if(!t.quota.tryAcquire())return{ok:!1,error:`搜索配额已用尽(每会话配额,0 = 不限)`};await gt(e.url);let i=await t.provider.open(e.url);return i.ok?(t.quota.release(i.value.length>0),t.memory.storeText(e.url,i.value),{ok:!0,text:L(i.value.slice(0,n))}):(t.quota.release(!1),{ok:!1,error:`open 失败(HTTP ${i.status}):${i.error}`})}let r;try{r=new RegExp(e.pattern,`i`)}catch{return{ok:!1,error:`非法正则:${e.pattern}`}}let i=await bt(e.url,t);if(!i.ok)return i;let a=i.text.split(`
|
|
30
30
|
`).map((e,t)=>({line:e,index:t})).filter(({line:e})=>r.test(e));return{ok:!0,text:L(a.length>0?a.slice(0,50).map(({line:e,index:t})=>`${t+1}: ${e}`).join(`
|
|
31
31
|
`):`(页内无匹配行)`).slice(0,n)}}async function bt(e,t){let n=t.memory.lookup(e);if(n!==void 0)return{ok:!0,text:n};if(!t.quota.tryAcquire())return{ok:!1,error:`搜索配额已用尽(每会话配额,0 = 不限)`};await gt(e);let r=await t.provider.open(e);return r.ok?(t.quota.release(r.value.length>0),t.memory.storeText(e,r.value),{ok:!0,text:r.value}):(t.quota.release(!1),{ok:!1,error:`open 失败(HTTP ${r.status}):${r.error}`})}const xt=_.Object({action:_.Union([_.Literal(`search`),_.Literal(`open`),_.Literal(`find`)]),query:_.Optional(_.String({description:`search:搜索词`})),url:_.Optional(_.String({description:`open/find:目标页面 url`})),pattern:_.Optional(_.String({description:`find:页内行匹配(正则)`})),count:_.Optional(_.Integer({minimum:1,maximum:50,description:`search:条数 1–50,默认 10`}))});function St(e){return{name:`web_ds_search`,label:`联网搜索`,description:`联网能力(三动作):search 概览(title/url/snippet)· open 抓整页 · find 页内行匹配。open/find 命中最近记忆则免费。配额按每进程计。`,parameters:xt,execute:async(t,n)=>{let r=n.action===`search`?{kind:`search`,query:n.query??``,count:n.count}:n.action===`open`?{kind:`open`,url:n.url??``}:{kind:`find`,url:n.url??``,pattern:n.pattern??``};if(r.kind===`search`&&r.query===``)return{content:[{type:`text`,text:`search 动作需要 query`}],details:void 0,isError:!0};if(r.kind!==`search`&&r.url===``)return{content:[{type:`text`,text:`${r.kind} 动作需要 url`}],details:void 0,isError:!0};let i=await yt(r,e);return{content:[{type:`text`,text:i.ok?i.text:i.error}],details:void 0,isError:!i.ok}}}}const q=`pi-ptc-subagents`,Ct=[`Added`,`Changed`,`Fixed`];function J(e){if(typeof e!=`string`||!/^\d+\.\d+\.\d+$/.test(e))return;let t=e.split(`.`).map(Number);return(t[0]??0)*0xe8d4a51000+(t[1]??0)*1e6+(t[2]??0)}function Y(e){let t=[];for(let n of e.split(/^## /m).slice(1)){let e=/^\[(\d+\.\d+\.\d+)\]/.exec(n)?.[1];if(!e)continue;let r=[],i=!1,a=[],o=()=>{a.length>0&&r.push(a.join(` `)),a=[]};for(let e of n.split(`
|
|
32
|
-
`)){let t=/^###\s+(.+)$/.exec(e);t?(o(),i=Ct.includes(t[1]?.trim()??``)):i&&(e.startsWith(`- `)?(o(),a=[e.slice(2).trim()]):a.length>0&&e.trim().length>0?a.push(e.trim()):o())}o(),t.push({version:e,bullets:r})}return t}function wt(e){let t=/^\*\*(.+?)\*\*/.exec(e);if(t)return It(
|
|
33
|
-
`)
|
|
32
|
+
`)){let t=/^###\s+(.+)$/.exec(e);t?(o(),i=Ct.includes(t[1]?.trim()??``)):i&&(e.startsWith(`- `)?(o(),a=[e.slice(2).trim()]):a.length>0&&e.trim().length>0?a.push(e.trim()):o())}o(),t.push({version:e,bullets:r})}return t}function wt(e){let t=/^\*\*(.+?)\*\*/.exec(e);if(t)return Lt(It(t[1]??``).replace(/\.$/,``));let n=/(?<!\d)\.(?=\s)/.exec(e);return Lt(It(n?e.slice(0,n.index+1):e).replace(/\.$/,``))}function Tt(e,t,n){let r=J(t),i=J(n);if(r===void 0||i===void 0)return[];let a=[];for(let t of e){let e=J(t.version);if(!(e===void 0||e<=r||e>i))for(let e of t.bullets)a.push(wt(e))}return a}function Et(e,t){if(!e.hasUI||typeof e.ui?.notify!=`function`)return;let n=t??kt();if(!n)return;let r=J(n.version);if(r===void 0)return;let i=Nt(n.statePath),a=J(i);if(a===r||a!==void 0&&a>r)return;let o=Y(Ft(n.changelogPath)),s=a===void 0?At(o,n.version):i;if(s===void 0||!Pt(n.statePath,n.version))return;let c=Tt(o,s,n.version);Dt(e,jt(a===void 0?void 0:i,n.version,c,Mt(n.repository)))}function Dt(e,t){e.mode===`tui`&&typeof e.ui?.setWidget==`function`?e.ui.setWidget(`ptc-upgrade`,t.split(`
|
|
33
|
+
`).filter(e=>e.length>0)):e.ui?.notify?.(t,`info`)}function Ot(e=import.meta.url){for(let t of[`..`,`../../..`])try{let n=D(new URL(`${t}/`,e)).replace(/[\\/]+$/,``),r=JSON.parse(s(m(n,`package.json`),`utf8`));if(r.name!==q||!r.version)continue;return{dir:n,version:r.version,repository:typeof r.repository==`string`?r.repository:r.repository?.url}}catch{}}function kt(){let e=Ot();if(e)return{version:e.version,repository:e.repository,changelogPath:m(e.dir,`CHANGELOG.md`),statePath:m(i(),q,`last-seen-version.json`)}}function At(e,t){let n=J(t);if(n===void 0)return;let r;for(let t of e){let e=J(t.version);e===void 0||e>=n||(r===void 0||e>(J(r)??0))&&(r=t.version)}return r}function jt(e,t,n,r){let i=[`${q} ${t}`];if(e!==void 0&&i.push(`Updated from ${e}.`),n.length>0){i.push(``,`What's new:`);for(let e of n.slice(0,5))i.push(`- ${e}`);n.length>5&&i.push(`...and ${n.length-5} more`)}return r&&i.push(``,`Changelog: ${r}`),i.join(`
|
|
34
|
+
`)}function Mt(e){if(!e)return;let t=e.replace(/^git\+/,``).replace(/\.git$/,``);return t.startsWith(`https://github.com/`)?`${t}/blob/main/CHANGELOG.md`:void 0}function Nt(e){try{let t=JSON.parse(s(e,`utf8`));return typeof t.version==`string`?t.version:void 0}catch{return}}function Pt(e,t){try{return o(p(e),{recursive:!0}),f(e,JSON.stringify({version:t})),!0}catch{return!1}}function Ft(e){try{return s(e,`utf8`)}catch{return``}}function It(e){return e.replace(/\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\*\*/g,``).trim()}function Lt(e){if(e.length<=200)return e;let t=e.slice(0,200),n=t.lastIndexOf(` `);return`${t.slice(0,n>0?n:200).trimEnd()}…`}function Rt(e){let t;t=e.status===`fulfilled`?(e.logs.length>0?[...e.logs,B(e.value)]:[B(e.value)]).join(`
|
|
34
35
|
`):e.status===`rejected`?[...e.logs,`[rejected] ${e.error}`].join(`
|
|
35
36
|
`):[...e.logs,`[canceled] ${e.reason}`].join(`
|
|
36
|
-
`);let{text:n,truncated:r,fullOutputPath:i}=H(L(t));return{text:n,truncated:r,fullOutputPath:i}}const
|
|
37
|
-
`);if(e&&typeof e==`object`){let t=e;if(typeof t.content==`string`)return t.content;if(typeof t.text==`string`)return t.text;if(t.type===`image`)return typeof t.note==`string`?t.note:`[image]`}return e}const
|
|
38
|
-
`);throw Error(t||`工具 ${e} 执行失败`)}return
|
|
39
|
-
`);throw Error(t||`工具 ${e} 执行失败`)}return
|
|
37
|
+
`);let{text:n,truncated:r,fullOutputPath:i}=H(L(t));return{text:n,truncated:r,fullOutputPath:i}}const zt=_.Object({code:_.String({description:`要执行的 TypeScript 程序体,可用顶层 await 和 return`}),description:_.String({description:`这段程序要干什么(给人看的一行)`}),timeoutMs:_.Optional(_.Number({description:`覆盖默认 2 分钟超时`}))});function Bt(e){return{name:`ptc_run_code`,label:`运行程序`,description:U.ptc_run_code.description(e.surface??`full_ptc`),parameters:zt,renderResult:tt(`run_code`),execute:async(...t)=>{let r=t[1],i=t.find(e=>typeof e?.executeTool==`function`);e.onToolContext?.(i);let a=await n({code:r.code,surface:`run_code`,cwd:e.cwd,timeoutMs:r.timeoutMs,bindings:e.getBindings(),pool:e.getPool?.()}),{text:o,truncated:s,fullOutputPath:c}=Rt(a),l=a.status===`fulfilled`?a.images??[]:[];return{content:[{type:`text`,text:o},...l],details:c?{status:a.status,truncated:s,fullOutputPath:c}:{status:a.status,truncated:s},isError:a.status!==`fulfilled`}}}}const Vt=_.Object({meta:_.Object({name:_.String(),description:_.String(),phases:_.Optional(_.Array(_.Object({name:_.String()})))}),script:_.String({description:`workflow 程序体,额外可用 workflow.log/phase/parallel/pipeline`}),args:_.Optional(_.Record(_.String(),_.Unknown())),timeoutMs:_.Optional(_.Number())});function Ht(e){return{name:`ptc_workflow`,label:`跑 workflow`,description:U.ptc_workflow.description(e.surface??`full_ptc`),parameters:Vt,renderResult:tt(`workflow`),execute:async(...t)=>{let r=t[1],i=t.find(e=>typeof e?.executeTool==`function`);e.onToolContext?.(i);try{Ut(r.args)}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],details:{status:`rejected`},isError:!0}}let a=await n({code:r.script,surface:`workflow`,cwd:e.cwd,timeoutMs:r.timeoutMs,args:r.args??{},bindings:e.getBindings(),pool:e.getPool?.()}),{text:o,truncated:s,fullOutputPath:c}=Rt(a),l=a.status===`fulfilled`?a.images??[]:[];return{content:[{type:`text`,text:o},...l],details:{status:a.status,truncated:s,...c?{fullOutputPath:c}:{},meta:r.meta},isError:a.status!==`fulfilled`}}}}function Ut(e){if(e!==void 0)try{let t=JSON.stringify(e);if(t===void 0)throw Error(`args 不可序列化`);JSON.parse(t)}catch(e){throw Error(`workflow args 必须是 JSON 值:${e instanceof Error?e.message:String(e)}`)}}const X=[`read`,`bash`,`grep`,`find`,`ls`,`edit`,`write`],Wt=[`bash`],Gt=X.filter(e=>!Wt.includes(e));function Kt(e,t=[]){let n=/* @__PURE__ */ new Set([...Gt,...t]);return X.filter(t=>e.includes(t)&&n.has(t))}const qt=`pi_task_ptc`,Jt=_.Object({task:_.String({minLength:1,description:W.task}),agent:_.Optional(_.String({description:W.agent})),why:_.Optional(_.String({description:W.why})),agentScope:_.Optional(_.Union([_.Literal(`user`),_.Literal(`project`),_.Literal(`both`)],{description:W.agentScope})),model:_.Optional(_.String({description:W.model})),thinkingLevel:_.Optional(_.String({description:W.thinkingLevel})),wait:_.Optional(_.Boolean({description:W.wait})),label:_.Optional(_.String({description:W.label})),readOnly:_.Optional(_.Union([_.Literal(`strict`),_.Literal(`lenient`)],{description:W.readOnly})),timeoutMs:_.Optional(_.Number({description:W.timeoutMs})),projectContext:_.Optional(_.Union([_.Literal(`auto`),_.Literal(`none`)],{description:W.projectContext}))});function Yt(e){return{name:qt,parameters:Jt,execute(t){let n=t??{};return e.createTask(n.task,{label:n.label,wait:n.wait,why:n.why,model:n.model,thinkingLevel:n.thinkingLevel,agent:n.agent,agentScope:n.agentScope,readOnly:n.readOnly,timeoutMs:n.timeoutMs,projectContext:n.projectContext})}}}function Xt(e){return async t=>{let n=t,r=n?.taskId??n?.task_id;if(typeof r!=`string`||r===``)return{error:`taskId 必须是非空字符串`};let i=e.registry.get(r)??await e.readArchivedRecord(r);return i?{...await et(e,i),status:i.status}:{error:`unknown task id ${r}`}}}function Zt(e={}){let t=new re(e.onTransition),n=new je({registry:t,gates:e.gates,whyEnabled:e.whyEnabled,context:e.context,...e.engine});return{registry:t,engine:n,createTask:(e,t)=>n.dispatch({...t,task:e}),taskListSnapshot:e=>Ze(t,e),stopTask:(e,t)=>n.stop(e,t),faceVisible:()=>Qe(t),shutdown:()=>n.shutdown(),readOutput:e=>n.readOutput(e),outputSize:e=>n.outputSize(e),readOutputTail:(e,t)=>n.readOutputTail(e,t),readArchivedRecord:e=>n.readArchivedRecord(e),readArchivedRecords:()=>n.readArchivedRecords(),get sessionId(){return e.context?.sessionId}}}function Qt(e,t){return{depth:0,piVersion:t,get sessionModel(){try{let t=e.model;return t?`${t.provider}/${t.id}`:void 0}catch{return}},get sessionId(){try{return e.sessionManager.getSessionId()}catch{return}}}}const Z=e=>({content:[{type:`text`,text:JSON.stringify(e,null,2)}],details:void 0});function Q(e){if(!e||typeof e!=`object`)return e;let t=e;if(!(`reportChannel`in t))return e;let n=Ue({delivery:t.delivery,findings:Array.isArray(t.report?.findings)?t.report.findings.length:0,channel:t.reportChannel});return n?{...t,deliveryNote:n}:t}const $t=D(new URL(`..`,import.meta.url)),en=m($t,`docs`,`routes`),tn=a(en)?en:m($t,`..`,`routes`,`docs`,`routes`);function nn(){try{return h(`pi --version`,{encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim()||void 0}catch{return}}function rn(n){n.on(`session_start`,(r,a)=>{if(Number(process.env.PI_PTC_DEPTH??0)>0){un(n);return}let o=n.getActiveTools().includes(`codemode`)?`codemode_ptc`:`full_ptc`,s=an(i()),c=!1,l=()=>{c=o===`full_ptc`&&s};l(),n.on(`before_agent_start`,e=>{l(),S();let t=e.systemPromptOptions?.sections;t&&(t.ptc=Xe(o,tn,c))});let u=new t(e),d=new Te;n.on(`turn_end`,()=>{for(let e of d.drain())try{let t=qe(e);n.sendMessage({customType:`bg-task-notifications`,content:t,display:!0},{deliverAs:`nextTurn`})}catch{}});let f=!0,p=!1,h=null,g=on(i()),_=cn(i()),v={userDir:m(i(),`agents`),projectDir:m(process.cwd(),`.pi`,`agents`)},y=nn(),b,x=/* @__PURE__ */ new Set,S=()=>{let e=n.getActiveTools(),t=b.faceVisible(),r=$.filter(t=>e.includes(t));if(t&&r.length===0){n.setActiveTools([...e,...$]);for(let e of $)x.add(e)}else if(!t&&r.length>0){let t=r.filter(e=>x.has(e));if(t.length===0)return;n.setActiveTools(e.filter(e=>!t.includes(e)));for(let e of t)x.delete(e)}};b=Zt({onTransition:()=>S(),whyEnabled:()=>h??g,context:Qt(a,y),engine:{notifications:d,resolveAgent:(e,t)=>we(e,v,t),childExtensionPath:D(import.meta.url),searchEnabled:sn(i()).enabled,storageDir:m(process.cwd(),`.pi`,`ptc-tasks`),output:new he(m(process.cwd(),`.pi`,`ptc-tasks`)),terminalRecordKeep:_.keep,archiveEnabled:_.archiveEnabled,archiveTtlDays:_.ttlDays},gates:[oe,de,se(()=>f),ce(()=>p),le(()=>Number(process.env.PI_PTC_DEPTH??0),3),ue,fe((e,t)=>we(e,v,t)!==null)]}),n.registerCommand(`ptc`,{description:`/ptc off|on:派发开关 · /ptc why on|off:理由开关 · /ptc mode on|off:PTC 模式(程序优先的引导层)`,handler:async(e,t)=>{let[n,r]=e.trim().split(/\s+/);n===`off`?(f=!1,ee(),c&&(s=!1,l())):n===`on`?(f=!0,O(),s=!0,l()):n===`why`?h=r!==`off`:n===`mode`&&(s=r!==`off`,l()),t.ui.notify(`/ptc:dispatchEnabled=${f},mode=${c?`on(引导层)`:`off`},whyEnabled=${h??g}(在飞任务不受影响)`,`info`)}});let C=st({ui:a.mode===`tui`?a.ui:void 0,source:b.registry,sessionId:b.sessionId});n.on(`session_shutdown`,()=>{p=!0,C.dispose(),u.drain(),b.shutdown()}),d.attach(b.registry);let w=/* @__PURE__ */ new Map,T=[],E=(e=>{w.set(e.name,e),n.registerTool(e)}),ee=()=>{for(let[e,t]of w)e.startsWith(`ptc_task_`)||(n.registerTool({...t,exposure:`hidden`}),T.push(e))},O=()=>{for(let e of T.splice(0)){let t=w.get(e);t&&n.registerTool(t)}};gn(E,b,o),S();let k=!1;n.on(`session_compact`,()=>{k=!0}),n.on(`context`,e=>{if(!k)return;k=!1;let t=$e(b.registry);if(t)return{messages:[...e.messages,{role:`user`,content:[{type:`text`,text:t}],timestamp:Date.now()}]}});let A,j=process.cwd();hn(E,{getBindings:()=>mn(n,b,()=>A,{cwd:j,extCtx:a,piVersion:y}),cwd:j,surface:o,getPool:()=>u,onToolContext:e=>{A=e}},o),o===`codemode_ptc`&&_n(E,b,o),n.on(`turn_end`,()=>u.drain()),a.ui.notify(`pi-ptc-subagents: surface=${o},任务面 3 工具 + PTC 工具对已注册`,`info`);try{Et(a)}catch{}})}const $=[`ptc_task_list`,`ptc_task_output`,`ptc_task_stop`];function an(e){try{return JSON.parse(s(m(e,`ptc.json`),`utf8`)).defaultMode!==!1}catch{return!0}}function on(e){try{let t=s(m(e,`ptc.json`),`utf8`);return JSON.parse(t).whyEnabled!==!1}catch{return!0}}function sn(e){try{let t=JSON.parse(s(m(e,`ptc.json`),`utf8`)),n=typeof t.searchMaxCalls==`number`?t.searchMaxCalls:30;return{enabled:t.webDsSearch===!0,maxCalls:n}}catch{return{enabled:!1,maxCalls:30}}}function cn(e){let t={keep:500,archiveEnabled:!0,ttlDays:30};try{let n=JSON.parse(s(m(e,`ptc.json`),`utf8`)),r=(e,t,n,r)=>typeof e==`number`&&Number.isFinite(e)?Math.min(n,Math.max(t,Math.round(e))):r;return{keep:r(n.taskTraceKeep,10,1e4,t.keep),archiveEnabled:typeof n.archiveEnabled==`boolean`?n.archiveEnabled:t.archiveEnabled,ttlDays:r(n.archiveTtlDays,1,365,t.ttlDays)}}catch{return t}}function ln(e){try{let t=JSON.parse(s(m(e,`auth.json`),`utf8`)),n=t.deepseek?.api_key??t.deepseek?.key;if(n)return n}catch{}try{let t=JSON.parse(s(m(e,`models.json`),`utf8`));if(t.providers?.deepseek?.apiKey)return t.providers.deepseek.apiKey}catch{}return process.env.DEEPSEEK_API_KEY??null}function un(e){let t=i(),n=sn(t);if(n.enabled){let r=ln(t);e.registerTool(St({provider:ft(r??`missing-key`),memory:mt(),quota:pt(n.maxCalls)}))}e.registerTool({name:`ptc_child_report`,label:`交报告`,description:`Deliver the child report(契约见你的 system prompt)。`,parameters:_.Object({summary:_.String(),findings:_.Optional(_.Array(_.Object({what:_.String(),evidence:_.Optional(_.String())}))),files_touched:_.Optional(_.Array(_.String())),usage:_.Optional(_.Object({input:_.Optional(_.Number()),output:_.Optional(_.Number()),cost:_.Optional(_.Number()),turns:_.Optional(_.Number())}))}),execute:async(e,t)=>({content:[{type:`text`,text:`child report received`}],structuredContent:t,details:{report:t}})})}function dn(e){if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(e=>{if(typeof e==`string`)return e;let t=e;return t.type===`image`?`[image]`:t.text??JSON.stringify(e)}).join(`
|
|
38
|
+
`);if(e&&typeof e==`object`){let t=e;if(typeof t.content==`string`)return t.content;if(typeof t.text==`string`)return t.text;if(t.type===`image`)return typeof t.note==`string`?t.note:`[image]`}return e}const fn=Object.fromEntries([`read`,`write`,`edit`,`grep`,`ls`,`find`].map(e=>[e,r[`create${e[0].toUpperCase()}${e.slice(1)}ToolDefinition`]]));function pn(e){if(!e)return!0;let[t=`0`,n=`0`]=e.trim().replace(/^v/,``).split(`.`),r=Number.parseInt(t,10),i=Number.parseInt(n,10);return Number.isNaN(r)||Number.isNaN(i)?!0:r>0||r===0&&i>=99}function mn(e,t,n,r){let{cwd:i,extCtx:a,piVersion:o}=r,s=e.getActiveTools(),c=new Set(X),l=Kt(!n()&&!s.some(e=>c.has(e))?e.getAllTools().map(e=>e.name):s),u,d=e=>{if(!u){u={};for(let[e,t]of Object.entries(fn))typeof t==`function`&&(u[e]=t(i))}return u[e]},f=Object.fromEntries(l.map(e=>[e,async(t,r)=>{let i=n();if(!i?.executeTool){let n=pn(o)?void 0:d(e);if(!n)throw Error(`此 pi 版本没有程序内调用工具的通道(需 pi ≥ 0.99,binding: ${e})`);let i=n.prepareArguments?n.prepareArguments(t):t,s=await n.execute(`ptc-${e}`,i,r.signal,void 0,a);for(let e of s.content??[])e.type===`image`&&r.emitImage(e);if(s.isError){let t=(s.content??[]).map(e=>{let t=e;return t.type===`text`?t.text??``:`[${t.type??`block`}]`}).join(`
|
|
39
|
+
`);throw Error(t||`工具 ${e} 执行失败`)}return dn(s.structuredContent??s.content)}let s=await i.executeTool(e,t,{signal:r.signal});for(let e of s.result.content)e.type===`image`&&r.emitImage(e);if(s.isError){let t=s.result.content.map(e=>e.type===`text`?e.text:`[${e.type}]`).join(`
|
|
40
|
+
`);throw Error(t||`工具 ${e} 执行失败`)}return dn(s.result.structuredContent??s.result.content)}])),p=Yt(t);return f[qt]=async e=>Q(await p.execute(e)),f.task_records=async e=>{let n=t.registry.list();return e?.scope===`all`?[...n,...await t.readArchivedRecords()]:n},f.task_output=Xt(t),f}function hn(e,t,n){n===`full_ptc`&&(e(Bt(t)),e(Ht(t)))}function gn(e,t,n){e({name:`ptc_task_list`,label:`任务列表`,description:U.ptc_task_list.description(n),parameters:_.Object({scope:_.Optional(_.Union([_.Literal(`recent`),_.Literal(`all`)],{description:`recent = 只热存(默认);all = 含压缩归档(更全但更慢)`})),limit:_.Optional(_.Number({description:`取多少条(默认 50,上限 200)`})),status:_.Optional(_.Union(te.map(e=>_.Literal(e)),{description:`只看某个状态`})),session:_.Optional(_.String({description:`按会话筛:current = 本会话,或给一个会话 id`}))}),defaultActive:!1,execute:async(e,n)=>{let r={scope:n.scope,limit:n.limit,status:n.status,session:n.session===`current`?t.sessionId:n.session},i=r.scope===`all`?await t.readArchivedRecords():[];return Z(Ze(t.registry,r,i))}}),e({name:`ptc_task_output`,label:`任务产出`,description:U.ptc_task_output.description(n),parameters:_.Object({task_id:_.String()}),defaultActive:!1,execute:async(e,n)=>{let r=t.registry.get(n.task_id)??await t.readArchivedRecord(n.task_id);return Z(r?Q({...r,...await et(t,r)}):{error:`unknown task id ${n.task_id}`})}}),e({name:`ptc_task_stop`,label:`停任务`,description:U.ptc_task_stop.description(n),parameters:_.Object({task_id:_.String(),reason:_.Optional(_.String())}),defaultActive:!1,execute:async(e,n)=>Z(await t.stopTask(n.task_id,n.reason??`user stop`))})}function _n(e,t,n){e({name:`pi_task_codemode`,label:`建任务`,description:U.pi_task_codemode.description(n),parameters:Jt,exposure:`codemode`,execute:async(e,n)=>{let r=await t.createTask(n.task,{label:n.label,wait:n.wait,why:n.why,agent:n.agent,agentScope:n.agentScope,model:n.model,thinkingLevel:n.thinkingLevel,readOnly:n.readOnly,timeoutMs:n.timeoutMs,projectContext:n.projectContext}),i=Q(r);return{...Z(i),structuredContent:i,isError:r.status===`rejected`}}})}export{Zt as assemblePtcSession,Qt as buildEngineContext,Xt as createTaskOutputBinding,rn as default,Ot as findInstalledPackage,Y as parseChangelog,Tt as pickBullets,Et as showUpgradeNotice,wt as summarize,J as versionNumber,Q as withDeliveryNote};
|
|
40
41
|
//# sourceMappingURL=index.js.map
|