howtocode 0.0.0-stage → 0.7.56
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/LICENSE +21 -0
- package/README.md +248 -2
- package/dist/chunk-27TRKD65.js +2 -0
- package/dist/chunk-2SHU7WQ5.js +10 -0
- package/dist/chunk-3FYCFLNK.js +1 -0
- package/dist/chunk-4BWBQ4HV.js +1 -0
- package/dist/chunk-7IUWRCVT.js +197 -0
- package/dist/chunk-7LA2AMZB.js +1 -0
- package/dist/chunk-A3LZMZ3C.js +2 -0
- package/dist/chunk-ADJLVYL3.js +1 -0
- package/dist/chunk-AEDSISJB.js +1 -0
- package/dist/chunk-AEWC7NIN.js +5 -0
- package/dist/chunk-AYBGCIQH.js +8 -0
- package/dist/chunk-DML5JQIR.js +1 -0
- package/dist/chunk-DT7VRY24.js +1 -0
- package/dist/chunk-EZNNALD3.js +1 -0
- package/dist/chunk-FGKA3GGW.js +6 -0
- package/dist/chunk-FJBHQI6Q.js +6 -0
- package/dist/chunk-JWPDIJUV.js +1 -0
- package/dist/chunk-KA2CULSQ.js +2 -0
- package/dist/chunk-KTS2F755.js +2 -0
- package/dist/chunk-LYLJZVZ7.js +1 -0
- package/dist/chunk-MCAAX33K.js +2 -0
- package/dist/chunk-MCDEIIEN.js +1 -0
- package/dist/chunk-MVVEYKN6.js +6 -0
- package/dist/chunk-MWSWXDNN.js +5 -0
- package/dist/chunk-ORJ2QZBG.js +3 -0
- package/dist/chunk-PH72JBBL.js +4 -0
- package/dist/chunk-PVFHAKN6.js +1 -0
- package/dist/chunk-QOYTPACU.js +3 -0
- package/dist/chunk-RGYXELNI.js +140 -0
- package/dist/chunk-SDO33XPR.js +4 -0
- package/dist/chunk-SZPFD4XF.js +47 -0
- package/dist/chunk-TOV557ET.js +12 -0
- package/dist/chunk-TSEKPGK4.js +1 -0
- package/dist/chunk-TUXY64DT.js +2 -0
- package/dist/chunk-U3GZBLTM.js +2 -0
- package/dist/chunk-UTYFLLSM.js +1 -0
- package/dist/chunk-V3R4FYTJ.js +1 -0
- package/dist/chunk-VWAUPT4A.js +1 -0
- package/dist/chunk-WKUJ7CFO.js +1 -0
- package/dist/chunk-WOT6VMZA.js +1 -0
- package/dist/chunk-XBVWQC7P.js +1 -0
- package/dist/chunk-XHHNV7A5.js +2 -0
- package/dist/chunk-YNMLRZJK.js +2 -0
- package/dist/chunk-YX2QDCVK.js +1 -0
- package/dist/main.js +102 -0
- package/dist/presets/backend/api/preset.json +17 -0
- package/dist/presets/backend/api/prompt.md +9 -0
- package/dist/presets/backend/api/skills/api-contract/SKILL.md +35 -0
- package/dist/presets/data/sql/preset.json +17 -0
- package/dist/presets/data/sql/prompt.md +9 -0
- package/dist/presets/data/sql/skills/query-hygiene/SKILL.md +48 -0
- package/dist/presets/devops/containers/preset.json +17 -0
- package/dist/presets/devops/containers/prompt.md +9 -0
- package/dist/presets/devops/containers/skills/image-discipline/SKILL.md +59 -0
- package/dist/presets/frontend/web-ui/preset.json +17 -0
- package/dist/presets/frontend/web-ui/prompt.md +11 -0
- package/dist/presets/frontend/web-ui/skills/responsive-check/SKILL.md +46 -0
- package/dist/presets/gamedev/rotoolbox/preset.json +31 -0
- package/dist/presets/gamedev/rotoolbox/prompt.md +34 -0
- package/dist/presets/gamedev/rotoolbox/skills/rotoolbox/SKILL.md +129 -0
- package/dist/presets/hub.json +14582 -0
- package/dist/presets/lang/typescript/preset.json +16 -0
- package/dist/presets/lang/typescript/prompt.md +5 -0
- package/dist/presets/lang/typescript/skills/ts-strict/SKILL.md +48 -0
- package/dist/presets/mcp/filesystem/preset.json +27 -0
- package/dist/presets/mcp/filesystem/prompt.md +8 -0
- package/dist/presets/mcp/filesystem/skills/mcp-files/SKILL.md +27 -0
- package/dist/presets/mcp/memory/preset.json +25 -0
- package/dist/presets/mcp/memory/skills/mcp-memory/SKILL.md +31 -0
- package/dist/presets/mcp/rea/preset.json +28 -0
- package/dist/presets/mcp/rea/prompt.md +5 -0
- package/dist/presets/mcp/rea/skills/mcp-rea/SKILL.md +6 -0
- package/dist/presets/mcp/remotion/preset.json +27 -0
- package/dist/presets/mcp/remotion/prompt.md +7 -0
- package/dist/presets/mcp/remotion/skills/mcp-remotion/SKILL.md +6 -0
- package/dist/presets/mcp-hub.json +157 -0
- package/dist/presets/mobile/app/preset.json +17 -0
- package/dist/presets/mobile/app/prompt.md +7 -0
- package/dist/presets/mobile/app/skills/touch-targets/SKILL.md +47 -0
- package/dist/presets/quality/antislop/preset.json +25 -0
- package/dist/presets/quality/antislop/prompt.md +16 -0
- package/dist/presets/quality/antislop/skills/antislop/SKILL.md +595 -0
- package/dist/presets/quality/antislop/skills/antislop/references/gate.md +84 -0
- package/dist/presets/quality/antislop/skills/antislop-code/SKILL.md +128 -0
- package/dist/presets/quality/antislop/skills/antislop-copywriting/SKILL.md +413 -0
- package/dist/presets/quality/antislop/skills/antislop-human/SKILL.md +147 -0
- package/dist/presets/quality/antislop/skills/antislop-human/contrast-check.py +165 -0
- package/dist/presets/quality/antislop/skills/antislop-layoutmobile/SKILL.md +170 -0
- package/dist/presets/quality/antislop/skills/antislop-ui/SKILL.md +313 -0
- package/dist/presets/quality/antislop/skills/antislop-ui/references/motion.md +34 -0
- package/dist/presets/quality/antislop/skills/antislop-ui/references/states.md +49 -0
- package/package.json +34 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i="https://howtofix.id",t=`${i}/keys`,n=`${i}/wallet`,o="https://discord.howtofix.id",r=/insufficient pro credit/i,a=/account blocked|device already claimed/i,d=/sent no device id|no hardware id|device id is required/i,c=/too many requests[^.]*\bper minute\b|too many requests:\s*\d+\s*per minute/i,h=/您已达到(?:总)?请求数限制|request limit (?:reached|exceeded)/i,l=/user has been banned|account (?:is )?(?:banned|suspended)/i,u=/group \S+ is unavailable or unauthorized|no permission to access this group|分组 \S+ 已被弃用/i,p=/token has no access to any models|token cannot access model/i,f=/您的 IP 不在令牌允许访问的列表中|ip is not in the token's allowlist/i,m=/无法解析客户端 IP 地址|cannot parse (?:the )?client ip/i,w=/普通用户不支持指定渠道/i;function y(s){let e=s??"";if(e.trim()){if(r.test(e))return{hint:`this model runs on the VIP lane and is billed from Pro Credit, which is empty or short \u2014 top up at ${n} (card, QRIS, e-wallet via Midtrans); /usage shows both balances.`,open:n};if(a.test(e))return{hint:`this account is blocked because its device claimed the daily credit for more than one account \u2014 appeal to staff at ${o}; the block clears by hand, not by retrying.`,open:o};if(d.test(e))return{hint:"this build did not send a device id, which the daily credit needs \u2014 update with `howtocode --update`, then start again."};if(c.test(e))return{hint:"this account is over its per-minute request budget, which tightens when it is exceeded \u2014 wait a moment and resend; a different model shares the same budget."};if(h.test(e))return{hint:"this model is over its request limit for the window \u2014 wait for it to reset, or /model picks a different one, which has its own allowance."};if(l.test(e))return{hint:`this account is disabled \u2014 appeal to staff at ${o}; a new token or another model will be refused the same way.`,open:o};if(u.test(e))return{hint:`this token is pinned to a group the account cannot use \u2014 /model picks a model from the group it can, or top up Pro Credit at ${n} to unlock the VIP lane.`,open:n};if(p.test(e))return{hint:"this token is not allowed to call that model \u2014 /model lists what it can reach, and the Console's keys page can widen the list.",open:t};if(m.test(e))return{hint:"the gateway could not read this machine's IP address \u2014 a proxy in front of the CLI is the usual cause; /proxy shows the one in use, and the token's IP restriction is on the Console's keys page.",open:t};if(f.test(e))return{hint:`this token only accepts calls from other addresses \u2014 remove the IP restriction on ${t}, or run from an allowed one.`,open:t};if(w.test(e))return{hint:"a token cannot choose its upstream channel \u2014 remove the channel pin from the token; /model is how a model is chosen.",open:t}}}export{t as a,n as b,y as c};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as s}from"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";import{existsSync as a,readFileSync as p}from"node:fs";import{join as f}from"node:path";var u=600*1e3;function d(r){return f(r,"pricing-cache.json")}function l(r,t=Date.now(),n=u){let i=d(r);if(!a(i))return;let e;try{e=JSON.parse(p(i,"utf8"))}catch{return}if(e?.version!==1||typeof e.fetchedAt!="number"||!e.prices)return;let c=t-e.fetchedAt;if(c<0||c>n)return;let o=new Map(Object.entries(e.prices));if(o.size!==0)return{prices:o,groups:new Map(Object.entries(e.groups??{}))}}function m(r,t,n,i=Date.now()){if(t.size===0)return;let e={version:1,fetchedAt:i,prices:Object.fromEntries(t),groups:Object.fromEntries(n)};try{s(d(r),`${JSON.stringify(e)}
|
|
2
|
+
`,{mode:384})}catch{}}export{u as PRICE_CACHE_MAX_AGE_MS,d as priceCachePath,l as readCachedPrices,m as writeCachedPrices};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as a}from"./chunk-MVVEYKN6.js";import{b as r}from"./chunk-AEWC7NIN.js";import"./chunk-WOT6VMZA.js";function c(e){return{prompt:s=>e.session.prompt(s),abort:()=>e.session.abort(),subscribe:s=>e.session.subscribe(n=>s(n)),getLastAssistantText:()=>a(e.session.getLastAssistantText()??""),lastStopReason:()=>{let s=e.session.state.messages.at(-1);return s?.role==="assistant"?s.stopReason:void 0},dispose:()=>e.dispose()}}async function g(e,s){let{openSession:n}=await import("./chunk-SZPFD4XF.js"),i=t=>n({cwd:t,model:s.model,thinking:s.thinking,continueSession:!1,noSession:!1,sessionPath:void 0,interactive:!1});if(e==="acp"){let{runAcp:t}=await import("./chunk-TOV557ET.js");await t({input:process.stdin,output:process.stdout,version:r,createAgent:async u=>c(await i(u))});return}let{runRpc:p}=await import("./chunk-QOYTPACU.js"),{createJsonEventEncoder:d}=await import("./chunk-MCDEIIEN.js"),o=await i(s.cwd),m=d();await p({input:process.stdin,output:process.stdout,agent:c(o),encodeEvent:t=>m.line(t),state:()=>({sessionId:o.session.sessionId,model:o.modelLabel,cwd:s.cwd})})}export{c as agentFromSession,g as serveProtocol};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{H as a,I as b,J as c,K as d,L as e,M as f,N as g,O as h,P as i,Q as j}from"./chunk-2SHU7WQ5.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";export{e as AGENTS_STORE_DIR,a as AGENT_DIR,j as IMAGES_DIR,g as REACHABLE_CACHE_PATH,f as USAGE_CACHE_PATH,b as USER_SKILLS_DIR,h as WORKFLOWS_DIR,d as additionalSkillPaths,i as pinAgentDir,c as projectSkillsDir};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var a="HowToCode",o="0.7.56",n=["You are HowToCode, a coding agent. The user wants the fix, not a tour of the problem.",'NEVER report a check you did not run. NEVER state a version, path, result or capability you have not verified \u2014 if you did not check it, say you are unsure. "Not found" is not "impossible": a tool missing from PATH is often installed anyway, and one that is truly absent can usually be installed. Exhaust the real options before calling anything unavailable; when you do report a limit, say plainly what you tried and what you could not do. Unexercised behaviour is not evidence.',"NEVER mention the underlying harness, its vendor or its project name to the user.","Every tool is `read`, `write` or `exec`, and each approval mode auto-approves every tier up to its own: `suggest` runs `read` only, `auto-edit` adds `write`, `full-auto` adds `exec`. A read-only shell command runs in every mode, so inspecting the tree asks nothing.","NEVER aim a command at the filesystem root, a block device or a system account file, and NEVER shut down the host: those are refused in EVERY mode, `full-auto` included, so proposing one wastes the turn. This is not a list of things to avoid \u2014 it is a list of things that will not run.","Lead with the diagnosis in one or two sentences, then change the code. SHOULD prefer the smallest correct change over a rewrite. Name the file and the reason in a short line; do not narrate tool calls.","Fix the problem that was asked for. NEVER add features, refactors, validation, error handling or dependencies nobody requested.","Something reported broken: reproduce it first, confirm the fix after. Cannot reproduce it? Say so \u2014 NEVER edit code and call it fixed.","Tests describe intended behaviour. A failing test means fix the code, not the test: NEVER delete, skip or loosen an assertion to get green, and NEVER re-pin an expected value to whatever the code happens to print.","Anything you cannot settle by reading \u2014 a page, a layout, a screenshot, a CLI, a service, a failure \u2014 run it and look at the result. For a visual task, find a browser the way a real one does: `$PUPPETEER_EXECUTABLE_PATH`, `$CHROME_PATH`, then `which` for google-chrome, chromium and chromium-browser, then /usr/bin, /snap/bin and /var/lib/flatpak, then the puppeteer and playwright caches under the home directory. Still empty? `npx -y puppeteer browsers install chrome`, or `npm i puppeteer-core` against a chrome the image already ships outside PATH. Then drive the real artifact \u2014 open it, read the DOM, click the controls, measure at the widths that matter \u2014 instead of describing what you assume it does.","Done means the requested behaviour works end to end and every stated requirement is met \u2014 not a scaffold, a narrowed test or a plausible subset. Genuinely out of reach? Finish everything else, then say exactly what is missing and what you tried.","SHOULD plan multi-step work with `todo` before starting it, and mark each step done as you finish. A plan the user can see is worth more than a narration of what you are about to do.","Genuinely ambiguous design: enter plan mode, write the plan to the plan file, then present it with `exit_plan_mode`. Use it when several reasonable approaches exist or when a restructuring would be hard to undo. In plan mode `edit` and `write` are refused for every path except the plan file itself \u2014 that limit is enforced, not advisory, so plan the work rather than starting it. Plan mode needs an interactive session in which the user can approve it; when there is no UI it is unavailable, so design the approach yourself instead of calling it.","Work that is independent and would flood this conversation belongs in `task` subagents. Give each a self-contained assignment, then verify the file it wrote rather than trusting its summary. When that work has a shape you can script \u2014 many items through the same stages, or fan-out whose results must be combined \u2014 `workflow` states the orchestration in one place and runs it deterministically; `task` is for the one-off you cannot describe in advance.","MUST give each subagent a self-contained assignment: a child starts with none of this conversation, so a brief that says 'the file we discussed' reaches it as nothing. Choose the agent by what the work is \u2014 scout looks something up, architect returns a plan, reviewer reports issues with file evidence, task changes files \u2014 and NEVER send work that needs an edit to scout or reviewer, because neither can make one.","SHOULD delegate only work that is genuinely parallel: a subagent costs its own session and its own requests on the same quota as this conversation. A single lookup, a file you can read yourself, or a step whose result decides the next step stays here. MUST keep one call to at most six agents and the session to twelve live or parked ones \u2014 a larger fan-out is refused, and the refusal is a limit rather than a failure to work around.","Record a decision, a file's role, or a fact you would otherwise re-derive with `context`: notes survive compaction and are visible to the other agents on the task.","Look it up instead of recalling it: `web_search` and `web_fetch` for anything outside this repo, `lsp` for a definition, reference or diagnostic. Name the source you checked.","Before calling changed code done, run `quality` and `slop` over it and act on what they report. A metric you did not measure is a claim you cannot make.","A command runs under a two-minute default timeout. MUST pass a longer timeout for anything that legitimately takes more than that \u2014 a recursive directory walk, a package install, a build, a network fetch \u2014 and SHOULD prefer a bounded command to an unbounded one: 'du -sh' with an explicit path beats the whole profile, and on Windows/MSYS a recursive 'du' over a profile directory takes minutes rather than seconds.","When a choice blocks the task, use `ask` instead of guessing; when you need to work something out, use `think`, whose text stays out of the transcript.","Above all: NEVER claim a check you did not run, and NEVER call done on a subset."].join(`
|
|
2
|
+
`);function s(e){return e===void 0?void 0:e.replace(/Use \/login to log into a provider[^\n]*/gi,"Connect a provider with /connect or /login:").replace(/^[ \t]*\S*hxf-coding-agent[\\/]docs[\\/][^\n]*$/gim,"").replace(/\bhxf-coding-agent\b/gi,"the harness").replace(/\n{3,}/g,`
|
|
3
|
+
|
|
4
|
+
`).trim()}var i=["# Project notes","","## What this is","","## Commands","- build:","- test:","","## Conventions","-",""].join(`
|
|
5
|
+
`);export{a,o as b,n as c,s as d,i as e};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{q as f,r as p}from"./chunk-2SHU7WQ5.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";import{execFileSync as v}from"node:child_process";import{existsSync as m,mkdirSync as x,readFileSync as S,readdirSync as j,statSync as $,writeFileSync as z}from"node:fs";import{join as i,relative as b,resolve as d}from"node:path";function F(o){let e=o.replace(/-/g," ").replace(/\b\w/g,t=>t.toUpperCase());return[{path:"preset.json",body:`${JSON.stringify({name:o,title:e,description:"One line saying what this preset is for.",category:"engineering",version:"1.0.0",skills:[`${o}-skill`]},null,2)}
|
|
2
|
+
`},{path:"prompt.md",body:["Rules the model should follow while this preset is active.","","This text is appended to the system prompt, never substituted for it, so it","adds to the agent's own rules rather than replacing them. Delete this file if","the preset only needs skills.",""].join(`
|
|
3
|
+
`)},{path:i("skills",`${o}-skill`,"SKILL.md"),body:["---",`name: ${o}-skill`,"description: When the model should reach for this skill. This line is what"," the model reads when deciding, so say when to use it, not what it contains.","---","",`# ${e}`,"","What the model should do, as instructions. A skill is read on demand: only the","frontmatter above is in every request, so the body costs nothing until used.","","Do not add `disable-model-invocation: true` unless the skill must only ever run","from `/skill:<name>` \u2014 it keeps the skill out of the model's catalogue entirely.",""].join(`
|
|
4
|
+
`)}]}function g(){return["usage:"," howtocode preset new <name> [dir] write a preset skeleton"," howtocode preset check [dir] validate a preset with the installer's rules"," howtocode preset pack [dir] build <name>-<version>.tar.gz for publishing","","A preset is a directory holding preset.json, an optional prompt.md, and a","skills/ tree. `check` runs the same validation the installer runs, so a preset","that passes here will not be refused at install."].join(`
|
|
5
|
+
`)}function w(o){let e=[],t=s=>{for(let l of j(s,{withFileTypes:!0}).sort((n,r)=>n.name.localeCompare(r.name))){let n=i(s,l.name);l.isDirectory()?t(n):e.push(b(o,n).split("\\").join("/"))}};return t(o),e}function C(o){let{manifest:e,problems:t}=p(o);if(!e){console.log(`not installable: ${o}`);for(let a of t)console.log(` - ${a}`);return!1}let s=f(o,e);if(s.length>0){console.log(`not installable: ${o}`);for(let a of s)console.log(` - ${a}`);return!1}let l=e.skills??[],n=0,r=0;for(let a of l){let u=i(o,"skills",a,"SKILL.md"),k=m(u)?/^---\r?\n([\s\S]*?)\r?\n---/.exec(S(u,"utf8")):null,y=k&&/^disable-model-invocation:\s*(.*)$/m.exec(k[1]);y&&y[1].trim().replace(/^["']|["']$/g,"").toLowerCase()==="true"?r+=1:n+=1}let h=w(o),c=h.reduce((a,u)=>a+$(i(o,u)).size,0);return console.log(`installable: ${e.name} ${e.version??""}`.trim()),console.log(` ${h.length} files, ${(c/1024).toFixed(1)} KB`),console.log(` ${l.length} skill(s): ${n} the model can choose`),r>0&&console.log(` ${r} invoke-only \u2014 reachable only as /skill:<name>`),!0}function L(o){let{manifest:e,problems:t}=p(o);if(!e){console.log(`cannot pack: ${o}`);for(let c of t)console.log(` - ${c}`);return!1}let s=f(o,e);if(s.length>0){console.log("cannot pack: the preset does not validate");for(let c of s)console.log(` - ${c}`);return!1}let l=e.version??"1.0.0",n=d(`${e.name}-${l}.tar.gz`),r=w(o);v("tar",["-czf",n,"-C",o,...r]);let h=$(n).size;return console.log(`packed ${n}`),console.log(` ${r.length} files, ${(h/1024).toFixed(1)} KB`),console.log(""),console.log("to offer it to the community registry, open a pull request adding an entry"),console.log("that names the repo, a pinned commit, and the skill directory inside it."),!0}function P(o){let[e,t]=o;if(!e||e==="--help"||e==="-h")return console.log(g()),e?0:2;if(e==="new"){if(!t)return console.log(`preset new: a name is required
|
|
6
|
+
`),console.log(g()),2;if(!/^[a-z0-9][a-z0-9-]*$/.test(t))return console.log(`preset new: "${t}" is not a usable name.`),console.log(" lower-case letters, digits and hyphens; must start with a letter or digit."),console.log(" The installer refuses anything else, and it refuses at install time."),2;let s=o[2]?d(o[2]):d("."),l=i(s,t);if(m(l))return console.log(`preset new: ${l} already exists.`),1;for(let n of F(t)){let r=i(l,n.path);x(i(r,".."),{recursive:!0}),z(r,n.body),console.log(` wrote ${b(l,r)}`)}return console.log(`
|
|
7
|
+
wrote ${l}`),console.log(` edit preset.json and the skill, then: howtocode preset check ${t}`),0}if(e==="check"||e==="pack"){let s=d(t??".");return m(i(s,"preset.json"))?(e==="check"?C(s):L(s))?0:1:(console.log(`${e}: no preset.json in ${s}`),2)}return console.log(`preset: unknown subcommand "${e}"
|
|
8
|
+
`),console.log(g()),2}export{P as runPresetCommand};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c}from"./chunk-MWSWXDNN.js";import"./chunk-2SHU7WQ5.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";export{c as formatSkillList,b as skillInvocation,a as skillSearchPaths};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j}from"./chunk-KA2CULSQ.js";import"./chunk-AEWC7NIN.js";import"./chunk-WOT6VMZA.js";export{h as CLI_CLIENT_HEADER,a as CLI_SIGNING_KEY_ID,i as cliClientHeader,c as cliSignaturePayload,f as cliSigningKeyFingerprint,e as cliSigningKeyMatchesPanel,b as cliSigningPublicKey,d as createNonce,g as describeClient,j as signLoginRequest};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as o}from"./chunk-7LA2AMZB.js";var s=/no available channel for model\s+([^\s"',)\]]+)/i;function a(t){let e=t??"";if(e.trim())return s.exec(e)?.[1]}function u(t){let e=t??"";if(!e.trim())return;let i=o(e);if(i!==void 0)return i.hint;if(/cannot find module|ERR_MODULE_NOT_FOUND/i.test(e))return"the install is missing a file \u2014 `npm install -g howtocode@latest` puts it back; `howtocode doctor` lists what is absent.";let n=a(e);if(n)return`the gateway has no live channel for ${n} right now \u2014 /model lists the models that answer; pick another.`;if(/\bmissing api key\b|\bauthenticationerror\b|\bauth\s*error\b/i.test(e))return"no key for this model yet \u2014 /connect signs you in and pulls the model list.";if(/\bunknown model\b/i.test(e))return"/connect pulls the current model list from the gateway.";if(/\bcode 11128\b|\billegal api invocation\b/i.test(e))return"the gateway refused the request shape (code 11128) \u2014 /connect re-syncs each model's compatibility flags.";if(/\binsufficient (?:balance|quota|credit)\b|\bexceeded your current quota\b|http\s*402/i.test(e))return"the account is out of credit \u2014 /usage shows what is left.";if(/\bserver error\b|http\s*5\d\d/i.test(e))return"the gateway's channel is failing, not the CLI \u2014 /model lists what your account can reach; pick another.";if(/\brate.?limit|\b429\b/i.test(e))return"the gateway is rate-limiting this token \u2014 wait a moment, then resend the prompt.";if(/\bprompt (?:is )?too long\b|\bprompt too long\b|\bexceeds? (?:the )?(?:model'?s )?maximum context length\b|\bmaximum context length is \d+ tokens\b|\bexceeds the context window\b|\bcontext[_ ]length[_ ]exceeded\b|\breduce the length of the messages\b/i.test(e))return"the conversation is past this model's context window \u2014 /compact summarises it and continues, or /model picks a model with a bigger window.";if(/\bupstream api error\b/i.test(e))return"the gateway refused the request \u2014 run /connect again to re-sync your models."}function l(t){let e=0,i;return{limit:t,close(n){e+=n},total(n){return e+n},check(n){if(t===void 0||i!==void 0)return i;let r=e+n;return r-t>1e-9&&(i={spent:r,limit:t}),i}}}function h(t,e){return`stopped \u2014 spent $${t.toFixed(4)} of a $${e.toFixed(2)} budget.`}function b(t,e){return`--max-budget-usd needs a model with prices, and ${t} declares none (its rates are zero, so every turn costs $0 and the budget would never fire). Add a cost to that model in ${e}/models.json, or drop the flag.`}export{a,u as b,l as c,h as d,b as e};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as v}from"./chunk-7LA2AMZB.js";import{a as w}from"./chunk-UTYFLLSM.js";import{h as M,i as T}from"./chunk-KA2CULSQ.js";import{existsSync as H,mkdirSync as I,readFileSync as b}from"node:fs";import{join as k}from"node:path";var J="https://models.dev/api.json";var N=["anthropic","openai","google","deepseek","zai","xai","moonshotai","minimax","alibaba","xiaomi","meta","tencent","nvidia","venice","openrouter"];function _(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"")}function S(n){let e=n.split("/");return _(e[e.length-1]??n)}function q(n){let e=new Map,s=new Map;if(!n||typeof n!="object")return e;let t=n,r=c=>{let o=N.indexOf(c);return o===-1?N.length:o};for(let c of Object.keys(t).sort()){let o=t[c]?.models;if(!(!o||typeof o!="object"))for(let a of Object.keys(o)){let i=o[a],u=Number(i?.limit?.context);if(!Number.isFinite(u)||u<=0)continue;let l=_(a),f=r(c),d=s.get(l);if(d!==void 0&&d<=f)continue;let m=Number(i?.limit?.output);e.set(l,{contextWindow:Math.floor(u),maxTokens:Number.isFinite(m)&&m>0?Math.floor(m):void 0,reasoning:i?.reasoning===!0,vision:Array.isArray(i?.modalities?.input)&&i.modalities.input.includes("image")}),s.set(l,f)}}return e}function A(n,e){let s=_(e);if(!s)return;let t=n.get(s);if(t)return t;let r=S(e);for(let[c,o]of n)if(S(c)===r)return o;for(let[c,o]of n)if(c.endsWith(s)||s.endsWith(c))return o}function R(n){return`${n}/models-dev-cache.json`}function $(n){let e={};for(let[s,t]of n)e[s]=[t.contextWindow,t.maxTokens??0,t.reasoning?1:0,t.vision?1:0];return JSON.stringify(e)}function P(n){let e=new Map,s;try{s=JSON.parse(n)}catch{return e}if(!s||typeof s!="object")return e;for(let[t,r]of Object.entries(s)){if(!Array.isArray(r)||r.length<3)continue;let c=Number(r[0]),o=Number(r[1]);!Number.isFinite(c)||c<=0||e.set(t,{contextWindow:Math.floor(c),maxTokens:Number.isFinite(o)&&o>0?Math.floor(o):void 0,reasoning:r[2]===1||r[2]===!0,vision:r[3]===1||r[3]===!0})}return e}async function U(n){let e=n?.url??J,s=n?.fetchImpl??fetch,t=n?.timeoutMs??2e4,r=new AbortController,c=setTimeout(()=>r.abort(),t);try{let o=await s(e,{signal:r.signal,headers:{Accept:"application/json"}});if(!o.ok)return{ok:!1,message:`the model catalogue answered ${o.status}`};let a=q(await o.json());return a.size===0?{ok:!1,message:"the model catalogue was empty or in an unexpected shape"}:{ok:!0,index:a}}catch(o){return{ok:!1,message:o instanceof Error&&o.name==="AbortError"?`the model catalogue did not answer within ${Math.round(t/1e3)}s`:"could not reach the model catalogue"}}finally{clearTimeout(c)}}var x="https://api.howtofix.id/v1",ce=v,C=["howtocode","howtocode-free"];function ue(n){try{let s=JSON.parse(b(k(n,"models.json"),"utf8")).providers;return!s||typeof s!="object"?new Set:new Set(Object.keys(s))}catch{return new Set}}function le(){return{baseUrl:x,api:"openai-completions",headers:{[M]:T()}}}function de(n){let e=k(n,"models.json"),s;try{s=JSON.parse(b(e,"utf8"))}catch{return 0}let t=s.providers;if(!t||typeof t!="object")return 0;let r=0;for(let c of C){let o=t[c];if(!o||!Array.isArray(o.models))continue;let a=Y(o.models),i={...o.headers??{},[M]:T()},u=o.headers?.[M]!==i[M];a.changed===0&&!u||(o.models=a.models,o.headers=i,r+=a.changed===0?1:a.changed)}if(r===0)return 0;try{w(e,`${JSON.stringify(s,null,2)}
|
|
2
|
+
`)}catch{return 0}return r}var G=10080*60*1e3;async function F(n,e){let s=R(n),t=e?.now??Date.now(),r,c=0;try{let i=JSON.parse(b(s,"utf8"));typeof i?.entries=="string"&&(r=P(i.entries),c=Number(i.at)||0)}catch{r=void 0}if(r&&r.size>0&&t-c<G&&!e?.force)return{index:r};let a=await U({fetchImpl:e?.fetchImpl});if(!a.ok)return r&&r.size>0?{index:r,message:a.message}:{index:new Map,message:a.message};try{I(n,{recursive:!0}),w(s,`${JSON.stringify({at:t,entries:$(a.index)})}
|
|
3
|
+
`)}catch{}return{index:a.index}}async function fe(n,e){let s=k(n,"models.json"),t;try{t=JSON.parse(b(s,"utf8"))}catch{return{changed:0}}let r=t.providers;if(!r||typeof r!="object")return{changed:0};let{index:c,message:o}=await F(n,e);if(c.size===0&&!e?.prices&&!e?.tiers)return{changed:0,message:o};let a=0;for(let i of C){let u=r[i];if(!u||!Array.isArray(u.models))continue;let l=Z(u.models,c,e?.prices,e?.tiers);l.changed!==0&&(u.models=l.models,a+=l.changed)}if(a>0)try{w(s,`${JSON.stringify(t,null,2)}
|
|
4
|
+
`)}catch{return{changed:0,message:"the models file could not be written"}}return{changed:a,message:o}}var B=3e5;function me(n){let e=k(n,"settings.json"),s={};try{let t=b(e,"utf8"),r=JSON.parse(t);r&&typeof r=="object"&&!Array.isArray(r)&&(s=r)}catch{if(H(e))return!1}if("httpIdleTimeoutMs"in s)return!1;s.httpIdleTimeoutMs=B;try{I(n,{recursive:!0}),w(e,`${JSON.stringify(s,null,2)}
|
|
5
|
+
`)}catch{return!1}return!0}var D={supportsDeveloperRole:!1},L=128e3;function pe(n){let e=n.trim();return e.length<=10?"***":`${e.slice(0,6)}\u2026${e.slice(-4)}`}function ge(n){return/^sk-[A-Za-z0-9_-]{8,}$/.test(n.trim())}function V(n){let e=(()=>{if(Array.isArray(n))return n;if(n&&typeof n=="object"){let t=n;if(Array.isArray(t.data))return t.data;if(Array.isArray(t.models))return t.models}return[]})(),s=[];for(let t of e){let r=typeof t=="string"?t:t&&typeof t=="object"&&typeof t.id=="string"?t.id:void 0;r&&!s.includes(r)&&s.push(r)}return s}function he(n){return C.includes(n)}var K=1e8;async function W(n,e){let s=await n(e,{headers:{Accept:"application/json"}});if(!s.ok)return"USD";let r=(await s.json())?.data?.quota_display_type;return typeof r=="string"&&r.trim()?r.trim().toUpperCase():"USD"}async function Q(n,e){try{let s=await n(e,{headers:{Accept:"application/json"}});if(!s.ok)return 5e5;let t=await s.json(),r=Number(t?.data?.quota_per_unit);return Number.isFinite(r)&&r>0?r:5e5}catch{return 5e5}}async function ye(n,e){let s=(e?.baseUrl??x).replace(/\/+$/,""),t=e?.fetchImpl??fetch,r=e?.timeoutMs??1e4,c=n.trim();if(!c)return;let o=s.replace(/\/v1$/,""),a=new AbortController,i=setTimeout(()=>a.abort(),r);try{let[u,l,f]=await Promise.all([t(`${o}/api/cli/auth/check`,{headers:{Authorization:`Bearer ${c}`},signal:a.signal}),Q(t,`${o}/api/status`),W(t,`${o}/api/status`)]);if(!u.ok)return;let d=await u.json();if(d.success!==!0)return;let m=d.data??{},g=h=>{let y=Number(h);return Number.isFinite(y)?y/l:void 0},p={credit:g(m.quota),pro:g(m.pro_quota),usedPro:g(m.used_pro_quota),unit:f};return p.credit===void 0&&p.pro===void 0?void 0:p}catch{return}finally{clearTimeout(i)}}async function be(n,e){let s=(e?.baseUrl??x).replace(/\/+$/,""),t=e?.fetchImpl??fetch,r=e?.timeoutMs??15e3,c=n.trim();if(!c)return{ok:!1,unlimited:!1,unit:"USD",message:"no token given"};let o=`${s.replace(/\/v1$/,"")}/api/status`,a=await W(t,o).catch(()=>"USD"),i=new AbortController,u=setTimeout(()=>i.abort(),r),l={Authorization:`Bearer ${c}`};try{let[f,d]=await Promise.all([t(`${s}/dashboard/billing/subscription`,{headers:l,signal:i.signal}),t(`${s}/dashboard/billing/usage`,{headers:l,signal:i.signal})]);if(f.status===401||f.status===403)return{ok:!1,unlimited:!1,unit:a,message:"the gateway rejected that token when asking for the balance"};if(!f.ok)return{ok:!1,unlimited:!1,unit:a,message:`the balance endpoint answered ${f.status}`};let m=await f.json();if(m.error?.message)return{ok:!1,unlimited:!1,unit:a,message:m.error.message};let g=Number(m.hard_limit_usd??m.soft_limit_usd??0);if(g>=K)return{ok:!0,unlimited:!0,unit:a,message:"this token has no quota limit"};let p=0;if(d.ok){let y=await d.json();p=Number(y.total_usage??0)/100}let h=Math.max(0,g-p);return{ok:!0,unlimited:!1,limit:g,used:p,remaining:h,unit:a,message:`${h.toFixed(2)} ${a} left of ${g.toFixed(2)} (${p.toFixed(2)} used)`}}catch(f){let d=f instanceof Error&&f.name==="AbortError";return{ok:!1,unlimited:!1,unit:a,message:d?`the gateway did not answer within ${Math.round(r/1e3)}s`:"could not reach the gateway"}}finally{clearTimeout(u)}}async function we(n,e,s){let t=k(n,"models.json"),r;try{r=JSON.parse(b(t,"utf8"))}catch{return{added:0,touched:0}}let c=r.providers;if(!c||typeof c!="object")return{added:0,touched:0};let{index:o}=await F(n).catch(()=>({index:new Map})),a=0,i=0;for(let u of C){let l=c[u];if(!l||!Array.isArray(l.models))continue;let f=l.models.length;l.models=X(l.models,e,o,s),a+=l.models.length-f,i++}if(a===0)return{added:0,touched:i};try{w(t,`${JSON.stringify(r,null,2)}
|
|
6
|
+
`)}catch{return{added:0,touched:i}}return{added:a,touched:i}}function X(n,e,s,t){let r=new Set(e),c=r.size>0?n.filter(i=>r.has(i.id)):[...n],o=new Set(c.map(i=>i.id)),a=[...c];for(let i of e){if(o.has(i))continue;o.add(i);let u=s?.get(_(i))??(s?A(s,i):void 0);a.push({id:i,contextWindow:u?.contextWindow??L,...u?.maxTokens?{maxTokens:u.maxTokens}:{},...u?{reasoning:u.reasoning}:{},...u?.vision?{input:["text","image"]}:{},...t?.get(i)?{cost:t.get(i)}:{},compat:{...D}})}return a}function Z(n,e,s,t){let r=0;return{models:n.map(o=>{let a=A(e,o.id);if(!a){let d=s?.get(o.id),m=t?.get(o.id),g=d&&!o.cost,p=m&&m.length>0&&!j(o.plans,m);return!g&&!p?o:(r++,{...o,...g?{cost:d}:{},...p?{plans:m,plan:m[0]}:{}})}let i={...o},u=!1;a.contextWindow&&o.contextWindow===L&&(i.contextWindow=a.contextWindow,u=!0),a.maxTokens&&!o.maxTokens&&(i.maxTokens=a.maxTokens,u=!0),o.reasoning===void 0&&(i.reasoning=a.reasoning,u=!0),a.vision&&!(o.input??[]).includes("image")&&(i.input=[...(o.input??["text"]).filter(d=>d!=="image"),"image"],u=!0);let l=s?.get(o.id);l&&!o.cost&&(i.cost=l,u=!0);let f=t?.get(o.id);return f&&f.length>0&&!j(o.plans,f)&&(i.plans=f,i.plan=f[0],u=!0),u?(r++,i):o}),changed:r}}function j(n,e){return!n||n.length!==e.length?!1:n.every((s,t)=>s===e[t])}function Y(n){let e=0;return{models:n.map(t=>t.compat?.supportsDeveloperRole===!1?t:(e++,{...t,compat:{...t.compat,...D}})),changed:e}}function ke(n,e){let s=new Set(n.map(t=>t.id));return e.filter(t=>!s.has(t)).length}async function ee(n,e,s){let t=(s?.baseUrl??x).replace(/\/+$/,""),r=s?.fetchImpl??fetch,c=s?.timeoutMs??1e4,o=new AbortController,a=setTimeout(()=>o.abort(),c);try{let i=await r(`${t}/chat/completions`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({model:n,messages:[{role:"user",content:"hi"}],max_tokens:1}),signal:o.signal});if(i.ok)return{ok:!0,detail:"ok"};let u=await i.text().catch(()=>"");return{ok:!1,detail:/"message"\s*:\s*"([^"]{0,80})/.exec(u)?.[1]??`HTTP ${i.status}`}}catch(i){return{ok:!1,detail:i instanceof Error&&i.name==="AbortError"?"timed out":"unreachable"}}finally{clearTimeout(a)}}async function xe(n,e,s){let t=Math.max(0,s?.limit??4),r=[...new Set(n)].filter(o=>o!==s?.exclude).slice(0,t),c=await Promise.all(r.map(o=>ee(o,e,s)));return{live:r.filter((o,a)=>c[a]?.ok),probed:r}}async function Me(n,e){let s=(e?.baseUrl??x).replace(/\/+$/,""),t=e?.fetchImpl??fetch,r=e?.timeoutMs??15e3,c=n.trim();if(!c)return{ok:!1,models:[],message:"no token given"};let o=new AbortController,a=setTimeout(()=>o.abort(),r);try{let i=await t(`${s}/models`,{headers:{Authorization:`Bearer ${c}`},signal:o.signal});if(i.status===401)return{ok:!1,models:[],message:"the gateway rejected that token (401). Check it in the Console, or make a new one."};if(i.status===403)return{ok:!1,models:[],message:"that token is not allowed to list models (403). The Console shows what a token may call."};if(!i.ok)return{ok:!1,models:[],message:`the gateway answered ${i.status}`};let u=V(await i.json());return u.length===0?{ok:!1,models:[],message:"the token works but the gateway listed no models"}:{ok:!0,models:u,message:`${u.length} models available to this token`}}catch(i){let u=i instanceof Error&&i.name==="AbortError";return{ok:!1,models:[],message:u?`the gateway did not answer within ${Math.round(r/1e3)}s`:"could not reach the gateway"}}finally{clearTimeout(a)}}async function _e(n,e){let t=`${(e?.baseUrl??x).replace(/\/+$/,"").replace(/\/v1$/,"")}/api/pricing`,r=e?.fetchImpl??fetch,c=e?.timeoutMs??15e3,o=new Map,a=n.trim();if(!a)return o;let i=new AbortController,u=setTimeout(()=>i.abort(),c);try{let l=await r(t,{headers:{Authorization:`Bearer ${a}`},signal:i.signal});if(!l.ok)return o;let f=await l.json();if(!Array.isArray(f?.data))return o;for(let d of f.data){let m=typeof d?.model_name=="string"?d.model_name:"";if(!m)continue;if(e?.groups&&Array.isArray(d.enable_groups)){let O=d.enable_groups.filter(z=>typeof z=="string");O.length>0&&e.groups.set(m,O)}if(Number(d.quota_type??0)!==0)continue;let g=Number(d.model_ratio);if(!Number.isFinite(g)||g<0)continue;let p=g*2,h=Number(d.completion_ratio),y=Number(d.cache_ratio),E=Number(d.create_cache_ratio);o.set(m,{input:p,output:Number.isFinite(h)&&h>=0?p*h:0,cacheRead:Number.isFinite(y)&&y>=0?p*y:0,cacheWrite:Number.isFinite(E)&&E>=0?p*E:0})}}catch{}finally{clearTimeout(u)}return o}function Ce(n,e){try{let t=JSON.parse(b(k(n,"auth.json"),"utf8"))?.[e];if(!t||typeof t!="object")return;let r=t;return r.type!=="api_key"?void 0:typeof r.key=="string"&&r.key.trim()!==""?r.key.trim():void 0}catch{return}}export{x as a,ce as b,C as c,ue as d,le as e,de as f,G as g,F as h,fe as i,B as j,me as k,D as l,L as m,pe as n,ge as o,V as p,he as q,K as r,ye as s,be as t,we as u,X as v,Z as w,Y as x,ke as y,ee as z,xe as A,Me as B,_e as C,Ce as D};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{b as j}from"./chunk-MCAAX33K.js";import{H as m,N as A}from"./chunk-2SHU7WQ5.js";import"./chunk-UTYFLLSM.js";import{j as R}from"./chunk-MVVEYKN6.js";import{b as M,d as T,f as D}from"./chunk-TUXY64DT.js";import{a as I}from"./chunk-U3GZBLTM.js";import{a as b}from"./chunk-AEWC7NIN.js";import"./chunk-WOT6VMZA.js";import{spawnSync as J}from"node:child_process";import{existsSync as S,readdirSync as E,readFileSync as x,realpathSync as B,statSync as C,writeFileSync as F,unlinkSync as z}from"node:fs";import{dirname as N,join as p}from"node:path";var k=[22,19];async function W(t="https://api.howtofix.id/api/status"){let n=[],[s,e]=process.versions.node.split(".").map(Number),r=s>k[0]||s===k[0]&&e>=k[1];n.push({name:"node",ok:r,detail:`${process.versions.node} (needs >= ${k[0]}.${k[1]})`});let i=J("git",["--version"],{encoding:"utf8"});n.push({name:"git",ok:i.status===0,detail:i.status===0?i.stdout.trim():"not found on PATH"});let o=I();n.push({name:"sandbox",ok:!!o,detail:o??"no working bubblewrap (Linux) or sandbox-exec (macOS); --sandbox unavailable",optional:!0});let l=!1,c=m;try{let d=p(m,`.doctor-${process.pid}`);F(d,"ok"),z(d),l=!0}catch(d){c=`${m} is not writable: ${d instanceof Error?d.message:String(d)}`}n.push({name:"state dir",ok:l,detail:c});let a=p(m,"auth.json"),u="no auth.json \u2014 run `howtocode` and sign in",h=!1;try{let d=JSON.parse(x(a,"utf8")),f=Object.keys(d).length;h=f>0,u=h?`${f} provider credential${f===1?"":"s"}`:u}catch{}n.push({name:"auth",ok:h,detail:u,optional:!0});try{let d=Date.now(),f=await fetch(t,{signal:AbortSignal.timeout(5e3)});n.push({name:"gateway",ok:f.ok,detail:`${t} \u2192 ${f.status} in ${Date.now()-d}ms`,optional:!0})}catch(d){n.push({name:"gateway",ok:!1,detail:`${t} unreachable: ${d instanceof Error?d.message:String(d)}`,optional:!0})}return n.push(G()),n}function G(t=q()){if(t===void 0)return{name:"install",ok:!0,detail:"not an npm install; skipped",optional:!0};if(!S(t))return{name:"install",ok:!0,detail:"no bundled dependencies to check",optional:!0};let n=[],s=0;for(let e of["@netrodev"]){let r=p(t,e);if(S(r))for(let i of E(r)){let o=p(r,i,"dist");if(S(o))for(let l of _(o)){s+=1;let c=x(l,"utf8");for(let a of c.matchAll(/import\("(\.[^"]+)"\)/g)){let u=p(N(l),a[1]);S(u)||n.push(`${e}/${i}: ${u.slice(o.length+1)}`)}}}}return n.length>0?{name:"install",ok:!1,detail:`${n.length} module${n.length===1?"":"s"} missing (${n[0]}); reinstall with \`npm install -g howtocode@latest\``}:{name:"install",ok:!0,detail:`${s} lazy module${s===1?"":"s"} present`}}function q(){try{return p(N(N(B(process.argv[1]??""))),"node_modules")}catch{return}}function _(t,n=[]){let s;try{s=E(t)}catch{return n}for(let e of s){let r=p(t,e);if(e.endsWith(".lazy.js"))n.push(r);else if(!e.includes("."))try{C(r).isDirectory()&&_(r,n)}catch{}}return n}async function ie(){let t=await W(),n=Math.max(...t.map(e=>e.name.length));for(let e of t){let r=e.ok?"ok ":e.optional?"warn":"FAIL";console.log(` ${r} ${e.name.padEnd(n)} ${e.detail}`)}let s=t.filter(e=>!e.ok&&!e.optional);return s.length>0?(console.log(`
|
|
2
|
+
${s.length} problem${s.length===1?"":"s"} must be fixed before a session will work.`),1):0}function ce(t=m){let n=p(t,"models.json"),s;try{s=x(n,"utf8")}catch(a){return a.code==="ENOENT"?console.log(` no models.json at ${n} \u2014 run \`howtocode /connect\` to pull the catalogue`):j(b,"models",a),1}let e;try{e=JSON.parse(s)}catch(a){return console.error(`${b}: models: ${n} is not valid JSON (${a instanceof Error?a.message:String(a)})`),console.error(" fix the file, or delete it and run `howtocode /connect` to write a new one"),1}let r=e.providers??{},i=D(A),o=i?new Set(i.ids):void 0,l=new Set,c=0;for(let[a,u]of Object.entries(r)){let h=u.models??[],d=h.map(f=>f.id).filter(Boolean);for(let f of d)l.add(f);c+=d.length,console.log(` ${a} (${d.length})`);for(let f of h){if(!f.id)continue;let O=T(m).get(f.id),$=M(O??[]),g=$?` ${$}`:"",w=o&&!o.has(f.id)?" \u2014 not on this account":"";console.log(` ${f.id}${g}${w}`)}}if(o){let a=[...l].filter(u=>!o.has(u)).length;console.log(`
|
|
3
|
+
${[...o].filter(u=>l.has(u)).length} of ${c} listed model(s) this account can call${a>0?`; ${a} cannot (kept for other plans)`:""}`)}else console.log("\n which of these this account can call is unknown: run `howtocode` once to record it");return c===0?(console.log(" no models configured"),1):0}function v(t=15,n=m){let s=p(n,"sessions"),e;try{e=E(s)}catch{return[]}let r=[];for(let i of e){let o=p(s,i),l;try{l=E(o)}catch{continue}for(let c of l){if(!c.endsWith(".jsonl"))continue;let a=p(o,c);try{let u=C(a);r.push({file:a,project:i,modified:u.mtimeMs,bytes:u.size})}catch{}}}return r.sort((i,o)=>o.modified-i.modified).slice(0,t)}function le(t){let n=t.indexOf("--search");if(n>=0){let o=t[n+1]?.trim();if(!o)return console.error(`${b}: sessions: --search needs a word or phrase`),2;let l=K(o);if(l.length===0)return console.log(` no session mentions "${o}"`),0;for(let c of l){let a=new Date(c.row.modified).toISOString().replace("T"," ").slice(0,16),u=`${c.matches} hit${c.matches===1?"":"s"}`;console.log(` ${a} ${c.row.project} (${u})`),console.log(` ${c.row.file}`),console.log(` ${c.snippet}`)}return 0}let s=t.indexOf("--limit"),e=s>=0&&Number(t[s+1])||15,r=v(e);if(r.length===0)return console.log(` no saved sessions under ${p(m,"sessions")}`),t.includes("--export")?1:0;let i=t.indexOf("--export");if(i>=0){let o=Number(t[i+1]);if(!Number.isInteger(o)||o<1||o>r.length)return console.error(`${b}: sessions: --export needs a number from the list (1-${r.length})`),2;let l=r[o-1];try{console.log(Q(l.file))}catch(c){return j(b,"sessions",c),1}return 0}return r.forEach((o,l)=>{let c=new Date(o.modified).toISOString().replace("T"," ").slice(0,16),a=Math.round(o.bytes/1024);console.log(` ${String(l+1).padStart(2)} ${c} ${String(a).padStart(6)}k ${o.project}`),console.log(` ${o.file}`)}),0}function H(t){let n=t;try{let s=JSON.parse(t),e=s.message?.content??s.content;if(typeof e=="string"&&e.trim())n=e;else if(Array.isArray(e)){let r=e.map(i=>i&&typeof i=="object"&&"text"in i?String(i.text):"").join(" ");r.trim()&&(n=r)}}catch{}return R(X(n).replace(/\s+/g," ").trim())}function X(t){return t.replace(/\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\u0007|\u001b[@-Z\\-_]/g,"")}function Z(t,n,s=80){let e=t.toLowerCase().indexOf(n);if(e<0)return t.slice(0,s*2).trim();let r=Math.max(0,e-s),i=Math.min(t.length,e+n.length+s);return`${r>0?"\u2026":""}${t.slice(r,i).trim()}${i<t.length?"\u2026":""}`}function K(t,n=10,s=m){let e=t.toLowerCase(),r=new RegExp(`\\b${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`,"i"),i=[];for(let o of v(Number.MAX_SAFE_INTEGER,s)){let l;try{l=x(o.file,"utf8")}catch{continue}let c=0,a=0,u=0,h=0,d=!1,f="";for(let $ of l.split(`
|
|
4
|
+
`)){let g=$.toLowerCase(),w=g.indexOf(e);if(w<0)continue;let y=0;for(;w>=0;)y++,w=g.indexOf(e,w+e.length);c+=y;let L=g.includes('"role":"user"'),P=g.includes('"role":"toolresult"')||g.includes('"role":"tool"');L?a+=y:P?h+=y:u+=y,r.test($)&&(d=!0),f||(f=Z(H($),e))}if(c===0)continue;let O=(a>0?100:0)+(u>0?10:0)+Math.min(h,5)+(d?5:0)+Math.min(c,10)/100;i.push({row:o,matches:c,score:O,snippet:f})}return i.sort((o,l)=>l.score-o.score||l.row.modified-o.row.modified).slice(0,n)}function Q(t){let n=[`# Session ${t.split(/[\\/]/).pop()??t}`,""];for(let s of x(t,"utf8").split(`
|
|
5
|
+
`)){if(!s.trim())continue;let e;try{e=JSON.parse(s)}catch{continue}if(e.type!=="message")continue;let r=H(s);r&&n.push(`## ${e.message?.role??"unknown"}`,"",r,"")}return n.join(`
|
|
6
|
+
`).trimEnd()}export{W as collectChecks,Q as exportSessionMarkdown,G as installIntegrity,v as listSessionFiles,ie as runDoctor,ce as runModels,le as runSessions,K as searchSessions};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A,B,C,D,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-FGKA3GGW.js";import"./chunk-7LA2AMZB.js";import"./chunk-UTYFLLSM.js";import"./chunk-KA2CULSQ.js";import"./chunk-AEWC7NIN.js";import"./chunk-WOT6VMZA.js";export{g as CATALOG_CACHE_TTL_MS,m as DEFAULT_CONTEXT_WINDOW,a as HOWTOCODE_BASE_URL,b as HOWTOCODE_CONSOLE_URL,l as HOWTOCODE_MODEL_COMPAT,c as HOWTOCODE_PROVIDERS,j as HTTP_IDLE_TIMEOUT_MS,r as UNLIMITED_SENTINEL,w as applyCatalog,x as applyCompat,B as checkAccount,s as checkCreditPools,t as checkUsage,d as configuredProviderIds,y as countNewModels,k as ensureGatewaySettings,C as fetchGatewayPrices,A as findLiveModels,q as isHowtoCodeProvider,h as loadCatalog,o as looksLikeToken,n as maskToken,v as mergeModels,e as newProviderEntry,p as parseModelIds,z as probeModel,D as readProviderKey,f as repairGatewayModels,i as repairModelFacts,u as syncGatewayModelsOnStart};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{b as o}from"./chunk-AEWC7NIN.js";import{createPrivateKey as p,createPublicKey as f,createHash as l,randomBytes as d,sign as y}from"node:crypto";import{arch as c,cpus as m,hostname as I,platform as s}from"node:os";var a="hf-cli-1",C="MC4CAQAwBQYDK2VwBCIEIDmKoNgInS7oDpncee1d1+Mnci1R/q4aE5xxHeCKq4Dc",x="howtocode-cli-auth-v1",i;function u(){return i||(i=p({key:Buffer.from(C,"base64"),format:"der",type:"pkcs8"})),i}function g(){return f(u())}function K(t,e,n,r){return Buffer.from([x,t,e,n,r].join(`
|
|
2
|
+
`),"utf8")}function h(){return d(16).toString("hex")}var E="tQ91uspGl0sw5Y8x+soLYnFNX6a9vEzSzCuuvalzdKk=";function P(){let t=g().export({format:"der",type:"spki"});return t.subarray(t.length-32).toString("base64")===E}function N(){let t=g().export({format:"der",type:"spki"});return l("sha256").update(t).digest("hex").slice(0,16)}function $(){let e=(m()[0]?.model??"").replace(/\s+/g," ").trim(),n=I(),r=e?`${n} (${s()}/${c()}, ${e})`:`${n} (${s()}/${c()})`;return`CLI (${o}, ${r})`}var k="X-HowToCode-Client";function A(){return`CLI (${o})`}function B(t,e){let n=h(),r=y(null,K(a,t,e,n),u());return{keyId:a,nonce:n,signature:r.toString("base64")}}export{a,g as b,K as c,h as d,P as e,N as f,$ as g,k as h,A as i,B as j};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{b as c,d as l}from"./chunk-27TRKD65.js";import{H as s}from"./chunk-2SHU7WQ5.js";import"./chunk-UTYFLLSM.js";import{a as i,b as r}from"./chunk-AEWC7NIN.js";import"./chunk-WOT6VMZA.js";var d=[["/connect","sign in to howtofix.id: approve it in your browser"],["/model","choose which model answers"],["/help","list every command"],["/quit","leave"]],u=[" \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557"," \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D"," \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2557 "," \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2554\u2550\u2550\u255D "," \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u255D \u2588\u2588\u2557\u2588\u2588\u2551 "," \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D "],g=[" _ _ _____ ","| | | | __ __ | ___|","| |_| | \\ \\/ / | |_ ","| _ | > < | _| ","|_| |_| /_/\\_\\ |_| "];function m(){if(process.platform==="win32")return!1;let e=(process.env.LC_ALL||process.env.LC_CTYPE||process.env.LANG||"").toLowerCase();return e===""||e==="c"||e==="posix"||!e.includes("utf-8")&&!e.includes("utf8")?!1:!/ja|ko|zh|_kr|_jp|_cn|_tw|_hk/.test(e)}function h(){return m()?u:g}var _="https://howtofix.id/cli";function p(e){let n=process.env.HOME??"",t=n!==""&&e.startsWith(n)?`~${e.slice(n.length)}`:e,o=t.split("/").filter(Boolean);return o.length>3?`\u2026/${o.slice(-2).join("/")}`:t}function f(e){let n=e.signedIn?d.filter(([t])=>t!=="/connect"):d;return[...h(),"",`${i} ${r} \u2014 a terminal coding agent. Describe the change you want and it reads, edits and runs the code in front of you.`,"",` working in ${p(e.cwd)}`,...e.note?[` session ${e.note}`]:[],"",...e.signedIn?[" already signed in to howtofix.id",""]:[],...n.map(([t,o])=>` ${t.padEnd(11)}${o}`),"",' Or just start typing. Every message goes to the model; anything beginning with "/" stays local.'].join(`
|
|
2
|
+
`)}function v(){return[{value:"connect",label:"Sign in to howtofix.id",description:"approve the sign-in in your browser"},{value:"ready",label:"I have a key \u2014 just give me the prompt",description:"drops you at the prompt; run /connect whenever you like"},{value:"release",label:"What's in this release",description:`opens the ${r} notes in your browser`}]}async function E(e,n,t){c(s).welcomeSeen||(l(s),t(`welcome to ${i}`,f(e)),!e.signedIn&&await new Promise(o=>{n("First run \u2014 how do you want to begin?",v(),a=>{a==="connect"&&e.runSlash("/connect"),a==="release"&&e.openExternal(_),o()},()=>o())}))}export{E as maybeShowWelcome};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u}from"./chunk-SDO33XPR.js";import"./chunk-WOT6VMZA.js";export{f as BROKEN_LOCK_GRACE_MS,c as CHECK_ATTEMPTS,k as CHECK_FAILED_MESSAGE,b as CHECK_TIMEOUT_MS,d as INSTALL_TIMEOUT_MS,e as LOCK_TIMEOUT_MS,j as NPM_MISSING_MESSAGE,a as PACKAGE_NAME,n as acquireUpdateLock,u as autoUpdateEnabled,l as checkFailedNote,q as checkForUpdate,g as compareVersions,s as installUpdate,t as isInstalledCopy,h as isNewer,p as latestVersion,r as npmFailureDetail,m as pidAlive,o as releaseUpdateLock,i as resolveNpm};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function d(n,t){let e=`${n??""} ${t}`;if(/EACCES|EPERM/.test(e))return"the file or directory is not writable; check permissions and try again";if(/ENOENT/.test(e))return"a file or directory this command needs is missing";if(/ENOSPC/.test(e))return"the disk is full";if(/ECONNREFUSED|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|UND_ERR|fetch failed/i.test(e))return"the network request failed; check the connection and the gateway address";if(/EADDRINUSE/.test(e))return"another process is already using that port";if(/MODULE_NOT_FOUND|ERR_MODULE_NOT_FOUND|Cannot find module/.test(e))return"a required file or package is missing; reinstall HowToCode";if(/JSON/i.test(e)&&/parse|unexpected token|end of input/i.test(e))return"a configuration file is not valid JSON";if(/not a git repository/i.test(e))return"run the command inside a project, or pass --cwd"}function c(n){let e=(n instanceof Error?n.message:String(n)).trim()||"unknown error",i=n?.code;return{message:e,hint:d(i,e)}}function u(n,t,e,i=!1){let{message:r,hint:s}=c(e),o=[t?`${n}: ${t}: ${r}`:`${n}: ${r}`];return s&&o.push(` ${s}`),i&&e instanceof Error&&e.stack&&o.push(e.stack),o.join(`
|
|
2
|
+
`)}function f(n,t,e,i){let r=i?.debug??process.env.HOWTOCODE_DEBUG==="1";(i?.write??(a=>console.error(a)))(u(n,t,e,r))}export{c as a,f as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c}from"./chunk-PH72JBBL.js";import"./chunk-MVVEYKN6.js";import"./chunk-WOT6VMZA.js";export{c as createJsonEventEncoder,b as jsonLine,a as toJsonEvent};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var T=/^m(\d{4})$/,F=/^b([1-9]\d*)$/,y=/^@([1-9]\d*)@$/,G=/^@b([1-9]\d*)@$/,M="dcp-message-id";function Y(){return{nextRef:1,keyToRef:{},refToKey:{}}}function I(e,n="xml"){let r=n==="compact"?Number.MAX_SAFE_INTEGER:9999;if(!Number.isSafeInteger(e)||e<1||e>r)throw new Error(`Message ID index out of bounds: ${e}. Supported range is 1-${r}.`);return n==="compact"?`@${e}@`:`m${e.toString().padStart(4,"0")}`}function D(e,n="xml"){if(!Number.isInteger(e)||e<1)throw new Error(`Invalid block ID: ${e}`);return n==="compact"?`@b${e}@`:`b${e}`}function k(e,n="xml"){let s=e.trim().toLowerCase().match(n==="compact"?y:T);if(!s)return null;let t=Number.parseInt(s[1],10);if(!Number.isSafeInteger(t))return null;let o=n==="compact"?Number.MAX_SAFE_INTEGER:9999;return t<1||t>o?null:t}function X(e,n="xml"){let s=e.trim().toLowerCase().match(n==="compact"?G:F);if(!s)return null;let t=Number.parseInt(s[1],10);return Number.isSafeInteger(t)?t:null}function j(e,n="xml"){let r=e.trim().toLowerCase(),s=k(r,n);if(s!==null)return{kind:"message",ref:I(s,n),index:s};let t=X(r,n);return t!==null?{kind:"compressed-block",ref:D(t,n),blockId:t}:null}function w(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function m(e){return!e.includes("<dcp-message-id")&&!e.includes("</dcp-message-id")?e:e.replace(/<dcp-message-id(?:\s[^>]*)?>[\s\S]*?<\/dcp-message-id>/gi,"").replace(/<dcp-message-id(?:\s[^>]*)?>[mb]?\d{0,6}/gi,"").replace(/<\/?dcp-message-id(?:\s[^>]*)?>?/gi,"")}function v(e,n,r="xml"){if(r==="compact"){if(e==="BLOCKED")return`
|
|
2
|
+
@blocked@`;let t=n?.priority;return`
|
|
3
|
+
${e}${t?` [${t}]`:""}`}let s=Object.entries(n||{}).sort(([t],[o])=>t.localeCompare(o)).map(([t,o])=>t.trim().length===0||typeof o!="string"||o.length===0?"":` ${t}="${w(o)}"`).join("");return`
|
|
4
|
+
<${M}${s}>${e}</${M}>`}function C(e){return e.role==="user"||e.role==="assistant"||e.role==="toolResult"}function R(e){let n=new Map;return e.map(r=>{if(!C(r))return null;let s=r.role==="toolResult"?`toolResult:${r.toolCallId}`:`${r.role}:${r.timestamp}`,t=n.get(s)??0;return n.set(s,t+1),r.role==="toolResult"?s:`${s}#${t}`})}function U(e,n){let r=0;for(let s of R(n)){if(s===null||e.keyToRef[s]!==void 0)continue;let t=O(e);e.keyToRef[s]=t,e.refToKey[String(t)]=s,r++}return r}function O(e){let n=Number.isInteger(e.nextRef)?Math.max(1,e.nextRef):1;for(;n<=9999;){if(e.refToKey[String(n)]===void 0)return e.nextRef=n+1,n;n++}throw new Error(`Message ID alias capacity exceeded. Cannot allocate more than ${I(9999)} aliases in this session.`)}function W(e,n){return R(n).map(r=>r===null?null:e.keyToRef[r]??null)}var _="[\\uFF5C|\\u2502\\u01C0\\u2223]",N=`${_}?DSML${_}?`,a="(?:invoke|parameter|tool[_ -]?call)",l=`(?:${N}\\s*)?`,c="(?:\\\\?<|<)",u="(?:>|>)",d="\\\\?/",i="\\s*",g="(?:(?!>|>)[\\s\\S])*",L="[\\s\\S]*?",P=new RegExp(`(?:dsml|${c}${i}(?:${d})?${i}${l}${a}\\b)`,"i"),B=new RegExp(`${c}${i}${l}(${a})\\b${g}${u}${L}${c}${i}${d}${i}${l}\\1\\b${g}${u}`,"gi"),K=new RegExp(`${c}${i}(?:${d})?${i}${l}${a}\\b${g}${u}?`,"gi"),z=new RegExp(`${c}${i}(?:${d})?${i}${N}[A-Za-z_]*`,"gi");function f(e){return P.test(e)?e.replace(B,"").replace(K,"").replace(z,""):e}function J(e){let n=f(m(e));return n===e?e:n.replace(/\n{3,}/g,`
|
|
5
|
+
|
|
6
|
+
`).trim()}var x=new RegExp(`${c}${i}${d}${i}${l}${a}\\b${g}${u}`,"iy"),A=new RegExp(`${c}${i}${l}${a}\\b${g}${u}`,"iy"),b=new RegExp(`${c}${i}(${d})?${i}${l}${a}\\b${g}${u}`,"gi"),h=96;function Q(e){let n=m(e),r=new RegExp(`${c}${i}${l}(${a})\\b${g}${u}`,"gi"),s=new RegExp(`${c}${i}${d}${i}${l}${a}\\b${g}${u}`,"i"),t=-1,o;for(;(o=r.exec(n))!==null;)if(!s.test(n.slice(o.index+o[0].length))){t=o.index;break}return f(t<0?n:n.slice(0,t))}function H(e){x.lastIndex=0;let n=x.exec(e);return n?{kind:"close",length:n[0].length}:(A.lastIndex=0,n=A.exec(e),n?{kind:"open",length:n[0].length}:null)}function V(){let e="",n=!1,r=0;return{push(s){e+=s;let t="";for(;;){if(n){b.lastIndex=0;let p=b.exec(e);if(p){r+=p[1]===void 0?1:-1,e=e.slice(p.index+p[0].length),r<=0&&(n=!1,r=0);continue}let S=Math.max(e.lastIndexOf("<"),e.lastIndexOf("&")),E=S<0?"":e.slice(S);e=E.length<=h&&!E.includes(">")?E:"";break}let o=e.search(/[<&]/);if(o<0){t+=f(e),e="";break}o>0&&(t+=f(e.slice(0,o)),e=e.slice(o));let $=H(e);if($){e=e.slice($.length),$.kind==="open"&&(n=!0,r=1);continue}if(!e.includes(">")&&e.length<=h)break;t+=e[0],e=e.slice(1)}return t},flush(){let s=f(e);return e="",n=!1,r=0,s}}}export{Y as a,I as b,D as c,j as d,m as e,v as f,U as g,W as h,f as i,J as j,Q as k,V as l};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{I as s,J as l}from"./chunk-2SHU7WQ5.js";function c(i){return[s,l(i)]}function d(i,n){let t=i.trim(),r=/^\/skill:([^\s]+)(?:\s+([\s\S]*))?$/.exec(t)??/^\/skill\s+([^\s]+)(?:\s+([\s\S]*))?$/.exec(t);if(!r)return;let e=r[1]??"";if(!n.includes(e))return;let o=(r[2]??"").trim();return o?`/skill:${e} ${o}`:`/skill:${e}`}function u(i){if(i.length===0){let[n,t]=c(process.cwd());return["no skills loaded.",`put a SKILL.md in ${n}`,`or in ${t}`,"invoke with /skill:<name>"].join(`
|
|
2
|
+
`)}return i.map(n=>{let t=n.disableModelInvocation?" (invoke only)":"";return`${n.name}${t}
|
|
3
|
+
${n.description}
|
|
4
|
+
${n.filePath}`}).join(`
|
|
5
|
+
`)}export{c as a,d as b,u as c};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{readFileSync as f,statSync as u}from"node:fs";import{isAbsolute as a,resolve as p}from"node:path";var $=64*1024;function S(o,c){return o.replace(/(^|\s)@([^\s]+)/g,(e,l,i)=>{let t=i.replace(/[),.;:]+$/,""),g=i.slice(t.length),n=a(t)?t:p(c,t);try{let r=u(n);if(!r.isFile()||r.size===0||r.size>$)return e;let s=f(n);return s.includes(0)?e:`${l}<file name="${n}">
|
|
2
|
+
${s.toString("utf8").trimEnd()}
|
|
3
|
+
</file>${g}`}catch{return e}})}export{S as a};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{i as o,l as a}from"./chunk-MVVEYKN6.js";function f(n){return n.type==="message_update"}function c(n){if(n.type==="toolcall_start"){let t=n.contentIndex,i=t===void 0?void 0:n.partial?.content[t];if(i?.type!=="toolCall")return;let{partial:l,...g}=n;return{...g,id:i.id,toolName:i.name}}if(!("partial"in n))return n;let{partial:s,...e}=n;return e}var p={text:!0,thinking:!0,content:!0};function d(n,s,e=!1){if(typeof n=="string")return e?s(n):n;if(Array.isArray(n))return n.map(t=>d(t,s,e));if(n&&typeof n=="object"){let t={};for(let[r,i]of Object.entries(n))p[r]&&typeof i=="string"?t[r]=s(i):t[r]=d(i,s,e||r==="sections");return t}return n}function u(n,s){let e=d(n,o);if(!f(e))return e;if(e.message.role!=="assistant")return;let t=c(e.assistantMessageEvent);if(t===void 0)return;let r={...t};return"delta"in r&&typeof r.delta=="string"&&(r.delta=s?s(r.delta):o(r.delta)),{type:"message_update",usage:e.message.usage,assistantMessageEvent:r}}function y(n){let s=u(n);if(s!==void 0)return`${JSON.stringify(s)}
|
|
2
|
+
`}function A(){let n=a(),s=e=>n.push(e);return{line(e){let t=u(e,s);if(t!==void 0)return`${JSON.stringify(t)}
|
|
3
|
+
`},finish(){let e=n.flush();if(n=a(),!!e)return`${JSON.stringify({type:"message_update",assistantMessageEvent:{type:"text_delta",delta:e}})}
|
|
4
|
+
`}}}export{u as a,y as b,A as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m,o as n,p as o,q as p,r as q}from"./chunk-YNMLRZJK.js";import"./chunk-WOT6VMZA.js";export{c as APPROVAL_LABELS,b as APPROVAL_MODES,f as MODE_MAX_TIER,e as TIER_RANK,q as createPermissionExtension,h as criticalCommand,n as decideToolCall,o as describeToolCall,p as formatApprovalPrompt,j as getApprovalMode,d as isApprovalMode,l as isDangerousBypass,a as isReadOnlyCommand,g as resolveTier,i as setApprovalMode,m as setApprovalPrompt,k as setDangerousBypass};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import"./chunk-WOT6VMZA.js";import{createInterface as l}from"node:readline";function f(r){let{agent:u}=r,m=t=>r.output.write(`${JSON.stringify(t)}
|
|
2
|
+
`),e=(t,a,c,s={})=>m({...t!==void 0?{id:t}:{},type:"response",command:a,success:c,...s}),p=u.subscribe(t=>{let a=r.encodeEvent?r.encodeEvent(t):`${JSON.stringify(t)}
|
|
3
|
+
`;a!==void 0&&r.output.write(a)}),d=null;return new Promise(t=>{let a=l({input:r.input});a.on("line",c=>{if(c.trim()==="")return;let s;try{s=JSON.parse(c)}catch{e(void 0,"parse",!1,{error:"a command must be one JSON object per line"});return}let{id:n,type:i}=s;if(i==="prompt"){if(typeof s.message!="string"||s.message.trim()===""){e(n,"prompt",!1,{error:"prompt needs a message"});return}if(d){e(n,"prompt",!1,{error:"a prompt is already running; abort it or wait"});return}e(n,"prompt",!0),d=u.prompt(s.message).catch(o=>{m({type:"error",message:o instanceof Error?o.message:String(o)})}).finally(()=>{d=null});return}if(i==="abort"){u.abort().then(()=>e(n,"abort",!0)).catch(o=>e(n,"abort",!1,{error:o instanceof Error?o.message:String(o)}));return}if(i==="get_state"){e(n,"get_state",!0,{data:{running:d!==null,...r.state?.()??{}}});return}if(i==="get_last_assistant_text"){e(n,"get_last_assistant_text",!0,{data:{text:u.getLastAssistantText()??null}});return}e(n,String(i??"unknown"),!1,{error:`unknown command ${String(i)}`})}),a.on("close",()=>{(d??Promise.resolve()).then(async()=>{p(),await u.dispose(),t()})})})}export{f as runRpc};
|