@tocca-systems/twp-cli 0.25.0 → 0.26.0
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.public.md +10 -0
- package/dist/{agent-loop-ZP47LTUE.js → agent-loop-AOTZLJP2.js} +1 -1
- package/dist/ai-dispatch-UQHPVRWN.js +85 -0
- package/dist/{api-command-VWJXBUCJ.js → api-command-M4TMA4PR.js} +1 -1
- package/dist/{app-3JIU5OUX.js → app-3EHZDREV.js} +1 -1
- package/dist/{chunk-X45SJNT2.js → chunk-4F4Q6AES.js} +2 -2
- package/dist/{chunk-24ZZFFA3.js → chunk-5PU5QU5U.js} +1 -1
- package/dist/{chunk-VGMWPPGD.js → chunk-RDJYKA3U.js} +1 -1
- package/dist/{chunk-WQ66EYZS.js → chunk-XAMHF5MK.js} +1 -1
- package/dist/{chunk-TYNCXQSN.js → chunk-Y2XAWM2X.js} +13 -12
- package/dist/cli.js +6 -6
- package/dist/{commands-OFLBUP6O.js → commands-DDXAFNPT.js} +1 -1
- package/dist/{commands-RG7M6E5K.js → commands-EOKUE4FC.js} +8 -7
- package/dist/{logout-guard-3PB3VMGP.js → logout-guard-ICSEMN3J.js} +1 -1
- package/dist/{run-VNHAQO24.js → run-CSHFVJT7.js} +1 -1
- package/dist/{server-settings-YL6KALXG.js → server-settings-RC5BOWUW.js} +1 -1
- package/dist/{setup-BJKIHANC.js → setup-CDQ2CEUR.js} +1 -1
- package/dist/{user-UU2SLVC4.js → user-SWPYLR32.js} +38 -39
- package/package.json +1 -1
- package/dist/ai-dispatch-VSCKUY6J.js +0 -77
package/CHANGELOG.public.md
CHANGED
|
@@ -11,6 +11,16 @@
|
|
|
11
11
|
`CHANGELOG.md` に残してあります。顧客向けの履歴は public 公開以降を対象とします。
|
|
12
12
|
-->
|
|
13
13
|
|
|
14
|
+
## 0.26.0
|
|
15
|
+
|
|
16
|
+
`twp user invite bulk --file` と `twp user assignment move --file` で、Excel の「CSV」形式(Shift_JIS)で保存したファイルをそのまま読めるようになりました。これまでは文字化けにより部署名などが見つからず、全行がエラーになっていました。
|
|
17
|
+
|
|
18
|
+
`twp task-loop` が各サイクルの最初に、予備として設定した AI(codex / gemini / copilot)が使える状態かを短く確認し、利用上限や認証切れで使えない AI にはそのサイクルのタスクを回さず、設定した順番の次の AI に回すようになりました。確認結果はループのログに1行ずつ出ます。
|
|
19
|
+
|
|
20
|
+
## 0.25.1
|
|
21
|
+
|
|
22
|
+
`twp task-loop` で Gemini CLI を使うとき、作業フォルダを信頼済みとして起動するようにしました。新しい Gemini CLI で「trusted directory ではない」と表示されてすぐ終了していた問題が解消します。
|
|
23
|
+
|
|
14
24
|
## 0.25.0
|
|
15
25
|
|
|
16
26
|
`twp user assignment move --file <CSV>` で、4月の定期異動のような多人数の異動を一度に流せるようになりました。送る前に全行を確認し、誤りのある行が1つでもあれば何も変更せずに、その行番号と理由をすべて表示します。`--dry-run` を付けると、各行で終了する所属と新しく作る所属を確認できます。途中で失敗した場合はそこで止め、どの行まで反映されたかと元に戻すコマンドを表示します。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{stepToItem}from"./chunk-VCZVITWG.js";import{loadLocalConfig}from"./chunk-
|
|
3
|
+
import{stepToItem}from"./chunk-VCZVITWG.js";import{loadLocalConfig}from"./chunk-RDJYKA3U.js";import{loadAiConfig}from"./chunk-Y2XAWM2X.js";import"./chunk-N2UVRM3Z.js";import"./chunk-GY7KI5E5.js";import{LIST_FLAGS,LIST_PAGING_HELP,envelopePaging,nonEmpty,positiveInteger}from"./chunk-G4OO4M44.js";import{requireResolved,singleRef,withResolved}from"./chunk-ZN5EFDH7.js";import"./chunk-II5RVJQN.js";import{acknowledgement,isRecord,pick}from"./chunk-ZWVYVS2A.js";
|
|
4
4
|
import"./chunk-PMOUHEJQ.js";import"./chunk-5WGOHFAS.js";import"./chunk-RZVI6PMW.js";import{ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";var LABEL="\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u30EB\u30FC\u30D7\u306E\u30A2\u30A4\u30C6\u30E0";var STATUSES=["pending","processing","completed","failed"];var AI_TYPES=["claude","gemini","codex","copilot"];var EFFORTS=["low","medium","high","xhigh","max"];var PRIORITIES=["P0","P1","P2","P3"];var LIST_COLUMNS=["item_id","status","task_key","label","ai_type","ai_effort","runner_id","created_at"];var GET_COLUMNS=["item_id","status","task_key","label","prompt","ai_type","ai_model","ai_effort","runn\
|
|
5
5
|
er_id","attempt_count","reclaim_count","error_message","created_by_name","created_at","started_at","completed_at"];var HISTORY_COLUMNS=["item_id","status","task_key","skill","ai_type","runner_id","duration_ms","cost_usd","created_at"];var PROJECT_FLAG={name:"--project",summary:"\u30AD\u30E5\u30FC\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\uFF08\u30B3\u30FC\u30C9\u307E\u305F\u306F ID\u3002\u7701\u7565\u6642\u306F TWP_PROJECT / .twp/config.json / ~/.twp/config.json\uFF09",takesValue:true,placeholder:"\
|
|
6
6
|
<\u30B3\u30FC\u30C9|ID>"};var ITEM_FLAG={name:"--item",summary:"\u30A2\u30A4\u30C6\u30E0\u306E ID\uFF08item_id\uFF09\u3002\u4F4D\u7F6E\u5F15\u6570\u3068\u540C\u3058\u610F\u5473\uFF08\u4E21\u65B9\u6307\u5B9A\u306F\u30A8\u30E9\u30FC\uFF09",takesValue:true,placeholder:"<\u30A2\u30A4\u30C6\u30E0ID>"};var FORBIDDEN_CORE="\u30C6\u30CA\u30F3\u30C8\u306E\u7BA1\u7406\u8005\uFF08admin \u30ED\u30FC\u30EB\uFF09\u306E\u6A29\u9650\u304C\u5FC5\u8981\u3067\u3059\uFF08\u500B\u4EBA\u30AD\u30E5\u30FC\u3092\u9664\u304F\uFF09";
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{failureHint,isAuthError,isCliFatalText,isRateLimited,isServerAiType,isUntrusted,maxTurnsReached,rateLimitWaitSeconds,tailForScan}from"./chunk-ZOOEH7ZE.js";import{detectAiClis}from"./chunk-5PU5QU5U.js";import{DEFAULT_CLAUDE_LAUNCHER,activeSlotPath,detectClaudeAutoSwitch,isClaudeAi,isUsableModelId,modelFitsRoute,resolveSpawnTarget,usesBedrock,wrapWithAutoSwitch}from"./chunk-Y2XAWM2X.js";import{isForceOnly,killProcessTree,system32}from"./chunk-N2UVRM3Z.js";import{findExecutable,
|
|
4
|
+
isWindowsDriveAbsolute}from"./chunk-PMOUHEJQ.js";import"./chunk-5WGOHFAS.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";import{spawnSync}from"child_process";import fs2 from"fs";import path2 from"path";import{spawn}from"child_process";import fs from"fs";import path from"path";var FINAL_REPORT_BEGIN="<<<AI_FINAL_REPORT>>>";var FINAL_REPORT_END="<<<END_AI_FINAL_REPORT>>>";var ClaudeStreamRenderer=class{constructor(now=()=>new Date){this.now=now}now;toolNames=new Map;toolCount=0;result={subtype:null,isError:null,numTurns:null,costUsd:null,durationMs:null,tokensIn:null,tokensOut:null,rateLimited:false,resetsAt:null,finalText:""};push(line){const trimmed=line.trim();if(trimmed==="")return[];let event;try{const parsed=JSON.parse(trimmed);if(parsed===null||typeof parsed!=="\
|
|
5
|
+
object"||Array.isArray(parsed)){return[line]}event=parsed}catch{return[line]}switch(event["type"]){case"rate_limit_event":return this.onRateLimit(event);case"assistant":return this.onAssistant(event);case"user":return this.onUser(event);case"result":return this.onResult(event);default:return event["type"]==="system"?[]:[line]}}sawRateLimit(){return this.result.rateLimited}lastRateLimitNote="";onRateLimit(event){const info=event["rate_limit_info"];if(info===null||typeof info!=="object")return[];const rec=info;
|
|
6
|
+
const status=typeof rec["status"]==="string"?rec["status"]:"";const resets=typeof rec["resetsAt"]==="number"?rec["resetsAt"]:null;if(status==="")return[];const at=isSaneEpochSec(resets)?` resets=${new Date(resets*1e3).toISOString()}`:"";if(status.startsWith("allowed")){if(status==="allowed")return[];const seen=`${status}|${resets??""}`;if(seen===this.lastRateLimitNote)return[];this.lastRateLimitNote=seen;return[this.line(`\u2139\uFE0F \u4E0A\u9650\u306B\u63A5\u8FD1\uFF08status=${status}${at}\uFF09\u2014 \u5B9F\
|
|
7
|
+
\u884C\u306F\u7D99\u7D9A\u3057\u307E\u3059`)]}if(resets!==null)this.result.resetsAt=resets;this.result.rateLimited=true;return[this.line(`\u26A0\uFE0F \u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u901A\u77E5: status=${status}${at}`)]}onAssistant(event){const out=[];for(const block of contentBlocks(event)){if(block.type==="tool_use"){const name=typeof block.name==="string"?block.name:"tool";if(typeof block.id==="string")this.toolNames.set(block.id,name);this.toolCount+=1;out.push(this.line(`>> ${name}${toolDetail(
|
|
8
|
+
name,block.input)}`))}else if(block.type==="text"&&typeof block.text==="string"&&block.text.trim()!==""){for(const l of block.text.trim().split("\n"))out.push(this.line(` \u{1F4AC} ${l}`))}}return out}onUser(event){const out=[];for(const block of contentBlocks(event)){if(block.type!=="tool_result")continue;const id=typeof block.id==="string"?block.id:"";const useId=typeof block.tool_use_id==="string"?block.tool_use_id:id;const name=this.toolNames.get(useId)??"tool";this.toolNames.delete(useId);
|
|
9
|
+
const isError=block.is_error===true;const detail=isError?firstErrorLine(block):"";out.push(this.line(`${isError?"!!":"<<"} ${name}${detail}`))}return out}onResult(event){const r=this.result;r.subtype=typeof event["subtype"]==="string"?event["subtype"]:null;r.isError=typeof event["is_error"]==="boolean"?event["is_error"]:null;r.numTurns=typeof event["num_turns"]==="number"?event["num_turns"]:null;r.costUsd=typeof event["total_cost_usd"]==="number"?event["total_cost_usd"]:null;r.durationMs=typeof event["\
|
|
10
|
+
duration_ms"]==="number"?event["duration_ms"]:null;const usage=event["usage"];if(usage!==null&&typeof usage==="object"&&!Array.isArray(usage)){const u=usage;const num=key=>typeof u[key]==="number"?u[key]:0;const hasIn=["input_tokens","cache_creation_input_tokens","cache_read_input_tokens"].some(k=>typeof u[k]==="number");r.tokensIn=hasIn?num("input_tokens")+num("cache_creation_input_tokens")+num("cache_read_input_tokens"):null;r.tokensOut=typeof u["output_tokens"]==="number"?u["output_tokens"]:null}
|
|
11
|
+
const out=[this.line(`\u5B8C\u4E86 (turns: ${r.numTurns??0}, tools: ${this.toolCount}, ${Math.round((r.durationMs??0)/1e3)}s, $${(r.costUsd??0).toFixed(3)})`)];const text=typeof event["result"]==="string"?event["result"]:"";r.finalText=text;if(text!==""){out.push(FINAL_REPORT_BEGIN,text,FINAL_REPORT_END)}return out}line(msg){const d=this.now();const ts=`${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;return` [${ts}] ${msg}`}};function firstErrorLine(block){const content=block.
|
|
12
|
+
content;const text=typeof content==="string"?content:Array.isArray(content)?content.map(c=>c!==null&&typeof c==="object"&&typeof c.text==="string"?c.text:"").join(" "):"";const first=text.trim().split("\n")[0]??"";return first===""?"":` | ${first.slice(0,120)}`}function contentBlocks(event){const message=event["message"];if(message===null||typeof message!=="object")return[];const content=message["content"];if(!Array.isArray(content))return[];return content.filter(b=>b!==null&&typeof b==="object")}
|
|
13
|
+
function toolDetail(name,input){if(input===void 0||input===null)return"";const str=k=>typeof input[k]==="string"?input[k]:"";if(name==="Bash"){const cmd=str("command");return cmd===""?"":` $ ${cmd.slice(0,80)}${cmd.length>80?"...":""}`}if(name==="Read"||name==="Write"||name==="Edit"){const p=str("file_path");return p===""?"":` ${p}`}if(name==="Grep"||name==="Glob"){const p=str("pattern");return p===""?"":` '${p}'`}if(name==="Skill"){const s=str("skill");return s===""?"":` /${s}`}if(name.includes(
|
|
14
|
+
"mcp__")){const args=[];for(const k of["task_id","project_id","status_id","issue_id"]){const v=str(k);if(v!=="")args.push(`${k}=${v.slice(0,16)}`)}return args.length===0?"":` (${args.slice(0,2).join(", ")})`}return""}function pad(n){return String(n).padStart(2,"0")}function isSaneEpochSec(v){return v!==null&&Number.isFinite(v)&&Math.abs(v)<864e10}var DEFAULT_AI_TIMING={abortGraceMs:5e3,abortReapMs:2e3,pollIntervalMs:5e3};function resolveTiming(over){return{abortGraceMs:over?.abortGraceMs??DEFAULT_AI_TIMING.abortGraceMs,abortReapMs:over?.abortReapMs??DEFAULT_AI_TIMING.abortReapMs,pollIntervalMs:over?.pollIntervalMs??DEFAULT_AI_TIMING.pollIntervalMs}}var MAX_RETAINED_BYTES=4*1024*1024;function closeStream(stream){return new Promise(resolve=>{if(stream===null)return resolve();stream.once("error",()=>resolve());stream.end(()=>resolve())})}function buildArgs(req,cfg,env,workspace){
|
|
15
|
+
const warnings=[];const requested=(req.model??"").trim();const usable=requested!==""&&isUsableModelId(requested);if(requested!==""&&!usable){warnings.push(`ai_model '${requested}' \u306F\u4F7F\u3048\u306A\u3044\u5F62\u3067\u3059 \u2192 \u30AB\u30C6\u30B4\u30EA\u65E2\u5B9A\u306E\u30E2\u30C7\u30EB\u3092\u4F7F\u3044\u307E\u3059`)}const fitsRoute=!usable||!isClaudeAi(req.ai)||modelFitsRoute(requested,env);if(usable&&!fitsRoute){warnings.push(`ai_model '${requested}' \u306F\u73FE\u5728\u306E\u5B9F\u884C\u7D4C\u8DEF\u3067\u306F\u89E3\u6C7A\u3067\u304D\u307E\u305B\u3093\uFF08\u3053\u306E\u6A5F\u4F53\u306F ${usesBedrock(
|
|
16
|
+
env)?"Bedrock":"Anthropic \u76F4"}\uFF09 \u2192 \u30AB\u30C6\u30B4\u30EA\u65E2\u5B9A\u306E\u30E2\u30C7\u30EB\u3092\u4F7F\u3044\u307E\u3059`)}const fallback=cfg.modelFor(req.ai,req.category,env);const safeFallback=fallback===""||!isClaudeAi(req.ai)||modelFitsRoute(fallback,env)?fallback:"";if(fallback!==""&&safeFallback===""){warnings.push(`CLAUDE_MODEL '${fallback}' \u3082\u73FE\u5728\u306E\u5B9F\u884C\u7D4C\u8DEF\u3067\u306F\u89E3\u6C7A\u3067\u304D\u307E\u305B\u3093 \u2192 \u30E2\u30C7\u30EB\u3092\u6307\u5B9A\u3057\u307E\u305B\u3093`)}
|
|
17
|
+
const model=usable&&fitsRoute?requested:safeFallback;const maxTurns=cfg.maxTurnsFor(req.category,env);let effort="";switch(req.ai){case"gemini":return{file:"gemini",args:["--yolo",...model?["--model",model]:[]],env:{GEMINI_CLI_TRUST_WORKSPACE:"true"},model,effort,maxTurns,warnings};case"codex":return{file:"codex",args:["exec","-s","danger-full-access",...model?["--model",model]:[]],env:{},model,effort,maxTurns,warnings};case"copilot":{const mcp=path.join(workspace,".copilot","mcp-config.json");const args=[
|
|
18
|
+
"--allow-all"];if(fs.existsSync(mcp))args.push("--additional-mcp-config",`@${mcp}`);else warnings.push(`${mcp} \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002copilot \u306F MCP \u306A\u3057\u3067\u5B9F\u884C\u3055\u308C\u307E\u3059`);if(model)args.push("--model",model);return{file:"copilot",args,env:{},model,effort,maxTurns,warnings}}default:{if(req.ai!=="claude")warnings.push(`\u672A\u77E5\u306E AI '${req.ai}'\u3002claude \u3067\u5B9F\u884C\u3057\u307E\u3059`);const e=cfg.effortFor(req.category,
|
|
19
|
+
req.skill,env,req.effort);if(e.warning!==null)warnings.push(e.warning);effort=e.value;const args=["-p","--max-turns",String(maxTurns),"--output-format","stream-json","--verbose","--dangerously-skip-permissions"];if(model)args.push("--model",model);if(effort)args.push("--effort",effort);return{file:"claude",args,env:{},model,effort,maxTurns,warnings}}}}async function runOnce(req,deps){let metrics=null;const result=await runOnceCore(req,deps,m=>{metrics=m});return metrics===null?result:{...result,
|
|
20
|
+
metrics}}async function runOnceCore(req,deps,onMetrics){const env=deps.env??process.env;const timing=resolveTiming(deps.timing);const isClaude=isClaudeAi(req.ai);const built=buildArgs(req,deps.config,env,req.cwd);for(const w of built.warnings)deps.log(` \u8B66\u544A: ${w}`);if(built.model)deps.log(` model: ${built.model} (ai_model=${req.model||"default"}, category=${req.category})`);if(built.effort)deps.log(` effort: ${built.effort} (category=${req.category}, skill=${req.skill||"none"})`);if(built.
|
|
21
|
+
effort&&(req.effort??"").trim()===built.effort){deps.log(` effort \u6307\u5B9A\u5143: item (ai_effort=${built.effort})`)}const launch=isClaude?wrapWithAutoSwitch(deps.cas,built.file,built.args):{file:built.file,args:built.args};const slot=req.slot!==void 0?req.slot:isClaude&&deps.cas!==null?activeSlotPath(deps.cas):null;if(slot!==null)deps.log(` claude \u67A0: ${slot}`);deps.log(`${req.ai} \u5B9F\u884C: ${firstLine(req.prompt)}`);deps.log(` \u30ED\u30B0: ${req.logFile}`);const renderer=isClaude?
|
|
22
|
+
new ClaudeStreamRenderer(deps.now):null;const lines=[];let retained=0;let truncated=false;let stream=null;try{fs.mkdirSync(path.dirname(req.logFile),{recursive:true,mode:448});stream=fs.createWriteStream(req.logFile,{flags:"w",mode:384})}catch{}const emit=line=>{const clean=stripTerminalControls(line);stream?.write(`${clean}
|
|
23
|
+
`);deps.log(clean);if(retained<MAX_RETAINED_BYTES){lines.push(clean);retained+=clean.length+1}else if(!truncated){truncated=true;lines.push("\u2026\uFF08\u51FA\u529B\u304C\u4E0A\u9650\u3092\u8D85\u3048\u305F\u305F\u3081\u3001\u4EE5\u964D\u306F\u30B9\u30C6\u30C3\u30D7\u30ED\u30B0\u306B\u306E\u307F\u8A18\u9332\u3057\u307E\u3059\uFF09")}};emit(` \u30D7\u30ED\u30F3\u30D7\u30C8: ${req.prompt.length} \u6587\u5B57\uFF08stdin \u7D4C\u7531\uFF09`);const target=resolveSpawnTarget(launch.file,launch.args,
|
|
24
|
+
{env,platform:deps.platform});if(!target.ok){emit(`[twp task-loop] ${launch.file} \u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093: ${target.reason}`);deps.onProcess?.(null);await closeStream(stream);return{outcome:"unavailable",output:lines.join("\n"),exitCode:null,cooldownSec:null,slot}}if(target.note!==null)deps.log(` \u8D77\u52D5: ${target.note}`);let spawned;try{spawned=spawn(target.file,target.args,{cwd:req.cwd,env:{...env,...built.env},detached:process.platform!=="win32",stdio:["pipe","p\
|
|
25
|
+
ipe","pipe"]})}catch(e){const code=e.code??"";if(!["EINVAL","ENOENT","EACCES","ENAMETOOLONG"].includes(code))throw e;const hint=code==="ENAMETOOLONG"?`\uFF08\u30B3\u30DE\u30F3\u30C9\u30E9\u30A4\u30F3\u304C\u9577\u3059\u304E\u307E\u3059\u3002\u5B9F\u884C\u30D5\u30A1\u30A4\u30EB\uFF0B\u5F15\u6570\u3067 ${[target.file,...target.args].join(" ").length} \u6587\u5B57\u3002Windows \u306E\u4E0A\u9650\u306F 32,767 \u6587\u5B57\u3002\u30D7\u30ED\u30F3\u30D7\u30C8 ${req.prompt.length} \u6587\u5B57\u306F stdin \u7D4C\u7531\u306A\u306E\u3067\u539F\u56E0\u3067\u306F\u3042\u308A\
|
|
26
|
+
\u307E\u305B\u3093\uFF09`:"";emit(`[twp task-loop] ${launch.file} \u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093: ${e.message}${hint}`);deps.onProcess?.(null);await closeStream(stream);return{outcome:"unavailable",output:lines.join("\n"),exitCode:null,cooldownSec:null,slot}}let stdinDelivered=false;let stdinError=null;spawned.stdin.on("error",e=>{if(stdinError===null)stdinError=e.code??e.message});spawned.stdin.on("finish",()=>{stdinDelivered=true});spawned.stdin.end(req.prompt);let killedFor=null;
|
|
27
|
+
const signalTree=signal=>killProcessTree(spawned,signal,{platform:deps.platform});const killTree=()=>{signalTree("SIGKILL")};let exited=false;let markExited=()=>{};const exitedPromise=new Promise(resolve=>{markExited=()=>{exited=true;deps.onProcess?.(null);resolve()}});const waitExit=ms=>Promise.race([exitedPromise,new Promise(resolve=>{const t=setTimeout(resolve,ms);t.unref?.()})]);const abort=async()=>{if(exited||spawned.exitCode!==null||spawned.signalCode!==null)return;if(killedFor===null)killedFor=
|
|
28
|
+
"aborted";if(isForceOnly(deps.platform)){deps.log(`\u26A0\uFE0F \u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u3051\u305F\u305F\u3081 ${req.ai} \u3092\u505C\u6B62\u3057\u307E\u3059\uFF08Windows \u306F\u7336\u4E88\u3092\u7F6E\u3051\u306A\u3044\u305F\u3081 taskkill /T /F \u3067\u6728\u3054\u3068\u5F37\u5236\u7D42\u4E86\u3057\u307E\u3059\uFF09`);const how=signalTree("SIGKILL");await waitExit(timing.abortReapMs);deps.log(!exited?` \u26A0\uFE0F ${req.ai} \u304C ${timing.abortReapMs/1e3}\u79D2 \u4EE5\u5185\u306B\u6D88\u3048\u307E\u305B\
|
|
29
|
+
\u3093\u3067\u3057\u305F\u3002\u6B8B\u3063\u3066\u3044\u306A\u3044\u304B taskkill /FI \u3067\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044`:how==="taskkill"?` ${req.ai} \u306E\u30D7\u30ED\u30BB\u30B9\u6728\u3092\u5F37\u5236\u7D42\u4E86\u3057\u307E\u3057\u305F\uFF08\u5B6B\u307E\u3067 taskkill /T \u304C\u5C4A\u304D\u307E\u3057\u305F\uFF09`:` \u26A0\uFE0F ${req.ai} \u306E\u76F4\u4E0B\u306E\u30D7\u30ED\u30BB\u30B9\u3060\u3051\u3092\u7D42\u4E86\u3057\u307E\u3057\u305F\uFF08taskkill \u3092\u6483\u3066\u306A\u304B\u3063\u305F\u305F\u3081\u5B6B\u304C\u6B8B\u3063\u3066\u3044\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\uFF09`);
|
|
30
|
+
return}deps.log(`\u26A0\uFE0F \u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u3051\u305F\u305F\u3081 ${req.ai} \u3092\u505C\u6B62\u3057\u307E\u3059\uFF08SIGTERM \u2192 \u6700\u5927${timing.abortGraceMs/1e3}\u79D2 \u2192 SIGKILL\uFF09`);signalTree("SIGTERM");await waitExit(timing.abortGraceMs);deps.log(exited?` ${req.ai} \u306F\u81EA\u5206\u304B\u3089\u7D42\u4E86\u3057\u307E\u3057\u305F\u3002\u6B8B\u3063\u305F\u5B50\u5B6B\u3092\u30D7\u30ED\u30BB\u30B9\u30B0\u30EB\u30FC\u30D7\u3054\u3068\u6383\u304D\u307E\u3059`:
|
|
31
|
+
` ${req.ai} \u304C\u7336\u4E88\u5185\u306B\u7D42\u4E86\u3057\u306A\u304B\u3063\u305F\u305F\u3081\u3001\u30D7\u30ED\u30BB\u30B9\u30B0\u30EB\u30FC\u30D7\u3092\u5F37\u5236\u7D42\u4E86\u3057\u307E\u3059`);signalTree("SIGKILL");await waitExit(timing.abortReapMs)};deps.onProcess?.(abort);const started=Date.now();const feed=lineFeeder(raw=>{if(renderer===null)emit(raw);else for(const l of renderer.push(raw))emit(l)});spawned.stdout.on("data",c=>feed(c.toString("utf8")));spawned.stderr.on("data",c=>feed(
|
|
32
|
+
c.toString("utf8")));const timer=setInterval(()=>{if((Date.now()-started)/1e3>=req.timeoutSec){deps.log(`\u26A0\uFE0F ${req.ai} \u30BF\u30A4\u30E0\u30A2\u30A6\u30C8 (${Math.trunc((Date.now()-started)/1e3)}s >= ${req.timeoutSec}s) \u2192 \u30D7\u30ED\u30BB\u30B9\u3092\u5F37\u5236\u7D42\u4E86`);killedFor="timeout";killTree();return}const limited=renderer!==null?renderer.sawRateLimit():isRateLimited(recentTail(lines),req.ai);if(limited){deps.log(`\u26A0\uFE0F ${req.ai} \u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u691C\u77E5 \u2192 \u5373\u5EA7\u306B\u30D7\u30ED\u30BB\u30B9\u3092\u7D42\u4E86`);
|
|
33
|
+
killedFor="rate-limited";killTree()}},timing.pollIntervalMs);let notLaunched=false;const exitCode=await new Promise(resolve=>{spawned.on("error",e=>{notLaunched=true;emit(`[twp task-loop] ${launch.file} \u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093: ${e.message}`);markExited();resolve(null)});spawned.on("close",code=>{markExited();resolve(code)})});deps.onProcess?.(null);clearInterval(timer);feed(null);if(stdinError!==null||!stdinDelivered){const cause=killedFor!==null?`\u3053\u3061\u3089\u304C ${killedFor}\
|
|
34
|
+
\u3067\u505C\u6B62\u3055\u305B\u305F\u305F\u3081`:notLaunched?"\u8D77\u52D5\u3067\u304D\u306A\u304B\u3063\u305F\u305F\u3081":exitCode===null?`AI \u304C signal\uFF08${spawned.signalCode??"\u4E0D\u660E"}\uFF09\u3067\u843D\u3061\u305F\u305F\u3081`:exitCode!==0?`AI \u304C\u7D42\u4E86\u30B3\u30FC\u30C9 ${exitCode} \u3067\u5148\u306B\u7D42\u308F\u3063\u305F\u305F\u3081`:"AI \u304C stdin \u3092\u8AAD\u307F\u5207\u3089\u306A\u304B\u3063\u305F\u305F\u3081";emit(`[twp task-loop] ${req.ai} \u3078\u30D7\u30ED\u30F3\u30D7\u30C8 ${req.
|
|
35
|
+
prompt.length} \u6587\u5B57\u3092\u9001\u308A\u5207\u308C\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${cause}${stdinError===null?"":`\u30FB${stdinError}`}\uFF09`)}await closeStream(stream);const output=lines.join("\n");const scan=tailForScan(output);onMetrics({turns:renderer?.result.numTurns??null,tokensIn:renderer?.result.tokensIn??null,tokensOut:renderer?.result.tokensOut??null,costUsd:renderer?.result.costUsd??null,effort:built.effort===""?null:built.effort});const fatalText=exitCode!==0&&isCliFatalText(
|
|
36
|
+
renderer?.result.finalText??"")?renderer?.result.finalText??"":"";if(killedFor==="aborted"){return{outcome:"aborted",output,exitCode,cooldownSec:null,slot}}const untrusted=isClaude&&isUntrusted(scan);if(untrusted){deps.log("\u26A0\uFE0F claude: \u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u672A\u30C8\u30E9\u30B9\u30C8\u306E\u8B66\u544A\u304C\u51FA\u3066\u3044\u307E\u3059\uFF08permissions.allow \u306F\u7121\u8996\u3055\u308C\u308B\u304C\u5B9F\u884C\u81EA\u4F53\u306F\u901A\u308B\u3002hasTrustDialogAccepted \u3092\u7ACB\u3066\u308B\u3053\u3068\uFF09")}
|
|
37
|
+
const structuredLimited=renderer?.result.rateLimited===true;const textLimited=renderer!==null?exitCode!==0&&isRateLimited(scan,req.ai):isRateLimited(scan,req.ai);const fatalLimited=fatalText!==""&&isRateLimited(fatalText,req.ai);if(killedFor==="rate-limited"||structuredLimited||textLimited||fatalLimited){return{outcome:"rate-limited",output,exitCode,cooldownSec:cooldownFrom(renderer,`${scan}
|
|
38
|
+
${fatalText}`,deps.now?.()??new Date),slot}}if(killedFor==="timeout")return{outcome:"timeout",output,exitCode,cooldownSec:null,slot};if(exitCode!==0&&(isAuthError(scan)||fatalText!==""&&isAuthError(fatalText))){deps.log(`\u26A0\uFE0F ${req.ai} \u8A8D\u8A3C\u30A8\u30E9\u30FC\u3092\u691C\u77E5\u3057\u307E\u3057\u305F\uFF08\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\u5BFE\u8C61\uFF09`);return{outcome:"auth-error",output,exitCode,cooldownSec:null,slot}}if(isClaude&&exitCode!==0){const byEvent=renderer?.
|
|
39
|
+
result.subtype==="error_max_turns";if(byEvent||maxTurnsReached(output,built.maxTurns)){deps.log(`\u26A0\uFE0F claude \u30BF\u30FC\u30F3\u4E0A\u9650(${built.maxTurns})\u5230\u9054\u3067\u6253\u3061\u5207\u3089\u308C\u307E\u3057\u305F\uFF08\u672A\u5B8C\u4E86\u306E\u53EF\u80FD\u6027\u304C\u9AD8\u3044\uFF09`);return{outcome:"max-turns",output,exitCode,cooldownSec:null,slot}}}if(notLaunched){deps.log(`\u26D4 ${req.ai} \u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u672A\u5C0E\u5165\u30FB\u5B9F\u884C\u6A29\u30FB\u30E9\u30C3\u30D1\u306E\u7834\u640D\u306E\u3044\u305A\u308C\u304B\uFF09`);
|
|
40
|
+
return{outcome:"unavailable",output,exitCode,cooldownSec:null,slot}}if(untrusted&&exitCode!==0){deps.log("\u26D4 claude: \u672A\u30C8\u30E9\u30B9\u30C8\u306E\u307E\u307E\u5931\u6557\u3057\u307E\u3057\u305F\uFF08permissions.allow \u7121\u8996\u304C\u539F\u56E0\u306E\u53EF\u80FD\u6027\uFF09");return{outcome:"untrusted",output,exitCode,cooldownSec:null,slot}}if(exitCode===0&&!stdinDelivered){deps.log(`\u26D4 ${req.ai} \u306F\u7D42\u4E86\u30B3\u30FC\u30C90\u3067\u7D42\u308F\u308A\u307E\u3057\u305F\u304C\u3001\u30D7\u30ED\u30F3\u30D7\u30C8 ${req.
|
|
41
|
+
prompt.length} \u6587\u5B57\u3092\u9001\u308A\u5207\u308C\u3066\u3044\u307E\u305B\u3093\uFF08\u5207\u308A\u8A70\u307E\u3063\u305F\u6307\u793A\u3067\u8D70\u3063\u305F\u53EF\u80FD\u6027\u304C\u3042\u308B\u305F\u3081\u6210\u529F\u3068\u3057\u3066\u6271\u3044\u307E\u305B\u3093\uFF09`);return{outcome:"failed",output,exitCode,cooldownSec:null,slot}}return{outcome:exitCode===0?"ok":"failed",output,exitCode,cooldownSec:null,slot}}function cooldownFrom(renderer,scan,now){const resets=renderer?.result.resetsAt??
|
|
42
|
+
null;if(resets!==null){const wait=Math.trunc((resets*1e3-now.getTime())/1e3);if(wait>0)return wait+30}return rateLimitWaitSeconds(scan,now)}function lineFeeder(onLine){let buffer="";return chunk=>{if(chunk===null){if(buffer!=="")onLine(buffer);buffer="";return}buffer+=chunk;const parts=buffer.split("\n");buffer=parts.pop()??"";for(const p of parts)onLine(p)}}function firstLine(prompt){return(prompt.split("\n")[0]??"").slice(0,80)}function recentTail(lines){let size=0;let from=lines.length;while(from>
|
|
43
|
+
0&&size<64*1024){from-=1;size+=(lines[from]??"").length+1}return lines.slice(from).join("\n")}function sleepSync(ms){const shared=new Int32Array(new SharedArrayBuffer(4));Atomics.wait(shared,0,0,ms)}var DEFAULT_CHARTER_PREFIX="===== \u4EE5\u4E0B\u306F\u958B\u767A\u61B2\u7AE0\u3067\u3059\u3002\u5168\u3066\u306E\u5224\u65AD\u306E\u6700\u4E0A\u4F4D\u57FA\u6E96\u3067\u3042\u308A\u3001\u500B\u5225\u30B9\u30AD\u30EB\u306E\u624B\u9806\u3068\u77DB\u76FE\u3059\u308B\u5834\u5408\u306F\u672C\u61B2\u7AE0\u304C\u512A\u5148\u3057\u307E\u3059\u3002\u884C\u52D5\u3059\u308B\u524D\u306B\u3001\u305D\u306E\u884C\u52D5\u304C\u61B2\u7AE0\u306E\u76EE\u7684\u306B\u5BC4\u4E0E\u3059\u308B\u304B\u3092\u81EA\u3089\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002 =====";
|
|
44
|
+
var DEFAULT_CHARTER_SUFFIX="===== \u958B\u767A\u61B2\u7AE0\u3053\u3053\u307E\u3067\u3002\u4EE5\u4E0B\u304C\u4ECA\u56DE\u306E\u30BF\u30B9\u30AF\u6307\u793A\u3067\u3059\u3002 =====";function wrapCharter(prefix,body,suffix){const parts=[];if(prefix!=="")parts.push(prefix);parts.push(body);if(suffix!=="")parts.push(suffix);return parts.join("\n\n")}var UNKNOWN_SLOT="(unresolved)";var FAST_FAIL_SEC=60;var FAST_FAIL_STREAK=3;var HEALTH_PROBE_AIS=["codex","gemini","copilot"];var HEALTH_PROBE_TTL_MS=1800*
|
|
45
|
+
1e3;var HEALTH_PROBE_TIMEOUT_SEC=60;var HEALTH_PROBE_PROMPT="Health check. Do not read or modify any files and do not run any commands. Reply with exactly: OK";var DispatchEngine=class{constructor(cfg,log,opts){this.cfg=cfg;this.log=log;this.opts=opts}cfg;log;opts;name="cli";cas=null;casDetected=false;slotResolved=new Map;lastSlot=new Map;charterWarned=false;unusable=null;activeAbort=null;aborting=false;unusableAt=0;fastFailStreak=new Map;healthyAt=new Map;launcherBin(){const v=this.opts.launcherBin?.
|
|
46
|
+
trim();return v===void 0||v===""?DEFAULT_CLAUDE_LAUNCHER.bin:v}async run(req){this.slotResolved.clear();if(this.aborting){this.log("\u26D4 \u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u3051\u3066\u3044\u308B\u305F\u3081 AI \u3092\u8D77\u52D5\u3057\u307E\u305B\u3093");return{outcome:"aborted",usedAi:"",serverAiType:null,output:"\uFF08\u4E2D\u65AD\u306E\u305F\u3081\u672A\u5B9F\u884C\uFF09"}}const env=this.opts.env??process.env;const skill=req.skill??"";const category=req.category??this.cfg.categoryForSkill(
|
|
47
|
+
skill);if(!this.preflightOk()){this.log("\u26D4 \u30DB\u30B9\u30C8\u5074\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u304C\u5230\u9054\u4E0D\u80FD\u3067\u3059\uFF08\u5168\u30DB\u30B9\u30C8\uFF09\u3002\u3053\u306E\u30A2\u30A4\u30C6\u30E0\u3067\u306F AI \u3092\u8D77\u52D5\u3057\u307E\u305B\u3093");return{outcome:"network-down",usedAi:"",serverAiType:null,output:"\uFF08\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u5230\u9054\u4E0D\u80FD\u306E\u305F\u3081\u672A\u5B9F\u884C\uFF09"}}if(!this.casDetected){this.cas=
|
|
48
|
+
this.opts.detect!==void 0?this.opts.detect():detectClaudeAutoSwitch(this.launcherBin());this.casDetected=true;this.log(this.cas===null?` ${this.launcherBin()}: \u672A\u5C0E\u5165\uFF08claude \u3092\u7D20\u3067\u8D77\u52D5\u3057\u307E\u3059\uFF09`:` ${this.launcherBin()}: \u691C\u51FA\uFF08exec ${this.cas.hasExec?"\u3042\u308A \u2192 \u7D4C\u7531\u3057\u3066\u8D77\u52D5\u3057\u307E\u3059":"\u7121\u3057 \u2192 \u7D20\u3067\u8D77\u52D5\u3057\u307E\u3059\uFF08\u66F4\u65B0\u3092\u63A8\u5968\uFF09"}\
|
|
49
|
+
\uFF09`)}const tried=[];let sawRateLimit=false;let sawTimeout=false;let sawFastFail=false;let sawUnavailable=false;let ranAny=false;let skippedForCooldown=false;let lastOutput="";let lastValidated=true;const requested=this.orderFor(category,skill,req.aiType);const head=requested[0]??"";const order=this.usableOrder(requested,category,skill);for(const ai of order){if(tried.includes(ai))continue;if(!this.cfg.isAllowed(ai,category,skill)){this.log(` ${ai} \u306F category=${category} / skill=${skill||
|
|
50
|
+
"none"} \u306E\u5B9F\u884C\u5BFE\u8C61\u5916\u306E\u305F\u3081\u30B9\u30AD\u30C3\u30D7`);continue}const slotFor=()=>{if(!isClaudeAi(ai))return null;if(this.cas===null)return null;if(this.slotResolved.has(ai))return this.slotResolved.get(ai)??null;const resolved=(this.opts.activeSlot??activeSlotPath)(this.cas);const effective=resolved??this.lastSlot.get(ai)??UNKNOWN_SLOT;if(resolved!==null)this.lastSlot.set(ai,resolved);else this.log(` ${ai} \u306E\u67A0\u3092\u89E3\u6C7A\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${this.
|
|
51
|
+
launcherBin()} ${DEFAULT_CLAUDE_LAUNCHER.activeArgs.join(" ")}\uFF09\u3002${effective} \u3068\u3057\u3066\u6271\u3044\u307E\u3059`);this.slotResolved.set(ai,effective);return effective};const slotNow=this.cfg.hasCooldownFor(ai,this.now())?slotFor():null;if(this.cfg.isRateLimited(ai,this.now(),slotNow)){skippedForCooldown=true;this.log(` ${ai} \u306F\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u4E2D\u306E\u305F\u3081\u30B9\u30AD\u30C3\u30D7`);continue}const isHead=tried.length===0&&ai===head;this.
|
|
52
|
+
log(isHead?` AI\u9078\u629E: ${ai} (preferred) [category=${category}]`:` \u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF: ${ai} [category=${category}]`);const prompt=this.buildPrompt(req.prompt,req.promptPrefix,ai,tried);const logFile=tried.length===0?req.logFile:req.logFile.replace(/\.log$/,`-fallback-${ai}.log`);if(this.aborting){this.log(` \u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u3051\u3066\u3044\u308B\u305F\u3081 ${ai} \u306F\u8D77\u52D5\u3057\u307E\u305B\u3093`);return{outcome:"abort\
|
|
53
|
+
ed",usedAi:tried[tried.length-1]??"",serverAiType:null,output:lastOutput}}ranAny=true;const startedAt=this.now();const result=await(this.opts.runOnce??runOnce)({ai,prompt,logFile,cwd:req.cwd,timeoutSec:req.timeoutSec,category,skill,slot:slotFor(),model:isHead?req.aiModel:void 0,effort:req.aiEffort},{config:this.cfg,cas:this.cas,log:this.log,env,now:this.opts.now,onProcess:abort=>{this.activeAbort=abort;if(abort!==null&&this.aborting)void abort()}});lastOutput=result.output;tried.push(ai);const elapsedMs=this.
|
|
54
|
+
now()-startedAt;const elapsedSec=Math.round(elapsedMs/1e3);if(result.outcome==="failed"&&result.exitCode!==0&&elapsedMs>=0&&elapsedSec<FAST_FAIL_SEC){sawFastFail=true;const streak=(this.fastFailStreak.get(ai)??0)+1;this.fastFailStreak.set(ai,streak);this.log(` ${ai} \u304C ${elapsedSec}\u79D2\u3067\u5931\u6557\u3057\u307E\u3057\u305F\uFF08AI \u304C\u4ED5\u4E8B\u3092\u59CB\u3081\u308B\u524D\u306B\u843D\u3061\u305F\u53EF\u80FD\u6027\uFF09 \u2192 \u6B21\u306EAI\u306B\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF`);
|
|
55
|
+
if(streak>=FAST_FAIL_STREAK){const sec=this.cfg.markAiUnusable(ai,this.now());this.fastFailStreak.delete(ai);this.log(` ${ai} \u306F\u8D77\u52D5\u76F4\u5F8C\u306E\u5931\u6557\u304C${streak}\u56DE\u7D9A\u3044\u3066\u3044\u307E\u3059 \u2192 ${sec}\u79D2\u9593\u306F\u9396\u304B\u3089\u5916\u3057\u307E\u3059\uFF08\u540C\u3058\u58C1\u306B\u5F8C\u7D9A\u30A2\u30A4\u30C6\u30E0\u3092\u5F53\u3066\u306A\u3044\u305F\u3081\u3002\u76F4\u8FD1\u306E\u51FA\u529B: ${failureHint(result.output)||"(\u7406\u7531\u884C\u306A\u3057)"}\
|
|
56
|
+
\uFF09`)}continue}if(!["rate-limited","auth-error","unavailable"].includes(result.outcome)){this.fastFailStreak.delete(ai)}if(!["rate-limited","auth-error","timeout","unavailable"].includes(result.outcome)){if(result.outcome==="ok"&&req.validate!==void 0){if(req.validate(result.output)){this.log(` ${ai} \u304B\u3089\u5B9F\u884C\u8A08\u753BJSON\u3092\u53D6\u5F97\u3057\u307E\u3057\u305F`)}else{this.log(` ${ai}: \u5B9F\u884C\u8A08\u753B\u306EJSON\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093 \u2192 \u6B21\u306EAI\u306B\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF`);
|
|
57
|
+
lastValidated=false;continue}}return this.finish(result.outcome,ai,result.output,result.metrics)}if(result.outcome==="rate-limited"){sawRateLimit=true;const seconds=result.cooldownSec??this.cfg.cooldownDefaultSec(ai,env);const slotUsed=slotFor();const capped=this.cfg.markRateLimited(ai,seconds,this.now(),slotUsed);this.log(` ${ai} \u3092\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u3068\u3057\u3066\u30DE\u30FC\u30AF (${capped}\u79D2\u9593${slotUsed===null?"":` / \u67A0 ${slotUsed}`})`);await this.
|
|
58
|
+
waitBeforeFallback(ai,env)}else if(result.outcome==="timeout"){sawTimeout=true;this.log(` ${ai} \u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8 \u2192 \u6B21\u306EAI\u306B\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF`)}else if(result.outcome==="unavailable"){sawUnavailable=true;const sec=this.cfg.markAiUnusable(ai,this.now());this.log(` ${ai} \u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093 \u2192 \u6B21\u306EAI\u306B\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\uFF08${sec}\u79D2\u9593\u306F\u9396\u304B\u3089\u5916\u3057\u307E\u3059\uFF09`)}else{
|
|
59
|
+
sawUnavailable=true;const sec=this.cfg.markAiUnusable(ai,this.now());this.log(` ${ai} \u306E\u8A8D\u8A3C\u30A8\u30E9\u30FC \u2192 \u6B21\u306EAI\u306B\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\uFF08${sec}\u79D2\u9593\u306F\u9396\u304B\u3089\u5916\u3057\u307E\u3059\uFF09`)}}if(!lastValidated&&!sawRateLimit&&ranAny){this.log("\u26A0\uFE0F \u3069\u306EAI\u304B\u3089\u3082\u5B9F\u884C\u8A08\u753BJSON\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F");return{outcome:"ok",usedAi:tried[tried.
|
|
60
|
+
length-1]??"",serverAiType:null,output:lastOutput}}if(!ranAny){if(skippedForCooldown){this.log("\u26A0\uFE0F \u5168AI\u304C\u30AF\u30FC\u30EB\u30C0\u30A6\u30F3\u4E2D\u30671\u3064\u3082\u5B9F\u884C\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u5F85\u6A5F\u3057\u3066\u518D\u8A66\u884C\u3057\u307E\u3059\uFF09");return{outcome:"rate-limited",usedAi:"",serverAiType:null,output:lastOutput}}this.log("\u26A0\uFE0F \u5B9F\u884C\u3067\u304D\u308BAI\u304C\u9396\u306B1\u3064\u3082\u3042\u308A\u307E\u305B\u3093\uFF08\u672A\u30ED\u30B0\u30A4\u30F3\u30FB\u30AB\u30C6\u30B4\u30EA\u8A2D\u5B9A\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\uFF09");
|
|
61
|
+
return{outcome:"unavailable",usedAi:"",serverAiType:null,output:lastOutput}}if(sawTimeout){this.log("\u26A0\uFE0F \u5168AI\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u307E\u305F\u306F\u8A8D\u8A3C\u30A8\u30E9\u30FC\u3067\u3059\uFF08\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u3067\u306F\u306A\u3044\u306E\u3067\u901A\u5E38\u5931\u6557\u3068\u3057\u3066\u6271\u3044\u307E\u3059\uFF09");return{outcome:"timeout",usedAi:tried[tried.length-1]??"",serverAiType:null,output:lastOutput}}if(sawRateLimit){this.
|
|
62
|
+
log("\u26A0\uFE0F \u5168AI\u304C\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u3067\u3059");return{outcome:"rate-limited",usedAi:"",serverAiType:null,output:lastOutput}}if(sawFastFail&&!sawUnavailable){this.log("\u26A0\uFE0F \u5168AI\u304C\u8D77\u52D5\u76F4\u5F8C\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08\u901A\u5E38\u5931\u6557\u3068\u3057\u3066\u6271\u3044\u307E\u3059\uFF09");return this.finish("failed",tried[tried.length-1]??"",lastOutput)}this.log("\u26A0\uFE0F \u5168AI\u304C\u8A8D\u8A3C\u30A8\u30E9\u30FC\u307E\u305F\u306F\u8D77\u52D5\u4E0D\u80FD\u3067\u3059\uFF081\u884C\u3082\u5B9F\u884C\u3057\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u5931\u6557\u3067\
|
|
63
|
+
\u306F\u306A\u304F\u672A\u5B9F\u884C\u3068\u3057\u3066\u6271\u3044\u307E\u3059\uFF09");return{outcome:"unavailable",usedAi:tried[tried.length-1]??"",serverAiType:null,output:lastOutput}}async healthCheck(ctx){const results=[];if(this.aborting)return results;const targets=HEALTH_PROBE_AIS.flatMap(ai=>{const category=this.cfg.probeCategoryFor(ai);return category===null?[]:[{ai,category}]});if(targets.length===0)return results;if(!this.preflightOk()){for(const{ai}of targets)results.push({ai,verdict:"\
|
|
64
|
+
skipped",reason:"\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u5230\u9054\u4E0D\u80FD",elapsedSec:null});this.logHealth(results);return results}const env=this.opts.env??process.env;const detected=this.detectUnusable();for(const{ai,category}of targets){const now=this.now();if(detected.get(ai)?.hard===true){results.push({ai,verdict:"skipped",reason:"\u672A\u5C0E\u5165",elapsedSec:null});continue}if(this.cfg.isAiUnusable(ai,now)||this.cfg.isRateLimited(ai,now)){results.push({ai,verdict:"skipped",reason:"\u9664\u5916\
|
|
65
|
+
\u4E2D\uFF08\u671F\u9650\u660E\u3051\u306B\u518D\u691C\u67FB\uFF09",elapsedSec:null});continue}const last=this.healthyAt.get(ai);if(last!==void 0&&now-last>=0&&now-last<HEALTH_PROBE_TTL_MS){results.push({ai,verdict:"skipped",reason:"\u76F4\u8FD1\u306B\u5065\u5168",elapsedSec:null});continue}if(this.aborting)break;const startedAt=this.now();let result;try{result=await(this.opts.runOnce??runOnce)({ai,prompt:HEALTH_PROBE_PROMPT,logFile:`${ctx.logFilePrefix}-${ai}.log`,cwd:ctx.cwd,timeoutSec:HEALTH_PROBE_TIMEOUT_SEC,
|
|
66
|
+
category,skill:""},{config:this.cfg,cas:this.cas,log:this.log,env,now:this.opts.now,onProcess:abort=>{this.activeAbort=abort;if(abort!==null&&this.aborting)void abort()}})}catch(err){results.push({ai,verdict:"inconclusive",reason:`\u691C\u67FB\u304C\u4F8B\u5916\u3067\u7D42\u4E86\uFF08${err.message}\uFF09`,elapsedSec:null});continue}const elapsedMs=this.now()-startedAt;const elapsedSec=Math.round(elapsedMs/1e3);const hint=failureHint(result.output)||"(\u7406\u7531\u884C\u306A\u3057)";if(result.outcome===
|
|
67
|
+
"ok"){this.healthyAt.set(ai,this.now());this.fastFailStreak.delete(ai);results.push({ai,verdict:"healthy",reason:"\u5FDC\u7B54\u3042\u308A",elapsedSec})}else if(result.outcome==="rate-limited"){const sec=this.cfg.markRateLimited(ai,result.cooldownSec??this.cfg.cooldownDefaultSec(ai,env),this.now());this.healthyAt.delete(ai);results.push({ai,verdict:"unhealthy",reason:`\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u30FB\u5229\u7528\u4E0A\u9650\uFF08${sec}\u79D2\u9593\u5916\u3057\u307E\u3059: ${hint}\
|
|
68
|
+
\uFF09`,elapsedSec})}else if(result.outcome==="auth-error"||result.outcome==="unavailable"){const sec=this.cfg.markAiUnusable(ai,this.now());this.healthyAt.delete(ai);results.push({ai,verdict:"unhealthy",reason:`${result.outcome==="auth-error"?"\u8A8D\u8A3C\u30A8\u30E9\u30FC":"\u8D77\u52D5\u4E0D\u80FD"}\uFF08${sec}\u79D2\u9593\u5916\u3057\u307E\u3059: ${hint}\uFF09`,elapsedSec})}else if(result.outcome==="failed"&&result.exitCode!==0&&elapsedMs>=0&&elapsedSec<FAST_FAIL_SEC){const sec=this.cfg.markAiUnusable(
|
|
69
|
+
ai,this.now());this.fastFailStreak.delete(ai);this.healthyAt.delete(ai);results.push({ai,verdict:"unhealthy",reason:`${elapsedSec}\u79D2\u3067\u7570\u5E38\u7D42\u4E86\uFF08${sec}\u79D2\u9593\u5916\u3057\u307E\u3059: ${hint}\uFF09`,elapsedSec})}else{results.push({ai,verdict:"inconclusive",reason:`${result.outcome}\uFF08\u5916\u3057\u307E\u305B\u3093\uFF09`,elapsedSec})}}this.activeAbort=null;this.logHealth(results);return results}logHealth(results){const label={healthy:"\u5065\u5168",unhealthy:"\u4E0D\
|
|
70
|
+
\u5065\u5168",skipped:"\u691C\u67FB\u7701\u7565",inconclusive:"\u5224\u5B9A\u4E0D\u80FD"};for(const r of results){this.log(` AI\u30D8\u30EB\u30B9\u30C1\u30A7\u30C3\u30AF: ${r.ai} ${label[r.verdict]}\uFF08${r.reason}${r.elapsedSec===null?"":`\u30FB${r.elapsedSec}\u79D2`}\uFF09`)}}async abort(){this.aborting=true;const abort=this.activeAbort;if(abort===null)return false;await abort();return true}now(){return(this.opts.now??(()=>new Date))().getTime()}usableOrder(order,category,skill){const detected=this.
|
|
71
|
+
detectUnusable();const unique=[...new Set(order)];const kept=[];const soft=[];const dropped=[];for(const ai of unique){const hit=this.cfg.isAiUnusable(ai,this.now())?{why:"\u76F4\u8FD1\u306E\u8A8D\u8A3C\u30A8\u30E9\u30FC\u30FB\u8D77\u52D5\u5931\u6557\u30FB\u8D77\u52D5\u76F4\u5F8C\u306E\u5931\u6557\u306E\u9023\u7D9A",hard:false}:detected.get(ai);if(hit===void 0){kept.push(ai);continue}dropped.push(`${ai}\uFF08${hit.why}\uFF09`);if(!hit.hard)soft.push(ai)}if(dropped.length===0)return unique;const canRun=list=>list.
|
|
72
|
+
some(ai=>this.cfg.isAllowed(ai,category,skill));if(!canRun(kept)&&canRun(soft)){this.log(` \u26A0\uFE0F \u9396\u306B\u5B9F\u884C\u3067\u304D\u308B AI \u304C\u6B8B\u308A\u307E\u305B\u3093\uFF08\u9664\u5916\u5019\u88DC: ${dropped.join(" / ")}\uFF09`);this.log(" \u63A8\u5B9A\u3067\u5916\u3057\u305F\u3082\u306E\u306F\u5224\u5B9A\u304C\u8AA4\u3063\u3066\u3044\u308B\u53EF\u80FD\u6027\u304C\u3042\u308B\u305F\u3081\u3001\u9396\u3078\u623B\u3057\u307E\u3059\uFF08fail-open\uFF09");return unique.filter(
|
|
73
|
+
ai=>kept.includes(ai)||soft.includes(ai))}this.log(` \u9396\u304B\u3089\u9664\u5916: ${dropped.join(" / ")}`);if(kept.length===0){this.log(" \u9396\u306B\u8D77\u52D5\u3067\u304D\u308B AI \u304C1\u3064\u3082\u6B8B\u308A\u307E\u305B\u3093\uFF08\u672A\u5C0E\u5165\u306E AI \u3092\u8D77\u52D5\u3057\u3066\u3082\u5FC5\u305A\u5931\u6557\u3057\u307E\u3059\uFF09")}return kept}detectUnusable(){const now=this.now();if(this.unusable!==null&&now-this.unusableAt<DETECT_CACHE_MS)return this.unusable;const map=new Map;
|
|
74
|
+
this.unusable=map;this.unusableAt=now;try{for(const d of(this.opts.detectClis??detectAiClis)({env:this.opts.env??process.env,launcherBin:this.launcherBin()})){if(!d.installed)map.set(d.ai,{why:"PATH \u306B\u7121\u3044\uFF08\u672A\u5C0E\u5165\uFF09",hard:true});else if(d.auth==="unauthenticated")map.set(d.ai,{why:"\u672A\u30ED\u30B0\u30A4\u30F3",hard:false})}}catch(err){this.log(` \u26A0\uFE0F AI CLI \u306E\u691C\u51FA\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${err.message}\uFF09\u3002\u9396\u306F\u305D\u306E\u307E\u307E\u4F7F\u3044\u307E\u3059`);
|
|
75
|
+
map.clear()}return map}orderFor(category,skill,preferred){const chain=this.cfg.chainFor(category);const head=preferred&&preferred.trim()!==""?preferred.trim():this.cfg.selectPrimary(category,skill,"P2","");return head===""?chain:[head,...chain]}finish(outcome,ai,output,metrics){const serverAiType=isServerAiType(ai)?ai:null;return metrics===void 0?{outcome,usedAi:ai,serverAiType,output}:{outcome,usedAi:ai,serverAiType,output,metrics}}async waitBeforeFallback(ai,env){const delay=this.cfg.fallbackDelaySec(
|
|
76
|
+
ai,env);if(delay<=0)return;this.log(` \u23F3 ${ai} \u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8 \u2192 \u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\u524D\u306B ${delay}\u79D2 \u5F85\u6A5F\uFF08\u4ED6AI\u3078\u306E\u8EE2\u5AC1\u3092\u6291\u5236\uFF09`);const sleep=this.opts.sleep??(ms=>new Promise(r=>setTimeout(r,ms)));await sleep(delay*1e3)}buildPrompt(body,promptPrefix,ai,tried){const expanded=this.expandForNonClaude(body,ai);const parts=[];if(tried.length>0)parts.push(fallbackNote(tried));const charter=this.
|
|
77
|
+
charter();if(charter!==null)parts.push(charter);if(promptPrefix!==void 0&&promptPrefix!=="")parts.push(promptPrefix);parts.push(expanded);return parts.join("\n\n")}expandForNonClaude(prompt,ai){const cmd=this.opts.compileCommand;if(ai==="claude"||cmd===void 0||cmd.length===0)return prompt;const[file,...args]=cmd;if(file===void 0)return prompt;const compileEnv={...this.opts.env??process.env};const resolved=process.platform!=="win32"||isWindowsDriveAbsolute(file)?file:findExecutable(file,{env:compileEnv,
|
|
78
|
+
platform:"win32"});if(resolved===null)return prompt;const r=spawnSync(resolved,[...args,"--provider",ai,"--project-dir",this.opts.workspace],{encoding:"utf8",env:{...this.opts.env??process.env,_AI_PROMPT:prompt},timeout:6e4,maxBuffer:32*1024*1024});const out=(r.stdout??"").trim();if(r.error!==void 0||r.status!==0||out===""){this.log(` \u26A0\uFE0F ${ai} \u5411\u3051\u306E\u30B9\u30AD\u30EB\u5C55\u958B\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08\u672A\u5C55\u958B\u306E\u307E\u307E\u5B9F\u884C\u3057\u307E\u3059\uFF09`);
|
|
79
|
+
return prompt}return out}charter(){if(this.opts.charterEnabled===false)return null;const server=this.opts.serverPrompts?.()??{};const prefix=server.charter_prefix??this.opts.charterPrefix??DEFAULT_CHARTER_PREFIX;const suffix=server.charter_suffix??this.opts.charterSuffix??DEFAULT_CHARTER_SUFFIX;if(server.charter!==void 0){return server.charter===""?null:wrapCharter(prefix,server.charter,suffix)}const file=this.opts.charterFile;if(file===void 0||file.trim()==="")return null;const resolved=path2.isAbsolute(
|
|
80
|
+
file)?file:path2.resolve(this.opts.workspace,file);let body;try{body=fs2.readFileSync(resolved,"utf8")}catch{if(!this.charterWarned){this.charterWarned=true;this.log(` \u26A0\uFE0F\u26A0\uFE0F \u61B2\u7AE0\u3092\u6CE8\u5165\u3067\u304D\u307E\u305B\u3093\uFF08${resolved} \u304C\u8AAD\u3081\u306A\u3044\uFF09\u3002\u4EE5\u5F8C\u306E\u5B9F\u884C\u306F\u61B2\u7AE0\u306A\u3057\u3067\u9032\u307F\u307E\u3059`);this.log(" \u30D5\u30A1\u30A4\u30EB\u306E\u79FB\u52D5\u30FB\u6539\u540D\u30FB\u6A29\u9650\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u8A2D\u5B9A: charter_file / CHARTER_FILE\uFF09")}
|
|
81
|
+
return null}return wrapCharter(prefix,body,suffix)}preflightOk(){const env=this.opts.env??process.env;if((env.PREFLIGHT_ENABLED??"true")!=="true")return true;const hosts=this.opts.preflightHosts??DEFAULT_PREFLIGHT_HOSTS;if(hosts.length===0)return true;const timeout=Number.parseInt(env.PREFLIGHT_TIMEOUT??"",10);const sec=Number.isInteger(timeout)&&timeout>0?timeout:5;for(let attempt=0;attempt<2;attempt+=1){if(attempt>0)sleepSync(2e3);for(const host of hosts){const nul=process.platform==="win32"?"\
|
|
82
|
+
NUL":"/dev/null";const curl=process.platform==="win32"?system32(process.env,"curl.exe"):"curl";if(curl===null)return false;const r=spawnSync(curl,["-sS","--max-time",String(sec),"-o",nul,`https://${host}/`],{encoding:"utf8",timeout:(sec+5)*1e3});if(r.error===void 0&&r.status===0)return true}}return false}};var DETECT_CACHE_MS=1800*1e3;var DEFAULT_PREFLIGHT_HOSTS=["api.anthropic.com","github.com"];function fallbackNote(tried){return["\u3010\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\u5B9F\u884C\u306B\u3064\u3044\u3066\u306E\u6CE8\u610F\u3011",
|
|
83
|
+
`\u3053\u306E\u30BF\u30B9\u30AF\u306F\u5225\u306EAI\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\uFF08${tried.join(", ")}\uFF09\u304C\u5148\u306B\u8A66\u884C\u3057\u307E\u3057\u305F\u304C\u3001\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u3001\u8A8D\u8A3C\u30A8\u30E9\u30FC\u3001\u307E\u305F\u306F\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u306B\u3088\u308A\u5B8C\u4E86\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002`,"\u524D\u306EAI\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u304C\u30BF\u30B9\u30AF\u306E\u9014\u4E2D\u307E\u3067\u4F5C\u696D\u3092\u9032\u3081\u3066\u3044\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002\u7279\u306B\u4EE5\u4E0B\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044:",
|
|
84
|
+
"- TWP\u30BF\u30B9\u30AF\u306E\u30B9\u30C6\u30FC\u30BF\u30B9\u304C\u300C\u9032\u884C\u4E2D\u300D\u306B\u5909\u66F4\u3055\u308C\u3066\u3044\u306A\u3044\u304B\uFF08\u5909\u66F4\u3055\u308C\u3066\u3044\u308B\u5834\u5408\u306F\u305D\u306E\u307E\u307E\u7D99\u7D9A\uFF09","- \u30B3\u30E1\u30F3\u30C8\u304C\u9014\u4E2D\u307E\u3067\u6295\u7A3F\u3055\u308C\u3066\u3044\u306A\u3044\u304B","- \u30D6\u30E9\u30F3\u30C1\u3084PR\u304C\u4F5C\u6210\u9014\u4E2D\u3067\u306A\u3044\u304B","\u307E\u305A\u73FE\u72B6\u3092\u78BA\u8A8D\u3057\u3066\u304B\u3089\u3001\u4E2D\u65AD\u3055\u308C\u305F\u7B87\u6240\u304B\u3089\u4F5C\u696D\u3092\u518D\u958B\u3057\u3066\u304F\
|
|
85
|
+
\u3060\u3055\u3044\u3002"].join("\n")}export{DEFAULT_CHARTER_PREFIX,DEFAULT_CHARTER_SUFFIX,DEFAULT_PREFLIGHT_HOSTS,DispatchEngine};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{CommandModelMissingError,MAX_REPORTED_VIOLATIONS,loadCommandModelDomain,loadCommandModelRoutes,validateBody,validateQuery}from"./chunk-NZ7WI4RZ.js";import{NO_REDACT_FLAG,NO_REDACT_NOTICE,exitCodeFor,fetchAllPages,reportError}from"./chunk-
|
|
3
|
+
import{CommandModelMissingError,MAX_REPORTED_VIOLATIONS,loadCommandModelDomain,loadCommandModelRoutes,validateBody,validateQuery}from"./chunk-NZ7WI4RZ.js";import{NO_REDACT_FLAG,NO_REDACT_NOTICE,exitCodeFor,fetchAllPages,reportError}from"./chunk-4F4Q6AES.js";import{parseOperationArgs,repeatedValues}from"./chunk-IOGVQVGD.js";import{renderOutput}from"./chunk-5Q2CH4E7.js";import{redactSecretValues,withDebug}from"./chunk-YVAN3H5W.js";import{readBody}from"./chunk-HGTG5XQ7.js";
|
|
4
4
|
import{DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,envelopePaging,positiveInteger,readEnvelopeCursor,shellQuote}from"./chunk-G4OO4M44.js";import"./chunk-NIAOX77K.js";import"./chunk-GMBJTG6A.js";import{ApiError,TwpApiClient,appendQuery}from"./chunk-FTYJZFEK.js";import"./chunk-II5RVJQN.js";import{GLOBAL_OPTIONS_HELP}from"./chunk-TAN5I2DP.js";import{HELP_TOKEN}from"./chunk-SP27PYHC.js";import"./chunk-QQRJLH6B.js";import{AuthSession,NotLoggedInError,SessionExpiredError,
|
|
5
5
|
loadCredentials}from"./chunk-XNLIEUAW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{effectiveApiUrl,resolveConfiguredOutput,resolveProfile}from"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import{OUTPUT_FORMATS,resolveOutputFormat}from"./chunk-K2ONOH3L.js";import"./chunk-WVS4W5FY.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{evaluateQuery}from"./chunk-GDM2QUBL.js";import{EXIT_OK,NetworkError,UsageError}from"./chunk-7WSNIXTQ.js";
|
|
6
6
|
import"./chunk-VSJBJXZO.js";var MIN_SEGMENT_CHARS=3;var parsedCache=new WeakMap;function splitSegments(path){return path.split("/").filter(segment=>segment!=="")}function parseRoutes(routes){const cached=parsedCache.get(routes);if(cached!==void 0)return cached;const parsed=[];for(const[key,domain]of Object.entries(routes.routes)){const space=key.indexOf(" ");if(space<=0)continue;const template=key.slice(space+1);parsed.push({method:key.slice(0,space),template,domain,segments:splitSegments(template).map(segment=>/^\{[^/{}]+\}$/.
|
|
@@ -1212,7 +1212,7 @@ cwd()){const listed=await gitListFiles(cwd2);const raw=listed??await walkFiles(c
|
|
|
1212
1212
|
1;const after=/^[^\s]*/.exec(text.slice(cursor))?.[0]??"";return{query,start,end:cursor+after.length}}var TWP_SLASH_ROUTES={"/tasks":{domain:"task",operation:"list"},"/task":{domain:"task",operation:"get"},"/projects":{domain:"project",operation:"list"}};function isTwpSlashCommand(name){return Object.hasOwn(TWP_SLASH_ROUTES,name)}async function runTwpSlashCommand(name,args,deps){const route=TWP_SLASH_ROUTES[name];if(!Object.hasOwn(TWP_SLASH_ROUTES,name)||route===void 0){return{code:2,out:"",err:`\u4E0D\u660E\u306A\u30B3\u30DE\u30F3\u30C9: ${name}
|
|
1213
1213
|
`}}const parsed=parseArgv([route.domain,route.operation,...args]);if(parsed.command!=="domain"||parsed.domain!==route.domain){return{code:2,out:"",err:`${name}: \u3053\u306E\u5F15\u6570\u306F\u4F7F\u3048\u307E\u305B\u3093\uFF08${args.join(" ")}\uFF09
|
|
1214
1214
|
`}}if(parsed.unknown.length>0){return{code:2,out:"",err:`\u4E0D\u660E\u306A\u5F15\u6570: ${parsed.unknown.join(" ")}
|
|
1215
|
-
`}}let out="";let err="";const io={out:text=>void(out+=text),err:text=>void(err+=text),isTty:true};const globals={profile:parsed.profile??deps.profile,...parsed.output!==void 0?{output:parsed.output}:{},...parsed.query!==void 0?{query:parsed.query}:{},dryRun:parsed.dryRun,debug:parsed.debug,yes:parsed.yes,refresh:parsed.refresh};const{runDomain}=await import("./run-
|
|
1215
|
+
`}}let out="";let err="";const io={out:text=>void(out+=text),err:text=>void(err+=text),isTty:true};const globals={profile:parsed.profile??deps.profile,...parsed.output!==void 0?{output:parsed.output}:{},...parsed.query!==void 0?{query:parsed.query}:{},dryRun:parsed.dryRun,debug:parsed.debug,yes:parsed.yes,refresh:parsed.refresh};const{runDomain}=await import("./run-CSHFVJT7.js");try{const code=await runDomain({domain:route.domain,...parsed.operation!==void 0?{operation:parsed.operation}:
|
|
1216
1216
|
{},argv:parsed.domainArgv,help:parsed.domainHelp,globals,version:deps.version,io,...deps.fetchImpl!==void 0?{fetchImpl:deps.fetchImpl}:{}});return{code,out,err}}catch(e){return{code:1,out,err:`${err}${e.message}
|
|
1217
1217
|
`}}}var GIT_LOG_OUTPUT=["9f3c1a2 feat(ui): \u4E00\u89A7\u306E\u30D5\u30A3\u30EB\u30BF\u3092 URL \u30AF\u30A8\u30EA\u3068\u540C\u671F\u3059\u308B","4b8e0d7 fix(ui): \u4EEE\u60F3\u30B9\u30AF\u30ED\u30FC\u30EB\u306E\u884C\u9AD8\u3055\u3092\u5B9F\u6E2C\u5024\u306B\u5408\u308F\u305B\u308B","c15a99e refactor(api): \u4E00\u89A7\u53D6\u5F97\u306E\u30DA\u30FC\u30B8\u30F3\u30B0\u51E6\u7406\u3092\u5171\u901A\u5316\u3059\u308B","2d70f4b test: \u4E00\u89A7\u30D5\u30A3\u30EB\u30BF\u306E\u56DE\u5E30\u30C6\u30B9\u30C8\u3092\u8FFD\u52A0\u3059\u308B",
|
|
1218
1218
|
"a6e2b38 fix(api): \u7A7A\u306E\u691C\u7D22\u6761\u4EF6\u3067\u5168\u4EF6\u8FD4\u3089\u306A\u3044\u3088\u3046\u306B\u3059\u308B","7c40d51 chore(deps): \u958B\u767A\u4F9D\u5B58\u3092\u6700\u65B0\u3078\u66F4\u65B0\u3059\u308B","e83b1c6 docs: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u624B\u9806\u306B Node 22 \u306E\u524D\u63D0\u3092\u8FFD\u8A18\u3059\u308B","b91f7a4 fix(ui): \u30E2\u30FC\u30C0\u30EB\u306E\u91CD\u306A\u308A\u9806\u3092\u6307\u5B9A\u3059\u308B","5a2c8e0 perf(api): \u4E00\u89A7\u306E N+1 \u3092\u89E3\u6D88\u3059\u308B",
|
|
@@ -18,8 +18,8 @@ ${operationSection}${subSection}
|
|
|
18
18
|
${GLOBAL_OPTIONS_HELP}
|
|
19
19
|
`}function renderOperationHelp(op,path2){const sections=[`twp ${path2} ${op.name} \u2014 ${op.summary}`,"","\u4F7F\u3044\u65B9:",` ${op.usage}`];if(op.description!==void 0){sections.push("",...op.description.split("\n"))}if(op.destructive===true){sections.push("","\u26A0 \u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u304C\u5FC5\u8981\u3067\u3059\u3002")}const flags=withCommonFlags(op.flags);if(flags.length>0){sections.push("","\u30AA\u30D7\u30B7\u30E7\u30F3:",
|
|
20
20
|
alignedList(flags.map(flag=>[flag.takesValue?`${flag.name} ${flag.placeholder??"<\u5024>"}`:flag.name,flag.summary])))}sections.push("",GLOBAL_OPTIONS_HELP,"");return sections.join("\n")}function renderUnknownOperation(resource,path2,attempted){const names=[...resource.operations.map(op=>op.name),...subresourcesOf(resource).map(sub=>`${sub.name} <\u64CD\u4F5C>`)].join(" / ");return attempted===void 0?`twp ${path2} \u306B\u306F\u64CD\u4F5C\u306E\u6307\u5B9A\u304C\u5FC5\u8981\u3067\u3059\uFF08${names}\
|
|
21
|
-
\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`:`twp ${path2} \u306B\u300C${attempted}\u300D\u3068\u3044\u3046\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${names}\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`}var LOADERS={"agent-loop":async()=>(await import("./agent-loop-
|
|
22
|
-
positionDomain,project:async()=>(await import("./project-DBNWB47J.js")).projectDomain,storage:async()=>(await import("./storage-ANKKJJJO.js")).storageDomain,task:async()=>(await import("./task-7VOYCG26.js")).taskDomain,user:async()=>(await import("./user-
|
|
21
|
+
\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`:`twp ${path2} \u306B\u300C${attempted}\u300D\u3068\u3044\u3046\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${names}\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`}var LOADERS={"agent-loop":async()=>(await import("./agent-loop-AOTZLJP2.js")).agentLoopDomain,attendance:async()=>(await import("./attendance-42XLURM7.js")).attendanceDomain,backlog:async()=>(await import("./backlog-KSMQIC2R.js")).backlogDomain,department:async()=>(await import("./department-GH475WCF.js")).departmentDomain,"job-title":async()=>(await import("./job-title-FC2GWDE7.js")).jobTitleDomain,media:async()=>(await import("./media-TD7D4TXF.js")).mediaDomain,position:async()=>(await import("./position-4RHTV3IK.js")).
|
|
22
|
+
positionDomain,project:async()=>(await import("./project-DBNWB47J.js")).projectDomain,storage:async()=>(await import("./storage-ANKKJJJO.js")).storageDomain,task:async()=>(await import("./task-7VOYCG26.js")).taskDomain,user:async()=>(await import("./user-SWPYLR32.js")).userDomain};async function loadDomain(name){return LOADERS[name]()}var writeOut=text=>void process.stdout.write(text);var writeErr=text=>void process.stderr.write(text);function line(text){return text===""?"":text.endsWith("\n")?text:`${text}
|
|
23
23
|
`}function outputValue(operation,format,body){return format==="json"?operation.raw(body):operation.summarize(body)}function requiresYes(operation,yes){return operation.destructive===true&&!yes}function exitCodeForStatus(status){if(status===401)return EXIT_AUTH;if(status===429)return EXIT_API_SERVER;if(status>=400&&status<500)return EXIT_API_CLIENT;return EXIT_API_SERVER}function exitCodeFor(err){if(err instanceof UsageError)return EXIT_USAGE;if(err instanceof NotLoggedInError||err instanceof SessionExpiredError)
|
|
24
24
|
return EXIT_AUTH;if(err instanceof ApiError)return exitCodeForStatus(err.status);if(err instanceof ApiRejectedError)return EXIT_API_CLIENT;if(err instanceof ApiResponseError||err instanceof NetworkError)return EXIT_API_SERVER;if(err instanceof ResolveError){return err.status===null?EXIT_API_SERVER:exitCodeForStatus(err.status)}return EXIT_FAILURE}function safeText(text){return redactSecrets(stripTerminalControls(text))}function reportError(err,format,code,write=writeErr){const message=safeText(err instanceof
|
|
25
25
|
Error?err.message:String(err));const rawHint=err instanceof UsageError?err.hint:void 0;const hint=rawHint!==void 0?safeText(rawHint):void 0;if(format==="json"){const body={code,message};if(err instanceof ApiError)body["status"]=err.status;if(err instanceof ResolveError&&err.status!==null)body["status"]=err.status;if(hint!==void 0)body["hint"]=hint;write(`${JSON.stringify({error:body},null,2)}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{DEFAULT_CLAUDE_LAUNCHER,activeSlotPath,detectClaudeAutoSwitch,spawnSyncResolved}from"./chunk-
|
|
3
|
+
import{DEFAULT_CLAUDE_LAUNCHER,activeSlotPath,detectClaudeAutoSwitch,spawnSyncResolved}from"./chunk-Y2XAWM2X.js";import{defaultIsExecutableFile,findOnPath,joinFor}from"./chunk-PMOUHEJQ.js";import{isBoolishTrue}from"./chunk-5WGOHFAS.js";import{spawnSync}from"child_process";import{createHash}from"crypto";import fs from"fs";import os from"os";import path from"path";var DETECTABLE_AIS=["claude","codex","gemini","copilot"];function isDetectableAi(value){return DETECTABLE_AIS.includes(value)}function isSelectable(d){return d.installed&&d.blockedReason===null&&d.auth!=="unauthenticated"}function resolveDetectDeps(deps={}){return resolve(deps)}function resolve(deps){const platform=deps.platform??process.platform;return{run:deps.run??spawnSync,env:deps.env??process.env,homedir:deps.homedir??os.homedir,isExecutableFile:deps.isExecutableFile??(p=>defaultIsExecutableFile(p,platform)),existsSync:deps.existsSync??fs.existsSync,readFileSync:deps.readFileSync??(p=>fs.readFileSync(p,"utf8")),platform,
|
|
4
4
|
now:deps.now??Date.now,launcherBin:nonEmptyBin(deps.launcherBin)??DEFAULT_CLAUDE_LAUNCHER.bin}}function nonEmptyBin(value){const t=value?.trim();return t===void 0||t===""?void 0:t}var PROBE_TIMEOUT_MS=1e4;function oneLine(text){return text.replace(/\s+/g," ").trim()}function claudeConfigDir(d){const lookup={env:d.env,platform:d.platform};const bin=nonEmptyBin(d.launcherBin)??DEFAULT_CLAUDE_LAUNCHER.bin;const cas=detectClaudeAutoSwitch(bin,d.run,lookup);if(cas!==null){const active=activeSlotPath(
|
|
5
5
|
cas,d.run,lookup);if(active!==null){return{dir:active,via:`${bin} ${DEFAULT_CLAUDE_LAUNCHER.activeArgs.join(" ")}`}}}const explicit=d.env.CLAUDE_CONFIG_DIR?.trim();if(explicit!==void 0&&explicit!=="")return{dir:explicit,via:"CLAUDE_CONFIG_DIR"};return{dir:joinFor(d.platform)(d.homedir(),".claude"),via:"\u65E2\u5B9A\uFF08~/.claude\uFF09"}}var CLAUDE_AUTH_ENV=[{key:"ANTHROPIC_API_KEY",label:"ANTHROPIC_API_KEY",boolish:false},{key:"ANTHROPIC_AUTH_TOKEN",label:"ANTHROPIC_AUTH_TOKEN",boolish:false},{
|
|
6
6
|
key:"CLAUDE_CODE_OAUTH_TOKEN",label:"CLAUDE_CODE_OAUTH_TOKEN",boolish:false},{key:"AWS_BEARER_TOKEN_BEDROCK",label:"AWS_BEARER_TOKEN_BEDROCK",boolish:false},{key:"CLAUDE_CODE_USE_BEDROCK",label:"CLAUDE_CODE_USE_BEDROCK\uFF08AWS \u8CC7\u683C\u60C5\u5831\u3067\u52D5\u304D\u307E\u3059\uFF09",boolish:true},{key:"CLAUDE_CODE_USE_VERTEX",label:"CLAUDE_CODE_USE_VERTEX\uFF08GCP \u8CC7\u683C\u60C5\u5831\u3067\u52D5\u304D\u307E\u3059\uFF09",boolish:true}];function envEnabled(raw,boolish){if(boolish)return isBoolishTrue(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{DEFAULT_CLAUDE_LAUNCHER,loadAiConfig}from"./chunk-
|
|
3
|
+
import{DEFAULT_CLAUDE_LAUNCHER,loadAiConfig}from"./chunk-Y2XAWM2X.js";import{killProcessTree}from"./chunk-N2UVRM3Z.js";import{projectFileKey}from"./chunk-GY7KI5E5.js";import{findExecutable,isWindowsDriveAbsolute}from"./chunk-PMOUHEJQ.js";import{isBoolishTrue}from"./chunk-5WGOHFAS.js";import{twpHomeDir}from"./chunk-RZVI6PMW.js";function stringField(value,key,fallback,warnings){if(value===void 0||value===null)return fallback;if(typeof value!=="string"||value.trim()===""){warnings.push(`claude_launcher.${key} \u306F\u7A7A\u3067\u306A\u3044\u6587\u5B57\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u65E2\u5B9A '${fallback}' \u3092\u4F7F\u3044\u307E\u3059\uFF09`);return fallback}return value.trim()}function argvField(value,key,fallback,warnings,allowEmpty){if(value===void 0||value===null)return fallback;
|
|
4
4
|
if(!Array.isArray(value)){warnings.push(`claude_launcher.${key} \u306F\u6587\u5B57\u5217\u306E\u914D\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u65E2\u5B9A [${fallback.join(", ")}] \u3092\u4F7F\u3044\u307E\u3059\uFF09`);return fallback}for(const v of value){if(typeof v!=="string"||v.trim()===""){warnings.push(`claude_launcher.${key} \u306E\u8981\u7D20\u306F\u7A7A\u3067\u306A\u3044\u6587\u5B57\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u65E2\u5B9A [${fallback.
|
|
5
5
|
join(", ")}] \u3092\u4F7F\u3044\u307E\u3059\uFF09`);return fallback}}if(value.length===0&&!allowEmpty){warnings.push(`claude_launcher.${key} \u306F1\u3064\u4EE5\u4E0A\u306E\u5F15\u6570\u304C\u8981\u308A\u307E\u3059\uFF08\u65E2\u5B9A [${fallback.join(", ")}] \u3092\u4F7F\u3044\u307E\u3059\uFF09`);return fallback}return value.map(v=>v.trim())}function probeMatchField(value,warnings){const raw=stringField(value,"probe_match",DEFAULT_CLAUDE_LAUNCHER.probeMatch,warnings);try{new RegExp(raw,"m")}catch(err){
|
|
6
6
|
warnings.push(`claude_launcher.probe_match \u306F\u6B63\u898F\u8868\u73FE\u3068\u3057\u3066\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093\uFF08${err.message}\uFF09\u3002\u65E2\u5B9A '${DEFAULT_CLAUDE_LAUNCHER.probeMatch}' \u3092\u4F7F\u3044\u307E\u3059`);return DEFAULT_CLAUDE_LAUNCHER.probeMatch}return raw}var NOT_YET_APPLIED=[{key:"probe",get:c=>c.probe},{key:"probe_match",get:c=>c.probeMatch},{key:"exec_args",get:c=>c.execArgs},{key:"active_args",get:c=>c.activeArgs}];function sameAsDefault(key,parsed){
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{describeError}from"./chunk-BKZGBJWT.js";import{CHAIN_KEYS,reloadAiConfig}from"./chunk-
|
|
3
|
+
import{describeError}from"./chunk-BKZGBJWT.js";import{CHAIN_KEYS,reloadAiConfig}from"./chunk-Y2XAWM2X.js";import{isPrivateProjectId}from"./chunk-GY7KI5E5.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import fs from"fs";import path from"path";var PROMPT_KEYS=["charter","charter_prefix","charter_suffix","plan_preamble","step_budget","non_interactive_note","safe_mode_note"];function parseServerSettings(res){const json=res.json;if(json===null||typeof json!=="object"||Array.isArray(json))return null;const top=json;const data=top["data"];const b=data!==null&&typeof data==="object"&&!Array.isArray(data)&&"revision"in data?data:top;const revision=b["revision"];if(typeof revision!=="number"||!Number.isInteger(revision)||revision<0)return null;
|
|
4
4
|
const rawAi=b["ai"];const ai=rawAi!==null&&typeof rawAi==="object"&&!Array.isArray(rawAi)?Object.fromEntries(Object.entries(rawAi).filter(([,v])=>v!==null&&v!==void 0)):{};const prompts={};const rawPrompts=b["prompts"];if(rawPrompts!==null&&typeof rawPrompts==="object"&&!Array.isArray(rawPrompts)){for(const key of PROMPT_KEYS){const v=rawPrompts[key];if(typeof v==="string")prompts[key]=v}}return{revision,ai,prompts}}function formatConfigHash(aiHash,revision,ai,charter){return`${aiHash};r=${revision}\
|
|
5
5
|
;ai=${ai};charter=${charter}`}function renderStepBudget(template,vars){return template.replaceAll("{timeout_min}",String(vars.timeoutMin)).replaceAll("{soft_min}",String(vars.softMin)).replaceAll("{wrap_up_min}",String(vars.wrapUpMin))}var LoopSettingsApplier=class{constructor(deps){this.deps=deps}deps;last=null;lastWarning="";lastAiWarning="";lastSummary="";serverAiApplied=false;lastSafeWarning="";async apply(){const{config,log}=this.deps;const outcome=await this.fetch();const warning=outcome.warning??
|
|
6
6
|
"";if(warning!==""&&warning!==this.lastWarning)log(` \u26A0\uFE0F ${warning}`);else if(warning===""&&this.lastWarning!=="")log("\u30EB\u30FC\u30D7\u8A2D\u5B9A\u3092\u30B5\u30FC\u30D0\u304B\u3089\u518D\u3073\u53D6\u5F97\u3067\u304D\u308B\u3088\u3046\u306B\u306A\u308A\u307E\u3057\u305F");this.lastWarning=warning;const settings=outcome.settings;config.serverPrompts=settings?.prompts??{};const safeNote=config.serverPrompts.safe_mode_note;const safeWarning=config.safeMode&&safeNote!==void 0?safeNote===
|
|
@@ -24,15 +24,16 @@ fromEntries(Object.entries(inline??{}).filter(([k])=>CHAIN_KEYS.includes(k)));re
|
|
|
24
24
|
null&&typeof v==="object"&&!Array.isArray(v)?Object.fromEntries(Object.entries(v).sort(([a],[b])=>a.localeCompare(b))):v)}var CHAIN_KEYS=["primary_rotation","fallback_chains"];var AiConfig=class _AiConfig{rotation=new Map;limitedUntil=new Map;unusableUntil=new Map;highRiskSkills;raw;fileLayerValue;constructor(raw,fileLayer=null){this.raw=raw;this.highRiskSkills=_AiConfig.highRiskSet(raw);this.fileLayerValue=fileLayer}get fileLayer(){return this.fileLayerValue}static highRiskSet(raw){return new Set(
|
|
25
25
|
(raw.high_risk_skills??[]).filter(v=>typeof v==="string"&&v!==""))}setFileLayer(file){this.fileLayerValue=file}replace(next){if(stableJson(next)===stableJson(this.raw))return false;this.raw=next;this.highRiskSkills=_AiConfig.highRiskSet(next);return true}hash(){const significant=Object.fromEntries(Object.entries(this.raw).filter(([k])=>!k.startsWith("_")&&!CHAIN_KEYS.includes(k)).sort(([a],[b])=>a.localeCompare(b)));return createHash("sha256").update(JSON.stringify(significant)).digest("hex").slice(
|
|
26
26
|
0,16)}categoryForSkill(skill){const name=stripPrefix2(skill);return this.raw.skill_category?.[name]??DEFAULT_CATEGORY}usesAi(ai){const rotations=this.raw.primary_rotation??BUILTIN.primary_rotation;const chains=this.raw.fallback_chains??BUILTIN.fallback_chains;const categories=new Set([DEFAULT_CATEGORY,...Object.keys(rotations),...Object.keys(chains),...Object.values(this.raw.skill_category??{})]);const matches=name=>isClaudeAi(ai)?isClaudeAi(name):name===ai;for(const category of categories){const rotation=rotations[category]??
|
|
27
|
-
rotations[DEFAULT_CATEGORY]??BUILTIN.primary_rotation[DEFAULT_CATEGORY]??[];const chain=chains[category]??chains[DEFAULT_CATEGORY]??BUILTIN.fallback_chains[DEFAULT_CATEGORY]??["claude"];for(const name of[...rotation,...chain]){if(matches(name))return true}}return false}
|
|
28
|
-
raw.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
27
|
+
rotations[DEFAULT_CATEGORY]??BUILTIN.primary_rotation[DEFAULT_CATEGORY]??[];const chain=chains[category]??chains[DEFAULT_CATEGORY]??BUILTIN.fallback_chains[DEFAULT_CATEGORY]??["claude"];for(const name of[...rotation,...chain]){if(matches(name))return true}}return false}probeCategoryFor(ai){const rotations=this.raw.primary_rotation??BUILTIN.primary_rotation;const chains=this.raw.fallback_chains??BUILTIN.fallback_chains;const categories=new Set([DEFAULT_CATEGORY,...Object.keys(rotations),...Object.
|
|
28
|
+
keys(chains),...Object.values(this.raw.skill_category??{})]);const matches=name=>isClaudeAi(ai)?isClaudeAi(name):name===ai;for(const category of categories){if(!this.isAllowed(ai,category,""))continue;const rotation=rotations[category]??rotations[DEFAULT_CATEGORY]??BUILTIN.primary_rotation[DEFAULT_CATEGORY]??[];const chain=chains[category]??chains[DEFAULT_CATEGORY]??BUILTIN.fallback_chains[DEFAULT_CATEGORY]??["claude"];if([...rotation,...chain].some(matches))return category}return null}chainFor(category){
|
|
29
|
+
const chains=this.raw.fallback_chains??BUILTIN.fallback_chains;return chains[category]??chains[DEFAULT_CATEGORY]??BUILTIN.fallback_chains[DEFAULT_CATEGORY]??["claude"]}primaryFor(category,skill){const rotations=this.raw.primary_rotation??BUILTIN.primary_rotation;const entries=rotations[category]??rotations[DEFAULT_CATEGORY]??BUILTIN.primary_rotation[DEFAULT_CATEGORY]??[];if(entries.length===0)return"";const start=this.rotation.get(category)??0;for(let i=0;i<entries.length;i+=1){const ai=entries[(start+
|
|
30
|
+
i)%entries.length];if(ai!==void 0&&this.isAllowed(ai,category,skill)){this.rotation.set(category,(start+i+1)%entries.length);return ai}}return""}isHighRisk(category,skill,priority,label){if(["verify","security","support"].includes(category))return true;if(priority==="P0"||priority==="P0.5")return true;const name=stripPrefix2(skill);if(this.highRiskSkills.has(name))return true;return HIGH_RISK_LABEL.test(label)}selectPrimary(category,skill,priority,label){if(this.isHighRisk(category,skill,priority,
|
|
31
|
+
label)&&this.chainFor(category).includes("claude")){return"claude"}return this.primaryFor(category,skill)}isAllowed(ai,category,skill){if(ai!=="gemini")return true;if(["complex","verify","security","support"].includes(category))return false;return!this.requiresGitRemote(skill)}requiresGitRemote(skill){return(this.raw.git_remote_skills??[]).includes(stripPrefix2(skill))}exclusiveSkills(){const configured=(this.raw.exclusive_skills??[]).map(s=>stripPrefix2((s??"").trim())).filter(s=>s!=="");return new Set(
|
|
32
|
+
[...configured,...EXCLUSIVE_SKILL_FLOOR])}isExclusiveSkill(skill){const name=stripPrefix2(skill.trim());return name!==""&&this.exclusiveSkills().has(name)}modelFor(ai,category,env=process.env){switch(ai){case"gemini":return this.raw.gemini_models?.[category]??"";case"codex":return this.raw.codex_models?.[category]??this.raw.codex_models?.[DEFAULT_CATEGORY]??"";case"claude":return this.claudeModelFor(category,env);default:return isClaudeAi(ai)?this.claudeModelFor(category,env):""}}claudeModelFor(category,env){
|
|
33
|
+
const table=usesBedrock(env)?this.raw.claude_models_bedrock:this.raw.claude_models;return table?.[category]??env.CLAUDE_MODEL??""}maxTurnsFor(category,env=process.env){const fallback=Number.parseInt(env.CLAUDE_MAX_TURNS??"",10);const base=Number.isInteger(fallback)&&fallback>0?fallback:200;const configured=this.raw.claude_max_turns?.[category];return Number.isInteger(configured)&&(configured??0)>0?configured:base}effortFor(category,skill,env=process.env,explicit){const name=stripPrefix2(skill);const item=(explicit??
|
|
34
|
+
"").trim();if(item!==""&&EFFORTS.has(item))return{value:item,warning:null};const itemWarning=item!==""?`\u4E0D\u6B63\u306A ai_effort '${item}'\uFF08\u30A2\u30A4\u30C6\u30E0\u6307\u5B9A\uFF09\u2192 \u30B9\u30AD\u30EB\uFF0F\u30AB\u30C6\u30B4\u30EA\u65E2\u5B9A\u3092\u4F7F\u3044\u307E\u3059`:null;const raw=(name!==""?this.raw.claude_effort_by_skill?.[name]:void 0)??this.raw.claude_effort?.[category]??env.CLAUDE_EFFORT??"";if(raw==="")return{value:"",warning:itemWarning};if(EFFORTS.has(raw))return{value:raw,
|
|
35
|
+
warning:itemWarning};return{value:"",warning:`\u4E0D\u6B63\u306A effort \u5024 '${raw}'\uFF08category=${category}, skill=${name||"none"}\uFF09\u2192 \u672A\u6307\u5B9A\u3068\u3057\u3066\u6271\u3044\u307E\u3059`}}fallbackDelaySec(ai,env=process.env){const fromEnv=Number.parseInt(env[`AI_FALLBACK_DELAY_${ai.toUpperCase()}`]??"",10);if(Number.isInteger(fromEnv)&&fromEnv>=0)return fromEnv;const cfg=this.raw.fallback_delay?.[ai];return Number.isInteger(cfg)&&(cfg??0)>=0?cfg:0}cooldownDefaultSec(ai,env=process.
|
|
36
|
+
env){const fromEnv=Number.parseInt(env[`AI_COOLDOWN_${ai.toUpperCase()}`]??"",10);if(Number.isInteger(fromEnv)&&fromEnv>0)return fromEnv;const cfg=this.raw.cooldown?.[ai];if(Number.isInteger(cfg)&&(cfg??0)>0)return cfg;const backoff=Number.parseInt(env.RATE_LIMIT_BACKOFF??"",10);return Number.isInteger(backoff)&&backoff>0?backoff:DEFAULT_COOLDOWN_SEC}limitKey(ai,slot){return slot===null||slot===void 0||slot===""?ai:`${ai}@${slot}`}hasCooldownFor(ai,now=Date.now()){for(const[key,until]of this.limitedUntil){
|
|
37
|
+
if(until<=now)continue;if(key===ai||key.startsWith(`${ai}@`))return true}return false}isRateLimited(ai,now=Date.now(),slot=null){return(this.limitedUntil.get(this.limitKey(ai,slot))??0)>now}markRateLimited(ai,seconds,now=Date.now(),slot=null){const capped=Math.min(Math.max(Math.trunc(seconds),1),MAX_COOLDOWN_SEC);this.limitedUntil.set(this.limitKey(ai,slot),now+capped*1e3);return capped}markAiUnusable(ai,now=Date.now()){this.unusableUntil.set(ai,now+AI_UNUSABLE_COOLDOWN_SEC*1e3);return AI_UNUSABLE_COOLDOWN_SEC}isAiUnusable(ai,now=Date.
|
|
38
|
+
now()){return(this.unusableUntil.get(ai)??0)>now}minCooldownRemainingSec(now=Date.now()){let min=null;for(const until of this.limitedUntil.values()){if(until<=now)continue;const remaining=Math.ceil((until-now)/1e3);if(min===null||remaining<min)min=remaining}return min}};var HIGH_RISK_LABEL=/本番|リリース|認証|認可|権限|セキュリティ|課金|給与|勤怠計算/;var TIER_ALIASES=new Set(["opus","sonnet","haiku","default"]);function modelFitsRoute(model,env=process.env){if(TIER_ALIASES.
|
|
39
|
+
has(model.trim().toLowerCase()))return true;if(model.startsWith("arn:aws:bedrock:"))return usesBedrock(env);const bedrockShaped=/(^|[./])anthropic\./.test(model);return usesBedrock(env)?bedrockShaped:!bedrockShaped}function isUsableModelId(value){return value!==""&&!value.startsWith("-")&&/^[A-Za-z0-9._:\-/[\]]+$/.test(value)}function stripPrefix2(skill){return skill.startsWith("twp-")?skill.slice(4):skill}export{resolveSpawnTarget,spawnSyncResolved,DEFAULT_CLAUDE_LAUNCHER,detectClaudeAutoSwitch,wrapWithAutoSwitch,activeSlotPath,isClaudeAi,normalizeSkillName,skillOfItem,exclusiveInflightEntries,formatExclusiveEntry,usesBedrock,loadAiConfig,reloadAiConfig,CHAIN_KEYS,AiConfig,modelFitsRoute,isUsableModelId};
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
3
3
|
const require = __twpCreateRequire(import.meta.url);
|
|
4
|
-
import{parseArgv}from"./chunk-YWGYRISN.js";import"./chunk-NAUH75MM.js";import{GLOBAL_OPTIONS_HELP}from"./chunk-TAN5I2DP.js";import"./chunk-SP27PYHC.js";import"./chunk-QQRJLH6B.js";import"./chunk-VSJBJXZO.js";var VERSION=true?"0.
|
|
4
|
+
import{parseArgv}from"./chunk-YWGYRISN.js";import"./chunk-NAUH75MM.js";import{GLOBAL_OPTIONS_HELP}from"./chunk-TAN5I2DP.js";import"./chunk-SP27PYHC.js";import"./chunk-QQRJLH6B.js";import"./chunk-VSJBJXZO.js";var VERSION=true?"0.26.0":"0.0.0-dev";var HELP=`twp ${VERSION} \u2014 TWP CLI
|
|
5
5
|
|
|
6
6
|
\u4F7F\u3044\u65B9:
|
|
7
7
|
twp \u5BFE\u8A71 TUI \u3092\u8D77\u52D5
|
|
@@ -250,10 +250,10 @@ TUI \u5185:
|
|
|
250
250
|
`);process.exit(1)}ignoreEpipe(process.stdout);ignoreEpipe(process.stderr);if(process.env["TWP_AUTO_UPDATE_WORKER"]==="1"){const{runAutoUpdateWorker}=await import("./auto-update-worker-OBFGN6FY.js");await runAutoUpdateWorker().catch(()=>void 0);return}const args=parseArgv(process.argv.slice(2));if(args.command==="version"){process.stdout.write(`${VERSION}
|
|
251
251
|
`);return}if(args.command==="help"){process.stdout.write(HELP);return}if(args.unknown.length>0){process.stderr.write(`\u4E0D\u660E\u306A\u5F15\u6570: ${args.unknown.join(" ")}
|
|
252
252
|
|
|
253
|
-
${HELP}`);process.exitCode=2;return}const autoUpdate=await import("./auto-update-CV2MM32C.js");autoUpdate.registerRunning();if(args.command==="task-loop"){process.env[autoUpdate.DISABLE_ENV]="1"}else if(args.command!=="update"){autoUpdate.onStartup(VERSION)}if(args.command==="domain"&&args.domain!==void 0){const{runDomain}=await import("./run-
|
|
254
|
-
domainHelp,globals:{...args.profile!==void 0?{profile:args.profile}:{},...args.output!==void 0?{output:args.output}:{},...args.query!==void 0?{query:args.query}:{},dryRun:args.dryRun,debug:args.debug,yes:args.yes,refresh:args.refresh},version:VERSION});return}if(args.command==="api"){const{runApiCommand}=await import("./api-command-
|
|
255
|
-
void 0?{output:args.output}:{},...args.query!==void 0?{query:args.query}:{},dryRun:args.dryRun,debug:args.debug,yes:args.yes},version:VERSION});return}if(args.command==="update"){const{runUpdate}=await import("./update-RLKK6N7U.js");process.exitCode=await runUpdate({...args.profile!==void 0?{profile:args.profile}:{},version:VERSION});return}if(args.command==="login"||args.command==="logout"||args.command==="whoami"){const{runLogin,runLogout,runWhoami}=await import("./commands-
|
|
256
|
-
const options={profile:args.profile,method:args.loginMethod,tenant:args.tenant,noBrowser:args.loginNoBrowser,cliVersion:VERSION,force:args.logoutForce,...args.output!==void 0?{output:args.output}:{},...args.query!==void 0?{query:args.query}:{}};const runner=args.command==="login"?runLogin:args.command==="logout"?runLogout:runWhoami;process.exitCode=await runner(options);return}if(args.command==="task-loop"){const{runTaskLoop}=await import("./commands-
|
|
253
|
+
${HELP}`);process.exitCode=2;return}const autoUpdate=await import("./auto-update-CV2MM32C.js");autoUpdate.registerRunning();if(args.command==="task-loop"){process.env[autoUpdate.DISABLE_ENV]="1"}else if(args.command!=="update"){autoUpdate.onStartup(VERSION)}if(args.command==="domain"&&args.domain!==void 0){const{runDomain}=await import("./run-CSHFVJT7.js");process.exitCode=await runDomain({domain:args.domain,...args.operation!==void 0?{operation:args.operation}:{},argv:args.domainArgv,help:args.
|
|
254
|
+
domainHelp,globals:{...args.profile!==void 0?{profile:args.profile}:{},...args.output!==void 0?{output:args.output}:{},...args.query!==void 0?{query:args.query}:{},dryRun:args.dryRun,debug:args.debug,yes:args.yes,refresh:args.refresh},version:VERSION});return}if(args.command==="api"){const{runApiCommand}=await import("./api-command-M4TMA4PR.js");process.exitCode=await runApiCommand({argv:args.domainArgv,help:args.domainHelp,globals:{...args.profile!==void 0?{profile:args.profile}:{},...args.output!==
|
|
255
|
+
void 0?{output:args.output}:{},...args.query!==void 0?{query:args.query}:{},dryRun:args.dryRun,debug:args.debug,yes:args.yes},version:VERSION});return}if(args.command==="update"){const{runUpdate}=await import("./update-RLKK6N7U.js");process.exitCode=await runUpdate({...args.profile!==void 0?{profile:args.profile}:{},version:VERSION});return}if(args.command==="login"||args.command==="logout"||args.command==="whoami"){const{runLogin,runLogout,runWhoami}=await import("./commands-DDXAFNPT.js");
|
|
256
|
+
const options={profile:args.profile,method:args.loginMethod,tenant:args.tenant,noBrowser:args.loginNoBrowser,cliVersion:VERSION,force:args.logoutForce,...args.output!==void 0?{output:args.output}:{},...args.query!==void 0?{query:args.query}:{}};const runner=args.command==="login"?runLogin:args.command==="logout"?runLogout:runWhoami;process.exitCode=await runner(options);return}if(args.command==="task-loop"){const{runTaskLoop}=await import("./commands-EOKUE4FC.js");process.exitCode=await runTaskLoop(
|
|
257
257
|
{action:args.taskLoopAction??"run",project:args.project,profile:args.profile,safe:args.safe,daemon:args.daemon,interval:args.interval,maxCycles:args.maxCycles,forceRunner:args.forceRunner,force:args.stopForce,drain:args.stopDrain,engine:args.engine,version:VERSION,verbose:args.verbose,scheduleNow:args.scheduleNow,scheduleCounts:args.scheduleCounts,scheduleGate:args.scheduleGate,charterOp:args.charterOp,charterInput:args.charterFile,charterOutput:args.charterOut,charterRevision:args.charterRevision,
|
|
258
258
|
skillOp:args.skillOp,skillName:args.skillName,skillAll:args.skillAll,skillDir:args.skillDir,yes:args.yes,ais:args.ais,workspace:args.workspace,aiConfigFile:args.aiConfigFile,noAiConfigFile:args.noAiConfigFile});return}if(args.command==="print"){const{runOneShot}=await import("./oneshot-QQOOZZDT.js");process.exitCode=await runOneShot({prompt:args.prompt??"",fromStdin:args.promptFromStdin,mode:args.mode??"dev",...args.permissionMode!==void 0?{permissionMode:args.permissionMode}:{},allowedTools:args.
|
|
259
|
-
allowedTools,disallowedTools:args.disallowedTools,...args.model!==void 0?{model:args.model}:{},...args.profile!==void 0?{profile:args.profile}:{},version:VERSION});return}const{startTui}=await import("./app-
|
|
259
|
+
allowedTools,disallowedTools:args.disallowedTools,...args.model!==void 0?{model:args.model}:{},...args.profile!==void 0?{profile:args.profile}:{},version:VERSION});return}const{startTui}=await import("./app-3EHZDREV.js");await startTui({mode:args.mode,permissionMode:args.permissionMode,allowedTools:args.allowedTools,disallowedTools:args.disallowedTools,model:args.model,profile:args.profile,noTui:args.noTui||!process.stdout.isTTY,doctor:args.doctor,version:VERSION})}await main();
|
|
@@ -50,7 +50,7 @@ ${err.hint?`${err.hint}
|
|
|
50
50
|
`);return 1}writeErr(`\u30A8\u30E9\u30FC: ${err.message}
|
|
51
51
|
`);return 1}}async function runLogin(options){return run(async()=>{const profile=resolveProfile(options.profile);const io=makeIo(options.cliVersion);if(options.method==="password"){await passwordLogin(profile,{tenantCode:options.tenant??void 0},process.env,io)}else if(options.method==="token"){await tokenLogin(profile,process.env,io)}else{await browserLogin(profile,process.env,io,{noBrowser:options.noBrowser})}})}async function runLogout(options){return run(async()=>{const profile=resolveProfile(
|
|
52
52
|
options.profile);const creds=loadCredentials(profile.name);if(!creds){writeOut(`\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB\u300C${profile.name}\u300D\u306F\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u3044\u307E\u305B\u3093\u3002
|
|
53
|
-
`);return}const{describeLogoutImpact,findLoopsUsingProfile}=await import("./logout-guard-
|
|
53
|
+
`);return}const{describeLogoutImpact,findLoopsUsingProfile}=await import("./logout-guard-ICSEMN3J.js");const found=findLoopsUsingProfile(profile.name,options.logoutGuard);if(found.users.length>0||found.undetermined.length>0){writeErr(describeLogoutImpact(profile.name,found,options.force===true));if(options.force!==true)throw new LogoutRefusedError}const apiUrl=effectiveApiUrl(profile,creds.api_url);const revoked=await httpFetch(`${apiUrl}/api/v2/auth/logout`,{method:"POST",headers:{Accept:"applic\
|
|
54
54
|
ation/json",Authorization:`Bearer ${creds.token}`}}).then(res=>res.ok,()=>false);await deleteCredentials(profile.name);writeOut(`\u2705 \u30ED\u30B0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\uFF08\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB: ${profile.name} / \u30C8\u30FC\u30AF\u30F3: ${maskToken(creds.token)}\uFF09
|
|
55
55
|
`);if(!revoked){writeOut("\u26A0 \u30B5\u30FC\u30D0\u5074\u306E\u30C8\u30FC\u30AF\u30F3\u5931\u52B9\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08\u30AA\u30D5\u30E9\u30A4\u30F3\u7B49\uFF09\u3002TWP \u306E\u300C\u8A2D\u5B9A > CLI\u7AEF\u672B\u300D\u304B\u3089\u3082\u5931\u52B9\u3067\u304D\u307E\u3059\u3002\n")}})}async function runWhoami(options){return run(async()=>{const profile=resolveProfile(options.profile);const structured=options.output!==void 0||options.query!==void 0;let format=null;if(structured){
|
|
56
56
|
const{resolveOutputFormat,OUTPUT_FORMATS}=await import("./format-NMW6Y2E5.js");format=resolveOutputFormat({...options.output!==void 0?{flag:options.output}:{},isTty:process.stdout.isTTY===true});if(format===null){throw new UsageError(`--output \u306B\u300C${options.output??""}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,`\u6307\u5B9A\u3067\u304D\u308B\u306E\u306F ${OUTPUT_FORMATS.join(" / ")} \u3067\u3059`)}}const stored=loadCredentials(profile.name);const apiUrl=effectiveApiUrl(
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{LoopSettingsApplier,renderStepBudget}from"./chunk-
|
|
3
|
+
import{LoopSettingsApplier,renderStepBudget}from"./chunk-XAMHF5MK.js";import{EngineNotConfiguredError,NoopEngine,UnknownEngineError,aiUnavailableLabel,assertKnownEngine,failureHint,isAiUnavailable,needsHumanToRestoreAi}from"./chunk-ZOOEH7ZE.js";import{claudeConfigDir,resolveDetectDeps}from"./chunk-5PU5QU5U.js";import{REQUIRE_ZERO_STATUS,ScheduleApi,collectDue,gateStatus,nowInZone,parseCounts,promptSection}from"./chunk-VYDEUFGU.js";import{AgentLoopApi,describeError,filterByStatus,
|
|
4
4
|
isPermanent,pick,pickString}from"./chunk-BKZGBJWT.js";import{InstanceLock,buildLockOwner,defaultIsLoopProcess,writeLockOwner}from"./chunk-3WHC4FSG.js";import{duplicateTaskKeyDropReason,excludedKeyInArgs,extractPlanJson,parseOpsCount,parsePlanExcludeKeys,placeholderTaskKey,releaseDeployDropReason,stepToItem,zeroTargetDropReasons}from"./chunk-VCZVITWG.js";import{CapacityReporter,buildLoopConfig,describeOperations,evaluateOwnership,formatHookIds,formatHookWiring,localDate,loopStateDir,
|
|
5
|
-
runHook,runPrefetch,runPreflight}from"./chunk-
|
|
5
|
+
runHook,runPrefetch,runPreflight}from"./chunk-RDJYKA3U.js";import{exclusiveInflightEntries,formatExclusiveEntry,normalizeSkillName,skillOfItem,spawnSyncResolved}from"./chunk-Y2XAWM2X.js";import{killProcessTree}from"./chunk-N2UVRM3Z.js";import{PRIVATE_PROJECT_REF,isPrivateProjectId,isPrivateProjectRef,privateProjectId,projectFileKey}from"./chunk-GY7KI5E5.js";import{resolveProjectRef,uuidProjectIdPolicy}from"./chunk-GMBJTG6A.js";import{isTaskKey}from"./chunk-II5RVJQN.js";
|
|
6
6
|
import{AuthSession}from"./chunk-XNLIEUAW.js";import{joinFor}from"./chunk-PMOUHEJQ.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{compareVersionCores,parseVersionCore}from"./chunk-DXXFUNYN.js";import"./chunk-5WGOHFAS.js";import{effectiveApiUrl,resolveProfile}from"./chunk-NERYSBA4.js";import{twpHomeDir}from"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";import fs10 from"fs";import path8 from"path";import fs from"fs";import path from"path";var LoopLogger=class{constructor(runnerId,logFile,out=process.stdout,now=()=>new Date){this.runnerId=runnerId;this.out=out;this.now=now;if(logFile){fs.mkdirSync(path.dirname(logFile),{recursive:true});this.stream=fs.createWriteStream(logFile,{flags:"a"})}}runnerId;out;now;stream=null;log(message){const d=this.now();const ts=`${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;const line=`[${ts}] [${this.runnerId}] ${stripTerminalControls(
|
|
7
7
|
message)}
|
|
8
8
|
`;this.out.write(line);this.stream?.write(line)}separator(){this.log("=".repeat(60))}close(){this.stream?.end();this.stream=null}};function pad(n){return String(n).padStart(2,"0")}function rotateLogs(dir,retentionDays,now=Date.now()){if(retentionDays<=0)return;const cutoff=now-retentionDays*864e5;let entries;try{entries=fs.readdirSync(dir)}catch{return}for(const name of entries){if(!/^(agent-loop|task-loop|step|plan|schedule-enqueued)-.*\.(log|txt)$/.test(name))continue;const file=path.join(dir,
|
|
@@ -178,8 +178,9 @@ await this.engine.abort?.();if(!inFlight){this.abortDrained=null;return}this.dep
|
|
|
178
178
|
resolve()},ABORT_DRAIN_TIMEOUT_MS);timer.unref?.()})]);if(timer!==null)clearTimeout(timer);this.abortDrained=null}async shutdown(){await this.planLock.release("failed")}async run(){const{config,log,runner}=this.deps;log.log(describeOperations(config.operations));if(!config.planEnabled){log.log("\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u306F\u7121\u52B9\u3067\u3059\uFF08plan_enabled=false\uFF09\u3002\u30AD\u30E5\u30FC\u304C\u7A7A\u3067\u3082\u8A08\u753BAI\u3092\u8D77\u52D5\u305B\u305A\u3001\u7A4D\u307E\u308C\u305F\u4ED5\u4E8B\u306E\u5B9F\u884C\u3060\u3051\u3092\u884C\u3044\u307E\u3059\u3002")}
|
|
179
179
|
let cycle=0;let noProgressStreak=0;let unavailableStreak=0;let undeterminedStreak=0;let exitCode=0;while(cycle<config.maxCycles){if(this.aborting){log.log("\u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u3051\u3066\u3044\u308B\u305F\u3081\u3001\u65B0\u3057\u3044\u30B5\u30A4\u30AF\u30EB\u3092\u958B\u59CB\u3057\u307E\u305B\u3093\u3002");break}if(this.draining){log.log(`\u30C9\u30EC\u30A4\u30F3\u8981\u6C42\u3092\u53D7\u3051\u3066\u3044\u308B\u305F\u3081\u3001\u65B0\u3057\u3044\u30B5\u30A4\u30AF\u30EB\u3092\u958B\u59CB\u3057\u307E\u305B\u3093\uFF08\u7D42\u4E86\u30B3\u30FC\u30C9 ${this.
|
|
180
180
|
drainExitCode}\uFF09\u3002`);exitCode=this.drainExitCode;break}cycle+=1;const cycleStart=Date.now();log.separator();log.log(`========== Cycle ${cycle}${config.daemon?"":`/${config.maxCycles}`} \u958B\u59CB ==========`);log.separator();await runner.beat("idle");log.log(formatHookWiring(config.prefetch,config.preflight));if(config.preflight.length>0){log.log(`\u74B0\u5883\u306E\u524D\u63D0\u6761\u4EF6\u3092\u78BA\u8A8D\u4E2D\uFF08\u30D5\u30C3\u30AF ${config.preflight.length}\u4EF6\uFF09...`)}this.
|
|
181
|
-
cyclePreflightSection=await runPreflight(config.preflight,config.workspace,m=>log.log(m));await this.settings.apply();
|
|
182
|
-
reclaimRes)}\uFF09\u3002\u53D6\u308A\u6B8B\u3057\u304C\u6B8B\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059`)}
|
|
181
|
+
cyclePreflightSection=await runPreflight(config.preflight,config.workspace,m=>log.log(m));await this.settings.apply();try{await this.engine.healthCheck?.({cwd:config.workspace,logFilePrefix:path5.join(config.logDir,`health-${this.timestamp}-${cycle}`)})}catch(err){log.log(` \u26A0\uFE0F AI\u30D8\u30EB\u30B9\u30C1\u30A7\u30C3\u30AF\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${err.message}\uFF09\u3002\u9396\u306F\u305D\u306E\u307E\u307E\u4F7F\u3044\u307E\u3059`)}for(const line of normalizeGitIdentity(
|
|
182
|
+
config.workspace,config.gitIdentity).logs)log.log(line);let planSkippedNoLock=false;const resent=await this.writeback.retryPending();for(const itemId of resent)await this.schedule.recordByItem(itemId,"completed");const reclaimRes=await this.deps.api.reclaim();if(!reclaimRes.ok){log.log(` \u26A0\uFE0F \u6B7B\u3093\u3060\u30E9\u30F3\u30CA\u30FC\u306E\u30A2\u30A4\u30C6\u30E0\u56DE\u53CEAPI\u304C\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${describeError(reclaimRes)}\uFF09\u3002\u53D6\u308A\u6B8B\u3057\u304C\u6B8B\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059`)}
|
|
183
|
+
await this.reclaimStaleProcessing();const trust=this.trustGate.evaluate();for(const line of trust.logs)log.log(line);if(trust.note!==null){this.cyclePreflightSection=this.cyclePreflightSection===""?trust.note:`${this.cyclePreflightSection}
|
|
183
184
|
|
|
184
185
|
${trust.note}`}if(trust.wait){await runner.beat("waiting");if(cycle<config.maxCycles)await this.sleepUnlessDraining(config.intervalSec*1e3);continue}const hadPending=await this.hasPendingItems();this.midcycleEnqueued=0;this.deferredIds=new Set;await this.enqueueDueScheduled(false);const planSkippedDisabled=!hadPending&&!config.planEnabled;if(hadPending){log.log("\u30AD\u30E5\u30FC\u306Bpending\u30A2\u30A4\u30C6\u30E0\u304C\u3042\u308A\u307E\u3059\u3002\u8A08\u753B\u3092\u30B9\u30AD\u30C3\u30D7\u3057\u3066\u5B9F\u884C\u306B\u9032\u307F\u307E\u3059\u3002")}else if(planSkippedDisabled){
|
|
185
186
|
log.log("\u30AD\u30E5\u30FC\u306F\u7A7A\u3067\u3059\u304C\u3001\u3053\u306E\u6A5F\u4F53\u306F\u8A08\u753B\u3092\u7ACB\u3066\u306A\u3044\u8A2D\u5B9A\u3067\u3059\uFF08plan_enabled=false\uFF09\u3002AI \u3092\u8D77\u52D5\u305B\u305A\u30AD\u30E5\u30FC\u306E\u5B9F\u884C\u3078\u9032\u307F\u307E\u3059\u3002")}else{log.log("\u30AD\u30E5\u30FC\u304C\u7A7A\u3067\u3059\u3002\u8A08\u753B\u3092\u7ACB\u6848\u3057\u3066\u30A8\u30F3\u30AD\u30E5\u30FC\u3057\u307E\u3059\u3002")}if(planSkippedDisabled){}else if(!hadPending&&
|
|
@@ -307,12 +308,12 @@ const startedAtMs=now();let warned="";let done=false;const check=()=>{if(done)re
|
|
|
307
308
|
decision.key)return;warned=decision.key;handlers.onWarn(decision.reason);return}done=true;const recorded=writeRestartAttempt(opts.stateDir,opts.projectKey,{from:decision.from,to:decision.to,at:new Date(now()).toISOString()},opts.store);if(!recorded){handlers.onWarn(`\u518D\u8D77\u52D5\u8A18\u9332\u3092\u66F8\u3051\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${restartAttemptPath(opts.stateDir,opts.projectKey)}\uFF09\u3002\u540C\u3058\u7248\u30C9\u30EA\u30D5\u30C8\u304C\u89E3\u6D88\u3057\u306A\u3044\u5834\u5408\u3001\u518D\u8D77\u52D5\u3092\u7E70\u308A\u8FD4\u3059\u9632\u6CE2\u5824\u304C\u52B9\u304D\u307E\u305B\u3093`)}
|
|
308
309
|
handlers.onRestart({from:decision.from,to:decision.to})};const timer=setInterval(check,opts.intervalMs??DRIFT_POLL_MS);timer.unref?.();return{stop:()=>{done=true;clearInterval(timer)},check}}import fs9 from"fs";import path7 from"path";var POLL_MS=1e3;var MAX_STOP_BYTES=4096;var MAX_AT_LENGTH=64;function markerPath(lockDir2,kind){return path7.join(lockDir2,kind)}function requestMarker(lockDir2,kind,pid,deps={}){const target=markerPath(lockDir2,kind);const write=deps.writeFileSync??((p,d)=>fs9.writeFileSync(p,d,{flag:"wx",mode:384}));const now=deps.now??(()=>new Date);clearMarker(lockDir2,kind,deps);try{write(target,`${JSON.stringify({pid,at:now().toISOString()})}
|
|
309
310
|
`);return{ok:true}}catch(err){const e=err;return{ok:false,reason:e.code??"UNKNOWN"}}}function readMarker(lockDir2,kind,deps={}){const target=markerPath(lockDir2,kind);const read=deps.readFileSync??(p=>fs9.readFileSync(p,"utf8"));const size=deps.statSize??(p=>fs9.statSync(p).size);let raw;try{if(size(target)>MAX_STOP_BYTES)return null;raw=read(target)}catch{return null}if(raw.length>MAX_STOP_BYTES)return null;try{const parsed=JSON.parse(raw);if(typeof parsed!=="object"||parsed===null)return null;const pid=parsed.pid;const at=parsed.at;if(typeof pid!=="number"||!Number.isInteger(pid)||
|
|
310
|
-
pid<=0)return null;return{pid,at:sanitizeAt(at)}}catch{return null}}function sanitizeAt(at){if(typeof at!=="string")return"";return at.replace(/[\u0000-\u001f\u007f]/g," ").slice(0,MAX_AT_LENGTH)}function clearMarker(lockDir2,kind,deps={}){const rm=deps.rmSync??(p=>fs9.rmSync(p,{recursive:true,force:true}));try{rm(markerPath(lockDir2,kind))}catch{}}function watchMarker(lockDir2,kind,selfPid,onStop,deps={}){let fired=false;const timer=setInterval(()=>{if(fired)return;const req=readMarker(lockDir2,kind,deps);if(req===null||req.pid!==selfPid)return;fired=true;onStop(req)},deps.intervalMs??POLL_MS);timer.unref?.();return()=>{fired=true;clearInterval(timer)}}function safe(s){return stripTerminalControls(s)}function compactTimestamp(at=new Date){const p2=n=>String(n).padStart(2,"0");return`${at.getFullYear()}${p2(at.getMonth()+1)}${p2(at.getDate())}-${p2(at.getHours())}${p2(at.getMinutes())}${p2(at.getSeconds())}`}async function buildEngine(config,log){if(config.engine==="noop")return new NoopEngine;const{DispatchEngine}=await import("./ai-dispatch-
|
|
311
|
+
pid<=0)return null;return{pid,at:sanitizeAt(at)}}catch{return null}}function sanitizeAt(at){if(typeof at!=="string")return"";return at.replace(/[\u0000-\u001f\u007f]/g," ").slice(0,MAX_AT_LENGTH)}function clearMarker(lockDir2,kind,deps={}){const rm=deps.rmSync??(p=>fs9.rmSync(p,{recursive:true,force:true}));try{rm(markerPath(lockDir2,kind))}catch{}}function watchMarker(lockDir2,kind,selfPid,onStop,deps={}){let fired=false;const timer=setInterval(()=>{if(fired)return;const req=readMarker(lockDir2,kind,deps);if(req===null||req.pid!==selfPid)return;fired=true;onStop(req)},deps.intervalMs??POLL_MS);timer.unref?.();return()=>{fired=true;clearInterval(timer)}}function safe(s){return stripTerminalControls(s)}function compactTimestamp(at=new Date){const p2=n=>String(n).padStart(2,"0");return`${at.getFullYear()}${p2(at.getMonth()+1)}${p2(at.getDate())}-${p2(at.getHours())}${p2(at.getMinutes())}${p2(at.getSeconds())}`}async function buildEngine(config,log){if(config.engine==="noop")return new NoopEngine;const{DispatchEngine}=await import("./ai-dispatch-UQHPVRWN.js");const{DEFAULT_PREFLIGHT_HOSTS}=await import("./ai-dispatch-UQHPVRWN.js");const extraHosts=config.
|
|
311
312
|
operations.preflightHosts;return new DispatchEngine(config.ai,log,{workspace:config.workspace,charterFile:config.charterFile??void 0,charterEnabled:config.charterEnabled,...config.charterPrefix===null?{}:{charterPrefix:config.charterPrefix},...config.charterSuffix===null?{}:{charterSuffix:config.charterSuffix},serverPrompts:()=>config.serverPrompts??{},compileCommand:config.compileCommand??void 0,launcherBin:config.claudeLauncher.bin,...extraHosts.length>0?{preflightHosts:[...DEFAULT_PREFLIGHT_HOSTS,
|
|
312
313
|
...extraHosts]}:{}})}function lockDir(config){return path8.join(config.stateDir,`task-loop-${projectFileKey(config.projectId)}.lock.d`)}async function runTaskLoop(opts){if(opts.action==="stop")return await stopLoop(opts);const profile=resolveProfile(opts.profile);let creds;try{creds=new AuthSession(profile.name,profile.apiUrl).loadOrThrow()}catch(err){process.stderr.write(`${err.message}
|
|
313
314
|
`);return 1}const apiUrl=effectiveApiUrl(profile,creds.api_url);const session=new AuthSession(profile.name,apiUrl);const projectRef=opts.project??process.env.TWP_PROJECT??"";if(projectRef===""){process.stderr.write("--project <\u30AD\u30FC|UUID> \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08TWP_PROJECT \u3067\u3082\u53EF\uFF09\n");return 2}const projectApi=new ProjectApi(apiUrl,session);let project;try{project=await projectApi.resolve(projectRef)}catch(err){process.stderr.write(`${err.
|
|
314
315
|
message}
|
|
315
|
-
`);return 1}const projectId=project.id;if(opts.action==="setup"){const{runSetup,parseAiList}=await import("./setup-
|
|
316
|
+
`);return 1}const projectId=project.id;if(opts.action==="setup"){const{runSetup,parseAiList}=await import("./setup-CDQ2CEUR.js");let ais;if(opts.ais!==void 0&&opts.ais.length>0){const parsed=parseAiList(opts.ais.join(","));if(parsed.unknown.length>0){process.stderr.write(`--ai \u306B\u672A\u77E5\u306E\u5024\u304C\u3042\u308A\u307E\u3059: ${parsed.unknown.join(" / ")}
|
|
316
317
|
`);return 2}ais=parsed.ais}return runSetup({projectId,projectRef,projectName:project.name===project.id?projectRef:`${project.code} / ${project.name}`,apiUrl,yes:opts.yes===true,...ais!==void 0?{ais}:{},...opts.workspace!==void 0?{workspace:opts.workspace}:{},...opts.aiConfigFile!==void 0?{aiConfigFile:opts.aiConfigFile}:{},...opts.noAiConfigFile===true?{noAiConfigFile:true}:{},...opts.profile!==void 0?{profile:opts.profile}:{}})}if(opts.action==="charter"){if(opts.charterOp===void 0){process.stderr.
|
|
317
318
|
write("charter \u306B\u306F push \u304B pull \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\n");return 2}if(isPrivateProjectId(projectId)){process.stderr.write("\u500B\u4EBA\u30BF\u30B9\u30AF\u306E\u30AD\u30E5\u30FC\uFF08--project __private__\uFF09\u306B\u306F\u61B2\u7AE0\u306E\u8A2D\u5B9A\u304C\u3042\u308A\u307E\u305B\u3093\n");return 2}const{runCharterCommand}=await import("./charter-command-ULFOEZWE.js");return runCharterCommand({api:new AgentLoopApi({apiUrl,projectId,session})},{op:opts.
|
|
318
319
|
charterOp,file:opts.charterInput,out:opts.charterOutput,revision:opts.charterRevision,yes:opts.yes===true,projectRef,profile:opts.profile})}if(opts.action==="skill"){if(opts.skillOp===void 0){process.stderr.write("skill \u306B\u306F push \u304B pull \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\n");return 2}if(isPrivateProjectId(projectId)){process.stderr.write("\u500B\u4EBA\u30BF\u30B9\u30AF\u306E\u30AD\u30E5\u30FC\uFF08--project __private__\uFF09\u306B\u306F\u30B9\u30AD\u30EB\u5B9A\u7FA9\u306E\u8A2D\u5B9A\u304C\u3042\u308A\u307E\u305B\u3093\n");
|
|
@@ -333,7 +334,7 @@ value:null};const shutdown=async()=>{if(shuttingDown)return;shuttingDown=true;st
|
|
|
333
334
|
once("SIGINT",onSignal);process.once("SIGTERM",onSignal);process.once("SIGHUP",onSignal);stopWatcher=watchMarker(lockDir(config),"stop",process.pid,req=>{log.log(`\u505C\u6B62\u8981\u6C42\u3092\u53D7\u3051\u53D6\u308A\u307E\u3057\u305F\uFF08${req.at||"\u6642\u523B\u4E0D\u660E"}\uFF09\u3002\u7D42\u4E86\u3057\u307E\u3059...`);stopWatcher?.();drainWatcher?.();driftWatcher?.();void shutdown().catch(()=>void 0).then(()=>process.exit(130))});drainWatcher=watchMarker(lockDir(config),"drain",process.pid,
|
|
334
335
|
req=>{drainWatcher?.();if(loop===null){pendingDrain.value={reason:`stop --drain\u30FB${req.at||"\u6642\u523B\u4E0D\u660E"}`,exitCode:0};log.log(`\u30C9\u30EC\u30A4\u30F3\u8981\u6C42\u3092\u53D7\u3051\u53D6\u308A\u307E\u3057\u305F\uFF08${req.at||"\u6642\u523B\u4E0D\u660E"}\uFF09\u3002\u8D77\u52D5\u51E6\u7406\u306E\u5B8C\u4E86\u5F8C\u306B\u53CD\u6620\u3057\u307E\u3059\u3002`);return}loop.requestDrain(`stop --drain\u30FB${req.at||"\u6642\u523B\u4E0D\u660E"}`)});if(installed!==null){const watch=watchVersionDrift(
|
|
335
336
|
{runningVersion:opts.version,stateDir:config.stateDir,projectKey:projectFileKey(config.projectId),supervised:autoRestart.supervised,disabled:autoRestart.disabled},{onWarn:reason=>log.log(`\u26A0\uFE0F ${reason}`),onRestart:({from,to})=>{driftWatcher?.();log.log(`\u7248\u30C9\u30EA\u30D5\u30C8\u3092\u691C\u51FA\u3057\u307E\u3057\u305F\uFF08${from} \u2192 ${to}\uFF09\u3002`);log.log(` \u5B9F\u884C\u4E2D\u306E\u30A2\u30A4\u30C6\u30E0\u3092\u5B8C\u8D70\u3055\u305B\u3066\u304B\u3089\u7D42\u4E86\u3057\u307E\u3059\uFF08\u7D42\u4E86\u30B3\u30FC\u30C9 ${EXIT_VERSION_DRIFT}\
|
|
336
|
-
\uFF09\u3002\u518D\u8D77\u52D5\u306F systemd\uFF08Restart=always\uFF09\u304C\u884C\u3044\u307E\u3059`);const reason=`\u7248\u30C9\u30EA\u30D5\u30C8 ${from} \u2192 ${to} \u306B\u3088\u308B\u81EA\u52D5\u518D\u8D77\u52D5`;if(loop===null)pendingDrain.value={reason,exitCode:EXIT_VERSION_DRIFT};else loop.requestDrain(reason,EXIT_VERSION_DRIFT)}});driftWatcher=watch.stop}try{const{LoopSettingsApplier:LoopSettingsApplier2}=await import("./server-settings-
|
|
337
|
+
\uFF09\u3002\u518D\u8D77\u52D5\u306F systemd\uFF08Restart=always\uFF09\u304C\u884C\u3044\u307E\u3059`);const reason=`\u7248\u30C9\u30EA\u30D5\u30C8 ${from} \u2192 ${to} \u306B\u3088\u308B\u81EA\u52D5\u518D\u8D77\u52D5`;if(loop===null)pendingDrain.value={reason,exitCode:EXIT_VERSION_DRIFT};else loop.requestDrain(reason,EXIT_VERSION_DRIFT)}});driftWatcher=watch.stop}try{const{LoopSettingsApplier:LoopSettingsApplier2}=await import("./server-settings-RC5BOWUW.js");const settings=new LoopSettingsApplier2(
|
|
337
338
|
{api,config,log:m=>log.log(m)});await settings.apply();await runner.checkHeartbeatInterval();await runner.registerOrThrow();runner.startHeartbeatWorker();log.log(` heartbeat: ${config.heartbeatIntervalSec}\u79D2\u3054\u3068\u306B\u9001\u4FE1${runner.heartbeatTimeoutServer?`\uFF08\u30B5\u30FC\u30D0\u306E\u6B7B\u6D3B\u3057\u304D\u3044\u5024 ${runner.heartbeatTimeoutServer}\u79D2\uFF09`:""}`);loop=new TaskLoop({api,projectApi,config,log,runner,engine:await buildEngine(config,m=>log.log(m)),settings});
|
|
338
339
|
if(pendingDrain.value!==null){loop.requestDrain(pendingDrain.value.reason,pendingDrain.value.exitCode)}exitCode=await loop.run()}catch(err){if(err instanceof RunnerRegistrationError){exitCode=1}else{log.log(`\u26D4 \u4E88\u671F\u3057\u306A\u3044\u30A8\u30E9\u30FC\u3067\u7D42\u4E86\u3057\u307E\u3059: ${err.message}`);exitCode=1}}finally{await shutdown()}return exitCode}async function showStatus(api,config){const out={write:text=>process.stdout.write(stripTerminalControls(text))};out.write(`\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\
|
|
339
340
|
: ${config.projectRef}\uFF08${config.projectId}\uFF09
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{defaultIsLoopProcess,readLockOwner,sameTwpHome}from"./chunk-3WHC4FSG.js";import{loopStateDir}from"./chunk-
|
|
3
|
+
import{defaultIsLoopProcess,readLockOwner,sameTwpHome}from"./chunk-3WHC4FSG.js";import{loopStateDir}from"./chunk-RDJYKA3U.js";import"./chunk-Y2XAWM2X.js";import"./chunk-N2UVRM3Z.js";import"./chunk-GY7KI5E5.js";import"./chunk-PMOUHEJQ.js";import"./chunk-5WGOHFAS.js";import{twpHomeDir}from"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";import fs from"fs";import path from"path";var PIDLESS_GRACE_MS=6e4;function defaultStateDirs(env){const dirs=[loopStateDir(env),loopStateDir({})].map(d=>path.resolve(d));return[...new Set(dirs)]}function readPidFile(lockDir){try{const raw=fs.readFileSync(path.join(lockDir,"pid"),"utf8").split("\n")[0]?.trim()??"";const n=Number.parseInt(raw,10);return{pid:Number.isInteger(n)&&n>0?n:null,error:null}}catch(err){const code=err.code;return{pid:null,error:code==="ENOENT"?null:code??err.message}}}function findLoopsUsingProfile(profileName,deps={}){
|
|
4
4
|
const env=deps.env??process.env;const now=deps.now??Date.now;const isLoopProcess=deps.isLoopProcess??defaultIsLoopProcess;const myHome=twpHomeDir(env);const result={users:[],undetermined:[]};for(const stateDir of deps.stateDirs??defaultStateDirs(env)){let dirs;try{dirs=fs.readdirSync(stateDir).filter(d=>/^task-loop-.*\.lock\.d$/.test(d))}catch(err){if(err.code==="ENOENT")continue;result.undetermined.push({pid:null,lockDir:stateDir,reason:`\u30ED\u30C3\u30AF\u306E\u7F6E\u304D\u5834\u6240\u3092\u8AAD\u3081\u307E\u305B\u3093\uFF08${err.
|
|
5
5
|
code??err.message}\uFF09`});continue}for(const dir of dirs){const lockDir=path.join(stateDir,dir);const pidFile=readPidFile(lockDir);if(pidFile.error!==null){result.undetermined.push({pid:null,lockDir,reason:`pid \u3092\u8AAD\u3081\u307E\u305B\u3093\uFF08${pidFile.error}\uFF09`});continue}const owner=readLockOwner(lockDir);let pid=pidFile.pid;if(pid===null){if(owner.ok){pid=owner.owner.pid}else{let ageMs=null;try{ageMs=now()-fs.statSync(lockDir).mtimeMs}catch{}if(ageMs!==null&&ageMs>=PIDLESS_GRACE_MS)
|
|
6
6
|
continue;result.undetermined.push({pid:null,lockDir,reason:"\u30ED\u30C3\u30AF\u306B pid \u304C\u3042\u308A\u307E\u305B\u3093\uFF08\u8D77\u52D5\u76F4\u5F8C\u306E\u53EF\u80FD\u6027\uFF09"});continue}}if(!isLoopProcess(pid))continue;if(!owner.ok){result.undetermined.push({pid,lockDir,reason:owner.reason});continue}if(owner.owner.pid!==pid){result.undetermined.push({pid,lockDir,reason:`\u6240\u6709\u8005\u306E\u8A18\u9332\uFF08pid=${owner.owner.pid}\uFF09\u304C\u30ED\u30C3\u30AF\u306E pid \u3068\u4E00\u81F4\u3057\u307E\u305B\u3093`});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{CURATED_PAGING_VOCABULARY,buildPrepareContext,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain}from"./chunk-
|
|
3
|
+
import{CURATED_PAGING_VOCABULARY,buildPrepareContext,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain}from"./chunk-4F4Q6AES.js";import"./chunk-IOGVQVGD.js";import"./chunk-5Q2CH4E7.js";import"./chunk-YVAN3H5W.js";import"./chunk-G4OO4M44.js";import"./chunk-NIAOX77K.js";import"./chunk-GMBJTG6A.js";import"./chunk-FTYJZFEK.js";import"./chunk-II5RVJQN.js";import"./chunk-TAN5I2DP.js";import"./chunk-SP27PYHC.js";
|
|
4
4
|
import"./chunk-QQRJLH6B.js";import"./chunk-XNLIEUAW.js";import"./chunk-J7QYPKVK.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import"./chunk-K2ONOH3L.js";import"./chunk-WVS4W5FY.js";import"./chunk-NHYMHCAT.js";import"./chunk-GDM2QUBL.js";import"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";export{CURATED_PAGING_VOCABULARY,buildPrepareContext,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{LoopSettingsApplier,PROMPT_KEYS,formatConfigHash,parseServerSettings,renderStepBudget}from"./chunk-
|
|
3
|
+
import{LoopSettingsApplier,PROMPT_KEYS,formatConfigHash,parseServerSettings,renderStepBudget}from"./chunk-XAMHF5MK.js";import"./chunk-BKZGBJWT.js";import"./chunk-Y2XAWM2X.js";import"./chunk-GY7KI5E5.js";import"./chunk-PMOUHEJQ.js";import"./chunk-J7QYPKVK.js";import"./chunk-5WGOHFAS.js";import"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";export{LoopSettingsApplier,PROMPT_KEYS,formatConfigHash,parseServerSettings,renderStepBudget};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{detectAiClis,formatDetection,isDetectableAi,isSelectable}from"./chunk-
|
|
3
|
+
import{detectAiClis,formatDetection,isDetectableAi,isSelectable}from"./chunk-5PU5QU5U.js";import{PromptAbortedError,promptText}from"./chunk-L37NS5L2.js";import{localConfigPath,parseClaudeLauncher}from"./chunk-RDJYKA3U.js";import{AiConfig}from"./chunk-Y2XAWM2X.js";import"./chunk-N2UVRM3Z.js";import"./chunk-GY7KI5E5.js";import"./chunk-PMOUHEJQ.js";import"./chunk-5WGOHFAS.js";import"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";
|
|
4
4
|
import"./chunk-VSJBJXZO.js";import fs from"fs";import path from"path";var RECOMMENDED_ROTATION={complex:["claude"],verify:["claude"],security:["claude"],support:["claude"],triage:["claude"],search:["claude"],simple:["claude"]};var RECOMMENDED_CHAINS={complex:["claude","codex"],verify:["claude","codex","copilot"],security:["claude","codex","copilot"],support:["claude","codex","copilot"],triage:["codex","gemini","copilot","claude"],search:["codex","gemini","copilot","claude"],simple:["codex","gemini","copilot","claude"]};var PREFERENCE=["claude","codex","gemini","co\
|
|
5
5
|
pilot"];function buildAiAssignment(selected){if(selected.length===0)throw new Error("\u9078\u629E\u3055\u308C\u305FAI\u304C\u7A7A\u3067\u3059");const fallbackOrder=PREFERENCE.filter(ai=>selected.includes(ai));for(const ai of selected)if(!fallbackOrder.includes(ai))fallbackOrder.push(ai);const chains={};const rotation={};for(const category of Object.keys(RECOMMENDED_CHAINS)){const filtered=(RECOMMENDED_CHAINS[category]??[]).filter(ai=>selected.includes(ai));const chain=filtered.length>0?filtered:
|
|
6
6
|
[...fallbackOrder];chains[category]=chain;const rot=(RECOMMENDED_ROTATION[category]??[]).filter(ai=>selected.includes(ai));const head=chain[0];rotation[category]=rot.length>0?rot:head===void 0?[...fallbackOrder]:[head]}return{primary_rotation:rotation,fallback_chains:chains}}var SETUP_EXIT_NO_CLI=3;var SETUP_EXIT_ABORTED=130;async function runSetup(opts){const env=opts.env??process.env;const rawOut=opts.out??(t=>void process.stdout.write(t));const rawErr=opts.err??(t=>void process.stderr.write(t));
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
3
|
import{repeatedValues}from"./chunk-IOGVQVGD.js";import{createFlags,fieldBody,hasAnyField,resolveRefFields,updateFlags}from"./chunk-IRAZ27WL.js";import{booleanText,boundedText,isoDate,isoDateValue}from"./chunk-UDPJ2IGK.js";import{LIST_FLAGS,LIST_PAGING_HELP,envelopePaging,flagSegment,nonEmpty,positiveInteger,shellQuote}from"./chunk-G4OO4M44.js";import{DEPARTMENTS_PATH,ORG_MASTER_LIMIT,POSITIONS_PATH}from"./chunk-NIAOX77K.js";import{ResolveError,isSafePathSegment}from"./chunk-GMBJTG6A.js";
|
|
4
|
-
import{ApiError}from"./chunk-FTYJZFEK.js";import{requireResolved,singleRef,withResolved}from"./chunk-ZN5EFDH7.js";import"./chunk-II5RVJQN.js";import{isRecord,pick}from"./chunk-ZWVYVS2A.js";import"./chunk-QQRJLH6B.js";import"./chunk-J7QYPKVK.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import"./chunk-NHYMHCAT.js";import{ApiRejectedError,ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";import
|
|
4
|
+
import{ApiError}from"./chunk-FTYJZFEK.js";import{requireResolved,singleRef,withResolved}from"./chunk-ZN5EFDH7.js";import"./chunk-II5RVJQN.js";import{isRecord,pick}from"./chunk-ZWVYVS2A.js";import"./chunk-QQRJLH6B.js";import"./chunk-J7QYPKVK.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import"./chunk-NHYMHCAT.js";import{ApiRejectedError,ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";import fs3 from"fs";import fs from"fs";var BOM=new RegExp(`^${String.fromCharCode(65279)}`);function decodeCsvText(bytes){try{return new TextDecoder("utf-8",{fatal:true}).decode(bytes).replace(BOM,"")}catch{return new TextDecoder("shift_jis").decode(bytes)}}function readCsvFileText(file,usage,maxBytes,tooLarge){try{const stat=fs.statSync(file);if(!stat.isFile())throw new UsageError(`--file \u306B\u901A\u5E38\u306E\u30D5\u30A1\u30A4\u30EB\u4EE5\u5916\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093: ${file}`,usage);if(stat.size>maxBytes)
|
|
5
|
+
throw tooLarge(stat.size);return decodeCsvText(fs.readFileSync(file))}catch(err){if(err instanceof UsageError)throw err;const reason=err.code??err.message;throw new UsageError(`--file \u306E\u30D5\u30A1\u30A4\u30EB\u3092\u8AAD\u3081\u307E\u305B\u3093: ${file}\uFF08${reason}\uFF09`,usage)}}var USER_REF_HELP="<\u30E6\u30FC\u30B6\u30FC> \u306F ID\u30FB\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u30FB\u793E\u54E1\u756A\u53F7\u30FB\u6C0F\u540D\u30FBme\uFF08\u81EA\u5206\uFF09\u306E\u3069\u308C\u3067\u3082\u6307\u5B9A\u3067\u304D\u307E\u3059\u3002\n\u6C0F\u540D\u306F\u5B8C\u5168\u4E00\u81F4\u30671\u4EBA\u306B\u7D5E\u308C\u305F\u3068\u304D\u3060\u3051\u53D7\u3051\u4ED8\u3051\u307E\u3059\uFF08\u540C\u59D3\u540C\u540D\u306A\u3089\u5019\u88DC\u3092\u51FA\u3057\u3066\u6B62\u307E\u308B\u306E\u3067\u3001\n\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u304B\u793E\u54E1\u756A\u53F7\u3067\u6307\u5B9A\u3057\u76F4\u3057\u3066\u304F\u3060\u3055\u3044\uFF09\u3002ID \u4EE5\u5916\u306F\u3001\u30C6\u30CA\u30F3\u30C8\u306E\u30E6\u30FC\u30B6\u30FC\u4E00\u89A7\n\uFF08\u65E2\u5B9A10\u5206\u30AD\u30E3\u30C3\u30B7\u30E5\u30FB--refresh \u3067\u53D6\u308A\u76F4\u3057\uFF09\u3068\u7167\u5408\u3057\u307E\u3059\u3002\n\u8868\u793A\u30D5\u30E9\u30B0\u3092\u5916\u3057\u305F\u30E6\u30FC\u30B6\u30FC\u306F\u793E\u54E1\u756A\u53F7\u3067\u306F\u5F15\u3051\u307E\u305B\u3093\u3002\u7D44\u7E54\u7BA1\u7406\u8005\u3067\u306A\u3044\u5834\u5408\u306F ID \u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002";
|
|
5
6
|
function userPath(input,suffix=""){const userId=requireResolved(input,"userId");if(!isSafePathSegment(userId)){throw new ApiResponseError(`\u30B5\u30FC\u30D0\u304C\u8FD4\u3057\u305F\u30E6\u30FC\u30B6\u30FC ID \u3092\u30D1\u30B9\u306B\u4F7F\u3048\u307E\u305B\u3093: ${userId}\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}return`${encodeURIComponent(userId)}${suffix}`}var USER_REF_FLAG={name:"--user",summary:"\u5BFE\u8C61\u306E\u30E6\u30FC\u30B6\u30FC\uFF08\u4F4D\u7F6E\u5F15\u6570\u306E\u4EE3\u308F\u308A\u306B\u4F7F\u3048\u308B\uFF09",
|
|
6
7
|
takesValue:true,placeholder:"<\u30E6\u30FC\u30B6\u30FC>"};async function prepareUser(input,ctx,usage){const ref=singleRef(input,{flag:"--user",label:"\u30E6\u30FC\u30B6\u30FC",usage});const user=await ctx.resolver.user(ref);return withResolved(input,{userId:user.id})}var ASSIGNMENT_COLUMNS=["id","department_name","position_name","start_date","end_date","is_primary","is_current","is_approval_route","effective_status"];function assignmentRows(body){const response=isRecord(body)&&"response"in body?body["response"]:body;const list=isRecord(response)?response["list"]:void 0;if(!Array.isArray(list)){throw new ApiResponseError("\u6240\u5C5E\u4E00\u89A7\u306E\u5FDC\u7B54\u306B list \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
7
8
|
return list}async function nameMap(ctx,path,label2){try{const body=await ctx.send({method:"GET",path,query:{limit:ORG_MASTER_LIMIT}});const list=isRecord(body)?body["list"]:void 0;if(!Array.isArray(list))throw new Error(`${label2}\u4E00\u89A7\u306E\u5FDC\u7B54\u306B list \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093`);const count=isRecord(body)?body["count"]:void 0;if(typeof count==="number"&&count>list.length){ctx.warn(`${label2}\u4E00\u89A7\u304C ${count} \u4EF6\u4E2D ${list.length} \u4EF6\u3067\u5207\u308A\u8A70\u3081\u3089\
|
|
@@ -73,17 +74,16 @@ takesValue:true,placeholder:"<CSV>"};var ROW_FLAGS=[...MOVE_FIELDS.map(field=>fi
|
|
|
73
74
|
trim());cell2=""}else{cell2+=ch}}cells.push(cell2.trim());return cells}var MOVE_CSV_HEADERS=new Set(["user","\u30E6\u30FC\u30B6\u30FC","email","\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9"]);function parseMoveCsv(text){const rows=[];const errors=[];const seen=new Map;let headerChecked=false;text.replace(/^\uFEFF/,"").split(/\r?\n/).forEach((raw,index)=>{const line=index+1;if(raw.trim()===""||raw.trim().startsWith("#"))return;const cells=splitCsvLine(raw);if(!headerChecked){headerChecked=true;if(MOVE_CSV_HEADERS.
|
|
74
75
|
has((cells[0]??"").toLowerCase()))return}if(cells.length<3||cells.length>7){errors.push(`${line} \u884C\u76EE: \u5217\u304C ${cells.length} \u500B\u3042\u308A\u307E\u3059\uFF08\u30E6\u30FC\u30B6\u30FC, \u90E8\u7F72, \u7570\u52D5\u65E5[, \u5F79\u8077, \u8077\u4F4D, \u4E0A\u9577, \u89B3\u5BDF\u8005] \u306E3\u301C7\u5217\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF09`);return}const[user="",department="",date="",position="",jobTitle="",manager="",observers=""]=cells;const missing=[user===""?"\u30E6\u30FC\u30B6\u30FC":
|
|
75
76
|
null,department===""?"\u90E8\u7F72":null,date===""?"\u7570\u52D5\u65E5":null].filter(item=>item!==null);if(missing.length>0){errors.push(`${line} \u884C\u76EE: ${missing.join("\u30FB")}\u304C\u7A7A\u3067\u3059`);return}let startDate;try{startDate=isoDateValue(date,"\u7570\u52D5\u65E5")}catch(err){errors.push(`${line} \u884C\u76EE: ${err.message}`);return}const key=user.toLowerCase();const first=seen.get(key);if(first!==void 0){errors.push(`${line} \u884C\u76EE: ${user} \u306F ${first} \u884C\u76EE\u3068\u91CD\u8907\u3057\u3066\u3044\u307E\u3059\
|
|
76
|
-
\uFF081\u4EBA\u306B\u3064\u304D1\u884C\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF09`);return}seen.set(key,line);const observerRefs=observers.split(";").map(ref=>ref.trim()).filter(ref=>ref!=="");rows.push({line,user,department,startDate,position:position===""?null:position,jobTitle:jobTitle===""?null:jobTitle,manager:manager===""?null:manager,observers:observerRefs})});return{rows,errors}}function readMoveCsv(file,usage){
|
|
77
|
-
`--file \
|
|
78
|
-
|
|
79
|
-
resolver.user(row.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
length} \u884C\u3042\u308B\u305F\u3081\u30011\u4EF6\u3082\u9001\u3063\u3066\u3044\u307E\u305B\u3093:
|
|
77
|
+
\uFF081\u4EBA\u306B\u3064\u304D1\u884C\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF09`);return}seen.set(key,line);const observerRefs=observers.split(";").map(ref=>ref.trim()).filter(ref=>ref!=="");rows.push({line,user,department,startDate,position:position===""?null:position,jobTitle:jobTitle===""?null:jobTitle,manager:manager===""?null:manager,observers:observerRefs})});return{rows,errors}}function readMoveCsv(file,usage){return readCsvFileText(file,usage,MOVE_CSV_MAX_BYTES,size=>new UsageError(
|
|
78
|
+
`--file \u306E\u30D5\u30A1\u30A4\u30EB\u304C\u5927\u304D\u3059\u304E\u307E\u3059\uFF08${size} \u30D0\u30A4\u30C8\u30FB\u4E0A\u9650 ${MOVE_CSV_MAX_BYTES} \u30D0\u30A4\u30C8\uFF09: ${file}`,"CSV \u3092\u5206\u3051\u3066\u6253\u3063\u3066\u304F\u3060\u3055\u3044\u3002"))}function isBulk(input){return input.flags.has(FILE_FLAG.name)}function bulkMoveRows(input){return JSON.parse(requireResolved(input,"bulkRows"))}function rowPlan(row){return{method:"POST",path:assignmentsPath(row.userId),body:row.body}}
|
|
79
|
+
async function prepareBulkRow(row,ctx,usage){const user=await ctx.resolver.user(row.user,"\u30E6\u30FC\u30B6\u30FC");const department=await ctx.resolver.department(row.department,"\u90E8\u7F72");const position=row.position===null?null:await ctx.resolver.position(row.position,"\u5F79\u8077");const noJobTitle=row.jobTitle!==null&&row.jobTitle.toLowerCase()===NO_JOB_TITLE;const jobTitle=row.jobTitle===null||noJobTitle?null:await ctx.resolver.jobTitle(row.jobTitle,"\u8077\u4F4D");const manager=row.manager===
|
|
80
|
+
null?null:await ctx.resolver.user(row.manager,"\u4E0A\u9577");const observers=[];for(const ref of row.observers)observers.push((await ctx.resolver.user(ref,"\u89B3\u5BDF\u8005")).id);const preflight=await primaryPreflight(ctx,user.id,row.startDate,usage);const current=preflight["currentPrimary"]===""||preflight["currentPrimary"]===void 0?null:JSON.parse(preflight["currentPrimary"]);let positionId=position?.id??null;if(positionId===null){if(current?.position_id==null){throw new UsageError("\u73FE\u5728\u306E\u4E3B\u6240\u5C5E\
|
|
81
|
+
\u304C\u7121\u3044\uFF08\u307E\u305F\u306F\u5F79\u8077\u304C\u7121\u3044\uFF09\u305F\u3081\u3001\u5F79\u8077\u3092\u5F15\u304D\u7D99\u3052\u307E\u305B\u3093\u3002\u5F79\u8077\u306E\u5217\u3092\u57CB\u3081\u3066\u304F\u3060\u3055\u3044")}positionId=current.position_id}const jobTitleId=jobTitle?.id??(noJobTitle?null:current?.job_title_id??null);const body={department_id:department.id,position_id:positionId};if(jobTitleId!==null)body["job_title_id"]=jobTitleId;if(manager!==null)body["manager_id"]=manager.
|
|
82
|
+
id;body["start_date"]=row.startDate;if(observers.length>0)body["observer_ids"]=observers;body["is_primary"]=true;return{line:row.line,user:row.user,userId:user.id,body,existingIds:JSON.parse(preflight["existingIds"]??"[]"),preview:{current,startDate:row.startDate,today:preflight["today"]??"",newDepartmentName:await nameOf(()=>ctx.resolver.departments(),department.id)??department.id,newPositionName:await nameOf(()=>ctx.resolver.positions(),positionId)??positionId,inheritedPosition:position===null,
|
|
83
|
+
inheritedJobTitle:jobTitle===null&&!noJobTitle&&jobTitleId!==null,given:{manager:manager!==null,observers:observers.length>0,interviewer:false,mentor:false}}}}async function prepareBulkMove(input,ctx){const usage="twp user assignment move help";if(input.args.length>0){throw new UsageError(`--file \u306E\u3068\u304D\u306F\u30E6\u30FC\u30B6\u30FC\u3092\u4F4D\u7F6E\u5F15\u6570\u3067\u53D7\u3051\u307E\u305B\u3093\uFF08CSV \u306E\u5217\u3067\u6307\u5B9A\u3057\u307E\u3059\uFF09: ${input.args.join(" ")}`,
|
|
84
|
+
usage)}const mixed=ROW_FLAGS.filter(flag=>input.flags.has(flag));if(mixed.length>0){throw new UsageError(`--file \u3068 ${mixed.join(" / ")} \u306F\u540C\u6642\u306B\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\uFF08\u884C\u3054\u3068\u306E\u5024\u306F CSV \u306E\u5217\u3067\u6E21\u3057\u307E\u3059\uFF09`,usage)}const file=input.flags.get(FILE_FLAG.name);if(file===void 0||file.trim()==="")throw new UsageError("--file <CSV> \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",usage);const parsed=parseMoveCsv(
|
|
85
|
+
readMoveCsv(file,usage));const errors=[...parsed.errors.map(text=>({line:Number(text.split(" ")[0]),text}))];const rows=[];const byUserId=new Map;for(const row of parsed.rows){try{const prepared=await prepareBulkRow(row,ctx,usage);const first=byUserId.get(prepared.userId);if(first!==void 0)throw new UsageError(`${row.user} \u306F ${first} \u884C\u76EE\u3068\u540C\u3058\u30E6\u30FC\u30B6\u30FC\u3067\u3059\uFF081\u4EBA\u306B\u3064\u304D1\u884C\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF09`);byUserId.
|
|
86
|
+
set(prepared.userId,row.line);rows.push(prepared)}catch(err){if(!(err instanceof UsageError))throw err;errors.push({line:row.line,text:`${row.line} \u884C\u76EE: ${err.message}`})}}if(errors.length>0){errors.sort((a,b)=>a.line-b.line);throw new UsageError(`CSV \u306B\u4E0D\u6B63\u306A\u884C\u304C ${errors.length} \u884C\u3042\u308B\u305F\u3081\u30011\u4EF6\u3082\u9001\u3063\u3066\u3044\u307E\u305B\u3093:
|
|
87
87
|
${errors.map(e=>e.text).join("\n ")}`,`\u6B63\u3057\u3044\u884C\u306F ${rows.length} \u884C\u3067\u3059\u3002\u4E0D\u6B63\u306A\u884C\u3092\u76F4\u3059\u304B\u524A\u9664\u3057\u3066\u304B\u3089\u6253\u3061\u76F4\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}if(rows.length===0)throw new UsageError(`CSV \u306B\u4ED8\u3051\u66FF\u3048\u308B\u884C\u304C\u3042\u308A\u307E\u305B\u3093: ${file}`,usage);return withResolved(input,{bulkRows:JSON.stringify(rows)})}function bulkPlannedNotes(input){const rows=bulkMoveRows(
|
|
88
88
|
input);const lines=[`${rows.length} \u4EF6\u3092\u4ED8\u3051\u66FF\u3048\u307E\u3059\uFF081\u884C\u305A\u3064\u6240\u5C5E\u306E\u4F5C\u6210\u3092 POST \u3057\u307E\u3059\u3002--dry-run \u306B\u51FA\u308B\u8981\u6C42\u306F1\u4EF6\u76EE\u306E\u5206\u3067\u3059\uFF09:`];for(const row of rows){lines.push(` ${row.line} \u884C\u76EE: ${row.user}`);lines.push(...movePreviewLines(row.preview," "))}lines.push("\u9001\u4FE1\u4E2D\u306B\u5931\u6557\u3057\u305F\u3089\u305D\u3053\u3067\u6B62\u3081\u3001\u6210\u529F\u3057\u305F\u884C\u30FB\u5931\u6557\u3057\u305F\u884C\u30FB\u672A\u9001\u4FE1\u306E\u884C\u3068\u3001\u6210\u529F\u3057\u305F\u884C\u306E\u623B\u3057\u65B9\u3092\u51FA\u3057\u307E\u3059\u3002");
|
|
89
89
|
return lines}function rowRevertCommands(row,newId){const current=row.preview.current;if(current===null)return[`twp user assignment delete ${shellQuote(newId)} --user ${shellQuote(row.userId)} --yes`];const immediate=row.preview.startDate<=row.preview.today;return revertCommands(row.userId,current,newId,immediate)}function isBulkBody(body){return isRecord(body)&&body["bulk"]===true&&Array.isArray(body["done"])}function revertBlock(done){const lines=[];for(const item of done){lines.push(` ${item.
|
|
@@ -139,10 +139,10 @@ ${commands.map(c=>` ${c}`).join("\n")}${later}`)}return notes}};var userAssignm
|
|
|
139
139
|
olumn <\u5217\u540D>] [--position-column <\u5217\u540D>] [--max-users <\u4EBA\u6570>]";var HELP="twp user export help";var listPaging=envelopePaging({label:"\u30E6\u30FC\u30B6\u30FC\u4E00\u89A7"});var LEDGER_ROLES=["code","name","email","department","position"];var ROLE_LABEL={code:"\u793E\u54E1\u756A\u53F7",name:"\u6C0F\u540D",email:"\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9",department:"\u90E8\u7F72",position:"\u5F79\u8077"};var COLUMN_CANDIDATES={code:["\u793E\u54E1\u756A\u53F7","\u5F93\u696D\u54E1\u756A\u53F7",
|
|
140
140
|
"\u793E\u54E1\u30B3\u30FC\u30C9","\u5F93\u696D\u54E1\u30B3\u30FC\u30C9","employee_code","employee_no"],name:["\u6C0F\u540D","\u540D\u524D","\u793E\u54E1\u540D","\u5F93\u696D\u54E1\u540D","name","user_name"],email:["\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9","\u4F1A\u793E\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9","email","login_id"],department:["\u90E8\u7F72","\u90E8\u7F72\u540D","\u6240\u5C5E\u90E8\u7F72","department","department_name"],position:["\u5F79\u8077","\u5F79\u8077\u540D","position",
|
|
141
141
|
"position_name"]};function parseCsvRecords(text){const records=[];let cells=[];let field="";let quoted=false;let started=false;let line=1;let recordLine=1;let i=0;const pushRecord=()=>{cells.push(field);records.push({line:recordLine,cells});cells=[];field="";started=false};while(i<text.length){const ch=text[i];if(quoted){if(ch==='"'){if(text[i+1]==='"'){field+='"';i+=2;continue}quoted=false}else if(ch==="\r"||ch==="\n"){if(ch==="\r"&&text[i+1]==="\n")i+=1;line+=1;field+="\n"}else{field+=ch}i+=1;
|
|
142
|
-
continue}if(ch==='"'&&field.trim()===""){quoted=true;started=true;field=""}else if(ch===","){cells.push(field);field="";started=true}else if(ch==="\r"||ch==="\n"){if(ch==="\r"&&text[i+1]==="\n")i+=1;pushRecord();line+=1;recordLine=line}else{field+=ch;started=true}i+=1}if(quoted)throw new UsageError(`\u53F0\u5E33 CSV \u306E ${recordLine} \u884C\u76EE\u3067\u5F15\u7528\u7B26\uFF08"\uFF09\u304C\u9589\u3058\u3066\u3044\u307E\u305B\u3093`,HELP);if(started)pushRecord();return records}var
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
continue}if(ch==='"'&&field.trim()===""){quoted=true;started=true;field=""}else if(ch===","){cells.push(field);field="";started=true}else if(ch==="\r"||ch==="\n"){if(ch==="\r"&&text[i+1]==="\n")i+=1;pushRecord();line+=1;recordLine=line}else{field+=ch;started=true}i+=1}if(quoted)throw new UsageError(`\u53F0\u5E33 CSV \u306E ${recordLine} \u884C\u76EE\u3067\u5F15\u7528\u7B26\uFF08"\uFF09\u304C\u9589\u3058\u3066\u3044\u307E\u305B\u3093`,HELP);if(started)pushRecord();return records}var decodeLedger=decodeCsvText;
|
|
143
|
+
function normalizeHeader(value){return value.normalize("NFKC").trim().toLowerCase()}function normalizeValue(value){return value.normalize("NFKC").replace(/\s+/g," ").trim().toLowerCase()}function resolveColumns(header,overrides){const normalized=header.map(normalizeHeader);const map={};for(const role of LEDGER_ROLES){const wanted=overrides[role];if(wanted!==void 0){const index2=normalized.indexOf(normalizeHeader(wanted));if(index2<0){throw new UsageError(`\u53F0\u5E33 CSV \u306B\u300C${wanted}\u300D\u3068\
|
|
144
|
+
\u3044\u3046\u5217\u304C\u3042\u308A\u307E\u305B\u3093\uFF08--${role}-column\uFF09`,`\u898B\u51FA\u3057\u884C\u306E\u5217: ${header.map(h=>h.trim()).join("\u3001")}`)}map[role]=index2;continue}const index=normalized.findIndex(h=>COLUMN_CANDIDATES[role].some(c=>normalizeHeader(c)===h));if(index>=0)map[role]=index}if(map.code===void 0&&map.email===void 0&&map.name===void 0){throw new UsageError("\u53F0\u5E33 CSV \u306B\u3001\u4EBA\u3092\u7A81\u304D\u5408\u308F\u305B\u308B\u5217\uFF08\u793E\u54E1\u756A\u53F7\u30FB\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u30FB\u6C0F\u540D\u306E\u3069\u308C\u304B\uFF09\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093",
|
|
145
|
+
`\u898B\u51FA\u3057\u884C\u306E\u5217: ${header.map(h=>h.trim()).join("\u3001")}
|
|
146
146
|
\u5217\u540D\u304C\u9055\u3046\u3068\u304D\u306F --code-column / --email-column / --name-column \u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}return map}function parseLedger(text,overrides){const records=parseCsvRecords(text).filter(r=>r.cells.some(c=>c.trim()!==""));const[header,...body]=records;if(header===void 0)throw new UsageError("\u53F0\u5E33 CSV \u304C\u7A7A\u3067\u3059\uFF081\u884C\u76EE\u306B\u898B\u51FA\u3057\u304C\u5FC5\u8981\u3067\u3059\uFF09",HELP);const columns=resolveColumns(
|
|
147
147
|
header.cells,overrides);const rows=[];const errors=[];const seen={code:new Map,email:new Map};for(const record of body){const value=role=>{const index=columns[role];if(index===void 0)return void 0;const raw=(record.cells[index]??"").trim();return raw===""?void 0:raw};const cells={};for(const role of LEDGER_ROLES){const v=value(role);if(v!==void 0)cells[role]=v}const row={line:record.line,...cells};if(row.code===void 0&&row.email===void 0&&row.name===void 0){errors.push(`${record.line} \u884C\u76EE: \u793E\u54E1\u756A\u53F7\u30FB\u30E1\
|
|
148
148
|
\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u30FB\u6C0F\u540D\u304C\u3059\u3079\u3066\u7A7A\u3067\u3059`);continue}let duplicated=false;for(const role of["code","email"]){const v=row[role];if(v===void 0)continue;const first=seen[role].get(normalizeValue(v));if(first!==void 0){errors.push(`${record.line} \u884C\u76EE: ${ROLE_LABEL[role]} ${v} \u306F ${first} \u884C\u76EE\u3068\u91CD\u8907\u3057\u3066\u3044\u307E\u3059`);duplicated=true}else{seen[role].set(normalizeValue(v),record.line)}}if(!duplicated)rows.
|
|
@@ -223,33 +223,32 @@ bled")?rows:rows.filter(r=>r.can_login);return{mode:"inventory",rows:visible,sca
|
|
|
223
223
|
rows.map(row=>Object.fromEntries(INVENTORY_COLUMNS.map(c=>{if(c==="permissions")return[c,permissionText(row.permissions)];if(c==="last_login_at")return[c,lastLoginText(row)];if(c==="manager_name")return[c,spreadsheetSafe(row.manager_name??row.manager_id)];return[c,spreadsheetSafe(row[c])]})))},raw:body=>exportBody(body).rows,notes(body){const result=exportBody(body);const notes=[`${result.scanned} \u4EBA\u3092\u8AAD\u307F\u307E\u3057\u305F\uFF08\u3046\u3061\u5931\u52B9\u6E08\u307F ${result.disabled}\
|
|
224
224
|
\u4EBA\uFF09\u3002`+(result.excludedHidden?"\u8868\u793A\u30D5\u30E9\u30B0\u3092\u5916\u3057\u305F\u30E6\u30FC\u30B6\u30FC\u306F\u5BFE\u8C61\u5916\u3067\u3059\uFF08--exclude-hidden\uFF09\u3002":"")];if(result.ssoUndetermined>0){notes.push(`\u8A8D\u8A3C\u30BF\u30A4\u30D7\u304C oauth \u306E ${result.ssoUndetermined} \u4EBA\u306F\u3001SSO \u306E\u30ED\u30B0\u30A4\u30F3\u304C\u8A18\u9332\u3055\u308C\u306A\u3044\u305F\u3081\u6700\u7D42\u30ED\u30B0\u30A4\u30F3\u3092\u5224\u5B9A\u3057\u3066\u3044\u307E\u305B\u3093\u3002`)}
|
|
225
225
|
if(result.mode==="diff"){const counts=new Map;for(const row of result.rows)counts.set(row.kind,(counts.get(row.kind)??0)+1);notes.push(counts.size===0?"\u53F0\u5E33\u3068\u306E\u5DEE\u5206\u306F\u3042\u308A\u307E\u305B\u3093\u3002":`\u5DEE\u5206: ${[...counts].map(([kind,n])=>`${kind} ${n}\u4EF6`).join(" / ")}`);if(result.excludedHidden){notes.push("--exclude-hidden \u306E\u305F\u3081\u3001\u8868\u793A\u30D5\u30E9\u30B0\u3092\u5916\u3057\u305F\u307E\u307E\u5931\u52B9\u3057\u3066\u3044\u306A\u3044\u30E6\u30FC\u30B6\u30FC\uFF08\u5931\u52B9\u6F0F\u308C\uFF09\u306F\u51FA\u3066\u3044\u307E\u305B\u3093\u3002\u307E\u305F\u3001\u8868\u793A\u30D5\u30E9\u30B0\u3092\u5916\u3057\u305F\u30E6\u30FC\u30B6\u30FC\u304C missing_in_twp\uFF08\u767B\u9332\u6F0F\u308C\uFF09\u3068\u3057\u3066\u51FA\u3066\u3044\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002")}}
|
|
226
|
-
return notes}};
|
|
226
|
+
return notes}};var INVITATIONS_PATH="/api/v2/admin/invitations";var INVITE_ROLES=["user","admin","super_admin"];var BULK_MAX=50;var CSV_MAX_BYTES=256*1024;var EMAIL_RE=/^[^\s@,;]+@[^\s@,;]+$/;var LIST_COLUMNS=["email","user_name","role","status","created_at","expires_at"];var ROLE_HELP="\u6A29\u9650\u306F user\uFF08\u4E00\u822C\uFF09/ admin\uFF08\u7BA1\u7406\u8005\uFF09/ super_admin\uFF08\u5168\u4F53\u7BA1\u7406\u8005\uFF09\u3067\u3059\u3002";var FORBIDDEN2="\u7D44\u7E54\u7BA1\u7406\u8005\u306E\u6A29\u9650\u304C\u5FC5\u8981\u3067\u3059\u3002\u30E6\u30FC\u30B6\u30FC\u306E\u62DB\u5F85\u306F\u7D44\u7E54\u7BA1\u7406\u8005\u3060\u3051\u304C\u6271\u3048\u307E\u3059";
|
|
227
227
|
var INVITE_REF_HELP="<\u62DB\u5F85> \u306F\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u3067\u6307\u5B9A\u3057\u307E\u3059\uFF08\u672A\u53D7\u8AFE\u306E\u62DB\u5F85\u304C1\u4EF6\u306B\u7D5E\u308C\u305F\u3068\u304D\u3060\u3051\u53D7\u3051\u4ED8\u3051\u307E\u3059\uFF09\u3002\n\u5BFE\u8C61\u306F twp user invite list \u306B\u51FA\u308B\u62DB\u5F85\uFF08\u671F\u9650\u5185\u306E\u672A\u53D7\u8AFE\uFF09\u3060\u3051\u3067\u3059\u3002\n\u540C\u3058\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u306B\u672A\u53D7\u8AFE\u306E\u62DB\u5F85\u304C\u8907\u6570\u3042\u308B\u3068\u304D\u306F\u3001twp user invite list --no-redact \u3067\n\u30C8\u30FC\u30AF\u30F3\u3092\u78BA\u8A8D\u3057\u3066\u3001\u30C8\u30FC\u30AF\u30F3\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002";
|
|
228
228
|
function roleValue(raw,where){const value=raw.trim().toLowerCase();if(!INVITE_ROLES.includes(value)){throw new UsageError(`${where}\u306B\u300C${raw}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,ROLE_HELP)}return value}function successAck(body,label2){if(!isRecord(body)||body["result"]!==true){throw new ApiResponseError(`${label2}\u306E\u5FDC\u7B54\u304C\u60F3\u5B9A\u306E\u5F62\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}
|
|
229
229
|
return{result:true,message:body["message"]??null}}function invitationRows(body){const rows=isRecord(body)?body["invitations"]:void 0;if(!Array.isArray(rows)){throw new ApiResponseError("\u62DB\u5F85\u4E00\u89A7\u306E\u5FDC\u7B54\u306B invitations \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return rows.filter(isRecord)}function cell(raw){const trimmed=raw.trim();return trimmed.length>=2&&trimmed.startsWith(
|
|
230
230
|
'"')&&trimmed.endsWith('"')?trimmed.slice(1,-1).trim():trimmed}function parseInviteCsv(text){const rows=[];const errors=[];const seen=new Map;const lines=text.replace(/^\uFEFF/,"").split(/\r?\n/);let headerChecked=false;lines.forEach((raw,index)=>{const line=index+1;if(raw.trim()===""||raw.trim().startsWith("#"))return;const cells=raw.split(",").map(cell);if(!headerChecked){headerChecked=true;const head=(cells[0]??"").toLowerCase();if(head==="email"||head==="\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9"||
|
|
231
231
|
head==="mail")return}if(cells.length!==2){errors.push(`${line} \u884C\u76EE: \u5217\u304C ${cells.length} \u500B\u3042\u308A\u307E\u3059\uFF08\u300C\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9, \u6A29\u9650\u300D\u306E2\u5217\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u6C0F\u540D\u306F\u53D7\u8AFE\u6642\u306B\u672C\u4EBA\u304C\u5165\u529B\u3057\u307E\u3059\uFF09`);return}const[email,role]=cells;if(!EMAIL_RE.test(email)){errors.push(`${line} \u884C\u76EE: \u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u306E\u5F62\u304C\u9055\u3044\u307E\u3059: ${email===
|
|
232
232
|
""?"\uFF08\u7A7A\uFF09":email}`);return}const normalizedRole=role.toLowerCase();if(!INVITE_ROLES.includes(normalizedRole)){errors.push(`${line} \u884C\u76EE: \u6A29\u9650\u306B\u300C${role===""?"\uFF08\u7A7A\uFF09":role}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\uFF08${INVITE_ROLES.join(" / ")}\uFF09`);return}const key=email.toLowerCase();const first=seen.get(key);if(first!==void 0){errors.push(`${line} \u884C\u76EE: ${email} \u306F ${first} \u884C\u76EE\u3068\u91CD\u8907\u3057\u3066\u3044\u307E\u3059`);
|
|
233
|
-
return}seen.set(key,line);rows.push({line,email,role:normalizedRole})});return{rows,errors}}function readCsvFile(file,usage){
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
"
|
|
245
|
-
"\
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
usage:"twp user invite bulk --file <CSV>",description:`CSV \u306F\u300C\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9, \u6A29\u9650\u300D\u306E2\u5217\u3067\u3059\uFF081\u884C\u76EE\u306E\u30D8\u30C3\u30C0 email,role \u306F\u7701\u7565\u3067\u304D\u307E\u3059\uFF09\u3002
|
|
233
|
+
return}seen.set(key,line);rows.push({line,email,role:normalizedRole})});return{rows,errors}}function readCsvFile(file,usage){return readCsvFileText(file,usage,CSV_MAX_BYTES,size=>new UsageError(`--file \u306E\u30D5\u30A1\u30A4\u30EB\u304C\u5927\u304D\u3059\u304E\u307E\u3059\uFF08${size} \u30D0\u30A4\u30C8\uFF09: ${file}`,`\u4E00\u5EA6\u306B\u62DB\u5F85\u3067\u304D\u308B\u306E\u306F ${BULK_MAX} \u4EF6\u307E\u3067\u3067\u3059\u3002`))}function bulkRows(input){return JSON.parse(requireResolved(input,
|
|
234
|
+
"rows"))}function matchResults(response,sent){const results=isRecord(response)?response["results"]:void 0;if(!isRecord(response)||response["result"]!==true||!Array.isArray(results)){throw new ApiResponseError("\u4E00\u62EC\u62DB\u5F85\u306E\u5FDC\u7B54\u306B results \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}const byEmail=new Map(sent.map(row=>[row.email.toLowerCase(),row]));const answered=new Set;const rows=results.
|
|
235
|
+
filter(isRecord).map(result=>{const email=String(result["email"]??"");const row=byEmail.get(email.toLowerCase());answered.add(email.toLowerCase());return{line:row?.line??null,email,role:row?.role??null,success:result["success"]===true,queued:result["queued"]===true,error:typeof result["error"]==="string"?result["error"]:null}});for(const row of sent){if(answered.has(row.email.toLowerCase()))continue;rows.push({line:row.line,email:row.email,role:row.role,success:false,queued:false,error:"\u30B5\u30FC\u30D0\u306E\u7D50\u679C\u306B\u542B\
|
|
236
|
+
\u307E\u308C\u3066\u3044\u307E\u305B\u3093\uFF08\u9001\u3089\u308C\u305F\u304B\u3069\u3046\u304B\u4E0D\u660E\u3067\u3059\u3002twp user invite list \u3067\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\uFF09"})}return rows}function lineErrors(err,sent){const list=err.body?.error_list;if(!Array.isArray(list))return[];const lines=[];for(const item of list){if(!isRecord(item))continue;const name=typeof item["name"]==="string"?item["name"]:"";const text=typeof item["message"]==="string"?item["messag\
|
|
237
|
+
e"]:"";const match=/^invitations\.(\d+)\./.exec(name);const row=match!==null?sent[Number(match[1])]:void 0;lines.push(row!==void 0?` ${row.line} \u884C\u76EE\uFF08${row.email}\uFF09: ${text}`:` ${name}: ${text}`)}return lines}async function runBulk(input,ctx){const sent=bulkRows(input);let response;try{response=await ctx.send(bulkPlan(input))}catch(err){if(err instanceof ApiError&&err.status===422){const lines=lineErrors(err,sent);if(lines.length>0)ctx.warn(["\u30B5\u30FC\u30D0\u304C CSV \u3092\u53D7\u3051\u4ED8\u3051\u307E\u305B\u3093\u3067\u3057\u305F\uFF081\u901A\u3082\u9001\u3063\u3066\u3044\u307E\u305B\u3093\uFF09:",
|
|
238
|
+
...lines].join("\n"))}throw err}const rows=matchResults(response,sent);const failed=rows.filter(row=>!row.success);if(failed.length>0){const lines=[`\u4E00\u62EC\u62DB\u5F85: ${rows.length} \u4EF6\u4E2D ${failed.length} \u4EF6\u304C\u5931\u6557\u3057\u307E\u3057\u305F\u3002`];for(const row of failed)lines.push(` \u5931\u6557: ${row.line??"?"} \u884C\u76EE ${row.email}\uFF08${row.error??"\u7406\u7531\u4E0D\u660E"}\uFF09`);const ok=rows.filter(row=>row.success);lines.push(ok.length===0?" \u62DB\u5F85\u3092\u9001\u3063\u305F\u884C\
|
|
239
|
+
\u306F\u3042\u308A\u307E\u305B\u3093\u3002":` \u9001\u4FE1\u6E08\u307F\uFF08\u6253\u3061\u76F4\u3059\u30682\u901A\u76EE\u304C\u5C4A\u304D\u307E\u3059\uFF09: ${ok.map(row=>`${row.line??"?"} \u884C\u76EE ${row.email}`).join(" / ")}`);lines.push("\u5931\u6557\u306E\u7406\u7531\u3092\u78BA\u304B\u3081\u3001\u76F4\u305B\u308B\u884C\u3060\u3051\u3092\u6B8B\u3057\u305F CSV \u3067\u6253\u3061\u76F4\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u9001\u4FE1\u6E08\u307F\u306E\u884C\u306F\u542B\u3081\u306A\u3044\uFF09\u3002");
|
|
240
|
+
ctx.warn(lines.join("\n"));throw new ApiRejectedError(`\u4E00\u62EC\u62DB\u5F85\u306F\u5B8C\u4E86\u3057\u3066\u3044\u307E\u305B\u3093\uFF08${failed.length} \u4EF6\u5931\u6557\u30FB${ok.length} \u4EF6\u9001\u4FE1\uFF09\u3002`)}return{response,rows}}function bulkPlan(input){return{method:"POST",path:`${INVITATIONS_PATH}/bulk`,body:{invitations:bulkRows(input).map(row=>({email:row.email,role:row.role}))}}}function bulkBody(body){return isRecord(body)&&"rows"in body?body:{}}var INVITE_REF_FLAG={name:"\
|
|
241
|
+
--invite",summary:"\u5BFE\u8C61\u306E\u62DB\u5F85\uFF08\u4F4D\u7F6E\u5F15\u6570\u306E\u4EE3\u308F\u308A\u306B\u4F7F\u3048\u308B\uFF09",takesValue:true,placeholder:"<\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9|\u30C8\u30FC\u30AF\u30F3>"};async function prepareInvite(input,usage){const ref=singleRef(input,{flag:INVITE_REF_FLAG.name,label:"\u62DB\u5F85",usage});if(!ref.includes("@")){if(!/^[A-Za-z0-9_-]+$/.test(ref))throw new UsageError(`\u62DB\u5F85\u306E\u30C8\u30FC\u30AF\u30F3\u306E\u5F62\u304C\u9055\u3044\u307E\u3059\uFF08${[
|
|
242
|
+
...ref].length} \u6587\u5B57\uFF09`,INVITE_REF_HELP);return withResolved(input,{token:ref})}return withResolved(input,{email:ref})}async function tokenFor(input,ctx){const token=input.resolved?.["token"];if(token!==void 0)return token;const email=requireResolved(input,"email");const rows=invitationRows(await ctx.send({method:"GET",path:INVITATIONS_PATH}));const hits=rows.filter(row=>String(row["email"]??"").toLowerCase()===email.toLowerCase()&&row["status"]!=="accepted");if(hits.length===0){throw new UsageError(
|
|
243
|
+
`${email} \u5B9B\u3066\u306E\u672A\u53D7\u8AFE\u306E\u62DB\u5F85\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093`,"twp user invite list \u3067\u62DB\u5F85\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}if(hits.length>1){const found=hits.map(row=>`${String(row["status"])}\uFF08\u4F5C\u6210 ${String(row["created_at"])}\uFF09`).join(" / ");throw new UsageError(`${email} \u5B9B\u3066\u306E\u672A\u53D7\u8AFE\u306E\u62DB\u5F85\u304C ${hits.length} \u4EF6\u3042\u308A\u307E\u3059: ${found}`,
|
|
244
|
+
INVITE_REF_HELP)}const hit=hits[0]?.["token"];if(typeof hit!=="string"||!/^[A-Za-z0-9_-]+$/.test(hit)){throw new ApiResponseError("\u62DB\u5F85\u4E00\u89A7\u306E\u5FDC\u7B54\u306E\u30C8\u30FC\u30AF\u30F3\u3092\u30D1\u30B9\u306B\u4F7F\u3048\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return hit}function invitePath(token,suffix=""){return`${INVITATIONS_PATH}/${encodeURIComponent(token)}${suffix}`}function refPlan(input,method,suffix=""){const token=input.
|
|
245
|
+
resolved?.["token"];return{method,path:token===void 0?`${INVITATIONS_PATH}/{token}${suffix}`:invitePath(token,suffix)}}function refNotes(input){const email=input.resolved?.["email"];return email===void 0?[]:[`\u3053\u306E\u524D\u306B\u3001${email} \u5B9B\u3066\u306E\u62DB\u5F85\u306E\u30C8\u30FC\u30AF\u30F3\u3092\u8ABF\u3079\u308B\u305F\u3081\u62DB\u5F85\u4E00\u89A7\u3092 GET \u3057\u307E\u3059\uFF08{token} \u306F\u305D\u306E\u7D50\u679C\u3067\u57CB\u307E\u308A\u307E\u3059\uFF09\u3002`]}var userInviteResource={
|
|
246
|
+
name:"invite",summary:"\u30E6\u30FC\u30B6\u30FC\u306E\u62DB\u5F85\uFF081\u4EF6\u30FBCSV \u4E00\u62EC\u30FB\u4E00\u89A7\u30FB\u518D\u9001\u30FB\u53D6\u6D88\uFF09",operations:[{name:"create",summary:"1\u4EBA\u3092\u62DB\u5F85\u3059\u308B\uFF08\u62DB\u5F85\u30E1\u30FC\u30EB\u3092\u9001\u308B\uFF09",usage:"twp user invite create --email <\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9> [--role user|admin|super_admin] [--name <\u6C0F\u540D>]",description:"--email \u304C\u5FC5\u9808\u3067\u3059\u3002--role \u3092\u7701\u304F\u3068\u4E00\u822C\u30E6\u30FC\u30B6\u30FC\uFF08user\uFF09\u3067\u62DB\u5F85\u3057\u307E\u3059\u3002\n--nam\
|
|
247
|
+
e \u306F\u62DB\u5F85\u30E1\u30FC\u30EB\u3068\u53D7\u8AFE\u753B\u9762\u306B\u51FA\u3059\u6C0F\u540D\u3067\u3059\uFF08\u53D7\u8AFE\u6642\u306B\u672C\u4EBA\u304C\u5909\u66F4\u3067\u304D\u307E\u3059\uFF09\u3002\n\u6A5F\u80FD\u6A29\u9650\u306F\u30C6\u30CA\u30F3\u30C8\u306E\u65E2\u5B9A\u3092\u4F7F\u3044\u307E\u3059\u3002\n\n"+ROLE_HELP,forbidden:FORBIDDEN2,flags:[{name:"--email",summary:"\u62DB\u5F85\u3059\u308B\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9",takesValue:true,placeholder:"<\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9>"},
|
|
248
|
+
{name:"--role",summary:"\u6A29\u9650\uFF08user / admin / super_admin\uFF09",takesValue:true,placeholder:"<\u6A29\u9650>"},{name:"--name",summary:"\u6C0F\u540D\uFF08\u62DB\u5F85\u30E1\u30FC\u30EB\u3068\u53D7\u8AFE\u753B\u9762\u306B\u51FA\u308B\uFF09",takesValue:true,placeholder:"<\u6C0F\u540D>"}],async prepare(input){if(input.args.length>0){throw new UsageError(`create \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,"twp user invite create help")}const email=input.
|
|
249
|
+
flags.get("--email")?.trim()??"";if(email==="")throw new UsageError("--email \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044","twp user invite create help");if(!EMAIL_RE.test(email))throw new UsageError(`--email \u306E\u5F62\u304C\u9055\u3044\u307E\u3059: ${email}`,"\u4F8B: --email new.member@example.com");const role=input.flags.get("--role");if(role!==void 0)roleValue(role,"--role ");const name=input.flags.get("--name");if(name!==void 0&&[...name].length>255){throw new UsageError(`\u6C0F\u540D\u304C\u9577\u3059\u304E\
|
|
250
|
+
\u307E\u3059\uFF08${[...name].length} \u6587\u5B57\u30FB\u4E0A\u9650 255 \u6587\u5B57\uFF09`,"twp user invite create help")}return input},plan(input){const role=input.flags.get("--role");const name=input.flags.get("--name")?.trim();return{method:"POST",path:INVITATIONS_PATH,body:{email:input.flags.get("--email").trim(),role:role===void 0?"user":roleValue(role,"--role "),...name!==void 0&&name!==""?{user_name:name}:{}}}},plannedNotes:input=>input.flags.has("--role")?[]:["--role \u672A\u6307\u5B9A\u306E\u305F\u3081\u3001\u4E00\u822C\u30E6\u30FC\u30B6\u30FC\uFF08user\
|
|
251
|
+
\uFF09\u3067\u62DB\u5F85\u3057\u307E\u3059\u3002"],summarize:body=>successAck(body,"\u62DB\u5F85"),raw:body=>successAck(body,"\u62DB\u5F85")},{name:"bulk",summary:"CSV \u306E\u5168\u54E1\u3092\u62DB\u5F85\u3059\u308B\uFF081\u56DE 50 \u4EF6\u307E\u3067\uFF09",usage:"twp user invite bulk --file <CSV>",description:`CSV \u306F\u300C\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9, \u6A29\u9650\u300D\u306E2\u5217\u3067\u3059\uFF081\u884C\u76EE\u306E\u30D8\u30C3\u30C0 email,role \u306F\u7701\u7565\u3067\u304D\u307E\u3059\uFF09\u3002
|
|
253
252
|
\u6C0F\u540D\u306E\u5217\u306F\u7F6E\u3051\u307E\u305B\u3093\uFF08\u4E00\u62EC\u62DB\u5F85\u3067\u306F\u6C0F\u540D\u306F\u9001\u3089\u308C\u305A\u3001\u53D7\u8AFE\u6642\u306B\u672C\u4EBA\u304C\u5165\u529B\u3057\u307E\u3059\uFF09\u3002
|
|
254
253
|
\u7A7A\u884C\u3068 # \u3067\u59CB\u307E\u308B\u884C\u306F\u8AAD\u307F\u98DB\u3070\u3057\u307E\u3059\u3002
|
|
255
254
|
|
|
@@ -285,8 +284,8 @@ var PASSWORD_HINT="\u30D1\u30B9\u30EF\u30FC\u30C9\u306F --password-file \u306B\u
|
|
|
285
284
|
function booleanFlag(input,flag){const raw=input.flags.get(flag);return raw===void 0?void 0:booleanText(flag,raw)}function roleType(input){const raw=input.flags.get("--role");if(raw===void 0)return void 0;const type=ROLE_TO_TYPE[raw.trim().toLowerCase()];if(type===void 0){throw new UsageError(`--role \u306B\u300C${raw}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,"\u6307\u5B9A\u3067\u304D\u308B\u306E\u306F admin\uFF08\u7BA1\u7406\u8005\uFF09/ user\uFF08\u4E00\u822C\uFF09\u3067\u3059\u3002")}
|
|
286
285
|
return type}function authType(input){const raw=input.flags.get("--auth-type");if(raw===void 0)return void 0;const value=raw.trim().toLowerCase();if(!AUTH_TYPES.includes(value)){throw new UsageError(`--auth-type \u306B\u300C${raw}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,`\u6307\u5B9A\u3067\u304D\u308B\u306E\u306F ${AUTH_TYPES.join(" / ")} \u3067\u3059\uFF08disabled \u3067\u5931\u52B9\uFF09\u3002`)}return value}async function readPassword(input,usage){const file=input.flags.get(PASSWORD_FILE_FLAG.
|
|
287
286
|
name);if(file===void 0)return void 0;let text;if(file==="-"){if(process.stdin.isTTY===true){throw new UsageError("--password-file - \u306F\u6A19\u6E96\u5165\u529B\u304B\u3089\u8AAD\u307F\u307E\u3059\u304C\u3001\u7AEF\u672B\u304C\u7E4B\u304C\u3063\u3066\u3044\u307E\u3059","\u30D1\u30A4\u30D7\u304B\u30EA\u30C0\u30A4\u30EC\u30AF\u30C8\u3067\u6A19\u6E96\u5165\u529B\u306B\u6E21\u3059\u304B\u3001--password-file \u306B\u30D5\u30A1\u30A4\u30EB\u306E\u30D1\u30B9\u3092\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
288
|
-
const chunks=[];let size=0;for await(const chunk of process.stdin){const buffer=Buffer.from(chunk);size+=buffer.length;if(size>PASSWORD_FILE_MAX_BYTES){throw new UsageError(`\u6A19\u6E96\u5165\u529B\u306E\u30D1\u30B9\u30EF\u30FC\u30C9\u304C\u5927\u304D\u3059\u304E\u307E\u3059\uFF08${PASSWORD_FILE_MAX_BYTES} \u30D0\u30A4\u30C8\u8D85\uFF09`,usage)}chunks.push(buffer)}text=Buffer.concat(chunks).toString("utf8")}else{try{const stat=
|
|
289
|
-
d-file \u306B\u901A\u5E38\u306E\u30D5\u30A1\u30A4\u30EB\u4EE5\u5916\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093: ${file}`,usage);if(stat.size>PASSWORD_FILE_MAX_BYTES){throw new UsageError(`--password-file \u306E\u30D5\u30A1\u30A4\u30EB\u304C\u5927\u304D\u3059\u304E\u307E\u3059\uFF08${stat.size} \u30D0\u30A4\u30C8\uFF09: ${file}`,usage)}text=
|
|
287
|
+
const chunks=[];let size=0;for await(const chunk of process.stdin){const buffer=Buffer.from(chunk);size+=buffer.length;if(size>PASSWORD_FILE_MAX_BYTES){throw new UsageError(`\u6A19\u6E96\u5165\u529B\u306E\u30D1\u30B9\u30EF\u30FC\u30C9\u304C\u5927\u304D\u3059\u304E\u307E\u3059\uFF08${PASSWORD_FILE_MAX_BYTES} \u30D0\u30A4\u30C8\u8D85\uFF09`,usage)}chunks.push(buffer)}text=Buffer.concat(chunks).toString("utf8")}else{try{const stat=fs3.statSync(file);if(!stat.isFile())throw new UsageError(`--passwor\
|
|
288
|
+
d-file \u306B\u901A\u5E38\u306E\u30D5\u30A1\u30A4\u30EB\u4EE5\u5916\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093: ${file}`,usage);if(stat.size>PASSWORD_FILE_MAX_BYTES){throw new UsageError(`--password-file \u306E\u30D5\u30A1\u30A4\u30EB\u304C\u5927\u304D\u3059\u304E\u307E\u3059\uFF08${stat.size} \u30D0\u30A4\u30C8\uFF09: ${file}`,usage)}text=fs3.readFileSync(file,"utf8")}catch(err){if(err instanceof UsageError)throw err;const reason=err.code??err.message;throw new UsageError(`--password-file \
|
|
290
289
|
\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u8AAD\u3081\u307E\u305B\u3093: ${file}\uFF08${reason}\uFF09`,usage)}}const password=text.replace(/^\uFEFF/,"").replace(/\r?\n$/,"");if([...password].length<PASSWORD_MIN_CHARS){throw new UsageError(`\u30D1\u30B9\u30EF\u30FC\u30C9\u306F ${PASSWORD_MIN_CHARS} \u6587\u5B57\u4EE5\u4E0A\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${[...password].length} \u6587\u5B57\uFF09`,usage)}return password}function userFields(input){const body={};for(const field of TEXT_FIELDS){
|
|
291
290
|
const value=boundedText(input,field.flag,{maxChars:field.maxChars,label:field.label});if(value!==void 0)body[field.key]=value}const type=roleType(input);if(type!==void 0)body["type"]=type;const hireDate=isoDate(input,HIRE_DATE_FLAG.name);if(hireDate!==void 0)body["hire_date"]=hireDate;for(const field of DISPLAY_FIELDS){const value=booleanFlag(input,field.flag);if(value!==void 0)body[field.key]=value}return body}function writeAck(body,label2){if(!isRecord(body)||body["result"]!==true){throw new ApiResponseError(
|
|
292
291
|
`${label2}\u306E\u5FDC\u7B54\u304C\u60F3\u5B9A\u306E\u5F62\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}const rest={...body};delete rest["result"];return rest}function licenseNotes(body){const warnings=isRecord(body)?body["license_warnings"]:void 0;if(!Array.isArray(warnings)||warnings.length===0)return[];const texts=warnings.map(warning=>isRecord(warning)?String(warning["message"]??warning["feature_label"]??warning["\
|
package/package.json
CHANGED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
-
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{failureHint,isAuthError,isCliFatalText,isRateLimited,isServerAiType,isUntrusted,maxTurnsReached,rateLimitWaitSeconds,tailForScan}from"./chunk-ZOOEH7ZE.js";import{detectAiClis}from"./chunk-24ZZFFA3.js";import{DEFAULT_CLAUDE_LAUNCHER,activeSlotPath,detectClaudeAutoSwitch,isClaudeAi,isUsableModelId,modelFitsRoute,resolveSpawnTarget,usesBedrock,wrapWithAutoSwitch}from"./chunk-TYNCXQSN.js";import{isForceOnly,killProcessTree,system32}from"./chunk-N2UVRM3Z.js";import{findExecutable,
|
|
4
|
-
isWindowsDriveAbsolute}from"./chunk-PMOUHEJQ.js";import"./chunk-5WGOHFAS.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";import{spawnSync}from"child_process";import fs2 from"fs";import path2 from"path";import{spawn}from"child_process";import fs from"fs";import path from"path";var FINAL_REPORT_BEGIN="<<<AI_FINAL_REPORT>>>";var FINAL_REPORT_END="<<<END_AI_FINAL_REPORT>>>";var ClaudeStreamRenderer=class{constructor(now=()=>new Date){this.now=now}now;toolNames=new Map;toolCount=0;result={subtype:null,isError:null,numTurns:null,costUsd:null,durationMs:null,tokensIn:null,tokensOut:null,rateLimited:false,resetsAt:null,finalText:""};push(line){const trimmed=line.trim();if(trimmed==="")return[];let event;try{const parsed=JSON.parse(trimmed);if(parsed===null||typeof parsed!=="\
|
|
5
|
-
object"||Array.isArray(parsed)){return[line]}event=parsed}catch{return[line]}switch(event["type"]){case"rate_limit_event":return this.onRateLimit(event);case"assistant":return this.onAssistant(event);case"user":return this.onUser(event);case"result":return this.onResult(event);default:return event["type"]==="system"?[]:[line]}}sawRateLimit(){return this.result.rateLimited}lastRateLimitNote="";onRateLimit(event){const info=event["rate_limit_info"];if(info===null||typeof info!=="object")return[];const rec=info;
|
|
6
|
-
const status=typeof rec["status"]==="string"?rec["status"]:"";const resets=typeof rec["resetsAt"]==="number"?rec["resetsAt"]:null;if(status==="")return[];const at=isSaneEpochSec(resets)?` resets=${new Date(resets*1e3).toISOString()}`:"";if(status.startsWith("allowed")){if(status==="allowed")return[];const seen=`${status}|${resets??""}`;if(seen===this.lastRateLimitNote)return[];this.lastRateLimitNote=seen;return[this.line(`\u2139\uFE0F \u4E0A\u9650\u306B\u63A5\u8FD1\uFF08status=${status}${at}\uFF09\u2014 \u5B9F\
|
|
7
|
-
\u884C\u306F\u7D99\u7D9A\u3057\u307E\u3059`)]}if(resets!==null)this.result.resetsAt=resets;this.result.rateLimited=true;return[this.line(`\u26A0\uFE0F \u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u901A\u77E5: status=${status}${at}`)]}onAssistant(event){const out=[];for(const block of contentBlocks(event)){if(block.type==="tool_use"){const name=typeof block.name==="string"?block.name:"tool";if(typeof block.id==="string")this.toolNames.set(block.id,name);this.toolCount+=1;out.push(this.line(`>> ${name}${toolDetail(
|
|
8
|
-
name,block.input)}`))}else if(block.type==="text"&&typeof block.text==="string"&&block.text.trim()!==""){for(const l of block.text.trim().split("\n"))out.push(this.line(` \u{1F4AC} ${l}`))}}return out}onUser(event){const out=[];for(const block of contentBlocks(event)){if(block.type!=="tool_result")continue;const id=typeof block.id==="string"?block.id:"";const useId=typeof block.tool_use_id==="string"?block.tool_use_id:id;const name=this.toolNames.get(useId)??"tool";this.toolNames.delete(useId);
|
|
9
|
-
const isError=block.is_error===true;const detail=isError?firstErrorLine(block):"";out.push(this.line(`${isError?"!!":"<<"} ${name}${detail}`))}return out}onResult(event){const r=this.result;r.subtype=typeof event["subtype"]==="string"?event["subtype"]:null;r.isError=typeof event["is_error"]==="boolean"?event["is_error"]:null;r.numTurns=typeof event["num_turns"]==="number"?event["num_turns"]:null;r.costUsd=typeof event["total_cost_usd"]==="number"?event["total_cost_usd"]:null;r.durationMs=typeof event["\
|
|
10
|
-
duration_ms"]==="number"?event["duration_ms"]:null;const usage=event["usage"];if(usage!==null&&typeof usage==="object"&&!Array.isArray(usage)){const u=usage;const num=key=>typeof u[key]==="number"?u[key]:0;const hasIn=["input_tokens","cache_creation_input_tokens","cache_read_input_tokens"].some(k=>typeof u[k]==="number");r.tokensIn=hasIn?num("input_tokens")+num("cache_creation_input_tokens")+num("cache_read_input_tokens"):null;r.tokensOut=typeof u["output_tokens"]==="number"?u["output_tokens"]:null}
|
|
11
|
-
const out=[this.line(`\u5B8C\u4E86 (turns: ${r.numTurns??0}, tools: ${this.toolCount}, ${Math.round((r.durationMs??0)/1e3)}s, $${(r.costUsd??0).toFixed(3)})`)];const text=typeof event["result"]==="string"?event["result"]:"";r.finalText=text;if(text!==""){out.push(FINAL_REPORT_BEGIN,text,FINAL_REPORT_END)}return out}line(msg){const d=this.now();const ts=`${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;return` [${ts}] ${msg}`}};function firstErrorLine(block){const content=block.
|
|
12
|
-
content;const text=typeof content==="string"?content:Array.isArray(content)?content.map(c=>c!==null&&typeof c==="object"&&typeof c.text==="string"?c.text:"").join(" "):"";const first=text.trim().split("\n")[0]??"";return first===""?"":` | ${first.slice(0,120)}`}function contentBlocks(event){const message=event["message"];if(message===null||typeof message!=="object")return[];const content=message["content"];if(!Array.isArray(content))return[];return content.filter(b=>b!==null&&typeof b==="object")}
|
|
13
|
-
function toolDetail(name,input){if(input===void 0||input===null)return"";const str=k=>typeof input[k]==="string"?input[k]:"";if(name==="Bash"){const cmd=str("command");return cmd===""?"":` $ ${cmd.slice(0,80)}${cmd.length>80?"...":""}`}if(name==="Read"||name==="Write"||name==="Edit"){const p=str("file_path");return p===""?"":` ${p}`}if(name==="Grep"||name==="Glob"){const p=str("pattern");return p===""?"":` '${p}'`}if(name==="Skill"){const s=str("skill");return s===""?"":` /${s}`}if(name.includes(
|
|
14
|
-
"mcp__")){const args=[];for(const k of["task_id","project_id","status_id","issue_id"]){const v=str(k);if(v!=="")args.push(`${k}=${v.slice(0,16)}`)}return args.length===0?"":` (${args.slice(0,2).join(", ")})`}return""}function pad(n){return String(n).padStart(2,"0")}function isSaneEpochSec(v){return v!==null&&Number.isFinite(v)&&Math.abs(v)<864e10}var DEFAULT_AI_TIMING={abortGraceMs:5e3,abortReapMs:2e3,pollIntervalMs:5e3};function resolveTiming(over){return{abortGraceMs:over?.abortGraceMs??DEFAULT_AI_TIMING.abortGraceMs,abortReapMs:over?.abortReapMs??DEFAULT_AI_TIMING.abortReapMs,pollIntervalMs:over?.pollIntervalMs??DEFAULT_AI_TIMING.pollIntervalMs}}var MAX_RETAINED_BYTES=4*1024*1024;function closeStream(stream){return new Promise(resolve=>{if(stream===null)return resolve();stream.once("error",()=>resolve());stream.end(()=>resolve())})}function buildArgs(req,cfg,env,workspace){
|
|
15
|
-
const warnings=[];const requested=(req.model??"").trim();const usable=requested!==""&&isUsableModelId(requested);if(requested!==""&&!usable){warnings.push(`ai_model '${requested}' \u306F\u4F7F\u3048\u306A\u3044\u5F62\u3067\u3059 \u2192 \u30AB\u30C6\u30B4\u30EA\u65E2\u5B9A\u306E\u30E2\u30C7\u30EB\u3092\u4F7F\u3044\u307E\u3059`)}const fitsRoute=!usable||!isClaudeAi(req.ai)||modelFitsRoute(requested,env);if(usable&&!fitsRoute){warnings.push(`ai_model '${requested}' \u306F\u73FE\u5728\u306E\u5B9F\u884C\u7D4C\u8DEF\u3067\u306F\u89E3\u6C7A\u3067\u304D\u307E\u305B\u3093\uFF08\u3053\u306E\u6A5F\u4F53\u306F ${usesBedrock(
|
|
16
|
-
env)?"Bedrock":"Anthropic \u76F4"}\uFF09 \u2192 \u30AB\u30C6\u30B4\u30EA\u65E2\u5B9A\u306E\u30E2\u30C7\u30EB\u3092\u4F7F\u3044\u307E\u3059`)}const fallback=cfg.modelFor(req.ai,req.category,env);const safeFallback=fallback===""||!isClaudeAi(req.ai)||modelFitsRoute(fallback,env)?fallback:"";if(fallback!==""&&safeFallback===""){warnings.push(`CLAUDE_MODEL '${fallback}' \u3082\u73FE\u5728\u306E\u5B9F\u884C\u7D4C\u8DEF\u3067\u306F\u89E3\u6C7A\u3067\u304D\u307E\u305B\u3093 \u2192 \u30E2\u30C7\u30EB\u3092\u6307\u5B9A\u3057\u307E\u305B\u3093`)}
|
|
17
|
-
const model=usable&&fitsRoute?requested:safeFallback;const maxTurns=cfg.maxTurnsFor(req.category,env);let effort="";switch(req.ai){case"gemini":return{file:"gemini",args:["--yolo",...model?["--model",model]:[]],model,effort,maxTurns,warnings};case"codex":return{file:"codex",args:["exec","-s","danger-full-access",...model?["--model",model]:[]],model,effort,maxTurns,warnings};case"copilot":{const mcp=path.join(workspace,".copilot","mcp-config.json");const args=["--allow-all"];if(fs.existsSync(mcp))
|
|
18
|
-
args.push("--additional-mcp-config",`@${mcp}`);else warnings.push(`${mcp} \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002copilot \u306F MCP \u306A\u3057\u3067\u5B9F\u884C\u3055\u308C\u307E\u3059`);if(model)args.push("--model",model);return{file:"copilot",args,model,effort,maxTurns,warnings}}default:{if(req.ai!=="claude")warnings.push(`\u672A\u77E5\u306E AI '${req.ai}'\u3002claude \u3067\u5B9F\u884C\u3057\u307E\u3059`);const e=cfg.effortFor(req.category,req.skill,env,req.effort);if(e.warning!==
|
|
19
|
-
null)warnings.push(e.warning);effort=e.value;const args=["-p","--max-turns",String(maxTurns),"--output-format","stream-json","--verbose","--dangerously-skip-permissions"];if(model)args.push("--model",model);if(effort)args.push("--effort",effort);return{file:"claude",args,model,effort,maxTurns,warnings}}}}async function runOnce(req,deps){let metrics=null;const result=await runOnceCore(req,deps,m=>{metrics=m});return metrics===null?result:{...result,metrics}}async function runOnceCore(req,deps,onMetrics){
|
|
20
|
-
const env=deps.env??process.env;const timing=resolveTiming(deps.timing);const isClaude=isClaudeAi(req.ai);const built=buildArgs(req,deps.config,env,req.cwd);for(const w of built.warnings)deps.log(` \u8B66\u544A: ${w}`);if(built.model)deps.log(` model: ${built.model} (ai_model=${req.model||"default"}, category=${req.category})`);if(built.effort)deps.log(` effort: ${built.effort} (category=${req.category}, skill=${req.skill||"none"})`);if(built.effort&&(req.effort??"").trim()===built.effort){deps.
|
|
21
|
-
log(` effort \u6307\u5B9A\u5143: item (ai_effort=${built.effort})`)}const launch=isClaude?wrapWithAutoSwitch(deps.cas,built.file,built.args):{file:built.file,args:built.args};const slot=req.slot!==void 0?req.slot:isClaude&&deps.cas!==null?activeSlotPath(deps.cas):null;if(slot!==null)deps.log(` claude \u67A0: ${slot}`);deps.log(`${req.ai} \u5B9F\u884C: ${firstLine(req.prompt)}`);deps.log(` \u30ED\u30B0: ${req.logFile}`);const renderer=isClaude?new ClaudeStreamRenderer(deps.now):null;const lines=[];
|
|
22
|
-
let retained=0;let truncated=false;let stream=null;try{fs.mkdirSync(path.dirname(req.logFile),{recursive:true,mode:448});stream=fs.createWriteStream(req.logFile,{flags:"w",mode:384})}catch{}const emit=line=>{const clean=stripTerminalControls(line);stream?.write(`${clean}
|
|
23
|
-
`);deps.log(clean);if(retained<MAX_RETAINED_BYTES){lines.push(clean);retained+=clean.length+1}else if(!truncated){truncated=true;lines.push("\u2026\uFF08\u51FA\u529B\u304C\u4E0A\u9650\u3092\u8D85\u3048\u305F\u305F\u3081\u3001\u4EE5\u964D\u306F\u30B9\u30C6\u30C3\u30D7\u30ED\u30B0\u306B\u306E\u307F\u8A18\u9332\u3057\u307E\u3059\uFF09")}};emit(` \u30D7\u30ED\u30F3\u30D7\u30C8: ${req.prompt.length} \u6587\u5B57\uFF08stdin \u7D4C\u7531\uFF09`);const target=resolveSpawnTarget(launch.file,launch.args,
|
|
24
|
-
{env,platform:deps.platform});if(!target.ok){emit(`[twp task-loop] ${launch.file} \u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093: ${target.reason}`);deps.onProcess?.(null);await closeStream(stream);return{outcome:"unavailable",output:lines.join("\n"),exitCode:null,cooldownSec:null,slot}}if(target.note!==null)deps.log(` \u8D77\u52D5: ${target.note}`);let spawned;try{spawned=spawn(target.file,target.args,{cwd:req.cwd,env,detached:process.platform!=="win32",stdio:["pipe","pipe","pipe"]})}catch(e){
|
|
25
|
-
const code=e.code??"";if(!["EINVAL","ENOENT","EACCES","ENAMETOOLONG"].includes(code))throw e;const hint=code==="ENAMETOOLONG"?`\uFF08\u30B3\u30DE\u30F3\u30C9\u30E9\u30A4\u30F3\u304C\u9577\u3059\u304E\u307E\u3059\u3002\u5B9F\u884C\u30D5\u30A1\u30A4\u30EB\uFF0B\u5F15\u6570\u3067 ${[target.file,...target.args].join(" ").length} \u6587\u5B57\u3002Windows \u306E\u4E0A\u9650\u306F 32,767 \u6587\u5B57\u3002\u30D7\u30ED\u30F3\u30D7\u30C8 ${req.prompt.length} \u6587\u5B57\u306F stdin \u7D4C\u7531\u306A\u306E\u3067\u539F\u56E0\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF09`:
|
|
26
|
-
"";emit(`[twp task-loop] ${launch.file} \u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093: ${e.message}${hint}`);deps.onProcess?.(null);await closeStream(stream);return{outcome:"unavailable",output:lines.join("\n"),exitCode:null,cooldownSec:null,slot}}let stdinDelivered=false;let stdinError=null;spawned.stdin.on("error",e=>{if(stdinError===null)stdinError=e.code??e.message});spawned.stdin.on("finish",()=>{stdinDelivered=true});spawned.stdin.end(req.prompt);let killedFor=null;const signalTree=signal=>killProcessTree(
|
|
27
|
-
spawned,signal,{platform:deps.platform});const killTree=()=>{signalTree("SIGKILL")};let exited=false;let markExited=()=>{};const exitedPromise=new Promise(resolve=>{markExited=()=>{exited=true;deps.onProcess?.(null);resolve()}});const waitExit=ms=>Promise.race([exitedPromise,new Promise(resolve=>{const t=setTimeout(resolve,ms);t.unref?.()})]);const abort=async()=>{if(exited||spawned.exitCode!==null||spawned.signalCode!==null)return;if(killedFor===null)killedFor="aborted";if(isForceOnly(deps.platform)){
|
|
28
|
-
deps.log(`\u26A0\uFE0F \u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u3051\u305F\u305F\u3081 ${req.ai} \u3092\u505C\u6B62\u3057\u307E\u3059\uFF08Windows \u306F\u7336\u4E88\u3092\u7F6E\u3051\u306A\u3044\u305F\u3081 taskkill /T /F \u3067\u6728\u3054\u3068\u5F37\u5236\u7D42\u4E86\u3057\u307E\u3059\uFF09`);const how=signalTree("SIGKILL");await waitExit(timing.abortReapMs);deps.log(!exited?` \u26A0\uFE0F ${req.ai} \u304C ${timing.abortReapMs/1e3}\u79D2 \u4EE5\u5185\u306B\u6D88\u3048\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u6B8B\u3063\u3066\u3044\u306A\u3044\u304B taskkill /FI \u3067\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044`:
|
|
29
|
-
how==="taskkill"?` ${req.ai} \u306E\u30D7\u30ED\u30BB\u30B9\u6728\u3092\u5F37\u5236\u7D42\u4E86\u3057\u307E\u3057\u305F\uFF08\u5B6B\u307E\u3067 taskkill /T \u304C\u5C4A\u304D\u307E\u3057\u305F\uFF09`:` \u26A0\uFE0F ${req.ai} \u306E\u76F4\u4E0B\u306E\u30D7\u30ED\u30BB\u30B9\u3060\u3051\u3092\u7D42\u4E86\u3057\u307E\u3057\u305F\uFF08taskkill \u3092\u6483\u3066\u306A\u304B\u3063\u305F\u305F\u3081\u5B6B\u304C\u6B8B\u3063\u3066\u3044\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\uFF09`);return}
|
|
30
|
-
deps.log(`\u26A0\uFE0F \u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u3051\u305F\u305F\u3081 ${req.ai} \u3092\u505C\u6B62\u3057\u307E\u3059\uFF08SIGTERM \u2192 \u6700\u5927${timing.abortGraceMs/1e3}\u79D2 \u2192 SIGKILL\uFF09`);signalTree("SIGTERM");await waitExit(timing.abortGraceMs);deps.log(exited?` ${req.ai} \u306F\u81EA\u5206\u304B\u3089\u7D42\u4E86\u3057\u307E\u3057\u305F\u3002\u6B8B\u3063\u305F\u5B50\u5B6B\u3092\u30D7\u30ED\u30BB\u30B9\u30B0\u30EB\u30FC\u30D7\u3054\u3068\u6383\u304D\u307E\u3059`:
|
|
31
|
-
` ${req.ai} \u304C\u7336\u4E88\u5185\u306B\u7D42\u4E86\u3057\u306A\u304B\u3063\u305F\u305F\u3081\u3001\u30D7\u30ED\u30BB\u30B9\u30B0\u30EB\u30FC\u30D7\u3092\u5F37\u5236\u7D42\u4E86\u3057\u307E\u3059`);signalTree("SIGKILL");await waitExit(timing.abortReapMs)};deps.onProcess?.(abort);const started=Date.now();const feed=lineFeeder(raw=>{if(renderer===null)emit(raw);else for(const l of renderer.push(raw))emit(l)});spawned.stdout.on("data",c=>feed(c.toString("utf8")));spawned.stderr.on("data",c=>feed(
|
|
32
|
-
c.toString("utf8")));const timer=setInterval(()=>{if((Date.now()-started)/1e3>=req.timeoutSec){deps.log(`\u26A0\uFE0F ${req.ai} \u30BF\u30A4\u30E0\u30A2\u30A6\u30C8 (${Math.trunc((Date.now()-started)/1e3)}s >= ${req.timeoutSec}s) \u2192 \u30D7\u30ED\u30BB\u30B9\u3092\u5F37\u5236\u7D42\u4E86`);killedFor="timeout";killTree();return}const limited=renderer!==null?renderer.sawRateLimit():isRateLimited(recentTail(lines),req.ai);if(limited){deps.log(`\u26A0\uFE0F ${req.ai} \u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u691C\u77E5 \u2192 \u5373\u5EA7\u306B\u30D7\u30ED\u30BB\u30B9\u3092\u7D42\u4E86`);
|
|
33
|
-
killedFor="rate-limited";killTree()}},timing.pollIntervalMs);let notLaunched=false;const exitCode=await new Promise(resolve=>{spawned.on("error",e=>{notLaunched=true;emit(`[twp task-loop] ${launch.file} \u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093: ${e.message}`);markExited();resolve(null)});spawned.on("close",code=>{markExited();resolve(code)})});deps.onProcess?.(null);clearInterval(timer);feed(null);if(stdinError!==null||!stdinDelivered){const cause=killedFor!==null?`\u3053\u3061\u3089\u304C ${killedFor}\
|
|
34
|
-
\u3067\u505C\u6B62\u3055\u305B\u305F\u305F\u3081`:notLaunched?"\u8D77\u52D5\u3067\u304D\u306A\u304B\u3063\u305F\u305F\u3081":exitCode===null?`AI \u304C signal\uFF08${spawned.signalCode??"\u4E0D\u660E"}\uFF09\u3067\u843D\u3061\u305F\u305F\u3081`:exitCode!==0?`AI \u304C\u7D42\u4E86\u30B3\u30FC\u30C9 ${exitCode} \u3067\u5148\u306B\u7D42\u308F\u3063\u305F\u305F\u3081`:"AI \u304C stdin \u3092\u8AAD\u307F\u5207\u3089\u306A\u304B\u3063\u305F\u305F\u3081";emit(`[twp task-loop] ${req.ai} \u3078\u30D7\u30ED\u30F3\u30D7\u30C8 ${req.
|
|
35
|
-
prompt.length} \u6587\u5B57\u3092\u9001\u308A\u5207\u308C\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${cause}${stdinError===null?"":`\u30FB${stdinError}`}\uFF09`)}await closeStream(stream);const output=lines.join("\n");const scan=tailForScan(output);onMetrics({turns:renderer?.result.numTurns??null,tokensIn:renderer?.result.tokensIn??null,tokensOut:renderer?.result.tokensOut??null,costUsd:renderer?.result.costUsd??null,effort:built.effort===""?null:built.effort});const fatalText=exitCode!==0&&isCliFatalText(
|
|
36
|
-
renderer?.result.finalText??"")?renderer?.result.finalText??"":"";if(killedFor==="aborted"){return{outcome:"aborted",output,exitCode,cooldownSec:null,slot}}const untrusted=isClaude&&isUntrusted(scan);if(untrusted){deps.log("\u26A0\uFE0F claude: \u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u672A\u30C8\u30E9\u30B9\u30C8\u306E\u8B66\u544A\u304C\u51FA\u3066\u3044\u307E\u3059\uFF08permissions.allow \u306F\u7121\u8996\u3055\u308C\u308B\u304C\u5B9F\u884C\u81EA\u4F53\u306F\u901A\u308B\u3002hasTrustDialogAccepted \u3092\u7ACB\u3066\u308B\u3053\u3068\uFF09")}
|
|
37
|
-
const structuredLimited=renderer?.result.rateLimited===true;const textLimited=renderer!==null?exitCode!==0&&isRateLimited(scan,req.ai):isRateLimited(scan,req.ai);const fatalLimited=fatalText!==""&&isRateLimited(fatalText,req.ai);if(killedFor==="rate-limited"||structuredLimited||textLimited||fatalLimited){return{outcome:"rate-limited",output,exitCode,cooldownSec:cooldownFrom(renderer,`${scan}
|
|
38
|
-
${fatalText}`,deps.now?.()??new Date),slot}}if(killedFor==="timeout")return{outcome:"timeout",output,exitCode,cooldownSec:null,slot};if(exitCode!==0&&(isAuthError(scan)||fatalText!==""&&isAuthError(fatalText))){deps.log(`\u26A0\uFE0F ${req.ai} \u8A8D\u8A3C\u30A8\u30E9\u30FC\u3092\u691C\u77E5\u3057\u307E\u3057\u305F\uFF08\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\u5BFE\u8C61\uFF09`);return{outcome:"auth-error",output,exitCode,cooldownSec:null,slot}}if(isClaude&&exitCode!==0){const byEvent=renderer?.
|
|
39
|
-
result.subtype==="error_max_turns";if(byEvent||maxTurnsReached(output,built.maxTurns)){deps.log(`\u26A0\uFE0F claude \u30BF\u30FC\u30F3\u4E0A\u9650(${built.maxTurns})\u5230\u9054\u3067\u6253\u3061\u5207\u3089\u308C\u307E\u3057\u305F\uFF08\u672A\u5B8C\u4E86\u306E\u53EF\u80FD\u6027\u304C\u9AD8\u3044\uFF09`);return{outcome:"max-turns",output,exitCode,cooldownSec:null,slot}}}if(notLaunched){deps.log(`\u26D4 ${req.ai} \u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u672A\u5C0E\u5165\u30FB\u5B9F\u884C\u6A29\u30FB\u30E9\u30C3\u30D1\u306E\u7834\u640D\u306E\u3044\u305A\u308C\u304B\uFF09`);
|
|
40
|
-
return{outcome:"unavailable",output,exitCode,cooldownSec:null,slot}}if(untrusted&&exitCode!==0){deps.log("\u26D4 claude: \u672A\u30C8\u30E9\u30B9\u30C8\u306E\u307E\u307E\u5931\u6557\u3057\u307E\u3057\u305F\uFF08permissions.allow \u7121\u8996\u304C\u539F\u56E0\u306E\u53EF\u80FD\u6027\uFF09");return{outcome:"untrusted",output,exitCode,cooldownSec:null,slot}}if(exitCode===0&&!stdinDelivered){deps.log(`\u26D4 ${req.ai} \u306F\u7D42\u4E86\u30B3\u30FC\u30C90\u3067\u7D42\u308F\u308A\u307E\u3057\u305F\u304C\u3001\u30D7\u30ED\u30F3\u30D7\u30C8 ${req.
|
|
41
|
-
prompt.length} \u6587\u5B57\u3092\u9001\u308A\u5207\u308C\u3066\u3044\u307E\u305B\u3093\uFF08\u5207\u308A\u8A70\u307E\u3063\u305F\u6307\u793A\u3067\u8D70\u3063\u305F\u53EF\u80FD\u6027\u304C\u3042\u308B\u305F\u3081\u6210\u529F\u3068\u3057\u3066\u6271\u3044\u307E\u305B\u3093\uFF09`);return{outcome:"failed",output,exitCode,cooldownSec:null,slot}}return{outcome:exitCode===0?"ok":"failed",output,exitCode,cooldownSec:null,slot}}function cooldownFrom(renderer,scan,now){const resets=renderer?.result.resetsAt??
|
|
42
|
-
null;if(resets!==null){const wait=Math.trunc((resets*1e3-now.getTime())/1e3);if(wait>0)return wait+30}return rateLimitWaitSeconds(scan,now)}function lineFeeder(onLine){let buffer="";return chunk=>{if(chunk===null){if(buffer!=="")onLine(buffer);buffer="";return}buffer+=chunk;const parts=buffer.split("\n");buffer=parts.pop()??"";for(const p of parts)onLine(p)}}function firstLine(prompt){return(prompt.split("\n")[0]??"").slice(0,80)}function recentTail(lines){let size=0;let from=lines.length;while(from>
|
|
43
|
-
0&&size<64*1024){from-=1;size+=(lines[from]??"").length+1}return lines.slice(from).join("\n")}function sleepSync(ms){const shared=new Int32Array(new SharedArrayBuffer(4));Atomics.wait(shared,0,0,ms)}var DEFAULT_CHARTER_PREFIX="===== \u4EE5\u4E0B\u306F\u958B\u767A\u61B2\u7AE0\u3067\u3059\u3002\u5168\u3066\u306E\u5224\u65AD\u306E\u6700\u4E0A\u4F4D\u57FA\u6E96\u3067\u3042\u308A\u3001\u500B\u5225\u30B9\u30AD\u30EB\u306E\u624B\u9806\u3068\u77DB\u76FE\u3059\u308B\u5834\u5408\u306F\u672C\u61B2\u7AE0\u304C\u512A\u5148\u3057\u307E\u3059\u3002\u884C\u52D5\u3059\u308B\u524D\u306B\u3001\u305D\u306E\u884C\u52D5\u304C\u61B2\u7AE0\u306E\u76EE\u7684\u306B\u5BC4\u4E0E\u3059\u308B\u304B\u3092\u81EA\u3089\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002 =====";
|
|
44
|
-
var DEFAULT_CHARTER_SUFFIX="===== \u958B\u767A\u61B2\u7AE0\u3053\u3053\u307E\u3067\u3002\u4EE5\u4E0B\u304C\u4ECA\u56DE\u306E\u30BF\u30B9\u30AF\u6307\u793A\u3067\u3059\u3002 =====";function wrapCharter(prefix,body,suffix){const parts=[];if(prefix!=="")parts.push(prefix);parts.push(body);if(suffix!=="")parts.push(suffix);return parts.join("\n\n")}var UNKNOWN_SLOT="(unresolved)";var FAST_FAIL_SEC=60;var FAST_FAIL_STREAK=3;var DispatchEngine=class{constructor(cfg,log,opts){this.cfg=cfg;this.log=log;
|
|
45
|
-
this.opts=opts}cfg;log;opts;name="cli";cas=null;casDetected=false;slotResolved=new Map;lastSlot=new Map;charterWarned=false;unusable=null;activeAbort=null;aborting=false;unusableAt=0;fastFailStreak=new Map;launcherBin(){const v=this.opts.launcherBin?.trim();return v===void 0||v===""?DEFAULT_CLAUDE_LAUNCHER.bin:v}async run(req){this.slotResolved.clear();if(this.aborting){this.log("\u26D4 \u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u3051\u3066\u3044\u308B\u305F\u3081 AI \u3092\u8D77\u52D5\u3057\u307E\u305B\u3093");
|
|
46
|
-
return{outcome:"aborted",usedAi:"",serverAiType:null,output:"\uFF08\u4E2D\u65AD\u306E\u305F\u3081\u672A\u5B9F\u884C\uFF09"}}const env=this.opts.env??process.env;const skill=req.skill??"";const category=req.category??this.cfg.categoryForSkill(skill);if(!this.preflightOk()){this.log("\u26D4 \u30DB\u30B9\u30C8\u5074\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u304C\u5230\u9054\u4E0D\u80FD\u3067\u3059\uFF08\u5168\u30DB\u30B9\u30C8\uFF09\u3002\u3053\u306E\u30A2\u30A4\u30C6\u30E0\u3067\u306F AI \u3092\u8D77\u52D5\u3057\u307E\u305B\u3093");
|
|
47
|
-
return{outcome:"network-down",usedAi:"",serverAiType:null,output:"\uFF08\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u5230\u9054\u4E0D\u80FD\u306E\u305F\u3081\u672A\u5B9F\u884C\uFF09"}}if(!this.casDetected){this.cas=this.opts.detect!==void 0?this.opts.detect():detectClaudeAutoSwitch(this.launcherBin());this.casDetected=true;this.log(this.cas===null?` ${this.launcherBin()}: \u672A\u5C0E\u5165\uFF08claude \u3092\u7D20\u3067\u8D77\u52D5\u3057\u307E\u3059\uFF09`:` ${this.launcherBin()}: \u691C\u51FA\uFF08exec ${this.
|
|
48
|
-
cas.hasExec?"\u3042\u308A \u2192 \u7D4C\u7531\u3057\u3066\u8D77\u52D5\u3057\u307E\u3059":"\u7121\u3057 \u2192 \u7D20\u3067\u8D77\u52D5\u3057\u307E\u3059\uFF08\u66F4\u65B0\u3092\u63A8\u5968\uFF09"}\uFF09`)}const tried=[];let sawRateLimit=false;let sawTimeout=false;let sawFastFail=false;let sawUnavailable=false;let ranAny=false;let skippedForCooldown=false;let lastOutput="";let lastValidated=true;const requested=this.orderFor(category,skill,req.aiType);const head=requested[0]??"";const order=this.
|
|
49
|
-
usableOrder(requested,category,skill);for(const ai of order){if(tried.includes(ai))continue;if(!this.cfg.isAllowed(ai,category,skill)){this.log(` ${ai} \u306F category=${category} / skill=${skill||"none"} \u306E\u5B9F\u884C\u5BFE\u8C61\u5916\u306E\u305F\u3081\u30B9\u30AD\u30C3\u30D7`);continue}const slotFor=()=>{if(!isClaudeAi(ai))return null;if(this.cas===null)return null;if(this.slotResolved.has(ai))return this.slotResolved.get(ai)??null;const resolved=(this.opts.activeSlot??activeSlotPath)(this.
|
|
50
|
-
cas);const effective=resolved??this.lastSlot.get(ai)??UNKNOWN_SLOT;if(resolved!==null)this.lastSlot.set(ai,resolved);else this.log(` ${ai} \u306E\u67A0\u3092\u89E3\u6C7A\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${this.launcherBin()} ${DEFAULT_CLAUDE_LAUNCHER.activeArgs.join(" ")}\uFF09\u3002${effective} \u3068\u3057\u3066\u6271\u3044\u307E\u3059`);this.slotResolved.set(ai,effective);return effective};const slotNow=this.cfg.hasCooldownFor(ai,this.now())?slotFor():null;if(this.cfg.isRateLimited(
|
|
51
|
-
ai,this.now(),slotNow)){skippedForCooldown=true;this.log(` ${ai} \u306F\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u4E2D\u306E\u305F\u3081\u30B9\u30AD\u30C3\u30D7`);continue}const isHead=tried.length===0&&ai===head;this.log(isHead?` AI\u9078\u629E: ${ai} (preferred) [category=${category}]`:` \u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF: ${ai} [category=${category}]`);const prompt=this.buildPrompt(req.prompt,req.promptPrefix,ai,tried);const logFile=tried.length===0?req.logFile:req.logFile.replace(
|
|
52
|
-
/\.log$/,`-fallback-${ai}.log`);if(this.aborting){this.log(` \u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u3051\u3066\u3044\u308B\u305F\u3081 ${ai} \u306F\u8D77\u52D5\u3057\u307E\u305B\u3093`);return{outcome:"aborted",usedAi:tried[tried.length-1]??"",serverAiType:null,output:lastOutput}}ranAny=true;const startedAt=this.now();const result=await(this.opts.runOnce??runOnce)({ai,prompt,logFile,cwd:req.cwd,timeoutSec:req.timeoutSec,category,skill,slot:slotFor(),model:isHead?req.aiModel:void 0,effort:req.
|
|
53
|
-
aiEffort},{config:this.cfg,cas:this.cas,log:this.log,env,now:this.opts.now,onProcess:abort=>{this.activeAbort=abort;if(abort!==null&&this.aborting)void abort()}});lastOutput=result.output;tried.push(ai);const elapsedMs=this.now()-startedAt;const elapsedSec=Math.round(elapsedMs/1e3);if(result.outcome==="failed"&&result.exitCode!==0&&elapsedMs>=0&&elapsedSec<FAST_FAIL_SEC){sawFastFail=true;const streak=(this.fastFailStreak.get(ai)??0)+1;this.fastFailStreak.set(ai,streak);this.log(` ${ai} \u304C ${elapsedSec}\
|
|
54
|
-
\u79D2\u3067\u5931\u6557\u3057\u307E\u3057\u305F\uFF08AI \u304C\u4ED5\u4E8B\u3092\u59CB\u3081\u308B\u524D\u306B\u843D\u3061\u305F\u53EF\u80FD\u6027\uFF09 \u2192 \u6B21\u306EAI\u306B\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF`);if(streak>=FAST_FAIL_STREAK){const sec=this.cfg.markAiUnusable(ai,this.now());this.fastFailStreak.delete(ai);this.log(` ${ai} \u306F\u8D77\u52D5\u76F4\u5F8C\u306E\u5931\u6557\u304C${streak}\u56DE\u7D9A\u3044\u3066\u3044\u307E\u3059 \u2192 ${sec}\u79D2\u9593\u306F\u9396\u304B\u3089\u5916\u3057\u307E\u3059\uFF08\u540C\u3058\u58C1\u306B\u5F8C\u7D9A\u30A2\u30A4\u30C6\u30E0\u3092\u5F53\u3066\u306A\u3044\u305F\u3081\
|
|
55
|
-
\u3002\u76F4\u8FD1\u306E\u51FA\u529B: ${failureHint(result.output)||"(\u7406\u7531\u884C\u306A\u3057)"}\uFF09`)}continue}if(!["rate-limited","auth-error","unavailable"].includes(result.outcome)){this.fastFailStreak.delete(ai)}if(!["rate-limited","auth-error","timeout","unavailable"].includes(result.outcome)){if(result.outcome==="ok"&&req.validate!==void 0){if(req.validate(result.output)){this.log(` ${ai} \u304B\u3089\u5B9F\u884C\u8A08\u753BJSON\u3092\u53D6\u5F97\u3057\u307E\u3057\u305F`)}else{this.
|
|
56
|
-
log(` ${ai}: \u5B9F\u884C\u8A08\u753B\u306EJSON\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093 \u2192 \u6B21\u306EAI\u306B\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF`);lastValidated=false;continue}}return this.finish(result.outcome,ai,result.output,result.metrics)}if(result.outcome==="rate-limited"){sawRateLimit=true;const seconds=result.cooldownSec??this.cfg.cooldownDefaultSec(ai,env);const slotUsed=slotFor();const capped=this.cfg.markRateLimited(ai,seconds,this.now(),slotUsed);this.log(` ${ai}\
|
|
57
|
-
\u3092\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u3068\u3057\u3066\u30DE\u30FC\u30AF (${capped}\u79D2\u9593${slotUsed===null?"":` / \u67A0 ${slotUsed}`})`);await this.waitBeforeFallback(ai,env)}else if(result.outcome==="timeout"){sawTimeout=true;this.log(` ${ai} \u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8 \u2192 \u6B21\u306EAI\u306B\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF`)}else if(result.outcome==="unavailable"){sawUnavailable=true;const sec=this.cfg.markAiUnusable(ai,this.now());this.log(` \
|
|
58
|
-
${ai} \u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093 \u2192 \u6B21\u306EAI\u306B\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\uFF08${sec}\u79D2\u9593\u306F\u9396\u304B\u3089\u5916\u3057\u307E\u3059\uFF09`)}else{sawUnavailable=true;const sec=this.cfg.markAiUnusable(ai,this.now());this.log(` ${ai} \u306E\u8A8D\u8A3C\u30A8\u30E9\u30FC \u2192 \u6B21\u306EAI\u306B\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\uFF08${sec}\u79D2\u9593\u306F\u9396\u304B\u3089\u5916\u3057\u307E\u3059\uFF09`)}}if(!lastValidated&&
|
|
59
|
-
!sawRateLimit&&ranAny){this.log("\u26A0\uFE0F \u3069\u306EAI\u304B\u3089\u3082\u5B9F\u884C\u8A08\u753BJSON\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F");return{outcome:"ok",usedAi:tried[tried.length-1]??"",serverAiType:null,output:lastOutput}}if(!ranAny){if(skippedForCooldown){this.log("\u26A0\uFE0F \u5168AI\u304C\u30AF\u30FC\u30EB\u30C0\u30A6\u30F3\u4E2D\u30671\u3064\u3082\u5B9F\u884C\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u5F85\u6A5F\u3057\u3066\u518D\u8A66\u884C\u3057\u307E\u3059\uFF09");
|
|
60
|
-
return{outcome:"rate-limited",usedAi:"",serverAiType:null,output:lastOutput}}this.log("\u26A0\uFE0F \u5B9F\u884C\u3067\u304D\u308BAI\u304C\u9396\u306B1\u3064\u3082\u3042\u308A\u307E\u305B\u3093\uFF08\u672A\u30ED\u30B0\u30A4\u30F3\u30FB\u30AB\u30C6\u30B4\u30EA\u8A2D\u5B9A\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\uFF09");return{outcome:"unavailable",usedAi:"",serverAiType:null,output:lastOutput}}if(sawTimeout){this.log("\u26A0\uFE0F \u5168AI\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u307E\u305F\u306F\u8A8D\u8A3C\u30A8\u30E9\u30FC\u3067\u3059\uFF08\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u3067\u306F\u306A\u3044\u306E\u3067\u901A\u5E38\u5931\u6557\u3068\u3057\u3066\u6271\u3044\u307E\u3059\uFF09");
|
|
61
|
-
return{outcome:"timeout",usedAi:tried[tried.length-1]??"",serverAiType:null,output:lastOutput}}if(sawRateLimit){this.log("\u26A0\uFE0F \u5168AI\u304C\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u3067\u3059");return{outcome:"rate-limited",usedAi:"",serverAiType:null,output:lastOutput}}if(sawFastFail&&!sawUnavailable){this.log("\u26A0\uFE0F \u5168AI\u304C\u8D77\u52D5\u76F4\u5F8C\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08\u901A\u5E38\u5931\u6557\u3068\u3057\u3066\u6271\u3044\u307E\u3059\uFF09");
|
|
62
|
-
return this.finish("failed",tried[tried.length-1]??"",lastOutput)}this.log("\u26A0\uFE0F \u5168AI\u304C\u8A8D\u8A3C\u30A8\u30E9\u30FC\u307E\u305F\u306F\u8D77\u52D5\u4E0D\u80FD\u3067\u3059\uFF081\u884C\u3082\u5B9F\u884C\u3057\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u5931\u6557\u3067\u306F\u306A\u304F\u672A\u5B9F\u884C\u3068\u3057\u3066\u6271\u3044\u307E\u3059\uFF09");return{outcome:"unavailable",usedAi:tried[tried.length-1]??"",serverAiType:null,output:lastOutput}}async abort(){this.aborting=true;
|
|
63
|
-
const abort=this.activeAbort;if(abort===null)return false;await abort();return true}now(){return(this.opts.now??(()=>new Date))().getTime()}usableOrder(order,category,skill){const detected=this.detectUnusable();const unique=[...new Set(order)];const kept=[];const soft=[];const dropped=[];for(const ai of unique){const hit=this.cfg.isAiUnusable(ai,this.now())?{why:"\u76F4\u8FD1\u306E\u8A8D\u8A3C\u30A8\u30E9\u30FC\u30FB\u8D77\u52D5\u5931\u6557\u30FB\u8D77\u52D5\u76F4\u5F8C\u306E\u5931\u6557\u306E\u9023\u7D9A",
|
|
64
|
-
hard:false}:detected.get(ai);if(hit===void 0){kept.push(ai);continue}dropped.push(`${ai}\uFF08${hit.why}\uFF09`);if(!hit.hard)soft.push(ai)}if(dropped.length===0)return unique;const canRun=list=>list.some(ai=>this.cfg.isAllowed(ai,category,skill));if(!canRun(kept)&&canRun(soft)){this.log(` \u26A0\uFE0F \u9396\u306B\u5B9F\u884C\u3067\u304D\u308B AI \u304C\u6B8B\u308A\u307E\u305B\u3093\uFF08\u9664\u5916\u5019\u88DC: ${dropped.join(" / ")}\uFF09`);this.log(" \u63A8\u5B9A\u3067\u5916\u3057\u305F\u3082\u306E\u306F\u5224\u5B9A\u304C\u8AA4\u3063\u3066\u3044\u308B\u53EF\u80FD\u6027\u304C\u3042\u308B\u305F\u3081\u3001\u9396\u3078\u623B\u3057\u307E\u3059\uFF08\
|
|
65
|
-
fail-open\uFF09");return unique.filter(ai=>kept.includes(ai)||soft.includes(ai))}this.log(` \u9396\u304B\u3089\u9664\u5916: ${dropped.join(" / ")}`);if(kept.length===0){this.log(" \u9396\u306B\u8D77\u52D5\u3067\u304D\u308B AI \u304C1\u3064\u3082\u6B8B\u308A\u307E\u305B\u3093\uFF08\u672A\u5C0E\u5165\u306E AI \u3092\u8D77\u52D5\u3057\u3066\u3082\u5FC5\u305A\u5931\u6557\u3057\u307E\u3059\uFF09")}return kept}detectUnusable(){const now=this.now();if(this.unusable!==null&&now-this.unusableAt<DETECT_CACHE_MS)
|
|
66
|
-
return this.unusable;const map=new Map;this.unusable=map;this.unusableAt=now;try{for(const d of(this.opts.detectClis??detectAiClis)({env:this.opts.env??process.env,launcherBin:this.launcherBin()})){if(!d.installed)map.set(d.ai,{why:"PATH \u306B\u7121\u3044\uFF08\u672A\u5C0E\u5165\uFF09",hard:true});else if(d.auth==="unauthenticated")map.set(d.ai,{why:"\u672A\u30ED\u30B0\u30A4\u30F3",hard:false})}}catch(err){this.log(` \u26A0\uFE0F AI CLI \u306E\u691C\u51FA\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${err.
|
|
67
|
-
message}\uFF09\u3002\u9396\u306F\u305D\u306E\u307E\u307E\u4F7F\u3044\u307E\u3059`);map.clear()}return map}orderFor(category,skill,preferred){const chain=this.cfg.chainFor(category);const head=preferred&&preferred.trim()!==""?preferred.trim():this.cfg.selectPrimary(category,skill,"P2","");return head===""?chain:[head,...chain]}finish(outcome,ai,output,metrics){const serverAiType=isServerAiType(ai)?ai:null;return metrics===void 0?{outcome,usedAi:ai,serverAiType,output}:{outcome,usedAi:ai,serverAiType,
|
|
68
|
-
output,metrics}}async waitBeforeFallback(ai,env){const delay=this.cfg.fallbackDelaySec(ai,env);if(delay<=0)return;this.log(` \u23F3 ${ai} \u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8 \u2192 \u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\u524D\u306B ${delay}\u79D2 \u5F85\u6A5F\uFF08\u4ED6AI\u3078\u306E\u8EE2\u5AC1\u3092\u6291\u5236\uFF09`);const sleep=this.opts.sleep??(ms=>new Promise(r=>setTimeout(r,ms)));await sleep(delay*1e3)}buildPrompt(body,promptPrefix,ai,tried){const expanded=this.expandForNonClaude(
|
|
69
|
-
body,ai);const parts=[];if(tried.length>0)parts.push(fallbackNote(tried));const charter=this.charter();if(charter!==null)parts.push(charter);if(promptPrefix!==void 0&&promptPrefix!=="")parts.push(promptPrefix);parts.push(expanded);return parts.join("\n\n")}expandForNonClaude(prompt,ai){const cmd=this.opts.compileCommand;if(ai==="claude"||cmd===void 0||cmd.length===0)return prompt;const[file,...args]=cmd;if(file===void 0)return prompt;const compileEnv={...this.opts.env??process.env};const resolved=process.
|
|
70
|
-
platform!=="win32"||isWindowsDriveAbsolute(file)?file:findExecutable(file,{env:compileEnv,platform:"win32"});if(resolved===null)return prompt;const r=spawnSync(resolved,[...args,"--provider",ai,"--project-dir",this.opts.workspace],{encoding:"utf8",env:{...this.opts.env??process.env,_AI_PROMPT:prompt},timeout:6e4,maxBuffer:32*1024*1024});const out=(r.stdout??"").trim();if(r.error!==void 0||r.status!==0||out===""){this.log(` \u26A0\uFE0F ${ai} \u5411\u3051\u306E\u30B9\u30AD\u30EB\u5C55\u958B\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08\u672A\u5C55\u958B\u306E\u307E\u307E\u5B9F\u884C\u3057\u307E\u3059\uFF09`);
|
|
71
|
-
return prompt}return out}charter(){if(this.opts.charterEnabled===false)return null;const server=this.opts.serverPrompts?.()??{};const prefix=server.charter_prefix??this.opts.charterPrefix??DEFAULT_CHARTER_PREFIX;const suffix=server.charter_suffix??this.opts.charterSuffix??DEFAULT_CHARTER_SUFFIX;if(server.charter!==void 0){return server.charter===""?null:wrapCharter(prefix,server.charter,suffix)}const file=this.opts.charterFile;if(file===void 0||file.trim()==="")return null;const resolved=path2.isAbsolute(
|
|
72
|
-
file)?file:path2.resolve(this.opts.workspace,file);let body;try{body=fs2.readFileSync(resolved,"utf8")}catch{if(!this.charterWarned){this.charterWarned=true;this.log(` \u26A0\uFE0F\u26A0\uFE0F \u61B2\u7AE0\u3092\u6CE8\u5165\u3067\u304D\u307E\u305B\u3093\uFF08${resolved} \u304C\u8AAD\u3081\u306A\u3044\uFF09\u3002\u4EE5\u5F8C\u306E\u5B9F\u884C\u306F\u61B2\u7AE0\u306A\u3057\u3067\u9032\u307F\u307E\u3059`);this.log(" \u30D5\u30A1\u30A4\u30EB\u306E\u79FB\u52D5\u30FB\u6539\u540D\u30FB\u6A29\u9650\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u8A2D\u5B9A: charter_file / CHARTER_FILE\uFF09")}
|
|
73
|
-
return null}return wrapCharter(prefix,body,suffix)}preflightOk(){const env=this.opts.env??process.env;if((env.PREFLIGHT_ENABLED??"true")!=="true")return true;const hosts=this.opts.preflightHosts??DEFAULT_PREFLIGHT_HOSTS;if(hosts.length===0)return true;const timeout=Number.parseInt(env.PREFLIGHT_TIMEOUT??"",10);const sec=Number.isInteger(timeout)&&timeout>0?timeout:5;for(let attempt=0;attempt<2;attempt+=1){if(attempt>0)sleepSync(2e3);for(const host of hosts){const nul=process.platform==="win32"?"\
|
|
74
|
-
NUL":"/dev/null";const curl=process.platform==="win32"?system32(process.env,"curl.exe"):"curl";if(curl===null)return false;const r=spawnSync(curl,["-sS","--max-time",String(sec),"-o",nul,`https://${host}/`],{encoding:"utf8",timeout:(sec+5)*1e3});if(r.error===void 0&&r.status===0)return true}}return false}};var DETECT_CACHE_MS=1800*1e3;var DEFAULT_PREFLIGHT_HOSTS=["api.anthropic.com","github.com"];function fallbackNote(tried){return["\u3010\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\u5B9F\u884C\u306B\u3064\u3044\u3066\u306E\u6CE8\u610F\u3011",
|
|
75
|
-
`\u3053\u306E\u30BF\u30B9\u30AF\u306F\u5225\u306EAI\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\uFF08${tried.join(", ")}\uFF09\u304C\u5148\u306B\u8A66\u884C\u3057\u307E\u3057\u305F\u304C\u3001\u30EC\u30FC\u30C8\u30EA\u30DF\u30C3\u30C8\u3001\u8A8D\u8A3C\u30A8\u30E9\u30FC\u3001\u307E\u305F\u306F\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u306B\u3088\u308A\u5B8C\u4E86\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002`,"\u524D\u306EAI\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u304C\u30BF\u30B9\u30AF\u306E\u9014\u4E2D\u307E\u3067\u4F5C\u696D\u3092\u9032\u3081\u3066\u3044\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002\u7279\u306B\u4EE5\u4E0B\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044:",
|
|
76
|
-
"- TWP\u30BF\u30B9\u30AF\u306E\u30B9\u30C6\u30FC\u30BF\u30B9\u304C\u300C\u9032\u884C\u4E2D\u300D\u306B\u5909\u66F4\u3055\u308C\u3066\u3044\u306A\u3044\u304B\uFF08\u5909\u66F4\u3055\u308C\u3066\u3044\u308B\u5834\u5408\u306F\u305D\u306E\u307E\u307E\u7D99\u7D9A\uFF09","- \u30B3\u30E1\u30F3\u30C8\u304C\u9014\u4E2D\u307E\u3067\u6295\u7A3F\u3055\u308C\u3066\u3044\u306A\u3044\u304B","- \u30D6\u30E9\u30F3\u30C1\u3084PR\u304C\u4F5C\u6210\u9014\u4E2D\u3067\u306A\u3044\u304B","\u307E\u305A\u73FE\u72B6\u3092\u78BA\u8A8D\u3057\u3066\u304B\u3089\u3001\u4E2D\u65AD\u3055\u308C\u305F\u7B87\u6240\u304B\u3089\u4F5C\u696D\u3092\u518D\u958B\u3057\u3066\u304F\
|
|
77
|
-
\u3060\u3055\u3044\u3002"].join("\n")}export{DEFAULT_CHARTER_PREFIX,DEFAULT_CHARTER_SUFFIX,DEFAULT_PREFLIGHT_HOSTS,DispatchEngine};
|