@tocca-systems/twp-cli 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.public.md +20 -0
- package/README.md +70 -6
- package/dist/{ai-dispatch-27EZS2S3.js → ai-dispatch-PNA4UF4I.js} +2 -2
- package/dist/{api-command-BH6ILQNX.js → api-command-2OPQMSTE.js} +24 -24
- package/dist/{app-4LRDLLTV.js → app-FZT4U3VG.js} +146 -82
- package/dist/auto-update-CV2MM32C.js +4 -0
- package/dist/auto-update-worker-ML7EBNQW.js +16 -0
- package/dist/{backlog-AYEKG575.js → backlog-NV7Z76R3.js} +1 -1
- package/dist/{chunk-U4QQNRXF.js → chunk-3SNMDSCW.js} +22 -22
- package/dist/chunk-3WHC4FSG.js +15 -0
- package/dist/chunk-5WGOHFAS.js +3 -0
- package/dist/{chunk-SQSVA6AT.js → chunk-BYRM4NSC.js} +1 -1
- package/dist/chunk-DEVIQH5U.js +18 -0
- package/dist/{chunk-RQFG3OUL.js → chunk-FOFV2MNL.js} +1 -1
- package/dist/chunk-GTABFTZP.js +23 -0
- package/dist/chunk-ILKQDXI5.js +22 -0
- package/dist/{chunk-7WEYBZSK.js → chunk-MIMDLO52.js} +1 -1
- package/dist/{chunk-H3JTPDCJ.js → chunk-NWABK3RZ.js} +3 -18
- package/dist/chunk-OVYHOZ3C.js +27 -0
- package/dist/{chunk-77CQG7O7.js → chunk-SPZO6C5N.js} +27 -24
- package/dist/{chunk-FKIZ5ZJU.js → chunk-TAN5I2DP.js} +2 -2
- package/dist/{chunk-63LDNYGW.js → chunk-XNLIEUAW.js} +1 -1
- package/dist/chunk-ZGG7TRAM.js +3 -0
- package/dist/cli.js +18 -34
- package/dist/{commands-VUWI4ERO.js → commands-7D5EEQBY.js} +6 -5
- package/dist/{commands-XYKBLMXT.js → commands-EWRHQZYM.js} +56 -61
- package/dist/logout-guard-Q4MQFEGR.js +13 -0
- package/dist/{oneshot-5EM5NFTK.js → oneshot-AXS5LWUY.js} +2 -2
- package/dist/{project-OKTJ32JT.js → project-BATJQR3F.js} +1 -1
- package/dist/run-2OQQAOHL.js +4 -0
- package/dist/{setup-AJ56N6XO.js → setup-ROGEF3UO.js} +2 -1
- package/dist/{task-VVBXZLPU.js → task-6QUH5OXF.js} +2 -2
- package/dist/update-EXFIHTMW.js +3 -0
- package/package.json +1 -1
- package/dist/run-XALXQIC3.js +0 -4
- package/dist/update-WDWUECN7.js +0 -21
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{stringWidth}from"./chunk-WVS4W5FY.js";import{
|
|
4
|
-
import{
|
|
3
|
+
import{stringWidth}from"./chunk-WVS4W5FY.js";import{parseOperationArgs}from"./chunk-O52CUEDO.js";import{GLOBAL_OPTIONS_HELP}from"./chunk-TAN5I2DP.js";import{HELP_TOKEN}from"./chunk-ZGG7TRAM.js";import{AuthSession,NotLoggedInError,SessionExpiredError,loadCredentials}from"./chunk-XNLIEUAW.js";import{Resolver,requireDefaultProject}from"./chunk-MIMDLO52.js";import{ApiError,TwpApiClient,appendQuery}from"./chunk-JKSXUBND.js";import{httpFetch}from"./chunk-J7QYPKVK.js";
|
|
4
|
+
import{effectiveApiUrl,loadUserConfig,resolveConfiguredOutput,resolveProfile}from"./chunk-NERYSBA4.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|signature)[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}"\\\
|
|
5
5
|
s*:\\s*)"(?:[^"\\\\]|\\\\.)*"`,"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===
|
|
6
6
|
"object"){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}`})}
|
|
7
7
|
var BODY_LIMIT=4e3;function formatBody(raw){const safe=redactSecrets(stripTerminalControls(raw));return safe.length>BODY_LIMIT?`${safe.slice(0,BODY_LIMIT)}
|
|
@@ -16,7 +16,8 @@ value)}return stripTerminalControls(JSON.stringify(value)??"")}function isPlainR
|
|
|
16
16
|
return text+" ".repeat(pad)}).join(" ").trimEnd()}function singleLine(text){return stripTerminalControls(text).replace(/\t/g,"\\t").replace(/\n/g,"\\n")}function renderGrid(header,rows){const normalizedHeader=header?header.map(singleLine):null;const normalizedRows=rows.map(row=>row.map(singleLine));return renderGridNormalized(normalizedHeader,normalizedRows)}function renderGridNormalized(header,rows){const all=header?[header,...rows]:rows;const columnCount=all.reduce((max,row)=>Math.max(max,row.
|
|
17
17
|
length),0);const widths=[];for(let i=0;i<columnCount;i+=1){widths.push(all.reduce((max,row)=>Math.max(max,stringWidth(row[i]??"")),0))}const lines=[];if(header){lines.push(renderRow(header,widths));lines.push(widths.map(w=>"-".repeat(Math.max(1,w))).join(" ").trimEnd())}for(const row of rows)lines.push(renderRow(row,widths));return lines.join("\n")}function formatTable(value){if(Array.isArray(value)){if(value.length===0)return"";const records=value.filter(isPlainRecord);if(records.length!==value.
|
|
18
18
|
length){return renderGrid(null,value.map(v=>[cell(v)]))}const columns=collectColumns(records);if(columns.length===0)return"";return renderGrid(columns,records.map(row=>columns.map(c=>cell(row[c]))))}if(isPlainRecord(value)){const entries=Object.entries(value);if(entries.length===0)return"";return renderGrid(null,entries.map(([k,v])=>[k,cell(v)]))}return cell(value)}function escapeDelimited(text){return text.replace(/\\/g,"\\\\").replace(/\t/g,"\\t").replace(/\r/g,"\\r").replace(/\n/g,"\\n")}function formatDelimited(value,separator){
|
|
19
|
-
const rows=[];if(Array.isArray(value)){const records=value.filter(isPlainRecord);if(value.length>0&&records.length===value.length){const columns=collectColumns(records);for(const row of records)rows.push(columns.map(c=>cell(row[c])))}else{for(const v of value)rows.push([cell(v)])}}else if(isPlainRecord(value)){rows.push(Object.values(value).map(cell))}else{rows.push([cell(value)])}return rows.map(row=>row.map(escapeDelimited).join(separator)).join("\n")}async function evaluateQuery(expression,value){if(expression.trim()===""){throw new UsageError("--query \u306B\u7A7A\u306E\u5F0F\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093")}const{search}=await import("./dist-HZIZTJ4O.js");try{return search(value??null,expression)}catch(err){throw new UsageError(`--query \u306E\u5F0F\u3092\u8A55\u4FA1\u3067\u304D\u307E\u305B\u3093: ${err.message}`)}}function renderOutput(value,format,noRedact=false){if(noRedact)return formatOutput(value,format);return redactSecrets(formatOutput(redactSecretValues(value),format))}
|
|
19
|
+
const rows=[];if(Array.isArray(value)){const records=value.filter(isPlainRecord);if(value.length>0&&records.length===value.length){const columns=collectColumns(records);for(const row of records)rows.push(columns.map(c=>cell(row[c])))}else{for(const v of value)rows.push([cell(v)])}}else if(isPlainRecord(value)){rows.push(Object.values(value).map(cell))}else{rows.push([cell(value)])}return rows.map(row=>row.map(escapeDelimited).join(separator)).join("\n")}async function evaluateQuery(expression,value){if(expression.trim()===""){throw new UsageError("--query \u306B\u7A7A\u306E\u5F0F\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093")}const{search}=await import("./dist-HZIZTJ4O.js");try{return search(value??null,expression)}catch(err){throw new UsageError(`--query \u306E\u5F0F\u3092\u8A55\u4FA1\u3067\u304D\u307E\u305B\u3093: ${err.message}`)}}function renderOutput(value,format,noRedact=false){if(noRedact)return formatOutput(value,format);return redactSecrets(formatOutput(redactSecretValues(value),format))}var NO_REDACT_FLAG={name:"--no-redact",summary:"\u5FDC\u7B54\u306E\u4F0F\u5B57\u5316\u3092\u89E3\u9664\u3057\u3066\u751F\u306E\u5024\u3092\u51FA\u3059\uFF08\u9375\u306E\u53D7\u3051\u53D6\u308A\u7B49\uFF09",takesValue:false};var NO_REDACT_NOTICE="\u6CE8\u8A18: --no-redact \u306E\u305F\u3081\u51FA\u529B\u3092\u4F0F\u5B57\u5316\u3057\u307E\u305B\u3093\uFF08\u7AEF\u672B\u3068\u30ED\u30B0\u306B\u5E73\u6587\u3067\u6B8B\u308A\u307E\u3059\uFF09\u3002";function withCommonFlags(flags){return flags.some(flag=>flag.
|
|
20
|
+
name===NO_REDACT_FLAG.name)?flags:[...flags,NO_REDACT_FLAG]}function alignedList(entries,indent=" "){const width=entries.reduce((max,[left])=>Math.max(max,stringWidth(left)),0);return entries.map(([left,right])=>`${indent}${left}${" ".repeat(Math.max(0,width-stringWidth(left)))} ${right}`).join("\n")}function subresourcesOf(resource){return resource.subresources??[]}function renderResourceHelp(resource,path2){const subresources=subresourcesOf(resource);const operationSection=resource.operations.length===0?"":`
|
|
20
21
|
\u64CD\u4F5C:
|
|
21
22
|
${alignedList(resource.operations.map(op=>[op.name,op.summary]))}
|
|
22
23
|
`;const subSection=subresources.length===0?"":`
|
|
@@ -29,14 +30,14 @@ ${alignedList(subresources.map(sub=>[`${sub.name} <\u64CD\u4F5C>`,sub.summary]))
|
|
|
29
30
|
twp ${path2} <\u64CD\u4F5C> ${HELP_TOKEN} \u305D\u306E\u64CD\u4F5C\u306E\u8A73\u3057\u3044\u30D8\u30EB\u30D7
|
|
30
31
|
${operationSection}${subSection}
|
|
31
32
|
${GLOBAL_OPTIONS_HELP}
|
|
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")}
|
|
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}\
|
|
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-
|
|
33
|
+
`}function renderOperationHelp(op,path2){const sections=[`twp ${path2} ${op.name} \u2014 ${op.summary}`,"","\u4F7F\u3044\u65B9:",` ${op.usage}`];if(op.description!==void 0){sections.push("",...op.description.split("\n"))}if(op.destructive===true){sections.push("","\u26A0 \u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u304C\u5FC5\u8981\u3067\u3059\u3002")}const flags=withCommonFlags(op.flags);if(flags.length>0){sections.push("","\u30AA\u30D7\u30B7\u30E7\u30F3:",
|
|
34
|
+
alignedList(flags.map(flag=>[flag.takesValue?`${flag.name} ${flag.placeholder??"<\u5024>"}`:flag.name,flag.summary])))}sections.push("",GLOBAL_OPTIONS_HELP,"");return sections.join("\n")}function renderUnknownOperation(resource,path2,attempted){const names=[...resource.operations.map(op=>op.name),...subresourcesOf(resource).map(sub=>`${sub.name} <\u64CD\u4F5C>`)].join(" / ");return attempted===void 0?`twp ${path2} \u306B\u306F\u64CD\u4F5C\u306E\u6307\u5B9A\u304C\u5FC5\u8981\u3067\u3059\uFF08${names}\
|
|
35
|
+
\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`:`twp ${path2} \u306B\u300C${attempted}\u300D\u3068\u3044\u3046\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${names}\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`}var LOADERS={backlog:async()=>(await import("./backlog-NV7Z76R3.js")).backlogDomain,project:async()=>(await import("./project-BATJQR3F.js")).projectDomain,task:async()=>(await import("./task-6QUH5OXF.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
36
|
`}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
|
-
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
|
-
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;
|
|
38
|
-
`);return}
|
|
39
|
-
`);if(hint!==void 0)
|
|
37
|
+
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,write=writeErr){const message=safeText(err instanceof Error?err.message:String(err));const rawHint=err instanceof
|
|
38
|
+
UsageError?err.hint:void 0;const hint=rawHint!==void 0?safeText(rawHint):void 0;if(format==="json"){const body={code,message};if(err instanceof ApiError)body["status"]=err.status;if(err instanceof ResolveError&&err.status!==null)body["status"]=err.status;if(hint!==void 0)body["hint"]=hint;write(`${JSON.stringify({error:body},null,2)}
|
|
39
|
+
`);return}write(`${message}
|
|
40
|
+
`);if(hint!==void 0)write(`${hint}
|
|
40
41
|
`)}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}async function send(client,apiUrl,plan){try{return 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(`${apiUrl} \u3078\u306E\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.
|
|
41
42
|
message}`,{cause:err})}}async function putSigned(fetchImpl,url,bytes,contentType){let res;try{res=await fetchImpl(url,{method:"PUT",headers:{"Content-Type":contentType},body:bytes})}catch(err){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u3078\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.message}`,{cause:err})}if(!res.ok){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u3078\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u304C\u62D2\u5426\u3055\u308C\u307E\u3057\u305F\uFF08HTTP ${res.
|
|
42
43
|
status}\uFF09`)}}function resolveDownloadTarget(spec,commandPath,operationName,input){const raw=input.flags.get(spec.outFlag);if(raw===void 0||raw.trim()===""){throw new UsageError(`${spec.outFlag} \u306F\u5FC5\u9808\u3067\u3059\uFF08twp ${commandPath} ${operationName}\uFF09`,`\u66F8\u304D\u51FA\u3057\u5148\u306E\u30D5\u30A1\u30A4\u30EB\u30D1\u30B9\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u6A19\u6E96\u51FA\u529B\u3078\u306F\u51FA\u3057\u307E\u305B\u3093\uFF09\u3002`)}return{out:path.
|
|
@@ -46,21 +47,23 @@ if(err instanceof ApiError||err instanceof NotLoggedInError||err instanceof Sess
|
|
|
46
47
|
\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"};
|
|
47
48
|
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)}\
|
|
48
49
|
\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,
|
|
49
|
-
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
|
|
50
|
+
args.apiUrl,plan)}catch(err){if(page>1){(args.warn??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
|
|
50
51
|
`)}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}\
|
|
51
52
|
\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")??
|
|
52
53
|
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{
|
|
53
54
|
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")}
|
|
54
|
-
const ref=requireDefaultProject(explicit,args.profileName,args.env,args.cwd).ref;const hit=cache.get(ref);if(hit!==void 0)return hit;const resolved=args.resolver.project(ref).then(project=>project.id);cache.set(ref,resolved);return resolved}}}async function runDomain(options){const{globals}=options;let format=null;try{const profile=resolveProfile(globals.profile);format=resolveOutputFormat({...globals.output!==void 0?{flag:globals.
|
|
55
|
-
name);return configured!==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`)}const domain=await loadDomain(options.domain);if(options.operation===HELP_TOKEN||options.help&&options.
|
|
56
|
-
renderResourceHelp(domain,domain.name));return EXIT_OK}const target=domain.subresources?.find(resource2=>resource2.name===extra);if(target===void 0||rest2.length>0){throw new UsageError(renderUnknownOperation(domain,domain.name,extra))}
|
|
57
|
-
void 0?options.operation:options.argv[0];const rest=sub===void 0?options.argv:options.argv.slice(1);if(sub!==void 0&&(operationName===HELP_TOKEN||options.help&&operationName===void 0)){
|
|
58
|
-
const input=parseOperationArgs(rest,operation.flags);if(!globals.dryRun&&requiresYes(operation,globals.yes)){throw new UsageError(`twp ${path2} ${operation.name} \u306F\u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002`)}const paging=resolvePaging(operation,path2,input);
|
|
59
|
-
profile.name);const apiUrl=effectiveApiUrl(profile,stored?.api_url);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);const ctx=buildPrepareContext(
|
|
60
|
-
cwd:process.cwd()});const prepared=operation.prepare===void 0?input:await operation.prepare(input,ctx);const plan=operation.plan(prepared);if(operation.execute!==void 0&&(operation.download!==void 0||operation.paging!==void 0||operation.fetchCached!==void 0)){throw new Error(`twp ${path2} ${operation.name}: execute \u306F download / paging /
|
|
61
|
-
(operation.download!==void 0||operation.paging!==void 0||operation.destructive===true||plan.method!=="GET")){throw new Error(`twp ${path2} ${operation.name}: fetchCached \u306F\u9001\u4FE1\u3057\u306A\u3044\u8AAD\u307F\u53D6\u308A\u5C02\u7528\u306E\u64CD\u4F5C\u306B\u3060\u3051\u5BA3\u8A00\u3067\u304D\u307E\u3059\uFF08\u914D\u7DDA\u306E\u8AA4\u308A\uFF09`)}
|
|
62
|
-
|
|
63
|
-
`)
|
|
64
|
-
|
|
65
|
-
`)}
|
|
66
|
-
|
|
55
|
+
const ref=requireDefaultProject(explicit,args.profileName,args.env,args.cwd).ref;const hit=cache.get(ref);if(hit!==void 0)return hit;const resolved=args.resolver.project(ref).then(project=>project.id);cache.set(ref,resolved);return resolved}}}async function runDomain(options){const{globals}=options;const out=options.io?.out??writeOut;const errOut=options.io?.err??writeErr;let format=null;try{const profile=resolveProfile(globals.profile);format=resolveOutputFormat({...globals.output!==void 0?{flag:globals.
|
|
56
|
+
output}:{},...(()=>{const configured=resolveConfiguredOutput(profile.name);return configured!==void 0?{configured}:{}})(),isTty:options.io?.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`)}const domain=await loadDomain(options.domain);if(options.operation===HELP_TOKEN||options.help&&options.
|
|
57
|
+
operation===void 0){const[extra,...rest2]=options.argv;if(extra===void 0){out(renderResourceHelp(domain,domain.name));return EXIT_OK}const target=domain.subresources?.find(resource2=>resource2.name===extra);if(target===void 0||rest2.length>0){throw new UsageError(renderUnknownOperation(domain,domain.name,extra))}out(renderResourceHelp(target,`${domain.name} ${extra}`));return EXIT_OK}const sub=domain.subresources?.find(resource2=>resource2.name===options.operation);const resource=sub??domain;const path2=sub===
|
|
58
|
+
void 0?domain.name:`${domain.name} ${sub.name}`;const operationName=sub===void 0?options.operation:options.argv[0];const rest=sub===void 0?options.argv:options.argv.slice(1);if(sub!==void 0&&(operationName===HELP_TOKEN||options.help&&operationName===void 0)){out(renderResourceHelp(sub,path2));return EXIT_OK}const operation=resource.operations.find(op=>op.name===operationName);if(operation===void 0){throw new UsageError(renderUnknownOperation(resource,path2,operationName))}if(options.help||rest[0]===
|
|
59
|
+
HELP_TOKEN){out(renderOperationHelp(operation,path2));return EXIT_OK}const input=parseOperationArgs(rest,withCommonFlags(operation.flags));const noRedact=input.flags.has("--no-redact");if(!globals.dryRun&&requiresYes(operation,globals.yes)){throw new UsageError(`twp ${path2} ${operation.name} \u306F\u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002`)}const paging=resolvePaging(operation,path2,input);
|
|
60
|
+
const downloadTarget=operation.download===void 0?void 0:resolveDownloadTarget(operation.download,path2,operation.name,input);const stored=loadCredentials(profile.name);const apiUrl=effectiveApiUrl(profile,stored?.api_url);const transport=options.fetchImpl??httpFetch;const fetchImpl=globals.debug?withDebug(transport,{write:errOut}):transport;const session=new AuthSession(profile.name,apiUrl,process.env,fetchImpl);const client=new TwpApiClient(apiUrl,session,fetchImpl,options.version);const ctx=buildPrepareContext(
|
|
61
|
+
{resolver:new Resolver(client,{profile:profile.name,refresh:globals.refresh,...profileAliases(profile.name)}),profileName:profile.name,env:process.env,cwd:process.cwd()});const prepared=operation.prepare===void 0?input:await operation.prepare(input,ctx);const plan=operation.plan(prepared);if(operation.execute!==void 0&&(operation.download!==void 0||operation.paging!==void 0||operation.fetchCached!==void 0)){throw new Error(`twp ${path2} ${operation.name}: execute \u306F download / paging / fetchCache\
|
|
62
|
+
d \u3068\u540C\u6642\u306B\u5BA3\u8A00\u3067\u304D\u307E\u305B\u3093\uFF08\u914D\u7DDA\u306E\u8AA4\u308A\uFF09`)}if(operation.fetchCached!==void 0&&(operation.download!==void 0||operation.paging!==void 0||operation.destructive===true||plan.method!=="GET")){throw new Error(`twp ${path2} ${operation.name}: fetchCached \u306F\u9001\u4FE1\u3057\u306A\u3044\u8AAD\u307F\u53D6\u308A\u5C02\u7528\u306E\u64CD\u4F5C\u306B\u3060\u3051\u5BA3\u8A00\u3067\u304D\u307E\u3059\uFF08\u914D\u7DDA\u306E\u8AA4\u308A\uFF09`)}
|
|
63
|
+
for(const note of operation.plannedNotes?.(prepared)??[])errOut(`${safeText(note)}
|
|
64
|
+
`);if(noRedact)errOut(`${NO_REDACT_NOTICE}
|
|
65
|
+
`);if(globals.dryRun){out(line(renderOutput(dryRunValue(apiUrl,plan),format,noRedact)));return EXIT_OK}let body;let paged;if(operation.execute!==void 0){const executeCtx={send:next=>send(client,apiUrl,next),putSigned:(url,bytes,contentType)=>putSigned(fetchImpl,url,bytes,contentType),warn:text=>errOut(`${safeText(text)}
|
|
66
|
+
`)};body=await operation.execute(prepared,executeCtx)}else 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.paging,maxPages:paging.maxPages,maxItems:paging.maxItems,
|
|
67
|
+
warn:errOut});body=paged.body}else{body=await send(client,apiUrl,plan)}const visible=noRedact?body:redactSecretValues(body);const value=globals.query!==void 0?await evaluateQuery(globals.query,operation.raw(visible)):outputValue(operation,format,visible);out(line(renderOutput(value,format,noRedact)));if(paged!==void 0){errOut(`--all: ${paged.pages} \u30DA\u30FC\u30B8\u3092\u8FBF\u3063\u3066 ${paged.count} \u4EF6\u3092\u53D6\u5F97\u3057\u307E\u3057\u305F\u3002
|
|
68
|
+
`)}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?.(visible,prepared)??[]]){errOut(`${safeText(note)}
|
|
69
|
+
`)}return EXIT_OK}catch(err){const code=exitCodeFor(err);reportError(err,format,code,errOut);return code}}export{redactSecretValues,withDebug,OUTPUT_FORMATS,resolveOutputFormat,evaluateQuery,renderOutput,NO_REDACT_FLAG,NO_REDACT_NOTICE,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
|
-
var
|
|
3
|
+
var GLOBAL_OPTIONS_HELP=`\u30B0\u30ED\u30FC\u30D0\u30EB\u30AA\u30D7\u30B7\u30E7\u30F3\uFF08\u30C9\u30E1\u30A4\u30F3\u30B3\u30DE\u30F3\u30C9\u5171\u901A\uFF09:
|
|
4
4
|
--profile <\u540D\u524D> \u63A5\u7D9A\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB\uFF08\u30C6\u30CA\u30F3\u30C8\uFF09\u3092\u6307\u5B9A\uFF08TWP_PROFILE \u3067\u3082\u53EF\uFF09
|
|
5
5
|
--output <\u5F62\u5F0F> json | table | text | tsv
|
|
6
6
|
\u65E2\u5B9A\u306F\u7AEF\u672B\u306A\u3089 table\u3001\u30D1\u30A4\u30D7\u306A\u3089 json
|
|
@@ -39,4 +39,4 @@ var DOMAIN_NAMES=["backlog","project","task"];function isDomainName(value){retur
|
|
|
39
39
|
\u5B9F\u4F53\u304C\u8907\u6570\u3042\u308B\u64CD\u4F5C\u3067\u306F\u4E3B\u305F\u308B\u5B9F\u4F53\u3060\u3051\u3092\u51FA\u3057\u307E\u3059\uFF08task update \u306E changes \u306F\u51FA\u307E\u305B\u3093\u3002
|
|
40
40
|
task delete / task comment delete \u306F result \u3068 message \u3060\u3051\u3067\u3059\uFF09\u3002
|
|
41
41
|
table / text / tsv \u306F\u4EBA\u304C\u8AAD\u3080\u305F\u3081\u306B\u9078\u3093\u3060\u8981\u7D04\u5217\u3067\u30013\u5F62\u5F0F\u3068\u3082\u540C\u3058\u5217\u3067\u3059\u3002
|
|
42
|
-
\u3053\u306E\u5217\u306F\u5951\u7D04\u3067\u306F\u306A\u304F\u4E88\u544A\u306A\u304F\u5909\u308F\u308A\u307E\u3059\u3002\u6A5F\u68B0\u51E6\u7406\u306F --output json \u304B --query \u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044\u3002`;export{
|
|
42
|
+
\u3053\u306E\u5217\u306F\u5951\u7D04\u3067\u306F\u306A\u304F\u4E88\u544A\u306A\u304F\u5909\u308F\u308A\u307E\u3059\u3002\u6A5F\u68B0\u51E6\u7406\u306F --output json \u304B --query \u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044\u3002`;export{GLOBAL_OPTIONS_HELP};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{
|
|
3
|
+
import{httpFetch}from"./chunk-J7QYPKVK.js";import{ensureTwpHome,twpHomeDir}from"./chunk-RZVI6PMW.js";import fs2 from"fs";import path from"path";import fs from"fs";import{setTimeout as sleep}from"timers/promises";var POLL_MS=100;var STALE_MS=3e4;var DEFAULT_TIMEOUT_MS=STALE_MS+5e3;var LockTimeoutError=class extends Error{};async function withFileLock(lockPath,fn,timeoutMs=DEFAULT_TIMEOUT_MS){const deadline=Date.now()+timeoutMs;for(;;){try{const fd=fs.openSync(lockPath,"wx");fs.writeSync(fd,`${process.pid}
|
|
4
4
|
`);fs.closeSync(fd);break}catch(err){if(err.code!=="EEXIST")throw err;let stale=false;try{stale=Date.now()-fs.statSync(lockPath).mtimeMs>STALE_MS}catch{}if(stale){fs.rmSync(lockPath,{force:true});continue}if(Date.now()>=deadline){throw new LockTimeoutError(`\u30ED\u30C3\u30AF\u306E\u53D6\u5F97\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F: ${lockPath}
|
|
5
5
|
\u5225\u306E twp \u30D7\u30ED\u30BB\u30B9\u304C\u8A8D\u8A3C\u60C5\u5831\u3092\u66F4\u65B0\u4E2D\u306E\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002\u6B8B\u9AB8\u306A\u3089\u524A\u9664\u3057\u3066\u518D\u8A66\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}await sleep(POLL_MS)}}try{return await fn()}finally{fs.rmSync(lockPath,{force:true})}}var CredentialPermissionError=class extends Error{};function credentialsPath(env=process.env){return path.join(twpHomeDir(env),"credentials.json")}function credentialsLockPath(env=process.env){return path.join(twpHomeDir(env),"credentials.lock")}async function withCredentialsLock(env,fn){ensureTwpHome(env);return withFileLock(credentialsLockPath(env),fn)}function assertDirPrivate(dir){if(process.platform==="win32")return;let st;try{st=fs2.lstatSync(dir)}catch{return}if(st.isSymbolicLink()){throw new CredentialPermissionError(
|
|
6
6
|
`${dir} \u304C\u30B7\u30F3\u30DC\u30EA\u30C3\u30AF\u30EA\u30F3\u30AF\u3067\u3059\u3002\u8A8D\u8A3C\u60C5\u5831\u306E\u7F6E\u304D\u5834\u6240\u306F\u30EA\u30F3\u30AF\u306B\u3057\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
var DOMAIN_NAMES=["backlog","project","task"];function isDomainName(value){return value!==void 0&&DOMAIN_NAMES.includes(value)}var HELP_TOKEN="help";var API_TOKEN="api";export{isDomainName,HELP_TOKEN,API_TOKEN};
|
package/dist/cli.js
CHANGED
|
@@ -1,31 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
3
3
|
const require = __twpCreateRequire(import.meta.url);
|
|
4
|
-
import{
|
|
5
|
-
-password","--token","--no-browser","--safe","--daemon","--force-runner","--force","--drain","--yes","-y","--no-ai-config-file","--verbose","--dry-run","--debug","--refresh"]);function dispatch(argv,limit=2){const tokens=[];const indexes=[];let truncated=false;for(let i=0;i<argv.length;i++){const arg=argv[i];if(arg===void 0)continue;if(arg.startsWith("-")&&arg!=="-"){const{name,value:inline}=splitFlagToken(arg);if(BOOLEAN_FLAGS.has(name)){if(inline!==void 0){truncated=true;break}continue}if(VALUE_FLAGS.
|
|
6
|
-
has(name)){if(inline!==void 0)continue;const next=argv[i+1];if(next!==void 0&&(!next.startsWith("-")||next==="-"))i++;continue}truncated=true;break}if(arg===""||arg==="-")continue;if(tokens.length>=limit)break;tokens.push(arg);indexes.push(i)}return{tokens,indexes,truncated}}function isBuiltin(token){return token!==void 0&&BUILTIN_COMMANDS.includes(token)}function isTaskLoopAction(token){return token!==void 0&&TASK_LOOP_ACTIONS.includes(token)}function resolveRoute(result){const{tokens,indexes}=result;
|
|
7
|
-
const[first,second]=tokens;const firstIndex=indexes[0];if(first===void 0||firstIndex===void 0)return{kind:"none",consumed:[]};const consumed=[firstIndex];const secondIndex=indexes[1];if(isBuiltin(first)){if(first==="task-loop"&&isTaskLoopAction(second)){if(secondIndex!==void 0)consumed.push(secondIndex);return{kind:"builtin",command:first,action:second,consumed}}return{kind:"builtin",command:first,...first==="task-loop"?{action:"run"}:{},consumed}}if(second!==void 0&&secondIndex!==void 0)consumed.
|
|
8
|
-
push(secondIndex);return{kind:"domain",domain:first,...second!==void 0?{operation:second}:{},consumed}}var GLOBAL_FLAGS=new Set(["-h","--help","-v","--version","--profile","--output","--query","--dry-run","--debug","--yes","-y","--refresh"]);function parseArgv(argv){const out={command:"tui",safe:false,daemon:false,forceRunner:false,stopForce:false,stopDrain:false,noTui:false,doctor:false,yes:false,noAiConfigFile:false,verbose:false,loginMethod:"browser",loginNoBrowser:false,promptFromStdin:false,domainArgv:[],domainHelp:false,dryRun:false,debug:false,refresh:false,unknown:[],allowedTools:[],disallowedTools:[]};
|
|
9
|
-
const route=resolveRoute(dispatch(argv));const consumed=new Set;const[firstIndex,secondIndex]=route.consumed;if(route.kind==="builtin"){out.command=route.command;if(route.action!==void 0)out.taskLoopAction=route.action;for(const index of route.consumed)consumed.add(index)}else if(route.kind==="domain"){if(route.domain===HELP_TOKEN){if(route.operation===void 0){out.command="help";if(firstIndex!==void 0)consumed.add(firstIndex)}else if(isDomainName(route.operation)){out.command="domain";out.domain=
|
|
10
|
-
route.operation;out.domainHelp=true;if(firstIndex!==void 0)consumed.add(firstIndex);if(secondIndex!==void 0)consumed.add(secondIndex)}else if(route.operation===API_TOKEN){out.command="api";out.domainHelp=true;if(firstIndex!==void 0)consumed.add(firstIndex);if(secondIndex!==void 0)consumed.add(secondIndex)}}else if(route.domain===API_TOKEN){out.command="api";if(firstIndex!==void 0)consumed.add(firstIndex)}else if(isDomainName(route.domain)){out.command="domain";out.domain=route.domain;if(route.operation!==
|
|
11
|
-
void 0)out.operation=route.operation;for(const index of route.consumed)consumed.add(index)}}const hasSubcommandToken=route.kind==="builtin"||route.kind==="domain"&&(route.domain===HELP_TOKEN||route.domain===API_TOKEN||isDomainName(route.domain));const isDomainRoute=out.command==="domain"||out.command==="api";const takeValue=(i,flag,inline)=>{const value=inline??argv[i+1];if(value===void 0||inline===void 0&&value.startsWith("-")){out.unknown.push(flag);return{step:0}}if(value.trim()===""){out.unknown.
|
|
12
|
-
push(inline===void 0?`${flag} `:`${flag}=${inline}`);return{step:0}}return{value,step:inline===void 0?1:0}};let optionsClosed=false;for(let i=0;i<argv.length;i++){if(consumed.has(i))continue;const raw=argv[i];if(raw===void 0)continue;if(isDomainRoute&&raw==="--")optionsClosed=true;const{name:arg,value:inline}=splitFlagToken(raw);if(isDomainRoute&&(optionsClosed||!GLOBAL_FLAGS.has(arg))){out.domainArgv.push(raw);continue}if(inline!==void 0&&BOOLEAN_FLAGS.has(arg)){out.unknown.push(raw);continue}switch(arg){case"\
|
|
13
|
-
-h":case"--help":if(isDomainRoute)out.domainHelp=true;else out.command="help";break;case"-v":case"--version":out.command="version";break;case"--no-tui":out.noTui=true;break;case"--doctor":out.doctor=true;break;case"--password":out.loginMethod="password";break;case"--token":out.loginMethod="token";break;case"--no-browser":out.loginNoBrowser=true;break;case"--profile":{const{value,step}=takeValue(i,"--profile",inline);if(value!==void 0){out.profile=value;i+=step}break}case"-p":case"--print":{const next=inline??
|
|
14
|
-
argv[i+1];const step=inline===void 0?1:0;if(hasSubcommandToken){out.unknown.push(raw)}else if(next==="-"){out.command="print";out.promptFromStdin=true;out.prompt="";i+=step}else if(next!==void 0&&(inline!==void 0||!next.startsWith("-"))){out.command="print";out.prompt=next;i+=step}else{out.unknown.push(raw)}break}case"--output":{const{value,step}=takeValue(i,"--output",inline);if(value!==void 0){out.output=value;i+=step}break}case"--query":{const{value,step}=takeValue(i,"--query",inline);if(value!==
|
|
15
|
-
void 0){out.query=value;i+=step}break}case"--dry-run":out.dryRun=true;break;case"--debug":out.debug=true;break;case"--refresh":out.refresh=true;break;case"--tenant":{const{value,step}=takeValue(i,"--tenant",inline);if(value!==void 0){out.tenant=value;i+=step}break}case"--mode":{const next=inline??argv[i+1];const step=inline===void 0?1:0;if(isModeId(next)){out.mode=next;i+=step}else if(next!==void 0&&(inline!==void 0||!next.startsWith("-"))){out.unknown.push(inline!==void 0?raw:`--mode ${next}`);
|
|
16
|
-
i+=step}else{out.unknown.push("--mode")}break}case"--permission-mode":{const next=inline??argv[i+1];const step=inline===void 0?1:0;if(isPermissionModeId(next)){out.permissionMode=next;i+=step}else if(next!==void 0&&(inline!==void 0||!next.startsWith("-"))){out.unknown.push(inline!==void 0?raw:`--permission-mode ${next}`);i+=step}else{out.unknown.push("--permission-mode")}break}case"--allowed-tools":case"--disallowed-tools":{const{value,step}=takeValue(i,arg,inline);if(value!==void 0){(arg==="--a\
|
|
17
|
-
llowed-tools"?out.allowedTools:out.disallowedTools).push(value);i+=step}break}case"--model":{const{value,step}=takeValue(i,"--model",inline);if(value!==void 0){out.model=value;i+=step}break}case"--safe":out.safe=true;break;case"--daemon":out.daemon=true;break;case"--force-runner":out.forceRunner=true;break;case"--force":out.stopForce=true;break;case"--drain":out.stopDrain=true;break;case"--project":{const{value,step}=takeValue(i,"--project",inline);if(value!==void 0){out.project=value;i+=step}break}case"\
|
|
18
|
-
--engine":{const{value,step}=takeValue(i,"--engine",inline);if(value!==void 0){out.engine=value;i+=step}break}case"--interval":case"--max-cycles":{const{value,step}=takeValue(i,arg,inline);if(value!==void 0){const n=Number.parseInt(value,10);if(Number.isInteger(n)&&n>0){if(arg==="--interval")out.interval=n;else out.maxCycles=n}else{out.unknown.push(inline!==void 0?raw:`${arg} ${value}`)}i+=step}break}case"--yes":case"-y":out.yes=true;break;case"--ai":{const{value:v,step}=takeValue(i,"--ai",inline);
|
|
19
|
-
if(v!==void 0){out.ais=[...out.ais??[],v];i+=step}break}case"--no-ai-config-file":out.noAiConfigFile=true;break;case"--workspace":{const{value:v,step}=takeValue(i,"--workspace",inline);if(v!==void 0){out.workspace=v;i+=step}break}case"--ai-config-file":{const{value:v,step}=takeValue(i,"--ai-config-file",inline);if(v!==void 0){out.aiConfigFile=v;i+=step}break}case"--verbose":out.verbose=true;break;case"--now":{const{value:v,step}=takeValue(i,"--now",inline);if(v!==void 0){out.scheduleNow=v;i+=step}
|
|
20
|
-
break}case"--counts":{const{value:v,step}=takeValue(i,"--counts",inline);if(v!==void 0){out.scheduleCounts=v;i+=step}break}case"--gate":{const{value:v,step}=takeValue(i,"--gate",inline);if(v!==void 0){out.scheduleGate=v;i+=step}break}default:out.unknown.push(raw)}}if(out.command!=="login"&&out.loginMethod!=="browser"){out.unknown.push(out.loginMethod==="password"?"--password":"--token");out.loginMethod="browser"}if(out.permissionMode!==void 0&&out.command!=="tui"&&out.command!=="print"){out.unknown.
|
|
21
|
-
push("--permission-mode");delete out.permissionMode}if(out.command!=="tui"&&out.command!=="print"){if(out.allowedTools.length>0)out.unknown.push("--allowed-tools");if(out.disallowedTools.length>0)out.unknown.push("--disallowed-tools");out.allowedTools=[];out.disallowedTools=[]}if(out.loginNoBrowser&&!(out.command==="login"&&out.loginMethod==="browser")){out.unknown.push("--no-browser");out.loginNoBrowser=false}if(out.command!=="task-loop"){if(out.safe)out.unknown.push("--safe");if(out.daemon)out.
|
|
22
|
-
unknown.push("--daemon");if(out.forceRunner)out.unknown.push("--force-runner");if(out.stopForce)out.unknown.push("--force");if(out.stopDrain)out.unknown.push("--drain");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.project!==void 0)out.unknown.push("--project");if(out.verbose)out.unknown.push("--verbose");if(out.scheduleNow!==void 0)out.unknown.push("--now");if(out.scheduleCounts!==
|
|
23
|
-
void 0)out.unknown.push("--counts");if(out.scheduleGate!==void 0)out.unknown.push("--gate");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.yes&&out.command!=="task-loop"&&!isDomainRoute)out.unknown.push("--yes");if(!isDomainRoute){if(out.output!==void 0)out.unknown.push("--output");if(out.query!==void 0)out.
|
|
24
|
-
unknown.push("--query");if(out.dryRun)out.unknown.push("--dry-run");if(out.debug)out.unknown.push("--debug");if(out.refresh)out.unknown.push("--refresh")}if(out.command==="api"&&out.refresh){out.unknown.push("--refresh");out.refresh=false}if(out.command==="task-loop"&&out.taskLoopAction!=="schedule"){if(out.verbose)out.unknown.push("--verbose");if(out.scheduleNow!==void 0)out.unknown.push("--now");if(out.scheduleCounts!==void 0)out.unknown.push("--counts");if(out.scheduleGate!==void 0)out.unknown.
|
|
25
|
-
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=false;out.stopDrain=false}if(out.command==="task-loop"&&out.taskLoopAction!==
|
|
26
|
-
"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.unknown.push("--daemon");if(out.forceRunner)out.unknown.push("--force-runn\
|
|
27
|
-
er");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.interval!==void 0)out.unknown.push("--interval");if(out.maxCycles!==void 0)
|
|
28
|
-
out.unknown.push("--max-cycles")}return out}var VERSION=true?"0.18.0":"0.0.0-dev";var HELP=`twp ${VERSION} \u2014 TWP CLI
|
|
4
|
+
import{parseArgv}from"./chunk-OVYHOZ3C.js";import"./chunk-BOBSH3QN.js";import{GLOBAL_OPTIONS_HELP}from"./chunk-TAN5I2DP.js";import"./chunk-ZGG7TRAM.js";import"./chunk-QQRJLH6B.js";import"./chunk-VSJBJXZO.js";var VERSION=true?"0.20.0":"0.0.0-dev";var HELP=`twp ${VERSION} \u2014 TWP CLI
|
|
29
5
|
|
|
30
6
|
\u4F7F\u3044\u65B9:
|
|
31
7
|
twp \u5BFE\u8A71 TUI \u3092\u8D77\u52D5
|
|
@@ -38,10 +14,10 @@ out.unknown.push("--max-cycles")}return out}var VERSION=true?"0.18.0":"0.0.0-dev
|
|
|
38
14
|
twp login --tenant <code>
|
|
39
15
|
\u30C6\u30CA\u30F3\u30C8\u30B3\u30FC\u30C9\u3092\u5148\u306B\u6307\u5B9A\uFF08--password \u306E\u30D7\u30ED\u30F3\u30D7\u30C8\u3092 1 \u3064\u7701\u304F\uFF09
|
|
40
16
|
twp logout \u30ED\u30B0\u30A2\u30A6\u30C8\uFF08\u30ED\u30FC\u30AB\u30EB\u524A\u9664\uFF0B\u30B5\u30FC\u30D0\u5074\u30C8\u30FC\u30AF\u30F3\u5931\u52B9\uFF09
|
|
17
|
+
\u540C\u3058\u8CC7\u683C\u60C5\u5831\u3067 task-loop \u304C\u7A3C\u50CD\u4E2D\u306A\u3089\u62D2\u5426\u3059\u308B\uFF08--force \u3067\u7D9A\u884C\uFF09
|
|
41
18
|
twp whoami \u30ED\u30B0\u30A4\u30F3\u4E2D\u306E\u30E6\u30FC\u30B6\u30FC\u30FB\u30C6\u30CA\u30F3\u30C8\u3092\u8868\u793A
|
|
42
19
|
twp update npm \u306E\u6700\u65B0\u7248\u3068\u3001\u30B5\u30FC\u30D0\u304C\u8981\u6C42\u3059\u308B\u6700\u5C0F\u30D0\u30FC\u30B8\u30E7\u30F3\u3092\u78BA\u8A8D
|
|
43
|
-
\uFF08\
|
|
44
|
-
\u4E0B\u9650\u672A\u6E80\u306A\u3089\u7D42\u4E86\u30B3\u30FC\u30C9 1\uFF09
|
|
20
|
+
\uFF08\u4E0B\u9650\u672A\u6E80\u306A\u3089\u7D42\u4E86\u30B3\u30FC\u30C9 1\u3002\u81EA\u52D5\u66F4\u65B0\u306E\u72B6\u614B\u3082\u8868\u793A\u3059\u308B\uFF09
|
|
45
21
|
twp task-loop setup --project <\u30AD\u30FC|UUID>
|
|
46
22
|
\u5BFE\u8A71\u8A2D\u5B9A\uFF08AI CLI \u3092\u691C\u51FA \u2192 \u4F7F\u3046\u3082\u306E\u3092\u9078\u629E \u2192 \u30AB\u30C6\u30B4\u30EA\u5272\u5F53\u3092\u751F\u6210\uFF09\u3002
|
|
47
23
|
--yes \u3067\u5BFE\u8A71\u3092\u7701\u7565\u3001--ai claude,codex \u3067\u660E\u793A\u3001
|
|
@@ -146,10 +122,17 @@ ${GLOBAL_OPTIONS_HELP}
|
|
|
146
122
|
TUI \u5185:
|
|
147
123
|
Shift+Tab / Alt+M \u30E2\u30FC\u30C9\u5DE1\u56DE\uFF08dev \u2192 biz \u2192 plan\uFF09
|
|
148
124
|
/ \u30B9\u30E9\u30C3\u30B7\u30E5\u30B3\u30DE\u30F3\u30C9\u30D1\u30EC\u30C3\u30C8\uFF08/exit \u3067\u7D42\u4E86\u30FB/quit \u3082\u53EF\uFF09
|
|
125
|
+
@ \u30D5\u30A1\u30A4\u30EB\u306E\u5019\u88DC\uFF08Tab \u3067\u78BA\u5B9A\uFF09\u3002\u9001\u4FE1\u3059\u308B\u3068\u4E2D\u8EAB\u3092\u6DFB\u4ED8\u30FB#ABC-123 \u306F\u30BF\u30B9\u30AF\u3092\u6DFB\u4ED8
|
|
149
126
|
Shift+Enter / Ctrl+J \u6539\u884C\uFF08\\ \u3092\u6253\u3063\u3066\u304B\u3089 Enter \u3067\u3082\u53EF\uFF09
|
|
150
127
|
Ctrl+R \u76F4\u524D\u306E\u30C4\u30FC\u30EB\u51FA\u529B\u3092\u5168\u6587\u5C55\u958B
|
|
151
128
|
Ctrl+C \u4E2D\u65AD\uFF08\u5165\u529B\u304C\u7A7A\u306A\u3089 2 \u56DE\u3067\u7D42\u4E86\uFF09 \xB7 Ctrl+D \u7D42\u4E86
|
|
152
129
|
|
|
130
|
+
\u81EA\u52D5\u66F4\u65B0:
|
|
131
|
+
npm \u3067\u30B0\u30ED\u30FC\u30D0\u30EB\u5C0E\u5165\u3057\u305F twp \u306F\u300124\u6642\u9593\u3054\u3068\u306B\u65B0\u3057\u3044\u7248\u3092\u78BA\u8A8D\u3057\u3066\u81EA\u52D5\u3067\u66F4\u65B0\u3059\u308B
|
|
132
|
+
\uFF08\u66F4\u65B0\u306F\u7D42\u4E86\u5F8C\u306B\u884C\u3044\u3001\u6B21\u56DE\u306E\u8D77\u52D5\u304B\u3089\u53CD\u6620\uFF09\u3002\u5931\u6557\u3057\u3066\u3082\u73FE\u5728\u306E\u7248\u306E\u307E\u307E\u52D5\u304F\u3002
|
|
133
|
+
TWP_NO_AUTO_UPDATE=1 \u304B ~/.twp/config.json \u306E "auto_update": false \u3067\u7121\u52B9\u5316\u3002
|
|
134
|
+
npx\u30FB\u30ED\u30FC\u30AB\u30EB\u5C0E\u5165\u306A\u3069\u3067\u306F\u66F4\u65B0\u305B\u305A\u3001\u65B0\u3057\u3044\u7248\u304C\u3042\u308B\u3053\u3068\u3060\u3051\u3092\u77E5\u3089\u305B\u308B
|
|
135
|
+
|
|
153
136
|
\u76E3\u67FB\u30ED\u30B0:
|
|
154
137
|
~/.twp/logs/session-*.jsonl
|
|
155
138
|
\u30C4\u30FC\u30EB\u540D\u30FB\u6A29\u9650\u5224\u65AD\u3068\u305D\u306E\u6839\u62E0\u30921\u884C1\u4EF6\u3067\u6B8B\u3059\uFF0814\u65E5\u30FB200\u672C\u3067
|
|
@@ -160,12 +143,13 @@ TUI \u5185:
|
|
|
160
143
|
\u4E0A\u306E\u300C\u30C9\u30E1\u30A4\u30F3\u30B3\u30DE\u30F3\u30C9\u300D\u306F\u5229\u7528\u8005\u304C\u76F4\u63A5\u6253\u3064\u3082\u306E\u3067\u3001\u3053\u3061\u3089\u306F\u5B9F\u7269\u3068\u3057\u3066\u52D5\u304D\u307E\u3059\u3002
|
|
161
144
|
\u4F1A\u8A71\u30FB\u30ED\u30FC\u30AB\u30EB\u30C4\u30FC\u30EB\uFF08\u30D5\u30A1\u30A4\u30EB\u30FB\u30B3\u30DE\u30F3\u30C9\u30FBgit\uFF09\u306F\u30C6\u30CA\u30F3\u30C8\u306E\u30AF\u30EC\u30B8\u30C3\u30C8\u3067\u5B9F\u969B\u306B\u52D5\u304D\u307E\u3059\u3002
|
|
162
145
|
`;function ignoreEpipe(stream){stream.on("error",err=>{if(err.code==="EPIPE")process.exit(0);throw err})}async function main(){const nodeMajor=Number(process.versions.node.split(".")[0]);if(nodeMajor<22){process.stderr.write(`twp-cli \u306B\u306F Node.js 22 \u4EE5\u4E0A\u304C\u5FC5\u8981\u3067\u3059\uFF08\u73FE\u5728: ${process.versions.node}\uFF09
|
|
163
|
-
`);process.exit(1)}ignoreEpipe(process.stdout);ignoreEpipe(process.stderr);const args=parseArgv(process.argv.slice(2));if(args.command==="version"){process.stdout.write(`${VERSION}
|
|
146
|
+
`);process.exit(1)}ignoreEpipe(process.stdout);ignoreEpipe(process.stderr);if(process.env["TWP_AUTO_UPDATE_WORKER"]==="1"){const{runAutoUpdateWorker}=await import("./auto-update-worker-ML7EBNQW.js");await runAutoUpdateWorker().catch(()=>void 0);return}const args=parseArgv(process.argv.slice(2));if(args.command==="version"){process.stdout.write(`${VERSION}
|
|
164
147
|
`);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(" ")}
|
|
165
148
|
|
|
166
|
-
${HELP}`);process.exitCode=2;return}if(args.command==="domain"&&args.domain!==void 0){const{runDomain}=await import("./run-
|
|
167
|
-
|
|
168
|
-
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-
|
|
169
|
-
await runner(options);return}if(args.command==="task-loop"){const{runTaskLoop}=await import("./commands-
|
|
170
|
-
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-
|
|
171
|
-
model!==void 0?{model:args.model}:{},...args.profile!==void 0?{profile:args.profile}:{},version:VERSION});return}const{startTui}=await import("./app-
|
|
149
|
+
${HELP}`);process.exitCode=2;return}const autoUpdate=await import("./auto-update-CV2MM32C.js");autoUpdate.registerRunning();if(args.command==="task-loop"){process.env[autoUpdate.DISABLE_ENV]="1"}else if(args.command!=="update"){autoUpdate.onStartup(VERSION)}if(args.command==="domain"&&args.domain!==void 0){const{runDomain}=await import("./run-2OQQAOHL.js");process.exitCode=await runDomain({domain:args.domain,...args.operation!==void 0?{operation:args.operation}:{},argv:args.domainArgv,help:args.
|
|
150
|
+
domainHelp,globals:{...args.profile!==void 0?{profile:args.profile}:{},...args.output!==void 0?{output:args.output}:{},...args.query!==void 0?{query:args.query}:{},dryRun:args.dryRun,debug:args.debug,yes:args.yes,refresh:args.refresh},version:VERSION});return}if(args.command==="api"){const{runApiCommand}=await import("./api-command-2OPQMSTE.js");process.exitCode=await runApiCommand({argv:args.domainArgv,help:args.domainHelp,globals:{...args.profile!==void 0?{profile:args.profile}:{},...args.output!==
|
|
151
|
+
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-EXFIHTMW.js");process.exitCode=await runUpdate({...args.profile!==void 0?{profile:args.profile}:{},version:VERSION});return}if(args.command==="login"||args.command==="logout"||args.command==="whoami"){const{runLogin,runLogout,runWhoami}=await import("./commands-7D5EEQBY.js");
|
|
152
|
+
const options={profile:args.profile,method:args.loginMethod,tenant:args.tenant,noBrowser:args.loginNoBrowser,cliVersion:VERSION,force:args.logoutForce};const runner=args.command==="login"?runLogin:args.command==="logout"?runLogout:runWhoami;process.exitCode=await runner(options);return}if(args.command==="task-loop"){const{runTaskLoop}=await import("./commands-EWRHQZYM.js");process.exitCode=await runTaskLoop({action:args.taskLoopAction??"run",project:args.project,profile:args.profile,safe:args.
|
|
153
|
+
safe,daemon:args.daemon,interval:args.interval,maxCycles:args.maxCycles,forceRunner:args.forceRunner,force:args.stopForce,drain:args.stopDrain,engine:args.engine,version:VERSION,verbose:args.verbose,scheduleNow:args.scheduleNow,scheduleCounts:args.scheduleCounts,scheduleGate:args.scheduleGate,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-AXS5LWUY.js");
|
|
154
|
+
process.exitCode=await runOneShot({prompt:args.prompt??"",fromStdin:args.promptFromStdin,mode:args.mode??"dev",...args.permissionMode!==void 0?{permissionMode:args.permissionMode}:{},allowedTools:args.allowedTools,disallowedTools:args.disallowedTools,...args.model!==void 0?{model:args.model}:{},...args.profile!==void 0?{profile:args.profile}:{},version:VERSION});return}const{startTui}=await import("./app-FZT4U3VG.js");await startTui({mode:args.mode,permissionMode:args.permissionMode,allowedTools:args.
|
|
155
|
+
allowedTools,disallowedTools:args.disallowedTools,model:args.model,profile:args.profile,noTui:args.noTui||!process.stdout.isTTY,doctor:args.doctor,version:VERSION})}await main();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{PromptAbortedError,promptHidden,promptText}from"./chunk-L37NS5L2.js";import{system32}from"./chunk-N2UVRM3Z.js";import{
|
|
4
|
-
import
|
|
3
|
+
import{PromptAbortedError,promptHidden,promptText}from"./chunk-L37NS5L2.js";import{system32}from"./chunk-N2UVRM3Z.js";import{AuthSession,NotLoggedInError,SessionExpiredError,deleteCredentials,loadCredentials,maskToken,saveCredentials}from"./chunk-XNLIEUAW.js";import{isWindowsDriveAbsolute}from"./chunk-PMOUHEJQ.js";import{ApiError,TwpApiClient}from"./chunk-JKSXUBND.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{effectiveApiUrl,resolveProfile}from"./chunk-NERYSBA4.js";
|
|
4
|
+
import"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";import os from"os";import{createHash,randomBytes}from"crypto";function generatePkcePair(){const verifier=randomBytes(32).toString("base64url");return{verifier,challenge:computeChallenge(verifier),method:"S256"}}function computeChallenge(verifier){return createHash("sha256").update(verifier,"ascii").digest("base64url")}function generateState(){return randomBytes(16).toString("base64url")}import http from"http";import crypto from"crypto";function safeEqual(a,b){const x=Buffer.from(a,"utf8");const y=Buffer.from(b,"utf8");const len=Math.max(x.length,y.length,1);const px=Buffer.alloc(len);const py=Buffer.alloc(len);x.copy(px);y.copy(py);return crypto.timingSafeEqual(px,py)&&x.length===y.length}var LoginTimeoutError=class extends Error{constructor(timeoutMs){super(`\u30D6\u30E9\u30A6\u30B6\u3067\u306E\u627F\u8A8D\u3092 ${Math.round(timeoutMs/1e3)} \u79D2\u5F85\u3061\u307E\u3057\u305F\u304C\u5B8C\u4E86\u3057\u307E\u305B\u3093\u3067\u3057\u305F\u3002twp login \u3092\u3084\u308A\u76F4\u3057\u3066\u304F\u3060\u3055\
|
|
5
5
|
\u3044\u3002`)}};var SUCCESS_HTML=`<!doctype html><html lang="ja"><head><meta charset="utf-8"><title>TWP CLI \u30ED\u30B0\u30A4\u30F3\u5B8C\u4E86</title></head>
|
|
6
6
|
<body style="font-family: sans-serif; text-align: center; padding-top: 4rem; background:#f7f9fc; color:#1b2559">
|
|
7
7
|
<h1 style="font-size:1.4rem">\u2705 \u30ED\u30B0\u30A4\u30F3\u304C\u5B8C\u4E86\u3057\u307E\u3057\u305F</h1>
|
|
@@ -44,12 +44,13 @@ res.status,body)}`)}if(body.is_two_factor_authentication){if(!body.two_factor_to
|
|
|
44
44
|
status,body)}`)}}const creds=toStoredCredentials(body,"password",profile);await saveCredentials(profile.name,creds,env);reportLoggedIn(io,profile,creds);return creds}async function tokenLogin(profile,env=process.env,io=defaultIo("0.0.0-dev")){const token=env.TWP_TOKEN?.trim()||await promptHidden("\u30A2\u30AF\u30BB\u30B9\u30C8\u30FC\u30AF\u30F3: ");if(!token)throw new LoginError("\u30C8\u30FC\u30AF\u30F3\u304C\u5165\u529B\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002");const res=await io.fetchImpl(
|
|
45
45
|
`${profile.apiUrl}/api/v2/user`,{headers:{Accept:"application/json",Authorization:`Bearer ${token}`}});if(!res.ok){throw new LoginError(`\u30C8\u30FC\u30AF\u30F3\u306E\u691C\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08GET /api/v2/user -> ${res.status}\uFF09\u3002\u5024\u3068\u63A5\u7D9A\u5148\uFF08${profile.apiUrl}\uFF09\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}const me=(await parseJson(res))?.user;const creds={token,token_expires_at:null,refresh_token:null,refresh_token_expires_at:null,
|
|
46
46
|
api_url:profile.apiUrl,frontend_url:profile.frontendUrl,relay_url:profile.relayUrl,tenant_code:me?.tenant_code??null,user:me?.id?{id:me.id,name:me.name??"",email:me.email??""}:null,method:"token",saved_at:new Date().toISOString()};await saveCredentials(profile.name,creds,env);reportLoggedIn(io,profile,creds);io.out(" \u26A0 \u30E2\u30C7\u30EB\u53D6\u6B21\uFF08\u4F1A\u8A71\uFF09\u306B\u306F `cli` \u6A29\u9650\u4ED8\u304D\u30C8\u30FC\u30AF\u30F3\u304C\u5FC5\u8981\u3067\u3059\u3002\u3053\u3053\u3067\u4FDD\u5B58\u3057\u305F\u30C8\u30FC\u30AF\u30F3\u304C\n `twp login` / `twp login --password` \u7531\u6765\u3067\u306A\u3044\u5834\u5408\u3001\u4F1A\u8A71\u306F 401 \u306B\u306A\u308A\u307E\u3059\u3002\n");
|
|
47
|
-
return creds}function writeOut(text){process.stdout.write(stripTerminalControls(text))}function writeErr(text){process.stderr.write(stripTerminalControls(text))}function makeIo(cliVersion){return{out:writeOut,fetchImpl:httpFetch,cliVersion}}async function run(fn){try{await fn();return 0}catch(err){if(err instanceof PromptAbortedError){writeErr("\n\u4E2D\u6B62\u3057\u307E\u3057\u305F\u3002\n");return 130}if(err instanceof
|
|
48
|
-
SessionExpiredError||err instanceof ApiError){writeErr(`${err.message}
|
|
47
|
+
return creds}function writeOut(text){process.stdout.write(stripTerminalControls(text))}function writeErr(text){process.stderr.write(stripTerminalControls(text))}function makeIo(cliVersion){return{out:writeOut,fetchImpl:httpFetch,cliVersion}}var LogoutRefusedError=class extends Error{};async function run(fn){try{await fn();return 0}catch(err){if(err instanceof LogoutRefusedError){return 1}if(err instanceof PromptAbortedError){writeErr("\n\u4E2D\u6B62\u3057\u307E\u3057\u305F\u3002\n");return 130}if(err instanceof
|
|
48
|
+
LoginError||err instanceof LoginTimeoutError||err instanceof NotLoggedInError||err instanceof SessionExpiredError||err instanceof ApiError){writeErr(`${err.message}
|
|
49
49
|
`);return 1}writeErr(`\u30A8\u30E9\u30FC: ${err.message}
|
|
50
50
|
`);return 1}}async function runLogin(options){return run(async()=>{const profile=resolveProfile(options.profile);const io=makeIo(options.cliVersion);if(options.method==="password"){await passwordLogin(profile,{tenantCode:options.tenant??void 0},process.env,io)}else if(options.method==="token"){await tokenLogin(profile,process.env,io)}else{await browserLogin(profile,process.env,io,{noBrowser:options.noBrowser})}})}async function runLogout(options){return run(async()=>{const profile=resolveProfile(
|
|
51
51
|
options.profile);const creds=loadCredentials(profile.name);if(!creds){writeOut(`\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB\u300C${profile.name}\u300D\u306F\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u3044\u307E\u305B\u3093\u3002
|
|
52
|
-
`);return}const apiUrl=effectiveApiUrl(profile,creds.api_url);const revoked=await httpFetch(`${apiUrl}/api/v2/auth/logout`,{method:"POST",headers:{Accept:"
|
|
52
|
+
`);return}const{describeLogoutImpact,findLoopsUsingProfile}=await import("./logout-guard-Q4MQFEGR.js");const found=findLoopsUsingProfile(profile.name,options.logoutGuard);if(found.users.length>0||found.undetermined.length>0){writeErr(describeLogoutImpact(profile.name,found,options.force===true));if(options.force!==true)throw new LogoutRefusedError}const apiUrl=effectiveApiUrl(profile,creds.api_url);const revoked=await httpFetch(`${apiUrl}/api/v2/auth/logout`,{method:"POST",headers:{Accept:"applic\
|
|
53
|
+
ation/json",Authorization:`Bearer ${creds.token}`}}).then(res=>res.ok,()=>false);await deleteCredentials(profile.name);writeOut(`\u2705 \u30ED\u30B0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\uFF08\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB: ${profile.name} / \u30C8\u30FC\u30AF\u30F3: ${maskToken(creds.token)}\uFF09
|
|
53
54
|
`);if(!revoked){writeOut("\u26A0 \u30B5\u30FC\u30D0\u5074\u306E\u30C8\u30FC\u30AF\u30F3\u5931\u52B9\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08\u30AA\u30D5\u30E9\u30A4\u30F3\u7B49\uFF09\u3002TWP \u306E\u300C\u8A2D\u5B9A > CLI\u7AEF\u672B\u300D\u304B\u3089\u3082\u5931\u52B9\u3067\u304D\u307E\u3059\u3002\n")}})}async function runWhoami(options){return run(async()=>{const profile=resolveProfile(options.profile);const stored=loadCredentials(profile.name);const apiUrl=effectiveApiUrl(profile,stored?.
|
|
54
55
|
api_url);const session=new AuthSession(profile.name,apiUrl);const client=new TwpApiClient(apiUrl,session,httpFetch,options.cliVersion);const me=await client.get("/api/v2/user");const user=me.user;const creds=loadCredentials(profile.name);writeOut(`\u30E6\u30FC\u30B6\u30FC: ${user?.name??"?"}\uFF08${user?.email??"?"}\uFF09
|
|
55
56
|
`);writeOut(`\u30C6\u30CA\u30F3\u30C8: ${user?.tenant_code??"?"}
|