@tocca-systems/twp-cli 0.22.0 → 0.24.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.
Files changed (65) hide show
  1. package/CHANGELOG.public.md +6 -0
  2. package/README.md +147 -6
  3. package/command-model/department.json +1 -1
  4. package/dist/{ai-dispatch-VSCKUY6J.js → ai-dispatch-36HRDRLF.js} +1 -1
  5. package/dist/{api-command-Q2CSB4PV.js → api-command-NMYYJKZH.js} +5 -17
  6. package/dist/{app-THTQX3A5.js → app-2KMY3QPM.js} +27 -26
  7. package/dist/{auto-update-FBZGOQFI.js → auto-update-CV2MM32C.js} +1 -1
  8. package/dist/{auto-update-worker-Z3XKBFMQ.js → auto-update-worker-AXBJIMFP.js} +2 -2
  9. package/dist/{backlog-X2MQTA6F.js → backlog-7MJIOT22.js} +2 -2
  10. package/dist/{charter-command-UPKTVL7H.js → charter-command-UBUE3KUO.js} +2 -2
  11. package/dist/{chunk-5ISIXBKD.js → chunk-4V4T5ZUS.js} +45 -18
  12. package/dist/chunk-5Q2CH4E7.js +3 -0
  13. package/dist/chunk-6NCY4NPV.js +62 -0
  14. package/dist/{chunk-M3GWY6NT.js → chunk-7WSNIXTQ.js} +2 -1
  15. package/dist/chunk-DDKZ5IPT.js +11 -0
  16. package/dist/{chunk-2VISRLWS.js → chunk-DMDVLOAY.js} +8 -8
  17. package/dist/chunk-EJ474UDB.js +3 -0
  18. package/dist/chunk-FTYJZFEK.js +10 -0
  19. package/dist/{chunk-E4H22AO5.js → chunk-GDM2QUBL.js} +1 -1
  20. package/dist/{chunk-X4RS5VBH.js → chunk-GMBJTG6A.js} +1 -1
  21. package/dist/{chunk-QVXZEUKN.js → chunk-HGTG5XQ7.js} +1 -1
  22. package/dist/{chunk-I2QFW7EK.js → chunk-HW3QGKYR.js} +1 -1
  23. package/dist/chunk-I3YPO7CY.js +57 -0
  24. package/dist/chunk-IJLJGDMZ.js +7 -0
  25. package/dist/{chunk-DSDVIU6A.js → chunk-ILKQDXI5.js} +1 -1
  26. package/dist/{chunk-O52CUEDO.js → chunk-IOGVQVGD.js} +1 -1
  27. package/dist/chunk-NAUH75MM.js +10 -0
  28. package/dist/chunk-NZ7WI4RZ.js +18 -0
  29. package/dist/{chunk-JB27KNCX.js → chunk-QOUFHYK5.js} +29 -25
  30. package/dist/{chunk-XLE4HW6B.js → chunk-UIWGEBWI.js} +1 -1
  31. package/dist/{chunk-JDMNIUVX.js → chunk-VCMVTC6B.js} +1 -1
  32. package/dist/chunk-WGVHYTZV.js +38 -0
  33. package/dist/{chunk-PI5DUWNZ.js → chunk-WOUKWOAR.js} +1 -1
  34. package/dist/{chunk-3XG457E3.js → chunk-YVAN3H5W.js} +5 -5
  35. package/dist/chunk-ZN5EFDH7.js +5 -0
  36. package/dist/chunk-ZWVYVS2A.js +4 -0
  37. package/dist/cli.js +78 -11
  38. package/dist/{commands-ET4F34OD.js → commands-6YTOVZ5P.js} +16 -16
  39. package/dist/{commands-NXBQ5OWL.js → commands-U36UTCKR.js} +8 -8
  40. package/dist/department-JOXXJKQB.js +33 -0
  41. package/dist/job-title-L47J6TZY.js +8 -0
  42. package/dist/{logout-guard-CMZZBRUL.js → logout-guard-FO7KZL3X.js} +1 -1
  43. package/dist/media-ZMDYHHNN.js +64 -0
  44. package/dist/{oneshot-QVFA2SUM.js → oneshot-KYATQPL7.js} +5 -5
  45. package/dist/position-FHWCMMBQ.js +8 -0
  46. package/dist/{project-2LJZW747.js → project-ZODASYER.js} +1 -1
  47. package/dist/query-EEALMOSO.js +3 -0
  48. package/dist/render-K45EOLHX.js +3 -0
  49. package/dist/run-QCDT35NT.js +4 -0
  50. package/dist/server-settings-CG3EM7R7.js +1 -1
  51. package/dist/{setup-UI6V2Q3V.js → setup-6CXUVCF5.js} +1 -1
  52. package/dist/storage-ANKKJJJO.js +3 -0
  53. package/dist/{task-GKNM3G4K.js → task-G5YWQ6L5.js} +7 -63
  54. package/dist/{update-3QHRK5BP.js → update-PZBUIYOL.js} +1 -1
  55. package/dist/user-DO4VNIBR.js +204 -0
  56. package/package.json +1 -1
  57. package/dist/chunk-BOBSH3QN.js +0 -9
  58. package/dist/chunk-GFC2ASHE.js +0 -6
  59. package/dist/chunk-JKSXUBND.js +0 -9
  60. package/dist/chunk-PEGUHUTD.js +0 -3
  61. package/dist/chunk-RKJ6B2KL.js +0 -56
  62. package/dist/query-NJMVSQR6.js +0 -3
  63. package/dist/render-XMVI3AKB.js +0 -3
  64. package/dist/run-IS46BQBB.js +0 -4
  65. package/dist/user-EU7Z3DAO.js +0 -24
@@ -1,6 +1,7 @@
1
1
  import { createRequire as __twpCreateRequire } from 'node:module';
2
2
  const require = __twpCreateRequire(import.meta.url);
3
- import{isForceOnly,killProcessTree,system32}from"./chunk-N2UVRM3Z.js";import{MODES,applyPermissionMode,checkPermission,isModeId,setActiveModes}from"./chunk-BOBSH3QN.js";import{DEFAULT_MAX_TOKENS,emptyUsage}from"./chunk-PI5DUWNZ.js";import{findExecutable,isWindowsDriveAbsolute}from"./chunk-PMOUHEJQ.js";import{configReadDirs,ensureTwpHome,twpHomeDir}from"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import fs2 from"fs";import path3 from"path";import os2 from"os";import{realpathSync}from"fs";import{homedir}from"os";import{dirname,isAbsolute,relative,resolve,sep}from"path";var PathDeniedError=class extends Error{constructor(message){super(message);this.name="PathDeniedError"}};function resolveToolPath(input,cwd,home=homedir()){if(typeof input!=="string"||input.trim()===""){throw new PathDeniedError("path must be a non-empty string")}const expanded=expandHome(input,home);const abs=isAbsolute(expanded)?resolve(expanded):resolve(cwd,expanded);const root=realOrSelf(resolve(cwd));assertInside(abs,resolve(cwd),abs);assertNotSecret(abs,home);const real=realOrSelf(abs);if(real!==
3
+ import{CommandModelMissingError,MAX_REPORTED_VIOLATIONS,loadCommandModelDomain,loadCommandModelIndex,validateBody,validateQuery}from"./chunk-NZ7WI4RZ.js";import{isForceOnly,killProcessTree,system32}from"./chunk-N2UVRM3Z.js";import{redactSecretValues,redactSecrets}from"./chunk-YVAN3H5W.js";import{ApiError,TwpApiClient,appendQuery}from"./chunk-FTYJZFEK.js";import{isSafePathSegment}from"./chunk-GMBJTG6A.js";import{MODES,applyPermissionMode,checkPermission,isModeId,setActiveModes}from"./chunk-NAUH75MM.js";
4
+ import{DEFAULT_MAX_TOKENS,emptyUsage}from"./chunk-WOUKWOAR.js";import{AuthSession}from"./chunk-XNLIEUAW.js";import{findExecutable,isWindowsDriveAbsolute}from"./chunk-PMOUHEJQ.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{configReadDirs,ensureTwpHome,twpHomeDir}from"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import fs2 from"fs";import path3 from"path";import os2 from"os";import{realpathSync}from"fs";import{homedir}from"os";import{dirname,isAbsolute,relative,resolve,sep}from"path";var PathDeniedError=class extends Error{constructor(message){super(message);this.name="PathDeniedError"}};function resolveToolPath(input,cwd,home=homedir()){if(typeof input!=="string"||input.trim()===""){throw new PathDeniedError("path must be a non-empty string")}const expanded=expandHome(input,home);const abs=isAbsolute(expanded)?resolve(expanded):resolve(cwd,expanded);const root=realOrSelf(resolve(cwd));assertInside(abs,resolve(cwd),abs);assertNotSecret(abs,home);const real=realOrSelf(abs);if(real!==
4
5
  abs){assertInside(real,root,abs);assertNotSecret(real,home)}return abs}function realToolPath(input,cwd,home=homedir()){return realOrSelf(resolveToolPath(input,cwd,home))}function assertInside(target,root,reported){const rel=relative(root,target);const outside=rel===".."||rel.startsWith(`..${sep}`)||isAbsolute(rel);if(outside){throw new PathDeniedError(`path escapes the working directory (${reported}). Only paths under ${root} can be accessed.`)}}function realOrSelf(target){let current=target;const rest=[];
5
6
  for(;;){try{const real=realpathSync(current);return rest.length===0?real:resolve(real,...rest.reverse())}catch{const parent=dirname(current);if(parent===current)return target;rest.push(current.slice(parent.length+1));current=parent}}}function assertNotSecret(absPath,home=homedir(),env=process.env){const reason=secretReason(absPath,home,env);if(reason!==null)throw new PathDeniedError(`refusing to access ${absPath}: ${reason}`)}function secretReason(absPath,_home=homedir(),env=process.env){const lower=absPath.
6
7
  toLowerCase();const segments=lower.split(sep);const base=segments[segments.length-1]??"";const parent=segments[segments.length-2]??"";if(base===".env"||base.startsWith(".env."))return".env files are denied (design \xA77)";if(segments.includes(".ssh"))return"SSH key material is denied (design \xA77)";if(parent===".git"&&base==="config"){return".git/config is denied (it can hold a GitHub token in the remote URL)"}if(base===".netrc"||base==="_netrc"||base===".npmrc")return"credential files are deni\
@@ -76,13 +77,13 @@ return third!==void 0&&SCRIPT_NAME.test(third)?`${pair} ${third}`:null}function
76
77
  for(const[key,sub]of Object.entries(props)){if(value[key]===void 0){if(sub.default!==void 0)value[key]=sub.default;continue}checkValue(`${key}`,sub,value[key],errors)}return{ok:errors.length===0,errors,value}}function checkValue(path8,schema,value,errors){switch(schema.type){case"string":if(typeof value!=="string")errors.push(`${path8} must be a string`);break;case"boolean":if(typeof value!=="boolean")errors.push(`${path8} must be a boolean`);break;case"integer":if(typeof value!=="number"||!Number.
77
78
  isInteger(value))errors.push(`${path8} must be an integer`);break;case"number":if(typeof value!=="number"||!Number.isFinite(value))errors.push(`${path8} must be a number`);break;case"array":if(!Array.isArray(value)){errors.push(`${path8} must be an array`);break}if(schema.items){value.forEach((item,i)=>checkValue(`${path8}[${i}]`,schema.items,item,errors))}break;case"object":if(typeof value!=="object"||value===null||Array.isArray(value)){errors.push(`${path8} must be an object`)}break;default:break}
78
79
  if(schema.enum&&!schema.enum.some(v=>v===value)){errors.push(`${path8} must be one of: ${schema.enum.join(", ")}`)}if(typeof value==="number"){if(schema.minimum!==void 0&&value<schema.minimum)errors.push(`${path8} must be >= ${schema.minimum}`);if(schema.maximum!==void 0&&value>schema.maximum)errors.push(`${path8} must be <= ${schema.maximum}`)}}async function executeTool(tool,rawInput,deps,callId){const validated=validateInput(tool.inputSchema,rawInput);if(!validated.ok){const content=`Invalid input for ${tool.name}:
79
- - ${validated.errors.join("\n- ")}`;deps.audit.record({event:"result",tool:tool.name,risk:tool.risk,outcome:"error",bytes:Buffer.byteLength(content),mode:deps.mode.id,reasonCode:"invalid_input",callId});return{content,isError:true,summary:`${tool.name} \xB7 \u5165\u529B\u304C\u4E0D\u6B63`}}const input=validated.value;let judged={tool};const verdictTarget=()=>judged;const recordDecision=(decision,reasonCode,reason)=>{deps.audit.record({event:"decision",tool:verdictTarget().tool.name,risk:verdictTarget().
80
- tool.risk,decision,reasonCode,reason,mode:deps.mode.id,rawInput:input,callId})};const verdict=checkToolPermission({tool,input},{mode:deps.mode,cwd:deps.ctx.cwd,sessionAllow:deps.sessionAllow,...deps.sessionRules?{sessionRules:deps.sessionRules}:{},...deps.permissionLayers?{layers:deps.permissionLayers}:{},...deps.permissionMode!==void 0?{permissionMode:deps.permissionMode}:{},...deps.resolveTool?{resolveTool:deps.resolveTool}:{}});const policy=verdict.decision;judged=verdict.target;const target=verdict.
81
- target;if(policy==="deny"){recordDecision("deny",reasonCodeOf(verdict),verdict.reason);return{content:denyMessage(tool.name,verdict,deps),isError:true,denied:true,summary:`${tool.name} \xB7 deny\uFF08${denySummary(verdict,deps)}\uFF09`}}const preview=safePreview(tool,input);const noAlwaysReason=neverAutoAllowReason(target.tool,target.input)??autoApproveExemptReason(target.tool,target.input,deps.ctx.cwd)??verdict.noAlwaysReason??null;const needsAsk=policy==="ask"||noAlwaysReason!==null;if(needsAsk){
82
- {if(!deps.askPermission){recordDecision("deny",noAlwaysReason===null?"non_interactive":"guard",noAlwaysReason??"\u975E\u5BFE\u8A71\u30BB\u30C3\u30B7\u30E7\u30F3\u3067\u627F\u8A8D\u304C\u5FC5\u8981\uFF08deny-and-continue\uFF09");return{content:`permission denied: ${tool.name} requires approval, and this session is non-interactive. `+(noAlwaysReason===null?"":`Reason: ${noAlwaysReason} `)+"Explain what you would run instead of running it.",isError:true,denied:true,summary:`${tool.name} \xB7 \u975E\u5BFE\u8A71\u306E\u305F\u3081\u62D2\u5426`}}
83
- let diff;try{diff=await tool.prepare?.(input,deps.ctx)??void 0}catch(err){diff=void 0;if(err instanceof PathDeniedError){recordDecision("deny","path_denied","\u4FDD\u8B77\u3055\u308C\u305F\u30D1\u30B9\uFF08paths.ts\uFF09");return{content:err.message,isError:true,denied:true,summary:`${tool.name} \xB7 deny\uFF08\u4FDD\u8B77\u3055\u308C\u305F\u30D1\u30B9\uFF09`}}}const persistOptions=deps.persistAllow?persistOptionsFor(target,noAlwaysReason,deps.ctx.cwd):[];const answer=await deps.askPermission({tool,
84
- input,preview,...diff?{diff}:{},noAlwaysReason,target,persistOptions});if(answer==="no"||typeof answer==="object"&&answer.kind==="instead"){const instead=typeof answer==="object"?answer.text.trim():"";recordDecision("deny","user_declined",instead===""?"\u5229\u7528\u8005\u304C\u62D2\u5426":"\u5229\u7528\u8005\u304C\u62D2\u5426\uFF08\u4EE3\u308F\u308A\u306E\u6307\u793A\u3042\u308A\uFF09");return{content:instead===""?`permission denied: the user declined to run ${tool.name}.`:`permission denied: t\
85
- he user declined to run ${tool.name} and asked you to do this instead:
80
+ - ${validated.errors.join("\n- ")}`;deps.audit.record({event:"result",tool:tool.name,risk:tool.risk,outcome:"error",bytes:Buffer.byteLength(content),mode:deps.mode.id,reasonCode:"invalid_input",callId});return{content,isError:true,summary:`${tool.name} \xB7 \u5165\u529B\u304C\u4E0D\u6B63`}}const input=validated.value;if(tool.name===INDIRECT_TOOL&&deps.prepareIndirect){await deps.prepareIndirect(input).catch(()=>void 0)}let judged={tool};const verdictTarget=()=>judged;const recordDecision=(decision,reasonCode,reason)=>{
81
+ deps.audit.record({event:"decision",tool:verdictTarget().tool.name,risk:verdictTarget().tool.risk,decision,reasonCode,reason,mode:deps.mode.id,rawInput:input,callId})};const verdict=checkToolPermission({tool,input},{mode:deps.mode,cwd:deps.ctx.cwd,sessionAllow:deps.sessionAllow,...deps.sessionRules?{sessionRules:deps.sessionRules}:{},...deps.permissionLayers?{layers:deps.permissionLayers}:{},...deps.permissionMode!==void 0?{permissionMode:deps.permissionMode}:{},...deps.resolveTool?{resolveTool:deps.
82
+ resolveTool}:{}});const policy=verdict.decision;judged=verdict.target;const target=verdict.target;if(policy==="deny"){recordDecision("deny",reasonCodeOf(verdict),verdict.reason);return{content:denyMessage(tool.name,verdict,deps),isError:true,denied:true,summary:`${tool.name} \xB7 deny\uFF08${denySummary(verdict,deps)}\uFF09`}}const preview=safePreview(tool,input);const noAlwaysReason=neverAutoAllowReason(target.tool,target.input)??autoApproveExemptReason(target.tool,target.input,deps.ctx.cwd)??verdict.
83
+ noAlwaysReason??null;const needsAsk=policy==="ask"||noAlwaysReason!==null;if(needsAsk){{if(!deps.askPermission){recordDecision("deny",noAlwaysReason===null?"non_interactive":"guard",noAlwaysReason??"\u975E\u5BFE\u8A71\u30BB\u30C3\u30B7\u30E7\u30F3\u3067\u627F\u8A8D\u304C\u5FC5\u8981\uFF08deny-and-continue\uFF09");return{content:`permission denied: ${tool.name} requires approval, and this session is non-interactive. `+(noAlwaysReason===null?"":`Reason: ${noAlwaysReason} `)+"Explain what you would\
84
+ run instead of running it.",isError:true,denied:true,summary:`${tool.name} \xB7 \u975E\u5BFE\u8A71\u306E\u305F\u3081\u62D2\u5426`}}let diff;try{diff=await tool.prepare?.(input,deps.ctx)??void 0}catch(err){diff=void 0;if(err instanceof PathDeniedError){recordDecision("deny","path_denied","\u4FDD\u8B77\u3055\u308C\u305F\u30D1\u30B9\uFF08paths.ts\uFF09");return{content:err.message,isError:true,denied:true,summary:`${tool.name} \xB7 deny\uFF08\u4FDD\u8B77\u3055\u308C\u305F\u30D1\u30B9\uFF09`}}}const persistOptions=deps.
85
+ persistAllow?persistOptionsFor(target,noAlwaysReason,deps.ctx.cwd):[];const answer=await deps.askPermission({tool,input,preview,...diff?{diff}:{},noAlwaysReason,target,persistOptions});if(answer==="no"||typeof answer==="object"&&answer.kind==="instead"){const instead=typeof answer==="object"?answer.text.trim():"";recordDecision("deny","user_declined",instead===""?"\u5229\u7528\u8005\u304C\u62D2\u5426":"\u5229\u7528\u8005\u304C\u62D2\u5426\uFF08\u4EE3\u308F\u308A\u306E\u6307\u793A\u3042\u308A\uFF09");
86
+ return{content:instead===""?`permission denied: the user declined to run ${tool.name}.`:`permission denied: the user declined to run ${tool.name} and asked you to do this instead:
86
87
  ${instead}`,isError:true,denied:true,summary:instead===""?`${tool.name} \xB7 \u5229\u7528\u8005\u304C\u62D2\u5426`:`${tool.name} \xB7 \u5229\u7528\u8005\u304C\u62D2\u5426\uFF08\u4EE3\u308F\u308A\u306E\u6307\u793A\u3042\u308A\uFF09`}}if(answer==="always"&&noAlwaysReason===null&&target.tool.name!==INDIRECT_TOOL){deps.sessionAllow.add(target.tool.name)}let persisted=false;if(typeof answer==="object"&&answer.kind==="persist"&&noAlwaysReason===null&&persistOptions.some(o=>o.rule===answer.rule)&&deps.
87
88
  persistAllow){persisted=await deps.persistAllow(answer.rule);if(persisted)deps.sessionRules?.push(answer.rule)}const how=answer==="always"?"\u5229\u7528\u8005\u304C\u627F\u8A8D\uFF08\u4ECA\u5F8C\u805E\u304B\u306A\u3044\uFF09":typeof answer==="object"&&answer.kind==="persist"?persisted?`\u5229\u7528\u8005\u304C\u627F\u8A8D\uFF08\u3053\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3067\u306F\u4ECA\u5F8C\u805E\u304B\u306A\u3044: ${answer.rule}\uFF09`:"\u5229\u7528\u8005\u304C\u627F\u8A8D\uFF08\u4ECA\u5F8C\u805E\u304B\u306A\u3044\u306E\u4FDD\u5B58\u306F\u884C\u308F\u306A\u304B\u3063\u305F\uFF09":
88
89
  "\u5229\u7528\u8005\u304C\u627F\u8A8D";recordDecision("allow","user_approved",`${how}\uFF08\u78BA\u8A8D\u306E\u7406\u7531: ${verdict.reason}\uFF09`)}}else{recordDecision("allow",reasonCodeOf(verdict),verdict.reason)}deps.onStart?.(tool,preview);try{const result=await tool.run(input,deps.ctx);deps.audit.record({event:"result",tool:tool.name,risk:tool.risk,outcome:result.isError===true?"error":"ok",bytes:Buffer.byteLength(result.content),mode:deps.mode.id,callId});return{summary:preview,...result}}catch(err){
@@ -141,13 +142,14 @@ while(offset<buf.length){const n=fs4.writeSync(handle,buf,offset,buf.length-offs
141
142
  `}if(Buffer.byteLength(line)>MAX_LINE_BYTES){line=`${JSON.stringify({ts:now(),v:1,session:sessionId,event:payload["event"],tool:clamp(String(payload["tool"]??""),40),_dropped:"line_too_long"})}
142
143
  `}if(written+Buffer.byteLength(line)>MAX_FILE_BYTES){stopped=true;writeAll(fd,`${JSON.stringify({ts:now(),v:1,session:sessionId,event:"truncated"})}
143
144
  `);return}writeAll(fd,line)}catch{stopped=true}};const common={v:1,session:sessionId,permission_mode:ctx.permissionMode??null};let wroteHeader=false;const header=()=>{if(wroteHeader)return;writeLine({ts:now(),...common,event:"session_start",mode:ctx.mode,model:ctx.model,cwd:ctx.cwd,cli_version:ctx.cliVersion,interactive:ctx.interactive,pid:process.pid});if(fd!==null&&!stopped)wroteHeader=true};const reportSaturation=()=>{if(!registry.saturated||reportedSaturation)return;reportedSaturation=true;writeLine(
144
- {ts:now(),...common,event:"registry_saturated"})};return{path:file,sessionId,get opened(){return everOpened},record(event){header();const safe=sanitizeEvent(event,registry);const tool=clamp(safe.tool,MAX_TOOL_NAME_BYTES);const callId=safe.callId===void 0?{}:{call_id:clamp(safe.callId,MAX_CALL_ID_BYTES)};if(safe.event==="decision"){writeLine({ts:now(),...common,event:"decision",tool,...callId,risk:safe.risk,decision:safe.decision,reason_code:safe.reasonCode,reason:safe.reason,mode:safe.mode,input:safe.
145
- input});reportSaturation();return}writeLine({ts:now(),...common,event:"result",tool,...callId,risk:safe.risk,outcome:safe.outcome,bytes:safe.bytes,mode:safe.mode,...safe.reasonCode!==void 0?{reason_code:safe.reasonCode}:{}})},close(){stopped=true;if(fd===null)return;try{fs4.closeSync(fd)}catch{}fd=null}}}function now(){return new Date().toISOString()}function lstatOrNull2(target){try{return fs4.lstatSync(target)}catch{return null}}function clamp(value,maxBytes){const total=Buffer.byteLength(value);
146
- if(total<=maxBytes)return value;let out=value;while(out.length>0&&Buffer.byteLength(out)>maxBytes)out=out.slice(0,-1);return`${out}\u2026(+${total-Buffer.byteLength(out)})`}function sanitizeInput(rawInput,registry){learnSecrets(rawInput,0,registry);return sanitizeObject(rawInput,0,registry)}function learnSecrets(value,depth,registry){if(depth>8||value===null||typeof value!=="object")return;if(Array.isArray(value)){for(const item of value)learnSecrets(item,depth+1,registry);return}for(const[key,child]of Object.
147
- entries(value)){if(REDACT_KEYS.has(key.toLowerCase()))registry.learn(child);else learnSecrets(child,depth+1,registry)}}function sanitizeObject(obj,depth,registry){const out={};let keys=0;for(const[key,value]of Object.entries(obj)){if(keys>=20){out["_twp_more_keys"]=true;break}keys++;if(REDACT_KEYS.has(key.toLowerCase())){out[key]=`<redacted ${byteLengthOf(value)} bytes>`;continue}out[key]=sanitizeValue(value,depth+1,registry)}return out}function sanitizeValue(value,depth,registry){if(value===null||
148
- typeof value==="number"||typeof value==="boolean")return value;if(typeof value==="string"){return clamp(registry.scrub(scrubSecrets(value)),MAX_STRING_BYTES)}if(depth>=3)return"<depth>";if(Array.isArray(value)){const head=value.slice(0,10).map(v=>sanitizeValue(v,depth+1,registry));return value.length>10?[...head,`\u2026(+${value.length-10})`]:head}if(typeof value==="object")return sanitizeObject(value,depth,registry);return`<${typeof value}>`}function byteLengthOf(value){if(typeof value==="strin\
149
- g")return Buffer.byteLength(value);try{return Buffer.byteLength(JSON.stringify(value)??"")}catch{return 0}}function prune(dir,nowMs=Date.now()){let entries;try{entries=fs4.readdirSync(dir).filter(n=>/^session-.*\.jsonl$/.test(n))}catch{return}const stats=[];for(const name of entries){try{stats.push({name,mtime:fs4.statSync(path5.join(dir,name)).mtimeMs})}catch{}}stats.sort((a,b)=>b.mtime-a.mtime);const cutoff=nowMs-MAX_AGE_DAYS*24*60*60*1e3;stats.forEach((entry,index)=>{const overCount=index>=MAX_FILES-
150
- 1;const tooOld=entry.mtime<cutoff;if(!tooOld&&!overCount)return;if(!tooOld&&nowMs-entry.mtime<PRUNE_GRACE_MS)return;try{fs4.unlinkSync(path5.join(dir,entry.name))}catch{}})}var CROCKFORD="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function newSessionId(nowMs=Date.now()){let time="";let remaining=nowMs;for(let i=0;i<10;i++){time=`${CROCKFORD[remaining%32]??"0"}${time}`;remaining=Math.floor(remaining/32)}const bytes=crypto.randomBytes(16);let rand="";for(const byte of bytes)rand+=CROCKFORD[byte%32]??"0";return`${time}${rand}`}import{readFileSync}from"fs";import{dirname as dirname2,join,resolve as resolve2,sep as sep3}from"path";function currentBranch(cwd=process.cwd()){let dir=cwd;for(;;){const gitPath=join(dir,".git");const head=readHead(gitPath);if(head!==null)return head;const parent=dirname2(dir);if(parent===dir)return null;dir=parent}}function readHead(gitPath){let headFile=join(gitPath,"HEAD");try{const stat2=readFileSync(gitPath,"utf8");const m=/^gitdir:\s*(.+)$/m.exec(stat2);if(m?.[1])headFile=join(resolve2(dirname2(
145
+ {ts:now(),...common,event:"registry_saturated"})};return{path:file,sessionId,get opened(){return everOpened},record(event){header();const safe2=sanitizeEvent(event,registry);const tool=clamp(safe2.tool,MAX_TOOL_NAME_BYTES);const callId=safe2.callId===void 0?{}:{call_id:clamp(safe2.callId,MAX_CALL_ID_BYTES)};if(safe2.event==="decision"){writeLine({ts:now(),...common,event:"decision",tool,...callId,risk:safe2.risk,decision:safe2.decision,reason_code:safe2.reasonCode,reason:safe2.reason,mode:safe2.
146
+ mode,input:safe2.input});reportSaturation();return}writeLine({ts:now(),...common,event:"result",tool,...callId,risk:safe2.risk,outcome:safe2.outcome,bytes:safe2.bytes,mode:safe2.mode,...safe2.reasonCode!==void 0?{reason_code:safe2.reasonCode}:{}})},close(){stopped=true;if(fd===null)return;try{fs4.closeSync(fd)}catch{}fd=null}}}function now(){return new Date().toISOString()}function lstatOrNull2(target){try{return fs4.lstatSync(target)}catch{return null}}function clamp(value,maxBytes){const total=Buffer.
147
+ byteLength(value);if(total<=maxBytes)return value;let out=value;while(out.length>0&&Buffer.byteLength(out)>maxBytes)out=out.slice(0,-1);return`${out}\u2026(+${total-Buffer.byteLength(out)})`}function sanitizeInput(rawInput,registry){learnSecrets(rawInput,0,registry);return sanitizeObject(rawInput,0,registry)}function learnSecrets(value,depth,registry){if(depth>8||value===null||typeof value!=="object")return;if(Array.isArray(value)){for(const item of value)learnSecrets(item,depth+1,registry);return}
148
+ for(const[key,child]of Object.entries(value)){if(REDACT_KEYS.has(key.toLowerCase()))registry.learn(child);else learnSecrets(child,depth+1,registry)}}function sanitizeObject(obj,depth,registry){const out={};let keys=0;for(const[key,value]of Object.entries(obj)){if(keys>=20){out["_twp_more_keys"]=true;break}keys++;if(REDACT_KEYS.has(key.toLowerCase())){out[key]=`<redacted ${byteLengthOf(value)} bytes>`;continue}out[key]=sanitizeValue(value,depth+1,registry)}return out}function sanitizeValue(value,depth,registry){
149
+ if(value===null||typeof value==="number"||typeof value==="boolean")return value;if(typeof value==="string"){return clamp(registry.scrub(scrubSecrets(value)),MAX_STRING_BYTES)}if(depth>=3)return"<depth>";if(Array.isArray(value)){const head=value.slice(0,10).map(v=>sanitizeValue(v,depth+1,registry));return value.length>10?[...head,`\u2026(+${value.length-10})`]:head}if(typeof value==="object")return sanitizeObject(value,depth,registry);return`<${typeof value}>`}function byteLengthOf(value){if(typeof value===
150
+ "string")return Buffer.byteLength(value);try{return Buffer.byteLength(JSON.stringify(value)??"")}catch{return 0}}function prune(dir,nowMs=Date.now()){let entries;try{entries=fs4.readdirSync(dir).filter(n=>/^session-.*\.jsonl$/.test(n))}catch{return}const stats=[];for(const name of entries){try{stats.push({name,mtime:fs4.statSync(path5.join(dir,name)).mtimeMs})}catch{}}stats.sort((a,b)=>b.mtime-a.mtime);const cutoff=nowMs-MAX_AGE_DAYS*24*60*60*1e3;stats.forEach((entry,index)=>{const overCount=index>=
151
+ MAX_FILES-1;const tooOld=entry.mtime<cutoff;if(!tooOld&&!overCount)return;if(!tooOld&&nowMs-entry.mtime<PRUNE_GRACE_MS)return;try{fs4.unlinkSync(path5.join(dir,entry.name))}catch{}})}var CROCKFORD="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function newSessionId(nowMs=Date.now()){let time="";let remaining=nowMs;for(let i=0;i<10;i++){time=`${CROCKFORD[remaining%32]??"0"}${time}`;remaining=Math.floor(remaining/32)}const bytes=crypto.randomBytes(16);let rand="";for(const byte of bytes)rand+=CROCKFORD[byte%32]??
152
+ "0";return`${time}${rand}`}import{readFileSync}from"fs";import{dirname as dirname2,join,resolve as resolve2,sep as sep3}from"path";function currentBranch(cwd=process.cwd()){let dir=cwd;for(;;){const gitPath=join(dir,".git");const head=readHead(gitPath);if(head!==null)return head;const parent=dirname2(dir);if(parent===dir)return null;dir=parent}}function readHead(gitPath){let headFile=join(gitPath,"HEAD");try{const stat2=readFileSync(gitPath,"utf8");const m=/^gitdir:\s*(.+)$/m.exec(stat2);if(m?.[1])headFile=join(resolve2(dirname2(
151
153
  gitPath),m[1].trim()),"HEAD")}catch{}try{const head=readFileSync(headFile,"utf8").trim();const ref=/^ref:\s*refs\/heads\/(.+)$/.exec(head);if(ref?.[1])return ref[1];return head.slice(0,7)}catch{return null}}function displayCwd(cwd=process.cwd(),home=process.env["HOME"]??process.env["USERPROFILE"]??""){if(!home)return cwd;const stripped=home.replace(new RegExp(`${escapeSep()}+$`),"");if(stripped==="")return cwd;const normalize=p=>process.platform==="win32"?p.toLowerCase():p;const h=normalize(stripped);
152
154
  const c=normalize(cwd);if(c===h)return"~";if(c.startsWith(h+sep3))return`~${cwd.slice(stripped.length)}`;return cwd}function escapeSep(){return sep3==="\\"?"\\\\":sep3}import{spawn}from"child_process";function keepTailBytes(buf,maxBytes){if(buf.length<=maxBytes)return{text:buf.toString("utf8"),droppedBytes:0};const start=buf.length-maxBytes;let cut=start;while(cut<buf.length&&(buf[cut]&192)===128)cut++;return{text:buf.subarray(cut).toString("utf8"),droppedBytes:cut}}function keepHeadBytes(text,maxBytes){const buf=Buffer.from(text,"utf8");if(buf.length<=maxBytes)return{text,truncated:false};let cut=maxBytes;while(cut>0&&(buf[cut]&192)===128)cut--;return{text:buf.subarray(0,cut).toString("utf8"),
153
155
  truncated:true}}import{existsSync}from"fs";import path6 from"path";var GIT_BASH_CANDIDATES=["C:\\Program Files\\Git\\bin\\bash.exe","C:\\Program Files (x86)\\Git\\bin\\bash.exe","C:\\Program Files\\Git\\usr\\bin\\bash.exe"];function system32Path(env,...rest){return system32(env,...rest)??path6.win32.join("C:\\Windows\\System32",...rest)}function defaultProbe(filePath){try{return existsSync(filePath)}catch{return false}}function selectShell(platform=process.platform,probe=defaultProbe,env=process.env){if(platform!=="win32"){return{toolName:"bash",command:"/bin/b\
@@ -200,6 +202,31 @@ limit"]:DEFAULT_LIMIT_LINES;const slice=lines.slice(offset-1,offset-1+limit);let
200
202
 
201
203
  [truncated: file has ${lines.length} lines; re-read with offset/limit for the rest]`:"";if(body===""){const reason=lines.length===0?"(empty file)":`(no lines at offset ${offset}; the file has ${lines.length} lines)`;return{content:reason,summary:`read_file \xB7 ${toolRelative(ctx.cwd,abs)} (0 \u884C)`}}return{content:body+note,summary:`read_file \xB7 ${toolRelative(ctx.cwd,abs)} (${slice.length} \u884C${eol==="\r\n"?" \xB7 CRLF":""})`}}};import{mkdir,readFile as readFile4,writeFile as writeFile2}from"fs/promises";import{dirname as dirname3}from"path";var writeFileTool={name:"write_file",domain:"local",risk:"write",description:"Write the full content of a file, creating it (and parent directories) if needed. Overwrites the whole file \u2014 prefer edit_file for partial changes. The existing line ending style (LF/CRLF) is preserved.",inputSchema:{type:"object",additionalProperties:false,properties:{path:{type:"string",description:"File path, relative to the working directory"},content:{type:"string",description:"Full new content. Use \\n for li\
202
204
  ne breaks."}},required:["path","content"]},preview(input){const content=typeof input["content"]==="string"?input["content"]:"";return`write_file \xB7 ${String(input["path"]??"")} (${content.split("\n").length} \u884C)`},async prepare(input,ctx){const abs=resolveToolPath(String(input["path"]),ctx.cwd);const before=await readFile4(abs,"utf8").catch(()=>"");return{path:toolRelative(ctx.cwd,abs),before,after:String(input["content"]??"")}},async run(input,ctx){const abs=resolveToolPath(String(input["\
203
- path"]),ctx.cwd);const existing=await readFile4(abs,"utf8").catch(()=>null);const eol=existing===null?"\n":detectEol(existing);const body=applyEol(String(input["content"]),eol);await mkdir(dirname3(abs),{recursive:true});await writeFile2(abs,body,"utf8");const rel=toolRelative(ctx.cwd,abs);return{content:`Wrote ${rel} (${body.split(eol).length} lines${eol==="\r\n"?", CRLF preserved":""}).`,summary:`write_file \xB7 ${rel}`,diff:{path:rel,before:existing??"",after:String(input["content"])}}}};var RESIDENT_TOKEN_CAP=8e3;function localTools(choice=selectShell()){return[readFileTool,writeFileTool,editFileTool,createBashTool(choice),globTool,grepTool,gitTool]}function buildResidentSet(mode,opts={}){const all=opts.tools??localTools();const cap=opts.cap??RESIDENT_TOKEN_CAP;const eligible=all.filter(tool=>matchesAnyGlob(tool.name,mode.tools)&&applyPermissionMode(checkPermission(tool.name,mode),tool.risk,opts.permissionMode).decision!=="deny"&&!isWholeToolDenied(tool.name,opts.permissionLayers??[]));const tools=[];const dropped=[];
204
- let tokens=0;for(const tool of eligible){const cost=estimateToolTokens(tool);if(tokens+cost>cap){dropped.push(tool.name);continue}tools.push(tool);tokens+=cost}return{tools,wire:tools.map(toWireTool),tokens,dropped}}function estimateToolTokens(tool){return Math.ceil(JSON.stringify(toWireTool(tool)).length/4)}function matchesAnyGlob(name,patterns){return patterns.some(pattern=>globToRegExp(pattern).test(name))}function globToRegExp(pattern){const escaped=pattern.replace(/[.+?^${}()|[\]\\]/g,"\\$&").
205
- replace(/\*/g,".*");return new RegExp(`^${escaped}$`)}export{secretReason,parseRule,projectPermissionsPath,projectRootFor,persistProjectAllow,activatePermissionSettings,executeTool,buildSystemPrompt,runTurn,parseFrontMatter,lstatOrNull,findProjectTwpSubdir,activateModeFiles,describeAuditLog,createAuditLogger,currentBranch,displayCwd,resolveGitExecutable,readFileTool,RESIDENT_TOKEN_CAP,localTools,buildResidentSet};
205
+ path"]),ctx.cwd);const existing=await readFile4(abs,"utf8").catch(()=>null);const eol=existing===null?"\n":detectEol(existing);const body=applyEol(String(input["content"]),eol);await mkdir(dirname3(abs),{recursive:true});await writeFile2(abs,body,"utf8");const rel=toolRelative(ctx.cwd,abs);return{content:`Wrote ${rel} (${body.split(eol).length} lines${eol==="\r\n"?", CRLF preserved":""}).`,summary:`write_file \xB7 ${rel}`,diff:{path:rel,before:existing??"",after:String(input["content"])}}}};var RESIDENT_TOKEN_CAP=8e3;function localTools(choice=selectShell()){return[readFileTool,writeFileTool,editFileTool,createBashTool(choice),globTool,grepTool,gitTool]}function buildResidentSet(mode,opts={}){const all=opts.tools??localTools();const cap=opts.cap??RESIDENT_TOKEN_CAP;const eligible=all.filter(tool=>matchesAnyGlob(tool.name,mode.tools)&&applyPermissionMode(checkPermission(tool.name,mode),tool.risk,opts.permissionMode).decision!=="deny"&&!isWholeToolDenied(tool.name,opts.permissionLayers??[]));const usage=opts.usage;
206
+ const pinned=opts.pinned;const ordered=usage===void 0&&pinned===void 0?eligible:eligible.map((tool,i)=>({tool,i,pin:pinned?.has(tool.name)===true,uses:usage?.get(tool.name)??0})).sort((a,b)=>Number(b.pin)-Number(a.pin)||b.uses-a.uses||a.i-b.i).map(entry=>entry.tool);const tools=[];const dropped=[];let tokens=0;for(const tool of ordered){const cost=estimateToolTokens(tool);if(tokens+cost>cap){dropped.push(tool.name);continue}tools.push(tool);tokens+=cost}return{tools,wire:tools.map(toWireTool),tokens,
207
+ dropped}}function estimateToolTokens(tool){return Math.ceil(JSON.stringify(toWireTool(tool)).length/4)}function matchesAnyGlob(name,patterns){return patterns.some(pattern=>globToRegExp(pattern).test(name))}function globToRegExp(pattern){const escaped=pattern.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp(`^${escaped}$`)}var CATALOG_TOOL_PREFIX="twp_";var WIRE_NAME_RE=/^[A-Za-z0-9_-]{1,64}$/;var MAX_RESULT_CHARS=4e4;function catalogToolName(op){if(op.name.includes("_")||op.domain.includes("_"))return null;const name=`${CATALOG_TOOL_PREFIX}${op.name.replace(/\./g,"-")}_${op.domain}`;return WIRE_NAME_RE.test(name)?name:null}function parseCatalogToolName(name){if(!name.startsWith(CATALOG_TOOL_PREFIX))return null;const rest=name.slice(CATALOG_TOOL_PREFIX.length);const sep4=rest.indexOf("_");if(sep4<=0||sep4===rest.length-
208
+ 1)return null;const domain=rest.slice(sep4+1);return/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(domain)?{domain}:null}function toolRiskOf(risk){switch(risk){case"read":return"read";case"write":return"write";default:return"exec"}}var SIMPLE_TYPES=new Set(["string","integer","number","boolean","array","object"]);function paramSchema(param){const declared=param.type;const schema={};if(typeof declared==="string"&&SIMPLE_TYPES.has(declared)&&declared!=="integer"&&declared!=="number"){schema.type=declared}if(param.
209
+ description!==void 0&&param.description!=="")schema.description=param.description;return schema}function inputSchemaOf(op){const properties={};const required=[];for(const param of op.pathParams){properties[param.name]={description:param.description||`path parameter ${param.name}`};required.push(param.name)}for(const param of op.queryParams){if(Object.hasOwn(properties,param.name))continue;properties[param.name]=paramSchema(param);if(param.required)required.push(param.name)}if(op.body!==null&&op.
210
+ method!=="GET"){properties["body"]={type:"object",description:"JSON request body (see twp_describe_tools for its schema)"}}return{type:"object",properties,...required.length>0?{required}:{},additionalProperties:false}}function catalogTool(op,deps){const name=catalogToolName(op);if(name===null)return null;const summary=op.summary!==""?op.summary:`${op.method} ${op.path}`;const risk=toolRiskOf(op.risk);return{name,domain:op.domain,risk,description:`${summary} (${op.method} ${op.path})`,inputSchema:inputSchemaOf(
211
+ op),preview:input=>previewOf(op,input),run:async input=>runOperation(op,name,input,deps)}}function previewOf(op,input){let path8=op.path;for(const param of op.pathParams){const value=input[param.name];path8=path8.split(`{${param.name}}`).join(typeof value==="string"||typeof value==="number"?String(value):`{${param.name}}`)}return`${op.method} ${path8}`}function buildRequest(op,input){const errors=[];let path8=op.path;const pathNames=new Set;for(const param of op.pathParams){pathNames.add(param.name);
212
+ const raw=input[param.name];const value=typeof raw==="number"?String(raw):raw;if(!isSafePathSegment(value)){errors.push(`${param.name}: \u30D1\u30B9\u8981\u7D20\u3068\u3057\u3066\u4F7F\u3048\u306A\u3044\u5024\u3067\u3059`);continue}path8=path8.split(`{${param.name}}`).join(value)}const query={};for(const[key,value]of Object.entries(input)){if(pathNames.has(key)||key==="body")continue;query[key]=value}const body=input["body"];errors.push(...validateQuery(op.queryParams,query));if(op.body!==null&&
213
+ op.method!=="GET")errors.push(...validateBody(op.body.schema,body??{}));if(errors.length>0)return{ok:false,errors};return{ok:true,path:path8.toLowerCase().startsWith("/api/")?path8:`/api${path8}`,query,body}}async function runOperation(op,name,input,deps){const built=buildRequest(op,input);if(!built.ok){const shown=built.errors.slice(0,MAX_REPORTED_VIOLATIONS);return{content:`Invalid input for ${name}:
214
+ - ${shown.join("\n- ")}`,isError:true,summary:`${name} \xB7 \u5165\u529B\u304C\u4E0D\u6B63`}}let response;try{response=await deps.client().request(op.method,appendQuery(built.path,built.query),built.body)}catch(err){if(err instanceof ApiError){return{content:`${name} failed: ${err.message}`,isError:true,summary:`${name} \xB7 HTTP ${err.status}`}}throw err}return{content:truncate(redactSecrets(JSON.stringify(redactSecretValues(response??null),null,1))),summary:previewOf(op,input)}}function truncate(text,limit=MAX_RESULT_CHARS){
215
+ if(text.length<=limit)return text;return`${text.slice(0,limit)}
216
+ \u2026(truncated: ${text.length-limit} more characters. Narrow the request with query parameters such as limit / keyword.)`}var SEARCH_LIMIT=20;var DESCRIBE_LIMIT=10;var MOUNT_LIMIT=12;var bundledSource={index:loadCommandModelIndex,domain:loadCommandModelDomain};var TwpToolkit=class{source;client;tools=new Map;operations=new Map;loadedDomains=new Set;mountedNames=[];usage=new Map;meta;constructor(opts){this.source=opts.source??bundledSource;this.client=opts.client;this.meta=[this.domainsTool(),this.searchTool(),this.describeTool(),this.callTool(),this.mountTool()]}metaTools(){return[...this.meta]}mountedTools(){return this.
217
+ mountedNames.flatMap(name=>{const tool=this.tools.get(name);return tool?[tool]:[]})}resolveTool=name=>this.tools.get(name);prepareIndirect=async input=>{const name=input["name"]??input["tool"];if(typeof name!=="string")return;await this.ensureLoaded(name).catch(()=>void 0)};recordUse(name){this.usage.set(name,(this.usage.get(name)??0)+1)}async ensureLoaded(name){const parsed=parseCatalogToolName(name);if(parsed===null)return void 0;await this.loadDomain(parsed.domain);return this.tools.get(name)}async loadDomain(domain){
218
+ const file=await this.source.domain(domain);if(!this.loadedDomains.has(domain)){for(const op of file.operations){const tool=catalogTool(op,{client:this.client});if(tool===null||this.tools.has(tool.name))continue;const run=tool.run;this.tools.set(tool.name,{...tool,run:async(input,ctx)=>{this.recordUse(tool.name);return run(input,ctx)}});this.operations.set(tool.name,op)}this.loadedDomains.add(domain)}return file.operations}async loadAll(){const index=await this.source.index();await Promise.all(index.
219
+ domains.map(d=>this.loadDomain(d.domain).catch(()=>[])))}domainsTool(){return{name:"twp_domains",domain:"meta",risk:"read",description:"List TWP API domains (tasks, projects, attendance, sales, ...) with operation counts. Use twp_search_tools to find a specific operation.",inputSchema:{type:"object",properties:{},additionalProperties:false},preview:()=>"twp_domains",run:async()=>guarded(async()=>{const index=await this.source.index();const lines=index.domains.map(d=>`${d.domain} (${d.operationCount}\
220
+ )${d.summary!==""?`: ${d.summary}`:""}`);return{content:`${index.totals.domains} domains / ${index.totals.operations} operations
221
+ ${lines.join("\n")}`}})}}searchTool(){return{name:"twp_search_tools",domain:"meta",risk:"read",description:"Search the TWP API tool catalog. Returns tool names with a one-line summary only (no schema). Query words match tool name, domain, path and summary (Japanese summaries are common, so Japanese keywords work). Then call twp_describe_tools for the schema and twp_call to run it.",inputSchema:{type:"object",properties:{query:{type:"string",description:"Space separated keywords"},domain:{type:"s\
222
+ tring",description:"Limit the search to one domain (see twp_domains)"}},required:["query"],additionalProperties:false},preview:input=>`twp_search_tools ${String(input["query"]??"")}`,run:async input=>guarded(async()=>{const domain=typeof input["domain"]==="string"&&input["domain"]!==""?input["domain"]:null;if(domain!==null)await this.loadDomain(domain);else await this.loadAll();const all=searchCatalog([...this.operations.entries()],String(input["query"]??""),domain,Number.POSITIVE_INFINITY);if(all.
223
+ length===0)return{content:"No matching tools. Try other keywords or twp_domains."};const hits=all.slice(0,SEARCH_LIMIT);const lines=hits.map(({name,op})=>`${name} [${op.risk}] ${op.summary||`${op.method} ${op.path}`}`);if(all.length>hits.length)lines.push(`(${all.length-hits.length} more matches; narrow the query or pass domain)`);return{content:lines.join("\n")}})}}describeTool(){return{name:"twp_describe_tools",domain:"meta",risk:"read",description:`Return the full JSON Schema of the named TWP\
224
+ tools (max ${DESCRIBE_LIMIT}). Names come from twp_search_tools.`,inputSchema:{type:"object",properties:{names:{type:"array",items:{type:"string"}}},required:["names"],additionalProperties:false},preview:input=>`twp_describe_tools ${Array.isArray(input["names"])?input["names"].join(", "):""}`,run:async input=>guarded(async()=>{const requested=input["names"].filter(n=>typeof n==="string");const names=requested.slice(0,DESCRIBE_LIMIT);const out=[];for(const name of names){const tool=await this.ensureLoaded(
225
+ name).catch(()=>void 0);const op=this.operations.get(name);if(!tool||!op){out.push({name,error:"unknown tool"});continue}out.push({name,risk:op.risk,method:op.method,path:op.path,description:tool.description,input_schema:tool.inputSchema,...op.body!==null&&op.method!=="GET"?{body_schema:op.body.schema}:{},...op.resultPath!==null?{result_path:op.resultPath}:{}})}const rest=requested.length-names.length;const note=rest>0?`
226
+ (${rest} more names were not described; call again with them)`:"";return{content:truncate(JSON.stringify(out,null,1))+note}})}}callTool(){return{name:INDIRECT_TOOL,domain:"meta",risk:"read",description:"Run a TWP catalog tool by name. input is validated against the tool schema at call time. Permission is checked against the real tool name, not twp_call.",inputSchema:{type:"object",properties:{name:{type:"string",description:"Tool name from twp_search_tools (e.g. twp_list_project-task)"},input:{type:"\
227
+ object",description:"Arguments for the tool (see twp_describe_tools)"}},required:["name"],additionalProperties:false},preview:input=>{const tool=typeof input["name"]==="string"?this.tools.get(input["name"]):void 0;const inner=input["input"]??{};return tool?`${INDIRECT_TOOL} \u2192 ${safe(()=>tool.preview(inner),tool.name)}`:`${INDIRECT_TOOL} ${String(input["name"]??"")}`},run:async(input,ctx)=>guarded(async()=>{const name=String(input["name"]);const tool=this.tools.get(name)??await this.ensureLoaded(
228
+ name);if(!tool)return{content:`Unknown tool: ${name}. Use twp_search_tools.`,isError:true};const validated=validateInput(tool.inputSchema,input["input"]??{});if(!validated.ok){return{content:`Invalid input for ${name}:
229
+ - ${validated.errors.join("\n- ")}`,isError:true,summary:`${name} \xB7 \u5165\u529B\u304C\u4E0D\u6B63`}}return tool.run(validated.value,ctx)})}}mountTool(){return{name:"twp_mount",domain:"meta",risk:"read",description:`Add up to ${MOUNT_LIMIT} main tools of a TWP domain to your tool list from the next turn on (sticky for this session). Use it when you will call the same domain repeatedly; otherwise twp_call is enough.`,inputSchema:{type:"object",properties:{domain:{type:"string"}},required:["dom\
230
+ ain"],additionalProperties:false},preview:input=>`twp_mount ${String(input["domain"]??"")}`,run:async input=>guarded(async()=>{const domain=String(input["domain"]);const ops=await this.loadDomain(domain);const picked=pickMainOperations(ops).map(op=>catalogToolName(op)).filter(name=>name!==null&&this.tools.has(name));for(const name of picked)if(!this.mountedNames.includes(name))this.mountedNames.push(name);return{content:`Mounted from the next turn: ${picked.join(", ")||"(none)"}`}})}}};function pickMainOperations(ops){
231
+ const order={read:0,write:1,destructive:2};return[...ops].sort((a,b)=>order[a.risk]-order[b.risk]).slice(0,MOUNT_LIMIT)}function searchCatalog(entries,query,domain,limit=SEARCH_LIMIT){const words=query.toLowerCase().split(/\s+/).filter(w=>w!=="");if(words.length===0)return[];const hits=[];for(const[name,op]of entries){if(domain!==null&&op.domain!==domain)continue;const haystack=`${name} ${op.domain} ${op.path} ${op.summary} ${op.aliases.join(" ")}`.toLowerCase();let score=0;for(const word of words)
232
+ if(haystack.includes(word))score+=op.summary.toLowerCase().includes(word)?2:1;if(score>0)hits.push({name,op,score})}return hits.sort((a,b)=>b.score-a.score||a.name.localeCompare(b.name)).slice(0,limit)}async function guarded(fn){try{return await fn()}catch(err){if(err instanceof CommandModelMissingError)return{content:err.message,isError:true};throw err}}function safe(fn,fallback){try{return fn()}catch{return fallback}}function createTwpToolkit(runtime,cliVersion){let client=null;return new TwpToolkit({client:()=>{client??=new TwpApiClient(runtime.apiUrl,runtime.session??new AuthSession(runtime.profileName,runtime.apiUrl),httpFetch,cliVersion);return client}})}function residentInputs(toolkit,local=localTools()){const meta=toolkit.metaTools();return{tools:[...local,...meta,...toolkit.mountedTools()],usage:toolkit.usage,pinned:new Set([...local,...meta].map(t=>t.name))}}export{secretReason,parseRule,projectPermissionsPath,projectRootFor,persistProjectAllow,activatePermissionSettings,executeTool,buildSystemPrompt,runTurn,parseFrontMatter,lstatOrNull,findProjectTwpSubdir,activateModeFiles,describeAuditLog,createAuditLogger,currentBranch,displayCwd,resolveGitExecutable,readFileTool,RESIDENT_TOKEN_CAP,localTools,buildResidentSet,createTwpToolkit,residentInputs};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __twpCreateRequire } from 'node:module';
2
+ const require = __twpCreateRequire(import.meta.url);
3
+ import{redactSecretValues,redactSecrets}from"./chunk-YVAN3H5W.js";import{formatOutput}from"./chunk-K2ONOH3L.js";function renderOutput(value,format,noRedact=false){if(noRedact)return formatOutput(value,format);return redactSecrets(formatOutput(redactSecretValues(value),format))}export{renderOutput};
@@ -0,0 +1,62 @@
1
+ import { createRequire as __twpCreateRequire } from 'node:module';
2
+ const require = __twpCreateRequire(import.meta.url);
3
+ import{parseOperationArgs}from"./chunk-IOGVQVGD.js";import{renderOutput}from"./chunk-5Q2CH4E7.js";import{redactSecretValues,redactSecrets,withDebug}from"./chunk-YVAN3H5W.js";import{Resolver,requireDefaultProject}from"./chunk-QOUFHYK5.js";import{ApiError,TwpApiClient,appendQuery}from"./chunk-FTYJZFEK.js";import{DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,nextPageNotes,positiveInteger,shellQuote}from"./chunk-DMDVLOAY.js";import{ResolveError}from"./chunk-GMBJTG6A.js";
4
+ import{GLOBAL_OPTIONS_HELP}from"./chunk-TAN5I2DP.js";import{HELP_TOKEN}from"./chunk-EJ474UDB.js";import{AuthSession,NotLoggedInError,SessionExpiredError,loadCredentials}from"./chunk-XNLIEUAW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{effectiveApiUrl,loadUserConfig,resolveConfiguredOutput,resolveProfile}from"./chunk-NERYSBA4.js";import{OUTPUT_FORMATS,resolveOutputFormat}from"./chunk-K2ONOH3L.js";import{stringWidth}from"./chunk-WVS4W5FY.js";import{
5
+ stripTerminalControls}from"./chunk-NHYMHCAT.js";import{evaluateQuery}from"./chunk-GDM2QUBL.js";import{ApiRejectedError,ApiResponseError,EXIT_API_CLIENT,EXIT_API_SERVER,EXIT_AUTH,EXIT_FAILURE,EXIT_OK,EXIT_USAGE,NetworkError,UsageError}from"./chunk-7WSNIXTQ.js";import fs from"fs";import path from"path";var NO_REDACT_FLAG={name:"--no-redact",summary:"\u5FDC\u7B54\u306E\u4F0F\u5B57\u5316\u3092\u89E3\u9664\u3057\u3066\u751F\u306E\u5024\u3092\u51FA\u3059\uFF08\u9375\u306E\u53D7\u3051\u53D6\u308A\u7B49\uFF09",takesValue:false};var NO_REDACT_NOTICE="\u6CE8\u8A18: --no-redact \u306E\u305F\u3081\u51FA\u529B\u3092\u4F0F\u5B57\u5316\u3057\u307E\u305B\u3093\uFF08\u7AEF\u672B\u3068\u30ED\u30B0\u306B\u5E73\u6587\u3067\u6B8B\u308A\u307E\u3059\uFF09\u3002";function withCommonFlags(flags){return flags.some(flag=>flag.
6
+ 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?"":`
7
+ \u64CD\u4F5C:
8
+ ${alignedList(resource.operations.map(op=>[op.name,op.summary]))}
9
+ `;const subSection=subresources.length===0?"":`
10
+ \u30B5\u30D6\u8CC7\u6E90:
11
+ ${alignedList(subresources.map(sub=>[`${sub.name} <\u64CD\u4F5C>`,sub.summary]))}
12
+ `;return`twp ${path2} \u2014 ${resource.summary}
13
+
14
+ \u4F7F\u3044\u65B9:
15
+ twp ${path2} <\u64CD\u4F5C> [\u5F15\u6570] [\u30AA\u30D7\u30B7\u30E7\u30F3]
16
+ twp ${path2} <\u64CD\u4F5C> ${HELP_TOKEN} \u305D\u306E\u64CD\u4F5C\u306E\u8A73\u3057\u3044\u30D8\u30EB\u30D7
17
+ ${operationSection}${subSection}
18
+ ${GLOBAL_OPTIONS_HELP}
19
+ `}function renderOperationHelp(op,path2){const sections=[`twp ${path2} ${op.name} \u2014 ${op.summary}`,"","\u4F7F\u3044\u65B9:",` ${op.usage}`];if(op.description!==void 0){sections.push("",...op.description.split("\n"))}if(op.destructive===true){sections.push("","\u26A0 \u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u304C\u5FC5\u8981\u3067\u3059\u3002")}const flags=withCommonFlags(op.flags);if(flags.length>0){sections.push("","\u30AA\u30D7\u30B7\u30E7\u30F3:",
20
+ alignedList(flags.map(flag=>[flag.takesValue?`${flag.name} ${flag.placeholder??"<\u5024>"}`:flag.name,flag.summary])))}sections.push("",GLOBAL_OPTIONS_HELP,"");return sections.join("\n")}function renderUnknownOperation(resource,path2,attempted){const names=[...resource.operations.map(op=>op.name),...subresourcesOf(resource).map(sub=>`${sub.name} <\u64CD\u4F5C>`)].join(" / ");return attempted===void 0?`twp ${path2} \u306B\u306F\u64CD\u4F5C\u306E\u6307\u5B9A\u304C\u5FC5\u8981\u3067\u3059\uFF08${names}\
21
+ \uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`:`twp ${path2} \u306B\u300C${attempted}\u300D\u3068\u3044\u3046\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${names}\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`}var LOADERS={backlog:async()=>(await import("./backlog-7MJIOT22.js")).backlogDomain,department:async()=>(await import("./department-JOXXJKQB.js")).departmentDomain,"job-title":async()=>(await import("./job-title-L47J6TZY.js")).jobTitleDomain,media:async()=>(await import("./media-ZMDYHHNN.js")).mediaDomain,position:async()=>(await import("./position-FHWCMMBQ.js")).positionDomain,project:async()=>(await import("./project-ZODASYER.js")).projectDomain,storage:async()=>(await import("./storage-ANKKJJJO.js")).
22
+ storageDomain,task:async()=>(await import("./task-G5YWQ6L5.js")).taskDomain,user:async()=>(await import("./user-DO4VNIBR.js")).userDomain};async function loadDomain(name){return LOADERS[name]()}var writeOut=text=>void process.stdout.write(text);var writeErr=text=>void process.stderr.write(text);function line(text){return text===""?"":text.endsWith("\n")?text:`${text}
23
+ `}function outputValue(operation,format,body){return format==="json"?operation.raw(body):operation.summarize(body)}function requiresYes(operation,yes){return operation.destructive===true&&!yes}function exitCodeForStatus(status){if(status===401)return EXIT_AUTH;if(status===429)return EXIT_API_SERVER;if(status>=400&&status<500)return EXIT_API_CLIENT;return EXIT_API_SERVER}function exitCodeFor(err){if(err instanceof UsageError)return EXIT_USAGE;if(err instanceof NotLoggedInError||err instanceof SessionExpiredError)
24
+ return EXIT_AUTH;if(err instanceof ApiError)return exitCodeForStatus(err.status);if(err instanceof ApiRejectedError)return EXIT_API_CLIENT;if(err instanceof ApiResponseError||err instanceof NetworkError)return EXIT_API_SERVER;if(err instanceof ResolveError){return err.status===null?EXIT_API_SERVER:exitCodeForStatus(err.status)}return EXIT_FAILURE}function safeText(text){return redactSecrets(stripTerminalControls(text))}function reportError(err,format,code,write=writeErr){const message=safeText(err instanceof
25
+ Error?err.message:String(err));const rawHint=err instanceof 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)}
26
+ `);return}write(`${message}
27
+ `);if(hint!==void 0)write(`${hint}
28
+ `)}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.
29
+ 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.
30
+ status}\uFF09`)}}async function getSigned(fetchImpl,url){let res;try{res=await fetchImpl(url,{method:"GET"})}catch(err){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u304B\u3089\u306E\u30C0\u30A6\u30F3\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\u304B\u3089\u306E\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u304C\u62D2\u5426\u3055\u308C\u307E\u3057\u305F\uFF08HTTP ${res.status}\uFF09`)}
31
+ return{bytes:new Uint8Array(await res.arrayBuffer()),contentType:res.headers.get("content-type")}}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`)}
32
+ return{out:path.resolve(raw.trim()),force:input.flags.has(spec.forceFlag)}}function assertWritableTarget(target,forceFlag){if(!target.force&&fs.existsSync(target.out)){throw new UsageError(`\u66F8\u304D\u51FA\u3057\u5148\u304C\u65E2\u306B\u3042\u308A\u307E\u3059: ${target.out}`,`\u4E0A\u66F8\u304D\u3059\u308B\u306A\u3089 ${forceFlag} \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\uFF08\u65E2\u5B9A\u3067\u306F\u4E0A\u66F8\u304D\u3057\u307E\u305B\u3093\uFF09\u3002`)}const dir=path.dirname(target.
33
+ out);if(!fs.existsSync(dir)){throw new UsageError(`\u66F8\u304D\u51FA\u3057\u5148\u306E\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u3042\u308A\u307E\u305B\u3093: ${dir}`,"\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3092\u4F5C\u3063\u3066\u304B\u3089\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u81EA\u52D5\u3067\u306F\u4F5C\u6210\u3057\u307E\u305B\u3093\uFF09\u3002")}}async function download(args){let received;if(args.signed!==void 0){const url=args.signed.signedUrl(await send(args.client,args.
34
+ apiUrl,args.plan),args.plan);received=await getSigned(args.signed.fetchImpl,url)}else{try{received=await args.client.requestBinary(args.plan.method,appendQuery(args.plan.path,args.plan.query))}catch(err){if(err instanceof ApiError||err instanceof NotLoggedInError||err instanceof SessionExpiredError)throw err;throw new NetworkError(`${args.apiUrl} \u3078\u306E\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.message}`,{cause:err})}}try{fs.writeFileSync(args.target.out,received.bytes,{
35
+ 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\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.
36
+ 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"};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}\
37
+ \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)} \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=[];
38
+ 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,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.
39
+ 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
40
+ `)}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}\
41
+ \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")??
42
+ 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{
43
+ 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")}
44
+ 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;let forbidden;let rejected;try{const profile=resolveProfile(globals.profile);format=resolveOutputFormat({...globals.
45
+ output!==void 0?{flag:globals.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===
46
+ HELP_TOKEN||options.help&&options.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);
47
+ const resource=sub??domain;const path2=sub===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,
48
+ path2,operationName))}forbidden=operation.forbidden;rejected=operation.rejected;if(options.help||rest[0]===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`)}
49
+ const paging=resolvePaging(operation,path2,input);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,
50
+ 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,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}\
51
+ ${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&&(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`)}
52
+ for(const note of operation.plannedNotes?.(prepared)??[])errOut(`${safeText(note)}
53
+ `);if(noRedact)errOut(`${NO_REDACT_NOTICE}
54
+ `);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)}
55
+ `)};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);const signedUrl=operation.download.signedUrl;body=await download({client,apiUrl,plan,target:downloadTarget,...signedUrl===void 0?{}:{signed:{fetchImpl,signedUrl}}})}else if(paging.all&&operation.paging!==void 0){paged=await fetchAllPages(
56
+ {client,apiUrl,plan,paging:operation.paging,maxPages:paging.maxPages,maxItems:paging.maxItems,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}\
57
+ \u4EF6\u3092\u53D6\u5F97\u3057\u307E\u3057\u305F\u3002
58
+ `)}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)}
59
+ `)}return EXIT_OK}catch(caught){const err=withRejectedGuidance(withForbiddenGuidance(caught,forbidden),rejected);const code=exitCodeFor(err);reportError(err,format,code,errOut);return code}}function withForbiddenGuidance(err,guidance){if(guidance===void 0||!(err instanceof ApiError)||err.status!==403)return err;const server=err.body?.error_description??err.body?.message;const wrapped=new ApiError(err.status,err.body,"","");wrapped.message=server!==void 0&&server!==""?`${guidance}\uFF08\u30B5\u30FC\u30D0\u306E\u5FDC\u7B54: ${server}\
60
+ \uFF09`:guidance;return wrapped}function withRejectedGuidance(err,guidance){if(guidance===void 0||!(err instanceof ApiError)||err.status!==422)return err;const description=err.body?.error_description;const fallback=err.body?.message;const server=(typeof description==="string"&&description!==""?description:void 0)??(typeof fallback==="string"?fallback:"");const extra=guidance(server);if(extra===void 0)return err;const wrapped=new ApiError(err.status,err.body,"","");wrapped.message=server!==""?`${server}\
61
+
62
+ ${extra}`:extra;return wrapped}export{NO_REDACT_FLAG,NO_REDACT_NOTICE,outputValue,requiresYes,exitCodeFor,reportError,CURATED_PAGING_VOCABULARY,fetchAllPages,resolvePaging,buildPrepareContext,runDomain};
@@ -1,3 +1,4 @@
1
1
  import { createRequire as __twpCreateRequire } from 'node:module';
2
2
  const require = __twpCreateRequire(import.meta.url);
3
- var EXIT_OK=0;var EXIT_FAILURE=1;var EXIT_USAGE=2;var EXIT_API_CLIENT=3;var EXIT_API_SERVER=4;var EXIT_AUTH=5;var UsageError=class extends Error{constructor(message,hint){super(message);this.hint=hint;this.name="UsageError"}hint};var ApiResponseError=class extends Error{constructor(message){super(message);this.name="ApiResponseError"}};var NetworkError=class extends Error{constructor(message,options){super(message,options);this.name="NetworkError"}};export{EXIT_OK,EXIT_FAILURE,EXIT_USAGE,EXIT_API_CLIENT,EXIT_API_SERVER,EXIT_AUTH,UsageError,ApiResponseError,NetworkError};
3
+ var EXIT_OK=0;var EXIT_FAILURE=1;var EXIT_USAGE=2;var EXIT_API_CLIENT=3;var EXIT_API_SERVER=4;var EXIT_AUTH=5;var UsageError=class extends Error{constructor(message,hint){super(message);this.hint=hint;this.name="UsageError"}hint};var ApiResponseError=class extends Error{constructor(message){super(message);this.name="ApiResponseError"}};var ApiRejectedError=class extends Error{constructor(message){super(message);this.name="ApiRejectedError"}};var NetworkError=class extends Error{constructor(message,options){
4
+ super(message,options);this.name="NetworkError"}};export{EXIT_OK,EXIT_FAILURE,EXIT_USAGE,EXIT_API_CLIENT,EXIT_API_SERVER,EXIT_AUTH,UsageError,ApiResponseError,ApiRejectedError,NetworkError};
@@ -0,0 +1,11 @@
1
+ import { createRequire as __twpCreateRequire } from 'node:module';
2
+ const require = __twpCreateRequire(import.meta.url);
3
+ import{isRecord,pick}from"./chunk-ZWVYVS2A.js";import{ApiRejectedError,ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";var STORAGE_FORBIDDEN="\u30B9\u30C8\u30EC\u30FC\u30B8\u306E\u4F7F\u7528\u72B6\u6CC1\u306F\u7BA1\u7406\u8005\u3060\u3051\u304C\u53C2\u7167\u3067\u304D\u307E\u3059\u3002\u7BA1\u7406\u8005\u306E\u30A2\u30AB\u30A6\u30F3\u30C8\u3067\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u524D\u306E\u5BB9\u91CF\u691C\u67FB\u306F\u4E00\u822C\u30E6\u30FC\u30B6\u30FC\u3067\u3082\u81EA\u52D5\u3067\u884C\u308F\u308C\u307E\u3059\uFF09\u3002";function checkResult(body){
4
+ const canUpload=isRecord(body)?body["can_upload"]:void 0;const result=isRecord(body)?body["check_result"]:void 0;if(typeof canUpload!=="boolean"||!isRecord(result)){throw new ApiResponseError("\u5BB9\u91CF\u691C\u67FB\u306E\u5FDC\u7B54\u306B can_upload / check_result \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}const text=key=>{const value=result[key];return typeof value==="string"?value:"\u4E0D\u660E"};return{canUpload,
5
+ softExceeded:result["soft_limit_exceeded"]===true,remaining:text("remaining_formatted"),quota:text("total_quota_formatted")}}async function checkUploadQuota(ctx,fileSize){const result=checkResult(await ctx.send(checkUploadPlan(fileSize)));if(!result.canUpload){throw new ApiRejectedError(`\u30C6\u30CA\u30F3\u30C8\u306E\u30B9\u30C8\u30EC\u30FC\u30B8\u5BB9\u91CF\u3092\u8D85\u3048\u308B\u305F\u3081\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3057\u307E\u305B\u3093\uFF08${fileSize} \u30D0\u30A4\u30C8\u30FB\u6B8B\u308A ${result.
6
+ remaining} / \u4E0A\u9650 ${result.quota}\uFF09\u3002\u4E0D\u8981\u306A\u30D5\u30A1\u30A4\u30EB\u3092\u524A\u9664\u3059\u308B\u304B\u3001\u7BA1\u7406\u8005\u306B\u5BB9\u91CF\u306E\u8FFD\u52A0\u3092\u4F9D\u983C\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}if(result.softExceeded){ctx.warn(`\u3053\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3067\u3001\u30C6\u30CA\u30F3\u30C8\u306E\u30B9\u30C8\u30EC\u30FC\u30B8\u4F7F\u7528\u91CF\u304C\u8B66\u544A\u306E\u95BE\u5024\u3092\u8D85\u3048\u307E\u3059\uFF08\u6B8B\u308A ${result.
7
+ remaining} / \u4E0A\u9650 ${result.quota}\uFF09\u3002`)}}function checkUploadPlan(fileSize){return{method:"POST",path:"/api/v2/storage/check-upload",body:{file_size:fileSize}}}var STATUS_COLUMNS=["status","can_upload","usage_percentage","used","remaining","quota","file_count","attachment","media","workspace"];function statusBody(body){if(!isRecord(body)||!isRecord(body["usage"])||!isRecord(body["quota"])){throw new ApiResponseError("\u30B9\u30C8\u30EC\u30FC\u30B8\u72B6\u6CC1\u306E\u5FDC\u7B54\u306B usage / quota \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
8
+ return body}function summarizeStatus(body){const status=statusBody(body);const usage=status["usage"];const quota=status["quota"];const byType=isRecord(usage["by_type"])?usage["by_type"]:{};const typeText=key=>{const row=byType[key];return isRecord(row)?`${String(row["formatted"])}\uFF08${String(row["file_count"])}\u4EF6\uFF09`:void 0};return pick({status:status["status"],can_upload:status["can_upload"],usage_percentage:status["usage_percentage"],used:usage["total_formatted"],remaining:status["re\
9
+ maining_formatted"],quota:quota["total_quota_formatted"],file_count:usage["total_file_count"],attachment:typeText("attachment"),media:typeText("media"),workspace:typeText("workspace")},STATUS_COLUMNS)}var GET_USAGE="twp storage get";var storageDomain={name:"storage",summary:"\u30C6\u30CA\u30F3\u30C8\u306E\u30B9\u30C8\u30EC\u30FC\u30B8\u4F7F\u7528\u91CF\u3068\u4E0A\u9650\uFF08\u7BA1\u7406\u8005\u306E\u307F\uFF09",operations:[{name:"get",summary:"\u4F7F\u7528\u91CF\u30FB\u4E0A\u9650\u30FB\u6B8B\u91CF\u30FB\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u53EF\u5426\u3092\u8868\u793A\u3059\u308B\uFF08\u7BA1\u7406\u8005\u306E\u307F\uFF09",
10
+ usage:GET_USAGE,description:"GET /api/v2/storage/status \u3092\u8868\u793A\u3057\u307E\u3059\uFF08\u4F7F\u7528\u91CF\u30FB\u4E0A\u9650\u306E\u4E21\u65B9\u3092\u542B\u307F\u307E\u3059\uFF09\u3002\n\u7A2E\u985E\u5225\uFF08attachment\uFF1D\u30BF\u30B9\u30AF\u6DFB\u4ED8 / media\uFF1D\u30E1\u30C7\u30A3\u30A2\u30E9\u30A4\u30D6\u30E9\u30EA / workspace\uFF09\u306E\u5185\u8A33\u3082\u51FA\u3057\u307E\u3059\u3002\n\u4F7F\u7528\u91CF\u306F\u30B5\u30FC\u30D0\u304C\u5B9A\u671F\u7684\u306B\u96C6\u8A08\u3057\u305F\u5024\u3067\u3059\uFF08--output json \u306E calculated_at \u304C\u96C6\u8A08\u6642\u523B\uFF09\u3002\n\u7BA1\u7406\u8005\u306E\u307F\u53C2\u7167\u3067\u304D\u307E\u3059\u3002\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u524D\u306E\u5BB9\u91CF\u691C\u67FB\uFF08check-upload\uFF09\u306F\u4E00\u822C\u30E6\u30FC\u30B6\u30FC\u3067\u3082\ntwp media upload / twp task attachment upload \u304C\u81EA\u52D5\u3067\u884C\u3044\u307E\u3059\u3002",
11
+ forbidden:STORAGE_FORBIDDEN,flags:[],plan(input){if(input.args.length>0){throw new UsageError(`get \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D7\u3051\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,GET_USAGE)}return{method:"GET",path:"/api/v2/storage/status"}},summarize:summarizeStatus,raw:body=>statusBody(body)}]};export{checkUploadQuota,checkUploadPlan,storageDomain};
@@ -1,16 +1,16 @@
1
1
  import { createRequire as __twpCreateRequire } from 'node:module';
2
2
  const require = __twpCreateRequire(import.meta.url);
3
- import{ApiResponseError,UsageError}from"./chunk-M3GWY6NT.js";var DEFAULT_MAX_PAGES=100;var DEFAULT_MAX_ITEMS=1e4;var LIST_FLAGS=[{name:"--limit",summary:"\u53D6\u5F97\u4EF6\u6570\uFF08\u30B5\u30FC\u30D0\u5074\u306E\u4E0A\u9650\u3067\u5207\u308A\u6368\u3066\u3089\u308C\u307E\u3059\uFF0F--all \u3068\u4F75\u7528\u3057\u305F\u3068\u304D\u306F1\u30DA\u30FC\u30B8\u306E\u4EF6\u6570\uFF09",takesValue:true,placeholder:"<\u4EF6\u6570>"},{name:"--cursor",summary:"\u7D9A\u304D\u3092\u53D6\u5F97\u3059\u308B\u30AB\u30FC\u30BD\u30EB\uFF08\u524D\u56DE\u306E\u5FDC\u7B54\u306E next_cursor\uFF09",
3
+ import{ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";var DEFAULT_MAX_PAGES=100;var DEFAULT_MAX_ITEMS=1e4;var LIST_FLAGS=[{name:"--limit",summary:"\u53D6\u5F97\u4EF6\u6570\uFF08\u30B5\u30FC\u30D0\u5074\u306E\u4E0A\u9650\u3067\u5207\u308A\u6368\u3066\u3089\u308C\u307E\u3059\uFF0F--all \u3068\u4F75\u7528\u3057\u305F\u3068\u304D\u306F1\u30DA\u30FC\u30B8\u306E\u4EF6\u6570\uFF09",takesValue:true,placeholder:"<\u4EF6\u6570>"},{name:"--cursor",summary:"\u7D9A\u304D\u3092\u53D6\u5F97\u3059\u308B\u30AB\u30FC\u30BD\u30EB\uFF08\u524D\u56DE\u306E\u5FDC\u7B54\u306E next_cursor\uFF09",
4
4
  takesValue:true,placeholder:"<\u30AB\u30FC\u30BD\u30EB>"},{name:"--all",summary:"\u5168\u30DA\u30FC\u30B8\u3092\u81EA\u52D5\u3067\u8FBF\u308B\uFF08--cursor \u3068\u4F75\u7528\u3059\u308B\u3068\u305D\u306E\u30AB\u30FC\u30BD\u30EB\u4EE5\u964D\u3092\u5168\u4EF6\uFF09",takesValue:false},{name:"--max-pages",summary:`--all \u304C\u7D9A\u304D\u3092\u53D6\u308A\u306B\u884C\u304F\u4E0A\u9650\u30DA\u30FC\u30B8\u6570\uFF08\u65E2\u5B9A ${DEFAULT_MAX_PAGES}\uFF09`,takesValue:true,placeholder:"<\u30DA\u30FC\u30B8\u6570>"},
5
5
  {name:"--max-items",summary:`--all \u304C\u7D9A\u304D\u3092\u53D6\u308A\u306B\u884C\u304F\u4E0A\u9650\u4EF6\u6570\uFF08\u65E2\u5B9A ${DEFAULT_MAX_ITEMS}\uFF09`,takesValue:true,placeholder:"<\u4EF6\u6570>"}];var LIST_PAGING_HELP="\u30DA\u30FC\u30B8\u30F3\u30B0:\n --all \u3092\u4ED8\u3051\u308B\u3068\u6700\u5F8C\u306E\u30DA\u30FC\u30B8\u307E\u3067\u81EA\u52D5\u3067\u8FBF\u308A\u307E\u3059\uFF08--limit \u306F1\u30DA\u30FC\u30B8\u306E\u4EF6\u6570\u306B\u306A\u308A\u307E\u3059\uFF09\u3002\n --all \u3068 --cursor \u3092\u4F75\u7528\u3059\u308B\u3068\u3001\u305D\u306E\u30AB\u30FC\u30BD\u30EB\u4EE5\u964D\u3092\u5168\u4EF6\u53D6\u5F97\u3057\u307E\u3059\uFF08\u4E2D\u65AD\u3057\u305F\u53D6\u5F97\u306E\u518D\u958B\uFF09\u3002\n\n \u66B4\u8D70\u3092\u9632\u3050\u305F\u3081 --max-pages / --max-items \u306E\u4E0A\u9650\u304C\u3042\u308A\u307E\u3059\u3002\u3053\u308C\u306F\u300C\u7D9A\u304D\u3092\u53D6\u308A\u306B\u884C\u304F\u304B\u300D\n \u306E\u5224\u5B9A\u306B\u3060\u3051\u4F7F\u308F\u308C\u3001\u7D50\u679C\u3092\u9014\u4E2D\u3067\u5207\u308A\u8A70\u3081\u308B\u3053\u3068\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u8FBF\u308A\u304D\u308B\u524D\u306B\u4E0A\u9650\u3078\u9054\u3057\u305F\n \u5834\u5408\u306F\u300C\u5168\u4EF6\u3067\u306F\u306A\u3044\u300D\u3053\u3068\u3092\u660E\u793A\u3057\u3066\u505C\u6B62\u3057\u3001\u90E8\u5206\u7684\u306A\u7D50\u679C\u306F\u51FA\u529B\u3057\u307E\u305B\u3093\uFF08\u53D6\u5F97\u6E08\u307F\u4EF6\u6570\u3068\n \u518D\u958B\
6
6
  \u7528\u306E\u30AB\u30FC\u30BD\u30EB\u306F stderr \u306B\u51FA\u307E\u3059\uFF09\u30021\u5F80\u5FA9\u3067\u5168\u4EF6\u304C\u8FD4\u3063\u305F\u3068\u304D\u306F\u4E0A\u9650\u3092\u8D85\u3048\u3066\u3044\u3066\u3082\u6210\u529F\u3067\u3059\u3002\n \u5F80\u5FA9\u304C\u591A\u3059\u304E\u3066\u4E0A\u9650\u306B\u5F53\u305F\u308B\u5834\u5408\u306F\u3001--max-pages \u3092\u4E0A\u3052\u308B\u3088\u308A --limit \u3092\u5927\u304D\u304F\u3059\u308B\u307B\u3046\u304C\u901F\u3044\n \u3053\u3068\u304C\u3042\u308A\u307E\u3059\uFF081\u5F80\u5FA9\u3042\u305F\u308A\u306E\u4EF6\u6570\u304C\u5897\u3048\u308B\u305F\u3081\uFF09\u3002\n\n \u26A0 --keyword \u3092\u4F75\u7528\u3057\u305F\u4E00\u89A7\u306F\u3001\u30B5\u30FC\u30D0\u5074\u304C\u30DA\u30FC\u30B8\u756A\u53F7\u306B\u3088\u308B\u4F4D\u7F6E\u6307\u5B9A\u3067\u5FDC\u7B54\u3057\u307E\u3059\u3002\n \u8FBF\u3063\u3066\u3044\u308B\u6700\u4E2D\u306B\u30C7\u30FC\u30BF\u304C\u5897\u6E1B\u3059\u308B\u3068\u3001\u53D6\u308A\u3053\u307C\u3057\u30FB\u91CD\u8907\u304C\u8D77\u3053\u308A\u5F97\u307E\u3059\u3002";
7
7
  function isRecord(value){return typeof value==="object"&&value!==null&&!Array.isArray(value)}function positiveInteger(flags,name){const raw=flags.get(name);if(raw===void 0)return void 0;const n=Number.parseInt(raw,10);if(!Number.isInteger(n)||n<=0||String(n)!==raw.trim()){throw new UsageError(`${name} \u306B\u306F\u6B63\u306E\u6574\u6570\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u53D7\u3051\u53D6\u3063\u305F\u5024: ${raw}\uFF09`)}return n}function nonEmpty(flags,name){const raw=flags.
8
- get(name);if(raw===void 0)return void 0;if(raw.trim()==="")throw new UsageError(`${name} \u306B\u7A7A\u306E\u5024\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`);return raw}function readEnvelopeCursor(body){const record=isRecord(body)?body:{};const nested=isRecord(record["pagination"])?record["pagination"]:void 0;return{hasMore:nested!==void 0&&"has_more"in nested?nested["has_more"]:record["has_more"],cursor:nested!==void 0&&"next_cursor"in nested?nested["next_cursor"]:record["next_cursor"]}}function envelopePaging(options){
9
- const itemsKey=options.itemsKey??"items";const cursorParam=options.cursorParam??"cursor";const items=body=>{const value=isRecord(body)?body[itemsKey]:void 0;if(!Array.isArray(value)){throw new ApiResponseError(`${options.label}\u306E\u5FDC\u7B54\u306B ${itemsKey} \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}return value};return{cursorParam,items,nextCursor(body){const{hasMore,cursor}=readEnvelopeCursor(body);
10
- if(hasMore!==true){if(hasMore===false||hasMore===void 0&&cursor===void 0||hasMore===null){return null}throw new ApiResponseError(`${options.label}\u306E\u5FDC\u7B54\u306E has_more \u3092\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093\uFF08\u53D7\u3051\u53D6\u3063\u305F\u5024: ${JSON.stringify(hasMore)??"undefined"}\uFF09\u3002\u7D9A\u304D\u306E\u6709\u7121\u3092\u5224\u5B9A\u3067\u304D\u306A\u3044\u305F\u3081\u4E2D\u65AD\u3057\u307E\u3057\u305F\u3002`)}if(typeof cursor!=="string"||cursor===""){throw new ApiResponseError(
11
- `${options.label}\u306E\u5FDC\u7B54\u306B\u7D9A\u304D\u304C\u3042\u308B\uFF08has_more: true\uFF09\u3068\u793A\u3055\u308C\u3066\u3044\u307E\u3059\u304C\u3001next_cursor \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u5168\u4EF6\u3092\u53D6\u5F97\u3067\u304D\u306A\u3044\u305F\u3081\u4E2D\u65AD\u3057\u307E\u3057\u305F\u3002`)}return cursor},withItems(body,merged){items(body);return{...body,[itemsKey]:[...merged]}}}}var SHELL_SAFE=/^[A-Za-z0-9_@%+:,./-][A-Za-z0-9_@%+=:,./-]*$/;function shellQuote(value){
12
- if(SHELL_SAFE.test(value))return value;return`'${value.replace(/'/g,"'\\''")}'`}function flagSegment(name,value){return value.startsWith("-")?`${name}=${shellQuote(value)}`:`${name} ${shellQuote(value)}`}var PAGING_CONTROL_FLAGS=new Set(LIST_FLAGS.map(spec=>spec.name).filter(name=>name!=="--limit"));var CONTROL_CHARS=/[\u0000-\u001f\u007f-\u009f]/;function nextPageCommand(input,cursor,context){const flags=[];if(context.profile!==void 0)flags.push(flagSegment("--profile",context.profile));for(const spec of context.
13
- flags){if(PAGING_CONTROL_FLAGS.has(spec.name))continue;const value=input.flags.get(spec.name);if(value===void 0)continue;flags.push(spec.takesValue?flagSegment(spec.name,value):spec.name)}flags.push(flagSegment("--cursor",cursor));const args=input.args.map(arg=>shellQuote(arg));const separated=input.args.some(arg=>arg.startsWith("-"));return separated?[context.command,...flags,"--",...args].join(" "):[context.command,...args,...flags].join(" ")}function nextPageNotes(body,input,context){const{hasMore,
14
- cursor}=readEnvelopeCursor(body);if(hasMore!==true){if(hasMore===false||hasMore===null||hasMore===void 0&&cursor===void 0)return[];return[`\u5FDC\u7B54\u306E has_more \u3092\u89E3\u91C8\u3067\u304D\u306A\u3044\u305F\u3081\u3001\u7D9A\u304D\u306E\u6709\u7121\u3092\u5224\u5B9A\u3067\u304D\u307E\u305B\u3093\uFF08\u53D7\u3051\u53D6\u3063\u305F\u5024: ${JSON.stringify(hasMore)??"undefined"}\uFF09\u3002\u5168\u4EF6\u304C\u8981\u308B\u306A\u3089 --all \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002`]}
8
+ get(name);if(raw===void 0)return void 0;if(raw.trim()==="")throw new UsageError(`${name} \u306B\u7A7A\u306E\u5024\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`);return raw}function readEnvelopeCursor(body){const record=isRecord(body)?body:{};const nested=isRecord(record["pagination"])?record["pagination"]:isRecord(record["meta"])&&"has_more"in record["meta"]?record["meta"]:void 0;return{hasMore:nested!==void 0&&"has_more"in nested?nested["has_more"]:record["has_more"],cursor:nested!==void 0&&
9
+ "next_cursor"in nested?nested["next_cursor"]:record["next_cursor"]}}function envelopePaging(options){const itemsKey=options.itemsKey??"items";const cursorParam=options.cursorParam??"cursor";const items=body=>{const value=isRecord(body)?body[itemsKey]:void 0;if(!Array.isArray(value)){throw new ApiResponseError(`${options.label}\u306E\u5FDC\u7B54\u306B ${itemsKey} \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}
10
+ return value};return{cursorParam,items,nextCursor(body){const{hasMore,cursor}=readEnvelopeCursor(body);if(hasMore!==true){if(hasMore===false||hasMore===void 0&&cursor===void 0||hasMore===null){return null}throw new ApiResponseError(`${options.label}\u306E\u5FDC\u7B54\u306E has_more \u3092\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093\uFF08\u53D7\u3051\u53D6\u3063\u305F\u5024: ${JSON.stringify(hasMore)??"undefined"}\uFF09\u3002\u7D9A\u304D\u306E\u6709\u7121\u3092\u5224\u5B9A\u3067\u304D\u306A\u3044\u305F\u3081\u4E2D\u65AD\u3057\u307E\u3057\u305F\u3002`)}
11
+ if(typeof cursor!=="string"||cursor===""){throw new ApiResponseError(`${options.label}\u306E\u5FDC\u7B54\u306B\u7D9A\u304D\u304C\u3042\u308B\uFF08has_more: true\uFF09\u3068\u793A\u3055\u308C\u3066\u3044\u307E\u3059\u304C\u3001next_cursor \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u5168\u4EF6\u3092\u53D6\u5F97\u3067\u304D\u306A\u3044\u305F\u3081\u4E2D\u65AD\u3057\u307E\u3057\u305F\u3002`)}return cursor},withItems(body,merged){items(body);return{...body,[itemsKey]:[...merged]}}}}var SHELL_SAFE=/^[A-Za-z0-9_@%+:,./-][A-Za-z0-9_@%+=:,./-]*$/;
12
+ function shellQuote(value){if(SHELL_SAFE.test(value))return value;return`'${value.replace(/'/g,"'\\''")}'`}function flagSegment(name,value){return value.startsWith("-")?`${name}=${shellQuote(value)}`:`${name} ${shellQuote(value)}`}var PAGING_CONTROL_FLAGS=new Set(LIST_FLAGS.map(spec=>spec.name).filter(name=>name!=="--limit"));var CONTROL_CHARS=/[\u0000-\u001f\u007f-\u009f]/;function nextPageCommand(input,cursor,context){const flags=[];if(context.profile!==void 0)flags.push(flagSegment("--profile",
13
+ context.profile));for(const spec of context.flags){if(PAGING_CONTROL_FLAGS.has(spec.name))continue;const value=input.flags.get(spec.name);if(value===void 0)continue;flags.push(spec.takesValue?flagSegment(spec.name,value):spec.name)}flags.push(flagSegment("--cursor",cursor));const args=input.args.map(arg=>shellQuote(arg));const separated=input.args.some(arg=>arg.startsWith("-"));return separated?[context.command,...flags,"--",...args].join(" "):[context.command,...args,...flags].join(" ")}function nextPageNotes(body,input,context){
14
+ const{hasMore,cursor}=readEnvelopeCursor(body);if(hasMore!==true){if(hasMore===false||hasMore===null||hasMore===void 0&&cursor===void 0)return[];return[`\u5FDC\u7B54\u306E has_more \u3092\u89E3\u91C8\u3067\u304D\u306A\u3044\u305F\u3081\u3001\u7D9A\u304D\u306E\u6709\u7121\u3092\u5224\u5B9A\u3067\u304D\u307E\u305B\u3093\uFF08\u53D7\u3051\u53D6\u3063\u305F\u5024: ${JSON.stringify(hasMore)??"undefined"}\uFF09\u3002\u5168\u4EF6\u304C\u8981\u308B\u306A\u3089 --all \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002`]}
15
15
  if(typeof cursor!=="string"||cursor==="")return["\u7D9A\u304D\u304C\u3042\u308A\u307E\u3059\u304C\u3001\u5FDC\u7B54\u306B next_cursor \u304C\u3042\u308A\u307E\u305B\u3093\u3002"];if(CONTROL_CHARS.test(cursor)){return["\u7D9A\u304D\u304C\u3042\u308A\u307E\u3059\u304C\u3001\u5FDC\u7B54\u306E next_cursor \u306B\u5236\u5FA1\u6587\u5B57\u304C\u542B\u307E\u308C\u308B\u305F\u3081\u6848\u5185\u3092\u51FA\u305B\u307E\u305B\u3093\u3002--all \u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044\u3002"]}const hint=context.
16
16
  flags.some(spec=>spec.name==="--all")?"\uFF08\u5168\u4EF6\u306F --all\uFF09":"";return[`\u7D9A\u304D\u304C\u3042\u308A\u307E\u3059\u3002\u6B21\u306E\u30DA\u30FC\u30B8: ${nextPageCommand(input,cursor,context)}${hint}`]}export{DEFAULT_MAX_PAGES,DEFAULT_MAX_ITEMS,LIST_FLAGS,LIST_PAGING_HELP,positiveInteger,nonEmpty,readEnvelopeCursor,envelopePaging,shellQuote,nextPageNotes};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __twpCreateRequire } from 'node:module';
2
+ const require = __twpCreateRequire(import.meta.url);
3
+ var DOMAIN_NAMES=["backlog","department","job-title","media","position","project","storage","task","user"];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};
@@ -0,0 +1,10 @@
1
+ import { createRequire as __twpCreateRequire } from 'node:module';
2
+ const require = __twpCreateRequire(import.meta.url);
3
+ import{httpFetch}from"./chunk-J7QYPKVK.js";function encodeScalar(key,value,inArray){if(typeof value==="boolean")return value?"true":"false";if(typeof value==="number"){if(!Number.isFinite(value)){throw new TypeError(`\u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF ${key} \u306B\u6709\u9650\u3067\u306A\u3044\u6570\u5024\u306F\u6E21\u305B\u307E\u305B\u3093: ${String(value)}`)}return String(value)}if(inArray&&value.includes(",")){throw new TypeError(`\u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF ${key} \u306E\u914D\u5217\u8981\u7D20\u306B\u30AB\u30F3\u30DE\u306F\u542B\u3081\u3089\u308C\u307E\u305B\u3093: ${value}`)}
4
+ return value}function buildQuery(params){if(!params)return"";const search=new URLSearchParams;for(const[key,value]of Object.entries(params)){if(value===null||value===void 0)continue;if(Array.isArray(value)){if(value.length===0)continue;search.append(key,value.map(v=>encodeScalar(key,v,true)).join(","));continue}search.append(key,encodeScalar(key,value,false))}return search.toString()}function appendQuery(path,params){const qs=buildQuery(params);if(qs==="")return path;if(path.endsWith("?")||path.
5
+ endsWith("&"))return`${path}${qs}`;return`${path}${path.includes("?")?"&":"?"}${qs}`}var ApiError=class extends Error{constructor(status,body,method,path){super(`${method} ${path} -> ${status}${reasonOf(body)}`);this.status=status;this.body=body}status;body};function reasonOf(body){const head=body?.error_description||body?.message||"";const detail=errorListMessages(body?.error_list).filter(text=>!text.endsWith(`: ${head}`)&&text!==head).join(" / ");if(head!==""&&detail!=="")return` (${head} ${detail})`;if(head!=="")return` (${head})`;return detail!==""?` (${detail})`:""}var TwpApiClient=class{constructor(apiUrl,session,fetchImpl=httpFetch,cliVersion="\
6
+ 0.0.0-dev"){this.apiUrl=apiUrl;this.session=session;this.fetchImpl=fetchImpl;this.cliVersion=cliVersion}apiUrl;session;fetchImpl;cliVersion;async get(path,query){return this.request("GET",appendQuery(path,query))}async post(path,body,query){return this.request("POST",appendQuery(path,query),body)}async put(path,body,query){return this.request("PUT",appendQuery(path,query),body)}async patch(path,body,query){return this.request("PATCH",appendQuery(path,query),body)}async delete(path,query){return this.
7
+ request("DELETE",appendQuery(path,query))}async requestBinary(method,path){let token=await this.session.getAccessToken();let res=await this.send(method,path,token);if(res.status===401){token=await this.session.refresh(token);res=await this.send(method,path,token)}if(!res.ok){const errBody=await res.json().then(parsed=>parsed,()=>null);throw new ApiError(res.status,errBody,method,path)}return{bytes:new Uint8Array(await res.arrayBuffer()),contentType:res.headers.get("content-type")}}async request(method,path,body){
8
+ let token=await this.session.getAccessToken();let res=await this.send(method,path,token,body);if(res.status===401){token=await this.session.refresh(token);res=await this.send(method,path,token,body)}if(!res.ok){const errBody=await res.json().then(parsed=>parsed,()=>null);throw new ApiError(res.status,errBody,method,path)}if(res.status===204||res.headers.get("content-length")==="0"){return null}const raw=await res.text();if(raw.trim()==="")return null;try{return JSON.parse(raw)}catch{throw new ApiError(
9
+ res.status,null,method,path)}}send(method,path,token,body){return this.fetchImpl(`${this.apiUrl}${path}`,{method,headers:{Accept:"application/json",Authorization:`Bearer ${token}`,"User-Agent":`twp-cli/${this.cliVersion}`,...body!==void 0?{"Content-Type":"application/json"}:{}},...body!==void 0?{body:JSON.stringify(body)}:{}})}};function errorListMessages(list){if(Array.isArray(list)){return list.flatMap(item=>{if(typeof item!=="object"||item===null)return[];const{name,message}=item;if(typeof message!==
10
+ "string"||message==="")return[];return[typeof name==="string"&&name!==""?`${name}: ${message}`:message]})}if(typeof list==="object"&&list!==null){return Object.entries(list).flatMap(([name,messages])=>(Array.isArray(messages)?messages:[messages]).filter(message=>typeof message==="string"&&message!=="").map(message=>`${name}: ${message}`))}return[]}export{appendQuery,ApiError,TwpApiClient,errorListMessages};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __twpCreateRequire } from 'node:module';
2
2
  const require = __twpCreateRequire(import.meta.url);
3
- import{UsageError}from"./chunk-M3GWY6NT.js";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}`)}}export{evaluateQuery};
3
+ import{UsageError}from"./chunk-7WSNIXTQ.js";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}`)}}export{evaluateQuery};
@@ -6,4 +6,4 @@ test(value)}function collapsesInUrlPath(value){return/^\.+$/.test(value)}async f
6
6
  it",project:{id:project.id,code:project.code??ref,name:project.name??ref}}}async function resolveByListScan(ref,get,policy){let cursor;for(let page=0;page<20;page++){const qs=new URLSearchParams({limit:"100"});if(cursor)qs.set("cursor",cursor);const res=await get(`/api/v2/projects?${qs.toString()}`);if(!res.ok){throw new ResolveError(`\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08HTTP ${res.status}\uFF09\u3002--project \u306B\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306EUUID\u3092\
7
7
  \u76F4\u63A5\u6307\u5B9A\u3059\u308B\u304B\u3001\u63A5\u7D9A\u5148\u3068\u30ED\u30B0\u30A4\u30F3\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`,res.status)}const body=res.json;const items=body?.items??[];const hit=items.find(p=>(p.code??"").toLowerCase()===ref.toLowerCase());if(hit){policy.assertId(hit.id);return hit}const hasMore=body?.pagination?.has_more??body?.has_more??false;const next=body?.pagination?.next_cursor??body?.next_cursor;if(!hasMore||!next)break;cursor=
8
8
  next}throw new ResolveError(`\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${ref}\uFF08\u30B3\u30FC\u30C9\u306E\u5B8C\u5168\u4E00\u81F4\u3067\u63A2\u3057\u3066\u3044\u307E\u3059\uFF09`,404)}async function resolveProjectRef(ref,get,policy){if(policy.isDirectId(ref))return{id:ref,code:ref,name:ref};if(collapsesInUrlPath(ref)){throw new ResolveError(`\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30B3\u30FC\u30C9\u3068\u3057\u3066\u4F7F\u3048\u306A\u3044\u5024\u3067\u3059: ${ref}`,
9
- 404)}const point=await resolveByCode(ref,get,policy);if(point.kind==="hit")return point.project;if(point.kind==="absent"){throw new ResolveError(`\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${ref}\uFF08\u30B3\u30FC\u30C9\u3067\u691C\u7D22\u3057\u3066\u3044\u307E\u3059\uFF09`,404)}return resolveByListScan(ref,get,policy)}export{ResolveError,UUID_RE,uuidProjectIdPolicy,safeProjectIdPolicy,isSafePathSegment,collapsesInUrlPath,resolveProjectRef};
9
+ 404)}const point=await resolveByCode(ref,get,policy);if(point.kind==="hit")return point.project;if(point.kind==="absent"){throw new ResolveError(`\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${ref}\uFF08\u30B3\u30FC\u30C9\u3067\u691C\u7D22\u3057\u3066\u3044\u307E\u3059\uFF09`,404)}return resolveByListScan(ref,get,policy)}export{ResolveError,UUID_RE,ULID_RE,uuidProjectIdPolicy,safeProjectIdPolicy,isSafePathSegment,collapsesInUrlPath,resolveProjectRef};
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __twpCreateRequire } from 'node:module';
2
2
  const require = __twpCreateRequire(import.meta.url);
3
- import{UsageError}from"./chunk-M3GWY6NT.js";import fs from"fs";var BOM="\uFEFF";async function readStdin(spec){if(process.stdin.isTTY===true){throw new UsageError(`${spec.fileFlag} - \u306F\u6A19\u6E96\u5165\u529B\u304B\u3089\u8AAD\u307F\u307E\u3059\u304C\u3001\u7AEF\u672B\u304C\u7E4B\u304C\u3063\u3066\u3044\u307E\u3059`,`\u30D1\u30A4\u30D7\u304B\u30EA\u30C0\u30A4\u30EC\u30AF\u30C8\u3067\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u4F8B: cat review.md | twp \u2026 ${spec.fileFlag} -\uFF09\u3002`)}const chunks=[];for await(const chunk of process.stdin)chunks.
3
+ import{UsageError}from"./chunk-7WSNIXTQ.js";import fs from"fs";var BOM="\uFEFF";async function readStdin(spec){if(process.stdin.isTTY===true){throw new UsageError(`${spec.fileFlag} - \u306F\u6A19\u6E96\u5165\u529B\u304B\u3089\u8AAD\u307F\u307E\u3059\u304C\u3001\u7AEF\u672B\u304C\u7E4B\u304C\u3063\u3066\u3044\u307E\u3059`,`\u30D1\u30A4\u30D7\u304B\u30EA\u30C0\u30A4\u30EC\u30AF\u30C8\u3067\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u4F8B: cat review.md | twp \u2026 ${spec.fileFlag} -\uFF09\u3002`)}const chunks=[];for await(const chunk of process.stdin)chunks.
4
4
  push(Buffer.from(chunk));return Buffer.concat(chunks).toString("utf8")}function charCount(text){return[...text].length}async function readBody(input,spec){const inline=input.flags.get(spec.flag);const file=input.flags.get(spec.fileFlag);if(inline!==void 0&&file!==void 0){throw new UsageError(`${spec.label}\u304C ${spec.flag} \u3068 ${spec.fileFlag} \u306E\u4E21\u65B9\u3067\u6307\u5B9A\u3055\u308C\u3066\u3044\u307E\u3059`,`\u3069\u3061\u3089\u304B\u4E00\u65B9\u3060\u3051\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${spec.
5
5
  fileFlag} - \u3067\u6A19\u6E96\u5165\u529B\u304B\u3089\u8AAD\u3081\u307E\u3059\uFF09\u3002`)}if(inline===void 0&&file===void 0)return void 0;const text=inline??await readFrom(file,spec);const stripped=text.startsWith(BOM)?text.slice(BOM.length):text;if(stripped.trim()===""){throw new UsageError(`${spec.label}\u304C\u7A7A\u3067\u3059\uFF08${inline!==void 0?spec.flag:`${spec.fileFlag} ${file}`}\uFF09`,spec.usage)}const count=charCount(stripped);if(count>spec.maxChars){throw new UsageError(`${spec.
6
6
  label}\u304C\u9577\u3059\u304E\u307E\u3059\uFF08${count} \u6587\u5B57\u30FB\u4E0A\u9650 ${spec.maxChars} \u6587\u5B57\uFF09`,"\u5206\u5272\u3057\u3066\u6295\u7A3F\u3059\u308B\u304B\u3001\u8A73\u7D30\u306F\u6DFB\u4ED8\u30D5\u30A1\u30A4\u30EB\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return stripped}async function readFrom(file,spec){if(file==="-")return readStdin(spec);try{const stat=fs.statSync(file);if(!stat.isFile()){throw new UsageError(`${spec.label}\u306B\u901A\u5E38\u306E\u30D5\u30A1\u30A4\u30EB\u4EE5\u5916\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093: ${file}`,
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __twpCreateRequire } from 'node:module';
2
2
  const require = __twpCreateRequire(import.meta.url);
3
- import{isModeId,isPermissionModeId}from"./chunk-BOBSH3QN.js";import{API_TOKEN,HELP_TOKEN,isDomainName}from"./chunk-PEGUHUTD.js";import{splitFlagToken}from"./chunk-QQRJLH6B.js";var BUILTIN_COMMANDS=["login","logout","whoami","update","task-loop"];var TASK_LOOP_ACTIONS=["run","status","stop","schedule","setup","charter"];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","--file","--out","--revision","--output","--query"]);var BOOLEAN_FLAGS=new Set(["-h","--help","\
3
+ import{isModeId,isPermissionModeId}from"./chunk-NAUH75MM.js";import{API_TOKEN,HELP_TOKEN,isDomainName}from"./chunk-EJ474UDB.js";import{splitFlagToken}from"./chunk-QQRJLH6B.js";var BUILTIN_COMMANDS=["login","logout","whoami","update","task-loop"];var TASK_LOOP_ACTIONS=["run","status","stop","schedule","setup","charter"];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","--file","--out","--revision","--output","--query"]);var BOOLEAN_FLAGS=new Set(["-h","--help","\
4
4
  -v","--version","--no-tui","--doctor","--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){
5
5
  truncated=true;break}continue}if(VALUE_FLAGS.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){
6
6
  const{tokens,indexes}=result;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&&
@@ -0,0 +1,57 @@
1
+ import { createRequire as __twpCreateRequire } from 'node:module';
2
+ const require = __twpCreateRequire(import.meta.url);
3
+ import{PRIVATE_PROJECT_REF,isPrivateProjectRef}from"./chunk-GY7KI5E5.js";import{checkUploadQuota}from"./chunk-DDKZ5IPT.js";import{PRIVATE_TASK_KEY_PREFIX,isPrivateTaskKey,isTaskKey}from"./chunk-II5RVJQN.js";import{requireResolved,singleRef,withResolved}from"./chunk-ZN5EFDH7.js";import{isSafePathSegment,safeProjectIdPolicy}from"./chunk-GMBJTG6A.js";import{isRecord,pick}from"./chunk-ZWVYVS2A.js";import{ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";function classifyTaskRef(ref){const value=ref.trim();if(safeProjectIdPolicy.isDirectId(value))return{kind:"id",value};if(isTaskKey(value))return{kind:"key",value};return{kind:"unknown",value}}function wantsPrivateSurface(input){const project=input.flags.get("--project");return project!==void 0&&isPrivateProjectRef(project)}function taskSurface(input,ref){const project=input.flags.get("--project");const{kind,value}=classifyTaskRef(ref);if(project!==void 0&&isPrivateProjectRef(project)){if(kind===
4
+ "key"&&!isPrivateTaskKey(value)){throw new UsageError(`--project ${PRIVATE_PROJECT_REF}\uFF08\u500B\u4EBA\u30BF\u30B9\u30AF\uFF09\u306B ${value} \u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,`\u500B\u4EBA\u30BF\u30B9\u30AF\u306E\u30AD\u30FC\u306F ${PRIVATE_TASK_KEY_PREFIX}-<\u756A\u53F7> \u306E\u5F62\u3067\u3059\u3002ID\uFF08UUID / ULID\uFF09\u3067\u3082\u6307\u5B9A\u3067\u304D\u307E\u3059\u3002
5
+ \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30BF\u30B9\u30AF\u3092\u6307\u3059\u306A\u3089 --project ${PRIVATE_PROJECT_REF} \u3092\u5916\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}return"private"}if(kind==="key"&&isPrivateTaskKey(value)&&project===void 0){throw new UsageError(`${value} \u306F\u500B\u4EBA\u30BF\u30B9\u30AF\u306E\u30AD\u30FC\u306B\u3082\u3001\u30B3\u30FC\u30C9 ${PRIVATE_TASK_KEY_PREFIX} \u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30BF\u30B9\u30AF\u30AD\u30FC\u306B\u3082\u8AAD\u3081\u307E\u3059`,
6
+ `\u3069\u3061\u3089\u3092\u6307\u3059\u304B --project \u3067\u9078\u3093\u3067\u304F\u3060\u3055\u3044\u3002
7
+ \u500B\u4EBA\u30BF\u30B9\u30AF : --project ${PRIVATE_PROJECT_REF}
8
+ \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8: --project ${PRIVATE_TASK_KEY_PREFIX}`)}return"project"}function rejectPrivateSurface(input,what){if(!wantsPrivateSurface(input))return;throw new UsageError(`--project ${PRIVATE_PROJECT_REF}\uFF08\u500B\u4EBA\u30BF\u30B9\u30AF\uFF09\u3067\u306F${what}\u3092\u6271\u3048\u307E\u305B\u3093`,`\u30B5\u30FC\u30D0\u5074\u306B\u500B\u4EBA\u30BF\u30B9\u30AF\u7528\u306E API \u304C\u3042\u308A\u307E\u305B\u3093\u3002TWP \u306E\u753B\u9762\u304B\u3089\u64CD\u4F5C\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}
9
+ async function resolveTaskLocation(input,ctx,ref){rejectPrivateSurface(input,"\u3053\u306E\u64CD\u4F5C");const{kind,value}=classifyTaskRef(ref);if(kind==="key"){if(isPrivateTaskKey(value)&&input.flags.get("--project")===void 0){throw new UsageError(`${value} \u306F\u500B\u4EBA\u30BF\u30B9\u30AF\u306E\u30AD\u30FC\u306B\u3082\u3001\u30B3\u30FC\u30C9 ${PRIVATE_TASK_KEY_PREFIX} \u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30BF\u30B9\u30AF\u30AD\u30FC\u306B\u3082\u8AAD\u3081\u307E\u3059`,`\u3053\u306E\u64CD\u4F5C\u306F\u500B\
10
+ \u4EBA\u30BF\u30B9\u30AF\u306B\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u305B\u3093\uFF08\u30B5\u30FC\u30D0\u5074\u306B API \u304C\u3042\u308A\u307E\u305B\u3093\uFF09\u3002
11
+ \u30B3\u30FC\u30C9 ${PRIVATE_TASK_KEY_PREFIX} \u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30BF\u30B9\u30AF\u3092\u6307\u3059\u306A\u3089 --project ${PRIVATE_TASK_KEY_PREFIX} \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002`)}rejectRedundantProject(input,value);const resolved=await ctx.resolver.taskByKey(value);const id=resolved.task["id"];if(!isSafePathSegment(id)){throw new ApiResponseError(`\u30BF\u30B9\u30AF\u30AD\u30FC\u89E3\u6C7A\u306E\u5FDC\u7B54\u306E task.id \u3092\u305D\u306E\u307E\u307E\u4F7F\u3048\u307E\u305B\u3093\uFF08${String(
12
+ id).slice(0,60)}\uFF09\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}return{projectId:resolved.projectId,taskId:id}}if(kind==="unknown"){throw new UsageError(`\u30BF\u30B9\u30AF\u306E\u6307\u5B9A\u304C\u300C\u30AD\u30FC\uFF08\u4F8B ABC-123\uFF09\u300D\u306B\u3082\u300CID\uFF08UUID / ULID\uFF09\u300D\u306B\u3082\u898B\u3048\u307E\u305B\u3093: ${ref}`,"\u30AD\u30FC\u306F\u300C\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30B3\u30FC\u30C9-\u756A\u53F7\u300D\u306E\u5F62\u3067\u3059\u3002ID \u3092\u6307\u5B9A\u3059\u308B\u5834\u5408\u306F --project \u3082\u5FC5\u8981\u3067\u3059\u3002")}
13
+ if(kind!=="id"){const exhaustive=kind;throw new Error(`\u672A\u77E5\u306E\u30BF\u30B9\u30AF\u53C2\u7167\u306E\u7A2E\u5225\u3067\u3059: ${String(exhaustive)}`)}return{projectId:await ctx.projectId(input.flags.get("--project")),taskId:value}}function rejectRedundantProject(input,ref){const project=input.flags.get("--project");if(project===void 0)return;if(isPrivateTaskKey(ref)){if(isPrivateProjectRef(project))return;if(project.trim().toLowerCase()===PRIVATE_TASK_KEY_PREFIX.toLowerCase())return;throw new UsageError(
14
+ `\u30AD\u30FC ${ref} \u3068 --project ${project} \u304C\u98DF\u3044\u9055\u3063\u3066\u3044\u307E\u3059`,`${ref} \u304C\u6307\u305B\u308B\u306E\u306F\u6B21\u306E2\u3064\u3060\u3051\u3067\u3059\u3002
15
+ \u500B\u4EBA\u30BF\u30B9\u30AF : --project ${PRIVATE_PROJECT_REF}
16
+ \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8: --project ${PRIVATE_TASK_KEY_PREFIX}\uFF08\u30AD\u30FC\u306E\u63A5\u982D\u8F9E\u3068\u540C\u3058\u30B3\u30FC\u30C9\uFF09
17
+ \u5225\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30BF\u30B9\u30AF\u3092\u6307\u3059\u306A\u3089\u3001\u30AD\u30FC\u3067\u306F\u306A\u304F\u305D\u306E\u30BF\u30B9\u30AF\u306E ID\uFF08UUID / ULID\uFF09\u3092\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}throw new UsageError(`\u30AD\u30FC\u5F62\u5F0F\uFF08${ref}\uFF09\u3067\u6307\u5B9A\u3057\u305F\u3068\u304D\u306B --project \u306F\u4F7F\u3048\u307E\u305B\u3093\uFF08--project ${project} \u306F\u7121\u8996\u3055\u308C\u307E\u3059\uFF09`,"\
18
+ \u30AD\u30FC\u306F\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3092\u542B\u3093\u3067\u3044\u308B\u306E\u3067 --project \u3092\u5916\u3057\u3066\u304F\u3060\u3055\u3044\u3002--project \u304C\u8981\u308B\u306E\u306F\u3001\u30BF\u30B9\u30AF\u3092 ID\uFF08UUID / ULID\uFF09\u3067\u6307\u5B9A\u3059\u308B\u3068\u304D\u3060\u3051\u3067\u3059\u3002")}var TASK_REF_FLAG={name:"--task",summary:"\u30BF\u30B9\u30AF\u306E\u30AD\u30FC\uFF08\u4F8B ABC-123\uFF09\u307E\u305F\u306F ID\u3002\u4F4D\u7F6E\u5F15\u6570\u3068\u540C\u3058\u610F\u5473\uFF08\u4E21\u65B9\u6307\u5B9A\u306F\u30A8\u30E9\u30FC\uFF09",
19
+ takesValue:true,placeholder:"<\u30AD\u30FC|ID>"};var PROJECT_FLAG={name:"--project",summary:`\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30B3\u30FC\u30C9\u307E\u305F\u306F ID\uFF08\u7701\u7565\u6642\u306F TWP_PROJECT / .twp/config.json / ~/.twp/config.json\uFF09\u3002\u30BF\u30B9\u30AF\u3092\u30AD\u30FC\u3067\u6307\u5B9A\u3059\u308B\u3068\u304D\u306F\u4F7F\u3048\u307E\u305B\u3093\u3002${PRIVATE_PROJECT_REF} \u3067\u500B\u4EBA\u30BF\u30B9\u30AF\u3092\u6307\u3057\u307E\u3059`,takesValue:true,placeholder:`\
20
+ <\u30B3\u30FC\u30C9|ID|${PRIVATE_PROJECT_REF}>`};var TASK_REF_HELP=`\u30AD\u30FC\u5F62\u5F0F\uFF08\u4F8B ABC-123\uFF09\u306A\u3089 --project \u306F\u8981\u308A\u307E\u305B\u3093\uFF081\u5F80\u5FA9\u3067\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3054\u3068\u89E3\u6C7A\u3055\u308C\u307E\u3059\uFF09\u3002
21
+ \u30AD\u30FC\u306F\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3092\u542B\u3093\u3067\u3044\u308B\u306E\u3067\u3001\u30AD\u30FC\u3068 --project \u3092\u4E00\u7DD2\u306B\u6307\u5B9A\u3059\u308B\u3068\u30A8\u30E9\u30FC\u306B\u306A\u308A\u307E\u3059\u3002
22
+ ID\uFF08UUID / ULID\uFF09\u3067\u6307\u5B9A\u3059\u308B\u5834\u5408\u3060\u3051 --project\uFF08\u307E\u305F\u306F\u65E2\u5B9A\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\uFF09\u304C\u8981\u308A\u307E\u3059\u3002
23
+ UUID / ULID \u306E\u5F62\u3092\u3057\u305F\u5024\u306F\u3001\u30AD\u30FC\u306E\u5F62\u306B\u3082\u8AAD\u3081\u308B\u3068\u304D\u3067\u3082 ID \u3068\u3057\u3066\u6271\u3044\u307E\u3059\uFF08\u4F8B: \u672B\u5C3E12\u6841\u304C\u5168\u6570\u5B57\u306E UUID\uFF09\u3002\u3053\u306E\u5834\u5408\u306F --project \u304C\u8981\u308A\u307E\u3059\u3002
24
+ --task <\u30AD\u30FC|ID> \u3067\u3082\u540C\u3058\u610F\u5473\u3067\u3059\u3002\u4F4D\u7F6E\u5F15\u6570\u3068 --task \u306E\u4E21\u65B9\u3092\u6307\u5B9A\u3059\u308B\u3068\u30A8\u30E9\u30FC\u306B\u306A\u308A\u307E\u3059\u3002
25
+ ${PRIVATE_TASK_KEY_PREFIX}-<\u756A\u53F7> \u306E\u5F62\u306E\u30AD\u30FC\u3060\u3051\u306F\u4F8B\u5916\u3067\u3001--project \u304C\u5FC5\u9808\u3067\u3059\uFF08\u500B\u4EBA\u30BF\u30B9\u30AF\u306E\u30AD\u30FC\u3068\u3082\u3001\u30B3\u30FC\u30C9 ${PRIVATE_TASK_KEY_PREFIX} \u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30BF\u30B9\u30AF\u30AD\u30FC\u3068\u3082\u8AAD\u3081\u308B\u305F\u3081\uFF09\u3002`;import fs from"fs";import path from"path";var TASK_SOURCE="task";var IDS_PER_REQUEST=100;var LIST_COLUMNS=["id","file_name","content_type","file_size","is_committed","created_at"];var UPLOAD_COLUMNS=["attachment_id","task_id","file_name","content_type","file_size","attachment_count"];var CONTENT_TYPES={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".pdf":"application/pdf",".txt":"text/plain",".log":"text/plain",".md":"text/markdown",".csv":"text/csv",".json":"application/json",".zip":"\
26
+ application/zip",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation"};function contentTypeFor(fileName){return CONTENT_TYPES[path.extname(fileName).toLowerCase()]??"application/octet-stream"}var FILE_FLAG={name:"--file",summary:"\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3059\u308B\u30ED\u30FC\u30AB\u30EB\u30D5\u30A1\u30A4\u30EB\u306E\u30D1\u30B9\uFF08\u5FC5\u9808\uFF09",
27
+ takesValue:true,placeholder:"<\u30D1\u30B9>"};var NAME_FLAG={name:"--name",summary:"\u30B5\u30FC\u30D0\u306B\u4FDD\u5B58\u3059\u308B\u30D5\u30A1\u30A4\u30EB\u540D\uFF08\u7701\u7565\u6642\u306F\u30ED\u30FC\u30AB\u30EB\u306E\u30D5\u30A1\u30A4\u30EB\u540D\uFF09",takesValue:true,placeholder:"<\u30D5\u30A1\u30A4\u30EB\u540D>"};var CONTENT_TYPE_FLAG={name:"--content-type",summary:"Content-Type\uFF08\u7701\u7565\u6642\u306F\u62E1\u5F35\u5B50\u304B\u3089\u63A8\u5B9A\u3002\u4E0D\u660E\u306A\u3089 application/octet-stream\uFF09",
28
+ takesValue:true,placeholder:"<\u578B>"};var OUT_FLAG={name:"--out",summary:"\u66F8\u304D\u51FA\u3057\u5148\u306E\u30D5\u30A1\u30A4\u30EB\u30D1\u30B9\uFF08\u5FC5\u9808\u3002\u6A19\u6E96\u51FA\u529B\u3078\u306F\u51FA\u3057\u307E\u305B\u3093\uFF09",takesValue:true,placeholder:"<\u30D1\u30B9>"};var ATTACHMENT_REF_FLAG={name:"--attachment",summary:"\u6DFB\u4ED8ID\u3002\u4F4D\u7F6E\u5F15\u6570\u3068\u540C\u3058\u610F\u5473\uFF08\u4E21\u65B9\u6307\u5B9A\u306F\u30A8\u30E9\u30FC\uFF09",takesValue:true,placeholder:"\
29
+ <\u6DFB\u4ED8ID>"};var FORCE_FLAG={name:"--force",summary:"\u66F8\u304D\u51FA\u3057\u5148\u304C\u65E2\u306B\u3042\u308C\u3070\u4E0A\u66F8\u304D\u3059\u308B\uFF08\u65E2\u5B9A\u3067\u306F\u4E0A\u66F8\u304D\u3057\u306A\u3044\uFF09",takesValue:false};function taskPath(input){const projectId=encodeURIComponent(requireResolved(input,"projectId"));return`/api/v2/projects/${projectId}/tasks/${encodeURIComponent(requireResolved(input,"taskId"))}`}function taskAttachmentIds(body){const task=isRecord(body)?
30
+ body["task"]:void 0;if(!isRecord(task)){throw new ApiResponseError("\u30BF\u30B9\u30AF\u8A73\u7D30\u306E\u5FDC\u7B54\u306B task \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}const ids=task["attachment_ids"];if(ids===null||ids===void 0)return[];if(!Array.isArray(ids)||!ids.every(id=>typeof id==="string")){throw new ApiResponseError("\u30BF\u30B9\u30AF\u8A73\u7D30\u306E attachment_ids \u304C\u6587\u5B57\u5217\u306E\u914D\u5217\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
31
+ return ids}function attachmentRows(body){const data=isRecord(body)?body["data"]:void 0;if(!Array.isArray(data)){throw new ApiResponseError("\u6DFB\u4ED8\u4E00\u89A7\u306E\u5FDC\u7B54\u306B data \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return data}async function resolveTask(input,ctx,usage){const ref=singleRef(input,{flag:"--task",label:"\u30BF\u30B9\u30AF",usage});return withResolved(input,await resolveTaskLocation(
32
+ input,ctx,ref))}function localFile(input){const raw=input.flags.get("--file");if(raw===void 0||raw.trim()===""){throw new UsageError("--file \u306F\u5FC5\u9808\u3067\u3059","twp task attachment upload <\u30AD\u30FC|ID> --file <\u30D1\u30B9>")}const file=path.resolve(raw.trim());let stat;try{stat=fs.statSync(file)}catch{throw new UsageError(`\u30D5\u30A1\u30A4\u30EB\u304C\u3042\u308A\u307E\u305B\u3093: ${file}`)}if(!stat.isFile())throw new UsageError(`\u901A\u5E38\u306E\u30D5\u30A1\u30A4\u30EB\u3067\u306F\u3042\u308A\u307E\u305B\u3093: ${file}`);
33
+ if(stat.size===0)throw new UsageError(`\u7A7A\u306E\u30D5\u30A1\u30A4\u30EB\u306F\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3067\u304D\u307E\u305B\u3093: ${file}`);const nameFlag=input.flags.get("--name");const name=nameFlag!==void 0&&nameFlag.trim()!==""?nameFlag.trim():path.basename(file);const typeFlag=input.flags.get("--content-type");const contentType=typeFlag!==void 0&&typeFlag.trim()!==""?typeFlag.trim():contentTypeFor(name);return{file,name,size:stat.size,contentType}}function uploadUrlPlan(input){
34
+ return{method:"POST",path:"/api/v2/attachments/upload-url",body:{file_name:requireResolved(input,"fileName"),content_type:requireResolved(input,"contentType"),file_size:Number(requireResolved(input,"fileSize")),source:TASK_SOURCE}}}function issued(body){const data=isRecord(body)?body["data"]:void 0;const id=isRecord(data)?data["id"]:void 0;const uploadUrl=isRecord(data)?data["upload_url"]:void 0;if(!isSafePathSegment(id)||typeof uploadUrl!=="string"||!/^https:\/\//.test(uploadUrl)){throw new ApiResponseError(
35
+ "\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9URL\u767A\u884C\u306E\u5FDC\u7B54\u306B data.id / data.upload_url \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return{id,uploadUrl}}async function upload(input,ctx){const file=requireResolved(input,"file");const size=Number(requireResolved(input,"fileSize"));const contentType=requireResolved(input,"contentType");await checkUploadQuota(ctx,size);const{id,uploadUrl}=issued(await ctx.send(
36
+ uploadUrlPlan(input)));const bytes=new Uint8Array(fs.readFileSync(file));if(bytes.byteLength!==size){throw new UsageError(`\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u4E2D\u306B\u30D5\u30A1\u30A4\u30EB\u306E\u5927\u304D\u3055\u304C\u5909\u308F\u308A\u307E\u3057\u305F\uFF08${size} \u2192 ${bytes.byteLength} \u30D0\u30A4\u30C8\uFF09: ${file}`)}await ctx.putSigned(uploadUrl,bytes,contentType);try{const current=taskAttachmentIds(await ctx.send({method:"GET",path:taskPath(input)}));const next=current.includes(
37
+ id)?current:[...current,id];const updated=await ctx.send({method:"PUT",path:taskPath(input),body:{attachment_ids:next}});const linked=taskAttachmentIds(updated);if(!linked.includes(id)){throw new ApiResponseError("\u30BF\u30B9\u30AF\u66F4\u65B0\u306E\u5FDC\u7B54\u306E attachment_ids \u306B\u4ECA\u56DE\u306E\u6DFB\u4ED8\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return{attachment_id:id,task_id:requireResolved(input,"ta\
38
+ skId"),project_id:requireResolved(input,"projectId"),file_name:requireResolved(input,"fileName"),content_type:contentType,file_size:size,attachment_count:linked.length}}catch(err){ctx.warn(`\u6DFB\u4ED8 ${id} \u306F\u30B9\u30C8\u30EC\u30FC\u30B8\u3078\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u307E\u3067\u5B8C\u4E86\u3057\u307E\u3057\u305F\u304C\u3001\u30BF\u30B9\u30AF\u3078\u306E\u7D10\u3065\u3051\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002
39
+ \u672A\u7D10\u3065\u3051\u306E\u6DFB\u4ED8\u306F\u30B5\u30FC\u30D0\u304C\u4E00\u5B9A\u6642\u9593\uFF08\u7F72\u540DURL\u306E\u6709\u52B9\u671F\u9650\uFF0B1\u6642\u9593\uFF09\u5F8C\u306B\u81EA\u52D5\u3067\u524A\u9664\u3057\u307E\u3059\u3002\u3082\u3046\u4E00\u5EA6 twp task attachment upload \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);throw err}}async function list(input,ctx){const ids=taskAttachmentIds(await ctx.send({method:"GET",path:taskPath(input)}));const rows=[];for(let offset=0;offset<
40
+ ids.length;offset+=IDS_PER_REQUEST){const chunk=ids.slice(offset,offset+IDS_PER_REQUEST);rows.push(...attachmentRows(await ctx.send({method:"GET",path:"/api/v2/attachments",query:{ids:chunk.join(",")}})))}if(rows.length<ids.length){ctx.warn(`\u30BF\u30B9\u30AF\u306B\u7D10\u3065\u304F\u6DFB\u4ED8 ${ids.length} \u4EF6\u306E\u3046\u3061 ${ids.length-rows.length} \u4EF6\u306F\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u524A\u9664\u6E08\u307F\u304B\u3001\u95B2\u89A7\u3067\u304D\u307E\u305B\u3093\uFF09\u3002`)}
41
+ return{data:rows}}var taskAttachmentResource={name:"attachment",summary:"\u30BF\u30B9\u30AF\u306E\u6DFB\u4ED8\u30D5\u30A1\u30A4\u30EB\uFF08\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u30FB\u4E00\u89A7\u30FB\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\uFF09",operations:[{name:"list",summary:"\u30BF\u30B9\u30AF\u306E\u6DFB\u4ED8\u30D5\u30A1\u30A4\u30EB\u3092\u4E00\u89A7\u3059\u308B",usage:"twp task attachment list <\u30AD\u30FC|ID> [--project <\u30B3\u30FC\u30C9|ID>]",description:`${TASK_REF_HELP}
42
+
43
+ \u30BF\u30B9\u30AF\u672C\u4F53\u306B\u7D10\u3065\u304F\u6DFB\u4ED8\u3060\u3051\u3092\u8FD4\u3057\u307E\u3059\uFF08\u30B3\u30E1\u30F3\u30C8\u306B\u4ED8\u3044\u305F\u6DFB\u4ED8\u306F\u542B\u307F\u307E\u305B\u3093\uFF09\u3002
44
+ \u30BF\u30B9\u30AF\u3092\u53D6\u5F97\u3057\u3066\u6DFB\u4ED8 ID \u3092\u5F97\u305F\u3042\u3068\u3001ID \u3067\u30E1\u30BF\u60C5\u5831\u3092\u53D6\u5F97\u3057\u307E\u3059\uFF082\u5F80\u5FA9\u4EE5\u4E0A\uFF09\u3002`,flags:[TASK_REF_FLAG,PROJECT_FLAG],prepare:(input,ctx)=>resolveTask(input,ctx,"twp task attachment list help"),plan:input=>({method:"GET",path:taskPath(input)}),plannedNotes:()=>["\u3053\u306E\u3042\u3068\u3001\u30BF\u30B9\u30AF\u306E attachment_ids \u3067 GET /api/v2/attachments?ids=\u2026 \u3092\u9001\u308A\u307E\u3059\u3002"],
45
+ execute:list,summarize:body=>attachmentRows(body).map(row=>pick(row,LIST_COLUMNS)),raw:body=>attachmentRows(body)},{name:"upload",summary:"\u30ED\u30FC\u30AB\u30EB\u30D5\u30A1\u30A4\u30EB\u3092\u30BF\u30B9\u30AF\u306B\u6DFB\u4ED8\u3059\u308B\uFF08\u767A\u884C\u30FB\u8EE2\u9001\u30FB\u7D10\u3065\u3051\u30921\u30B3\u30DE\u30F3\u30C9\u3067\uFF09",usage:"twp task attachment upload <\u30AD\u30FC|ID> --file <\u30D1\u30B9> [--name <\u30D5\u30A1\u30A4\u30EB\u540D>] [--content-type <\u578B>]",description:`${TASK_REF_HELP}\
46
+
47
+
48
+ \u5BB9\u91CF\u3092\u78BA\u304B\u3081\u3066\u304B\u3089\u3001\u6B21\u306E3\u5F80\u5FA9\u30921\u30B3\u30DE\u30F3\u30C9\u3067\u884C\u3044\u307E\u3059\u3002
49
+ 0. POST /api/v2/storage/check-upload\uFF08\u30C6\u30CA\u30F3\u30C8\u306E\u5BB9\u91CF\u691C\u67FB\u3002\u8D85\u904E\u306A\u3089\u4F55\u3082\u9001\u3089\u305A\u306B\u6B62\u307E\u308A\u307E\u3059\uFF09
50
+ 1. POST /api/v2/attachments/upload-url\uFF08\u7F72\u540DURL\u306E\u767A\u884C\uFF09
51
+ 2. \u7F72\u540DURL\u3078 PUT\uFF08\u30D5\u30A1\u30A4\u30EB\u672C\u4F53\u3002TWP \u306E\u8A8D\u8A3C\u60C5\u5831\u306F\u9001\u308A\u307E\u305B\u3093\uFF09
52
+ 3. \u30BF\u30B9\u30AF\u306E attachment_ids \u306B\u8FFD\u52A0\u3057\u3066 PUT\uFF08\u3053\u3053\u3067\u6DFB\u4ED8\u304C\u78BA\u5B9A\u3057\u307E\u3059\uFF09
53
+ 3 \u304C\u5931\u6557\u3057\u305F\u5834\u5408\u306F\u6DFB\u4ED8 ID \u3092 stderr \u306B\u51FA\u3057\u3066\u5931\u6557\u3057\u307E\u3059\u3002\u672A\u78BA\u5B9A\u306E\u6DFB\u4ED8\u306F\u30B5\u30FC\u30D0\u304C\u81EA\u52D5\u3067\u524A\u9664\u3057\u307E\u3059\u3002
54
+ --dry-run \u306F 1 \u306E\u30EA\u30AF\u30A8\u30B9\u30C8\u3060\u3051\u3092\u8868\u793A\u3057\u307E\u3059\uFF082 \u4EE5\u964D\u306F 1 \u306E\u5FDC\u7B54\u306B\u4F9D\u5B58\u3059\u308B\u305F\u3081\uFF09\u3002`,flags:[FILE_FLAG,NAME_FLAG,CONTENT_TYPE_FLAG,TASK_REF_FLAG,PROJECT_FLAG],async prepare(input,ctx){const local=localFile(input);const resolved=await resolveTask(input,ctx,"twp task attachment upload help");return withResolved(resolved,{file:local.file,fileName:local.name,fileSize:String(local.size),
55
+ contentType:local.contentType})},plan:uploadUrlPlan,plannedNotes:input=>[`\u5B9F\u884C\u6642\u306F\u3001\u3053\u306E\u524D\u306B\u5BB9\u91CF\u691C\u67FB\uFF08POST /api/v2/storage/check-upload\uFF09\u3092\u9001\u308A\u3001\u3053\u306E\u3042\u3068\u7F72\u540DURL\u3078 ${requireResolved(input,"fileSize")} \u30D0\u30A4\u30C8\u3092 PUT \u3057\u3001\u30BF\u30B9\u30AF\u306E attachment_ids \u306B\u8FFD\u52A0\u3057\u3066 PUT \u3057\u307E\u3059\u3002`],execute:upload,summarize:body=>pick(body,UPLOAD_COLUMNS),
56
+ raw:body=>body},{name:"download",summary:"\u6DFB\u4ED8\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u3057\u3066\u30D5\u30A1\u30A4\u30EB\u3078\u66F8\u304D\u51FA\u3059",usage:"twp task attachment download <\u6DFB\u4ED8ID> --out <\u30D1\u30B9> [--force]",description:"\u6DFB\u4ED8 ID \u306F twp task attachment list \u306E id \u3067\u3059\u3002\n\u66F8\u304D\u51FA\u3057\u5148\u306F --out \u3067\u5FC5\u305A\u6307\u5B9A\u3057\u307E\u3059\uFF08\u6A19\u6E96\u51FA\u529B\u3078\u306F\u51FA\u3057\u307E\u305B\u3093\uFF09\u3002\u65E2\u5B58\u30D5\u30A1\u30A4\u30EB\u306F --force \u304C\u7121\u3051\u308C\u3070\u4E0A\u66F8\u304D\u3057\u307E\u305B\u3093\u3002",
57
+ flags:[ATTACHMENT_REF_FLAG,OUT_FLAG,FORCE_FLAG],download:{outFlag:"--out",forceFlag:"--force"},plan(input){const id=singleRef(input,{flag:"--attachment",label:"\u6DFB\u4ED8ID",usage:"twp task attachment download help"});if(!isSafePathSegment(id))throw new UsageError(`\u6DFB\u4ED8ID \u306E\u5F62\u5F0F\u304C\u9055\u3044\u307E\u3059: ${id}`);return{method:"GET",path:`/api/v2/attachments/${encodeURIComponent(id)}/download`}},summarize:body=>body,raw:body=>body}]};export{classifyTaskRef,wantsPrivateSurface,taskSurface,resolveTaskLocation,rejectRedundantProject,TASK_REF_FLAG,PROJECT_FLAG,TASK_REF_HELP,contentTypeFor,taskAttachmentResource};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __twpCreateRequire } from 'node:module';
2
+ const require = __twpCreateRequire(import.meta.url);
3
+ import{UsageError}from"./chunk-7WSNIXTQ.js";var ISO_DATE_RE=/^\d{4}-\d{2}-\d{2}$/;function isoDate(input,flag){const raw=input.flags.get(flag);if(raw===void 0)return void 0;const value=raw.trim();if(!ISO_DATE_RE.test(value)){throw new UsageError(`${flag} \u306F YYYY-MM-DD \u306E\u5F62\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044: ${raw}`,"\u4F8B: 2026-09-30")}const[y,m,d]=value.split("-").map(Number);const probe=new Date(Date.UTC(y,m-1,d));if(probe.getUTCFullYear()!==y||probe.getUTCMonth()+1!==m||probe.getUTCDate()!==d){throw new UsageError(
4
+ `${flag} \u306B\u5B58\u5728\u3057\u306A\u3044\u65E5\u4ED8\u304C\u6307\u5B9A\u3055\u308C\u3066\u3044\u307E\u3059: ${raw}`,"\u4F8B: 2026-09-30")}return value}function booleanText(flag,raw){const value=raw.trim().toLowerCase();if(value==="true")return true;if(value==="false")return false;throw new UsageError(`${flag} \u306F true \u304B false \u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044: ${raw}`,`\u4F8B: ${flag} false`)}function priority(input,flag="--priority"){const raw=input.flags.get(flag);
5
+ if(raw===void 0)return void 0;const trimmed=raw.trim();const value=/^\d+$/.test(trimmed)?Number(trimmed):Number.NaN;if(!Number.isInteger(value)||value<1||value>3){throw new UsageError(`${flag} \u306F 1 / 2 / 3 \u306E\u3044\u305A\u308C\u304B\u3067\u3059: ${raw}`,"1: \u9AD8 \uFF0F 2: \u4E2D \uFF0F 3: \u4F4E")}return value}function decimal(input,flag,options){const raw=input.flags.get(flag);if(raw===void 0)return void 0;const trimmed=raw.trim();const value=/^\d+(\.\d+)?$/.test(trimmed)?Number(trimmed):
6
+ Number.NaN;if(!Number.isFinite(value)||value<options.min||value>options.max){throw new UsageError(`${flag} \u306F ${options.min} \u4EE5\u4E0A ${options.max} \u4EE5\u4E0B\u306E\u6570\u5024\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044: ${raw}`,"\u4F8B: 3 / 3.5")}return value}function boundedText(input,flag,options){const raw=input.flags.get(flag);if(raw===void 0)return void 0;if(raw.trim()===""){throw new UsageError(`${flag} \u306B\u7A7A\u306E\u5024\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,
7
+ `${options.label}\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}const count=[...raw].length;if(count>options.maxChars){throw new UsageError(`${options.label}\u304C\u9577\u3059\u304E\u307E\u3059\uFF08${count} \u6587\u5B57\u30FB\u4E0A\u9650 ${options.maxChars} \u6587\u5B57\uFF09`,`${flag} \u3092 ${options.maxChars} \u6587\u5B57\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}return raw}export{isoDate,booleanText,priority,decimal,boundedText};
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __twpCreateRequire } from 'node:module';
2
2
  const require = __twpCreateRequire(import.meta.url);
3
- import{PACKAGE_NAME,UPDATE_COMMAND,compareVersionCores,parseVersionCore}from"./chunk-DXXFUNYN.js";import{loadUserConfig}from"./chunk-NERYSBA4.js";import{isBoolishTrue}from"./chunk-5WGOHFAS.js";import{twpHomeDir}from"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{spawn}from"child_process";import fs from"fs";import path from"path";var CHECK_INTERVAL_MS=24*60*60*1e3;var DISABLE_ENV="TWP_NO_AUTO_UPDATE";var WORKER_ENV="TWP_AUTO_UPDATE_WORKER";var PARENT_PID_ENV="TWP_AUTO_UPDATE_PARENT_PID";function stateFilePath(env=process.env){return path.join(twpHomeDir(env),"update-state.json")}function lockFilePath(env=process.env){return path.join(twpHomeDir(env),"update.lock")}function runDirPath(env=process.env){return path.join(twpHomeDir(env),"run")}function registerRunning(env=process.env){try{const dir=runDirPath(env);fs.mkdirSync(
3
+ import{PACKAGE_NAME,UPDATE_COMMAND,compareVersionCores,parseVersionCore}from"./chunk-DXXFUNYN.js";import{isBoolishTrue}from"./chunk-5WGOHFAS.js";import{loadUserConfig}from"./chunk-NERYSBA4.js";import{twpHomeDir}from"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{spawn}from"child_process";import fs from"fs";import path from"path";var CHECK_INTERVAL_MS=24*60*60*1e3;var DISABLE_ENV="TWP_NO_AUTO_UPDATE";var WORKER_ENV="TWP_AUTO_UPDATE_WORKER";var PARENT_PID_ENV="TWP_AUTO_UPDATE_PARENT_PID";function stateFilePath(env=process.env){return path.join(twpHomeDir(env),"update-state.json")}function lockFilePath(env=process.env){return path.join(twpHomeDir(env),"update.lock")}function runDirPath(env=process.env){return path.join(twpHomeDir(env),"run")}function registerRunning(env=process.env){try{const dir=runDirPath(env);fs.mkdirSync(
4
4
  dir,{recursive:true,mode:448});const file=path.join(dir,String(process.pid));fs.writeFileSync(file,"",{mode:384});process.once("exit",()=>{try{fs.rmSync(file,{force:true})}catch{}})}catch{}}function listRegisteredPids(env=process.env){try{return fs.readdirSync(runDirPath(env)).filter(name=>/^\d+$/.test(name)).map(Number)}catch{return[]}}function readUpdateState(env=process.env){try{const parsed=JSON.parse(fs.readFileSync(stateFilePath(env),"utf8"));return parsed!==null&&typeof parsed==="object"&&
5
5
  !Array.isArray(parsed)?parsed:{}}catch{return{}}}function writeUpdateState(state,env=process.env){const file=stateFilePath(env);const tmp=`${file}.${process.pid}.tmp`;try{fs.mkdirSync(path.dirname(file),{recursive:true,mode:448});fs.rmSync(tmp,{force:true});fs.writeFileSync(tmp,`${JSON.stringify(state,null,2)}
6
6
  `,{mode:384,flag:"wx"});fs.renameSync(tmp,file)}catch{try{fs.rmSync(tmp,{force:true})}catch{}}}function autoUpdateDisabledReason(env=process.env){if(isBoolishTrue(env[DISABLE_ENV]))return`${DISABLE_ENV} \u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u307E\u3059`;if(isBoolishTrue(env["CI"]))return"CI \u74B0\u5883\uFF08CI \u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u307E\u3059\uFF09";if(process.getuid?.()===0&&(env["SUDO_UID"]??"")!=="")return"sudo \u3067\u5B9F\u884C\u3055\u308C\u3066\u3044\u307E\u3059";