@tocca-systems/twp-cli 0.27.0 → 0.27.1
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 +4 -0
- package/dist/{agent-loop-AOTZLJP2.js → agent-loop-NF4ACJUG.js} +1 -1
- package/dist/{api-command-CR2JAAE4.js → api-command-DP5SNPPM.js} +1 -1
- package/dist/{app-WEMM2X7A.js → app-66TCBVZN.js} +1 -1
- package/dist/{chunk-QQR4OHGV.js → chunk-AFESUZTW.js} +1 -1
- package/dist/{chunk-RDJYKA3U.js → chunk-FH5MAPUC.js} +16 -14
- package/dist/cli.js +6 -6
- package/dist/{commands-EOKUE4FC.js → commands-2GTXVB7A.js} +2 -2
- package/dist/{commands-DDXAFNPT.js → commands-HSJFGNGS.js} +1 -1
- package/dist/{logout-guard-ICSEMN3J.js → logout-guard-HXXWNI3Z.js} +1 -1
- package/dist/{run-XCH5FTSU.js → run-FTMR5GXS.js} +1 -1
- package/dist/{setup-CDQ2CEUR.js → setup-CSUSF75E.js} +1 -1
- package/package.json +1 -1
package/CHANGELOG.public.md
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
`CHANGELOG.md` に残してあります。顧客向けの履歴は public 公開以降を対象とします。
|
|
12
12
|
-->
|
|
13
13
|
|
|
14
|
+
## 0.27.1
|
|
15
|
+
|
|
16
|
+
エージェントループのアカウント枠の観測で、取得が一時的に失敗しても直前の枠情報が画面に残るようになりました。表示される「○分前」は、枠を最後に実際に測った時刻を指すようになりました。
|
|
17
|
+
|
|
14
18
|
## 0.27.0
|
|
15
19
|
|
|
16
20
|
`twp task status create` / `update` / `delete` で、プロジェクトのタスクステータスを追加・変更・削除できるようになりました。作成したステータスは、その名前のまま `--status` に指定できます。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{stepToItem}from"./chunk-VCZVITWG.js";import{loadLocalConfig}from"./chunk-
|
|
3
|
+
import{stepToItem}from"./chunk-VCZVITWG.js";import{loadLocalConfig}from"./chunk-FH5MAPUC.js";import{loadAiConfig}from"./chunk-Y2XAWM2X.js";import"./chunk-N2UVRM3Z.js";import"./chunk-GY7KI5E5.js";import{LIST_FLAGS,LIST_PAGING_HELP,envelopePaging,nonEmpty,positiveInteger}from"./chunk-G4OO4M44.js";import{requireResolved,singleRef,withResolved}from"./chunk-ZN5EFDH7.js";import"./chunk-II5RVJQN.js";import{acknowledgement,isRecord,pick}from"./chunk-ZWVYVS2A.js";
|
|
4
4
|
import"./chunk-PMOUHEJQ.js";import"./chunk-5WGOHFAS.js";import"./chunk-RZVI6PMW.js";import{ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";var LABEL="\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u30EB\u30FC\u30D7\u306E\u30A2\u30A4\u30C6\u30E0";var STATUSES=["pending","processing","completed","failed"];var AI_TYPES=["claude","gemini","codex","copilot"];var EFFORTS=["low","medium","high","xhigh","max"];var PRIORITIES=["P0","P1","P2","P3"];var LIST_COLUMNS=["item_id","status","task_key","label","ai_type","ai_effort","runner_id","created_at"];var GET_COLUMNS=["item_id","status","task_key","label","prompt","ai_type","ai_model","ai_effort","runn\
|
|
5
5
|
er_id","attempt_count","reclaim_count","error_message","created_by_name","created_at","started_at","completed_at"];var HISTORY_COLUMNS=["item_id","status","task_key","skill","ai_type","runner_id","duration_ms","cost_usd","created_at"];var PROJECT_FLAG={name:"--project",summary:"\u30AD\u30E5\u30FC\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\uFF08\u30B3\u30FC\u30C9\u307E\u305F\u306F ID\u3002\u7701\u7565\u6642\u306F TWP_PROJECT / .twp/config.json / ~/.twp/config.json\uFF09",takesValue:true,placeholder:"\
|
|
6
6
|
<\u30B3\u30FC\u30C9|ID>"};var ITEM_FLAG={name:"--item",summary:"\u30A2\u30A4\u30C6\u30E0\u306E ID\uFF08item_id\uFF09\u3002\u4F4D\u7F6E\u5F15\u6570\u3068\u540C\u3058\u610F\u5473\uFF08\u4E21\u65B9\u6307\u5B9A\u306F\u30A8\u30E9\u30FC\uFF09",takesValue:true,placeholder:"<\u30A2\u30A4\u30C6\u30E0ID>"};var FORBIDDEN_CORE="\u30C6\u30CA\u30F3\u30C8\u306E\u7BA1\u7406\u8005\uFF08admin \u30ED\u30FC\u30EB\uFF09\u306E\u6A29\u9650\u304C\u5FC5\u8981\u3067\u3059\uFF08\u500B\u4EBA\u30AD\u30E5\u30FC\u3092\u9664\u304F\uFF09";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{CommandModelMissingError,MAX_REPORTED_VIOLATIONS,loadCommandModelDomain,loadCommandModelRoutes,validateBody,validateQuery}from"./chunk-NZ7WI4RZ.js";import{NO_REDACT_FLAG,NO_REDACT_NOTICE,exitCodeFor,fetchAllPages,reportError}from"./chunk-
|
|
3
|
+
import{CommandModelMissingError,MAX_REPORTED_VIOLATIONS,loadCommandModelDomain,loadCommandModelRoutes,validateBody,validateQuery}from"./chunk-NZ7WI4RZ.js";import{NO_REDACT_FLAG,NO_REDACT_NOTICE,exitCodeFor,fetchAllPages,reportError}from"./chunk-AFESUZTW.js";import{parseOperationArgs,repeatedValues}from"./chunk-IOGVQVGD.js";import{renderOutput}from"./chunk-5Q2CH4E7.js";import{redactSecretValues,withDebug}from"./chunk-YVAN3H5W.js";import{readBody}from"./chunk-HGTG5XQ7.js";
|
|
4
4
|
import{DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,envelopePaging,positiveInteger,readEnvelopeCursor,shellQuote}from"./chunk-G4OO4M44.js";import"./chunk-ECAVSNCJ.js";import"./chunk-GMBJTG6A.js";import{ApiError,TwpApiClient,appendQuery}from"./chunk-FTYJZFEK.js";import"./chunk-II5RVJQN.js";import{GLOBAL_OPTIONS_HELP}from"./chunk-TAN5I2DP.js";import{HELP_TOKEN}from"./chunk-SP27PYHC.js";import"./chunk-QQRJLH6B.js";import{AuthSession,NotLoggedInError,SessionExpiredError,
|
|
5
5
|
loadCredentials}from"./chunk-XNLIEUAW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{effectiveApiUrl,resolveConfiguredOutput,resolveProfile}from"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import{OUTPUT_FORMATS,resolveOutputFormat}from"./chunk-K2ONOH3L.js";import"./chunk-WVS4W5FY.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{evaluateQuery}from"./chunk-GDM2QUBL.js";import{EXIT_OK,NetworkError,UsageError}from"./chunk-7WSNIXTQ.js";
|
|
6
6
|
import"./chunk-VSJBJXZO.js";var MIN_SEGMENT_CHARS=3;var parsedCache=new WeakMap;function splitSegments(path){return path.split("/").filter(segment=>segment!=="")}function parseRoutes(routes){const cached=parsedCache.get(routes);if(cached!==void 0)return cached;const parsed=[];for(const[key,domain]of Object.entries(routes.routes)){const space=key.indexOf(" ");if(space<=0)continue;const template=key.slice(space+1);parsed.push({method:key.slice(0,space),template,domain,segments:splitSegments(template).map(segment=>/^\{[^/{}]+\}$/.
|
|
@@ -1212,7 +1212,7 @@ cwd()){const listed=await gitListFiles(cwd2);const raw=listed??await walkFiles(c
|
|
|
1212
1212
|
1;const after=/^[^\s]*/.exec(text.slice(cursor))?.[0]??"";return{query,start,end:cursor+after.length}}var TWP_SLASH_ROUTES={"/tasks":{domain:"task",operation:"list"},"/task":{domain:"task",operation:"get"},"/projects":{domain:"project",operation:"list"}};function isTwpSlashCommand(name){return Object.hasOwn(TWP_SLASH_ROUTES,name)}async function runTwpSlashCommand(name,args,deps){const route=TWP_SLASH_ROUTES[name];if(!Object.hasOwn(TWP_SLASH_ROUTES,name)||route===void 0){return{code:2,out:"",err:`\u4E0D\u660E\u306A\u30B3\u30DE\u30F3\u30C9: ${name}
|
|
1213
1213
|
`}}const parsed=parseArgv([route.domain,route.operation,...args]);if(parsed.command!=="domain"||parsed.domain!==route.domain){return{code:2,out:"",err:`${name}: \u3053\u306E\u5F15\u6570\u306F\u4F7F\u3048\u307E\u305B\u3093\uFF08${args.join(" ")}\uFF09
|
|
1214
1214
|
`}}if(parsed.unknown.length>0){return{code:2,out:"",err:`\u4E0D\u660E\u306A\u5F15\u6570: ${parsed.unknown.join(" ")}
|
|
1215
|
-
`}}let out="";let err="";const io={out:text=>void(out+=text),err:text=>void(err+=text),isTty:true};const globals={profile:parsed.profile??deps.profile,...parsed.output!==void 0?{output:parsed.output}:{},...parsed.query!==void 0?{query:parsed.query}:{},dryRun:parsed.dryRun,debug:parsed.debug,yes:parsed.yes,refresh:parsed.refresh};const{runDomain}=await import("./run-
|
|
1215
|
+
`}}let out="";let err="";const io={out:text=>void(out+=text),err:text=>void(err+=text),isTty:true};const globals={profile:parsed.profile??deps.profile,...parsed.output!==void 0?{output:parsed.output}:{},...parsed.query!==void 0?{query:parsed.query}:{},dryRun:parsed.dryRun,debug:parsed.debug,yes:parsed.yes,refresh:parsed.refresh};const{runDomain}=await import("./run-FTMR5GXS.js");try{const code=await runDomain({domain:route.domain,...parsed.operation!==void 0?{operation:parsed.operation}:
|
|
1216
1216
|
{},argv:parsed.domainArgv,help:parsed.domainHelp,globals,version:deps.version,io,...deps.fetchImpl!==void 0?{fetchImpl:deps.fetchImpl}:{}});return{code,out,err}}catch(e){return{code:1,out,err:`${err}${e.message}
|
|
1217
1217
|
`}}}var GIT_LOG_OUTPUT=["9f3c1a2 feat(ui): \u4E00\u89A7\u306E\u30D5\u30A3\u30EB\u30BF\u3092 URL \u30AF\u30A8\u30EA\u3068\u540C\u671F\u3059\u308B","4b8e0d7 fix(ui): \u4EEE\u60F3\u30B9\u30AF\u30ED\u30FC\u30EB\u306E\u884C\u9AD8\u3055\u3092\u5B9F\u6E2C\u5024\u306B\u5408\u308F\u305B\u308B","c15a99e refactor(api): \u4E00\u89A7\u53D6\u5F97\u306E\u30DA\u30FC\u30B8\u30F3\u30B0\u51E6\u7406\u3092\u5171\u901A\u5316\u3059\u308B","2d70f4b test: \u4E00\u89A7\u30D5\u30A3\u30EB\u30BF\u306E\u56DE\u5E30\u30C6\u30B9\u30C8\u3092\u8FFD\u52A0\u3059\u308B",
|
|
1218
1218
|
"a6e2b38 fix(api): \u7A7A\u306E\u691C\u7D22\u6761\u4EF6\u3067\u5168\u4EF6\u8FD4\u3089\u306A\u3044\u3088\u3046\u306B\u3059\u308B","7c40d51 chore(deps): \u958B\u767A\u4F9D\u5B58\u3092\u6700\u65B0\u3078\u66F4\u65B0\u3059\u308B","e83b1c6 docs: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u624B\u9806\u306B Node 22 \u306E\u524D\u63D0\u3092\u8FFD\u8A18\u3059\u308B","b91f7a4 fix(ui): \u30E2\u30FC\u30C0\u30EB\u306E\u91CD\u306A\u308A\u9806\u3092\u6307\u5B9A\u3059\u308B","5a2c8e0 perf(api): \u4E00\u89A7\u306E N+1 \u3092\u89E3\u6D88\u3059\u308B",
|
|
@@ -18,7 +18,7 @@ ${operationSection}${subSection}
|
|
|
18
18
|
${GLOBAL_OPTIONS_HELP}
|
|
19
19
|
`}function renderOperationHelp(op,path2){const sections=[`twp ${path2} ${op.name} \u2014 ${op.summary}`,"","\u4F7F\u3044\u65B9:",` ${op.usage}`];if(op.description!==void 0){sections.push("",...op.description.split("\n"))}if(op.destructive===true){sections.push("","\u26A0 \u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u304C\u5FC5\u8981\u3067\u3059\u3002")}const flags=withCommonFlags(op.flags);if(flags.length>0){sections.push("","\u30AA\u30D7\u30B7\u30E7\u30F3:",
|
|
20
20
|
alignedList(flags.map(flag=>[flag.takesValue?`${flag.name} ${flag.placeholder??"<\u5024>"}`:flag.name,flag.summary])))}sections.push("",GLOBAL_OPTIONS_HELP,"");return sections.join("\n")}function renderUnknownOperation(resource,path2,attempted){const names=[...resource.operations.map(op=>op.name),...subresourcesOf(resource).map(sub=>`${sub.name} <\u64CD\u4F5C>`)].join(" / ");return attempted===void 0?`twp ${path2} \u306B\u306F\u64CD\u4F5C\u306E\u6307\u5B9A\u304C\u5FC5\u8981\u3067\u3059\uFF08${names}\
|
|
21
|
-
\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`:`twp ${path2} \u306B\u300C${attempted}\u300D\u3068\u3044\u3046\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${names}\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`}var LOADERS={"agent-loop":async()=>(await import("./agent-loop-
|
|
21
|
+
\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`:`twp ${path2} \u306B\u300C${attempted}\u300D\u3068\u3044\u3046\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${names}\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`}var LOADERS={"agent-loop":async()=>(await import("./agent-loop-NF4ACJUG.js")).agentLoopDomain,attendance:async()=>(await import("./attendance-42XLURM7.js")).attendanceDomain,backlog:async()=>(await import("./backlog-I7GP3RXI.js")).backlogDomain,department:async()=>(await import("./department-6LOJILBM.js")).departmentDomain,"job-title":async()=>(await import("./job-title-WROIJ7IK.js")).jobTitleDomain,media:async()=>(await import("./media-4CAV5ZRC.js")).mediaDomain,position:async()=>(await import("./position-JI33IPTS.js")).
|
|
22
22
|
positionDomain,project:async()=>(await import("./project-DBNWB47J.js")).projectDomain,storage:async()=>(await import("./storage-ANKKJJJO.js")).storageDomain,task:async()=>(await import("./task-VDNZD2FU.js")).taskDomain,user:async()=>(await import("./user-JBHTU4TP.js")).userDomain};async function loadDomain(name){return LOADERS[name]()}var writeOut=text=>void process.stdout.write(text);var writeErr=text=>void process.stderr.write(text);function line(text){return text===""?"":text.endsWith("\n")?text:`${text}
|
|
23
23
|
`}function outputValue(operation,format,body){return format==="json"?operation.raw(body):operation.summarize(body)}function requiresYes(operation,yes){return operation.destructive===true&&!yes}function exitCodeForStatus(status){if(status===401)return EXIT_AUTH;if(status===429)return EXIT_API_SERVER;if(status>=400&&status<500)return EXIT_API_CLIENT;return EXIT_API_SERVER}function exitCodeFor(err){if(err instanceof UsageError)return EXIT_USAGE;if(err instanceof NotLoggedInError||err instanceof SessionExpiredError)
|
|
24
24
|
return EXIT_AUTH;if(err instanceof ApiError)return exitCodeForStatus(err.status);if(err instanceof ApiRejectedError)return EXIT_API_CLIENT;if(err instanceof ApiResponseError||err instanceof NetworkError)return EXIT_API_SERVER;if(err instanceof ResolveError){return err.status===null?EXIT_API_SERVER:exitCodeForStatus(err.status)}return EXIT_FAILURE}function safeText(text){return redactSecrets(stripTerminalControls(text))}function reportError(err,format,code,write=writeErr){const message=safeText(err instanceof
|
|
@@ -23,26 +23,28 @@ trim()!=="")sections.push(`--- preflight: ${r.id} ---
|
|
|
23
23
|
${r.stdout.trim()}`)}else{log(` \u26A0\uFE0F preflight: ${r.id} \u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${r.reason}\uFF09`);sections.push(`--- preflight: ${r.id} ---
|
|
24
24
|
\uFF08\u78BA\u8A8D\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${r.reason}\u3002\u3053\u306E\u524D\u63D0\u6761\u4EF6\u306F\u4E0D\u660E\u3067\u3059\uFF09`)}}if(sections.length===0)return"";return["\u3010\u74B0\u5883\u306E\u524D\u63D0\u6761\u4EF6\uFF08preflight\uFF09\u3011","\u4EE5\u4E0B\u306F\u3053\u306E\u30B5\u30A4\u30AF\u30EB\u306E\u5192\u982D\u3067\u78BA\u8A8D\u3057\u305F\u74B0\u5883\u60C5\u5831\u3067\u3059\u3002\u8A08\u753B\u3068\u5404\u30A2\u30A4\u30C6\u30E0\u306E\u5B9F\u884C\u3067\u8003\u616E\u3057\u3066\u304F\u3060\u3055\u3044\u3002",
|
|
25
25
|
"\u5931\u6557\u3057\u305F\u30D5\u30C3\u30AF\u304C\u3042\u3063\u3066\u3082\u30B5\u30A4\u30AF\u30EB\u306F\u7D99\u7D9A\u3057\u307E\u3059\u3002\u5FC5\u8981\u306A\u62C5\u4FDD\u304C\u53D6\u308C\u306A\u3044\u5834\u5408\u306F\u3001\u305D\u306E\u4E8B\u5B9F\u3092\u660E\u8A18\u3057\u3066\u304F\u3060\u3055\u3044\u3002","",sections.join("\n\n")].join("\n")}function firstLine(s){return(s.trim().split("\n")[0]??"").slice(0,200)}function formatHookWiring(prefetch,preflight){return`LOOP_HOOKS ${formatHookIds(prefetch,
|
|
26
|
-
preflight)}`}function formatHookIds(prefetch,preflight){const ids=hooks=>hooks.map(h=>h.id).join(",");return`prefetch=[${ids(prefetch)}] preflight=[${ids(preflight)}]`}var CAPACITY_SCHEMA="twp.capacity/v1";var CAPACITY_MAX_BYTES=8192;var CAPACITY_FORMATS=[CAPACITY_SCHEMA,"claude_auto_switch/v1"];var IDENTITY_MODES=["masked","none","full"];var DEFAULT_CAPACITY_PROBE={format:CAPACITY_SCHEMA,interval:
|
|
26
|
+
preflight)}`}function formatHookIds(prefetch,preflight){const ids=hooks=>hooks.map(h=>h.id).join(",");return`prefetch=[${ids(prefetch)}] preflight=[${ids(preflight)}]`}var CAPACITY_SCHEMA="twp.capacity/v1";var CAPACITY_MAX_BYTES=8192;var CAPACITY_FORMATS=[CAPACITY_SCHEMA,"claude_auto_switch/v1"];var IDENTITY_MODES=["masked","none","full"];var DEFAULT_CAPACITY_PROBE={format:CAPACITY_SCHEMA,interval:300,timeout:15,identity:"masked"};var LOCAL_HEAD=1;var LOCAL_TAIL=2;var DOMAIN_HEAD=2;var DOMAIN_TAIL=2;var COLLAPSED="***";function maskPart(value,head,tail){if(value.length<head+tail+1)return null;return`${value.slice(0,head)}${"*".repeat(value.length-head-tail)}${value.
|
|
27
27
|
slice(value.length-tail)}`}function maskEmail(raw){const value=raw.trim();const at=value.lastIndexOf("@");if(at<0)return maskPart(value,LOCAL_HEAD,LOCAL_TAIL)??COLLAPSED;const local=value.slice(0,at);const domain=value.slice(at+1);const maskedLocal=maskPart(local,LOCAL_HEAD,LOCAL_TAIL);const maskedDomain=maskPart(domain,DOMAIN_HEAD,DOMAIN_TAIL);if(maskedLocal===null||maskedDomain===null)return`${COLLAPSED}@${COLLAPSED}`;return`${maskedLocal}@${maskedDomain}`}function identityHash(raw){return`sha\
|
|
28
28
|
256:${createHash("sha256").update(raw.trim()).digest("hex").slice(0,12)}`}function applyIdentity(slot,raw,mode){if(mode==="none")return;if(typeof raw!=="string"||raw.trim()==="")return;slot.identity_masked=mode==="full"?raw.trim():maskEmail(raw);slot.identity_hash=identityHash(raw)}var CAS_METRIC_LABELS={five_hour:"5\u6642\u9593\u67A0",seven_day:"\u9031\u9593",weekly_fable:"\u9031\u9593(Fable)"};function isRecord(v){return typeof v==="object"&&v!==null&&!Array.isArray(v)}function num(v){return typeof v===
|
|
29
|
-
"number"&&Number.isFinite(v)?v:void 0}function str(v){return typeof v==="string"&&v.trim()!==""?v.trim():void 0}function epochToIso(v){const n=num(v);if(n===void 0||n<=0)return void 0;
|
|
30
|
-
isArray(
|
|
31
|
-
m["
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
29
|
+
"number"&&Number.isFinite(v)?v:void 0}function str(v){return typeof v==="string"&&v.trim()!==""?v.trim():void 0}function epochToIso(v){const n=num(v);if(n===void 0||n<=0)return void 0;const d=new Date(n*1e3);return Number.isNaN(d.getTime())?void 0:d.toISOString()}function toSlotState(raw,eligible){const s=str(raw);if(s==="needs_login")return"needs_login";if(eligible===false)return"excluded";if(s==="over_ceiling")return"excluded";if(s===void 0)return"unknown";return"usable"}function newestMeasuredAt(accounts){
|
|
30
|
+
if(!Array.isArray(accounts))return null;let newest=null;for(const entry of accounts){if(!isRecord(entry))continue;const at=num(entry["metrics_fetched_at"]);if(at===void 0||at<=0||epochToIso(at)===void 0)continue;if(newest===null||at>newest)newest=at}return newest}function adaptClaudeAutoSwitch(raw,identity){if(!isRecord(raw)||!Array.isArray(raw["accounts"]))return null;const slots=[];for(const entry of raw["accounts"]){if(!isRecord(entry))continue;const name=str(entry["name"]);if(name===void 0)continue;
|
|
31
|
+
const metrics=[];if(isRecord(entry["metrics"])){for(const[key,m]of Object.entries(entry["metrics"])){if(!isRecord(m))continue;const metric={key};const label=CAS_METRIC_LABELS[key];if(label!==void 0)metric.label=label;const utilization=num(m["utilization"]);if(utilization!==void 0)metric.utilization=utilization;const threshold=num(m["threshold"]);if(threshold!==void 0)metric.threshold=threshold;const ceiling=num(m["ceiling"]);if(ceiling!==void 0)metric.ceiling=ceiling;const resets=epochToIso(m["r\
|
|
32
|
+
esets_at"]);if(resets!==void 0)metric.resets_at=resets;metrics.push(metric)}}const slot={name,state:toSlotState(entry["state"],entry["eligible"]),metrics};const stateLabel=str(entry["state_label"]);if(stateLabel!==void 0)slot.state_label=stateLabel;if(typeof entry["eligible"]==="boolean")slot.eligible=entry["eligible"];if(isRecord(entry["relogin"])){const deadline=str(entry["relogin"]["deadline_iso"])??epochToIso(entry["relogin"]["deadline"]);if(deadline!==void 0)slot.relogin_deadline=deadline}applyIdentity(
|
|
33
|
+
slot,entry["email"],identity);slots.push(slot)}const report={schema:CAPACITY_SCHEMA,provider:"claude",slots};const generatedAt=epochToIso(newestMeasuredAt(raw["accounts"]))??epochToIso(raw["generated_at"]);if(generatedAt!==void 0)report.generated_at=generatedAt;const active=str(raw["active"]);if(active!==void 0)report.active_slot=active;return report}function adaptCanonical(raw,identity){if(!isRecord(raw))return null;if(str(raw["schema"])!==CAPACITY_SCHEMA)return null;const report={...raw};if(identity===
|
|
34
|
+
"none"&&Array.isArray(report.slots)){report.slots=report.slots.map(slot=>{const stripped={...slot};delete stripped.identity_masked;delete stripped.identity_hash;return stripped})}return report}function summarize(slots){const s={total:slots.length,usable:0,excluded:0,needs_login:0,unknown:0};for(const slot of slots){const state=isRecord(slot)?slot.state:void 0;if(state==="usable"||state==="excluded"||state==="needs_login")s[state]+=1;else s.unknown+=1}return s}function capacityError(reason){return JSON.
|
|
35
|
+
stringify({schema:CAPACITY_SCHEMA,error:"probe_failed",reason})}function encodeCapacity(report){const withSummary={...report};if(Array.isArray(withSummary.slots)&&withSummary.summary===void 0){withSummary.summary=summarize(withSummary.slots)}const full=JSON.stringify(withSummary);if(Buffer.byteLength(full,"utf8")<=CAPACITY_MAX_BYTES)return full;const compact={...withSummary,slots_omitted:true};delete compact.slots;const trimmed=JSON.stringify(compact);if(Buffer.byteLength(trimmed,"utf8")<=CAPACITY_MAX_BYTES)
|
|
36
|
+
return trimmed;return capacityError("payload_too_large")}function parseCapacityProbe(value){const warnings=[];if(value===void 0||value===null)return{probe:null,warnings};if(!isRecord(value)){return{probe:null,warnings:["capacity_probe \u306F\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u67A0\u306E\u89B3\u6E2C\u306F\u884C\u3044\u307E\u305B\u3093"]}}const rawCommand=value["command"];if(!Array.isArray(rawCommand)||rawCommand.length===0){return{probe:null,
|
|
37
|
+
warnings:["capacity_probe.command \u306F1\u3064\u4EE5\u4E0A\u306E\u6587\u5B57\u5217\u306E\u914D\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u67A0\u306E\u89B3\u6E2C\u306F\u884C\u3044\u307E\u305B\u3093"]}}for(const v of rawCommand){if(typeof v!=="string"||v.trim()===""){return{probe:null,warnings:["capacity_probe.command \u306E\u8981\u7D20\u306F\u7A7A\u3067\u306A\u3044\u6587\u5B57\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u67A0\u306E\u89B3\u6E2C\u306F\u884C\u3044\u307E\u305B\u3093"]}}}
|
|
37
38
|
let format=DEFAULT_CAPACITY_PROBE.format;const rawFormat=value["format"];if(rawFormat!==void 0&&rawFormat!==null){if(typeof rawFormat==="string"&&CAPACITY_FORMATS.includes(rawFormat.trim())){format=rawFormat.trim()}else{warnings.push(`capacity_probe.format \u306F ${CAPACITY_FORMATS.join(" / ")} \u306E\u3044\u305A\u308C\u304B\u3067\u3059\uFF08\u65E2\u5B9A '${DEFAULT_CAPACITY_PROBE.format}' \u3092\u4F7F\u3044\u307E\u3059\uFF09`)}}let identity=DEFAULT_CAPACITY_PROBE.identity;const rawIdentity=value["\
|
|
38
39
|
identity"];if(rawIdentity!==void 0&&rawIdentity!==null){if(typeof rawIdentity==="string"&&IDENTITY_MODES.includes(rawIdentity.trim())){identity=rawIdentity.trim()}else{warnings.push(`capacity_probe.identity \u306F ${IDENTITY_MODES.join(" / ")} \u306E\u3044\u305A\u308C\u304B\u3067\u3059\uFF08\u65E2\u5B9A '${DEFAULT_CAPACITY_PROBE.identity}' \u3092\u4F7F\u3044\u307E\u3059\uFF09`)}}const interval=intField(value["interval"],"interval",DEFAULT_CAPACITY_PROBE.interval,warnings);const timeout=intField(
|
|
39
40
|
value["timeout"],"timeout",DEFAULT_CAPACITY_PROBE.timeout,warnings,TIMEOUT_MAX_SEC);return{probe:{command:rawCommand.map(v=>v.trim()),format,interval,timeout,identity},warnings}}var TIMEOUT_MAX_SEC=60;function intField(value,key,fallback,warnings,max){if(value===void 0||value===null||value==="")return fallback;const n=typeof value==="number"?value:Number.parseInt(String(value),10);if(Number.isInteger(n)&&n>=1){if(max!==void 0&&n>max){warnings.push(`capacity_probe.${key} \u306F ${max} \u4EE5\u4E0B\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\
|
|
40
41
|
\uFF08${max} \u306B\u4E38\u3081\u307E\u3059\u3002heartbeat \u306E\u9001\u4FE1\u3092\u5F85\u305F\u305B\u308B\u6642\u9593\u3067\u3059\uFF09`);return max}return n}warnings.push(`capacity_probe.${key} \u306F1\u4EE5\u4E0A\u306E\u6574\u6570\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u65E2\u5B9A ${fallback} \u3092\u4F7F\u3044\u307E\u3059\uFF09`);return fallback}function classify(outcome){switch(outcome.failure){case"timeout":return"timeout";case"spawn":return"spawn_failed";case"empty":
|
|
41
|
-
return"empty_output";default:return"exit_status"}}async function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
return"empty_output";default:return"exit_status"}}function failed(reason){return{payload:capacityError(reason),ok:false}}async function probeCapacityOutcome(probe,cwd,log,env){const outcome=await runHook({id:"capacity_probe",command:probe.command,timeout:probe.timeout},cwd,env);if(!outcome.ok){const reason=classify(outcome);log(` \u26A0\uFE0F capacity_probe \u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${reason}: ${(outcome.reason??"\u7406\u7531\u4E0D\u660E").slice(0,200)}\uFF09\u3002\u7D9A\u884C\u3057\u307E\u3059`);return failed(reason)}let parsed;
|
|
43
|
+
try{parsed=JSON.parse(outcome.stdout)}catch{log(" \u26A0\uFE0F capacity_probe \u306E\u51FA\u529B\u3092 JSON \u3068\u3057\u3066\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u7D9A\u884C\u3057\u307E\u3059");return failed("invalid_json")}try{const report=probe.format==="claude_auto_switch/v1"?adaptClaudeAutoSwitch(parsed,probe.identity):adaptCanonical(parsed,probe.identity);if(report===null){log(` \u26A0\uFE0F capacity_probe \u306E\u51FA\u529B\u304C ${probe.format} \u306E\u60F3\u5B9A\u3068\u9055\u3044\u307E\u3059\u3002\
|
|
44
|
+
\u7D9A\u884C\u3057\u307E\u3059`);return failed("unexpected_shape")}const payload=encodeCapacity(report);const ok=report.error===void 0&&JSON.parse(payload).error===void 0;return{payload,ok}}catch{log(` \u26A0\uFE0F capacity_probe \u306E\u51FA\u529B\u3092 ${probe.format} \u3068\u3057\u3066\u5909\u63DB\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u7D9A\u884C\u3057\u307E\u3059`);return failed("unexpected_shape")}}var REUSE_LAST_SUCCESS_MS=30*60*1e3;var CapacityReporter=class{constructor(probe,cwd,log,env=process.
|
|
45
|
+
env,now=()=>Date.now()){this.probe=probe;this.cwd=cwd;this.log=log;this.env=env;this.now=now}probe;cwd;log;env;now;cached=null;lastSuccess=null;lastSuccessAt=0;lastProbedAt=0;pending=false;running=false;async refreshIfDue(){const at=this.now();if(this.cached!==null&&at-this.lastProbedAt<this.probe.interval*1e3)return;await this.refresh()}async refresh(){if(this.running)return;this.running=true;try{const outcome=await probeCapacityOutcome(this.probe,this.cwd,this.log,this.env);const at=this.now();
|
|
46
|
+
if(outcome.ok){this.lastSuccess=outcome.payload;this.lastSuccessAt=at}const reuse=!outcome.ok&&this.lastSuccess!==null&&at-this.lastSuccessAt<REUSE_LAST_SUCCESS_MS;this.cached=reuse?this.lastSuccess:outcome.payload;if(reuse){this.log(" \u76F4\u524D\u306B\u53D6\u5F97\u3067\u304D\u305F\u67A0\u60C5\u5831\u3092\u9001\u308A\u307E\u3059\uFF08\u4E00\u6642\u7684\u306A\u5931\u6557\u3068\u3057\u3066\u6271\u3044\u307E\u3059\uFF09")}this.lastProbedAt=this.now();this.pending=true}finally{this.running=false}}take(){
|
|
47
|
+
if(!this.pending||this.cached===null)return null;this.pending=false;return this.cached}rearm(){if(this.cached!==null)this.pending=true}};function evaluateOwnership(item,runnerId,runId){if(!item){return{verdict:"unknown",reason:"\u30A2\u30A4\u30C6\u30E0\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F"}}if(runnerId===""||runId===""){return{verdict:"unknown",reason:"\u81EA\u5206\u306E runner_id / run_id \u304C\u7A7A\u3067\u3059"}}const status=(item.status??"").trim();if(status===""){return{verdict:"unknown",reason:"\u5FDC\u7B54\u306B status \u304C\u3042\u308A\u307E\u305B\u3093"}}if(status!=="processing"){return{verdict:"\
|
|
46
48
|
lost",reason:`status=${status}\uFF08processing \u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF09`}}const itemRunner=(item.runner_id??"").trim();const itemRun=(item.run_id??"").trim();if(itemRunner===""||itemRun===""){return{verdict:"unknown",reason:"\u5FDC\u7B54\u306B runner_id / run_id \u304C\u3042\u308A\u307E\u305B\u3093"}}if(itemRunner!==runnerId){return{verdict:"lost",reason:`\u5225\u306E\u30E9\u30F3\u30CA\u30FC\u304C\u4FDD\u6301\u3057\u3066\u3044\u307E\u3059\uFF08runner=${itemRunner}\uFF09`}}
|
|
47
49
|
if(itemRun!==runId){return{verdict:"lost",reason:`\u540C\u3058\u6A5F\u4F53\u306E\u5225\u306E\u8D77\u52D5\u304C\u4FDD\u6301\u3057\u3066\u3044\u307E\u3059\uFF08run_id \u304C\u4E00\u81F4\u3057\u307E\u305B\u3093\uFF09`}}return{verdict:"held",reason:"processing \u304B\u3064 runner_id / run_id \u304C\u4E00\u81F4"}}var OWNERSHIP_CHECK_INTERVAL_SEC=60;var NO_OPERATIONS={exclusiveSkills:new Set,statusEndpoint:null,highRiskSkills:new Set,preflightHosts:[],releaseRecoverySkill:null,postSuccessEnqueue:new Map,contractSkills:new Set,zeroTargetGates:{},countHooks:new Map};var DEFAULT_STATUS_PATH="/api/release/list";var DEFAULT_STATUS_HEADER="X-API-Key";function stringArray(value,label,warnings){if(value===void 0||value===null)return[];if(!Array.isArray(value)){warnings.push(`operations.${label} \u306F\u914D\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u7121\u8996\u3057\u307E\u3059\uFF09`);
|
|
48
50
|
return[]}const out=[];for(const v of value){if(typeof v!=="string"||v.trim()===""){warnings.push(`operations.${label} \u306E\u8981\u7D20\u306F\u7A7A\u3067\u306A\u3044\u6587\u5B57\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u3053\u306E\u8981\u7D20\u306F\u7121\u8996\u3057\u307E\u3059\uFF09`);continue}out.push(v.trim())}return out}function stringMap(value,label,warnings){const out=new Map;if(value===void 0||value===null)return out;if(typeof value!=="object"||Array.isArray(value)){
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
3
3
|
const require = __twpCreateRequire(import.meta.url);
|
|
4
|
-
import{parseArgv}from"./chunk-YWGYRISN.js";import"./chunk-NAUH75MM.js";import{GLOBAL_OPTIONS_HELP}from"./chunk-TAN5I2DP.js";import"./chunk-SP27PYHC.js";import"./chunk-QQRJLH6B.js";import"./chunk-VSJBJXZO.js";var VERSION=true?"0.27.
|
|
4
|
+
import{parseArgv}from"./chunk-YWGYRISN.js";import"./chunk-NAUH75MM.js";import{GLOBAL_OPTIONS_HELP}from"./chunk-TAN5I2DP.js";import"./chunk-SP27PYHC.js";import"./chunk-QQRJLH6B.js";import"./chunk-VSJBJXZO.js";var VERSION=true?"0.27.1":"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
|
|
@@ -255,10 +255,10 @@ TUI \u5185:
|
|
|
255
255
|
`);process.exit(1)}ignoreEpipe(process.stdout);ignoreEpipe(process.stderr);if(process.env["TWP_AUTO_UPDATE_WORKER"]==="1"){const{runAutoUpdateWorker}=await import("./auto-update-worker-OBFGN6FY.js");await runAutoUpdateWorker().catch(()=>void 0);return}const args=parseArgv(process.argv.slice(2));if(args.command==="version"){process.stdout.write(`${VERSION}
|
|
256
256
|
`);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(" ")}
|
|
257
257
|
|
|
258
|
-
${HELP}`);process.exitCode=2;return}const autoUpdate=await import("./auto-update-CV2MM32C.js");autoUpdate.registerRunning();if(args.command==="task-loop"){process.env[autoUpdate.DISABLE_ENV]="1"}else if(args.command!=="update"){autoUpdate.onStartup(VERSION)}if(args.command==="domain"&&args.domain!==void 0){const{runDomain}=await import("./run-
|
|
259
|
-
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-
|
|
260
|
-
void 0?{output:args.output}:{},...args.query!==void 0?{query:args.query}:{},dryRun:args.dryRun,debug:args.debug,yes:args.yes},version:VERSION});return}if(args.command==="update"){const{runUpdate}=await import("./update-RLKK6N7U.js");process.exitCode=await runUpdate({...args.profile!==void 0?{profile:args.profile}:{},version:VERSION});return}if(args.command==="login"||args.command==="logout"||args.command==="whoami"){const{runLogin,runLogout,runWhoami}=await import("./commands-
|
|
261
|
-
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-
|
|
258
|
+
${HELP}`);process.exitCode=2;return}const autoUpdate=await import("./auto-update-CV2MM32C.js");autoUpdate.registerRunning();if(args.command==="task-loop"){process.env[autoUpdate.DISABLE_ENV]="1"}else if(args.command!=="update"){autoUpdate.onStartup(VERSION)}if(args.command==="domain"&&args.domain!==void 0){const{runDomain}=await import("./run-FTMR5GXS.js");process.exitCode=await runDomain({domain:args.domain,...args.operation!==void 0?{operation:args.operation}:{},argv:args.domainArgv,help:args.
|
|
259
|
+
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-DP5SNPPM.js");process.exitCode=await runApiCommand({argv:args.domainArgv,help:args.domainHelp,globals:{...args.profile!==void 0?{profile:args.profile}:{},...args.output!==
|
|
260
|
+
void 0?{output:args.output}:{},...args.query!==void 0?{query:args.query}:{},dryRun:args.dryRun,debug:args.debug,yes:args.yes},version:VERSION});return}if(args.command==="update"){const{runUpdate}=await import("./update-RLKK6N7U.js");process.exitCode=await runUpdate({...args.profile!==void 0?{profile:args.profile}:{},version:VERSION});return}if(args.command==="login"||args.command==="logout"||args.command==="whoami"){const{runLogin,runLogout,runWhoami}=await import("./commands-HSJFGNGS.js");
|
|
261
|
+
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-2GTXVB7A.js");process.exitCode=await runTaskLoop(
|
|
262
262
|
{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,
|
|
263
263
|
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-J4VX47WN.js");process.exitCode=await runOneShot({prompt:args.prompt??"",fromStdin:args.promptFromStdin,mode:args.mode??"dev",...args.permissionMode!==void 0?{permissionMode:args.permissionMode}:{},allowedTools:args.
|
|
264
|
-
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-
|
|
264
|
+
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-66TCBVZN.js");await startTui({mode:args.mode,permissionMode:args.permissionMode,allowedTools:args.allowedTools,disallowedTools:args.disallowedTools,model:args.model,profile:args.profile,noTui:args.noTui||!process.stdout.isTTY,doctor:args.doctor,version:VERSION})}await main();
|
|
@@ -2,7 +2,7 @@ import { createRequire as __twpCreateRequire } from 'node:module';
|
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
3
|
import{LoopSettingsApplier,renderStepBudget}from"./chunk-XAMHF5MK.js";import{EngineNotConfiguredError,NoopEngine,UnknownEngineError,aiUnavailableLabel,assertKnownEngine,failureHint,isAiUnavailable,needsHumanToRestoreAi}from"./chunk-ZOOEH7ZE.js";import{claudeConfigDir,resolveDetectDeps}from"./chunk-5PU5QU5U.js";import{REQUIRE_ZERO_STATUS,ScheduleApi,collectDue,gateStatus,nowInZone,parseCounts,promptSection}from"./chunk-VYDEUFGU.js";import{AgentLoopApi,describeError,filterByStatus,
|
|
4
4
|
isPermanent,pick,pickString}from"./chunk-BKZGBJWT.js";import{InstanceLock,buildLockOwner,defaultIsLoopProcess,writeLockOwner}from"./chunk-3WHC4FSG.js";import{duplicateTaskKeyDropReason,excludedKeyInArgs,extractPlanJson,parseOpsCount,parsePlanExcludeKeys,placeholderTaskKey,releaseDeployDropReason,stepToItem,zeroTargetDropReasons}from"./chunk-VCZVITWG.js";import{CapacityReporter,buildLoopConfig,describeOperations,evaluateOwnership,formatHookIds,formatHookWiring,localDate,loopStateDir,
|
|
5
|
-
runHook,runPrefetch,runPreflight}from"./chunk-
|
|
5
|
+
runHook,runPrefetch,runPreflight}from"./chunk-FH5MAPUC.js";import{exclusiveInflightEntries,formatExclusiveEntry,normalizeSkillName,skillOfItem,spawnSyncResolved}from"./chunk-Y2XAWM2X.js";import{killProcessTree}from"./chunk-N2UVRM3Z.js";import{PRIVATE_PROJECT_REF,isPrivateProjectId,isPrivateProjectRef,privateProjectId,projectFileKey}from"./chunk-GY7KI5E5.js";import{resolveProjectRef,uuidProjectIdPolicy}from"./chunk-GMBJTG6A.js";import{isTaskKey}from"./chunk-II5RVJQN.js";
|
|
6
6
|
import{AuthSession}from"./chunk-XNLIEUAW.js";import{joinFor}from"./chunk-PMOUHEJQ.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{compareVersionCores,parseVersionCore}from"./chunk-DXXFUNYN.js";import"./chunk-5WGOHFAS.js";import{effectiveApiUrl,resolveProfile}from"./chunk-NERYSBA4.js";import{twpHomeDir}from"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";import fs10 from"fs";import path8 from"path";import fs from"fs";import path from"path";var LoopLogger=class{constructor(runnerId,logFile,out=process.stdout,now=()=>new Date){this.runnerId=runnerId;this.out=out;this.now=now;if(logFile){fs.mkdirSync(path.dirname(logFile),{recursive:true});this.stream=fs.createWriteStream(logFile,{flags:"a"})}}runnerId;out;now;stream=null;log(message){const d=this.now();const ts=`${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;const line=`[${ts}] [${this.runnerId}] ${stripTerminalControls(
|
|
7
7
|
message)}
|
|
8
8
|
`;this.out.write(line);this.stream?.write(line)}separator(){this.log("=".repeat(60))}close(){this.stream?.end();this.stream=null}};function pad(n){return String(n).padStart(2,"0")}function rotateLogs(dir,retentionDays,now=Date.now()){if(retentionDays<=0)return;const cutoff=now-retentionDays*864e5;let entries;try{entries=fs.readdirSync(dir)}catch{return}for(const name of entries){if(!/^(agent-loop|task-loop|step|plan|schedule-enqueued)-.*\.(log|txt)$/.test(name))continue;const file=path.join(dir,
|
|
@@ -313,7 +313,7 @@ operations.preflightHosts;return new DispatchEngine(config.ai,log,{workspace:con
|
|
|
313
313
|
...extraHosts]}:{}})}function lockDir(config){return path8.join(config.stateDir,`task-loop-${projectFileKey(config.projectId)}.lock.d`)}async function runTaskLoop(opts){if(opts.action==="stop")return await stopLoop(opts);const profile=resolveProfile(opts.profile);let creds;try{creds=new AuthSession(profile.name,profile.apiUrl).loadOrThrow()}catch(err){process.stderr.write(`${err.message}
|
|
314
314
|
`);return 1}const apiUrl=effectiveApiUrl(profile,creds.api_url);const session=new AuthSession(profile.name,apiUrl);const projectRef=opts.project??process.env.TWP_PROJECT??"";if(projectRef===""){process.stderr.write("--project <\u30AD\u30FC|UUID> \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08TWP_PROJECT \u3067\u3082\u53EF\uFF09\n");return 2}const projectApi=new ProjectApi(apiUrl,session);let project;try{project=await projectApi.resolve(projectRef)}catch(err){process.stderr.write(`${err.
|
|
315
315
|
message}
|
|
316
|
-
`);return 1}const projectId=project.id;if(opts.action==="setup"){const{runSetup,parseAiList}=await import("./setup-
|
|
316
|
+
`);return 1}const projectId=project.id;if(opts.action==="setup"){const{runSetup,parseAiList}=await import("./setup-CSUSF75E.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(" / ")}
|
|
317
317
|
`);return 2}ais=parsed.ais}return runSetup({projectId,projectRef,projectName:project.name===project.id?projectRef:`${project.code} / ${project.name}`,apiUrl,yes:opts.yes===true,...ais!==void 0?{ais}:{},...opts.workspace!==void 0?{workspace:opts.workspace}:{},...opts.aiConfigFile!==void 0?{aiConfigFile:opts.aiConfigFile}:{},...opts.noAiConfigFile===true?{noAiConfigFile:true}:{},...opts.profile!==void 0?{profile:opts.profile}:{}})}if(opts.action==="charter"){if(opts.charterOp===void 0){process.stderr.
|
|
318
318
|
write("charter \u306B\u306F push \u304B pull \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\n");return 2}if(isPrivateProjectId(projectId)){process.stderr.write("\u500B\u4EBA\u30BF\u30B9\u30AF\u306E\u30AD\u30E5\u30FC\uFF08--project __private__\uFF09\u306B\u306F\u61B2\u7AE0\u306E\u8A2D\u5B9A\u304C\u3042\u308A\u307E\u305B\u3093\n");return 2}const{runCharterCommand}=await import("./charter-command-ULFOEZWE.js");return runCharterCommand({api:new AgentLoopApi({apiUrl,projectId,session})},{op:opts.
|
|
319
319
|
charterOp,file:opts.charterInput,out:opts.charterOutput,revision:opts.charterRevision,yes:opts.yes===true,projectRef,profile:opts.profile})}if(opts.action==="skill"){if(opts.skillOp===void 0){process.stderr.write("skill \u306B\u306F push \u304B pull \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\n");return 2}if(isPrivateProjectId(projectId)){process.stderr.write("\u500B\u4EBA\u30BF\u30B9\u30AF\u306E\u30AD\u30E5\u30FC\uFF08--project __private__\uFF09\u306B\u306F\u30B9\u30AD\u30EB\u5B9A\u7FA9\u306E\u8A2D\u5B9A\u304C\u3042\u308A\u307E\u305B\u3093\n");
|
|
@@ -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-HXXWNI3Z.js");const found=findLoopsUsingProfile(profile.name,options.logoutGuard);if(found.users.length>0||found.undetermined.length>0){writeErr(describeLogoutImpact(profile.name,found,options.force===true));if(options.force!==true)throw new LogoutRefusedError}const apiUrl=effectiveApiUrl(profile,creds.api_url);const revoked=await httpFetch(`${apiUrl}/api/v2/auth/logout`,{method:"POST",headers:{Accept:"applic\
|
|
54
54
|
ation/json",Authorization:`Bearer ${creds.token}`}}).then(res=>res.ok,()=>false);await deleteCredentials(profile.name);writeOut(`\u2705 \u30ED\u30B0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\uFF08\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB: ${profile.name} / \u30C8\u30FC\u30AF\u30F3: ${maskToken(creds.token)}\uFF09
|
|
55
55
|
`);if(!revoked){writeOut("\u26A0 \u30B5\u30FC\u30D0\u5074\u306E\u30C8\u30FC\u30AF\u30F3\u5931\u52B9\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08\u30AA\u30D5\u30E9\u30A4\u30F3\u7B49\uFF09\u3002TWP \u306E\u300C\u8A2D\u5B9A > CLI\u7AEF\u672B\u300D\u304B\u3089\u3082\u5931\u52B9\u3067\u304D\u307E\u3059\u3002\n")}})}async function runWhoami(options){return run(async()=>{const profile=resolveProfile(options.profile);const structured=options.output!==void 0||options.query!==void 0;let format=null;if(structured){
|
|
56
56
|
const{resolveOutputFormat,OUTPUT_FORMATS}=await import("./format-NMW6Y2E5.js");format=resolveOutputFormat({...options.output!==void 0?{flag:options.output}:{},isTty:process.stdout.isTTY===true});if(format===null){throw new UsageError(`--output \u306B\u300C${options.output??""}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,`\u6307\u5B9A\u3067\u304D\u308B\u306E\u306F ${OUTPUT_FORMATS.join(" / ")} \u3067\u3059`)}}const stored=loadCredentials(profile.name);const apiUrl=effectiveApiUrl(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{defaultIsLoopProcess,readLockOwner,sameTwpHome}from"./chunk-3WHC4FSG.js";import{loopStateDir}from"./chunk-
|
|
3
|
+
import{defaultIsLoopProcess,readLockOwner,sameTwpHome}from"./chunk-3WHC4FSG.js";import{loopStateDir}from"./chunk-FH5MAPUC.js";import"./chunk-Y2XAWM2X.js";import"./chunk-N2UVRM3Z.js";import"./chunk-GY7KI5E5.js";import"./chunk-PMOUHEJQ.js";import"./chunk-5WGOHFAS.js";import{twpHomeDir}from"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";import fs from"fs";import path from"path";var PIDLESS_GRACE_MS=6e4;function defaultStateDirs(env){const dirs=[loopStateDir(env),loopStateDir({})].map(d=>path.resolve(d));return[...new Set(dirs)]}function readPidFile(lockDir){try{const raw=fs.readFileSync(path.join(lockDir,"pid"),"utf8").split("\n")[0]?.trim()??"";const n=Number.parseInt(raw,10);return{pid:Number.isInteger(n)&&n>0?n:null,error:null}}catch(err){const code=err.code;return{pid:null,error:code==="ENOENT"?null:code??err.message}}}function findLoopsUsingProfile(profileName,deps={}){
|
|
4
4
|
const env=deps.env??process.env;const now=deps.now??Date.now;const isLoopProcess=deps.isLoopProcess??defaultIsLoopProcess;const myHome=twpHomeDir(env);const result={users:[],undetermined:[]};for(const stateDir of deps.stateDirs??defaultStateDirs(env)){let dirs;try{dirs=fs.readdirSync(stateDir).filter(d=>/^task-loop-.*\.lock\.d$/.test(d))}catch(err){if(err.code==="ENOENT")continue;result.undetermined.push({pid:null,lockDir:stateDir,reason:`\u30ED\u30C3\u30AF\u306E\u7F6E\u304D\u5834\u6240\u3092\u8AAD\u3081\u307E\u305B\u3093\uFF08${err.
|
|
5
5
|
code??err.message}\uFF09`});continue}for(const dir of dirs){const lockDir=path.join(stateDir,dir);const pidFile=readPidFile(lockDir);if(pidFile.error!==null){result.undetermined.push({pid:null,lockDir,reason:`pid \u3092\u8AAD\u3081\u307E\u305B\u3093\uFF08${pidFile.error}\uFF09`});continue}const owner=readLockOwner(lockDir);let pid=pidFile.pid;if(pid===null){if(owner.ok){pid=owner.owner.pid}else{let ageMs=null;try{ageMs=now()-fs.statSync(lockDir).mtimeMs}catch{}if(ageMs!==null&&ageMs>=PIDLESS_GRACE_MS)
|
|
6
6
|
continue;result.undetermined.push({pid:null,lockDir,reason:"\u30ED\u30C3\u30AF\u306B pid \u304C\u3042\u308A\u307E\u305B\u3093\uFF08\u8D77\u52D5\u76F4\u5F8C\u306E\u53EF\u80FD\u6027\uFF09"});continue}}if(!isLoopProcess(pid))continue;if(!owner.ok){result.undetermined.push({pid,lockDir,reason:owner.reason});continue}if(owner.owner.pid!==pid){result.undetermined.push({pid,lockDir,reason:`\u6240\u6709\u8005\u306E\u8A18\u9332\uFF08pid=${owner.owner.pid}\uFF09\u304C\u30ED\u30C3\u30AF\u306E pid \u3068\u4E00\u81F4\u3057\u307E\u305B\u3093`});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{CURATED_PAGING_VOCABULARY,buildPrepareContext,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain}from"./chunk-
|
|
3
|
+
import{CURATED_PAGING_VOCABULARY,buildPrepareContext,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain}from"./chunk-AFESUZTW.js";import"./chunk-IOGVQVGD.js";import"./chunk-5Q2CH4E7.js";import"./chunk-YVAN3H5W.js";import"./chunk-G4OO4M44.js";import"./chunk-ECAVSNCJ.js";import"./chunk-GMBJTG6A.js";import"./chunk-FTYJZFEK.js";import"./chunk-II5RVJQN.js";import"./chunk-TAN5I2DP.js";import"./chunk-SP27PYHC.js";
|
|
4
4
|
import"./chunk-QQRJLH6B.js";import"./chunk-XNLIEUAW.js";import"./chunk-J7QYPKVK.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import"./chunk-K2ONOH3L.js";import"./chunk-WVS4W5FY.js";import"./chunk-NHYMHCAT.js";import"./chunk-GDM2QUBL.js";import"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";export{CURATED_PAGING_VOCABULARY,buildPrepareContext,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{detectAiClis,formatDetection,isDetectableAi,isSelectable}from"./chunk-5PU5QU5U.js";import{PromptAbortedError,promptText}from"./chunk-L37NS5L2.js";import{localConfigPath,parseClaudeLauncher}from"./chunk-
|
|
3
|
+
import{detectAiClis,formatDetection,isDetectableAi,isSelectable}from"./chunk-5PU5QU5U.js";import{PromptAbortedError,promptText}from"./chunk-L37NS5L2.js";import{localConfigPath,parseClaudeLauncher}from"./chunk-FH5MAPUC.js";import{AiConfig}from"./chunk-Y2XAWM2X.js";import"./chunk-N2UVRM3Z.js";import"./chunk-GY7KI5E5.js";import"./chunk-PMOUHEJQ.js";import"./chunk-5WGOHFAS.js";import"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";
|
|
4
4
|
import"./chunk-VSJBJXZO.js";import fs from"fs";import path from"path";var RECOMMENDED_ROTATION={complex:["claude"],verify:["claude"],security:["claude"],support:["claude"],triage:["claude"],search:["claude"],simple:["claude"]};var RECOMMENDED_CHAINS={complex:["claude","codex"],verify:["claude","codex","copilot"],security:["claude","codex","copilot"],support:["claude","codex","copilot"],triage:["codex","gemini","copilot","claude"],search:["codex","gemini","copilot","claude"],simple:["codex","gemini","copilot","claude"]};var PREFERENCE=["claude","codex","gemini","co\
|
|
5
5
|
pilot"];function buildAiAssignment(selected){if(selected.length===0)throw new Error("\u9078\u629E\u3055\u308C\u305FAI\u304C\u7A7A\u3067\u3059");const fallbackOrder=PREFERENCE.filter(ai=>selected.includes(ai));for(const ai of selected)if(!fallbackOrder.includes(ai))fallbackOrder.push(ai);const chains={};const rotation={};for(const category of Object.keys(RECOMMENDED_CHAINS)){const filtered=(RECOMMENDED_CHAINS[category]??[]).filter(ai=>selected.includes(ai));const chain=filtered.length>0?filtered:
|
|
6
6
|
[...fallbackOrder];chains[category]=chain;const rot=(RECOMMENDED_ROTATION[category]??[]).filter(ai=>selected.includes(ai));const head=chain[0];rotation[category]=rot.length>0?rot:head===void 0?[...fallbackOrder]:[head]}return{primary_rotation:rotation,fallback_chains:chains}}var SETUP_EXIT_NO_CLI=3;var SETUP_EXIT_ABORTED=130;async function runSetup(opts){const env=opts.env??process.env;const rawOut=opts.out??(t=>void process.stdout.write(t));const rawErr=opts.err??(t=>void process.stderr.write(t));
|