@tocca-systems/twp-cli 0.61.1 → 0.63.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/README.md +12 -0
- package/dist/{agent-loop-DFTHXSGN.js → agent-loop-6FS7FFXY.js} +2 -2
- package/dist/{ai-dispatch-M42S3SLX.js → ai-dispatch-HRXPRWCT.js} +6 -15
- package/dist/{api-command-4WOUH5PL.js → api-command-SFJFE2PE.js} +1 -1
- package/dist/{app-UJE2OSRN.js → app-N2ZLD6HG.js} +2 -2
- package/dist/{chunk-HAA3YDV2.js → chunk-2B7A3OY7.js} +26 -18
- package/dist/chunk-4ZREAAP4.js +36 -0
- package/dist/chunk-DXUFECE7.js +13 -0
- package/dist/{chunk-27BLHO7A.js → chunk-NXWXTUU6.js} +1 -1
- package/dist/chunk-PIB6MGG5.js +15 -0
- package/dist/{chunk-OPRRLLVH.js → chunk-PNLP5SXG.js} +2 -2
- package/dist/chunk-QEWCTKPV.js +15 -0
- package/dist/chunk-QHX5YFMM.js +23 -0
- package/dist/{chunk-OIC5Z6M3.js → chunk-UVCIVMT6.js} +1 -1
- package/dist/cli.js +14 -9
- package/dist/{commands-5E6DNXCQ.js → commands-6QNMVCU3.js} +45 -38
- package/dist/{commands-EYEMPZJX.js → commands-WIQVCMQE.js} +1 -1
- package/dist/{completion-WKXK7VGT.js → completion-MUSSUG6N.js} +4 -4
- package/dist/{logout-guard-HZLNYFXC.js → logout-guard-GQBF3GQH.js} +1 -1
- package/dist/{media-YU4GJOH2.js → media-4RUOR6LY.js} +1 -1
- package/dist/plan-submit-AWMD7XOY.js +3 -0
- package/dist/{registry-664USKMN.js → registry-4V3YNENU.js} +1 -1
- package/dist/{run-F2MRZYJO.js → run-J7ACNZ3D.js} +1 -1
- package/dist/{server-settings-EINXR7SK.js → server-settings-3YD7RR3A.js} +1 -1
- package/dist/{server-skills-5CKBIIQ4.js → server-skills-IFTDV3IQ.js} +1 -1
- package/dist/{setup-QJAHEDFF.js → setup-MUPUY2AX.js} +1 -1
- package/package.json +1 -1
- package/dist/chunk-5BDE3A3N.js +0 -34
- package/dist/chunk-MPEHKAAL.js +0 -15
- package/dist/chunk-OLASZWF5.js +0 -13
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{placeholderTaskKey,stepToItem}from"./chunk-QEWCTKPV.js";import{createHash,randomBytes}from"crypto";import fs from"fs";import path from"path";var PLAN_TOKEN_ENV="TWP_LOOP_PLAN_TOKEN";var PLAN_DIR_ENV="TWP_LOOP_PLAN_DIR";var SKILL_NAME_RE=/^[a-z][a-z0-9-]*$/;var PRIORITY_RE=/^P[0-9]$/;function fingerprint(token){return createHash("sha256").update(token).digest("hex").slice(0,32)}function sessionPath(dir,token){return path.join(dir,`plan-session-${fingerprint(token)}.json`)}function submissionPath(dir,token){return path.join(dir,`plan-submission-${fingerprint(token)}.json`)}function writeAtomic(file,body){const tmp=`${file}.${process.pid}\
|
|
4
|
+
.tmp`;fs.writeFileSync(tmp,body,{mode:384});fs.renameSync(tmp,file)}var NO_PLAN_SESSION={env:{},submission:()=>null,close:()=>void 0};var STALE_MS=24*60*60*1e3;function sweepStale(dir,now){let names;try{names=fs.readdirSync(dir)}catch{return}for(const f of names){if(!/^plan-(session|submission)-/.test(f))continue;try{const file=path.join(dir,f);if(now-fs.statSync(file).mtimeMs>STALE_MS)fs.rmSync(file,{force:true})}catch{}}}function fileSkillNames(dirs){const out=[];for(const dir of dirs){try{for(const f of fs.
|
|
5
|
+
readdirSync(dir))if(f.endsWith(".md"))out.push(f.slice(0,-3))}catch{}}return out}function openPlanSession(dir,skills){fs.mkdirSync(dir,{recursive:true});sweepStale(dir,Date.now());const token=randomBytes(24).toString("hex");const session={version:1,created_at:new Date().toISOString(),skills:[...new Set(skills)].sort()};writeAtomic(sessionPath(dir,token),JSON.stringify(session));return{env:{[PLAN_TOKEN_ENV]:token,[PLAN_DIR_ENV]:dir},submission:()=>readSubmission(submissionPath(dir,token)),close:()=>{
|
|
6
|
+
for(const f of[sessionPath(dir,token),submissionPath(dir,token)]){try{fs.rmSync(f,{force:true})}catch{}}}}}function readSubmission(file){let raw;try{raw=fs.readFileSync(file,"utf8")}catch{return null}try{const obj=JSON.parse(raw);if(obj&&typeof obj==="object"&&obj.plan&&Array.isArray(obj.plan.steps))return obj}catch{}return null}function checkPlan(input,skills){const errors=[];if(input===null||typeof input!=="object"||Array.isArray(input)){return{errors:['\u8A08\u753B\u306F {"steps": [...]} \u306E\u5F62\u306E\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u306B\u3057\u3066\u304F\u3060\u3055\u3044'],
|
|
7
|
+
steps:[],accepted:false}}const steps=input.steps;if(!Array.isArray(steps)){return{errors:["steps \u304C\u914D\u5217\u3067\u306F\u3042\u308A\u307E\u305B\u3093"],steps:[],accepted:false}}if(steps.length===0){errors.push("steps \u304C\u7A7A\u3067\u3059\u30020\u4EF6\u306E\u8A08\u753B\u306F --empty \u3067\u63D0\u51FA\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u5931\u6557\u3068\u533A\u5225\u3059\u308B\u305F\u3081\uFF09");return{errors,steps:[],accepted:false}}const seenKeys=new Map;const verdicts=steps.
|
|
8
|
+
map((raw,index)=>{const reasons=[];if(raw===null||typeof raw!=="object"||Array.isArray(raw)){return{index,skill:"",args:"",accepted:false,reasons:["step \u304C\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3067\u306F\u3042\u308A\u307E\u305B\u3093"]}}const step=raw;for(const k of["args","label","priority","ai_category"]){if(step[k]!==void 0&&typeof step[k]!=="string")reasons.push(`${k} \u306F\u6587\u5B57\u5217\u306B\u3057\u3066\u304F\u3060\u3055\u3044`)}const skill=typeof step.skill==="string"?step.skill.
|
|
9
|
+
trim():"";const args=typeof step.args==="string"?step.args.trim():"";if(skill===""){reasons.push("skill \u304C\u3042\u308A\u307E\u305B\u3093")}else if(skill.startsWith("twp-")||skill.startsWith("/")){reasons.push(`skill \u306F '/twp-' \u3092\u4ED8\u3051\u305A\u306B\u66F8\u3044\u3066\u304F\u3060\u3055\u3044\uFF08\u4F8B: '${skill.replace(/^\/?(twp-)?/,"")}'\uFF09`)}else if(!SKILL_NAME_RE.test(skill)){reasons.push(`skill '${skill}' \u306B\u4F7F\u3048\u306A\u3044\u6587\u5B57\u304C\u3042\u308A\u307E\u3059\uFF08\u82F1\u5C0F\u6587\u5B57\u30FB\u6570\u5B57\u30FB\u30CF\u30A4\u30D5\u30F3\u306E\u307F\uFF09`)}else if(skills.
|
|
10
|
+
size>0&&!skills.has(`twp-${skill}`)){reasons.push(`\u30B9\u30AD\u30EB '/twp-${skill}' \u306F\u5B58\u5728\u3057\u307E\u305B\u3093`)}if(typeof step.priority==="string"&&!PRIORITY_RE.test(step.priority)){reasons.push(`priority '${step.priority}' \u306F P0\u301CP9 \u306E\u5F62\u306B\u3057\u3066\u304F\u3060\u3055\u3044`)}const placeholder=placeholderTaskKey(args);if(placeholder!==null)reasons.push(`args \u306E\u30BF\u30B9\u30AF\u30AD\u30FC\u304C\u96DB\u5F62\u306E\u307E\u307E\u3067\u3059\uFF08'${placeholder}\
|
|
11
|
+
'\uFF09`);if(reasons.length===0){const item=stepToItem(step);const key=item?.task_key??"";if(key!==""){const first=seenKeys.get(key);if(first!==void 0)reasons.push(`${key} \u306F steps[${first}] \u3068\u91CD\u8907\u3057\u3066\u3044\u307E\u3059\uFF08\u540C\u3058\u8A08\u753B\u306B1\u4EF6\u307E\u3067\uFF09`);else seenKeys.set(key,index)}}return{index,skill,args,accepted:reasons.length===0,reasons}});return{errors,steps:verdicts,accepted:errors.length===0&&verdicts.every(v=>v.accepted)}}function formatCheck(check){
|
|
12
|
+
const lines=[];for(const e of check.errors)lines.push(`\u2717 ${e}`);for(const v of check.steps){const head=`steps[${v.index}] ${v.accepted?"\u53D7\u7406":"\u68C4\u5374"} /twp-${v.skill}${v.args?` ${v.args}`:""}`;lines.push(`${v.accepted?"\u2713":"\u2717"} ${head}`);for(const r of v.reasons)lines.push(` - ${r}`)}return lines.join("\n")}function runPlanSubmit(opts,deps){const token=deps.env[PLAN_TOKEN_ENV]?.trim()??"";const dir=deps.env[PLAN_DIR_ENV]?.trim()??"";if(token===""||dir===""){deps.
|
|
13
|
+
stderr(`plan submit \u306F\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u306E\u4E2D\u3067\u3060\u3051\u4F7F\u3048\u307E\u3059\uFF08${PLAN_TOKEN_ENV} / ${PLAN_DIR_ENV} \u304C\u3042\u308A\u307E\u305B\u3093\uFF09
|
|
14
|
+
`);return 2}let session;try{session=JSON.parse(fs.readFileSync(sessionPath(dir,token),"utf8"))}catch{deps.stderr("\u9375\u304C\u7121\u52B9\u3067\u3059\uFF08\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u304C\u65E2\u306B\u7D42\u308F\u3063\u3066\u3044\u308B\u304B\u3001\u5225\u306E\u8A08\u753B\u306E\u9375\u3067\u3059\uFF09\n");return 2}if(opts.empty===(opts.file!==void 0)){deps.stderr("--file <\u30D1\u30B9|-> \u304B --empty \u306E\u3069\u3061\u3089\u304B\u4E00\u65B9\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\n");
|
|
15
|
+
return 2}let plan;if(opts.empty){plan={steps:[]}}else{let text;try{text=opts.file==="-"?deps.readStdin():fs.readFileSync(opts.file,"utf8")}catch(err){deps.stderr(`\u8A08\u753B\u3092\u8AAD\u3081\u307E\u305B\u3093: ${err.message}
|
|
16
|
+
`);return 2}let parsed;try{parsed=JSON.parse(text)}catch(err){deps.stderr(`\u8A08\u753B\u304C JSON \u3068\u3057\u3066\u8AAD\u3081\u307E\u305B\u3093: ${err.message}
|
|
17
|
+
`);return 1}const check=checkPlan(parsed,new Set(session.skills??[]));deps.stdout(`${formatCheck(check)}
|
|
18
|
+
|
|
19
|
+
${JSON.stringify(check,null,2)}
|
|
20
|
+
`);if(!check.accepted){deps.stderr("\u68C4\u5374\u304C\u3042\u308B\u305F\u3081\u63D0\u51FA\u3057\u3066\u3044\u307E\u305B\u3093\u3002\u7406\u7531\u3092\u76F4\u3057\u3066\u51FA\u3057\u76F4\u3057\u3066\u304F\u3060\u3055\u3044\n");if(readSubmission(submissionPath(dir,token))!==null){deps.stderr("\uFF08\u524D\u56DE\u53D7\u7406\u3057\u305F\u63D0\u51FA\u304C\u6709\u52B9\u306A\u307E\u307E\u3067\u3059\u3002\u51FA\u3057\u76F4\u3055\u306A\u3051\u308C\u3070\u30EB\u30FC\u30D7\u306F\u305D\u308C\u3092\u767B\u9332\u3057\u307E\u3059\uFF09\n")}
|
|
21
|
+
return 1}plan=parsed}if(opts.check){deps.stdout(opts.empty?"\u691C\u67FB\u306E\u307F: \u7A7A\u306E\u8A08\u753B\uFF080\u4EF6\uFF09\n":"\u691C\u67FB\u306E\u307F: \u7F6E\u3044\u3066\u3044\u307E\u305B\u3093\uFF08--check\uFF09\n");return 0}const submitted={plan,empty:opts.empty,submitted_at:new Date().toISOString()};writeAtomic(submissionPath(dir,token),JSON.stringify(submitted));deps.stdout(opts.empty?"\u7A7A\u306E\u8A08\u753B\uFF080\u4EF6\uFF09\u3092\u63D0\u51FA\u3057\u307E\u3057\u305F\u3002\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u306E\u7D42\u4E86\u5F8C\u3001\u4F55\u3082\u7A4D\u307F\u307E\u305B\u3093\n":
|
|
22
|
+
`\u8A08\u753B\uFF08${plan.steps.length}\u4EF6\uFF09\u3092\u63D0\u51FA\u3057\u307E\u3057\u305F\u3002\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u306E\u7D42\u4E86\u5F8C\u306B\u30EB\u30FC\u30D7\u304C\u4E00\u5EA6\u306B\u767B\u9332\u3057\u307E\u3059\uFF08\u51FA\u3057\u76F4\u3059\u3068\u6700\u5F8C\u306E\u63D0\u51FA\u304C\u6709\u52B9\uFF09
|
|
23
|
+
`);return 0}export{PLAN_TOKEN_ENV,PLAN_DIR_ENV,NO_PLAN_SESSION,fileSkillNames,openPlanSession,checkPlan,formatCheck,runPlanSubmit};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{loadDomain}from"./chunk-
|
|
3
|
+
import{loadDomain}from"./chunk-PNLP5SXG.js";import{evaluateQuery}from"./chunk-GFLGXGWE.js";import{renderDocument,renderOutput}from"./chunk-YXVN6OCH.js";import{redactSecretValues,redactSecrets,withDebug}from"./chunk-UFGJSWKU.js";import{JsonBodyWithView}from"./chunk-Q3B65OFC.js";import{parseOperationArgs}from"./chunk-RX5HWI4L.js";import{DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,nextPageNotes,positiveInteger,shellQuote}from"./chunk-MI6HVYR2.js";import{Resolver,requireDefaultProject}from"./chunk-MYWDL3WX.js";
|
|
4
4
|
import{ResolveError}from"./chunk-HVZUXLQ4.js";import{ApiError,MultipartBody,TwpApiClient,appendQuery}from"./chunk-JA5A6UJ2.js";import{isRecord}from"./chunk-3ZRMMBP5.js";import{ApiRejectedError,ApiResponseError,EXIT_API_CLIENT,EXIT_API_SERVER,EXIT_AUTH,EXIT_FAILURE,EXIT_OK,EXIT_USAGE,EXIT_WAIT_TIMEOUT,NetworkError,UsageError,WaitTimeoutError}from"./chunk-VFPY2A23.js";import{GLOBAL_OPTIONS_HELP}from"./chunk-PECIBNFD.js";import{AuthSession,NotLoggedInError,SessionExpiredError,
|
|
5
5
|
loadCredentials}from"./chunk-XNLIEUAW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{effectiveApiUrl,loadUserConfig,resolveConfiguredOutput,resolveProfile}from"./chunk-4VZKNEVN.js";import{HELP_TOKEN}from"./chunk-QZBE4KC2.js";import{OUTPUT_FORMATS,resolveOutputFormat}from"./chunk-74BPZOKU.js";import{stringWidth}from"./chunk-UREA4ZIG.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import fs from"fs";import path from"path";var NO_REDACT_FLAG={name:"--no-redact",summary:"\u5FDC\u7B54\u306E\u4F0F\u5B57\u5316\u3092\u89E3\u9664\u3057\u3066\u751F\u306E\u5024\u3092\u51FA\u3059\uFF08\u9375\u306E\u53D7\u3051\u53D6\u308A\u7B49\uFF09",takesValue:false};var NO_REDACT_NOTICE="\u6CE8\u8A18: --no-redact \u306E\u305F\u3081\u51FA\u529B\u3092\u4F0F\u5B57\u5316\u3057\u307E\u305B\u3093\uFF08\u7AEF\u672B\u3068\u30ED\u30B0\u306B\u5E73\u6587\u3067\u6B8B\u308A\u307E\u3059\uFF09\u3002";function withCommonFlags(flags){return flags.some(flag=>flag.
|
|
6
6
|
name===NO_REDACT_FLAG.name)?flags:[...flags,NO_REDACT_FLAG]}function alignedList(entries,indent=" "){const width=entries.reduce((max,[left])=>Math.max(max,stringWidth(left)),0);return entries.map(([left,right])=>`${indent}${left}${" ".repeat(Math.max(0,width-stringWidth(left)))} ${right}`).join("\n")}function subresourcesOf(resource){return resource.subresources??[]}function renderResourceHelp(resource,path2){const subresources=subresourcesOf(resource);const operationSection=resource.operations.length===0?"":`
|
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{GLOBAL_OPTIONS_HELP}from"./chunk-PECIBNFD.js";import{parseArgv}from"./chunk-
|
|
4
|
+
import{GLOBAL_OPTIONS_HELP}from"./chunk-PECIBNFD.js";import{parseArgv}from"./chunk-4ZREAAP4.js";import"./chunk-2LOT54OO.js";import"./chunk-QZBE4KC2.js";import"./chunk-QQRJLH6B.js";import"./chunk-VSJBJXZO.js";var VERSION=true?"0.63.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
|
|
@@ -59,6 +59,10 @@ import{GLOBAL_OPTIONS_HELP}from"./chunk-PECIBNFD.js";import{parseArgv}from"./chu
|
|
|
59
59
|
twp task-loop skill pull --project <\u30AD\u30FC|UUID> <\u540D\u524D|--all> [--dir <\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA>]
|
|
60
60
|
\u30B5\u30FC\u30D0\u306E\u30B9\u30AD\u30EB\u5B9A\u7FA9\u3092\u30D5\u30A1\u30A4\u30EB\u3078\u5C55\u958B\u3002\u65E2\u5B58\u30D5\u30A1\u30A4\u30EB\u3068\u9055\u3046\u3068\u304D\u306F
|
|
61
61
|
\u5DEE\u5206\u3092\u8868\u793A\u3057\u3001--yes \u3067\u4E0A\u66F8\u304D\uFF08\u624B\u5143\u306B\u3060\u3051\u3042\u308B\u30D5\u30A1\u30A4\u30EB\u306F\u6D88\u3055\u306A\u3044\uFF09
|
|
62
|
+
twp task-loop plan submit --file <\u30D1\u30B9|-> | --empty [--check]
|
|
63
|
+
\u8A08\u753BAI\u304C\u8A08\u753B\u3092\u30EB\u30FC\u30D7\u3078\u63D0\u51FA\u3059\u308B\uFF08\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u306E\u4E2D\u3067\u3060\u3051\u53D7\u3051\u4ED8\u3051\u308B\uFF09\u3002
|
|
64
|
+
step \u3054\u3068\u306B\u53D7\u7406/\u68C4\u5374\u3068\u7406\u7531\u3092\u8868\u793A\u3057\u3001\u68C4\u5374\u304C\u3042\u308C\u3070\u975E0\u3067\u7D42\u308F\u308B\u3002
|
|
65
|
+
\u51FA\u3057\u76F4\u3059\u3068\u6700\u5F8C\u306E\u63D0\u51FA\u304C\u6709\u52B9\u3002--check \u306F\u691C\u67FB\u3060\u3051\u3067\u7F6E\u304B\u306A\u3044
|
|
62
66
|
twp --mode <id> \u8D77\u52D5\u6642\u306E\u30E2\u30FC\u30C9\u3092\u6307\u5B9A\uFF08dev | biz | plan\uFF09
|
|
63
67
|
twp --permission-mode <v>
|
|
64
68
|
\u30C4\u30FC\u30EB\u5B9F\u884C\u306E\u65E2\u5B9A\u3092\u4E0A\u66F8\u304D\uFF08plan | acceptEdits | denyAll\uFF09\u3002
|
|
@@ -1121,15 +1125,16 @@ TUI \u5185:
|
|
|
1121
1125
|
TWP API \u3092\u547C\u3079\u307E\u3059\u3002TWP API \u306E\u30C4\u30FC\u30EB\u306F\u65E2\u5B9A\u3067\u78BA\u8A8D\u304C\u51FA\u307E\u3059\uFF08-p \u3067\u306F\u62D2\u5426\u3002--allowed-tools \u3067\u540D\u524D\u3092\u8A31\u53EF\uFF09\u3002
|
|
1122
1126
|
\u4F1A\u8A71\u30FB\u30ED\u30FC\u30AB\u30EB\u30C4\u30FC\u30EB\uFF08\u30D5\u30A1\u30A4\u30EB\u30FB\u30B3\u30DE\u30F3\u30C9\u30FBgit\uFF09\u306F\u30C6\u30CA\u30F3\u30C8\u306E\u30AF\u30EC\u30B8\u30C3\u30C8\u3067\u5B9F\u969B\u306B\u52D5\u304D\u307E\u3059\u3002
|
|
1123
1127
|
`;function ignoreEpipe(stream){stream.on("error",err=>{if(err.code==="EPIPE")process.exit(0);throw err})}async function main(){const nodeMajor=Number(process.versions.node.split(".")[0]);if(nodeMajor<22){process.stderr.write(`twp-cli \u306B\u306F Node.js 22 \u4EE5\u4E0A\u304C\u5FC5\u8981\u3067\u3059\uFF08\u73FE\u5728: ${process.versions.node}\uFF09
|
|
1124
|
-
`);process.exit(1)}ignoreEpipe(process.stdout);ignoreEpipe(process.stderr);if(process.env["TWP_AUTO_UPDATE_WORKER"]==="1"){const{runAutoUpdateWorker}=await import("./auto-update-worker-VG77U4UA.js");await runAutoUpdateWorker().catch(()=>void 0);return}const[first,...rest]=process.argv.slice(2);if(first==="__complete"||first==="completion"){const completion=await import("./completion-
|
|
1125
|
-
const[{loadDomain},{loadUserConfig}]=await Promise.all([import("./registry-
|
|
1128
|
+
`);process.exit(1)}ignoreEpipe(process.stdout);ignoreEpipe(process.stderr);if(process.env["TWP_AUTO_UPDATE_WORKER"]==="1"){const{runAutoUpdateWorker}=await import("./auto-update-worker-VG77U4UA.js");await runAutoUpdateWorker().catch(()=>void 0);return}const[first,...rest]=process.argv.slice(2);if(first==="__complete"||first==="completion"){const completion=await import("./completion-MUSSUG6N.js");if(first==="completion"){process.exitCode=completion.runCompletion(rest,process.stdout,process.stderr);return}
|
|
1129
|
+
const[{loadDomain},{loadUserConfig}]=await Promise.all([import("./registry-4V3YNENU.js"),import("./config-3CNEQ7KN.js")]);process.exitCode=await completion.runComplete(rest,process.stdout,{loadDomain,profileNames:()=>Object.keys(loadUserConfig().profiles??{})});return}if(first==="configure"){const autoUpdate2=await import("./auto-update-YMI3F44R.js");autoUpdate2.registerRunning();autoUpdate2.onStartup(VERSION);const{runConfigure}=await import("./configure-3H3CGGBI.js");process.exitCode=
|
|
1126
1130
|
await runConfigure(rest);return}const args=parseArgv(process.argv.slice(2));if(args.command==="version"){process.stdout.write(`${VERSION}
|
|
1127
1131
|
`);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(" ")}
|
|
1128
1132
|
|
|
1129
|
-
${HELP}`);process.exitCode=2;return}const autoUpdate=await import("./auto-update-YMI3F44R.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-
|
|
1130
|
-
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-
|
|
1131
|
-
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-NCAVUXSX.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-
|
|
1132
|
-
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-
|
|
1133
|
+
${HELP}`);process.exitCode=2;return}const autoUpdate=await import("./auto-update-YMI3F44R.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-J7ACNZ3D.js");process.exitCode=await runDomain({domain:args.domain,...args.operation!==void 0?{operation:args.operation}:{},argv:args.domainArgv,help:args.
|
|
1134
|
+
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-SFJFE2PE.js");process.exitCode=await runApiCommand({argv:args.domainArgv,help:args.domainHelp,globals:{...args.profile!==void 0?{profile:args.profile}:{},...args.output!==
|
|
1135
|
+
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-NCAVUXSX.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-WIQVCMQE.js");
|
|
1136
|
+
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-6QNMVCU3.js");process.exitCode=await runTaskLoop(
|
|
1133
1137
|
{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,
|
|
1134
|
-
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-4NIS4J4S.js");process.exitCode=await runOneShot({prompt:args.prompt??"",fromStdin:args.promptFromStdin,mode:args.mode??"dev",...args.permissionMode!==
|
|
1135
|
-
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-
|
|
1138
|
+
skillOp:args.skillOp,skillName:args.skillName,skillAll:args.skillAll,skillDir:args.skillDir,planOp:args.planOp,planEmpty:args.planEmpty,planCheck:args.planCheck,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-4NIS4J4S.js");process.exitCode=await runOneShot({prompt:args.prompt??"",fromStdin:args.promptFromStdin,mode:args.mode??"dev",...args.permissionMode!==
|
|
1139
|
+
void 0?{permissionMode:args.permissionMode}:{},allowedTools:args.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-N2ZLD6HG.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.
|
|
1140
|
+
isTTY,doctor:args.doctor,version:VERSION})}await main();
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{
|
|
4
|
-
import{ServerSkillCatalog,formatSkillOrigins}from"./chunk-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
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(
|
|
3
|
+
import{EngineNotConfiguredError,NoopEngine,UnknownEngineError,aiUnavailableLabel,assertKnownEngine,failureHint,isAiUnavailable,needsHumanToRestoreAi}from"./chunk-ZOOEH7ZE.js";import{claudeConfigDir,resolveDetectDeps}from"./chunk-T4QZO6RQ.js";import{ScheduleApi,collectDue,gateStatus,nowInZone,parseCounts,promptSection}from"./chunk-S5DEP2HA.js";import{InstanceLock,buildLockOwner,defaultIsLoopProcess,writeLockOwner}from"./chunk-3WHC4FSG.js";import{LoopSettingsApplier,renderStepBudget}from"./chunk-NXWXTUU6.js";
|
|
4
|
+
import{ServerSkillCatalog,formatSkillOrigins}from"./chunk-PIB6MGG5.js";import"./chunk-YJZT3UD3.js";import"./chunk-A4LFG7MW.js";import"./chunk-VRBI2NPI.js";import{NO_PLAN_SESSION,fileSkillNames,openPlanSession}from"./chunk-QHX5YFMM.js";import{CapacityReporter,buildLoopConfig,describeOperations,evaluateOwnership,evaluatePlanGate,exportStateDirEnv,formatHookIds,formatHookWiring,localDate,loopStateDir,planGateStatePath,recordPlanned,runHook,runPrefetch,runPreflight}from"./chunk-2B7A3OY7.js";
|
|
5
|
+
import{exclusiveInflightEntries,formatExclusiveEntry,normalizeSkillName,skillOfItem,spawnSyncResolved}from"./chunk-AEJHDFXB.js";import{killProcessTree}from"./chunk-N2UVRM3Z.js";import{duplicateTaskKeyDropReason,excludedKeyInArgs,extractPlanJson,parseOpsCount,parsePlanExcludeKeys,placeholderTaskKey,releaseDeployDropReason,stepToItem,zeroTargetDropReasons}from"./chunk-QEWCTKPV.js";import"./chunk-DXUFECE7.js";import{AgentLoopApi,describeError,filterByStatus,isPermanent,pick,
|
|
6
|
+
pickString}from"./chunk-AT432SCP.js";import{PRIVATE_PROJECT_REF,isPrivateProjectId,isPrivateProjectRef,privateProjectId,projectFileKey}from"./chunk-GY7KI5E5.js";import{ULID_RE,loopProjectIdPolicy,resolveProjectRef}from"./chunk-HVZUXLQ4.js";import{isTaskKey}from"./chunk-II5RVJQN.js";import"./chunk-VFPY2A23.js";import{joinFor}from"./chunk-PMOUHEJQ.js";import{AuthSession}from"./chunk-XNLIEUAW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{compareVersionCores,
|
|
7
|
+
parseVersionCore}from"./chunk-DXXFUNYN.js";import"./chunk-5WGOHFAS.js";import{effectiveApiUrl,resolveProfile}from"./chunk-4VZKNEVN.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(
|
|
8
8
|
message)}
|
|
9
9
|
`;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,
|
|
10
|
-
name);try{if(fs.statSync(file).mtimeMs<cutoff)fs.rmSync(file,{force:true})}catch{}}}import fs7 from"fs";import path5 from"path";var MAX_OUTCOME_DETAIL_LENGTH=1e3;function parseOutcomeDetail(logText){const matches=[...logText.matchAll(/\b[A-Z][A-Z0-9_]*_RESULT:[^\n]*/g)];const line=matches.at(-1)?.[0];if(line===void 0)return null;const sep=line.indexOf("|");if(sep<0)return null;const detail=line.slice(sep+1).split("|").map(s=>s.trim()).filter(s=>s!=="").join(" | ");return detail===""?null:detail.slice(0,MAX_OUTCOME_DETAIL_LENGTH)}var str=v=>typeof v==="string"&&v!==""?v:null;function toRun(v){if(v===null||typeof v!=="obje\
|
|
10
|
+
name);try{if(fs.statSync(file).mtimeMs<cutoff)fs.rmSync(file,{force:true})}catch{}}}import fs7 from"fs";import os2 from"os";import path5 from"path";var MAX_OUTCOME_DETAIL_LENGTH=1e3;function parseOutcomeDetail(logText){const matches=[...logText.matchAll(/\b[A-Z][A-Z0-9_]*_RESULT:[^\n]*/g)];const line=matches.at(-1)?.[0];if(line===void 0)return null;const sep=line.indexOf("|");if(sep<0)return null;const detail=line.slice(sep+1).split("|").map(s=>s.trim()).filter(s=>s!=="").join(" | ");return detail===""?null:detail.slice(0,MAX_OUTCOME_DETAIL_LENGTH)}var str=v=>typeof v==="string"&&v!==""?v:null;function toRun(v){if(v===null||typeof v!=="obje\
|
|
11
11
|
ct"||Array.isArray(v))return null;const r=v;return{runnerId:str(r["runner_id"]),completedAt:str(r["completed_at"])??str(r["created_at"]),outcomeCode:str(r["outcome_code"]),outcomeDetail:str(r["outcome_detail"])}}function parseOutcomesResponse(skill,res){const failed={skill,recent:null,summary:null,truncated:false};if(!res.ok)return failed;const json=res.json;if(json===null||typeof json!=="object"||Array.isArray(json))return failed;const top=json;const data=top["data"];const b=data!==null&&typeof data===
|
|
12
12
|
"object"&&!Array.isArray(data)&&"items"in data?data:top;const items=b["items"];if(!Array.isArray(items))return failed;const recent=items.map(toRun).filter(r=>r!==null);const s=b["summary"];let summary=null;if(s!==null&&typeof s==="object"&&!Array.isArray(s)){const o=s;const streak=typeof o["failure_streak"]==="number"?o["failure_streak"]:0;const alert=typeof o["streak_alert"]==="number"?o["streak_alert"]:null;summary={lastSuccessAt:str(o["last_success_at"]),failureStreak:streak,streakIsLowerBound:o["\
|
|
13
13
|
streak_is_lower_bound"]===true,streakReasons:(Array.isArray(o["streak_reasons"])?o["streak_reasons"]:[]).map(toRun).filter(r=>r!==null),noContractSinceSuccess:typeof o["no_contract_since_success"]==="number"?o["no_contract_since_success"]:0,streakAlert:alert,alerting:o["alerting"]===true}}return{skill,recent,summary,truncated:b["truncated"]===true}}async function fetchOutcomeReports(api,skills){return Promise.all(skills.map(async skill=>{try{return parseOutcomesResponse(skill,await api.outcomes(
|
|
@@ -181,7 +181,7 @@ api.update(itemId,rest,runId||this.config.runId);if(res.ok){fs6.rmSync(file,{for
|
|
|
181
181
|
var ABORT_DRAIN_TIMEOUT_MS=15e3;function lastContractLine(logText,line){const prefix=line!==null&&/^[A-Z][A-Z0-9_]*$/.test(line)?line:"[A-Z][A-Z0-9_]*_RESULT";return[...logText.matchAll(new RegExp(`^(?:${prefix}):[^\\n]*`,"gm"))].at(-1)?.[0]??""}var TaskLoop=class{constructor(deps){this.deps=deps;this.writeback=new Writeback(deps.api,deps.config,deps.log);this.schedule=new ScheduleBridge({config:deps.config,log:deps.log,api:new ScheduleApi(deps.api),fetchCount:async(key,statusId)=>{const{total,error}=await deps.
|
|
182
182
|
projectApi.countByStatus(deps.config.projectId,statusId);if(error){deps.log.log(` \u26A0\uFE0F require_zero\u300C${key}\u300D\u306E\u4EF6\u6570\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${error}\uFF09\u3002\u3053\u306E\u67A0\u306F\u767A\u706B\u3057\u307E\u305B\u3093\uFF08fail-closed\uFF09`)}const refined=await refineCount(key,total,deps.config.operations.countHooks,deps.config.workspace);if(refined.note)deps.log.log(` ${refined.note}`);return refined.total}});this.
|
|
183
183
|
engine=deps.engine;this.releaseLog=new ReleaseOutcomeLog(deps.config.releaseOutcomeLogPath);this.postDeps={api:deps.api,config:deps.config,log:deps.log,releaseLog:this.releaseLog};this.planLock=new PlanLock({api:deps.api,config:deps.config,log:deps.log,runner:deps.runner,hasPendingItems:async()=>await this.hasPendingItems()&&!this.nothingClaimableBacklog,reregister:async()=>{deps.runner.registered=false;await deps.runner.registerOrThrow()},...deps.sleepFn?{sleepFn:deps.sleepFn}:{}});this.trustGate=
|
|
184
|
-
deps.trustGate??new TrustGate({enabled:()=>deps.config.ai.usesAi("claude"),check:()=>checkWorkspaceTrust(deps.config.workspace,{launcherBin:deps.config.claudeLauncher.bin})});this.timestamp=new Date().toISOString().replace(/[-:]/g,"").replace(/\..*$/,"");this.settings=deps.settings??new LoopSettingsApplier({api:deps.api,config:deps.config,log:m=>deps.log.log(m)});this.skills=deps.skills??new ServerSkillCatalog({api:deps.api,config:deps.config,log:m=>deps.log.log(m)})}deps;writeback;schedule;planLock;engine;releaseLog;postDeps;timestamp;deferredIds=new Set;midcycleEnqueued=0;aborting=false;draining=false;nothingClaimableBacklog=false;drainExitCode=0;drainWaiters=new Set;itemInFlight=null;ownershipLostItemId=null;abortDrained=null;cyclePreflightSection="";trustGate;settings;skills;sleep(ms){
|
|
184
|
+
deps.trustGate??new TrustGate({enabled:()=>deps.config.ai.usesAi("claude"),check:()=>checkWorkspaceTrust(deps.config.workspace,{launcherBin:deps.config.claudeLauncher.bin})});this.timestamp=new Date().toISOString().replace(/[-:]/g,"").replace(/\..*$/,"");this.settings=deps.settings??new LoopSettingsApplier({api:deps.api,config:deps.config,log:m=>deps.log.log(m)});this.skills=deps.skills??new ServerSkillCatalog({api:deps.api,config:deps.config,log:m=>deps.log.log(m)})}deps;planGateFingerprint=null;lastPlanWasEmpty=false;writeback;schedule;planLock;engine;releaseLog;postDeps;timestamp;deferredIds=new Set;midcycleEnqueued=0;aborting=false;draining=false;nothingClaimableBacklog=false;drainExitCode=0;drainWaiters=new Set;itemInFlight=null;ownershipLostItemId=null;abortDrained=null;cyclePreflightSection="";trustGate;settings;skills;sleep(ms){
|
|
185
185
|
return(this.deps.sleepFn??sleep)(ms)}sleepUnlessDraining(ms){if(this.draining)return Promise.resolve();return new Promise(resolve=>{let timer=null;let settled=false;const wake=()=>{if(settled)return;settled=true;if(timer!==null)clearTimeout(timer);this.drainWaiters.delete(wake);resolve()};this.drainWaiters.add(wake);const injected=this.deps.sleepFn;if(injected)void injected(ms).then(wake);else timer=setTimeout(wake,ms)})}requestDrain(reason,exitCode=0){if(this.draining)return;this.draining=true;
|
|
186
186
|
this.drainExitCode=exitCode;const running=this.itemInFlight;const why=reason.trim()===""?"\u7406\u7531\u4E0D\u660E":reason;this.deps.log.log(running===null?`\u30C9\u30EC\u30A4\u30F3\u8981\u6C42\u3092\u53D7\u3051\u53D6\u308A\u307E\u3057\u305F\uFF08${why}\uFF09\u3002\u5B9F\u884C\u4E2D\u306E\u30A2\u30A4\u30C6\u30E0\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u65B0\u3057\u3044\u30A2\u30A4\u30C6\u30E0\u3092\u53D6\u3089\u305A\u306B\u7D42\u4E86\u3057\u307E\u3059\u3002`:`\u30C9\u30EC\u30A4\u30F3\u8981\u6C42\u3092\u53D7\u3051\u53D6\u308A\u307E\u3057\u305F\uFF08${why}\
|
|
187
187
|
\uFF09\u3002\u5B9F\u884C\u4E2D\u306E\u30A2\u30A4\u30C6\u30E0\uFF08${running}\uFF09\u3092\u5B8C\u8D70\u3055\u305B\u3066\u304B\u3089\u7D42\u4E86\u3057\u307E\u3059\u3002`);const waiters=[...this.drainWaiters];this.drainWaiters.clear();for(const w of waiters)w()}cooldownNote(outcome){if(outcome!=="rate-limited")return"";const remaining=this.deps.config.ai.minCooldownRemainingSec();return remaining===null?"":`\uFF08\u6700\u77ED\u306E\u89E3\u9664\u307E\u3067\u7D04${remaining}\u79D2\uFF09`}startOwnershipWatch(itemId){
|
|
@@ -193,29 +193,30 @@ resolve()},ABORT_DRAIN_TIMEOUT_MS);timer.unref?.()})]);if(timer!==null)clearTime
|
|
|
193
193
|
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")}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\
|
|
194
194
|
\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.drainExitCode}\uFF09\u3002`);exitCode=this.drainExitCode;break}cycle+=1;const cycleStart=Date.now();log.separator();log.log(`========== Cy\
|
|
195
195
|
cle ${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.cyclePreflightSection=await runPreflight(config.preflight,config.workspace,m=>log.log(m));await this.settings.apply();await this.skills.refresh();
|
|
196
|
-
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(config.workspace,config.gitIdentity).logs)log.log(line);let planSkippedNoLock=false;
|
|
197
|
-
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`)}await this.reclaimStaleProcessing();
|
|
196
|
+
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(config.workspace,config.gitIdentity).logs)log.log(line);let planSkippedNoLock=false;let planSkippedNoChange=false;
|
|
197
|
+
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`)}await this.reclaimStaleProcessing();
|
|
198
198
|
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}
|
|
199
199
|
|
|
200
200
|
${trust.note}`}if(trust.wait){await runner.beat("waiting");if(cycle<config.maxCycles)await this.sleepUnlessDraining(config.intervalSec*1e3);continue}const pendingListed=await this.hasPendingItems();const hadPending=pendingListed&&!this.nothingClaimableBacklog;if(pendingListed&&!hadPending){log.log("pending \u306F\u3053\u306E\u6A5F\u4F53\u304C\u53D6\u308C\u306A\u3044\u3082\u306E\uFF08\u524D\u63D0\u672A\u5145\u8DB3\u30FB\u5225\u30D7\u30E9\u30C3\u30C8\u30D5\u30A9\u30FC\u30E0\u5C02\u7528\uFF09\u3060\u3051\u3067\u3059\uFF08\u524D\u56DE\u306E claim \u306E\u5224\u5B9A\uFF09\u3002\u30AD\u30E5\u30FC\u304C\u7A7A\u306E\u3068\u304D\u3068\u540C\u3058\u304F\u8A08\u753B\u3057\u307E\u3059\u3002")}
|
|
201
201
|
this.midcycleEnqueued=0;this.deferredIds=new Set;await this.enqueueDueScheduled(false);const planSkippedDisabled=!hadPending&&(!config.planEnabled||config.operations.planSkill===null);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){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\uFF08${config.
|
|
202
|
-
planEnabled?"operations.plan_skill \u672A\u8A2D\u5B9A":"plan_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&&this.draining){log.log("\u30C9\u30EC\u30A4\u30F3\u8981\u6C42\u3092\u53D7\u3051\u3066\u3044\u308B\u305F\u3081\u3001\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u3092\u5B9F\u884C\u3057\u307E\u305B\u3093\u3002")}else if(!hadPending
|
|
203
|
-
const acquired=await this.planLock.acquire();if(acquired!=="acquired"){planSkippedNoLock=true;log.log("\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u3092\u30B9\u30AD\u30C3\u30D7\u3057\u3066\u30AD\u30E5\u30FC\u306E\u5B9F\u884C\u3078\u9032\u307F\u307E\u3059\u3002")}else{
|
|
204
|
-
if(planResult==="aborted"){log.log("\u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u306B\u3088\u308A\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u3092\u6253\u3061\u5207\u308A\u307E\u3057\u305F\u3002\u30EB\u30FC\u30D7\u3092\u7D42\u4E86\u3057\u307E\u3059\u3002");
|
|
205
|
-
)`);log.log(` ${AI_RECOVERY_HINT}`);if(unavailableStreak>=3){exitCode=1;log.log("\u26D4 AI \u30921\u3064\u3082\u8D77\u52D5\u3067\u304D\u306A\u3044\u72B6\u614B\u304C\u7D9A\u3044\u3066\u3044\u307E\u3059\u3002\u30EB\u30FC\u30D7\u3092\u7D42\u4E86\u3057\u307E\u3059\uFF08\u7D42\u4E86\u30B3\u30FC\u30C91\uFF09");
|
|
206
|
-
break}}else{unavailableStreak=0;log.log(`\u26A0\uFE0F ${aiUnavailableLabel(planResult)}\u3067\u8A08\u753B\u3067\u304D\u307E\u305B\u3093${this.cooldownNote(planResult)}\uFF08\u9023\u7D9A\u30AB\u30A6\u30F3\u30C8\u306F\u52A0\u7B97\u3057\u306A\u3044\u30FB\u6B21\u30B5\u30A4\u30AF\u30EB\u3067\u518D\u5224\u5B9A\uFF09`)}
|
|
207
|
-
if(config.daemon){log.log(`\u30C7\u30FC\u30E2\u30F3\u30E2\u30FC\u30C9\u306E\u305F\u3081 ${config.intervalSec}\u79D2\u5F8C\u306B\u30EA\u30C8\u30E9\u30A4...`);await runner.beat("waiting");await this.sleepUnlessDraining(config.intervalSec*1e3);continue}break}}}const outcome=await this.
|
|
208
|
-
\u30A4\u30C6\u30E0\u306F\u5B8C\u8D70\u6E08\u307F\u30FB\u7D42\u4E86\u30B3\u30FC\u30C9 ${this.drainExitCode}\uFF09\u3002`:"/stop \u30B3\u30DE\u30F3\u30C9\u306B\u3088\u308A\u30EB\u30FC\u30D7\u3092\u7D42\u4E86\u3057\u307E\u3059\u3002");
|
|
209
|
-
unexecuted>0&&outcome.needsHuman){undeterminedStreak=0;
|
|
210
|
-
\u4EF6\u3092\
|
|
211
|
-
emptyQueue&&planSkippedDisabled){undeterminedStreak=0;log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle}: \u8A08\u753B\u3092\u7ACB\u3066\u306A\u3044\u8A2D\u5B9A\u3067\u30AD\u30E5\u30FC\u3082\u7A7A\u3067\u3057\u305F\uFF08\u5F85\u6A5F\u30FB\u9023\u7D9A\u30AB\u30A6\u30F3\u30C8\u306F\u52A0\u7B97\u3057\u306A\u3044\uFF09`)}else if(outcome.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
202
|
+
planEnabled?"operations.plan_skill \u672A\u8A2D\u5B9A":"plan_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&&this.draining){log.log("\u30C9\u30EC\u30A4\u30F3\u8981\u6C42\u3092\u53D7\u3051\u3066\u3044\u308B\u305F\u3081\u3001\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u3092\u5B9F\u884C\u3057\u307E\u305B\u3093\u3002")}else if(!hadPending&&
|
|
203
|
+
await this.planGateSaysSkip()){planSkippedNoChange=true;log.log("\u8A08\u753B\u306E AI \u3092\u8D77\u52D5\u305B\u305A\u30AD\u30E5\u30FC\u306E\u5B9F\u884C\u3078\u9032\u307F\u307E\u3059\uFF08\u5165\u529B\u306B\u5909\u5316\u306A\u3057\uFF09\u3002")}else if(!hadPending){const acquired=await this.planLock.acquire();if(acquired!=="acquired"){planSkippedNoLock=true;log.log("\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u3092\u30B9\u30AD\u30C3\u30D7\u3057\u3066\u30AD\u30E5\u30FC\u306E\u5B9F\u884C\u3078\u9032\u307F\u307E\u3059\u3002")}else{
|
|
204
|
+
await runner.beat("plan");this.planLock.startRenewWorker();let planResult="failed";try{planResult=await this.runPlanAndEnqueue(cycle)}finally{await this.planLock.release(planResult==="ok"?"completed":"failed");this.planLock.reportIfLost()}if(planResult==="ok"&&this.lastPlanWasEmpty)this.recordPlanGateFingerprint();if(planResult==="aborted"){log.log("\u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u306B\u3088\u308A\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u3092\u6253\u3061\u5207\u308A\u307E\u3057\u305F\u3002\u30EB\u30FC\u30D7\u3092\u7D42\u4E86\u3057\u307E\u3059\u3002");
|
|
205
|
+
break}if(planResult!=="ok"&&isAiUnavailable(planResult)){undeterminedStreak=0;if(needsHumanToRestoreAi(planResult)){noProgressStreak+=1;unavailableStreak+=1;log.log(`\u26D4 ${aiUnavailableLabel(planResult)}\u305F\u3081\u8A08\u753B\u3067\u304D\u307E\u305B\u3093 (\u9023\u7D9A: ${unavailableStreak})`);log.log(` ${AI_RECOVERY_HINT}`);if(unavailableStreak>=3){exitCode=1;log.log("\u26D4 AI \u30921\u3064\u3082\u8D77\u52D5\u3067\u304D\u306A\u3044\u72B6\u614B\u304C\u7D9A\u3044\u3066\u3044\u307E\u3059\u3002\u30EB\u30FC\u30D7\u3092\u7D42\u4E86\u3057\u307E\u3059\uFF08\u7D42\u4E86\u30B3\u30FC\u30C91\uFF09");
|
|
206
|
+
log.log(" **\u518D\u30ED\u30B0\u30A4\u30F3\uFF0F\u30C8\u30FC\u30AF\u30F3\u6295\u5165\u307E\u3067\u518D\u8D77\u52D5\u3057\u3066\u3082\u540C\u3058\u7D50\u679C\u306B\u306A\u308A\u307E\u3059**");break}}else{unavailableStreak=0;log.log(`\u26A0\uFE0F ${aiUnavailableLabel(planResult)}\u3067\u8A08\u753B\u3067\u304D\u307E\u305B\u3093${this.cooldownNote(planResult)}\uFF08\u9023\u7D9A\u30AB\u30A6\u30F3\u30C8\u306F\u52A0\u7B97\u3057\u306A\u3044\u30FB\u6B21\u30B5\u30A4\u30AF\u30EB\u3067\u518D\u5224\u5B9A\uFF09`)}
|
|
207
|
+
if(cycle<config.maxCycles){await runner.beat("waiting");await this.sleepUnlessDraining(config.intervalSec*1e3)}continue}if(planResult!=="ok"){log.log("\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u304C\u5931\u6557\u3057\u307E\u3057\u305F");if(config.daemon){log.log(`\u30C7\u30FC\u30E2\u30F3\u30E2\u30FC\u30C9\u306E\u305F\u3081 ${config.intervalSec}\u79D2\u5F8C\u306B\u30EA\u30C8\u30E9\u30A4...`);await runner.beat("waiting");await this.sleepUnlessDraining(config.intervalSec*1e3);continue}break}}}const outcome=await this.
|
|
208
|
+
runDequeueLoop(cycle);if(outcome.stop){log.log(this.aborting?"\u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u306B\u3088\u308A\u30EB\u30FC\u30D7\u3092\u7D42\u4E86\u3057\u307E\u3059\u3002":this.draining?`\u30C9\u30EC\u30A4\u30F3\u8981\u6C42\u306B\u3088\u308A\u30EB\u30FC\u30D7\u3092\u7D42\u4E86\u3057\u307E\u3059\uFF08\u5B9F\u884C\u4E2D\u306E\u30A2\u30A4\u30C6\u30E0\u306F\u5B8C\u8D70\u6E08\u307F\u30FB\u7D42\u4E86\u30B3\u30FC\u30C9 ${this.drainExitCode}\uFF09\u3002`:"/stop \u30B3\u30DE\u30F3\u30C9\u306B\u3088\u308A\u30EB\u30FC\u30D7\u3092\u7D42\u4E86\u3057\u307E\u3059\u3002");
|
|
209
|
+
if(this.draining)exitCode=this.drainExitCode;break}unavailableStreak=outcome.unexecuted>0&&outcome.needsHuman?unavailableStreak+1:0;if(outcome.progress){noProgressStreak=0;undeterminedStreak=0;log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle}: \u9032\u6357\u3042\u308A`)}else if(outcome.unexecuted>0&&outcome.needsHuman){undeterminedStreak=0;noProgressStreak+=1;log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle}: AI \u30921\u3064\u3082\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${outcome.unexecuted}\
|
|
210
|
+
\u4EF6\u3092\u30AD\u30E5\u30FC\u3078\u8FD4\u5374\u30FB\u9023\u7D9A: ${noProgressStreak}\uFF09`);log.log(` ${AI_RECOVERY_HINT}`)}else if(outcome.unexecuted>0){undeterminedStreak=0;log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle}: AI \u5074\u306E\u90FD\u5408\u3067 ${outcome.unexecuted}\u4EF6\u3092\u5B9F\u884C\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F${this.cooldownNote("rate-limited")}\uFF08\u30AD\u30E5\u30FC\u3078\u8FD4\u5374\u30FB\u9023\u7D9A\u30AB\u30A6\u30F3\u30C8\u306F\u52A0\u7B97\u3057\u306A\u3044\uFF09`)}else if(outcome.
|
|
211
|
+
deferred>0){log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle}: \u6642\u9593\u5E2F\u30B2\u30FC\u30C8\u3067\u5F85\u6A5F\u4E2D\uFF08${outcome.deferred}\u4EF6\u3092\u5F8C\u56DE\u3057\u30FB\u9023\u7D9A\u30AB\u30A6\u30F3\u30C8\u306F\u52A0\u7B97\u3057\u306A\u3044\uFF09`)}else if(outcome.emptyQueue&&planSkippedDisabled){undeterminedStreak=0;log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle}: \u8A08\u753B\u3092\u7ACB\u3066\u306A\u3044\u8A2D\u5B9A\u3067\u30AD\u30E5\u30FC\u3082\u7A7A\u3067\u3057\u305F\uFF08\u5F85\u6A5F\u30FB\u9023\u7D9A\u30AB\u30A6\u30F3\u30C8\u306F\u52A0\u7B97\u3057\u306A\u3044\uFF09`)}else if(outcome.
|
|
212
|
+
emptyQueue&&planSkippedNoChange){undeterminedStreak=0;log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle}: \u5165\u529B\u306B\u5909\u5316\u304C\u306A\u3044\u305F\u3081\u8A08\u753B\u3092\u30B9\u30AD\u30C3\u30D7\u3057\u3001\u30AD\u30E5\u30FC\u3082\u7A7A\u3067\u3057\u305F\uFF08\u5F85\u6A5F\u30FB\u9023\u7D9A\u30AB\u30A6\u30F3\u30C8\u306F\u52A0\u7B97\u3057\u306A\u3044\uFF09`)}else if(outcome.emptyQueue&&planSkippedNoLock){undeterminedStreak=0;if(this.planLock.permanentFail&&this.planLock.failStreak>=config.planLockPermanentMax){
|
|
213
|
+
noProgressStreak+=1;log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle}: \u8A08\u753B\u30ED\u30C3\u30AF\u306E\u53D6\u5F97\u304C\u6052\u4E45\u30A8\u30E9\u30FC\uFF084xx\uFF09\u3067 ${this.planLock.failStreak}\u30B5\u30A4\u30AF\u30EB\u9023\u7D9A\u3057\u3066\u3044\u307E\u3059`);log.log(` **\u518D\u8A66\u884C\u3067\u306F\u89E3\u6D88\u3057\u306A\u3044\u305F\u3081\u3001\u9032\u6357\u306A\u3057\u3068\u3057\u3066\u6570\u3048\u307E\u3059** (\u9023\u7D9A: ${noProgressStreak})`)}else{log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle}\
|
|
214
|
+
: \u8A08\u753B\u3092\u30B9\u30AD\u30C3\u30D7\u3057\u3001\u30AD\u30E5\u30FC\u3082\u7A7A\u3067\u3057\u305F\uFF08\u9023\u7D9A\u30AB\u30A6\u30F3\u30C8\u306F\u52A0\u7B97\u3057\u306A\u3044\u30FB\u6B21\u30B5\u30A4\u30AF\u30EB\u3067\u518D\u5224\u5B9A\uFF09`)}}else if(outcome.undetermined){undeterminedStreak+=1;log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle}: \u30AD\u30E5\u30FC\u306E\u72B6\u614B\u3092\u5224\u5B9A\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${undeterminedStreak}\u30B5\u30A4\u30AF\u30EB\u9023\u7D9A\u30FB\u9032\u6357\u306A\u3057\u306B\u306F\u6570\u3048\u306A\u3044\uFF09`);
|
|
215
|
+
if(undeterminedStreak>=config.queueUndeterminedMax){log.log(`\u26D4 claim API\u306E\u969C\u5BB3\u304C ${undeterminedStreak} \u30B5\u30A4\u30AF\u30EB\u7D9A\u3044\u3066\u3044\u307E\u3059\u3002\u30EB\u30FC\u30D7\u3092\u7D42\u4E86\u3057\u307E\u3059\uFF08\u7D42\u4E86\u30B3\u30FC\u30C91\uFF09`);log.log(" \u78BA\u8A8D: API\u306E\u758E\u901A\uFF0F\u30ED\u30B0\u30A4\u30F3\u72B6\u614B\uFF0F--project \u306E\u6307\u5B9A\u3002\u5FA9\u65E7\u5F8C\u306B\u518D\u8D77\u52D5\u3057\u3066\u304F\u3060\u3055\u3044");
|
|
216
|
+
exitCode=1;break}}else{undeterminedStreak=0;noProgressStreak+=1;log.log(outcome.emptyQueue?`\u30B5\u30A4\u30AF\u30EB ${cycle}: \u30AD\u30E5\u30FC\u304C\u7A7A\u3067\u3057\u305F (\u9023\u7D9A: ${noProgressStreak})`:`\u30B5\u30A4\u30AF\u30EB ${cycle}: \u9032\u6357\u306A\u3057 (\u9023\u7D9A: ${noProgressStreak})`)}log.log(`\u30B5\u30A4\u30AF\u30EB ${cycle} \u5B8C\u4E86 (duration: ${Math.trunc((Date.now()-cycleStart)/1e3)}s)`);if(noProgressStreak>=3){log.log("3\u30B5\u30A4\u30AF\u30EB\u9023\u7D9A\u3067\u9032\u6357\u306A\u3057\u3002\u30EB\u30FC\u30D7\u3092\u7D42\u4E86\u3057\u307E\u3059\u3002");
|
|
217
|
+
if(unavailableStreak>=3){exitCode=1;log.log("\u26D4 \u539F\u56E0\u306F\u300CAI \u30921\u3064\u3082\u8D77\u52D5\u3067\u304D\u306A\u3044\u300D\u3053\u3068\u3067\u3059\uFF08\u672A\u30ED\u30B0\u30A4\u30F3\u7B49\uFF09\u3002");log.log(` ${AI_RECOVERY_HINT}`);log.log(" **\u8CC7\u683C\u60C5\u5831\u3092\u76F4\u3059\u307E\u3067\u518D\u8D77\u52D5\u3057\u3066\u3082\u540C\u3058\u7D50\u679C\u306B\u306A\u308A\u307E\u3059**")}if(this.planLock.permanentFail){log.log("\u26D4 \u539F\u56E0\u306F\u8A08\u753B\u30ED\u30C3\u30AFAPI\u306E\u6052\u4E45\u30A8\u30E9\u30FC\uFF084xx\uFF09\u3067\u3059\u3002**\u8A2D\u5B9A\u3092\u76F4\u3059\u307E\u3067\u518D\u8D77\u52D5\u3057\u3066\
|
|
218
|
+
\u3082\u540C\u3058\u7D50\u679C\u306B\u306A\u308A\u307E\u3059**");exitCode=1}break}if(cycle<config.maxCycles){log.log(`\u6B21\u30B5\u30A4\u30AF\u30EB\u307E\u3067 ${config.intervalSec}\u79D2 \u5F85\u6A5F...`);await runner.beat("waiting");await this.sleepUnlessDraining(config.intervalSec*1e3)}}log.separator();this.abortDrained?.();log.log("twp task-loop \u7D42\u4E86");log.log(` \u7DCF\u30B5\u30A4\u30AF\u30EB\u6570: ${cycle}`);log.log(` \u30ED\u30B0: ${config.logDir}`);log.separator();return exitCode}async hasPendingItems(){
|
|
219
|
+
const res=await this.deps.api.list({status:"pending",limit:1});if(!res.ok){this.deps.log.log(` \u26A0\uFE0F pending\u4EF6\u6570\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${describeError(res)}\uFF09\u3002\u5B89\u5168\u5074\u306B\u5012\u3057\u3066\u8A08\u753B\u3092\u30B9\u30AD\u30C3\u30D7\u3057\u307E\u3059\u3002`);return true}const items=pick(res.json,"items");if(!Array.isArray(items)){this.deps.log.log(` \u26A0\uFE0F pending\u4EF6\u6570\u3092\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u5FDC\u7B54\u306E\u5148\u982D: ${res.
|
|
219
220
|
raw.slice(0,120)}\uFF09\u3002\u5B89\u5168\u5074\u306B\u5012\u3057\u3066\u8A08\u753B\u3092\u30B9\u30AD\u30C3\u30D7\u3057\u307E\u3059\u3002`);return true}return filterByStatus(items,"pending").length>0}async reclaimStaleProcessing(){const{config,log,api}=this.deps;if(config.staleReclaimHours<=0)return;const floorH=staleFloorHours(config.aiTimeoutSec);let hours=config.staleReclaimHours;if(hours<floorH){log.log(` \u2139\uFE0F STALE_RECLAIM_HOURS=${hours}h \u306F\u6700\u9577\u5B9F\u884C\u6642\u9593(AI_TIMEOUT\xD72=${floorH}\
|
|
220
221
|
h)\u3092\u4E0B\u56DE\u308B\u305F\u3081 ${floorH}h \u3092\u4F7F\u3044\u307E\u3059`);hours=floorH}const thresholdMs=hours*36e5;const now=Date.now();const stale=[];let cursor;for(let page=0;page<50;page++){const res=await api.list({status:"processing",limit:200,cursor});if(!res.ok){log.log(` \u26A0\uFE0F stale processing \u306E\u8D70\u67FB\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${describeError(res)}\uFF09\u3002`);log.log(" \u53D6\u308A\u6B8B\u3057\u306E\u56DE\u53CE\u306F\u3053\u306E\u30B5\u30A4\u30AF\u30EB\u884C\u308F\u308C\u3066\u3044\u307E\u305B\u3093");
|
|
221
222
|
return}const items=pick(res.json,"items");if(!Array.isArray(items)){log.log(` \u26A0\uFE0F stale processing \u306E\u4E00\u89A7\u3092\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u5FDC\u7B54\u306E\u5148\u982D: ${res.raw.slice(0,120)}\uFF09\u3002`);log.log(" \u53D6\u308A\u6B8B\u3057\u306E\u56DE\u53CE\u306F\u3053\u306E\u30B5\u30A4\u30AF\u30EB\u884C\u308F\u308C\u3066\u3044\u307E\u305B\u3093");return}for(const it of filterByStatus(items,"processing")){if(it.runner_id)continue;
|
|
@@ -233,15 +234,20 @@ led \u3068\u3057\u3066\u8FD4\u3057\u307E\u305B\u3093**")}else{await this.schedul
|
|
|
233
234
|
scheduleId}] ${row.windowKey} \u2192 ${itemId}\uFF09`);log.log(" **\u30EA\u30FC\u30B9\u671F\u9650\u5F8C\u306B\u540C\u3058\u67A0\u304C\u518D\u6295\u5165\u3055\u308C\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059**\u3002\u5B9A\u671F\u67A0\u304C\u672C\u756A\u30EA\u30EA\u30FC\u30B9\u306A\u3089\u4E8C\u91CD\u5B9F\u884C\u306B\u306A\u308A\u307E\u3059")}if(exclusiveSkill!==null)exclusiveEnqueued.add(exclusiveSkill);enqueuedLines.push(`- [${row.priority}] ${row.label} \u2192 ${prompt}`);log.log(
|
|
234
235
|
` \u5B9A\u671F\u30A8\u30F3\u30AD\u30E5\u30FC: [${row.priority}] ${row.label} \u2192 ${prompt}`);count+=1}if(count>0){log.log(midcycle?`\u5B9A\u671F\u30B9\u30B1\u30B8\u30E5\u30FC\u30EB\uFF08\u4E2D\u9593\u5224\u5B9A\uFF09: ${count}\u4EF6\u3092\u30AD\u30E5\u30FC\u306B\u6295\u5165\u3057\u307E\u3057\u305F`:`\u5B9A\u671F\u30B9\u30B1\u30B8\u30E5\u30FC\u30EB: ${count}\u4EF6\u3092\u30AD\u30E5\u30FC\u306B\u6295\u5165\u3057\u307E\u3057\u305F`);this.midcycleEnqueued+=count}else if(!midcycle){log.log("\u5B9A\u671F\u30B9\u30B1\u30B8\
|
|
235
236
|
\u30E5\u30FC\u30EB: \u4ECA\u30B5\u30A4\u30AF\u30EB\u3067\u767A\u706B\u3057\u305F\u5B9A\u671F\u30BF\u30B9\u30AF\u306F\u3042\u308A\u307E\u305B\u3093")}if(!midcycle){const file=path5.join(this.deps.config.logDir,`schedule-enqueued-${this.timestamp}.txt`);try{fs7.mkdirSync(path5.dirname(file),{recursive:true});fs7.writeFileSync(file,enqueuedLines.join("\n"))}catch{}}}async maybeEnqueueDueMidcycle(){const res=await this.deps.api.reclaim();if(!res.ok){this.deps.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(
|
|
236
|
-
res)}\uFF09`)}if(this.midcycleEnqueued>=this.deps.config.scheduleMidcycleMax)return;await this.enqueueDueScheduled(true)}async
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
res)}\uFF09`)}if(this.midcycleEnqueued>=this.deps.config.scheduleMidcycleMax)return;await this.enqueueDueScheduled(true)}async planGateSaysSkip(){const{config,log}=this.deps;this.planGateFingerprint=null;const gate=config.operations.planGate;if(gate===null)return false;const decision=await evaluatePlanGate(gate,{cwd:config.workspace,statePath:planGateStatePath(config.stateDir,projectFileKey(config.projectId)),nowMs:Date.now()});log.log(` plan_gate: ${decision.reason}`);this.planGateFingerprint=
|
|
238
|
+
decision.fingerprint;return decision.skip}recordPlanGateFingerprint(){const{config,log}=this.deps;const fingerprint=this.planGateFingerprint;this.planGateFingerprint=null;if(fingerprint===null)return;const statePath=planGateStatePath(config.stateDir,projectFileKey(config.projectId));if(!recordPlanned(statePath,fingerprint,Date.now())){log.log(` \u26A0\uFE0F plan_gate: \u8A08\u753B\u6642\u306E\u6307\u7D0B\u3092 ${statePath} \u306B\u8A18\u9332\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u6B21\u30B5\u30A4\u30AF\u30EB\u3082\u8A08\u753B\u3057\u307E\u3059\uFF09`)}}async runPlanAndEnqueue(cycle){
|
|
239
|
+
const{config,log}=this.deps;this.lastPlanWasEmpty=false;const planSkill=config.operations.planSkill;if(planSkill===null)return"failed";log.separator();log.log("Phase 1: \u8A08\u753B\u3092\u7ACB\u6848\u3057\u3066\u30AD\u30E5\u30FC\u306B\u683C\u7D0D...");log.separator();const planLogFile=path5.join(config.logDir,`plan-${this.timestamp}-${cycle}.log`);const enqueuedFile=path5.join(config.logDir,`schedule-enqueued-${this.timestamp}.txt`);const scheduleSection=await this.schedule.promptSection(enqueuedFile);
|
|
240
|
+
if(config.prefetch.length>0)log.log(`\u8A08\u753B\u7528\u30C7\u30FC\u30BF\u3092\u4E8B\u524D\u53D6\u5F97\u4E2D\uFF08\u30D5\u30C3\u30AF ${config.prefetch.length}\u4EF6\uFF09...`);const prefetchSection=await runPrefetch(config.prefetch,config.workspace,m=>log.log(m));const excludeKeys=parsePlanExcludeKeys(prefetchSection);if(excludeKeys.size>0){log.log(` \u8A08\u753B\u5019\u88DC\u304B\u3089\u5916\u3059\u30BF\u30B9\u30AF\uFF08\u672A\u56DE\u7B54\u306E\u8CEA\u554F\u3042\u308A\uFF09: ${[...excludeKeys].
|
|
241
|
+
sort().join(", ")}`)}const taskStatusSnapshot=parseTaskStatusSnapshot(prefetchSection);if(taskStatusSnapshot===null){log.log(" \u26A0\uFE0F prefetch \u306B OPS_TASK_STATUS \u30DE\u30FC\u30AB\u30FC\u304C\u3042\u308A\u307E\u305B\u3093");log.log(" \u300C\u524D\u56DE\u304C\u72B6\u614B\u3092\u9032\u3081\u305F\u5834\u5408\u306E\u518D\u6295\u5165\u6291\u6B62\u300D\u306F**\u3053\u306E\u30B5\u30A4\u30AF\u30EB\u7121\u52B9**\u3067\u3059\uFF08\u6295\u5165\u306F\u6B62\u3081\u307E\u305B\u3093\uFF09")}else if(!taskStatusSnapshot.
|
|
239
242
|
complete){log.log(" \u26A0\uFE0F \u30BF\u30B9\u30AF\u306E\u30B9\u30C6\u30FC\u30BF\u30B9\u3092\u4E00\u90E8\u53D6\u5F97\u3067\u304D\u3066\u3044\u307E\u305B\u3093\uFF08complete=0\uFF09\u2192 \u518D\u6295\u5165\u6291\u6B62\u306F\u3053\u306E\u30B5\u30A4\u30AF\u30EB\u7121\u52B9\u3067\u3059")}const outcomeReports=await fetchOutcomeReports(this.deps.api,config.outcomeSkills??[]);for(const w of outcomeStreakWarnings(outcomeReports))log.log(` \u26A0\uFE0F ${w}`);const outcomeSection=renderOutcomeSection(
|
|
240
|
-
outcomeReports);
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
243
|
+
outcomeReports);let planSession;try{planSession=openPlanSession(path5.join(config.stateDir,"plan-submit"),[...fileSkillNames([path5.join(config.workspace,".claude","commands"),...process.env.CLAUDE_CONFIG_DIR?[path5.join(process.env.CLAUDE_CONFIG_DIR,"commands")]:[],path5.join(os2.homedir(),".claude","commands")]),...this.skills.names()])}catch(err){log.log(` \u26A0\uFE0F \u8A08\u753B\u306E\u63D0\u51FA\u53E3\u3092\u6E96\u5099\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${err.message}\uFF09\
|
|
244
|
+
\u3002\u3053\u306E\u30B5\u30A4\u30AF\u30EB\u306F\u5FDC\u7B54\u306E\u6587\u7AE0\u304B\u3089\u8A08\u753B\u3092\u53D6\u308A\u51FA\u3057\u307E\u3059`);planSession=NO_PLAN_SESSION}let result;let submitted;try{result=await this.engine.run({prompt:buildPlanPrompt(config,planSkill,scheduleSection,prefetchSection,outcomeSection),promptPrefix:this.cyclePreflightSection,logFile:planLogFile,timeoutSec:config.planTimeoutSec,cwd:config.workspace,skill:normalizeSkillName(planSkill.replace(/^\//,"")),...Object.
|
|
245
|
+
keys(planSession.env).length>0?{extraEnv:planSession.env}:{},validate:output=>planSession.submission()!==null||extractPlanJson(output)!==null});submitted=planSession.submission()}finally{planSession.close()}writeLogFile(planLogFile,result.output);if(result.outcome==="aborted"){log.log(" \u23F9 \u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u306B\u3088\u308A\u8A08\u753B\u3092\u6253\u3061\u5207\u308A\u307E\u3057\u305F");return"aborted"}if(result.outcome!=="ok"){if(isAiUnavailable(result.outcome)){log.log(`\
|
|
246
|
+
\u23ED AI \u3092\u8D77\u52D5\u3067\u304D\u306A\u3044\u305F\u3081\u8A08\u753B\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08outcome=${result.outcome}\uFF09`);return result.outcome}log.log(` \u26D4 \u8A08\u753B\u306E\u5B9F\u884C\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08outcome=${result.outcome}\uFF09`);return"failed"}if(this.planLock.isLost()){log.log(` \u26D4 \u8A08\u753B\u4E2D\u306B\u8A08\u753B\u30ED\u30C3\u30AF\u3092\u5931\u3044\u307E\u3057\u305F\uFF08reason=${this.planLock.lostReasonText()}\
|
|
247
|
+
\uFF09`);log.log(" **\u30A8\u30F3\u30AD\u30E5\u30FC\u3092\u4E2D\u6B62\u3057\u307E\u3059**\u3002\u8A08\u753B\u7D50\u679C\u306F\u7834\u68C4\u3057\u3001\u6B21\u30B5\u30A4\u30AF\u30EB\u3067\u53D6\u308A\u76F4\u3057\u307E\u3059");return"ok"}if(submitted?.empty===true){log.log("\u8A08\u753BAI\u306F\u7A7A\u306E\u8A08\u753B\uFF080\u4EF6\uFF09\u3092\u63D0\u51FA\u3057\u307E\u3057\u305F");this.lastPlanWasEmpty=true;return"ok"}if(submitted!==null){log.log(`\u63D0\u51FA\u3055\u308C\u305F\u8A08\u753B\u3092\u4F7F\u3044\u307E\u3059\uFF08plan submit\u30FB${submitted.
|
|
248
|
+
plan.steps.length}\u4EF6\u30FB${submitted.submitted_at}\uFF09`)}else{log.log("\u8A08\u753B\u306E\u63D0\u51FA\u304C\u7121\u3044\u305F\u3081\u3001\u5FDC\u7B54\u306E\u6587\u7AE0\u304B\u3089\u8A08\u753B\u3092\u53D6\u308A\u51FA\u3057\u307E\u3059")}const plan=submitted?.plan??extractPlanJson(result.output);if(!plan||plan.steps.length===0){log.log("\u8A08\u753B\u306Bsteps\u304C\u3042\u308A\u307E\u305B\u3093");this.lastPlanWasEmpty=true;return"ok"}const verifyBacklog=parseOpsCount(prefetchSection,"verif\
|
|
249
|
+
y");const devVerifyPlanned=plan.steps.filter(s=>(s.skill??"").trim()==="dev-verify").length;const releaseDeployDrop=releaseDeployDropReason(verifyBacklog,devVerifyPlanned);if(releaseDeployDrop!==null&&plan.steps.some(s=>normalizeSkillName(s.skill??"")==="release-deploy")){log.log(` release-deploy \u306F\u8A08\u753B\u304B\u3089\u9664\u5916\u3057\u307E\u3059\uFF08\u7A7A\u632F\u308A\u9632\u6B62\u30AC\u30FC\u30C9\uFF09: ${releaseDeployDrop}`)}const zeroTargetDrops=zeroTargetDropReasons(prefetchSection,
|
|
250
|
+
config.operations.zeroTargetGates);for(const[skill,reason]of zeroTargetDrops){if(plan.steps.some(s=>normalizeSkillName(s.skill??"")===skill)){log.log(` ${skill} \u306F\u8A08\u753B\u304B\u3089\u9664\u5916\u3057\u307E\u3059\uFF08\u5BFE\u8C61\u8AAD\u307F\u66FF\u3048\u9632\u6B62\u30AC\u30FC\u30C9\uFF09: ${reason}`)}}const processing=await this.deps.api.processingSnapshot();const inflightKeys=new Set;if(processing===null){log.log(" \u26A0\uFE0F \u51E6\u7406\u4E2D\u30A2\u30A4\u30C6\u30E0\u306E\u4E00\u89A7\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F");
|
|
245
251
|
log.log(" \u540C\u4E00\u30BF\u30B9\u30AF\u306E\u4E8C\u91CD\u7740\u624B\u30AC\u30FC\u30C9\u306F**\u3053\u306E\u30B5\u30A4\u30AF\u30EB\u7121\u52B9**\u3067\u3059\uFF08\u6295\u5165\u306F\u6B62\u3081\u307E\u305B\u3093\uFF09")}else{const entries=inflightEntries(processing,new Date,inflightStaleHours(config.aiTimeoutSec));for(const entry of entries)inflightKeys.add(entry.key);if(entries.length>0){log.log(" \u4ED6\u30E9\u30F3\u30CA\u30FC\u304C\u51E6\u7406\u4E2D\u306E task_key\uFF08\u3053\u306E\u8A08\u753B\u304B\u3089\u306F\u9664\u5916\u3057\u307E\u3059\uFF09:");
|
|
246
252
|
for(const entry of entries)log.log(` - ${formatInflightEntry(entry)}`)}}let pendingCache=null;let pendingFetched=false;const pendingOnce=async()=>{if(!pendingFetched){pendingFetched=true;pendingCache=await this.deps.api.pendingSnapshot()}return pendingCache};let pendingKeys=null;let pendingKeysResolved=false;const queuedPendingKeys=async()=>{if(pendingKeysResolved)return pendingKeys;pendingKeysResolved=true;const pending=await pendingOnce();if(pending===null){log.log(" \u26A0\uFE0F pending \u306E\u4E00\u89A7\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\
|
|
247
253
|
\u3093\u3067\u3057\u305F");log.log(" \u30AD\u30E5\u30FC\u5F85\u3061\u30AD\u30FC\u306E\u7A4D\u307F\u76F4\u3057\u6291\u6B62\u306F**\u3053\u306E\u30B5\u30A4\u30AF\u30EB\u7121\u52B9**\u3067\u3059\uFF08\u6295\u5165\u306F\u6B62\u3081\u307E\u305B\u3093\uFF09");return null}pendingKeys=new Set(pending.map(p=>(p.task_key??"").trim()).filter(k=>k!==""));return pendingKeys};let exclusiveQueued=null;let exclusiveFetched=false;const exclusiveInflight=async()=>{if(exclusiveFetched)return exclusiveQueued;exclusiveFetched=
|
|
@@ -329,12 +335,13 @@ const startedAtMs=now();let warned="";let done=false;const check=()=>{if(done)re
|
|
|
329
335
|
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`)}
|
|
330
336
|
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()})}
|
|
331
337
|
`);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)||
|
|
332
|
-
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-
|
|
338
|
+
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-HRXPRWCT.js");const{DEFAULT_PREFLIGHT_HOSTS}=await import("./ai-dispatch-HRXPRWCT.js");const extraHosts=config.
|
|
333
339
|
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,skillOverlayDir:path8.join(config.stateDir,"skill-overlay",projectFileKey(config.projectId)),launcherBin:config.
|
|
334
|
-
claudeLauncher.bin,...extraHosts.length>0?{preflightHosts:[...DEFAULT_PREFLIGHT_HOSTS,...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);
|
|
340
|
+
claudeLauncher.bin,...extraHosts.length>0?{preflightHosts:[...DEFAULT_PREFLIGHT_HOSTS,...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);if(opts.action==="plan"){if(opts.planOp!=="submit"){process.stderr.write("plan \u306B\u306F submit \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\n");return 2}const{runPlanSubmit}=await import("./plan-submit-AWMD7XOY.js");
|
|
341
|
+
return runPlanSubmit({file:opts.charterInput,empty:opts.planEmpty===true,check:opts.planCheck===true},{env:process.env,readStdin:()=>fs10.readFileSync(0,"utf8"),stdout:s=>process.stdout.write(s),stderr:s=>process.stderr.write(s)})}const profile=resolveProfile(opts.profile);let creds;try{creds=new AuthSession(profile.name,profile.apiUrl).loadOrThrow()}catch(err){process.stderr.write(`${err.message}
|
|
335
342
|
`);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.
|
|
336
343
|
message}
|
|
337
|
-
`);return 1}const projectId=project.id;if(opts.action==="setup"){const{runSetup,parseAiList}=await import("./setup-
|
|
344
|
+
`);return 1}const projectId=project.id;if(opts.action==="setup"){const{runSetup,parseAiList}=await import("./setup-MUPUY2AX.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(" / ")}
|
|
338
345
|
`);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.
|
|
339
346
|
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-LIX2JXRJ.js");return runCharterCommand({api:new AgentLoopApi({apiUrl,projectId,session})},{op:opts.
|
|
340
347
|
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");
|
|
@@ -356,7 +363,7 @@ log.log("\u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u4FE1\u3057\u307E\u305
|
|
|
356
363
|
"\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,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"}\
|
|
357
364
|
\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({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.
|
|
358
365
|
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}\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`;
|
|
359
|
-
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-
|
|
366
|
+
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-3YD7RR3A.js");const settings=new LoopSettingsApplier2({api,config,log:m=>log.log(m)});await settings.apply();const{ServerSkillCatalog:ServerSkillCatalog2}=await import("./server-skills-IFTDV3IQ.js");const skills=new ServerSkillCatalog2({api,config,log:m=>log.log(m)});await skills.
|
|
360
367
|
refresh();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,skills});if(pendingDrain.value!==null){loop.
|
|
361
368
|
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: ${config.
|
|
362
369
|
projectRef}\uFF08${config.projectId}\uFF09
|
|
@@ -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-GQBF3GQH.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-F6PPBPY5.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,12 +1,12 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{BUILTIN_COMMANDS,GLOBAL_FLAGS,TASK_LOOP_ACTIONS,VALUE_FLAGS}from"./chunk-
|
|
3
|
+
import{BUILTIN_COMMANDS,GLOBAL_FLAGS,TASK_LOOP_ACTIONS,VALUE_FLAGS}from"./chunk-4ZREAAP4.js";import"./chunk-2LOT54OO.js";import{API_TOKEN,DOMAIN_NAMES,HELP_TOKEN,isDomainName}from"./chunk-QZBE4KC2.js";import"./chunk-QQRJLH6B.js";import{OUTPUT_FORMATS}from"./chunk-74BPZOKU.js";import"./chunk-UREA4ZIG.js";import"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";var EXTRA_TOP_LEVEL=[API_TOKEN,HELP_TOKEN,"completion","configure"];var COMPLETION_SHELLS=["bash","zsh","fish","powershell"];var TOP_LEVEL_FLAGS=["--help","--version","-p","--print","--profile","--mode","--permission-mode","--model","--allowed-tools","--disallowed-tools","--no-tui","--doctor"];var DOMAIN_GLOBAL_FLAGS=[...GLOBAL_FLAGS].filter(flag=>flag.startsWith("--"));function staticValues(flag,ctx){if(flag==="--output")return OUTPUT_FORMATS;if(flag==="--profile")return ctx.profileNames();return void 0}
|
|
4
4
|
function positionals(words,takesValue){const out=[];for(let i=0;i<words.length;i++){const word=words[i]??"";if(word==="--"){out.push(...words.slice(i+1));break}if(word.startsWith("-")){if(!word.includes("=")&&takesValue(word))i++;continue}out.push(word)}return out}function byPrefix(candidates,current){const seen=new Set;for(const candidate of candidates){if(candidate.startsWith(current))seen.add(candidate)}return[...seen]}function remainingFlags(flags,words){const used=new Set(words.filter(w=>w.
|
|
5
5
|
startsWith("--")).map(w=>w.split("=")[0]));return[...flags.filter(f=>f.repeatable===true||!used.has(f.name)).map(f=>f.name),...DOMAIN_GLOBAL_FLAGS.filter(f=>!used.has(f))]}async function complete(words,current,ctx){const previous=words[words.length-1];if(previous!==void 0&&previous.startsWith("--")&&!previous.includes("=")){const values=staticValues(previous,ctx);if(values!==void 0)return byPrefix(values,current)}const eq=current.indexOf("=");if(current.startsWith("--")&&eq>0){const flag=current.
|
|
6
6
|
slice(0,eq);const values=staticValues(flag,ctx);return values===void 0?[]:byPrefix(values.map(v=>`${flag}=${v}`),current)}const pos=positionals(words,flag=>VALUE_FLAGS.has(flag));const[first,second]=pos;if(first===void 0){if(current.startsWith("-"))return byPrefix([...TOP_LEVEL_FLAGS,...DOMAIN_GLOBAL_FLAGS],current);return byPrefix([...BUILTIN_COMMANDS,...DOMAIN_NAMES,...EXTRA_TOP_LEVEL],current)}if(first==="completion")return pos.length===1?byPrefix(COMPLETION_SHELLS,current):[];if(first==="con\
|
|
7
|
-
figure")return current.startsWith("-")?byPrefix(["--profile"],current):[];if(first===HELP_TOKEN)return pos.length===1?byPrefix([...DOMAIN_NAMES,API_TOKEN],current):[];if(first==="task-loop"){if(pos.length===1&&!current.startsWith("-"))return byPrefix(TASK_LOOP_ACTIONS,current);if(pos.length===2&&(second==="charter"||second==="skill")&&!current.startsWith("-")){return byPrefix(["push","pull"],current)}
|
|
8
|
-
subresources??[];if(second===void 0){if(current.startsWith("-"))return byPrefix(DOMAIN_GLOBAL_FLAGS,current);return byPrefix([...domain.operations.map(op=>op.name),...subresources.map(sub2=>sub2.name),HELP_TOKEN],current)}const sub=subresources.find(resource=>resource.name===second);let operation;if(sub!==void 0){const third=pos[2];if(third===void 0){if(current.startsWith("-"))return byPrefix(
|
|
9
|
-
sub.operations.find(op=>op.name===third)}else{operation=domain.operations.find(op=>op.name===second)}if(operation===void 0)return[];if(!current.startsWith("-"))return[];return byPrefix(remainingFlags(operation.flags,words),current)}function completionScript(shell){switch(shell){case"bash":return`# twp \u306E bash \u88DC\u5B8C\uFF08twp completion bash \u304C\u51FA\u529B\uFF09
|
|
7
|
+
figure")return current.startsWith("-")?byPrefix(["--profile"],current):[];if(first===HELP_TOKEN)return pos.length===1?byPrefix([...DOMAIN_NAMES,API_TOKEN],current):[];if(first==="task-loop"){if(pos.length===1&&!current.startsWith("-"))return byPrefix(TASK_LOOP_ACTIONS,current);if(pos.length===2&&(second==="charter"||second==="skill")&&!current.startsWith("-")){return byPrefix(["push","pull"],current)}if(pos.length===2&&second==="plan"&&!current.startsWith("-"))return byPrefix(["submit"],current);
|
|
8
|
+
return[]}if(!isDomainName(first))return[];const domain=await ctx.loadDomain(first);const subresources=domain.subresources??[];if(second===void 0){if(current.startsWith("-"))return byPrefix(DOMAIN_GLOBAL_FLAGS,current);return byPrefix([...domain.operations.map(op=>op.name),...subresources.map(sub2=>sub2.name),HELP_TOKEN],current)}const sub=subresources.find(resource=>resource.name===second);let operation;if(sub!==void 0){const third=pos[2];if(third===void 0){if(current.startsWith("-"))return byPrefix(
|
|
9
|
+
DOMAIN_GLOBAL_FLAGS,current);return byPrefix([...sub.operations.map(op=>op.name),HELP_TOKEN],current)}operation=sub.operations.find(op=>op.name===third)}else{operation=domain.operations.find(op=>op.name===second)}if(operation===void 0)return[];if(!current.startsWith("-"))return[];return byPrefix(remainingFlags(operation.flags,words),current)}function completionScript(shell){switch(shell){case"bash":return`# twp \u306E bash \u88DC\u5B8C\uFF08twp completion bash \u304C\u51FA\u529B\uFF09
|
|
10
10
|
# \u8AAD\u307F\u8FBC\u307F: eval "$(twp completion bash)" \uFF0F \u5E38\u7528: ~/.bashrc \u306B\u540C\u30581\u884C\u3092\u66F8\u304F
|
|
11
11
|
# \uFF08source <(...) \u306F macOS \u6A19\u6E96\u306E bash 3.2 \u3067\u8AAD\u307F\u8FBC\u307E\u308C\u306A\u3044\u306E\u3067\u4F7F\u308F\u306A\u3044\uFF09
|
|
12
12
|
# \u78BA\u5B9A\u6E08\u307F\u306E\u8A9E\u306F\u914D\u5217\u30B9\u30E9\u30A4\u30B9\u3067\u306F\u306A\u304F\u30EB\u30FC\u30D7\u3067\u96C6\u3081\u308B\uFF08macOS \u6A19\u6E96\u306E bash 3.2 \u3067\u3082\u540C\u3058\u306B\u52D5\u304B\u3059\u305F\u3081\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{LEGACY_STATE_DIR_NAME,STATE_DIR_NAME,loopStateDir}from"./chunk-
|
|
3
|
+
import{defaultIsLoopProcess,readLockOwner,sameTwpHome}from"./chunk-3WHC4FSG.js";import{LEGACY_STATE_DIR_NAME,STATE_DIR_NAME,loopStateDir}from"./chunk-2B7A3OY7.js";import"./chunk-AEJHDFXB.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 os from"os";import path from"path";var PIDLESS_GRACE_MS=6e4;function defaultStateDirs(env){const home=os.homedir();const dirs=[loopStateDir(env),path.join(home,STATE_DIR_NAME),path.join(home,LEGACY_STATE_DIR_NAME)].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==="ENO\
|
|
4
4
|
ENT"?null:code??err.message}}}function findLoopsUsingProfile(profileName,deps={}){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,
|
|
5
5
|
lockDir:stateDir,reason:`\u30ED\u30C3\u30AF\u306E\u7F6E\u304D\u5834\u6240\u3092\u8AAD\u3081\u307E\u305B\u3093\uFF08${err.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.
|
|
6
6
|
owner.pid}else{let ageMs=null;try{ageMs=now()-fs.statSync(lockDir).mtimeMs}catch{}if(ageMs!==null&&ageMs>=PIDLESS_GRACE_MS)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,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{parseWaitOptions,waitUntilTerminal}from"./chunk-WVCEKC7V.js";import{checkOutTarget}from"./chunk-
|
|
3
|
+
import{parseWaitOptions,waitUntilTerminal}from"./chunk-WVCEKC7V.js";import{checkOutTarget}from"./chunk-UVCIVMT6.js";import"./chunk-PNLP5SXG.js";import"./chunk-GFLGXGWE.js";import"./chunk-YXVN6OCH.js";import"./chunk-UFGJSWKU.js";import"./chunk-Q3B65OFC.js";import{contentTypeFor,inspectLocalFile}from"./chunk-I4TR55UF.js";import{checkUploadQuota}from"./chunk-V64CGX7V.js";import"./chunk-GY7KI5E5.js";import{repeatedValues}from"./chunk-RX5HWI4L.js";
|
|
4
4
|
import{LIST_FLAGS,LIST_PAGING_HELP,envelopePaging,nonEmpty,positiveInteger,readEnvelopeCursor,shellQuote}from"./chunk-MI6HVYR2.js";import{readBody}from"./chunk-6LSQCOCJ.js";import"./chunk-MYWDL3WX.js";import{collapsesInUrlPath,isSafePathSegment}from"./chunk-HVZUXLQ4.js";import{ApiError}from"./chunk-JA5A6UJ2.js";import"./chunk-H4CDX4TX.js";import{requireResolved,singleRef,withResolved}from"./chunk-PS5QFKHB.js";import"./chunk-II5RVJQN.js";import{acknowledgement,
|
|
5
5
|
isRecord,pick}from"./chunk-3ZRMMBP5.js";import{ApiRejectedError,ApiResponseError,NetworkError,UsageError,WaitTimeoutError}from"./chunk-VFPY2A23.js";import"./chunk-PECIBNFD.js";import"./chunk-XNLIEUAW.js";import"./chunk-J7QYPKVK.js";import"./chunk-4VZKNEVN.js";import"./chunk-RZVI6PMW.js";import"./chunk-QZBE4KC2.js";import"./chunk-QQRJLH6B.js";import"./chunk-74BPZOKU.js";import"./chunk-UREA4ZIG.js";import"./chunk-NHYMHCAT.js";
|
|
6
6
|
import"./chunk-VSJBJXZO.js";import crypto2 from"crypto";import fs2 from"fs";import path from"path";var SCOPE_PERSONAL="personal";var SCOPE_PROJECT="project";var UUID=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;var FORBIDDEN_NAME=/[/\\:*?"<>|]/;var NAME_MAX=255;var ROW_COLUMNS=["id","path","name","file_count","subfolder_count","parent_id","updated_at"];var TRASH_COLUMNS=["id","path","name","file_count","subfolder_count","parent_id","deleted_at"];function folderRows(raw){return raw.map(row=>{const id=row["id"];const name=row["name"];const parentId=row["parent_id"];if(typeof id!==
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{NO_PLAN_SESSION,PLAN_DIR_ENV,PLAN_TOKEN_ENV,checkPlan,fileSkillNames,formatCheck,openPlanSession,runPlanSubmit}from"./chunk-QHX5YFMM.js";import"./chunk-QEWCTKPV.js";import"./chunk-DXUFECE7.js";import"./chunk-AT432SCP.js";import"./chunk-GY7KI5E5.js";import"./chunk-II5RVJQN.js";import"./chunk-J7QYPKVK.js";import"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";export{NO_PLAN_SESSION,PLAN_DIR_ENV,PLAN_TOKEN_ENV,checkPlan,fileSkillNames,formatCheck,openPlanSession,runPlanSubmit};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{loadDomain}from"./chunk-
|
|
3
|
+
import{loadDomain}from"./chunk-PNLP5SXG.js";import"./chunk-VSJBJXZO.js";export{loadDomain};
|
|
@@ -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,checkOutTarget,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain}from"./chunk-
|
|
3
|
+
import{CURATED_PAGING_VOCABULARY,buildPrepareContext,checkOutTarget,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain}from"./chunk-UVCIVMT6.js";import"./chunk-PNLP5SXG.js";import"./chunk-GFLGXGWE.js";import"./chunk-YXVN6OCH.js";import"./chunk-UFGJSWKU.js";import"./chunk-Q3B65OFC.js";import"./chunk-RX5HWI4L.js";import"./chunk-MI6HVYR2.js";import"./chunk-MYWDL3WX.js";import"./chunk-HVZUXLQ4.js";import"./chunk-JA5A6UJ2.js";
|
|
4
4
|
import"./chunk-H4CDX4TX.js";import"./chunk-II5RVJQN.js";import"./chunk-3ZRMMBP5.js";import"./chunk-VFPY2A23.js";import"./chunk-PECIBNFD.js";import"./chunk-XNLIEUAW.js";import"./chunk-J7QYPKVK.js";import"./chunk-4VZKNEVN.js";import"./chunk-RZVI6PMW.js";import"./chunk-QZBE4KC2.js";import"./chunk-QQRJLH6B.js";import"./chunk-74BPZOKU.js";import"./chunk-UREA4ZIG.js";import"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";export{CURATED_PAGING_VOCABULARY,buildPrepareContext,checkOutTarget,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-NXWXTUU6.js";import"./chunk-2B7A3OY7.js";import"./chunk-AEJHDFXB.js";import"./chunk-N2UVRM3Z.js";import"./chunk-AT432SCP.js";import"./chunk-GY7KI5E5.js";import"./chunk-PMOUHEJQ.js";import"./chunk-J7QYPKVK.js";import"./chunk-5WGOHFAS.js";import"./chunk-RZVI6PMW.js";import"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";export{LoopSettingsApplier,PROMPT_KEYS,formatConfigHash,parseServerSettings,renderStepBudget};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{ServerSkillCatalog,expandServerSkills,formatSkillOrigins,parseSkillBody,parseSkillList,prepareSkillOverlay,referencedSkills,stripFrontmatter}from"./chunk-
|
|
3
|
+
import{ServerSkillCatalog,expandServerSkills,formatSkillOrigins,parseSkillBody,parseSkillList,prepareSkillOverlay,referencedSkills,stripFrontmatter}from"./chunk-PIB6MGG5.js";import"./chunk-YJZT3UD3.js";import"./chunk-A4LFG7MW.js";import"./chunk-VRBI2NPI.js";import"./chunk-AT432SCP.js";import"./chunk-GY7KI5E5.js";import"./chunk-VFPY2A23.js";import"./chunk-J7QYPKVK.js";import"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";export{ServerSkillCatalog,expandServerSkills,formatSkillOrigins,parseSkillBody,parseSkillList,prepareSkillOverlay,referencedSkills,stripFrontmatter};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{
|
|
3
|
+
import{detectAiClis,formatDetection,isDetectableAi,isSelectable}from"./chunk-T4QZO6RQ.js";import{PromptAbortedError,promptText}from"./chunk-L37NS5L2.js";import{localConfigPath,parseClaudeLauncher}from"./chunk-2B7A3OY7.js";import{AiConfig}from"./chunk-AEJHDFXB.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));
|