@tocca-systems/twp-cli 0.16.0 → 0.17.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/command-model/_routes.json +1939 -0
- package/command-model/analysis.json +4 -4
- package/command-model/attendance.json +2 -2
- package/command-model/badge.json +4 -4
- package/command-model/company.json +19 -0
- package/command-model/department.json +10 -0
- package/command-model/dynamo-inquiry.json +41 -0
- package/command-model/equipment.json +5 -0
- package/command-model/holiday.json +19 -19
- package/command-model/index.json +25 -25
- package/command-model/invoice.json +25 -3
- package/command-model/meeting.json +29 -9
- package/command-model/my-task.json +1 -0
- package/command-model/note.json +34 -8
- package/command-model/notification.json +35 -0
- package/command-model/private-task.json +46 -1
- package/command-model/project-member.json +2 -1
- package/command-model/project-task-comment.json +1 -1
- package/command-model/project-task.json +153 -4
- package/command-model/project.json +90 -1
- package/command-model/prospect.json +24 -1
- package/command-model/report.json +62 -18
- package/command-model/sales.json +150 -150
- package/command-model/staff-kpi.json +47 -6
- package/command-model/staffing-plan.json +41 -0
- package/command-model/survey.json +38 -29
- package/command-model/user-group.json +2 -2
- package/command-model/user.json +2 -1
- package/command-model/wiki.json +29 -5
- package/command-model/workflow-instance.json +8 -3
- package/dist/{ai-dispatch-NTBNFFCS.js → ai-dispatch-27EZS2S3.js} +1 -1
- package/dist/api-command-UIL4WGMG.js +127 -0
- package/dist/{chunk-2SGDY6YP.js → chunk-2VISRLWS.js} +1 -1
- package/dist/{chunk-3WJHTPOZ.js → chunk-H3JTPDCJ.js} +7 -4
- package/dist/{chunk-BPMSIIOU.js → chunk-KXFT226N.js} +11 -11
- package/dist/{chunk-EZCMF4I3.js → chunk-SQSVA6AT.js} +3 -2
- package/dist/cli.js +4 -4
- package/dist/{commands-UGGBVOYU.js → commands-XYKBLMXT.js} +17 -14
- package/dist/{project-KIPSH5GP.js → project-OKTJ32JT.js} +1 -1
- package/dist/run-DWQEHR6I.js +4 -0
- package/dist/{setup-I4PA2TQW.js → setup-AJ56N6XO.js} +1 -1
- package/dist/{task-UK4QO26W.js → task-7K54BO5U.js} +1 -1
- package/package.json +1 -1
- package/dist/api-command-HGTPIEAP.js +0 -73
- package/dist/run-BJQLIPWN.js +0 -4
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{readBody}from"./chunk-QVXZEUKN.js";import{OUTPUT_FORMATS,evaluateQuery,exitCodeFor,fetchAllPages,redactSecretValues,renderOutput,reportError,resolveOutputFormat,withDebug}from"./chunk-KXFT226N.js";import"./chunk-WVS4W5FY.js";import{AuthSession,NotLoggedInError,SessionExpiredError,loadCredentials}from"./chunk-63LDNYGW.js";import{GLOBAL_OPTIONS_HELP,HELP_TOKEN}from"./chunk-FKIZ5ZJU.js";import{parseOperationArgs,repeatedValues}from"./chunk-O52CUEDO.js";import"./chunk-QQRJLH6B.js";
|
|
4
|
+
import"./chunk-7WEYBZSK.js";import{ApiError,TwpApiClient,appendQuery}from"./chunk-JKSXUBND.js";import"./chunk-II5RVJQN.js";import{effectiveApiUrl,resolveConfiguredOutput,resolveProfile}from"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,envelopePaging,positiveInteger,readEnvelopeCursor,shellQuote}from"./chunk-2VISRLWS.js";
|
|
5
|
+
import{EXIT_OK,NetworkError,UsageError}from"./chunk-M3GWY6NT.js";import"./chunk-5QCAIKFE.js";import"./chunk-VSJBJXZO.js";import{readFile}from"fs/promises";import{existsSync}from"fs";import{dirname,join,resolve}from"path";import{fileURLToPath}from"url";var DIR_NAME="command-model";var cachedDir;function commandModelDir(){if(cachedDir!==void 0)return cachedDir;let current=dirname(fileURLToPath(import.meta.url));for(let depth=0;depth<6;depth+=1){const candidate=join(current,DIR_NAME);if(existsSync(join(candidate,"index.json"))){cachedDir=candidate;return cachedDir}if(existsSync(join(current,"package.json")))break;const parent=resolve(
|
|
6
|
+
current,"..");if(parent===current)break;current=parent}cachedDir=null;return cachedDir}var CommandModelMissingError=class extends Error{constructor(detail){super(`\u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\uFF08${DIR_NAME}/\uFF09\u3092\u8AAD\u3081\u307E\u305B\u3093: ${detail}
|
|
7
|
+
\u958B\u767A\u6642\u306F \`npm run generate:command-model -- --spec <api.json>\` \u3067\u751F\u6210\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);this.name="CommandModelMissingError"}};var domainCache=new Map;var routesCache=null;async function readJson(file){const dir=commandModelDir();if(dir===null)throw new CommandModelMissingError("\u30D1\u30C3\u30B1\u30FC\u30B8\u306B\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u3042\u308A\u307E\u305B\u3093");const path=join(dir,file);try{return JSON.parse(await readFile(path,"utf8"))}catch(cause){throw new CommandModelMissingError(`${path} \u3092\u8AAD\u3081\u307E\u305B\u3093\uFF08${cause.message}\uFF09`)}}async function loadCommandModelRoutes(){if(routesCache!==null)return routesCache;const file=await readJson("_routes.json");if(typeof file?.routes!=="object"||file.routes===null||Array.isArray(file.routes)){throw new CommandModelMissingError("_routes.json \u306E\u5F62\u304C\u9055\u3044\u307E\u3059\uFF08routes \u304C\u8AAD\u3081\u307E\u305B\u3093\uFF09")}routesCache=file;return routesCache}async function loadCommandModelDomain(domain){const cached=domainCache.get(domain);if(cached!==void 0)return cached;
|
|
8
|
+
if(!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(domain)){throw new CommandModelMissingError(`\u30C9\u30E1\u30A4\u30F3\u540D\u3068\u3057\u3066\u4E0D\u6B63\u3067\u3059: ${domain}`)}const file=await readJson(`${domain}.json`);if(typeof file?.domain!=="string"||!Array.isArray(file?.operations)){throw new CommandModelMissingError(`${domain}.json \u306E\u5F62\u304C\u9055\u3044\u307E\u3059\uFF08domain / operations \u304C\u8AAD\u3081\u307E\u305B\u3093\uFF09`)}domainCache.set(domain,file);return file}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=>/^\{[^/{}]+\}$/.
|
|
9
|
+
test(segment)?null:segment)})}parsedCache.set(routes,parsed);return parsed}function matches(route,segments){if(route.segments.length!==segments.length)return false;return route.segments.every((literal,i)=>literal===null||literal===segments[i])}function compareSpecificity(a,b){const literals=route=>route.segments.filter(segment=>segment!==null).length;const diff=literals(b)-literals(a);if(diff!==0)return diff;for(let i=0;i<a.segments.length;i+=1){const aLiteral=a.segments[i]!==null;const bLiteral=b.
|
|
10
|
+
segments[i]!==null;if(aLiteral!==bLiteral)return aLiteral?-1:1}return 0}function lookupRoute(routes,method,path){const segments=splitSegments(path);const hits=parseRoutes(routes).filter(route=>matches(route,segments));const sameMethod=hits.filter(route=>route.method===method).sort(compareSpecificity);const best=sameMethod[0];if(best!==void 0)return{kind:"matched",domain:best.domain,template:best.template};if(hits.length>0){const[top]=[...hits].sort(compareSpecificity);const template=top.template;
|
|
11
|
+
const methods=[...new Set(hits.filter(route=>route.template===template).map(route=>route.method))].sort();return{kind:"method-mismatch",template,methods}}return{kind:"unknown"}}function pickOperation(operations,method,template){return operations.find(op=>op.method===method&&op.path===template)??null}async function suggestRoutes(routes,path,limit=5){const{default:fuzzysort}=await import("./fuzzysort-DFVKV4B4.js");const parsed=parseRoutes(routes);const templates=[...new Set(parsed.map(route=>route.
|
|
12
|
+
template))];const literals=new Set(parsed.flatMap(route=>route.segments.filter(segment=>segment!==null)));const kept=splitSegments(path).filter(segment=>literals.has(segment)||!/\d/.test(segment));for(let length=kept.length;length>=2;length-=1){const head=kept.slice(0,length-1);const last=kept[length-1];for(let cut=last.length;cut>=Math.min(MIN_SEGMENT_CHARS,last.length);cut-=1){const results=fuzzysort.go(`/${[...head,last.slice(0,cut)].join("/")}`,templates,{limit});if(results.length>0)return results.
|
|
13
|
+
map(result=>result.target)}}return[]}var MAX_REPORTED_VIOLATIONS=20;function isRecord(value){return typeof value==="object"&&value!==null&&!Array.isArray(value)}function typesOf(schema){const type=schema["type"];if(typeof type==="string")return[type];if(Array.isArray(type)&&type.every(t=>typeof t==="string"))return type;return null}var INTEGER_STRING=/^[+-]?\d+$/;var BOOLEAN_STRINGS=new Set(["0","1","true","false","yes","no","on","off"]);var NUMBER_STRING=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function matchesType(type,value){switch(type){case"\
|
|
14
|
+
null":return value===null;case"string":return typeof value==="string";case"integer":return typeof value==="number"&&Number.isInteger(value)||typeof value==="string"&&INTEGER_STRING.test(value);case"number":return typeof value==="number"&&Number.isFinite(value)||typeof value==="string"&&NUMBER_STRING.test(value);case"boolean":return typeof value==="boolean"||value===0||value===1||typeof value==="string"&&BOOLEAN_STRINGS.has(value.toLowerCase());case"array":case"object":return typeof value==="obje\
|
|
15
|
+
ct"&&value!==null;default:return true}}function describe(value){if(value===null)return"null";if(Array.isArray(value))return"\u914D\u5217";if(typeof value==="object")return"\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8";if(typeof value==="string")return`\u6587\u5B57\u5217\uFF08${[...value].length} \u6587\u5B57\uFF09`;return`${typeof value==="number"?"\u6570\u5024":typeof value==="boolean"?"\u771F\u507D\u5024":typeof value} ${String(value)}`}function numericValue(value){if(typeof value==="number")return value;
|
|
16
|
+
if(typeof value==="string"&&NUMBER_STRING.test(value))return Number(value);return null}var PHP_DELIMITED=/^([^A-Za-z0-9\\\s^])[\s\S]*\1[A-Za-z]*$/;function compilePattern(pattern){if(PHP_DELIMITED.test(pattern))return null;try{return new RegExp(pattern,"u")}catch{return null}}function walk(schema,value,at,out){if(!isRecord(schema))return;const types=typesOf(schema);if(types!==null&&!types.some(type=>matchesType(type,value))){out.push(`${at}: ${types.join(" / ")} \u3092\u671F\u5F85\u3057\u307E\u3057\u305F\u304C ${describe(
|
|
17
|
+
value)} \u3067\u3059`);return}if(value===null)return;const enumValues=schema["enum"];if(Array.isArray(enumValues)&&enumValues.length>0){const allowed=enumValues.filter(item=>item!==null).map(item=>String(item));if(!allowed.includes(String(value))){out.push(`${at}: ${allowed.join(" / ")} \u306E\u3044\u305A\u308C\u304B\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u53D7\u3051\u53D6\u3063\u305F\u5024: ${describe(value)}\uFF09`)}}if(typeof value==="string"){const length=[...value].length;
|
|
18
|
+
const max=schema["maxLength"];const min=schema["minLength"];if(typeof max==="number"&&length>max)out.push(`${at}: ${max} \u6587\u5B57\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${length} \u6587\u5B57\uFF09`);if(typeof min==="number"&&length<min)out.push(`${at}: ${min} \u6587\u5B57\u4EE5\u4E0A\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${length} \u6587\u5B57\uFF09`);const pattern=schema["pattern"];if(typeof pattern==="string"){const re=compilePattern(pattern);if(re!==null&&!re.
|
|
19
|
+
test(value))out.push(`${at}: \u5F62\u5F0F\u304C\u9055\u3044\u307E\u3059\uFF08${pattern}\uFF09`)}}const numeric=types?.some(type=>type==="integer"||type==="number")?numericValue(value):null;if(numeric!==null){const minimum=schema["minimum"];const maximum=schema["maximum"];if(typeof minimum==="number"&&numeric<minimum)out.push(`${at}: ${minimum} \u4EE5\u4E0A\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${numeric}\uFF09`);if(typeof maximum==="number"&&numeric>maximum)out.push(`${at}: ${maximum} \u4EE5\
|
|
20
|
+
\u4E0B\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${numeric}\uFF09`)}if(Array.isArray(value)){const maxItems=schema["maxItems"];const minItems=schema["minItems"];if(typeof maxItems==="number"&&value.length>maxItems)out.push(`${at}: \u8981\u7D20\u306F ${maxItems} \u4EF6\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${value.length} \u4EF6\uFF09`);if(typeof minItems==="number"&&value.length<minItems)out.push(`${at}: \u8981\u7D20\u306F ${minItems} \u4EF6\u4EE5\u4E0A\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${value.
|
|
21
|
+
length} \u4EF6\uFF09`);if(isRecord(schema["items"]))value.forEach((item,i)=>walk(schema["items"],item,`${at}[${i}]`,out));return}if(isRecord(value)){const required=schema["required"];if(Array.isArray(required)){for(const key of required){if(typeof key==="string"&&!Object.prototype.hasOwnProperty.call(value,key))out.push(`${at}.${key}: \u5FC5\u9808\u3067\u3059`)}}const properties=schema["properties"];if(isRecord(properties)){for(const[key,child]of Object.entries(properties)){if(Object.prototype.hasOwnProperty.
|
|
22
|
+
call(value,key))walk(child,value[key],`${at}.${key}`,out)}}}}function validateBody(schema,body){const out=[];walk(schema,body,"body",out);return out}function validateQuery(params,query){const out=[];for(const param of params){const has=Object.prototype.hasOwnProperty.call(query,param.name)&&query[param.name]!==void 0;if(!has){if(param.required)out.push(`query.${param.name}: \u5FC5\u9808\u3067\u3059`);continue}if(param.source!=="spec")continue;const declared=param.type;const types=typeof declared===
|
|
23
|
+
"string"?[declared]:Array.isArray(declared)?declared.filter(t=>typeof t==="string"):[];const checked=types.filter(type=>type==="integer"||type==="number"||type==="boolean");if(checked.length===0||types.includes("string"))continue;const raw=query[param.name];if(types.includes("null")&&raw==="")continue;if(!checked.some(type=>matchesType(type,raw))){out.push(`query.${param.name}: ${checked.join(" / ")} \u3092\u671F\u5F85\u3057\u307E\u3057\u305F\u304C ${describe(raw)} \u3067\u3059`)}}return out}var API_COMMAND_HELP=`twp api \u2014 API \u306E\u30D1\u30B9\u3092\u76F4\u63A5\u53E9\u304F\uFF08\u30A8\u30B9\u30B1\u30FC\u30D7\u30CF\u30C3\u30C1\uFF09
|
|
24
|
+
|
|
25
|
+
\u4F7F\u3044\u65B9:
|
|
26
|
+
twp api <\u30D1\u30B9> [\u30AA\u30D7\u30B7\u30E7\u30F3]
|
|
27
|
+
|
|
28
|
+
\u753B\u9762\u3067\u3067\u304D\u308B\u64CD\u4F5C\u306F\u3059\u3079\u3066 API \u306E\u30D1\u30B9\u3092\u6301\u3064\u306E\u3067\u3001\u30AD\u30E5\u30EC\u30FC\u30B7\u30E7\u30F3\u5C64\uFF08twp task / twp project \u2026\uFF09\u306B
|
|
29
|
+
\u51FA\u3066\u3044\u306A\u3044\u64CD\u4F5C\u3078\u306F\u3053\u3053\u304B\u3089\u5230\u9054\u3067\u304D\u307E\u3059\u3002\u30D1\u30B9\u306F API \u306E\u5951\u7D04\u305D\u306E\u3082\u306E\u306A\u306E\u3067\u3001
|
|
30
|
+
\u3053\u306E CLI \u306F\u30D1\u30B9\u306B\u3064\u3044\u3066\u5F8C\u65B9\u4E92\u63DB\u3092\u7D04\u675F\u3057\u307E\u305B\u3093\u3002
|
|
31
|
+
|
|
32
|
+
\u4F8B:
|
|
33
|
+
twp api /v2/projects?limit=10
|
|
34
|
+
twp api /v2/projects --query-param limit=10
|
|
35
|
+
twp api /v2/tasks/{taskId} --method PUT --body-file body.json --yes
|
|
36
|
+
twp api /v2/attendance/records --method POST --generate-cli-skeleton > in.json
|
|
37
|
+
twp api /v2/attendance/records --method POST --cli-input-json in.json --yes
|
|
38
|
+
|
|
39
|
+
\u30AA\u30D7\u30B7\u30E7\u30F3:
|
|
40
|
+
--method <\u30E1\u30BD\u30C3\u30C9> GET | POST | PUT | PATCH | DELETE\uFF08\u65E2\u5B9A GET\uFF09
|
|
41
|
+
--body-file <\u30D1\u30B9> \u30EA\u30AF\u30A8\u30B9\u30C8\u30DC\u30C7\u30A3\u306E JSON \u30D5\u30A1\u30A4\u30EB\uFF08- \u3067\u6A19\u6E96\u5165\u529B\uFF09
|
|
42
|
+
--cli-input-json <\u30D1\u30B9> \u5168\u5F15\u6570\u3092 JSON \u3067\u6E21\u3059\uFF08- \u3067\u6A19\u6E96\u5165\u529B\uFF09
|
|
43
|
+
\u500B\u5225\u30D5\u30E9\u30B0\u3068\u4F75\u7528\u3057\u305F\u3068\u304D\u306F**\u30D5\u30E9\u30B0\u304C\u52DD\u3061\u307E\u3059**
|
|
44
|
+
--generate-cli-skeleton --cli-input-json \u3078\u6E21\u3059\u5165\u529B\u3072\u306A\u5F62\u3092\u51FA\u529B\u3057\u3066\u7D42\u4E86\u3057\u307E\u3059
|
|
45
|
+
\uFF08\u9001\u4FE1\u3082\u30ED\u30B0\u30A4\u30F3\u3082\u884C\u3044\u307E\u305B\u3093\uFF09
|
|
46
|
+
--query-param <k=v> \u30AF\u30A8\u30EA\u5F15\u6570\u3002\u8907\u6570\u6307\u5B9A\u3067\u304D\u307E\u3059
|
|
47
|
+
\u5024\u306E\u4E2D\u306E = \u306F\u5207\u308A\u843D\u3068\u3057\u307E\u305B\u3093\uFF08\u6700\u521D\u306E = \u3067\u5206\u5272\uFF09
|
|
48
|
+
--no-redact \u5FDC\u7B54\u306E\u4F0F\u5B57\u5316\u3092\u89E3\u9664\u3057\u307E\u3059\uFF08\u65E2\u5B9A\u306F\u4F0F\u5B57\u5316\u3059\u308B\uFF09
|
|
49
|
+
\u9375\u306E\u767A\u884C\u306A\u3069\u3001\u4F0F\u305B\u308B\u3068\u5024\u304C\u4F7F\u3048\u306A\u3044\u64CD\u4F5C\u306E\u305F\u3081\u306E\u3082\u306E\u3067\u3059
|
|
50
|
+
|
|
51
|
+
\u51FA\u529B\u306E\u4F0F\u5B57\u5316:
|
|
52
|
+
\u5FDC\u7B54\u306B\u8F09\u308B token / secret / api_key / password \u306A\u3069\u306E\u5024\u306F\u3001\u65E2\u5B9A\u3067 ***\uFF08\u4F0F\u5B57\uFF09\u306B\u3057\u3066\u51FA\u3057\u307E\u3059\u3002
|
|
53
|
+
\u51FA\u529B\u306F\u7AEF\u672B\u3068\u30ED\u30B0\uFF08AI CLI \u306E\u30C8\u30E9\u30F3\u30B9\u30AF\u30EA\u30D7\u30C8\u3092\u542B\u3080\uFF09\u306B\u5E73\u6587\u3067\u6B8B\u308B\u305F\u3081\u3067\u3059\u3002
|
|
54
|
+
\u767A\u884C\u3057\u305F\u9375\u3092\u53D7\u3051\u53D6\u308B\u306A\u3069\u5024\u305D\u306E\u3082\u306E\u304C\u8981\u308B\u3068\u304D\u306F --no-redact \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044
|
|
55
|
+
\uFF08\u4ED8\u3051\u305F\u3053\u3068\u306F stderr \u30781\u884C\u51FA\u307E\u3059\uFF09\u3002
|
|
56
|
+
|
|
57
|
+
\u66F8\u304D\u8FBC\u307F\u306E\u6271\u3044:
|
|
58
|
+
GET \u4EE5\u5916\u306F --yes \u304C\u5FC5\u8981\u3067\u3059\u3002\u751F\u30D1\u30B9\u306F\u4EFB\u610F\u306E\u66F8\u304D\u8FBC\u307F\u3078\u5230\u9054\u3067\u304D\u308B\u305F\u3081\u3001
|
|
59
|
+
\u300C\u8AAD\u307F\u53D6\u308A\u4EE5\u5916\u306F\u3059\u3079\u3066\u78BA\u8A8D\u3092\u8981\u3059\u308B\u300D\u306B\u5012\u3057\u3066\u3044\u307E\u3059\u3002
|
|
60
|
+
\u9001\u308B\u5185\u5BB9\u306F --dry-run \u3067\u5148\u306B\u78BA\u8A8D\u3067\u304D\u307E\u3059\uFF08--dry-run \u306F\u9001\u3089\u306A\u3044\u306E\u3067 --yes \u306F\u8981\u308A\u307E\u305B\u3093\uFF09\u3002
|
|
61
|
+
\u5B9F\u884C\u306E\u524D\u306B\u63A5\u7D9A\u5148\uFF08\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB\u540D\u3068 URL\uFF09\u3092 stderr \u3078\u51FA\u3057\u307E\u3059\u3002
|
|
62
|
+
|
|
63
|
+
\u9001\u4FE1\u524D\u306E\u691C\u8A3C:
|
|
64
|
+
\u30D1\u30B9\u304C\u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\uFF08\u540C\u68B1\u306E API \u5B9A\u7FA9\uFF09\u306B\u8F09\u3063\u3066\u3044\u308C\u3070\u3001\u9001\u308B\u524D\u306B\u30DC\u30C7\u30A3\u3068\u30AF\u30A8\u30EA\u3092\u691C\u8A3C\u3057\u307E\u3059\u3002
|
|
65
|
+
\u5FC5\u9808\u9805\u76EE\u306E\u6B20\u843D\u30FB\u578B\u30FB\u6587\u5B57\u6570\u30FB\u9078\u629E\u80A2\u306E\u9055\u3044\u306F\u3001\u30B5\u30FC\u30D0\u3078\u9001\u3089\u305A\u306B\u7D42\u4E86\u30B3\u30FC\u30C9 2 \u3067\u6B62\u307E\u308A\u307E\u3059\u3002
|
|
66
|
+
\u5B9A\u7FA9\u306F\u30B5\u30FC\u30D0\u306E\u691C\u8A3C\u898F\u5247\u304B\u3089\u63A8\u5B9A\u3057\u305F\u3082\u306E\u306A\u306E\u3067\u3001\u30B5\u30FC\u30D0\u304C\u53D7\u3051\u308B\u306F\u305A\u306E\u5165\u529B\u304C\u62D2\u307E\u308C\u305F\u3068\u304D\u306F
|
|
67
|
+
--no-validate \u3067\u691C\u8A3C\u3092\u5916\u3057\u3066\u9001\u308C\u307E\u3059\uFF08\u5916\u3057\u305F\u3053\u3068\u306F stderr \u30781\u884C\u51FA\u307E\u3059\uFF09\u3002
|
|
68
|
+
--no-validate \u9001\u4FE1\u524D\u306E\u30B9\u30AD\u30FC\u30DE\u691C\u8A3C\u3092\u884C\u3044\u307E\u305B\u3093
|
|
69
|
+
|
|
70
|
+
\u81EA\u52D5\u30DA\u30FC\u30B8\u30F3\u30B0:
|
|
71
|
+
\u4E00\u89A7\u306E GET \u306F\u3001\u65E2\u5B9A\u3067\u6700\u5F8C\u306E\u30DA\u30FC\u30B8\u307E\u3067\u8FBF\u3063\u30661\u3064\u306E\u5FDC\u7B54\u306B\u307E\u3068\u3081\u307E\u3059\uFF08\u5224\u5B9A\u306F has_more \u3068
|
|
72
|
+
next_cursor \u3060\u3051\u3067\u3001total \u306F\u8AAD\u307F\u307E\u305B\u3093\uFF09\u3002\u8FBF\u3063\u305F\u30DA\u30FC\u30B8\u6570\u3068\u4EF6\u6570\u306F stderr \u3078\u51FA\u307E\u3059\u3002
|
|
73
|
+
--max-items <\u4EF6\u6570> \u8FBF\u308B\u4E0A\u9650\u4EF6\u6570\uFF08\u65E2\u5B9A ${DEFAULT_MAX_ITEMS}\uFF09\u3002\u4E0A\u9650\u306B\u9054\u3057\u305F\u3089\u3001\u5168\u4EF6\u3067\u306F\u306A\u3044\u3053\u3068\u3092
|
|
74
|
+
\u660E\u793A\u3057\u3066\u6B62\u307E\u308A\u3001\u90E8\u5206\u7684\u306A\u7D50\u679C\u306F\u51FA\u3057\u307E\u305B\u3093\uFF08\u518D\u958B\u7528\u306E\u30AB\u30FC\u30BD\u30EB\u306F stderr \u306B\u51FA\u307E\u3059\uFF09
|
|
75
|
+
--starting-token <\u30AB\u30FC\u30BD\u30EB> \u3053\u306E\u30AB\u30FC\u30BD\u30EB\uFF08\u524D\u56DE\u306E next_cursor\uFF09\u304B\u3089\u53D6\u5F97\u3092\u59CB\u3081\u307E\u3059
|
|
76
|
+
--no-paginate 1\u30DA\u30FC\u30B8\u3060\u3051\u53D6\u5F97\u3057\u307E\u3059\uFF08\u7D9A\u304D\u304C\u3042\u308C\u3070\u3001\u305D\u306E\u53D6\u308A\u65B9\u3092 stderr \u3078\u51FA\u3057\u307E\u3059\uFF09
|
|
77
|
+
|
|
78
|
+
\u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\u306B\u7121\u3044\u30D1\u30B9:
|
|
79
|
+
\u65B0\u3057\u304F\u751F\u3048\u305F\u30EB\u30FC\u30C8\u3067\u3082\u9001\u308C\u307E\u3059\u3002\u305D\u306E\u5834\u5408\u306F\u691C\u8A3C\u3068\u81EA\u52D5\u30DA\u30FC\u30B8\u30F3\u30B0\u304C\u52B9\u304B\u306A\u3044\u3053\u3068\u3092 stderr \u3078\u51FA\u3057\u3001
|
|
80
|
+
\u8FD1\u3044\u30D1\u30B9\u304C\u3042\u308C\u3070\u4E26\u3079\u307E\u3059\u3002\u4E00\u89A7\u306E\u7D9A\u304D\u306F\u5FDC\u7B54\u306E next_cursor \u3092 --starting-token \u306B\u6E21\u3057\u3066\u8FBF\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
81
|
+
|
|
82
|
+
${GLOBAL_OPTIONS_HELP}
|
|
83
|
+
`;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}
|
|
84
|
+
`}var API_METHODS=["GET","POST","PUT","PATCH","DELETE"];var API_FLAGS=[{name:"--method",summary:`HTTP \u30E1\u30BD\u30C3\u30C9\uFF08${API_METHODS.join(" / ")}\u30FB\u65E2\u5B9A GET\uFF09`,takesValue:true,placeholder:"<\u30E1\u30BD\u30C3\u30C9>"},{name:"--body-file",summary:"\u30EA\u30AF\u30A8\u30B9\u30C8\u30DC\u30C7\u30A3\u306E JSON \u30D5\u30A1\u30A4\u30EB\uFF08- \u3067\u6A19\u6E96\u5165\u529B\uFF09",takesValue:true,placeholder:"<\u30D1\u30B9>"},{name:"--cli-input-json",summary:"\u5168\u5F15\u6570\u3092 JSON \u3067\u6E21\u3059\uFF08-\
|
|
85
|
+
\u3067\u6A19\u6E96\u5165\u529B\uFF09",takesValue:true,placeholder:"<\u30D1\u30B9>"},{name:"--generate-cli-skeleton",summary:"--cli-input-json \u3078\u6E21\u3059\u5165\u529B\u3072\u306A\u5F62\u3092\u51FA\u529B\u3057\u3066\u7D42\u4E86\u3059\u308B",takesValue:false},{name:"--query-param",summary:"\u30AF\u30A8\u30EA\u5F15\u6570\uFF08k=v\u30FB\u8907\u6570\u6307\u5B9A\u53EF\uFF09",takesValue:true,placeholder:"<k=v>",repeatable:true},{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",
|
|
86
|
+
takesValue:false},{name:"--max-items",summary:`\u81EA\u52D5\u30DA\u30FC\u30B8\u30F3\u30B0\u306E\u4E0A\u9650\u4EF6\u6570\uFF08\u65E2\u5B9A ${DEFAULT_MAX_ITEMS}\u30FB\u8D85\u3048\u305F\u3089\u5168\u4EF6\u3067\u306F\u306A\u3044\u3068\u660E\u793A\u3057\u3066\u6B62\u307E\u308B\uFF09`,takesValue:true,placeholder:"<\u4EF6\u6570>"},{name:"--starting-token",summary:"\u3053\u306E\u30AB\u30FC\u30BD\u30EB\uFF08\u524D\u56DE\u306E next_cursor\uFF09\u304B\u3089\u53D6\u5F97\u3092\u59CB\u3081\u308B",takesValue:true,
|
|
87
|
+
placeholder:"<\u30AB\u30FC\u30BD\u30EB>"},{name:"--no-paginate",summary:"\u81EA\u52D5\u30DA\u30FC\u30B8\u30F3\u30B0\u3092\u305B\u305A1\u30DA\u30FC\u30B8\u3060\u3051\u53D6\u5F97\u3059\u308B",takesValue:false},{name:"--no-validate",summary:"\u9001\u4FE1\u524D\u306E\u30B9\u30AD\u30FC\u30DE\u691C\u8A3C\u3092\u884C\u308F\u306A\u3044\uFF08\u691C\u8A3C\u304C\u8AA4\u3063\u3066\u62D2\u3080\u3068\u304D\u7528\uFF09",takesValue:false}];var API_PAGING_VOCABULARY={mode:"\u81EA\u52D5\u30DA\u30FC\u30B8\u30F3\u30B0",
|
|
88
|
+
resumeFlag:"--starting-token",capAdvice:"--query-param limit=<\u4EF6\u6570> \u30671\u30DA\u30FC\u30B8\u306E\u4EF6\u6570\u3092\u5897\u3084\u3057\u3066\u5F80\u5FA9\u3092\u6E1B\u3089\u3059\u304B\u3001--max-items \u3092\u4E0A\u3052\u3066\u304F\u3060\u3055\u3044\u3002"};var ENVELOPE_ITEMS_KEY="items";var CURSOR_PARAM="cursor";var SUGGESTION_LIMIT=5;var MAX_BODY_CHARS=1e6;function normalizeApiPath(raw){const trimmed=raw.trim();if(trimmed==="")throw new UsageError("\u30D1\u30B9\u304C\u7A7A\u3067\u3059",
|
|
89
|
+
"\u4F8B: twp api /v2/projects");if(/^https?:\/\//i.test(trimmed)){throw new UsageError(`\u30D1\u30B9\u306B URL \u306F\u6E21\u305B\u307E\u305B\u3093: ${trimmed}`,"\u63A5\u7D9A\u5148\u306F\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB\u304C\u6C7A\u3081\u307E\u3059\u3002\u30D1\u30B9\u3060\u3051\u3092\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u4F8B: /v2/projects\uFF09\u3002")}const hashIndex=trimmed.indexOf("#");const withoutHash=hashIndex===-1?trimmed:trimmed.slice(0,hashIndex);const queryIndex=withoutHash.
|
|
90
|
+
indexOf("?");const pathPart=queryIndex===-1?withoutHash:withoutHash.slice(0,queryIndex);const queryPart=queryIndex===-1?void 0:withoutHash.slice(queryIndex+1);const withSlash=pathPart.startsWith("/")?pathPart:`/${pathPart}`;const path=withSlash.toLowerCase().startsWith("/api/")?withSlash:`/api${withSlash}`;return{path,query:queryPart===void 0||queryPart===""?void 0:queryPart}}function parseMethod(raw){if(raw===void 0)return"GET";const upper=raw.trim().toUpperCase();if(API_METHODS.includes(upper))
|
|
91
|
+
return upper;throw new UsageError(`--method \u306B\u300C${raw}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,`\u6307\u5B9A\u3067\u304D\u308B\u306E\u306F ${API_METHODS.join(" / ")} \u3067\u3059\u3002`)}function parseQueryParams(values){const out={};for(const raw of values){const index=raw.indexOf("=");if(index<=0){throw new UsageError(`--query-param \u306F k=v \u306E\u5F62\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044: ${raw}`,"\u4F8B: --query-param limit=10 --query-param keyword=\u4F1A\u8B70")}
|
|
92
|
+
const key=raw.slice(0,index);if(Object.prototype.hasOwnProperty.call(out,key)){throw new UsageError(`--query-param ${key} \u304C\u8907\u6570\u56DE\u6307\u5B9A\u3055\u308C\u3066\u3044\u307E\u3059`)}out[key]=raw.slice(index+1)}return out}function parseQueryString(raw){if(raw===void 0)return{};const out={};for(const[key,value]of new URLSearchParams(raw))out[key]=value;return out}function buildSkeleton(method,path,query){const skeleton={method,path};const queryEntries=Object.entries(query);skeleton.
|
|
93
|
+
query=queryEntries.length>0?Object.fromEntries(queryEntries.map(([key,value])=>[key,String(value??"")])):{};if(method!=="GET")skeleton.body={};return skeleton}function parseCliInput(text){let parsed;try{parsed=JSON.parse(text)}catch(err){throw new UsageError(`--cli-input-json \u306E JSON \u3092\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093: ${err.message}`)}if(parsed===null||typeof parsed!=="object"||Array.isArray(parsed)){throw new UsageError("--cli-input-json \u306B\u306F\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3092\u6E21\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
94
|
+
'\u4F8B: {"method":"POST","path":"/v2/...","body":{}}')}const known=new Set(["method","path","query","body"]);const unknown=Object.keys(parsed).filter(key=>!known.has(key));if(unknown.length>0){throw new UsageError(`--cli-input-json \u306B\u77E5\u3089\u306A\u3044\u30AD\u30FC\u304C\u3042\u308A\u307E\u3059: ${unknown.join(" / ")}`,`\u4F7F\u3048\u308B\u306E\u306F ${[...known].join(" / ")} \u3067\u3059\u3002`)}const input=parsed;for(const key of["method","path"]){const value=input[key];if(value!==void 0&&
|
|
95
|
+
typeof value!=="string"){throw new UsageError(`--cli-input-json \u306E ${key} \u306F\u6587\u5B57\u5217\u3067\u6E21\u3057\u3066\u304F\u3060\u3055\u3044`)}}if(input.query!==void 0){if(input.query===null||typeof input.query!=="object"||Array.isArray(input.query)){throw new UsageError("--cli-input-json \u306E query \u306F\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3067\u6E21\u3057\u3066\u304F\u3060\u3055\u3044")}for(const[key,value]of Object.entries(input.query)){if(typeof value!=="string"&&typeof value!==
|
|
96
|
+
"number"&&typeof value!=="boolean"){throw new UsageError(`--cli-input-json \u306E query.${key} \u306F\u6587\u5B57\u5217\u30FB\u6570\u5024\u30FB\u771F\u507D\u5024\u3067\u6E21\u3057\u3066\u304F\u3060\u3055\u3044`)}}}return input}async function runApiCommand(options){const{globals}=options;let format=null;try{const profile=resolveProfile(globals.profile);format=resolveOutputFormat({...globals.output!==void 0?{flag:globals.output}:{},...(()=>{const configured=resolveConfiguredOutput(profile.name);return configured!==
|
|
97
|
+
void 0?{configured}:{}})(),isTty:process.stdout.isTTY===true});if(format===null){throw new UsageError(`--output \u306B\u300C${globals.output??""}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,`\u6307\u5B9A\u3067\u304D\u308B\u306E\u306F ${OUTPUT_FORMATS.join(" / ")} \u3067\u3059`)}if(options.help||options.argv[0]===HELP_TOKEN){const extra=options.argv[0]===HELP_TOKEN?options.argv.slice(1):options.argv;if(extra.length>0&&!options.help){throw new UsageError(`twp api help \u306F\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${extra.
|
|
98
|
+
join(" ")}`,"\u30D1\u30B9\u3092\u53E9\u304F\u306A\u3089 help \u3092\u5916\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u4F8B: twp api /v2/projects\uFF09\u3002")}writeOut(API_COMMAND_HELP);return EXIT_OK}const input=parseOperationArgs(options.argv,API_FLAGS);const noRedact=input.flags.has("--no-redact");const cliInputText=await readBody(input,{flag:"--cli-input-json-inline",fileFlag:"--cli-input-json",label:"--cli-input-json",maxChars:MAX_BODY_CHARS,usage:"\u4F8B: twp api /v2/projects --method POST --gen\
|
|
99
|
+
erate-cli-skeleton > in.json"});const cliInput=cliInputText===void 0?void 0:parseCliInput(cliInputText);const[pathArg,...extraArgs]=input.args;if(extraArgs.length>0){throw new UsageError(`\u4F59\u5206\u306A\u5F15\u6570\u304C\u3042\u308A\u307E\u3059: ${extraArgs.join(" ")}`,"twp api \u304C\u53D7\u3051\u308B\u4F4D\u7F6E\u5F15\u6570\u306F\u30D1\u30B91\u3064\u3060\u3051\u3067\u3059\u3002\u30AF\u30A8\u30EA\u306F\u30D1\u30B9\u306B\u66F8\u304F\u304B --query-param \u3067\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
100
|
+
const rawPath=pathArg??cliInput?.path;if(rawPath===void 0){throw new UsageError("\u30D1\u30B9\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044","\u4F8B: twp api /v2/projects?limit=10\uFF08\u4E00\u89A7\u306F twp api help\uFF09")}const{path,query:inlineQuery}=normalizeApiPath(rawPath);const method=parseMethod(input.flags.get("--method")??cliInput?.method);const query={...parseQueryString(inlineQuery),...cliInput?.query??{},...parseQueryParams(repeatedValues(input,"--query-param"))};if(input.flags.
|
|
101
|
+
has("--generate-cli-skeleton")){if(input.flags.has("--body-file")){throw new UsageError("--generate-cli-skeleton \u3068 --body-file \u306F\u540C\u6642\u306B\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093","\u3072\u306A\u5F62\u3092\u51FA\u3057\u3066\u304B\u3089\u7DE8\u96C6\u3057\u3001--cli-input-json \u3067\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}writeOut(`${JSON.stringify(buildSkeleton(method,path.replace(/^\/api/,""),query),null,2)}
|
|
102
|
+
`);return EXIT_OK}const bodyText=await readBody(input,{flag:"--body-inline",fileFlag:"--body-file",label:"\u30EA\u30AF\u30A8\u30B9\u30C8\u30DC\u30C7\u30A3",maxChars:MAX_BODY_CHARS,usage:"\u4F8B: twp api /v2/projects --method POST --body-file body.json --yes"});let body;if(bodyText!==void 0){try{body=JSON.parse(bodyText)}catch(err){throw new UsageError(`--body-file \u306E JSON \u3092\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093: ${err.message}`)}}else if(cliInput!==void 0&&"body"in cliInput){body=cliInput.
|
|
103
|
+
body}if(body!==void 0&&method==="GET"){throw new UsageError("GET \u306B\u30EA\u30AF\u30A8\u30B9\u30C8\u30DC\u30C7\u30A3\u306F\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093","\u66F8\u304D\u8FBC\u307F\u306A\u3089 --method POST / PUT / PATCH \u3092\u3001\u7D5E\u308A\u8FBC\u307F\u306A\u3089 --query-param \u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044\u3002")}if(!globals.dryRun&&method!=="GET"&&!globals.yes){throw new UsageError(`twp api \u306F GET \u4EE5\u5916\u306B --yes \u304C\u5FC5\u8981\u3067\u3059\uFF08\u6307\u5B9A: ${method}\
|
|
104
|
+
${path}\uFF09`,"\u9001\u308B\u5185\u5BB9\u306F --dry-run \u3067\u5148\u306B\u78BA\u8A8D\u3067\u304D\u307E\u3059\u3002")}const noValidate=input.flags.has("--no-validate");const model=await resolveModel(method,path);const paging=resolveApiPaging(input,model,method,query);if(paging.startingToken!==void 0)query[CURSOR_PARAM]=paging.startingToken;if(model.operation!==null&&!noValidate)assertValid(model.operation,query,body);const plan={method,path,query,...body!==void 0?{body}:{}};const stored=loadCredentials(
|
|
105
|
+
profile.name);const apiUrl=effectiveApiUrl(profile,stored?.api_url);writeErr(`\u63A5\u7D9A\u5148: ${stripTerminalControls(profile.name)} (${stripTerminalControls(apiUrl)})
|
|
106
|
+
`);for(const note of model.notes)writeErr(`${stripTerminalControls(note)}
|
|
107
|
+
`);if(noValidate)writeErr("\u6CE8\u8A18: --no-validate \u306E\u305F\u3081\u9001\u4FE1\u524D\u306E\u30B9\u30AD\u30FC\u30DE\u691C\u8A3C\u3092\u884C\u3044\u307E\u305B\u3093\u3002\n");if(noRedact){writeErr("\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\n")}if(globals.dryRun){writeOut(line(renderOutput(dryRunValue(apiUrl,plan),format,noRedact)));return EXIT_OK}
|
|
108
|
+
const transport=options.fetchImpl??httpFetch;const fetchImpl=globals.debug?withDebug(transport):transport;const session=new AuthSession(profile.name,apiUrl,process.env,fetchImpl);const client=new TwpApiClient(apiUrl,session,fetchImpl,options.version);let responseBody;try{responseBody=await client.request(plan.method,appendQuery(plan.path,plan.query),plan.body)}catch(err){if(err instanceof ApiError||err instanceof NotLoggedInError||err instanceof SessionExpiredError)throw err;throw new NetworkError(
|
|
109
|
+
`${apiUrl} \u3078\u306E\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.message}`,{cause:err})}let paged;if(paging.resultPath!==null&&isPageable(responseBody,{...paging,resultPath:paging.resultPath})){paged=await fetchAllPages({client,apiUrl,plan,paging:envelopePaging({label:`${method} ${model.template??path}`,itemsKey:paging.resultPath,cursorParam:CURSOR_PARAM}),maxPages:DEFAULT_MAX_PAGES,maxItems:paging.maxItems,firstPage:responseBody,vocabulary:API_PAGING_VOCABULARY});responseBody=
|
|
110
|
+
paged.body}const source=noRedact?responseBody:redactSecretValues(responseBody);const value=globals.query===void 0?source:await evaluateQuery(globals.query,source);writeOut(line(renderOutput(value,format,noRedact)));if(paged!==void 0&&paged.pages>1){writeErr(`\u81EA\u52D5\u30DA\u30FC\u30B8\u30F3\u30B0: ${paged.pages} \u30DA\u30FC\u30B8\u3092\u8FBF\u3063\u3066 ${paged.count} \u4EF6\u3092\u53D6\u5F97\u3057\u307E\u3057\u305F\u3002
|
|
111
|
+
`)}if(paged===void 0&&method==="GET"){const note=continuationNote(responseBody,paging);if(note!==null)writeErr(`${stripTerminalControls(note)}
|
|
112
|
+
`)}return EXIT_OK}catch(err){const code=exitCodeFor(err);reportError(err,format,code);return code}}function dryRunValue(apiUrl,plan){const value={method:plan.method,url:`${apiUrl}${appendQuery(plan.path,plan.query)}`};if(plan.body!==void 0)value["body"]=plan.body;return value}var NOT_APPLIED="\u30B9\u30AD\u30FC\u30DE\u691C\u8A3C\u3068\u81EA\u52D5\u30DA\u30FC\u30B8\u30F3\u30B0\u306F\u884C\u3044\u307E\u305B\u3093\u3002";async function resolveModel(method,path){const modelPath=path.replace(/^\/api(?=\/)/i,
|
|
113
|
+
"");try{const routes=await loadCommandModelRoutes();const found=lookupRoute(routes,method,modelPath);if(found.kind==="matched"){const operation=pickOperation((await loadCommandModelDomain(found.domain)).operations,method,found.template);if(operation!==null)return{operation,unmatched:null,template:found.template,notes:[]};return{operation:null,unmatched:"\u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\u306E\u7D22\u5F15\u3068\u5B9A\u7FA9\u304C\u98DF\u3044\u9055\u3063\u3066\u3044\u308B\u305F\u3081",template:null,
|
|
114
|
+
notes:[`\u6CE8\u8A18: \u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\u306E\u7D22\u5F15\u3068\u5B9A\u7FA9\u304C\u98DF\u3044\u9055\u3063\u3066\u3044\u307E\u3059\uFF08${method} ${found.template}\uFF09\u3002${NOT_APPLIED}`]}}if(found.kind==="method-mismatch"){return{operation:null,unmatched:`\u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\u306B ${method} \u306E\u5B9A\u7FA9\u304C\u7121\u3044\u305F\u3081`,template:null,notes:[`\u6CE8\u8A18: \u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\u306E ${found.template} \u306B ${method}\
|
|
115
|
+
\u306F\u3042\u308A\u307E\u305B\u3093\uFF08\u5B9A\u7FA9\u304C\u3042\u308B\u306E\u306F ${found.methods.join(" / ")}\uFF09\u3002${NOT_APPLIED}`]}}const candidates=await suggestRoutes(routes,modelPath,SUGGESTION_LIMIT);return{operation:null,unmatched:"\u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\u306B\u7121\u3044\u30D1\u30B9\u306E\u305F\u3081",template:null,notes:[`\u6CE8\u8A18: \u3053\u306E\u30D1\u30B9\u306F\u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\u306B\u3042\u308A\u307E\u305B\u3093\u3002${NOT_APPLIED}`,
|
|
116
|
+
...candidates.length>0?["\u8FD1\u3044\u30D1\u30B9:",...candidates.map(candidate=>` ${candidate}`)]:[]]}}catch(err){if(!(err instanceof CommandModelMissingError))throw err;const reason=err.message.split("\n")[0]??"";return{operation:null,unmatched:"\u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\u3092\u8AAD\u3081\u306A\u3044\u305F\u3081",template:null,notes:[`\u6CE8\u8A18: ${reason}\u3002${NOT_APPLIED}`]}}}function unpageableReason(model,method){const{operation}=model;if(method!=="GET")return"GET \u3067\u306F\u306A\
|
|
117
|
+
\u3044\u305F\u3081";if(operation===null)return model.unmatched??"\u30B3\u30DE\u30F3\u30C9\u30E2\u30C7\u30EB\u306B\u5B9A\u7FA9\u304C\u7121\u3044\u305F\u3081";if(operation.resultPath==="")return"\u5FDC\u7B54\u304C\u914D\u5217\u305D\u306E\u3082\u306E\u3067\u7D9A\u304D\u3092\u6301\u305F\u306A\u3044\u305F\u3081";return null}function resolveApiPaging(input,model,method,query){const noPaginate=input.flags.has("--no-paginate");const maxItems=positiveInteger(input.flags,"--max-items");const startingToken=input.
|
|
118
|
+
flags.get("--starting-token");const reason=unpageableReason(model,method);if(startingToken!==void 0){if(startingToken.trim()==="")throw new UsageError("--starting-token \u306B\u7A7A\u306E\u5024\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093");if(method!=="GET")throw new UsageError("--starting-token \u306F GET \u3067\u3060\u3051\u4F7F\u3048\u307E\u3059");if(query[CURSOR_PARAM]!==void 0){throw new UsageError("--starting-token \u3068\u30AF\u30A8\u30EA\u306E cursor \u304C\u4E21\u65B9\u6307\u5B9A\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
119
|
+
"\u3069\u3061\u3089\u304B\u4E00\u65B9\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08--starting-token \u306F\u30AF\u30A8\u30EA\u306E cursor \u306B\u5165\u308A\u307E\u3059\uFF09\u3002")}}if(maxItems!==void 0){if(noPaginate){throw new UsageError("--max-items \u3068 --no-paginate \u306F\u540C\u6642\u306B\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093","--no-paginate \u306F1\u30DA\u30FC\u30B8\u3060\u3051\u3092\u53D6\u308B\u306E\u3067\u3001\u4E0A\u9650\u4EF6\u6570\u306F\u52B9\u304D\u307E\u305B\u3093\u3002")}
|
|
120
|
+
if(reason!==null){throw new UsageError(`--max-items \u306F\u81EA\u52D5\u30DA\u30FC\u30B8\u30F3\u30B0\u3067\u304D\u308B\u4E00\u89A7\u3067\u3060\u3051\u4F7F\u3048\u307E\u3059\uFF08${reason}\uFF09`,"--max-items \u3060\u3051\u3067\u306F\u4F55\u3082\u5909\u308F\u308A\u307E\u305B\u3093\u3002")}}const declared=model.operation?.resultPath??null;const resultPath=noPaginate||reason!==null?null:declared??ENVELOPE_ITEMS_KEY;return{resultPath,inferred:resultPath!==null&&declared===null,maxItems:maxItems??DEFAULT_MAX_ITEMS,
|
|
121
|
+
startingToken,notPagedReason:noPaginate?"--no-paginate \u306E\u305F\u3081":reason}}function assertValid(operation,query,body){const violations=[...validateQuery(operation.queryParams,query),...operation.body!==null&&operation.method!=="GET"?validateBody(operation.body.schema,body??{}):[]];if(violations.length===0)return;const shown=violations.slice(0,MAX_REPORTED_VIOLATIONS).map(violation=>` - ${violation}`);const rest=violations.length-shown.length;throw new UsageError(`\u9001\u4FE1\u524D\u306E\u691C\u8A3C\u3067 ${violations.
|
|
122
|
+
length} \u4EF6\u306E\u554F\u984C\u304C\u898B\u3064\u304B\u308A\u307E\u3057\u305F\uFF08${operation.method} ${operation.path}\uFF09:
|
|
123
|
+
${shown.join("\n")}${rest>0?`
|
|
124
|
+
\u2026\u307B\u304B ${rest} \u4EF6`:""}`,"\u30B9\u30AD\u30FC\u30DE\u306F\u30B5\u30FC\u30D0\u306E\u691C\u8A3C\u898F\u5247\u304B\u3089\u63A8\u5B9A\u3057\u305F\u3082\u306E\u3067\u3059\u3002\u30B5\u30FC\u30D0\u304C\u53D7\u3051\u308B\u306F\u305A\u306E\u5165\u529B\u304C\u62D2\u307E\u308C\u305F\u5834\u5408\u306F --no-validate \u3067\u691C\u8A3C\u3092\u5916\u3057\u3066\u9001\u308C\u307E\u3059\u3002")}function isPageable(body,paging){if(typeof body!=="object"||body===null||Array.isArray(body))return false;
|
|
125
|
+
const hasArray=Array.isArray(body[paging.resultPath]);const{hasMore}=readEnvelopeCursor(body);if(paging.inferred)return hasArray&&hasMore!==void 0;if(hasArray)return true;return hasMore!==void 0&&hasMore!==null&&hasMore!==false}function continuationNote(body,paging){const{hasMore,cursor}=readEnvelopeCursor(body);const why=paging.notPagedReason===null?"":`\uFF08${paging.notPagedReason}1\u30DA\u30FC\u30B8\u3060\u3051\u53D6\u5F97\u3057\u307E\u3057\u305F\uFF09`;if(hasMore===false||hasMore===null||hasMore===
|
|
126
|
+
void 0)return null;if(hasMore!==true){return`\u6CE8\u8A18: \u5FDC\u7B54\u306E has_more \u3092\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093\uFF08\u53D7\u3051\u53D6\u3063\u305F\u5024: ${JSON.stringify(hasMore)??"undefined"}\uFF09${why}\u3002\u3053\u308C\u304C\u5168\u4EF6\u304B\u3069\u3046\u304B\u306F\u5224\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002`}if(typeof cursor!=="string"||cursor===""){return`\u6CE8\u8A18: \u7D9A\u304D\u304C\u3042\u308B\u3068\u793A\u3055\u308C\u3066\u3044\u307E\u3059\u304C next_cursor \u304C\u3042\u308A\u307E\u305B\u3093${why}\
|
|
127
|
+
\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002`}return`\u6CE8\u8A18: \u7D9A\u304D\u304C\u3042\u308A\u307E\u3059${why}\u3002\u7D9A\u304D\u306F --starting-token ${shellQuote(cursor)} \u3067\u53D6\u5F97\u3067\u304D\u307E\u3059\u3002`}export{API_FLAGS,API_METHODS,buildSkeleton,normalizeApiPath,parseCliInput,parseMethod,parseQueryParams,parseQueryString,runApiCommand};
|
|
@@ -13,4 +13,4 @@ if(SHELL_SAFE.test(value))return value;return`'${value.replace(/'/g,"'\\''")}'`}
|
|
|
13
13
|
flags){if(PAGING_CONTROL_FLAGS.has(spec.name))continue;const value=input.flags.get(spec.name);if(value===void 0)continue;flags.push(spec.takesValue?flagSegment(spec.name,value):spec.name)}flags.push(flagSegment("--cursor",cursor));const args=input.args.map(arg=>shellQuote(arg));const separated=input.args.some(arg=>arg.startsWith("-"));return separated?[context.command,...flags,"--",...args].join(" "):[context.command,...args,...flags].join(" ")}function nextPageNotes(body,input,context){const{hasMore,
|
|
14
14
|
cursor}=readEnvelopeCursor(body);if(hasMore!==true){if(hasMore===false||hasMore===null||hasMore===void 0&&cursor===void 0)return[];return[`\u5FDC\u7B54\u306E has_more \u3092\u89E3\u91C8\u3067\u304D\u306A\u3044\u305F\u3081\u3001\u7D9A\u304D\u306E\u6709\u7121\u3092\u5224\u5B9A\u3067\u304D\u307E\u305B\u3093\uFF08\u53D7\u3051\u53D6\u3063\u305F\u5024: ${JSON.stringify(hasMore)??"undefined"}\uFF09\u3002\u5168\u4EF6\u304C\u8981\u308B\u306A\u3089 --all \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002`]}
|
|
15
15
|
if(typeof cursor!=="string"||cursor==="")return["\u7D9A\u304D\u304C\u3042\u308A\u307E\u3059\u304C\u3001\u5FDC\u7B54\u306B next_cursor \u304C\u3042\u308A\u307E\u305B\u3093\u3002"];if(CONTROL_CHARS.test(cursor)){return["\u7D9A\u304D\u304C\u3042\u308A\u307E\u3059\u304C\u3001\u5FDC\u7B54\u306E next_cursor \u306B\u5236\u5FA1\u6587\u5B57\u304C\u542B\u307E\u308C\u308B\u305F\u3081\u6848\u5185\u3092\u51FA\u305B\u307E\u305B\u3093\u3002--all \u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044\u3002"]}const hint=context.
|
|
16
|
-
flags.some(spec=>spec.name==="--all")?"\uFF08\u5168\u4EF6\u306F --all\uFF09":"";return[`\u7D9A\u304D\u304C\u3042\u308A\u307E\u3059\u3002\u6B21\u306E\u30DA\u30FC\u30B8: ${nextPageCommand(input,cursor,context)}${hint}`]}export{DEFAULT_MAX_PAGES,DEFAULT_MAX_ITEMS,LIST_FLAGS,LIST_PAGING_HELP,positiveInteger,nonEmpty,envelopePaging,shellQuote,nextPageNotes};
|
|
16
|
+
flags.some(spec=>spec.name==="--all")?"\uFF08\u5168\u4EF6\u306F --all\uFF09":"";return[`\u7D9A\u304D\u304C\u3042\u308A\u307E\u3059\u3002\u6B21\u306E\u30DA\u30FC\u30B8: ${nextPageCommand(input,cursor,context)}${hint}`]}export{DEFAULT_MAX_PAGES,DEFAULT_MAX_ITEMS,LIST_FLAGS,LIST_PAGING_HELP,positiveInteger,nonEmpty,readEnvelopeCursor,envelopePaging,shellQuote,nextPageNotes};
|
|
@@ -14,9 +14,12 @@ ok:true,file:prog,args:[...shim.nodeArgs,target,...args],note:`${file} \u2192 ${
|
|
|
14
14
|
return ai==="claude"||!["gemini","codex","copilot"].includes(ai)}import{createHash}from"crypto";import fs2 from"fs";var FALSY=new Set(["0","false","no","off"]);function isBoolishTrue(raw){const v=(raw??"").trim();if(v==="")return false;return!FALSY.has(v.toLowerCase())}var EXCLUSIVE_SKILL_FLOOR=["support-triage"];function normalizeSkillName(skill){return skill.trim().replace(/^twp-/,"")}var stripPrefix=normalizeSkillName;function skillOfItem(item){const explicit=(item.ai_skill??"").trim();if(explicit)return stripPrefix(explicit);const m=/\/twp-([a-z0-9-]+)/.exec(item.prompt??"");return m?.[1]??""}function ageMinutesOf(item,now){for(const raw of[item.started_at,item.updated_at,item.dequeued_at,item.created_at]){if(!raw)continue;const ts=Date.parse(raw);if(Number.
|
|
15
15
|
isNaN(ts))continue;return Math.floor((now.getTime()-ts)/6e4)}return null}function exclusiveInflightEntries(groups,opts){const now=opts.now??new Date;const staleMinutes=opts.staleHours*60;const bySkill=new Map;for(const group of groups){for(const item of group.items){const skill=skillOfItem(item);if(!skill)continue;const status=group.status==="mixed"?item.status??"unknown":group.status;const ageMinutes=ageMinutesOf(item,now);if(status==="processing"&&ageMinutes!==null&&ageMinutes>staleMinutes)continue;
|
|
16
16
|
const entry={skill,status,runner:item.runner_id??"-",ageMinutes};const prev=bySkill.get(skill);if(!prev||(entry.ageMinutes??-1)>(prev.ageMinutes??-1))bySkill.set(skill,entry)}}return[...bySkill.values()].sort((a,b)=>a.skill.localeCompare(b.skill))}function formatExclusiveEntry(entry){const age=entry.ageMinutes===null?"\u4E0D\u660E":`${entry.ageMinutes}\u5206`;return`${entry.skill} status=${entry.status} runner=${entry.runner} \u7D4C\u904E=${age}`}import path2 from"path";var BUILTIN={primary_rotation:{complex:["claude"],search:["claude"],simple:["claude"]},fallback_chains:{complex:["claude","codex"],search:["codex","gemini","copilot","claude"],simple:["codex","gemini","copilot","claude"]}};function usesBedrock(env){return isBoolishTrue(env.CLAUDE_CODE_USE_BEDROCK)}var DEFAULT_CATEGORY="complex";var EFFORTS=new Set(["low","medium","high","xhigh","max"]);var MAX_COOLDOWN_SEC=3600;var DEFAULT_COOLDOWN_SEC=300;var AI_UNUSABLE_COOLDOWN_SEC=1800;
|
|
17
|
-
function loadAiConfig(inline,file,workspace){const
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function loadAiConfig(inline,file,workspace){const read=readAiConfigFile(file,workspace);const warnings=read.problem===null?[]:[read.problem.startsWith("ai_config_file \u3092\u8AAD\u3081\u307E\u305B\u3093")?`${read.problem}
|
|
18
|
+
\u3053\u306E\u72B6\u614B\u3067\u306F\u5168\u30B9\u30AD\u30EB\u304C\u65E2\u5B9A\u30AB\u30C6\u30B4\u30EA\u3067\u8D70\u308A\u307E\u3059\u3002\u78BA\u8A8D: python3 -m json.tool <file>`:read.problem];return{config:new AiConfig(mergeAiConfig(read.file,inline)),warnings}}function readAiConfigFile(file,workspace){if(file===void 0||file.trim()==="")return{file:null,problem:null};const resolved=path2.isAbsolute(file)?file:path2.resolve(workspace,file);try{const parsed=JSON.parse(fs2.readFileSync(resolved,
|
|
19
|
+
"utf8"));if(parsed===null||typeof parsed!=="object"||Array.isArray(parsed)){return{file:null,problem:`ai_config_file \u304C\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3067\u306F\u3042\u308A\u307E\u305B\u3093: ${resolved}`}}return{file:parsed,problem:null}}catch(err){return{file:null,problem:`ai_config_file \u3092\u8AAD\u3081\u307E\u305B\u3093: ${resolved}\uFF08${err.message}\uFF09`}}}function mergeAiConfig(fromFile,inline){return{...fromFile??{},...inline??{}}}function reloadAiConfig(target,inline,file,workspace){
|
|
20
|
+
const hashBefore=target.hash();const read=readAiConfigFile(file,workspace);if(read.file===null){if(read.problem===null)return{status:"skipped",hashBefore,hashAfter:hashBefore,warnings:[]};return{status:"kept",hashBefore,hashAfter:hashBefore,warnings:[`${read.problem}
|
|
21
|
+
\u73FE\u5728\u306E\u8A2D\u5B9A\uFF08config_hash ${hashBefore}\uFF09\u306E\u307E\u307E\u8D70\u308A\u307E\u3059\u3002\u78BA\u8A8D: python3 -m json.tool <file>`]}}const changed=target.replace(mergeAiConfig(read.file,inline));return{status:changed?"updated":"unchanged",hashBefore,hashAfter:target.hash(),warnings:[]}}function stableJson(value){return JSON.stringify(value,(_key,v)=>v!==null&&typeof v==="object"&&!Array.isArray(v)?Object.fromEntries(Object.entries(v).sort(([a],[b])=>a.localeCompare(
|
|
22
|
+
b))):v)}var CHAIN_KEYS=["primary_rotation","fallback_chains"];var AiConfig=class _AiConfig{rotation=new Map;limitedUntil=new Map;unusableUntil=new Map;highRiskSkills;raw;constructor(raw){this.raw=raw;this.highRiskSkills=_AiConfig.highRiskSet(raw)}static highRiskSet(raw){return new Set((raw.high_risk_skills??[]).filter(v=>typeof v==="string"&&v!==""))}replace(next){if(stableJson(next)===stableJson(this.raw))return false;this.raw=next;this.highRiskSkills=_AiConfig.highRiskSet(next);return true}hash(){
|
|
20
23
|
const significant=Object.fromEntries(Object.entries(this.raw).filter(([k])=>!k.startsWith("_")&&!CHAIN_KEYS.includes(k)).sort(([a],[b])=>a.localeCompare(b)));return createHash("sha256").update(JSON.stringify(significant)).digest("hex").slice(0,16)}categoryForSkill(skill){const name=stripPrefix2(skill);return this.raw.skill_category?.[name]??DEFAULT_CATEGORY}usesAi(ai){const rotations=this.raw.primary_rotation??BUILTIN.primary_rotation;const chains=this.raw.fallback_chains??BUILTIN.fallback_chains;
|
|
21
24
|
const categories=new Set([DEFAULT_CATEGORY,...Object.keys(rotations),...Object.keys(chains),...Object.values(this.raw.skill_category??{})]);const matches=name=>isClaudeAi(ai)?isClaudeAi(name):name===ai;for(const category of categories){const rotation=rotations[category]??rotations[DEFAULT_CATEGORY]??BUILTIN.primary_rotation[DEFAULT_CATEGORY]??[];const chain=chains[category]??chains[DEFAULT_CATEGORY]??BUILTIN.fallback_chains[DEFAULT_CATEGORY]??["claude"];for(const name of[...rotation,...chain]){if(matches(
|
|
22
25
|
name))return true}}return false}chainFor(category){const chains=this.raw.fallback_chains??BUILTIN.fallback_chains;return chains[category]??chains[DEFAULT_CATEGORY]??BUILTIN.fallback_chains[DEFAULT_CATEGORY]??["claude"]}primaryFor(category,skill){const rotations=this.raw.primary_rotation??BUILTIN.primary_rotation;const entries=rotations[category]??rotations[DEFAULT_CATEGORY]??BUILTIN.primary_rotation[DEFAULT_CATEGORY]??[];if(entries.length===0)return"";const start=this.rotation.get(category)??0;for(let i=0;i<
|
|
@@ -45,4 +48,4 @@ return{auth:"unknown",detail:oneLine(`\u8CC7\u683C\u60C5\u5831\u3092\u89E3\u91C8
|
|
|
45
48
|
blockedReason:null}}function detectPending(ai){return{auth:"unknown",detail:"\u30ED\u30B0\u30A4\u30F3\u5224\u5B9A\u306E\u65B9\u6CD5\u304C\u672A\u78BA\u5B9A\u3067\u3059",blockedReason:`${ai} \u306F\u7121\u4EBA\u5B9F\u884C\u3067\u306E\u8A8D\u8A3C\u72B6\u614B\u3092\u5224\u5B9A\u3059\u308B\u65B9\u6CD5\u304C\u672A\u78BA\u5B9A\u306E\u305F\u3081\u9078\u629E\u3067\u304D\u307E\u305B\u3093`}}function detectAiClis(deps={}){const d=resolve(deps);return DETECTABLE_AIS.map(ai=>{const binPath=findOnPath(ai,d);
|
|
46
49
|
if(binPath===null){return{ai,installed:false,binPath:null,auth:"unknown",detail:"PATH \u306B\u898B\u3064\u304B\u308A\u307E\u305B\u3093\uFF08\u672A\u5C0E\u5165\uFF09",blockedReason:null}}const state=ai==="claude"?detectClaude(d):ai==="codex"?detectCodex(d,binPath):detectPending(ai);return{ai,installed:true,binPath,...state}})}function formatDetection(d,index){const selectable=isSelectable(d);const mark=selectable?d.auth==="authenticated"?"\u2705":"\u2754":" ";const num=index===null?" ":`${String(
|
|
47
50
|
index).padStart(2)}.`;const state=!d.installed?"\u672A\u5C0E\u5165":d.auth==="authenticated"?"\u30ED\u30B0\u30A4\u30F3\u6E08\u307F":d.auth==="unauthenticated"?"\u672A\u30ED\u30B0\u30A4\u30F3":"\u672A\u5224\u5B9A";const blocked=d.blockedReason===null?"":`
|
|
48
|
-
\u9078\u629E\u3067\u304D\u307E\u305B\u3093: ${oneLine(d.blockedReason)}`;return`${num} ${mark} ${d.ai.padEnd(8)} ${state.padEnd(8)} ${oneLine(d.detail)}${blocked}`}export{isBoolishTrue,resolveSpawnTarget,spawnSyncResolved,DEFAULT_CLAUDE_LAUNCHER,detectClaudeAutoSwitch,wrapWithAutoSwitch,activeSlotPath,isClaudeAi,normalizeSkillName,skillOfItem,exclusiveInflightEntries,formatExclusiveEntry,usesBedrock,loadAiConfig,AiConfig,modelFitsRoute,isUsableModelId,isDetectableAi,isSelectable,resolveDetectDeps,claudeConfigDir,detectAiClis,formatDetection};
|
|
51
|
+
\u9078\u629E\u3067\u304D\u307E\u305B\u3093: ${oneLine(d.blockedReason)}`;return`${num} ${mark} ${d.ai.padEnd(8)} ${state.padEnd(8)} ${oneLine(d.detail)}${blocked}`}export{isBoolishTrue,resolveSpawnTarget,spawnSyncResolved,DEFAULT_CLAUDE_LAUNCHER,detectClaudeAutoSwitch,wrapWithAutoSwitch,activeSlotPath,isClaudeAi,normalizeSkillName,skillOfItem,exclusiveInflightEntries,formatExclusiveEntry,usesBedrock,loadAiConfig,reloadAiConfig,AiConfig,modelFitsRoute,isUsableModelId,isDetectableAi,isSelectable,resolveDetectDeps,claudeConfigDir,detectAiClis,formatDetection};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
3
|
import{stringWidth}from"./chunk-WVS4W5FY.js";import{AuthSession,NotLoggedInError,SessionExpiredError,loadCredentials}from"./chunk-63LDNYGW.js";import{GLOBAL_OPTIONS_HELP,HELP_TOKEN}from"./chunk-FKIZ5ZJU.js";import{parseOperationArgs}from"./chunk-O52CUEDO.js";import{Resolver,requireDefaultProject}from"./chunk-7WEYBZSK.js";import{ApiError,TwpApiClient,appendQuery}from"./chunk-JKSXUBND.js";import{effectiveApiUrl,loadUserConfig,resolveConfiguredOutput,resolveProfile}from"./chunk-NERYSBA4.js";
|
|
4
|
-
import{httpFetch}from"./chunk-J7QYPKVK.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,nextPageNotes,positiveInteger,shellQuote}from"./chunk-
|
|
5
|
-
"`).replace(new RegExp(`([?&]${SECRET_KEY_PATTERN}=)[^&\\s"'\`,;)\\]}]+`,"gi"),`$1${REDACTED}`).replace(new RegExp(`(
|
|
6
|
-
test(key)?REDACTED:redactSecretValues(item)}return out}return value}function formatHeaders(headers){if(!headers)return[];const entries=headers instanceof Headers?[...headers.entries()]:Array.isArray(headers)?headers:Object.entries(headers);return entries.map(([name,value])=>{const shown=SENSITIVE_HEADERS.has(name.toLowerCase())?REDACTED:redactSecrets(String(value));return` ${name.toLowerCase()}: ${shown}`})}var BODY_LIMIT=4e3;
|
|
7
|
-
raw));return safe.length>BODY_LIMIT?`${safe.slice(0,BODY_LIMIT)}
|
|
4
|
+
import{httpFetch}from"./chunk-J7QYPKVK.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,nextPageNotes,positiveInteger,shellQuote}from"./chunk-2VISRLWS.js";import{ApiResponseError,EXIT_API_CLIENT,EXIT_API_SERVER,EXIT_AUTH,EXIT_FAILURE,EXIT_OK,EXIT_USAGE,NetworkError,UsageError}from"./chunk-M3GWY6NT.js";import{ResolveError}from"./chunk-5QCAIKFE.js";import fs from"fs";import path from"path";var SENSITIVE_HEADERS=new Set(["authorization","proxy-authorization","cookie","set-cookie","x-api-key","x-auth-token","x-vercel-protection-bypass"]);var REDACTED="***\uFF08\u4F0F\u5B57\uFF09";var SECRET_KEY_PATTERN="[A-Za-z0-9_-]*(?:token|secret|password|passwd|api[_-]?key|credential)[A-Za-z0-9_-]*";var NOT_SECRET_FLAGS="(?:starting-token)";function redactSecrets(text){return text.replace(/\bBearer\s+[^\s"'`,;)\]}]+/gi,`Bearer ${REDACTED}`).replace(new RegExp(`("${SECRET_KEY_PATTERN}"\\s*:\\s*)"(?\
|
|
5
|
+
:[^"\\\\]|\\\\.)*"`,"gi"),`$1"${REDACTED}"`).replace(new RegExp(`([?&]${SECRET_KEY_PATTERN}=)[^&\\s"'\`,;)\\]}]+`,"gi"),`$1${REDACTED}`).replace(new RegExp(`(--(?!${NOT_SECRET_FLAGS}(?:=|\\s))${SECRET_KEY_PATTERN}(?:=|\\s+))('[^']*'|"[^"]*"|[A-Za-z0-9_.~+/=|:%-]+)`,"gi"),`$1${REDACTED}`)}var SECRET_KEY_NAME=new RegExp(`^${SECRET_KEY_PATTERN}$`,"i");function redactSecretValues(value){if(Array.isArray(value))return value.map(item=>redactSecretValues(item));if(value!==null&&typeof value==="object"){
|
|
6
|
+
const out={};for(const[key,item]of Object.entries(value)){out[key]=SECRET_KEY_NAME.test(key)?REDACTED:redactSecretValues(item)}return out}return value}function formatHeaders(headers){if(!headers)return[];const entries=headers instanceof Headers?[...headers.entries()]:Array.isArray(headers)?headers:Object.entries(headers);return entries.map(([name,value])=>{const shown=SENSITIVE_HEADERS.has(name.toLowerCase())?REDACTED:redactSecrets(String(value));return` ${name.toLowerCase()}: ${shown}`})}var BODY_LIMIT=4e3;
|
|
7
|
+
function formatBody(raw){const safe=redactSecrets(stripTerminalControls(raw));return safe.length>BODY_LIMIT?`${safe.slice(0,BODY_LIMIT)}
|
|
8
8
|
\u2026\uFF08\u4EE5\u964D ${safe.length-BODY_LIMIT} \u6587\u5B57\u3092\u7701\u7565\uFF09`:safe}function isTextualContentType(contentType){if(contentType===null)return false;return/^\s*(text\/|application\/(json|xml|javascript|x-www-form-urlencoded)|application\/[\w.+-]*\+(json|xml))/i.test(contentType)}function withDebug(inner,options={}){const write=options.write??(text=>void process.stderr.write(text));const now=options.now??(()=>Date.now());return async(input,init)=>{const method=init?.method??
|
|
9
9
|
"GET";const lines=[`[debug] \u2192 ${method} ${redactSecrets(input)}`,...formatHeaders(init?.headers)];if(typeof init?.body==="string")lines.push(` ${formatBody(init.body)}`);write(`${lines.join("\n")}
|
|
10
10
|
`);const started=now();let res;try{res=await inner(input,init)}catch(err){write(`[debug] \u2717 \u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F (${now()-started}ms): ${redactSecrets(err.message)}
|
|
@@ -31,7 +31,7 @@ ${operationSection}${subSection}
|
|
|
31
31
|
${GLOBAL_OPTIONS_HELP}
|
|
32
32
|
`}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")}if(op.flags.length>0){sections.push("","\u30AA\u30D7\u30B7\u30E7\u30F3:",alignedList(op.flags.
|
|
33
33
|
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}\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2}\
|
|
34
|
-
${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={backlog:async()=>(await import("./backlog-AYEKG575.js")).backlogDomain,project:async()=>(await import("./project-
|
|
34
|
+
${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={backlog:async()=>(await import("./backlog-AYEKG575.js")).backlogDomain,project:async()=>(await import("./project-OKTJ32JT.js")).projectDomain,task:async()=>(await import("./task-7K54BO5U.js")).taskDomain};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}
|
|
35
35
|
`}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)
|
|
36
36
|
return EXIT_AUTH;if(err instanceof ApiError)return exitCodeForStatus(err.status);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){const message=safeText(err instanceof Error?err.message:String(err));const rawHint=err instanceof
|
|
37
37
|
UsageError?err.hint:void 0;const hint=rawHint!==void 0?safeText(rawHint):void 0;if(format==="json"){const body={code,message};if(err instanceof ApiError)body["status"]=err.status;if(err instanceof ResolveError&&err.status!==null)body["status"]=err.status;if(hint!==void 0)body["hint"]=hint;writeErr(`${JSON.stringify({error:body},null,2)}
|
|
@@ -42,11 +42,11 @@ message}`,{cause:err})}}function resolveDownloadTarget(spec,commandPath,operatio
|
|
|
42
42
|
out:path.resolve(raw.trim()),force:input.flags.has(spec.forceFlag)}}function assertWritableTarget(target,forceFlag){if(!target.force&&fs.existsSync(target.out)){throw new UsageError(`\u66F8\u304D\u51FA\u3057\u5148\u304C\u65E2\u306B\u3042\u308A\u307E\u3059: ${target.out}`,`\u4E0A\u66F8\u304D\u3059\u308B\u306A\u3089 ${forceFlag} \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\uFF08\u65E2\u5B9A\u3067\u306F\u4E0A\u66F8\u304D\u3057\u307E\u305B\u3093\uFF09\u3002`)}const dir=path.dirname(target.out);if(!fs.
|
|
43
43
|
existsSync(dir)){throw new UsageError(`\u66F8\u304D\u51FA\u3057\u5148\u306E\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u3042\u308A\u307E\u305B\u3093: ${dir}`,"\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3092\u4F5C\u3063\u3066\u304B\u3089\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u81EA\u52D5\u3067\u306F\u4F5C\u6210\u3057\u307E\u305B\u3093\uFF09\u3002")}}async function download(args){let received;try{received=await args.client.requestBinary(args.plan.method,appendQuery(args.plan.path,args.plan.
|
|
44
44
|
query))}catch(err){if(err instanceof ApiError||err instanceof NotLoggedInError||err instanceof SessionExpiredError)throw err;throw new NetworkError(`${args.apiUrl} \u3078\u306E\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.message}`,{cause:err})}try{fs.writeFileSync(args.target.out,received.bytes,{flag:args.target.force?"w":"wx"})}catch(err){const code=err.code;if(code==="EEXIST"){throw new UsageError(`\u66F8\u304D\u51FA\u3057\u5148\u304C\u65E2\u306B\u3042\u308A\u307E\u3059: ${args.
|
|
45
|
-
target.out}`,"\u4E0A\u66F8\u304D\u3059\u308B\u306A\u3089 --force \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002")}throw new Error(`\u66F8\u304D\u51FA\u3057\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${args.target.out}\uFF09: ${err.message}`,{cause:err})}return{path:args.target.out,size:received.bytes.byteLength,contentType:received.contentType}}
|
|
46
|
-
\uFF0F${pages} \u30DA\u30FC\u30B8\u30FB${count} \u4EF6\u3092\u53D6\u5F97\u6E08\u307F\uFF09\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002
|
|
47
|
-
const{paging,maxPages,maxItems}=args;const merged=[];const first=args.plan.query?.[paging.cursorParam];let sent=typeof first==="string"?first:"";for(let page=1;;page+=1){const plan=page===1?args.plan:{...args.plan,query:{...args.plan.query,[paging.cursorParam]:sent}};let body;try{body=await send(args.client,
|
|
48
|
-
\u4EF6\u3092\u53D6\u5F97\u6E08\u307F\uFF09\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u7D9A\u304D\u306F
|
|
49
|
-
`)}throw err}for(const item of paging.items(body))merged.push(item);const next=paging.nextCursor(body);if(next===null)return{body:paging.withItems(body,merged),pages:page,count:merged.length};if(merged.length>=maxItems)throw capExceeded(
|
|
45
|
+
target.out}`,"\u4E0A\u66F8\u304D\u3059\u308B\u306A\u3089 --force \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002")}throw new Error(`\u66F8\u304D\u51FA\u3057\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${args.target.out}\uFF09: ${err.message}`,{cause:err})}return{path:args.target.out,size:received.bytes.byteLength,contentType:received.contentType}}var CURATED_PAGING_VOCABULARY={mode:"--all",resumeFlag:"--cursor",capAdvice:"--limit \u3092\u5927\u304D\u304F\u3057\u3066\u5F80\u5FA9\u3092\u6E1B\u3089\u3059\u304B\u3001--max-pages / --max-items \u3092\u4E0A\u3052\u3066\u304F\u3060\u3055\u3044\u3002"};
|
|
46
|
+
function capExceeded(vocabulary,reason,pages,count,cursor){return new UsageError(`${vocabulary.mode} \u304C\u4E0A\u9650\u306B\u9054\u3057\u305F\u305F\u3081\u4E2D\u65AD\u3057\u307E\u3057\u305F\uFF08${reason}\uFF0F${pages} \u30DA\u30FC\u30B8\u30FB${count} \u4EF6\u3092\u53D6\u5F97\u6E08\u307F\uFF09\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002`,`${vocabulary.capAdvice}\u7D9A\u304D\u3060\u3051\u3092\u53D6\u308B\u306A\u3089 ${vocabulary.resumeFlag} ${shellQuote(cursor)}\
|
|
47
|
+
\u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059`)}async function fetchAllPages(args){const{paging,maxPages,maxItems}=args;const vocabulary=args.vocabulary??CURATED_PAGING_VOCABULARY;const merged=[];const first=args.plan.query?.[paging.cursorParam];let sent=typeof first==="string"?first:"";for(let page=1;;page+=1){const plan=page===1?args.plan:{...args.plan,query:{...args.plan.query,[paging.cursorParam]:sent}};let body;try{body=page===1&&"firstPage"in args?args.firstPage:await send(args.client,
|
|
48
|
+
args.apiUrl,plan)}catch(err){if(page>1){writeErr(`${vocabulary.mode} \u306F ${page} \u30DA\u30FC\u30B8\u76EE\u3067\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${page-1} \u30DA\u30FC\u30B8\u30FB${merged.length} \u4EF6\u3092\u53D6\u5F97\u6E08\u307F\uFF09\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u7D9A\u304D\u306F ${vocabulary.resumeFlag} ${shellQuote(stripTerminalControls(sent))} \u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059\u3002
|
|
49
|
+
`)}throw err}for(const item of paging.items(body))merged.push(item);const next=paging.nextCursor(body);if(next===null)return{body:paging.withItems(body,merged),pages:page,count:merged.length};if(merged.length>=maxItems)throw capExceeded(vocabulary,`\u6700\u5927\u4EF6\u6570 ${maxItems} \u4EF6`,page,merged.length,next);if(page>=maxPages)throw capExceeded(vocabulary,`\u6700\u5927\u30DA\u30FC\u30B8\u6570 ${maxPages}`,page,merged.length,next);if(next===sent){throw new ApiResponseError(`\u540C\u3058\u30AB\u30FC\u30BD\u30EB\uFF08${next}\
|
|
50
50
|
\uFF09\u304C\u7E70\u308A\u8FD4\u3057\u8FD4\u3055\u308C\u305F\u305F\u3081\u4E2D\u65AD\u3057\u307E\u3057\u305F\u3002${merged.length} \u4EF6\u3092\u53D6\u5F97\u3057\u305F\u6642\u70B9\u3067\u3001\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002`)}sent=next}}function resolvePaging(operation,path2,input){const all=input.flags.has("--all");const maxPages=positiveInteger(input.flags,"--max-pages")??DEFAULT_MAX_PAGES;const maxItems=positiveInteger(input.flags,"--max-items")??
|
|
51
51
|
DEFAULT_MAX_ITEMS;positiveInteger(input.flags,"--limit");if(all&&operation.paging===void 0){throw new UsageError(`twp ${path2} ${operation.name} \u306F --all \u306B\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u305B\u3093`)}for(const name of["--max-pages","--max-items"]){if(!all&&input.flags.has(name)){throw new UsageError(`${name} \u306F --all \u3068\u4F75\u305B\u3066\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`,`${name} \u3060\u3051\u3067\u306F\u4F55\u3082\u5909\u308F\u308A\u307E\u305B\u3093`)}}return{
|
|
52
52
|
all,maxPages,maxItems}}function profileAliases(profileName){const aliases=loadUserConfig().profiles?.[profileName]?.aliases;return aliases!==void 0?{aliases}:{}}function buildPrepareContext(args){const cache=new Map;return{resolver:args.resolver,projectId(explicit){if(explicit!==void 0&&explicit.trim()===""){throw new UsageError("--project \u306B\u7A7A\u306E\u5024\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093","--project <\u30B3\u30FC\u30C9|ID> \u3092\u6307\u5B9A\u3059\u308B\u304B\u3001--project \u3054\u3068\u5916\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
@@ -61,4 +61,4 @@ for(const note of operation.plannedNotes?.(prepared)??[])writeErr(`${safeText(no
|
|
|
61
61
|
`);if(globals.dryRun){writeOut(line(renderOutput(dryRunValue(apiUrl,plan),format)));return EXIT_OK}let body;let paged;if(operation.fetchCached!==void 0){body=await operation.fetchCached(prepared,ctx)}else if(operation.download!==void 0&&downloadTarget!==void 0){assertWritableTarget(downloadTarget,operation.download.forceFlag);body=await download({client,apiUrl,plan,target:downloadTarget})}else if(paging.all&&operation.paging!==void 0){paged=await fetchAllPages({client,apiUrl,plan,paging:operation.
|
|
62
62
|
paging,maxPages:paging.maxPages,maxItems:paging.maxItems});body=paged.body}else{body=await send(client,apiUrl,plan)}const value=globals.query!==void 0?await evaluateQuery(globals.query,operation.raw(body)):outputValue(operation,format,body);writeOut(line(renderOutput(value,format)));if(paged!==void 0){writeErr(`--all: ${paged.pages} \u30DA\u30FC\u30B8\u3092\u8FBF\u3063\u3066 ${paged.count} \u4EF6\u3092\u53D6\u5F97\u3057\u307E\u3057\u305F\u3002
|
|
63
63
|
`)}const pagingNotes=operation.paging===void 0?[]:nextPageNotes(body,prepared,{command:`twp ${path2} ${operation.name}`,flags:operation.flags,profile:globals.profile});for(const note of[...pagingNotes,...operation.notes?.(body,prepared)??[]]){writeErr(`${safeText(note)}
|
|
64
|
-
`)}return EXIT_OK}catch(err){const code=exitCodeFor(err);reportError(err,format,code);return code}}export{redactSecretValues,withDebug,OUTPUT_FORMATS,resolveOutputFormat,evaluateQuery,renderOutput,outputValue,requiresYes,exitCodeFor,reportError,fetchAllPages,resolvePaging,buildPrepareContext,runDomain};
|
|
64
|
+
`)}return EXIT_OK}catch(err){const code=exitCodeFor(err);reportError(err,format,code);return code}}export{redactSecretValues,withDebug,OUTPUT_FORMATS,resolveOutputFormat,evaluateQuery,renderOutput,outputValue,requiresYes,exitCodeFor,reportError,CURATED_PAGING_VOCABULARY,fetchAllPages,resolvePaging,buildPrepareContext,runDomain};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{DEFAULT_CLAUDE_LAUNCHER,isBoolishTrue,loadAiConfig}from"./chunk-
|
|
3
|
+
import{DEFAULT_CLAUDE_LAUNCHER,isBoolishTrue,loadAiConfig}from"./chunk-H3JTPDCJ.js";import{killProcessTree}from"./chunk-N2UVRM3Z.js";import{findExecutable,isWindowsDriveAbsolute}from"./chunk-PMOUHEJQ.js";import{projectFileKey}from"./chunk-GY7KI5E5.js";import{twpHomeDir}from"./chunk-RZVI6PMW.js";function stringField(value,key,fallback,warnings){if(value===void 0||value===null)return fallback;if(typeof value!=="string"||value.trim()===""){warnings.push(`claude_launcher.${key} \u306F\u7A7A\u3067\u306A\u3044\u6587\u5B57\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u65E2\u5B9A '${fallback}' \u3092\u4F7F\u3044\u307E\u3059\uFF09`);return fallback}return value.trim()}function argvField(value,key,fallback,warnings,allowEmpty){if(value===void 0||value===null)return fallback;
|
|
4
4
|
if(!Array.isArray(value)){warnings.push(`claude_launcher.${key} \u306F\u6587\u5B57\u5217\u306E\u914D\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u65E2\u5B9A [${fallback.join(", ")}] \u3092\u4F7F\u3044\u307E\u3059\uFF09`);return fallback}for(const v of value){if(typeof v!=="string"||v.trim()===""){warnings.push(`claude_launcher.${key} \u306E\u8981\u7D20\u306F\u7A7A\u3067\u306A\u3044\u6587\u5B57\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u65E2\u5B9A [${fallback.
|
|
5
5
|
join(", ")}] \u3092\u4F7F\u3044\u307E\u3059\uFF09`);return fallback}}if(value.length===0&&!allowEmpty){warnings.push(`claude_launcher.${key} \u306F1\u3064\u4EE5\u4E0A\u306E\u5F15\u6570\u304C\u8981\u308A\u307E\u3059\uFF08\u65E2\u5B9A [${fallback.join(", ")}] \u3092\u4F7F\u3044\u307E\u3059\uFF09`);return fallback}return value.map(v=>v.trim())}function probeMatchField(value,warnings){const raw=stringField(value,"probe_match",DEFAULT_CLAUDE_LAUNCHER.probeMatch,warnings);try{new RegExp(raw,"m")}catch(err){
|
|
6
6
|
warnings.push(`claude_launcher.probe_match \u306F\u6B63\u898F\u8868\u73FE\u3068\u3057\u3066\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093\uFF08${err.message}\uFF09\u3002\u65E2\u5B9A '${DEFAULT_CLAUDE_LAUNCHER.probeMatch}' \u3092\u4F7F\u3044\u307E\u3059`);return DEFAULT_CLAUDE_LAUNCHER.probeMatch}return raw}var NOT_YET_APPLIED=[{key:"probe",get:c=>c.probe},{key:"probe_match",get:c=>c.probeMatch},{key:"exec_args",get:c=>c.execArgs},{key:"active_args",get:c=>c.activeArgs}];function sameAsDefault(key,parsed){
|
|
@@ -74,4 +74,5 @@ daemon,maxCycles:input.daemon?Number.MAX_SAFE_INTEGER:input.maxCycles??1,interva
|
|
|
74
74
|
env.PLAN_LOCK_RENEW_INTERVAL,Math.trunc(planLockTtlSec/3),1,"PLAN_LOCK_RENEW_INTERVAL="),planLockStealAttempts:num2(env.PLAN_LOCK_STEAL_ATTEMPTS,3,0,"PLAN_LOCK_STEAL_ATTEMPTS="),planLockPermanentMax:num2(env.PLAN_LOCK_PERMANENT_MAX,3,1,"PLAN_LOCK_PERMANENT_MAX="),scheduleMidcycleMax:num2(env.SCHEDULE_MIDCYCLE_MAX,6,1,"SCHEDULE_MIDCYCLE_MAX="),blockerRecoveryMaxPerDay:num2(env.BLOCKER_RECOVERY_MAX_PER_DAY,2,1,"BLOCKER_RECOVERY_MAX_PER_DAY="),releaseRerunAutoEnqueue:env.RELEASE_RERUN_AUTOENQUEUE_ENABLED!==
|
|
75
75
|
"false",releaseRerunMaxPerCause:num2(env.RELEASE_RERUN_MAX_PER_CAUSE,2,1,"RELEASE_RERUN_MAX_PER_CAUSE="),writebackMaxAgeDays:num2(env.AGENT_LOOP_WRITEBACK_MAX_AGE_DAYS,7,1,"AGENT_LOOP_WRITEBACK_MAX_AGE_DAYS="),scheduleTimezone:nonEmpty(env.AGENT_LOOP_SCHEDULE_TZ)??"Asia/Tokyo",counterTimezone:nonEmpty(env.AGENT_LOOP_COUNTER_TZ)??"Asia/Tokyo",compileCommand:local.compile_command!==void 0&&local.compile_command.length>0?local.compile_command:null,charterFile:nonEmpty(env.CHARTER_FILE)??nonEmpty(local.
|
|
76
76
|
charter_file)??"CONSTITUTION.md",charterEnabled:resolveCharterEnabled(env.CHARTER_ENABLED,local.charter_enabled,m=>warnings.push(m)),charterPrefix:charterWrapper(env.CHARTER_PREFIX,local.charter_prefix,"charter_prefix",m=>warnings.push(m)),charterSuffix:charterWrapper(env.CHARTER_SUFFIX,local.charter_suffix,"charter_suffix",m=>warnings.push(m)),planEnabled:resolveBoolSetting(env.PLAN_ENABLED,local.plan_enabled,"plan_enabled",true,"\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u3092\u5B9F\u884C\u3057\u307E\u3059",
|
|
77
|
-
m=>warnings.push(m)),ai:ai.config,operations:operations.operations,claudeLauncher:claudeLauncher.launcher,capacityProbe:capacityProbe.probe,prefetch:prefetch.hooks,preflight:preflight.hooks,configHash:ai.config.hash(),version:input.version,warnings,releaseOutcomeLogPath:releaseOutcomeLogPath(env)}}function localDate(timezone,now=new Date){const fmt=new Intl.DateTimeFormat("en-CA",{timeZone:timezone,year:"numeric",month:"2-digit",day:"2-digit"});
|
|
77
|
+
m=>warnings.push(m)),ai:ai.config,aiSource:{inline:local.ai,file:local.ai_config_file},operations:operations.operations,claudeLauncher:claudeLauncher.launcher,capacityProbe:capacityProbe.probe,prefetch:prefetch.hooks,preflight:preflight.hooks,configHash:ai.config.hash(),version:input.version,warnings,releaseOutcomeLogPath:releaseOutcomeLogPath(env)}}function localDate(timezone,now=new Date){const fmt=new Intl.DateTimeFormat("en-CA",{timeZone:timezone,year:"numeric",month:"2-digit",day:"2-digit"});
|
|
78
|
+
return fmt.format(now)}export{runPrefetch,runPreflight,formatHookWiring,formatHookIds,CapacityReporter,parseClaudeLauncher,evaluateOwnership,describeOperations,loopStateDir,localConfigPath,buildLoopConfig,localDate};
|
package/dist/cli.js
CHANGED
|
@@ -24,7 +24,7 @@ if(out.output!==void 0)out.unknown.push("--output");if(out.query!==void 0)out.un
|
|
|
24
24
|
void 0)out.unknown.push("--counts");if(out.scheduleGate!==void 0)out.unknown.push("--gate")}if(out.command==="task-loop"&&out.taskLoopAction!=="stop"&&out.stopForce){out.unknown.push("--force")}if(out.command==="task-loop"&&out.taskLoopAction!=="stop"&&out.stopDrain){out.unknown.push("--drain")}if(out.command==="task-loop"&&out.taskLoopAction==="stop"&&out.stopForce&&out.stopDrain){out.unknown.push("--force \u3068 --drain \u306F\u540C\u6642\u306B\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093");out.stopForce=
|
|
25
25
|
false;out.stopDrain=false}if(out.command==="task-loop"&&out.taskLoopAction!=="setup"){if(out.yes)out.unknown.push("--yes");if(out.ais!==void 0)out.unknown.push("--ai");if(out.workspace!==void 0)out.unknown.push("--workspace");if(out.aiConfigFile!==void 0)out.unknown.push("--ai-config-file");if(out.noAiConfigFile)out.unknown.push("--no-ai-config-file")}if(out.command==="task-loop"&&(out.taskLoopAction==="stop"||out.taskLoopAction==="status")){if(out.safe)out.unknown.push("--safe");if(out.daemon)out.
|
|
26
26
|
unknown.push("--daemon");if(out.forceRunner)out.unknown.push("--force-runner");if(out.engine!==void 0)out.unknown.push("--engine");if(out.interval!==void 0)out.unknown.push("--interval");if(out.maxCycles!==void 0)out.unknown.push("--max-cycles")}if(out.command==="task-loop"&&out.taskLoopAction==="setup"){if(out.engine!==void 0)out.unknown.push("--engine");if(out.safe)out.unknown.push("--safe");if(out.daemon)out.unknown.push("--daemon");if(out.forceRunner)out.unknown.push("--force-runner");if(out.
|
|
27
|
-
interval!==void 0)out.unknown.push("--interval");if(out.maxCycles!==void 0)out.unknown.push("--max-cycles")}return out}var VERSION=true?"0.
|
|
27
|
+
interval!==void 0)out.unknown.push("--interval");if(out.maxCycles!==void 0)out.unknown.push("--max-cycles")}return out}var VERSION=true?"0.17.1":"0.0.0-dev";var HELP=`twp ${VERSION} \u2014 TWP CLI
|
|
28
28
|
|
|
29
29
|
\u4F7F\u3044\u65B9:
|
|
30
30
|
twp \u5BFE\u8A71 TUI \u3092\u8D77\u52D5
|
|
@@ -149,9 +149,9 @@ TUI \u5185:
|
|
|
149
149
|
`);process.exit(1)}ignoreEpipe(process.stdout);ignoreEpipe(process.stderr);const args=parseArgv(process.argv.slice(2));if(args.command==="version"){process.stdout.write(`${VERSION}
|
|
150
150
|
`);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(" ")}
|
|
151
151
|
|
|
152
|
-
${HELP}`);process.exitCode=2;return}if(args.command==="domain"&&args.domain!==void 0){const{runDomain}=await import("./run-
|
|
153
|
-
refresh},version:VERSION});return}if(args.command==="api"){const{runApiCommand}=await import("./api-command-
|
|
152
|
+
${HELP}`);process.exitCode=2;return}if(args.command==="domain"&&args.domain!==void 0){const{runDomain}=await import("./run-DWQEHR6I.js");process.exitCode=await runDomain({domain:args.domain,...args.operation!==void 0?{operation:args.operation}:{},argv:args.domainArgv,help:args.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.
|
|
153
|
+
refresh},version:VERSION});return}if(args.command==="api"){const{runApiCommand}=await import("./api-command-UIL4WGMG.js");process.exitCode=await runApiCommand({argv:args.domainArgv,help:args.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},version:VERSION});return}if(args.command==="update"){const{runUpdate}=await import("./update-WDWUECN7.js");
|
|
154
154
|
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-VUWI4ERO.js");const options={profile:args.profile,method:args.loginMethod,tenant:args.tenant,noBrowser:args.loginNoBrowser,cliVersion:VERSION};const runner=args.command==="login"?runLogin:args.command==="logout"?runLogout:runWhoami;process.exitCode=
|
|
155
|
-
await runner(options);return}if(args.command==="task-loop"){const{runTaskLoop}=await import("./commands-
|
|
155
|
+
await runner(options);return}if(args.command==="task-loop"){const{runTaskLoop}=await import("./commands-XYKBLMXT.js");process.exitCode=await runTaskLoop({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,
|
|
156
156
|
scheduleGate:args.scheduleGate,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-HQJEXZHJ.js");process.exitCode=await runOneShot({prompt:args.prompt??"",fromStdin:args.promptFromStdin,mode:args.mode??"dev",...args.permissionMode!==void 0?{permissionMode:args.permissionMode}:{},...args.model!==void 0?{model:args.model}:{},...args.profile!==void 0?{profile:args.
|
|
157
157
|
profile}:{},version:VERSION});return}const{startTui}=await import("./app-LLSZV6SM.js");await startTui({mode:args.mode,permissionMode:args.permissionMode,model:args.model,profile:args.profile,noTui:args.noTui||!process.stdout.isTTY,doctor:args.doctor,version:VERSION})}await main();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{EngineNotConfiguredError,NoopEngine,UnknownEngineError,aiUnavailableLabel,assertKnownEngine,failureHint,isAiUnavailable,needsHumanToRestoreAi}from"./chunk-ZOOEH7ZE.js";import{CapacityReporter,buildLoopConfig,describeOperations,evaluateOwnership,formatHookIds,formatHookWiring,localDate,loopStateDir,runPrefetch,runPreflight}from"./chunk-
|
|
4
|
-
import{AgentLoopApi,REQUIRE_ZERO_STATUS,ScheduleApi,collectDue,describeError,filterByStatus,gateStatus,isPermanent,nowInZone,parseCounts,pick,pickString,promptSection}from"./chunk-N56AWWTM.js";import{compareVersionCores,parseVersionCore}from"./chunk-DXXFUNYN.js";import{killProcessTree,system32}from"./chunk-N2UVRM3Z.js";import{joinFor}from"./chunk-PMOUHEJQ.js";import{PRIVATE_PROJECT_REF,isPrivateProjectRef,privateProjectId,
|
|
5
|
-
AuthSession}from"./chunk-63LDNYGW.js";import{extractLeadingTaskKey}from"./chunk-II5RVJQN.js";import{effectiveApiUrl,resolveProfile}from"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{resolveProjectRef,uuidProjectIdPolicy}from"./chunk-5QCAIKFE.js";import"./chunk-VSJBJXZO.js";import fs11 from"fs";import path9 from"path";import{execFileSync}from"child_process";import fs from"fs";import path from"path";var DEFAULT_GRACE_MS=6e4;var InstanceLock=class{constructor(lockDir2,opts={}){this.lockDir=lockDir2;this.opts=opts}lockDir;opts;owned=null;acquire(){const mine=this.tryMkdir();if(mine)return{acquired:true,reason:"",note:null};const oldPid=this.readPid();if(oldPid!==null){if(this.isLoop(oldPid)){return{acquired:false,reason:`\u540C\u3058\u30DE\u30B7\u30F3\u3067\u5225\u306E task-loop \u304C\u7A3C\u50CD\u4E2D\u3067\u3059\uFF08pid=${oldPid} / \u30ED\u30C3\u30AF: ${this.lockDir}\uFF09`,note:null}}const note=`\
|
|
3
|
+
import{EngineNotConfiguredError,NoopEngine,UnknownEngineError,aiUnavailableLabel,assertKnownEngine,failureHint,isAiUnavailable,needsHumanToRestoreAi}from"./chunk-ZOOEH7ZE.js";import{CapacityReporter,buildLoopConfig,describeOperations,evaluateOwnership,formatHookIds,formatHookWiring,localDate,loopStateDir,runPrefetch,runPreflight}from"./chunk-SQSVA6AT.js";import{claudeConfigDir,exclusiveInflightEntries,formatExclusiveEntry,normalizeSkillName,reloadAiConfig,resolveDetectDeps,skillOfItem,
|
|
4
|
+
spawnSyncResolved}from"./chunk-H3JTPDCJ.js";import{AgentLoopApi,REQUIRE_ZERO_STATUS,ScheduleApi,collectDue,describeError,filterByStatus,gateStatus,isPermanent,nowInZone,parseCounts,pick,pickString,promptSection}from"./chunk-N56AWWTM.js";import{compareVersionCores,parseVersionCore}from"./chunk-DXXFUNYN.js";import{killProcessTree,system32}from"./chunk-N2UVRM3Z.js";import{joinFor}from"./chunk-PMOUHEJQ.js";import{PRIVATE_PROJECT_REF,isPrivateProjectRef,privateProjectId,
|
|
5
|
+
projectFileKey}from"./chunk-GY7KI5E5.js";import{AuthSession}from"./chunk-63LDNYGW.js";import{extractLeadingTaskKey}from"./chunk-II5RVJQN.js";import{effectiveApiUrl,resolveProfile}from"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{resolveProjectRef,uuidProjectIdPolicy}from"./chunk-5QCAIKFE.js";import"./chunk-VSJBJXZO.js";import fs11 from"fs";import path9 from"path";import{execFileSync}from"child_process";import fs from"fs";import path from"path";var DEFAULT_GRACE_MS=6e4;var InstanceLock=class{constructor(lockDir2,opts={}){this.lockDir=lockDir2;this.opts=opts}lockDir;opts;owned=null;acquire(){const mine=this.tryMkdir();if(mine)return{acquired:true,reason:"",note:null};const oldPid=this.readPid();if(oldPid!==null){if(this.isLoop(oldPid)){return{acquired:false,reason:`\u540C\u3058\u30DE\u30B7\u30F3\u3067\u5225\u306E task-loop \u304C\u7A3C\u50CD\u4E2D\u3067\u3059\uFF08pid=${oldPid} / \u30ED\u30C3\u30AF: ${this.lockDir}\uFF09`,note:null}}const note=`\
|
|
6
6
|
\u30ED\u30C3\u30AF\u306EPID ${oldPid} \u306F\u5225\u306E\u30D7\u30ED\u30BB\u30B9\u306B\u518D\u5229\u7528\u3055\u308C\u3066\u3044\u307E\u3059\uFF08\u30EB\u30FC\u30D7\u3067\u306F\u306A\u3044\uFF09\u2192 \u6B8B\u9AB8\u3068\u3057\u3066\u5F15\u304D\u53D6\u308A\u307E\u3059`;return this.takeOver(note)}const age=this.lockAgeMs();const grace=this.opts.graceMs??DEFAULT_GRACE_MS;if(age===null||age<grace){return{acquired:false,reason:`\u30ED\u30C3\u30AF\u304C\u4F5C\u6210\u76F4\u5F8C\u306E\u305F\u3081\u5F85\u6A5F\u5074\u306B\u5012\u3057\u307E\u3059\uFF08\u30ED\u30C3\u30AF: ${this.
|
|
7
7
|
lockDir}\uFF09`,note:null}}return this.takeOver(`\u30ED\u30C3\u30AF\u306B pid \u304C\u306A\u304F\u4F5C\u6210\u304B\u3089 ${Math.trunc(age/1e3)} \u79D2\u7D4C\u904E\u3057\u3066\u3044\u307E\u3059 \u2192 \u6B8B\u9AB8\u3068\u3057\u3066\u5F15\u304D\u53D6\u308A\u307E\u3059`)}release(){if(!this.owned)return;if(this.readPid()===process.pid){fs.rmSync(this.owned,{recursive:true,force:true})}this.owned=null}takeOver(note){fs.rmSync(this.lockDir,{recursive:true,force:true});if(this.tryMkdir())return{acquired:true,
|
|
8
8
|
reason:"",note};return{acquired:false,reason:`\u30ED\u30C3\u30AF\u306E\u5F15\u304D\u53D6\u308A\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08\u5225\u30D7\u30ED\u30BB\u30B9\u304C\u5148\u306B\u53D6\u5F97\u3057\u305F\u53EF\u80FD\u6027\uFF09: ${this.lockDir}`,note:null}}tryMkdir(){try{fs.mkdirSync(path.dirname(this.lockDir),{recursive:true,mode:448});fs.mkdirSync(this.lockDir,{mode:448})}catch{return false}try{fs.writeFileSync(path.join(this.lockDir,"pid"),`${process.pid}
|
|
@@ -23,10 +23,11 @@ const raw=env[key];if(raw===void 0)continue;const value=raw.trim();const ok=key.
|
|
|
23
23
|
\uFF0F ${via}\uFF09`}}raw=d.readFileSync(file)}catch(err){return{state:"unknown",file,detail:`\u30C8\u30E9\u30B9\u30C8\u8A2D\u5B9A\u3092\u8AAD\u3081\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${file}: ${err.message}\uFF09`}}let projects;try{projects=JSON.parse(raw).projects}catch{return{state:"unknown",file,detail:`\u30C8\u30E9\u30B9\u30C8\u8A2D\u5B9A\u3092\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${file}\uFF09`}}if(typeof projects!=="object"||projects===null){return{state:"\
|
|
24
24
|
untrusted",file,detail:`\u30C8\u30E9\u30B9\u30C8\u8A2D\u5B9A\u306B projects \u304C\u3042\u308A\u307E\u305B\u3093\uFF08${file}\uFF09`}}const table=projects;for(const key of workspaceKeys(workspace,deps)){const entry=table[key];if(typeof entry!=="object"||entry===null)continue;if(entry.hasTrustDialogAccepted===true){return{state:"trusted",file,detail:`\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u306F\u30C8\u30E9\u30B9\u30C8\u6E08\u307F\u3067\u3059\uFF08${key} \uFF0F ${file}\uFF09`}}}return{state:"u\
|
|
25
25
|
ntrusted",file,detail:`\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u304C\u672A\u30C8\u30E9\u30B9\u30C8\u3067\u3059\uFF08${workspace} \uFF0F ${file}\uFF09`}}function workspaceKeys(workspace,deps){const keys=[workspace];try{const real=(deps.realpathSync??fs4.realpathSync)(workspace);if(real!==workspace)keys.push(real)}catch{}return keys}var TRUST_GATE_TIMEOUT_MS=30*6e4;var PROCEED={wait:false,logs:[],note:null};var TrustGate=class{constructor(deps){this.deps=deps}deps;since=null;expired=false;now(){
|
|
26
|
-
return(this.deps.now??Date.now)()}get timeoutMs(){return this.deps.timeoutMs??TRUST_GATE_TIMEOUT_MS}evaluate(){
|
|
27
|
-
since===null?null:this.now()-this.since;this.since=null;this.expired=false;return{wait:false,logs:waited2===null?[]:[` \u2705 \u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u306E\u30C8\u30E9\u30B9\u30C8\u304C\u5C0E\u51FA\u3055\u308C\u307E\u3057\u305F\uFF08\u5F85\u6A5F ${Math.round(waited2/1e3)}\u79D2\uFF09\u3002\u5B9F\u884C\u3092\u518D\u958B\u3057\u307E\u3059`],note:null}}if(r.state==="unknown"){return{wait:false,logs:[` \u26A0\uFE0F ${r.detail}\
|
|
28
|
-
note:null}}if(this.expired)return{wait:false,logs:[this.expiredLog()],note:expiredNote()};const now=this.now();if(this.since===null){this.since=now;return{wait:true,logs:[` \u23F8 ${r.detail}`,` \u30C8\u30E9\u30B9\u30C8\u304C\u5C0E\u51FA\u3055\u308C\u308B\u307E\u3067\u30A2\u30A4\u30C6\u30E0\u3092\u53D6\u308A\u307E\u305B\u3093\uFF08\u6700\u5927${Math.round(this.timeoutMs/
|
|
29
|
-
note:null}}const waited=now-this.since;if(waited>=this.timeoutMs){this.expired=true;return{wait:false,logs:[this.expiredLog()],note:expiredNote()}}return{wait:true,logs:[` \u23F8 ${r.detail}\uFF08\u5F85\u6A5F ${Math.round(waited/1e3)}\u79D2\uFF09`],
|
|
26
|
+
return(this.deps.now??Date.now)()}get timeoutMs(){return this.deps.timeoutMs??TRUST_GATE_TIMEOUT_MS}evaluate(){const enabled=typeof this.deps.enabled==="function"?this.deps.enabled():this.deps.enabled;if(!enabled)return PROCEED;let r;try{r=this.deps.check()}catch(err){return{wait:false,logs:[` \u26A0\uFE0F \u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u306E\u30C8\u30E9\u30B9\u30C8\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${err.message}\uFF09\u3002\u901A\u5E38\u3069\u304A\u308A\u7D9A\u884C\u3057\u307E\u3059`],
|
|
27
|
+
note:null}}if(r.state==="trusted"){const waited2=this.since===null?null:this.now()-this.since;this.since=null;this.expired=false;return{wait:false,logs:waited2===null?[]:[` \u2705 \u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u306E\u30C8\u30E9\u30B9\u30C8\u304C\u5C0E\u51FA\u3055\u308C\u307E\u3057\u305F\uFF08\u5F85\u6A5F ${Math.round(waited2/1e3)}\u79D2\uFF09\u3002\u5B9F\u884C\u3092\u518D\u958B\u3057\u307E\u3059`],note:null}}if(r.state==="unknown"){return{wait:false,logs:[` \u26A0\uFE0F ${r.detail}\
|
|
28
|
+
\u3002\u672A\u30C8\u30E9\u30B9\u30C8\u3068\u306F\u65AD\u5B9A\u3067\u304D\u306A\u3044\u305F\u3081\u7D9A\u884C\u3057\u307E\u3059`],note:null}}if(this.expired)return{wait:false,logs:[this.expiredLog()],note:expiredNote()};const now=this.now();if(this.since===null){this.since=now;return{wait:true,logs:[` \u23F8 ${r.detail}`,` \u30C8\u30E9\u30B9\u30C8\u304C\u5C0E\u51FA\u3055\u308C\u308B\u307E\u3067\u30A2\u30A4\u30C6\u30E0\u3092\u53D6\u308A\u307E\u305B\u3093\uFF08\u6700\u5927${Math.round(this.timeoutMs/
|
|
29
|
+
6e4)}\u5206\uFF09\u3002\u672A\u30C8\u30E9\u30B9\u30C8\u306E\u307E\u307E\u5B9F\u884C\u3059\u308B\u3068 permissions.allow \u304C\u7121\u8996\u3055\u308C\u3001\u6210\u679C\u3092\u51FA\u3057\u3066\u3082 untrusted \u3067\u8A18\u9332\u3055\u308C\u307E\u3059`],note:null}}const waited=now-this.since;if(waited>=this.timeoutMs){this.expired=true;return{wait:false,logs:[this.expiredLog()],note:expiredNote()}}return{wait:true,logs:[` \u23F8 ${r.detail}\uFF08\u5F85\u6A5F ${Math.round(waited/1e3)}\u79D2\uFF09`],
|
|
30
|
+
note:null}}expiredLog(){return` \u26D4 ${Math.round(this.timeoutMs/6e4)}\u5206\u5F85\u3063\u3066\u3082\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u306E\u30C8\u30E9\u30B9\u30C8\u304C\u5C0E\u51FA\u3055\u308C\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u7121\u8A00\u306E\u7121\u7A3C\u50CD\u3092\u907F\u3051\u308B\u305F\u3081\u901A\u5E38\u52D5\u4F5C\u3078\u843D\u3068\u3057\u307E\u3059\uFF08untrusted \u3067\u5931\u6557\u8A18\u9332\u304C\u6B8B\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\uFF09\u3002\u78BA\u8A8D: runner-state status \uFF0F \u67A0\u306E .claude.json \u306E projects[<workspace>].hasTrustDialogAccepted`}};
|
|
30
31
|
function expiredNote(){return["\u3010\u8B66\u544A: \u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u304C\u672A\u30C8\u30E9\u30B9\u30C8\u3067\u3059\u3011","\u3053\u306E\u30DE\u30B7\u30F3\u306E claude \u306F\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u3092\u672A\u30C8\u30E9\u30B9\u30C8\u306E\u72B6\u614B\u3067\u8D77\u52D5\u3057\u3066\u3044\u307E\u3059\u3002","permissions.allow \u304C\u7121\u8996\u3055\u308C\u3001\u6210\u679C\u3092\u51FA\u3057\u5207\u3063\u3066\u3082\u5B9F\u884C\u7D50\u679C\u304C untrusted \u3068\u3057\u3066\u8A18\u9332\u3055\u308C\u308B\u3053\u3068\u304C\u3042\u308A\u307E\u3059\u3002",
|
|
31
32
|
"\u30C8\u30E9\u30B9\u30C8\u306E\u5C0E\u51FA\uFF08runner-state \u306E2\u5206\u3054\u3068\u306E\u6CBB\u7652\uFF09\u304C30\u5206\u4EE5\u4E0A\u6210\u7ACB\u3057\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u3053\u306E\u72B6\u614B\u306E\u307E\u307E\u5B9F\u884C\u3057\u3066\u3044\u307E\u3059\u3002"].join("\n")}import os from"os";var RunnerRegistrationError=class extends Error{};var RunnerSession=class{constructor(api,config,log,now=()=>Date.now()){this.api=api;this.config=config;this.log=log;this.now=now;this.forcePending=config.forceRunner;this.capacity=config.capacityProbe===null?null:new CapacityReporter(config.capacityProbe,config.workspace,m=>this.log.log(m),process.env,this.now)}api;config;log;now;registered=false;heartbeatTimeoutServer=null;forcePending;hooksPayloadWarningLogged=false;timer=null;phase="idle";currentItemId="";lastTickAt=0;lastOkAt=0;failures=0;sending=false;silenceWarned=false;capacity;capacityRefresh(force){
|
|
32
33
|
const reporter=this.capacity;if(reporter===null)return null;return(force?reporter.refresh():reporter.refreshIfDue()).catch(err=>{this.log.log(` \u26A0\uFE0F capacity_probe \u3067\u4F8B\u5916\u304C\u767A\u751F\u3057\u307E\u3057\u305F\uFF08${err.message}\uFF09\u3002\u67A0\u60C5\u5831\u306A\u3057\u3067\u7D9A\u884C\u3057\u307E\u3059`)})}payload(phase,itemId="",force=false){const p={runner_id:this.config.runnerId,run_id:this.config.runId,phase,pid:process.pid,safe_mode:this.config.safeMode};const host=os.
|
|
@@ -178,10 +179,12 @@ api.update(itemId,rest,runId||this.config.runId);if(res.ok){fs7.rmSync(file,{for
|
|
|
178
179
|
\u2192 \u7D50\u679C\u306F\u7834\u68C4\u3057\u307E\u3059`)}else if(res.status!==null&&res.status>=400&&res.status<500&&res.status!==408&&res.status!==429){fs7.rmSync(file,{force:true});this.log.log(` \u26D4 \u30B5\u30FC\u30D0\u306B\u6052\u4E45\u7684\u306B\u62D2\u5426\u3055\u308C\u305F\u305F\u3081\u7834\u68C4\u3057\u307E\u3059\uFF08http=${res.status}\uFF09: item=${itemId}`)}else{this.log.log(` \u26A0\uFE0F \u518D\u9001\u306B\u5931\u6557\uFF08${describeError(res)}\uFF09: item=${itemId}\u3002\u6B21\u30B5\u30A4\u30AF\u30EB\u3067\u518D\u8A66\
|
|
179
180
|
\u884C\u3057\u307E\u3059`)}}return recorded}};function exitReasonFor(outcome){if(outcome==="ok")return"ok";if(outcome==="timeout")return"timeout";if(outcome==="rate-limited")return"rate_limited";if(outcome==="aborted")return"interrupted";if(outcome==="max-turns")return"max_turns";return"error"}function withFailureHint(base,output){const hint=failureHint(output);return hint===""?base:`${base} | ${hint}`}var STOP_WAIT_MAX_SEC=3600;var AI_RECOVERY_HINT="\u78BA\u8A8D: claude-auto-switch status \uFF0F \u5404AI CLI\u306E\u30ED\u30B0\u30A4\u30F3\u72B6\u614B\uFF08twp task-loop setup \u3067\u691C\u51FA\u7D50\u679C\u304C\u51FA\u307E\u3059\uFF09";
|
|
180
181
|
var ABORT_DRAIN_TIMEOUT_MS=15e3;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=>{const statusId=Object.prototype.hasOwnProperty.call(REQUIRE_ZERO_STATUS,key)?REQUIRE_ZERO_STATUS[key]:void 0;if(!statusId)return null;const{total}=await deps.projectApi.countByStatus(deps.config.projectId,statusId);return total}});this.engine=
|
|
181
|
-
deps.engine;this.releaseLog=new ReleaseOutcomeLog(deps.config.releaseOutcomeLogPath,deps.log);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:()=>this.hasPendingItems(),reregister:async()=>{deps.runner.registered=false;await deps.runner.registerOrThrow()},...deps.sleepFn?{sleepFn:deps.sleepFn}:{}});this.trustGate=deps.trustGate??new TrustGate({enabled:deps.
|
|
182
|
-
config.ai.usesAi("claude"),check:()=>checkWorkspaceTrust(deps.config.workspace,{launcherBin:deps.config.claudeLauncher.bin})});this.timestamp=new Date().toISOString().replace(/[-:]/g,"").replace(/\..*$/,"")}deps;writeback;schedule;planLock;engine;releaseLog;postDeps;timestamp;deferredIds=new Set;midcycleEnqueued=0;aborting=false;draining=false;drainExitCode=0;drainWaiters=new Set;itemInFlight=null;ownershipLostItemId=null;abortDrained=null;cyclePreflightSection="";trustGate;
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
deps.engine;this.releaseLog=new ReleaseOutcomeLog(deps.config.releaseOutcomeLogPath,deps.log);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:()=>this.hasPendingItems(),reregister:async()=>{deps.runner.registered=false;await deps.runner.registerOrThrow()},...deps.sleepFn?{sleepFn:deps.sleepFn}:{}});this.trustGate=deps.trustGate??new TrustGate({enabled:()=>deps.
|
|
183
|
+
config.ai.usesAi("claude"),check:()=>checkWorkspaceTrust(deps.config.workspace,{launcherBin:deps.config.claudeLauncher.bin})});this.timestamp=new Date().toISOString().replace(/[-:]/g,"").replace(/\..*$/,"")}deps;writeback;schedule;planLock;engine;releaseLog;postDeps;timestamp;deferredIds=new Set;midcycleEnqueued=0;aborting=false;draining=false;drainExitCode=0;drainWaiters=new Set;itemInFlight=null;ownershipLostItemId=null;abortDrained=null;cyclePreflightSection="";trustGate;lastAiReloadWarning="";reloadAiConfig(){
|
|
184
|
+
const{config,log}=this.deps;const r=reloadAiConfig(config.ai,config.aiSource.inline,config.aiSource.file,config.workspace);const warning=r.warnings.join("\n");if(warning!==""&&warning!==this.lastAiReloadWarning){for(const w of r.warnings)log.log(` \u26A0\uFE0F ${w}`)}else if(warning===""&&this.lastAiReloadWarning!==""&&r.status!=="skipped"){log.log("AI \u5272\u5F53\u30D5\u30A1\u30A4\u30EB\u3092\u518D\u3073\u8AAD\u3081\u308B\u3088\u3046\u306B\u306A\u308A\u307E\u3057\u305F")}this.lastAiReloadWarning=
|
|
185
|
+
warning;if(r.status!=="updated")return;config.configHash=config.ai.hash();log.log(r.hashBefore===r.hashAfter?`AI \u5272\u5F53\u30D5\u30A1\u30A4\u30EB\u306E\u5909\u66F4\u3092\u53CD\u6620\u3057\u307E\u3057\u305F\uFF08config_hash ${r.hashAfter} \u306F\u4E0D\u5909\uFF1D\u9396\u304B\u30B3\u30E1\u30F3\u30C8\u3060\u3051\u306E\u5909\u66F4\uFF09`:`AI \u5272\u5F53\u30D5\u30A1\u30A4\u30EB\u306E\u5909\u66F4\u3092\u53CD\u6620\u3057\u307E\u3057\u305F\uFF08config_hash ${r.hashBefore} \u2192 ${r.hashAfter}\uFF09`)}sleep(ms){
|
|
186
|
+
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;
|
|
187
|
+
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}\
|
|
185
188
|
\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){
|
|
186
189
|
const{config,log,api}=this.deps;const intervalSec=config.ownershipCheckIntervalSec;if(intervalSec<=0)return{stop:()=>{}};let stopped=false;let checking=false;let unknownLogged=false;const timer=setInterval(()=>{if(stopped||checking)return;checking=true;void(async()=>{try{const res=await api.getItem(itemId);const check=evaluateOwnership(res.json?.item??null,config.runnerId,config.runId);if(stopped)return;if(check.verdict==="unknown"){if(!unknownLogged){unknownLogged=true;log.log(` \u26A0\uFE0F \u6240\u6709\u6A29\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\
|
|
187
190
|
\u3093\u3067\u3057\u305F\uFF08${check.reason}\uFF09\u3002\u76E3\u8996\u306F\u7D9A\u3051\u307E\u3059\u304C\u5B9F\u884C\u306F\u6B62\u3081\u307E\u305B\u3093`)}return}if(check.verdict!=="lost")return;stopped=true;clearInterval(timer);this.ownershipLostItemId=itemId;log.log(` \u26D4 \u5B9F\u884C\u4E2D\u306B\u3053\u306E\u30A2\u30A4\u30C6\u30E0\u306E\u6240\u6709\u6A29\u3092\u5931\u3044\u307E\u3057\u305F: ${check.reason}`);log.log(" **AI \u3092\u3053\u3053\u3067\u505C\u6B62\u3057\u307E\u3059**\uFF08\u7D9A\u3051\u3066\u3082\u7D50\u679C\u306F\u66F8\u304D\u623B\u305B\u305A\u3001PR\u30FB\u30B3\u30E1\u30F3\u30C8\u3060\u3051\u304C\u91CD\u8907\u3057\u307E\u3059\uFF09");
|
|
@@ -190,7 +193,7 @@ await this.engine.abort?.();if(!inFlight){this.abortDrained=null;return}this.dep
|
|
|
190
193
|
resolve()},ABORT_DRAIN_TIMEOUT_MS);timer.unref?.()})]);if(timer!==null)clearTimeout(timer);this.abortDrained=null}async shutdown(){await this.planLock.release("failed")}async run(){const{config,log,runner}=this.deps;log.log(describeOperations(config.operations));if(!config.planEnabled){log.log("\u8A08\u753B\u30D5\u30A7\u30FC\u30BA\u306F\u7121\u52B9\u3067\u3059\uFF08plan_enabled=false\uFF09\u3002\u30AD\u30E5\u30FC\u304C\u7A7A\u3067\u3082\u8A08\u753BAI\u3092\u8D77\u52D5\u305B\u305A\u3001\u7A4D\u307E\u308C\u305F\u4ED5\u4E8B\u306E\u5B9F\u884C\u3060\u3051\u3092\u884C\u3044\u307E\u3059\u3002")}
|
|
191
194
|
let cycle=0;let noProgressStreak=0;let unavailableStreak=0;let undeterminedStreak=0;let exitCode=0;while(cycle<config.maxCycles){if(this.aborting){log.log("\u4E2D\u65AD\u30B7\u30B0\u30CA\u30EB\u3092\u53D7\u3051\u3066\u3044\u308B\u305F\u3081\u3001\u65B0\u3057\u3044\u30B5\u30A4\u30AF\u30EB\u3092\u958B\u59CB\u3057\u307E\u305B\u3093\u3002");break}if(this.draining){log.log(`\u30C9\u30EC\u30A4\u30F3\u8981\u6C42\u3092\u53D7\u3051\u3066\u3044\u308B\u305F\u3081\u3001\u65B0\u3057\u3044\u30B5\u30A4\u30AF\u30EB\u3092\u958B\u59CB\u3057\u307E\u305B\u3093\uFF08\u7D42\u4E86\u30B3\u30FC\u30C9 ${this.
|
|
192
195
|
drainExitCode}\uFF09\u3002`);exitCode=this.drainExitCode;break}cycle+=1;const cycleStart=Date.now();log.separator();log.log(`========== Cycle ${cycle}${config.daemon?"":`/${config.maxCycles}`} \u958B\u59CB ==========`);log.separator();await runner.beat("idle");log.log(formatHookWiring(config.prefetch,config.preflight));if(config.preflight.length>0){log.log(`\u74B0\u5883\u306E\u524D\u63D0\u6761\u4EF6\u3092\u78BA\u8A8D\u4E2D\uFF08\u30D5\u30C3\u30AF ${config.preflight.length}\u4EF6\uFF09...`)}this.
|
|
193
|
-
cyclePreflightSection=await runPreflight(config.preflight,config.workspace,m=>log.log(m));for(const line of normalizeGitIdentity(config.workspace,config.gitIdentity).logs)log.log(line);let planSkippedNoLock=false;const resent=await this.writeback.retryPending();for(const itemId of resent)await this.schedule.recordByItem(itemId,"completed");const reclaimRes=await this.deps.api.reclaim();if(!reclaimRes.ok){log.log(` \u26A0\uFE0F \u6B7B\u3093\u3060\u30E9\u30F3\u30CA\u30FC\u306E\u30A2\u30A4\u30C6\u30E0\u56DE\u53CEAPI\u304C\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${describeError(
|
|
196
|
+
cyclePreflightSection=await runPreflight(config.preflight,config.workspace,m=>log.log(m));this.reloadAiConfig();for(const line of normalizeGitIdentity(config.workspace,config.gitIdentity).logs)log.log(line);let planSkippedNoLock=false;const resent=await this.writeback.retryPending();for(const itemId of resent)await this.schedule.recordByItem(itemId,"completed");const reclaimRes=await this.deps.api.reclaim();if(!reclaimRes.ok){log.log(` \u26A0\uFE0F \u6B7B\u3093\u3060\u30E9\u30F3\u30CA\u30FC\u306E\u30A2\u30A4\u30C6\u30E0\u56DE\u53CEAPI\u304C\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${describeError(
|
|
194
197
|
reclaimRes)}\uFF09\u3002\u53D6\u308A\u6B8B\u3057\u304C\u6B8B\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059`)}await this.reclaimStaleProcessing();const trust=this.trustGate.evaluate();for(const line of trust.logs)log.log(line);if(trust.note!==null){this.cyclePreflightSection=this.cyclePreflightSection===""?trust.note:`${this.cyclePreflightSection}
|
|
195
198
|
|
|
196
199
|
${trust.note}`}if(trust.wait){await runner.beat("waiting");if(cycle<config.maxCycles)await this.sleepUnlessDraining(config.intervalSec*1e3);continue}const hadPending=await this.hasPendingItems();this.midcycleEnqueued=0;this.deferredIds=new Set;await this.enqueueDueScheduled(false);const planSkippedDisabled=!hadPending&&!config.planEnabled;if(hadPending){log.log("\u30AD\u30E5\u30FC\u306Bpending\u30A2\u30A4\u30C6\u30E0\u304C\u3042\u308A\u307E\u3059\u3002\u8A08\u753B\u3092\u30B9\u30AD\u30C3\u30D7\u3057\u3066\u5B9F\u884C\u306B\u9032\u307F\u307E\u3059\u3002")}else if(planSkippedDisabled){
|
|
@@ -318,12 +321,12 @@ const startedAtMs=now();let warned="";let done=false;const check=()=>{if(done)re
|
|
|
318
321
|
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`)}
|
|
319
322
|
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 fs10 from"fs";import path8 from"path";var POLL_MS=1e3;var MAX_STOP_BYTES=4096;var MAX_AT_LENGTH=64;function markerPath(lockDir2,kind){return path8.join(lockDir2,kind)}function requestMarker(lockDir2,kind,pid,deps={}){const target=markerPath(lockDir2,kind);const write=deps.writeFileSync??((p,d)=>fs10.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()})}
|
|
320
323
|
`);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=>fs10.readFileSync(p,"utf8"));const size=deps.statSize??(p=>fs10.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(
|
|
321
|
-
pid)||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=>fs10.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-
|
|
324
|
+
pid)||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=>fs10.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-27EZS2S3.js");const{DEFAULT_PREFLIGHT_HOSTS}=await import("./ai-dispatch-27EZS2S3.js");const extraHosts=config.
|
|
322
325
|
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},compileCommand:config.compileCommand??void 0,launcherBin:config.claudeLauncher.bin,...extraHosts.length>0?{preflightHosts:[...DEFAULT_PREFLIGHT_HOSTS,...extraHosts]}:{}})}function lockDir(config){
|
|
323
326
|
return path9.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}
|
|
324
327
|
`);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.
|
|
325
328
|
message}
|
|
326
|
-
`);return 1}const projectId=project.id;if(opts.action==="setup"){const{runSetup,parseAiList}=await import("./setup-
|
|
329
|
+
`);return 1}const projectId=project.id;if(opts.action==="setup"){const{runSetup,parseAiList}=await import("./setup-AJ56N6XO.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(" / ")}
|
|
327
330
|
`);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}:{}})}const config=buildLoopConfig({projectId,projectRef,apiUrl,safeMode:opts.
|
|
328
331
|
safe,daemon:opts.daemon,...opts.maxCycles!==void 0?{maxCycles:opts.maxCycles}:{},...opts.interval!==void 0?{intervalSec:opts.interval}:{},forceRunner:opts.forceRunner,...opts.engine!==void 0?{engine:opts.engine}:{},version:opts.version});const api=new AgentLoopApi({apiUrl,projectId,session});if(opts.action==="status"||opts.action==="schedule"){for(const warning of config.warnings)process.stderr.write(`\u26A0\uFE0F ${warning}
|
|
329
332
|
`)}if(opts.action==="status")return showStatus(api,config);if(opts.action==="schedule"){const{runScheduleCommand}=await import("./schedule-command-YPKIO3FK.js");return runScheduleCommand({api,projectApi,config},{now:opts.scheduleNow,counts:opts.scheduleCounts,gate:opts.scheduleGate,verbose:opts.verbose===true})}if(config.engine===""){process.stderr.write(`${new EngineNotConfiguredError().message}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{isRecord,pick,requireResolved,withResolved}from"./chunk-GFC2ASHE.js";import{LIST_FLAGS,LIST_PAGING_HELP,envelopePaging,nonEmpty,positiveInteger}from"./chunk-
|
|
3
|
+
import{isRecord,pick,requireResolved,withResolved}from"./chunk-GFC2ASHE.js";import{LIST_FLAGS,LIST_PAGING_HELP,envelopePaging,nonEmpty,positiveInteger}from"./chunk-2VISRLWS.js";import{ApiResponseError,UsageError}from"./chunk-M3GWY6NT.js";import{collapsesInUrlPath,safeProjectIdPolicy}from"./chunk-5QCAIKFE.js";import"./chunk-VSJBJXZO.js";var LIST_COLUMNS=["id","code","name","status","effective_status"];var GET_COLUMNS=["id","code","name","status","effective_status","display_flg","closed_flg","task_enabled_flg","start_date","end_date","created_at","updated_at"];var MEMBER_COLUMNS=["user_id","user_name","user_email","role","alias","department_name"];function memberItems(body){const list=isRecord(body)?body["list"]:void 0;if(!Array.isArray(list)){throw new ApiResponseError("\u30E1\u30F3\u30D0\u30FC\u4E00\u89A7\u306E\u5FDC\u7B54\u306B list \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
4
4
|
return list}var listPaging=envelopePaging({label:"\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u4E00\u89A7"});function listItems(body){return listPaging.items(body)}function projectObject(body){const project=isRecord(body)?body["project"]:void 0;if(!isRecord(project)){throw new ApiResponseError("\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u8A73\u7D30\u306E\u5FDC\u7B54\u306B project \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return project}
|
|
5
5
|
var projectDomain={name:"project",summary:"\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u4E00\u89A7\u30FB\u8A73\u7D30",operations:[{name:"list",summary:"\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3092\u4E00\u89A7\u3059\u308B",usage:"twp project list [--all] [--limit <\u4EF6\u6570>] [--cursor <\u30AB\u30FC\u30BD\u30EB>] [--keyword <\u8A9E>] [--status <\u72B6\u614B>]",description:"--output json \u306F API \u304C\u8FD4\u3059\u5168\u30D5\u30A3\u30FC\u30EB\u30C9\u3092\u51FA\u3057\u307E\u3059\u3002\n--output table / text / tsv \u306F\u8981\u7D04\u5217\uFF08id / code / name / status / effective_status\uFF09\u3067\u3059\u3002\n\u6B32\u3057\u3044\u5217\u3060\u3051\u3092\
|
|
6
6
|
\u6A5F\u68B0\u51E6\u7406\u3057\u305F\u3044\u3068\u304D\u306F --query \u3067\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08--query \u306F\u751F\u30C7\u30FC\u30BF\u306B\u5BFE\u3057\u3066\u8A55\u4FA1\u3055\u308C\u307E\u3059\uFF09\u3002\n\n"+LIST_PAGING_HELP,flags:[...LIST_FLAGS,{name:"--keyword",summary:"\u30B3\u30FC\u30C9\u30FB\u540D\u79F0\u306E\u90E8\u5206\u4E00\u81F4\u3067\u7D5E\u308A\u8FBC\u3080",takesValue:true,placeholder:"<\u8A9E>"},{name:"--status",summary:"\u30B9\u30C6\u30FC\u30BF\u30B9\u3067\u7D5E\u308A\u8FBC\u3080\uFF08\u4F8B: active\uFF09",
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{CURATED_PAGING_VOCABULARY,buildPrepareContext,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain}from"./chunk-KXFT226N.js";import"./chunk-WVS4W5FY.js";import"./chunk-63LDNYGW.js";import"./chunk-FKIZ5ZJU.js";import"./chunk-O52CUEDO.js";import"./chunk-QQRJLH6B.js";import"./chunk-7WEYBZSK.js";import"./chunk-JKSXUBND.js";import"./chunk-II5RVJQN.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";
|
|
4
|
+
import"./chunk-J7QYPKVK.js";import"./chunk-NHYMHCAT.js";import"./chunk-2VISRLWS.js";import"./chunk-M3GWY6NT.js";import"./chunk-5QCAIKFE.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{PromptAbortedError,promptText}from"./chunk-L37NS5L2.js";import{localConfigPath,parseClaudeLauncher}from"./chunk-
|
|
3
|
+
import{PromptAbortedError,promptText}from"./chunk-L37NS5L2.js";import{localConfigPath,parseClaudeLauncher}from"./chunk-SQSVA6AT.js";import{AiConfig,detectAiClis,formatDetection,isDetectableAi,isSelectable}from"./chunk-H3JTPDCJ.js";import"./chunk-N2UVRM3Z.js";import"./chunk-PMOUHEJQ.js";import"./chunk-GY7KI5E5.js";import"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";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\
|
|
4
4
|
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:
|
|
5
5
|
[...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));
|
|
6
6
|
const out=t=>rawOut(stripTerminalControls(t));const err=t=>rawErr(stripTerminalControls(t));const rawAsk=opts.ask??promptText;const ask=q=>rawAsk(stripTerminalControls(q));const detect=opts.detect??detectAiClis;try{return await setupFlow(opts,{env,out,err,ask,detect})}catch(e){if(e instanceof PromptAbortedError){err("\n\u4E2D\u6B62\u3057\u307E\u3057\u305F\u3002\u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB\u306F\u4F5C\u6210\u3057\u3066\u3044\u307E\u305B\u3093\u3002\n \u5BFE\u8A71\u305B\u305A\u306B\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002\n");
|