@tocca-systems/twp-cli 0.17.1 → 0.19.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 +8 -0
- package/README.md +82 -7
- package/dist/{ai-dispatch-27EZS2S3.js → ai-dispatch-PNA4UF4I.js} +2 -2
- package/dist/{api-command-UIL4WGMG.js → api-command-JJJOEIZQ.js} +2 -2
- package/dist/{app-LLSZV6SM.js → app-SOQPONUU.js} +22 -21
- 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-3WHC4FSG.js +15 -0
- package/dist/chunk-5WGOHFAS.js +3 -0
- package/dist/chunk-BOBSH3QN.js +9 -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-Y5RTTQ4Y.js → chunk-MGKVUKU5.js} +90 -43
- package/dist/{chunk-7WEYBZSK.js → chunk-MIMDLO52.js} +1 -1
- package/dist/{chunk-H3JTPDCJ.js → chunk-NWABK3RZ.js} +3 -18
- package/dist/{chunk-KXFT226N.js → chunk-VGK2JMBW.js} +17 -15
- package/dist/{chunk-63LDNYGW.js → chunk-XNLIEUAW.js} +1 -1
- package/dist/cli.js +54 -33
- 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-HQJEXZHJ.js → oneshot-XLLRNRLK.js} +8 -7
- package/dist/{project-OKTJ32JT.js → project-BATJQR3F.js} +1 -1
- package/dist/{run-DWQEHR6I.js → run-OB3JFPSH.js} +2 -2
- package/dist/{setup-AJ56N6XO.js → setup-ROGEF3UO.js} +2 -1
- package/dist/{task-7K54BO5U.js → task-6QUH5OXF.js} +39 -8
- package/dist/update-EXFIHTMW.js +3 -0
- package/package.json +1 -1
- package/dist/chunk-S646CPM4.js +0 -9
- package/dist/update-WDWUECN7.js +0 -21
|
@@ -1,10 +1,10 @@
|
|
|
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
|
-
|
|
5
|
-
|
|
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}`})}
|
|
7
|
-
function formatBody(raw){const safe=redactSecrets(stripTerminalControls(raw));return safe.length>BODY_LIMIT?`${safe.slice(0,BODY_LIMIT)}
|
|
3
|
+
import{stringWidth}from"./chunk-WVS4W5FY.js";import{parseOperationArgs}from"./chunk-O52CUEDO.js";import{GLOBAL_OPTIONS_HELP,HELP_TOKEN}from"./chunk-FKIZ5ZJU.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";import{effectiveApiUrl,loadUserConfig,
|
|
4
|
+
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
|
+
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
|
+
"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
|
+
var BODY_LIMIT=4e3;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,18 +31,19 @@ ${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-
|
|
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-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
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)}
|
|
38
38
|
`);return}writeErr(`${message}
|
|
39
39
|
`);if(hint!==void 0)writeErr(`${hint}
|
|
40
40
|
`)}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
|
-
message}`,{cause:err})}}function
|
|
42
|
-
|
|
43
|
-
existsSync(
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
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
|
+
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.
|
|
43
|
+
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.existsSync(
|
|
44
|
+
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.query))}catch(err){
|
|
45
|
+
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.target.out}`,"\u4E0A\u66F8\u304D\
|
|
46
|
+
\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
47
|
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
48
|
\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
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
|
|
@@ -56,9 +57,10 @@ renderResourceHelp(domain,domain.name));return EXIT_OK}const target=domain.subre
|
|
|
56
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)){writeOut(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]===HELP_TOKEN){writeOut(renderOperationHelp(operation,path2));return EXIT_OK}
|
|
57
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);const downloadTarget=operation.download===void 0?void 0:resolveDownloadTarget(operation.download,path2,operation.name,input);const stored=loadCredentials(
|
|
58
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({resolver:new Resolver(client,{profile:profile.name,refresh:globals.refresh,...profileAliases(profile.name)}),profileName:profile.name,env:process.env,
|
|
59
|
-
cwd:process.cwd()});const prepared=operation.prepare===void 0?input:await operation.prepare(input,ctx);const plan=operation.plan(prepared);if(operation.
|
|
60
|
-
for(const note of operation.plannedNotes?.(prepared)??[])writeErr(`${safeText(note)}
|
|
61
|
-
`);if(globals.dryRun){writeOut(line(renderOutput(dryRunValue(apiUrl,plan),format)));return EXIT_OK}let body;let paged;if(operation.
|
|
62
|
-
|
|
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 / fetchCached \u3068\u540C\u6642\u306B\u5BA3\u8A00\u3067\u304D\u307E\u305B\u3093\uFF08\u914D\u7DDA\u306E\u8AA4\u308A\uFF09`)}if(operation.fetchCached!==void 0&&
|
|
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`)}for(const note of operation.plannedNotes?.(prepared)??[])writeErr(`${safeText(note)}
|
|
62
|
+
`);if(globals.dryRun){writeOut(line(renderOutput(dryRunValue(apiUrl,plan),format)));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=>writeErr(`${safeText(text)}
|
|
63
|
+
`)};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});
|
|
64
|
+
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
65
|
`)}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
66
|
`)}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{
|
|
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
|
package/dist/cli.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
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{isModeId,isPermissionModeId}from"./chunk-
|
|
5
|
-
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
|
-
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
|
-
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
|
-
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:[]
|
|
9
|
-
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=
|
|
10
|
-
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.
|
|
11
|
-
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.
|
|
12
|
-
|
|
13
|
-
--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}
|
|
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{
|
|
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.
|
|
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"--
|
|
17
|
-
|
|
18
|
-
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":{
|
|
19
|
-
|
|
20
|
-
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.
|
|
21
|
-
command!=="
|
|
22
|
-
"
|
|
23
|
-
if(out.
|
|
24
|
-
void 0)out.unknown.push("--
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
interval!==void 0)out.unknown.push("--interval");if(out.maxCycles!==void 0)out.unknown.push("--max-cycles")}
|
|
4
|
+
import{isModeId,isPermissionModeId}from"./chunk-BOBSH3QN.js";import{API_TOKEN,GLOBAL_OPTIONS_HELP,HELP_TOKEN,isDomainName}from"./chunk-FKIZ5ZJU.js";import{splitFlagToken}from"./chunk-QQRJLH6B.js";import"./chunk-VSJBJXZO.js";var BUILTIN_COMMANDS=["login","logout","whoami","update","task-loop"];var TASK_LOOP_ACTIONS=["run","status","stop","schedule","setup"];var VALUE_FLAGS=new Set(["-p","--print","--profile","--tenant","--mode","--permission-mode","--model","--allowed-tools","--disallowed-tools","--project","--engine","--interval","--max-cycles","--ai","--workspace","--ai-config-file","--now","--counts","--gate","--output","--query"]);var BOOLEAN_FLAGS=new Set(["-h","--help","-v","--version","--no-tui","--doctor","-\
|
|
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,logoutForce: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:[],
|
|
9
|
+
disallowedTools:[]};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=
|
|
10
|
+
"domain";out.domain=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.
|
|
11
|
+
domain;if(route.operation!==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.
|
|
12
|
+
trim()===""){out.unknown.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.
|
|
13
|
+
push(raw);continue}switch(arg){case"-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}
|
|
14
|
+
break}case"-p":case"--print":{const next=inline??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{
|
|
15
|
+
value,step}=takeValue(i,"--query",inline);if(value!==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.
|
|
16
|
+
unknown.push(inline!==void 0?raw:`--mode ${next}`);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(
|
|
17
|
+
i,arg,inline);if(value!==void 0){(arg==="--allowed-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!==
|
|
18
|
+
void 0){out.project=value;i+=step}break}case"--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":{
|
|
19
|
+
const{value:v,step}=takeValue(i,"--ai",inline);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",
|
|
20
|
+
inline);if(v!==void 0){out.scheduleNow=v;i+=step}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.
|
|
21
|
+
command!=="tui"&&out.command!=="print"){out.unknown.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==="logout"&&out.stopForce){
|
|
22
|
+
out.logoutForce=true;out.stopForce=false}if(out.command!=="task-loop"){if(out.safe)out.unknown.push("--safe");if(out.daemon)out.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.
|
|
23
|
+
push("--project");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.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"&&
|
|
24
|
+
!isDomainRoute)out.unknown.push("--yes");if(!isDomainRoute){if(out.output!==void 0)out.unknown.push("--output");if(out.query!==void 0)out.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!==
|
|
25
|
+
void 0)out.unknown.push("--now");if(out.scheduleCounts!==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");
|
|
26
|
+
out.stopForce=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.
|
|
27
|
+
daemon)out.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-runn\
|
|
28
|
+
er");if(out.interval!==void 0)out.unknown.push("--interval");if(out.maxCycles!==void 0)out.unknown.push("--max-cycles")}return out}var VERSION=true?"0.19.0":"0.0.0-dev";var HELP=`twp ${VERSION} \u2014 TWP CLI
|
|
28
29
|
|
|
29
30
|
\u4F7F\u3044\u65B9:
|
|
30
31
|
twp \u5BFE\u8A71 TUI \u3092\u8D77\u52D5
|
|
@@ -37,10 +38,10 @@ interval!==void 0)out.unknown.push("--interval");if(out.maxCycles!==void 0)out.u
|
|
|
37
38
|
twp login --tenant <code>
|
|
38
39
|
\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
|
|
39
40
|
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
|
|
41
|
+
\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
|
|
40
42
|
twp whoami \u30ED\u30B0\u30A4\u30F3\u4E2D\u306E\u30E6\u30FC\u30B6\u30FC\u30FB\u30C6\u30CA\u30F3\u30C8\u3092\u8868\u793A
|
|
41
43
|
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
|
|
42
|
-
\uFF08\
|
|
43
|
-
\u4E0B\u9650\u672A\u6E80\u306A\u3089\u7D42\u4E86\u30B3\u30FC\u30C9 1\uFF09
|
|
44
|
+
\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
|
|
44
45
|
twp task-loop setup --project <\u30AD\u30FC|UUID>
|
|
45
46
|
\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
|
|
46
47
|
--yes \u3067\u5BFE\u8A71\u3092\u7701\u7565\u3001--ai claude,codex \u3067\u660E\u793A\u3001
|
|
@@ -69,6 +70,13 @@ interval!==void 0)out.unknown.push("--interval");if(out.maxCycles!==void 0)out.u
|
|
|
69
70
|
plan / denyAll \u306F git \u3082\u6B62\u3081\u308B\uFF08\u30EA\u30DD\u30B8\u30C8\u30EA\u8A2D\u5B9A\u7D4C\u7531\u3067
|
|
70
71
|
\u4EFB\u610F\u30B3\u30DE\u30F3\u30C9\u304C\u8D70\u308A\u3046\u308B\u305F\u3081\uFF09\u3002
|
|
71
72
|
\u975E\u5BFE\u8A71\uFF08-p / \u30D1\u30A4\u30D7\uFF09\u3067\u306F\u627F\u8A8D\u3067\u304D\u306A\u3044\u305F\u3081 ask \u306F\u62D2\u5426\u306B\u306A\u308B
|
|
73
|
+
twp --allowed-tools <\u898F\u5247>
|
|
74
|
+
twp --disallowed-tools <\u898F\u5247>
|
|
75
|
+
\u6A29\u9650\u30EB\u30FC\u30EB\u3092\u8FFD\u52A0\uFF08Claude Code \u4E92\u63DB\u3002\u4F8B: "Bash(git status:*)",
|
|
76
|
+
"Write(src/**)", twp_update_task\u3002\u30AB\u30F3\u30DE\u533A\u5207\u308A\u30FB\u7E70\u308A\u8FD4\u3057\u53EF\uFF09\u3002
|
|
77
|
+
deny \u306F\u5E38\u306B\u52DD\u3064\uFF08--allowed-tools \u3067\u3082\u30E2\u30FC\u30C9\u306E deny \u306F\u8986\u3089\u306A\u3044\uFF09\u3002
|
|
78
|
+
\u30D5\u30A1\u30A4\u30EB\u3067\u306F ~/.twp/settings.json \u306E permissions.allow/ask/deny\u3002
|
|
79
|
+
.twp/settings*.json\uFF08\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u914D\u4E0B\uFF09\u306F\u7DE0\u3081\u308B\u5411\u304D\u306B\u3057\u304B\u52B9\u304B\u306A\u3044
|
|
72
80
|
twp --model <id> \u8D77\u52D5\u6642\u306E\u30E2\u30C7\u30EB\u3092\u6307\u5B9A
|
|
73
81
|
twp --profile <name> \u63A5\u7D9A\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB\u3092\u6307\u5B9A\uFF08TWP_PROFILE \u3067\u3082\u53EF\uFF09
|
|
74
82
|
twp --no-tui \u7D20\u306E\u30B9\u30C8\u30EA\u30FC\u30E0\u51FA\u529B\u3067\u8D77\u52D5\uFF08VT \u975E\u5BFE\u5FDC\u7AEF\u672B\u30FB\u30D1\u30A4\u30D7\u5411\u3051\uFF09
|
|
@@ -95,6 +103,12 @@ interval!==void 0)out.unknown.push("--interval");if(out.maxCycles!==void 0)out.u
|
|
|
95
103
|
\u30B3\u30E1\u30F3\u30C8\u306E\u672C\u6587\u3092\u66F8\u304D\u63DB\u3048\u308B\uFF08--task \u304C\u8981\u308B\uFF09
|
|
96
104
|
twp task comment delete <\u30B3\u30E1\u30F3\u30C8ID>
|
|
97
105
|
\u30B3\u30E1\u30F3\u30C8\u3092\u524A\u9664\u3059\u308B\uFF08--task \u3068 --yes \u304C\u8981\u308B\uFF09
|
|
106
|
+
twp task attachment list <\u30AD\u30FC>
|
|
107
|
+
\u30BF\u30B9\u30AF\u306E\u6DFB\u4ED8\u30D5\u30A1\u30A4\u30EB\u3092\u4E00\u89A7\u3059\u308B
|
|
108
|
+
twp task attachment upload <\u30AD\u30FC>
|
|
109
|
+
\u30D5\u30A1\u30A4\u30EB\u3092\u6DFB\u4ED8\u3059\u308B\uFF08--file \u5FC5\u9808\u30FB3\u5F80\u5FA9\u30921\u30B3\u30DE\u30F3\u30C9\u3067\uFF09
|
|
110
|
+
twp task attachment download <\u6DFB\u4ED8ID>
|
|
111
|
+
\u6DFB\u4ED8\u3092\u30D5\u30A1\u30A4\u30EB\u3078\u66F8\u304D\u51FA\u3059\uFF08--out \u5FC5\u9808\uFF09
|
|
98
112
|
twp task status list --status \u306B\u6E21\u305B\u308B\u30B9\u30C6\u30FC\u30BF\u30B9\u3092\u4E00\u89A7\u3059\u308B\uFF08\u65E2\u5B9A\u306F is_default\uFF09
|
|
99
113
|
twp task type list --type \u306B\u6E21\u305B\u308B\u7A2E\u5225\u3092\u4E00\u89A7\u3059\u308B
|
|
100
114
|
twp task category list \u30BF\u30B9\u30AF\u306E\u30AB\u30C6\u30B4\u30EA\u3092\u4E00\u89A7\u3059\u308B
|
|
@@ -136,6 +150,12 @@ TUI \u5185:
|
|
|
136
150
|
Ctrl+R \u76F4\u524D\u306E\u30C4\u30FC\u30EB\u51FA\u529B\u3092\u5168\u6587\u5C55\u958B
|
|
137
151
|
Ctrl+C \u4E2D\u65AD\uFF08\u5165\u529B\u304C\u7A7A\u306A\u3089 2 \u56DE\u3067\u7D42\u4E86\uFF09 \xB7 Ctrl+D \u7D42\u4E86
|
|
138
152
|
|
|
153
|
+
\u81EA\u52D5\u66F4\u65B0:
|
|
154
|
+
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
|
|
155
|
+
\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
|
|
156
|
+
TWP_NO_AUTO_UPDATE=1 \u304B ~/.twp/config.json \u306E "auto_update": false \u3067\u7121\u52B9\u5316\u3002
|
|
157
|
+
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
|
|
158
|
+
|
|
139
159
|
\u76E3\u67FB\u30ED\u30B0:
|
|
140
160
|
~/.twp/logs/session-*.jsonl
|
|
141
161
|
\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
|
|
@@ -146,12 +166,13 @@ TUI \u5185:
|
|
|
146
166
|
\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
|
|
147
167
|
\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
|
|
148
168
|
`;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
|
|
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}
|
|
169
|
+
`);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}
|
|
150
170
|
`);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
171
|
|
|
152
|
-
${HELP}`);process.exitCode=2;return}if(args.command==="domain"&&args.domain!==void 0){const{runDomain}=await import("./run-
|
|
153
|
-
|
|
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-
|
|
155
|
-
await runner(options);return}if(args.command==="task-loop"){const{runTaskLoop}=await import("./commands-
|
|
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-
|
|
157
|
-
profile}:{},version:VERSION});return}const{startTui}=await import("./app-
|
|
172
|
+
${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-OB3JFPSH.js");process.exitCode=await runDomain({domain:args.domain,...args.operation!==void 0?{operation:args.operation}:{},argv:args.domainArgv,help:args.
|
|
173
|
+
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-JJJOEIZQ.js");process.exitCode=await runApiCommand({argv:args.domainArgv,help:args.domainHelp,globals:{...args.profile!==void 0?{profile:args.profile}:{},...args.output!==
|
|
174
|
+
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");
|
|
175
|
+
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.
|
|
176
|
+
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-XLLRNRLK.js");
|
|
177
|
+
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-SOQPONUU.js");await startTui({mode:args.mode,permissionMode:args.permissionMode,allowedTools:args.
|
|
178
|
+
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??"?"}
|