@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.
- package/CHANGELOG.public.md +6 -0
- package/README.md +147 -6
- package/command-model/department.json +1 -1
- package/dist/{ai-dispatch-VSCKUY6J.js → ai-dispatch-36HRDRLF.js} +1 -1
- package/dist/{api-command-Q2CSB4PV.js → api-command-NMYYJKZH.js} +5 -17
- package/dist/{app-THTQX3A5.js → app-2KMY3QPM.js} +27 -26
- package/dist/{auto-update-FBZGOQFI.js → auto-update-CV2MM32C.js} +1 -1
- package/dist/{auto-update-worker-Z3XKBFMQ.js → auto-update-worker-AXBJIMFP.js} +2 -2
- package/dist/{backlog-X2MQTA6F.js → backlog-7MJIOT22.js} +2 -2
- package/dist/{charter-command-UPKTVL7H.js → charter-command-UBUE3KUO.js} +2 -2
- package/dist/{chunk-5ISIXBKD.js → chunk-4V4T5ZUS.js} +45 -18
- package/dist/chunk-5Q2CH4E7.js +3 -0
- package/dist/chunk-6NCY4NPV.js +62 -0
- package/dist/{chunk-M3GWY6NT.js → chunk-7WSNIXTQ.js} +2 -1
- package/dist/chunk-DDKZ5IPT.js +11 -0
- package/dist/{chunk-2VISRLWS.js → chunk-DMDVLOAY.js} +8 -8
- package/dist/chunk-EJ474UDB.js +3 -0
- package/dist/chunk-FTYJZFEK.js +10 -0
- package/dist/{chunk-E4H22AO5.js → chunk-GDM2QUBL.js} +1 -1
- package/dist/{chunk-X4RS5VBH.js → chunk-GMBJTG6A.js} +1 -1
- package/dist/{chunk-QVXZEUKN.js → chunk-HGTG5XQ7.js} +1 -1
- package/dist/{chunk-I2QFW7EK.js → chunk-HW3QGKYR.js} +1 -1
- package/dist/chunk-I3YPO7CY.js +57 -0
- package/dist/chunk-IJLJGDMZ.js +7 -0
- package/dist/{chunk-DSDVIU6A.js → chunk-ILKQDXI5.js} +1 -1
- package/dist/{chunk-O52CUEDO.js → chunk-IOGVQVGD.js} +1 -1
- package/dist/chunk-NAUH75MM.js +10 -0
- package/dist/chunk-NZ7WI4RZ.js +18 -0
- package/dist/{chunk-JB27KNCX.js → chunk-QOUFHYK5.js} +29 -25
- package/dist/{chunk-XLE4HW6B.js → chunk-UIWGEBWI.js} +1 -1
- package/dist/{chunk-JDMNIUVX.js → chunk-VCMVTC6B.js} +1 -1
- package/dist/chunk-WGVHYTZV.js +38 -0
- package/dist/{chunk-PI5DUWNZ.js → chunk-WOUKWOAR.js} +1 -1
- package/dist/{chunk-3XG457E3.js → chunk-YVAN3H5W.js} +5 -5
- package/dist/chunk-ZN5EFDH7.js +5 -0
- package/dist/chunk-ZWVYVS2A.js +4 -0
- package/dist/cli.js +78 -11
- package/dist/{commands-ET4F34OD.js → commands-6YTOVZ5P.js} +16 -16
- package/dist/{commands-NXBQ5OWL.js → commands-U36UTCKR.js} +8 -8
- package/dist/department-JOXXJKQB.js +33 -0
- package/dist/job-title-L47J6TZY.js +8 -0
- package/dist/{logout-guard-CMZZBRUL.js → logout-guard-FO7KZL3X.js} +1 -1
- package/dist/media-ZMDYHHNN.js +64 -0
- package/dist/{oneshot-QVFA2SUM.js → oneshot-KYATQPL7.js} +5 -5
- package/dist/position-FHWCMMBQ.js +8 -0
- package/dist/{project-2LJZW747.js → project-ZODASYER.js} +1 -1
- package/dist/query-EEALMOSO.js +3 -0
- package/dist/render-K45EOLHX.js +3 -0
- package/dist/run-QCDT35NT.js +4 -0
- package/dist/server-settings-CG3EM7R7.js +1 -1
- package/dist/{setup-UI6V2Q3V.js → setup-6CXUVCF5.js} +1 -1
- package/dist/storage-ANKKJJJO.js +3 -0
- package/dist/{task-GKNM3G4K.js → task-G5YWQ6L5.js} +7 -63
- package/dist/{update-3QHRK5BP.js → update-PZBUIYOL.js} +1 -1
- package/dist/user-DO4VNIBR.js +204 -0
- package/package.json +1 -1
- package/dist/chunk-BOBSH3QN.js +0 -9
- package/dist/chunk-GFC2ASHE.js +0 -6
- package/dist/chunk-JKSXUBND.js +0 -9
- package/dist/chunk-PEGUHUTD.js +0 -3
- package/dist/chunk-RKJ6B2KL.js +0 -56
- package/dist/query-NJMVSQR6.js +0 -3
- package/dist/render-XMVI3AKB.js +0 -3
- package/dist/run-IS46BQBB.js +0 -4
- package/dist/user-EU7Z3DAO.js +0 -24
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{
|
|
4
|
-
isPermanent,pick,pickString}from"./chunk-ODLJ2LNQ.js";import{
|
|
5
|
-
|
|
6
|
-
import
|
|
3
|
+
import{REQUIRE_ZERO_STATUS,ScheduleApi,collectDue,gateStatus,nowInZone,parseCounts,promptSection}from"./chunk-UG2I6VRD.js";import{InstanceLock,buildLockOwner,defaultIsLoopProcess,writeLockOwner}from"./chunk-3WHC4FSG.js";import{CapacityReporter,buildLoopConfig,describeOperations,evaluateOwnership,formatHookIds,formatHookWiring,localDate,loopStateDir,runPrefetch,runPreflight}from"./chunk-UIWGEBWI.js";import{LoopSettingsApplier,renderStepBudget}from"./chunk-Y2QAP6SU.js";import{
|
|
4
|
+
AgentLoopApi,describeError,filterByStatus,isPermanent,pick,pickString}from"./chunk-ODLJ2LNQ.js";import{EngineNotConfiguredError,NoopEngine,UnknownEngineError,aiUnavailableLabel,assertKnownEngine,failureHint,isAiUnavailable,needsHumanToRestoreAi}from"./chunk-ZOOEH7ZE.js";import{claudeConfigDir,resolveDetectDeps}from"./chunk-24ZZFFA3.js";import{killProcessTree}from"./chunk-N2UVRM3Z.js";import{exclusiveInflightEntries,formatExclusiveEntry,normalizeSkillName,skillOfItem,spawnSyncResolved}from"./chunk-TYNCXQSN.js";
|
|
5
|
+
import{PRIVATE_PROJECT_REF,isPrivateProjectId,isPrivateProjectRef,privateProjectId,projectFileKey}from"./chunk-GY7KI5E5.js";import{extractLeadingTaskKey,isTaskKey}from"./chunk-II5RVJQN.js";import{resolveProjectRef,uuidProjectIdPolicy}from"./chunk-GMBJTG6A.js";import{AuthSession}from"./chunk-XNLIEUAW.js";import{joinFor}from"./chunk-PMOUHEJQ.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{compareVersionCores,parseVersionCore}from"./chunk-DXXFUNYN.js";
|
|
6
|
+
import"./chunk-5WGOHFAS.js";import{effectiveApiUrl,resolveProfile}from"./chunk-NERYSBA4.js";import{twpHomeDir}from"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";import fs10 from"fs";import path8 from"path";import fs from"fs";import path from"path";var LoopLogger=class{constructor(runnerId,logFile,out=process.stdout,now=()=>new Date){this.runnerId=runnerId;this.out=out;this.now=now;if(logFile){fs.mkdirSync(path.dirname(logFile),{recursive:true});this.stream=fs.createWriteStream(logFile,{flags:"a"})}}runnerId;out;now;stream=null;log(message){const d=this.now();const ts=`${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;const line=`[${ts}] [${this.runnerId}] ${stripTerminalControls(
|
|
7
7
|
message)}
|
|
8
8
|
`;this.out.write(line);this.stream?.write(line)}separator(){this.log("=".repeat(60))}close(){this.stream?.end();this.stream=null}};function pad(n){return String(n).padStart(2,"0")}function rotateLogs(dir,retentionDays,now=Date.now()){if(retentionDays<=0)return;const cutoff=now-retentionDays*864e5;let entries;try{entries=fs.readdirSync(dir)}catch{return}for(const name of entries){if(!/^(agent-loop|task-loop|step|plan|schedule-enqueued)-.*\.(log|txt)$/.test(name))continue;const file=path.join(dir,
|
|
9
9
|
name);try{if(fs.statSync(file).mtimeMs<cutoff)fs.rmSync(file,{force:true})}catch{}}}import fs7 from"fs";import path5 from"path";import{spawnSync}from"child_process";import fs2 from"fs";import path2 from"path";var GIT_IDENTITY_ENV_KEYS=["GIT_AUTHOR_NAME","GIT_AUTHOR_EMAIL","GIT_COMMITTER_NAME","GIT_COMMITTER_EMAIL"];function resolveDeps(deps){return{run:deps.run??spawnSync,readdirSync:deps.readdirSync??(dir=>fs2.readdirSync(dir,{withFileTypes:true})),existsSync:deps.existsSync??fs2.existsSync,env:deps.env??process.env}}function expectedIdentity(configured,env=process.env){const pick2=(envKey,fromConfig)=>{const fromEnv=(env[envKey]??"").trim();if(fromEnv!=="")return fromEnv;return(fromConfig??"").trim()};
|
|
@@ -84,10 +84,10 @@ ${it.task_key??""}`))}function localTimestamp(at=new Date){const p2=n=>String(n)
|
|
|
84
84
|
const clean=reason.replace(/[\t\n]/g," ").slice(0,200);const line=`${localTimestamp()} ${result} ${phase||"unknown"} ${ai||"unknown"} ${clean}
|
|
85
85
|
`;try{fs4.mkdirSync(path3.dirname(this.file),{recursive:true});fs4.appendFileSync(this.file,line)}catch{return}if(result!=="NOT_EXECUTED")return;const streak=this.notExecutedStreak();if(streak>=3){this.log.log(` \u26A0\uFE0F \u30EA\u30EA\u30FC\u30B9\u304C ${streak} \u56DE\u9023\u7D9A\u3067\u672A\u5B9F\u884C\u3067\u3059\uFF08${this.file}\uFF09\u3002\u6B21\u30B5\u30A4\u30AF\u30EB\u3067\u30D6\u30ED\u30C3\u30AB\u30FC\u89E3\u6D88\u3092\u6700\u512A\u5148\u3059\u308B\u3053\u3068`)}}notExecutedStreak(){
|
|
86
86
|
let text;try{text=fs4.readFileSync(this.file,"utf8")}catch{return 0}let n=0;for(const line of text.split("\n")){if(line.trim()==="")continue;n=line.split(" ")[1]==="NOT_EXECUTED"?n+1:0}return n}};function parseReleaseResult(logText){const matches=[...logText.matchAll(/RELEASE_RESULT:[^|\n]*\|[^|\n]*\|[^\n]*/g)];const line=matches.at(-1)?.[0];if(!line)return null;const parts=line.split("|").map(s=>s.trim());return{executed:!/NOT_EXECUTED/.test(parts[0]??""),phase:parts[1]??"",reason:parts[2]??"",
|
|
87
|
-
line}}function parseOutcomeCode(logText){const matches=[...logText.matchAll(/\b([A-Z][A-Z0-9_]*_RESULT):[ \t]*([^|\n]*)/g)];const last=matches.at(-1);if(last===void 0)return null;const value=(last[2]??"").trim();return value===""?null:`${last[1]??""}: ${value}`}var RECOVER_KEY_RE=/RECOVER:[ \t]*([^\s|、,,]+-\d+)/;function parseRecoverKey(line){const
|
|
88
|
-
null}function parsePhase5Pending(line){const m=/PHASE5_PENDING:\s*(\d+)/.exec(line);return m?.[1]??null}function parseMergedKeys(logText){const matches=[...logText.matchAll(/MERGED_KEYS:[ \t]*([A-Za-z0-9,_-]*)/g)];const raw=matches.at(-1)?.[1];if(raw===void 0)return null;const trimmed=raw.trim();if(trimmed===""||trimmed==="none")return[];
|
|
89
|
-
var STATUS_HUMAN_DECISION="35e2d271-8a6e-4f3f-8bb6-1588a2d5a894";async function enqueueBlockerRecovery(deps,releaseLine){const{api,config,log}=deps;const key=parseRecoverKey(releaseLine);if(!key)return;const queued=await api.queuedSnapshot();if(queued===null){log.log(" \u26A0\uFE0F \u30AD\u30E5\u30FC\u306E\u4E00\u89A7\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F \u2192 \u30D6\u30ED\u30C3\u30AB\u30FC\u4FEE\u6B63\u306E\u6295\u5165\u3092\u898B\u9001\u308A\u307E\u3059");
|
|
90
|
-
" \uFF08\u65E2\u306B\u30AD\u30E5\u30FC\u306B\u5C45\u308B\u304B\u5224\u5B9A\u3067\u304D\u306A\u3044\u72B6\u614B\u3067\u6295\u5165\u3059\u308B\u3068\u3001\u4E0A\u9650\u67A0\u3092\u6D88\u8CBB\u3057\u3066\u91CD\u8907\u30A2\u30A4\u30C6\u30E0\u3092\u4F5C\u308A\u307E\u3059\uFF09");return}if(queueContainsKey(queued,key)){log.log(` \u23ED ${key} \u306E\u30A2\u30A4\u30C6\u30E0\u306F\u65E2\u306B\u30AD\u30E5\u30FC\u306B\u3042\u308A\u307E\u3059 \u2192 \u30D6\u30ED\u30C3\u30AB\u30FC\u4FEE\u6B63\u306E\u6295\u5165\u3092\u30B9\u30AD\u30C3\u30D7`);
|
|
87
|
+
line}}function parseOutcomeCode(logText){const matches=[...logText.matchAll(/\b([A-Z][A-Z0-9_]*_RESULT):[ \t]*([^|\n]*)/g)];const last=matches.at(-1);if(last===void 0)return null;const value=(last[2]??"").trim();return value===""?null:`${last[1]??""}: ${value}`}var RECOVER_KEY_RE=/RECOVER:[ \t]*([^\s|、,,]+-\d+)/;function parseRecoverKey(line){const raw=RECOVER_KEY_RE.exec(line)?.[1];if(raw===void 0)return null;if(!raw.includes("%"))return raw;try{const key=decodeURIComponent(raw);return isTaskKey(
|
|
88
|
+
key)&&key.trim()===key?key:null}catch{return null}}function parsePartialMergeCause(line){const m=/PARTIAL_MERGE:\s*([A-Za-z0-9_.:-]+)/.exec(line);return m?.[1]??null}function parsePhase5Pending(line){const m=/PHASE5_PENDING:\s*(\d+)/.exec(line);return m?.[1]??null}function parseMergedKeys(logText){const matches=[...logText.matchAll(/MERGED_KEYS:[ \t]*([A-Za-z0-9,_-]*)/g)];const raw=matches.at(-1)?.[1];if(raw===void 0)return null;const trimmed=raw.trim();if(trimmed===""||trimmed==="none")return[];
|
|
89
|
+
return trimmed.split(",").filter(k=>k!=="")}var PHASE5_RECOVERY_MAX=2;var PARTIAL_MERGE_ESCALATION_MAX=1;var TANI_USER_ID="2f391dda-f0e3-42f8-a9fd-8ffc271be765";var STATUS_HUMAN_DECISION="35e2d271-8a6e-4f3f-8bb6-1588a2d5a894";async function enqueueBlockerRecovery(deps,releaseLine){const{api,config,log}=deps;const key=parseRecoverKey(releaseLine);if(!key)return;const queued=await api.queuedSnapshot();if(queued===null){log.log(" \u26A0\uFE0F \u30AD\u30E5\u30FC\u306E\u4E00\u89A7\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F \u2192 \u30D6\u30ED\u30C3\u30AB\u30FC\u4FEE\u6B63\u306E\u6295\u5165\u3092\u898B\u9001\u308A\u307E\u3059");
|
|
90
|
+
log.log(" \uFF08\u65E2\u306B\u30AD\u30E5\u30FC\u306B\u5C45\u308B\u304B\u5224\u5B9A\u3067\u304D\u306A\u3044\u72B6\u614B\u3067\u6295\u5165\u3059\u308B\u3068\u3001\u4E0A\u9650\u67A0\u3092\u6D88\u8CBB\u3057\u3066\u91CD\u8907\u30A2\u30A4\u30C6\u30E0\u3092\u4F5C\u308A\u307E\u3059\uFF09");return}if(queueContainsKey(queued,key)){log.log(` \u23ED ${key} \u306E\u30A2\u30A4\u30C6\u30E0\u306F\u65E2\u306B\u30AD\u30E5\u30FC\u306B\u3042\u308A\u307E\u3059 \u2192 \u30D6\u30ED\u30C3\u30AB\u30FC\u4FEE\u6B63\u306E\u6295\u5165\u3092\u30B9\u30AD\u30C3\u30D7`);
|
|
91
91
|
return}const today=localDate(config.counterTimezone);const res=await api.consumeCounter(`blocker_recovery.${key}`,today,config.blockerRecoveryMaxPerDay);if(!res.ok){if(res.status!==null&&res.status>=400&&res.status<500){log.log(` \u26D4 ${key} \u306E\u30D6\u30ED\u30C3\u30AB\u30FC\u4FEE\u6B63\u306E\u6295\u5165\u4E0A\u9650\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\uFF08${describeError(res)}\uFF09\u3002**\u518D\u8A66\u884C\u3067\u306F\u89E3\u6D88\u3057\u307E\u305B\u3093**`);log.log(` \u78BA\u8A8D:\
|
|
92
92
|
\u30BF\u30A4\u30E0\u30BE\u30FC\u30F3\uFF08\u73FE\u5728 ${config.counterTimezone}\u30FB\u9001\u4FE1\u3057\u305F\u65E5\u4ED8 ${today}\uFF09\uFF0F\u4E0A\u9650\uFF08\u73FE\u5728 ${config.blockerRecoveryMaxPerDay}\uFF09`)}else{log.log(` \u26D4 ${key} \u306E\u30D6\u30ED\u30C3\u30AB\u30FC\u4FEE\u6B63\u306E\u6295\u5165\u4E0A\u9650\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${describeError(res)}\uFF09\u2192 \u4ECA\u56DE\u306F\u6295\u5165\u3057\u307E\u305B\u3093\uFF08\u6B21\u30B5\u30A4\u30AF\u30EB\u3067\u518D\u5224\u5B9A\uFF09`)}
|
|
93
93
|
return}const granted=pickString(res.json,"granted");const count=pickString(res.json,"counter.count");if(granted===""){log.log(` \u26D4 ${key} \u306E\u6295\u5165\u4E0A\u9650\u306E\u5FDC\u7B54\u3092\u89E3\u91C8\u3067\u304D\u307E\u305B\u3093\uFF08granted \u304C\u8AAD\u3081\u307E\u305B\u3093\uFF09\u2192 \u4ECA\u56DE\u306F\u6295\u5165\u3057\u307E\u305B\u3093\u3002\u5FDC\u7B54\u306E\u5148\u982D: ${res.raw.slice(0,120)}`);return}if(granted!=="true"){log.log(` \u23ED ${key} \u306E\u30D6\u30ED\u30C3\u30AB\u30FC\u4FEE\u6B63\u306F\u672C\u65E5 ${count||
|
|
@@ -139,11 +139,11 @@ continue}const{itemId,detail}=await createItem(api,{label:`[P1] ${key} \u306Edev
|
|
|
139
139
|
explicit);return skillOfItem(item)}function advanceKey(taskKey,skill){return`${taskKey}#${normalizeSkillName(skill)}`}function buildRecentCandidateIndex(items,opts={}){const nowMicros=(opts.now??new Date).getTime()*1e3;const latest=new Map;for(const item of items){if(item.status!==void 0&&item.status!=="completed")continue;const taskKey=(item.task_key??"").trim();if(taskKey==="")continue;const skill=skillOfLedgerItem(item);if(skill==="")continue;const sortOrder=typeof item.sort_order==="number"?
|
|
140
140
|
item.sort_order:0;const key=advanceKey(taskKey,skill);const prev=latest.get(key);if(prev&&prev.sortOrder>=sortOrder)continue;latest.set(key,{sortOrder,candidate:{taskKey,skill,itemId:item.item_id,outcomeCode:normalizeOutcomeCode(item.outcome_code),ageMinutes:sortOrder>0?Math.floor((nowMicros-sortOrder)/6e7):null}})}const index=new Map;for(const[key,value]of latest)index.set(key,value.candidate);return index}function findRecentCandidate(index,taskKey,skill){if(taskKey.trim()===""||skill.trim()===
|
|
141
141
|
"")return null;return index.get(advanceKey(taskKey.trim(),skill))??null}async function resolveRecentAdvance(candidate,fetchResult){let outcome=candidate.outcomeCode;if(outcome===null){const result=await fetchResult(candidate.itemId);outcome=result?normalizeOutcomeCode(parseOutcomeCode(result)):null}if(outcome===null||!ADVANCING.has(outcome))return null;return{taskKey:candidate.taskKey,skill:candidate.skill,outcome,itemId:candidate.itemId,ageMinutes:candidate.ageMinutes}}function formatRecentAdvance(advance){
|
|
142
|
-
const age=advance.ageMinutes===null?"\u4E0D\u660E":`${advance.ageMinutes}\u5206\u524D`;return`${advance.outcome}\uFF08${age} / item=${advance.itemId}\uFF09`}function windowStartMicros(now,hours=RECENT_ADVANCE_WINDOW_HOURS){return Math.trunc((now.getTime()-hours*36e5)*1e3)}var EXPECTED_STATUS_AFTER={"DEV_VERIFY_RESULT: VERIFIED":"relwait","DEVELOP_MERGE_RESULT: MERGED":"verify","REVIEW_RESULT: APPROVED":"mergewait","RELEASE_RESULT: EXECUTED":"processed"};var MARKER_PAIR_RE
|
|
143
|
-
|
|
144
|
-
if(snapshot===null){return{suppress:false,reason:"\u30B9\u30C6\u30FC\u30BF\u30B9\u306E\u30DE\u30FC\u30AB\u30FC\uFF08OPS_TASK_STATUS\uFF09\u304C prefetch \u306B\u7121\u3044"}}if(!snapshot.complete){return{suppress:false,reason:"\u30B9\u30C6\u30FC\u30BF\u30B9\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u305F\u3082\u306E\u304C\u3042\u308B\uFF08complete=0\uFF09"}}
|
|
145
|
-
h\uFF09\u304C\u6291\u6B62\u306E\u7A93\uFF08${RECENT_ADVANCE_WINDOW_HOURS}h\uFF09\u3088\u308A\u72ED\u3044`}}const expected=EXPECTED_STATUS_AFTER[advance.outcome];if(expected===void 0){return{suppress:false,reason:`${advance.outcome} \u306E\u60F3\u5B9A\u30B9\u30C6\u30FC\u30BF\u30B9\u304C\u5BFE\u5FDC\u8868\u306B\u7121\u3044`}}const current=snapshot.byKey.
|
|
146
|
-
|
|
142
|
+
const age=advance.ageMinutes===null?"\u4E0D\u660E":`${advance.ageMinutes}\u5206\u524D`;return`${advance.outcome}\uFF08${age} / item=${advance.itemId}\uFF09`}function windowStartMicros(now,hours=RECENT_ADVANCE_WINDOW_HOURS){return Math.trunc((now.getTime()-hours*36e5)*1e3)}var EXPECTED_STATUS_AFTER={"DEV_VERIFY_RESULT: VERIFIED":"relwait","DEVELOP_MERGE_RESULT: MERGED":"verify","REVIEW_RESULT: APPROVED":"mergewait","RELEASE_RESULT: EXECUTED":"processed"};var MARKER_PAIR_RE=/^([^=\s,]+)=([a-z]+)$/;
|
|
143
|
+
function decodeMarkerKey(raw){let key;try{key=decodeURIComponent(raw)}catch{return null}return isTaskKey(key)&&key.trim()===key?key:null}function parseTaskStatusSnapshot(prefetchSection){const m=/<!--\s*OPS_TASK_STATUS\s([^>]*?)-->/.exec(prefetchSection);if(!m||m[1]===void 0)return null;const body=m[1];const windowMatch=/\bwindow_hours=(\d+)\b/.exec(body);const byKey=new Map;for(const token of body.trim().split(/\s+/)){for(const part of token.split(",")){const pair=MARKER_PAIR_RE.exec(part);if(!pair)
|
|
144
|
+
continue;const key=decodeMarkerKey(pair[1]);if(key!==null)byKey.set(key,pair[2])}}return{complete:/\bcomplete=1\b/.test(body),windowHours:windowMatch?Number(windowMatch[1]):0,byKey}}function shouldSuppressForStatus(advance,snapshot){if(snapshot===null){return{suppress:false,reason:"\u30B9\u30C6\u30FC\u30BF\u30B9\u306E\u30DE\u30FC\u30AB\u30FC\uFF08OPS_TASK_STATUS\uFF09\u304C prefetch \u306B\u7121\u3044"}}if(!snapshot.complete){return{suppress:false,reason:"\u30B9\u30C6\u30FC\u30BF\u30B9\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u305F\u3082\u306E\u304C\u3042\u308B\uFF08complete=0\uFF09"}}
|
|
145
|
+
if(snapshot.windowHours<RECENT_ADVANCE_WINDOW_HOURS){return{suppress:false,reason:`\u30DE\u30FC\u30AB\u30FC\u306E\u7A93\uFF08${snapshot.windowHours}h\uFF09\u304C\u6291\u6B62\u306E\u7A93\uFF08${RECENT_ADVANCE_WINDOW_HOURS}h\uFF09\u3088\u308A\u72ED\u3044`}}const expected=EXPECTED_STATUS_AFTER[advance.outcome];if(expected===void 0){return{suppress:false,reason:`${advance.outcome} \u306E\u60F3\u5B9A\u30B9\u30C6\u30FC\u30BF\u30B9\u304C\u5BFE\u5FDC\u8868\u306B\u7121\u3044`}}const current=snapshot.byKey.
|
|
146
|
+
get(advance.taskKey);if(current===void 0){return{suppress:true,reason:""}}if(current===expected)return{suppress:true,reason:""};return{suppress:false,reason:`\u524D\u56DE\u306E\u5B9F\u884C\u306E\u5F8C\u306B\u30BF\u30B9\u30AF\u304C\u52D5\u3044\u305F\uFF08${expected} \u2192 ${current}\uFF09\uFF1D\u65B0\u3057\u3044\u4ED5\u4E8B`}}var USER_ID_RE=/^[A-Za-z0-9._-]{1,64}$/;var ProjectApi=class{constructor(apiUrl,session,fetchImpl=httpFetch){this.apiUrl=apiUrl;this.session=session;this.fetchImpl=fetchImpl}apiUrl;session;fetchImpl;async resolve(ref){if(isPrivateProjectRef(ref))return this.resolvePrivate();return resolveProjectRef(ref,path9=>this.get(path9),uuidProjectIdPolicy)}async resolvePrivate(){const res=await this.get("/api/v2/user");if(!res.ok){throw new Error(`\u30ED\u30B0\u30A4\u30F3\u4E2D\u306E\u30E6\u30FC\u30B6\u30FC\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08HTTP ${res.
|
|
147
147
|
status}\uFF09\u3002\u500B\u4EBA\u30AD\u30E5\u30FC\u3092\u56DE\u3059\u306B\u306F \`twp login\` \u304C\u5FC5\u8981\u3067\u3059\u3002\u63A5\u7D9A\u5148\u3068\u30ED\u30B0\u30A4\u30F3\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}const userId=res.json?.user?.id;if(typeof userId!=="string"||!USER_ID_RE.test(userId)){throw new Error(`\u30B5\u30FC\u30D0\u304C\u8FD4\u3057\u305F\u30E6\u30FC\u30B6\u30FCID\u3092\u500B\u4EBA\u30AD\u30E5\u30FC\u306EID\u306B\u4F7F\u3048\u307E\u305B\u3093\uFF08${String(
|
|
148
148
|
userId).slice(0,60)}\uFF09\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}return{id:privateProjectId(userId),code:PRIVATE_PROJECT_REF,name:"\u500B\u4EBA\u30BF\u30B9\u30AF"}}async countByStatus(projectId,statusId){const res=await this.get(`/api/v2/projects/${projectId}/tasks?status_id=${encodeURIComponent(statusId)}&limit=1`);if(!res.ok){return{total:null,error:res.status===null?res.error??"\u901A\u4FE1\u5931\u6557":`HTTP ${res.status}`}}const total=res.json?.
|
|
149
149
|
pagination?.total;if(typeof total!=="number"){return{total:null,error:"\u5FDC\u7B54\u304B\u3089 pagination.total \u3092\u8AAD\u3081\u306A\u3044"}}return{total,error:null}}async get(path9){let token;try{token=await this.session.getAccessToken()}catch(err){return{ok:false,status:null,json:null,error:err.message}}try{const res=await this.fetchImpl(`${this.apiUrl}${path9}`,{headers:{Authorization:`Bearer ${token}`,"Content-Type":"application/json",Accept:"application/json"}});const raw=await res.text();
|
|
@@ -313,14 +313,14 @@ const startedAtMs=now();let warned="";let done=false;const check=()=>{if(done)re
|
|
|
313
313
|
decision.key)return;warned=decision.key;handlers.onWarn(decision.reason);return}done=true;const recorded=writeRestartAttempt(opts.stateDir,opts.projectKey,{from:decision.from,to:decision.to,at:new Date(now()).toISOString()},opts.store);if(!recorded){handlers.onWarn(`\u518D\u8D77\u52D5\u8A18\u9332\u3092\u66F8\u3051\u307E\u305B\u3093\u3067\u3057\u305F\uFF08${restartAttemptPath(opts.stateDir,opts.projectKey)}\uFF09\u3002\u540C\u3058\u7248\u30C9\u30EA\u30D5\u30C8\u304C\u89E3\u6D88\u3057\u306A\u3044\u5834\u5408\u3001\u518D\u8D77\u52D5\u3092\u7E70\u308A\u8FD4\u3059\u9632\u6CE2\u5824\u304C\u52B9\u304D\u307E\u305B\u3093`)}
|
|
314
314
|
handlers.onRestart({from:decision.from,to:decision.to})};const timer=setInterval(check,opts.intervalMs??DRIFT_POLL_MS);timer.unref?.();return{stop:()=>{done=true;clearInterval(timer)},check}}import fs9 from"fs";import path7 from"path";var POLL_MS=1e3;var MAX_STOP_BYTES=4096;var MAX_AT_LENGTH=64;function markerPath(lockDir2,kind){return path7.join(lockDir2,kind)}function requestMarker(lockDir2,kind,pid,deps={}){const target=markerPath(lockDir2,kind);const write=deps.writeFileSync??((p,d)=>fs9.writeFileSync(p,d,{flag:"wx",mode:384}));const now=deps.now??(()=>new Date);clearMarker(lockDir2,kind,deps);try{write(target,`${JSON.stringify({pid,at:now().toISOString()})}
|
|
315
315
|
`);return{ok:true}}catch(err){const e=err;return{ok:false,reason:e.code??"UNKNOWN"}}}function readMarker(lockDir2,kind,deps={}){const target=markerPath(lockDir2,kind);const read=deps.readFileSync??(p=>fs9.readFileSync(p,"utf8"));const size=deps.statSize??(p=>fs9.statSync(p).size);let raw;try{if(size(target)>MAX_STOP_BYTES)return null;raw=read(target)}catch{return null}if(raw.length>MAX_STOP_BYTES)return null;try{const parsed=JSON.parse(raw);if(typeof parsed!=="object"||parsed===null)return null;const pid=parsed.pid;const at=parsed.at;if(typeof pid!=="number"||!Number.isInteger(pid)||
|
|
316
|
-
pid<=0)return null;return{pid,at:sanitizeAt(at)}}catch{return null}}function sanitizeAt(at){if(typeof at!=="string")return"";return at.replace(/[\u0000-\u001f\u007f]/g," ").slice(0,MAX_AT_LENGTH)}function clearMarker(lockDir2,kind,deps={}){const rm=deps.rmSync??(p=>fs9.rmSync(p,{recursive:true,force:true}));try{rm(markerPath(lockDir2,kind))}catch{}}function watchMarker(lockDir2,kind,selfPid,onStop,deps={}){let fired=false;const timer=setInterval(()=>{if(fired)return;const req=readMarker(lockDir2,kind,deps);if(req===null||req.pid!==selfPid)return;fired=true;onStop(req)},deps.intervalMs??POLL_MS);timer.unref?.();return()=>{fired=true;clearInterval(timer)}}function safe(s){return stripTerminalControls(s)}function compactTimestamp(at=new Date){const p2=n=>String(n).padStart(2,"0");return`${at.getFullYear()}${p2(at.getMonth()+1)}${p2(at.getDate())}-${p2(at.getHours())}${p2(at.getMinutes())}${p2(at.getSeconds())}`}async function buildEngine(config,log){if(config.engine==="noop")return new NoopEngine;const{DispatchEngine}=await import("./ai-dispatch-
|
|
316
|
+
pid<=0)return null;return{pid,at:sanitizeAt(at)}}catch{return null}}function sanitizeAt(at){if(typeof at!=="string")return"";return at.replace(/[\u0000-\u001f\u007f]/g," ").slice(0,MAX_AT_LENGTH)}function clearMarker(lockDir2,kind,deps={}){const rm=deps.rmSync??(p=>fs9.rmSync(p,{recursive:true,force:true}));try{rm(markerPath(lockDir2,kind))}catch{}}function watchMarker(lockDir2,kind,selfPid,onStop,deps={}){let fired=false;const timer=setInterval(()=>{if(fired)return;const req=readMarker(lockDir2,kind,deps);if(req===null||req.pid!==selfPid)return;fired=true;onStop(req)},deps.intervalMs??POLL_MS);timer.unref?.();return()=>{fired=true;clearInterval(timer)}}function safe(s){return stripTerminalControls(s)}function compactTimestamp(at=new Date){const p2=n=>String(n).padStart(2,"0");return`${at.getFullYear()}${p2(at.getMonth()+1)}${p2(at.getDate())}-${p2(at.getHours())}${p2(at.getMinutes())}${p2(at.getSeconds())}`}async function buildEngine(config,log){if(config.engine==="noop")return new NoopEngine;const{DispatchEngine}=await import("./ai-dispatch-36HRDRLF.js");const{DEFAULT_PREFLIGHT_HOSTS}=await import("./ai-dispatch-36HRDRLF.js");const extraHosts=config.
|
|
317
317
|
operations.preflightHosts;return new DispatchEngine(config.ai,log,{workspace:config.workspace,charterFile:config.charterFile??void 0,charterEnabled:config.charterEnabled,...config.charterPrefix===null?{}:{charterPrefix:config.charterPrefix},...config.charterSuffix===null?{}:{charterSuffix:config.charterSuffix},serverPrompts:()=>config.serverPrompts??{},compileCommand:config.compileCommand??void 0,launcherBin:config.claudeLauncher.bin,...extraHosts.length>0?{preflightHosts:[...DEFAULT_PREFLIGHT_HOSTS,
|
|
318
318
|
...extraHosts]}:{}})}function lockDir(config){return path8.join(config.stateDir,`task-loop-${projectFileKey(config.projectId)}.lock.d`)}async function runTaskLoop(opts){if(opts.action==="stop")return await stopLoop(opts);const profile=resolveProfile(opts.profile);let creds;try{creds=new AuthSession(profile.name,profile.apiUrl).loadOrThrow()}catch(err){process.stderr.write(`${err.message}
|
|
319
319
|
`);return 1}const apiUrl=effectiveApiUrl(profile,creds.api_url);const session=new AuthSession(profile.name,apiUrl);const projectRef=opts.project??process.env.TWP_PROJECT??"";if(projectRef===""){process.stderr.write("--project <\u30AD\u30FC|UUID> \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08TWP_PROJECT \u3067\u3082\u53EF\uFF09\n");return 2}const projectApi=new ProjectApi(apiUrl,session);let project;try{project=await projectApi.resolve(projectRef)}catch(err){process.stderr.write(`${err.
|
|
320
320
|
message}
|
|
321
|
-
`);return 1}const projectId=project.id;if(opts.action==="setup"){const{runSetup,parseAiList}=await import("./setup-
|
|
321
|
+
`);return 1}const projectId=project.id;if(opts.action==="setup"){const{runSetup,parseAiList}=await import("./setup-6CXUVCF5.js");let ais;if(opts.ais!==void 0&&opts.ais.length>0){const parsed=parseAiList(opts.ais.join(","));if(parsed.unknown.length>0){process.stderr.write(`--ai \u306B\u672A\u77E5\u306E\u5024\u304C\u3042\u308A\u307E\u3059: ${parsed.unknown.join(" / ")}
|
|
322
322
|
`);return 2}ais=parsed.ais}return runSetup({projectId,projectRef,projectName:project.name===project.id?projectRef:`${project.code} / ${project.name}`,apiUrl,yes:opts.yes===true,...ais!==void 0?{ais}:{},...opts.workspace!==void 0?{workspace:opts.workspace}:{},...opts.aiConfigFile!==void 0?{aiConfigFile:opts.aiConfigFile}:{},...opts.noAiConfigFile===true?{noAiConfigFile:true}:{},...opts.profile!==void 0?{profile:opts.profile}:{}})}if(opts.action==="charter"){if(opts.charterOp===void 0){process.stderr.
|
|
323
|
-
write("charter \u306B\u306F push \u304B pull \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\n");return 2}if(isPrivateProjectId(projectId)){process.stderr.write("\u500B\u4EBA\u30BF\u30B9\u30AF\u306E\u30AD\u30E5\u30FC\uFF08--project __private__\uFF09\u306B\u306F\u61B2\u7AE0\u306E\u8A2D\u5B9A\u304C\u3042\u308A\u307E\u305B\u3093\n");return 2}const{runCharterCommand}=await import("./charter-command-
|
|
323
|
+
write("charter \u306B\u306F push \u304B pull \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\n");return 2}if(isPrivateProjectId(projectId)){process.stderr.write("\u500B\u4EBA\u30BF\u30B9\u30AF\u306E\u30AD\u30E5\u30FC\uFF08--project __private__\uFF09\u306B\u306F\u61B2\u7AE0\u306E\u8A2D\u5B9A\u304C\u3042\u308A\u307E\u305B\u3093\n");return 2}const{runCharterCommand}=await import("./charter-command-UBUE3KUO.js");return runCharterCommand({api:new AgentLoopApi({apiUrl,projectId,session})},{op:opts.
|
|
324
324
|
charterOp,file:opts.charterInput,out:opts.charterOutput,revision:opts.charterRevision,yes:opts.yes===true,projectRef,profile:opts.profile})}const config=buildLoopConfig({projectId,projectRef,apiUrl,safeMode:opts.safe,daemon:opts.daemon,...opts.maxCycles!==void 0?{maxCycles:opts.maxCycles}:{},...opts.interval!==void 0?{intervalSec:opts.interval}:{},forceRunner:opts.forceRunner,...opts.engine!==void 0?{engine:opts.engine}:{},version:opts.version});const api=new AgentLoopApi({apiUrl,projectId,session});
|
|
325
325
|
if(opts.action==="status"||opts.action==="schedule"){for(const warning of config.warnings)process.stderr.write(`\u26A0\uFE0F ${warning}
|
|
326
326
|
`)}if(opts.action==="status")return showStatus(api,config);if(opts.action==="schedule"){const{runScheduleCommand}=await import("./schedule-command-GKXKNMLG.js");return runScheduleCommand({api,projectApi,config},{now:opts.scheduleNow,counts:opts.scheduleCounts,gate:opts.scheduleGate,verbose:opts.verbose===true})}if(config.engine===""){process.stderr.write(`${new EngineNotConfiguredError().message}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{PromptAbortedError,promptHidden,promptText}from"./chunk-L37NS5L2.js";import{
|
|
4
|
-
import"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{EXIT_USAGE,UsageError}from"./chunk-
|
|
3
|
+
import{PromptAbortedError,promptHidden,promptText}from"./chunk-L37NS5L2.js";import{system32}from"./chunk-N2UVRM3Z.js";import{ApiError,TwpApiClient,errorListMessages}from"./chunk-FTYJZFEK.js";import{AuthSession,NotLoggedInError,SessionExpiredError,deleteCredentials,loadCredentials,maskToken,saveCredentials}from"./chunk-XNLIEUAW.js";import{isWindowsDriveAbsolute}from"./chunk-PMOUHEJQ.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{effectiveApiUrl,resolveProfile}from"./chunk-NERYSBA4.js";
|
|
4
|
+
import"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import{EXIT_USAGE,UsageError}from"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";import os from"os";import{createHash,randomBytes}from"crypto";function generatePkcePair(){const verifier=randomBytes(32).toString("base64url");return{verifier,challenge:computeChallenge(verifier),method:"S256"}}function computeChallenge(verifier){return createHash("sha256").update(verifier,"ascii").digest("base64url")}function generateState(){return randomBytes(16).toString("base64url")}import http from"http";import crypto from"crypto";function safeEqual(a,b){const x=Buffer.from(a,"utf8");const y=Buffer.from(b,"utf8");const len=Math.max(x.length,y.length,1);const px=Buffer.alloc(len);const py=Buffer.alloc(len);x.copy(px);y.copy(py);return crypto.timingSafeEqual(px,py)&&x.length===y.length}var LoginTimeoutError=class extends Error{constructor(timeoutMs){super(`\u30D6\u30E9\u30A6\u30B6\u3067\u306E\u627F\u8A8D\u3092 ${Math.round(timeoutMs/1e3)} \u79D2\u5F85\u3061\u307E\u3057\u305F\u304C\u5B8C\u4E86\u3057\u307E\u305B\u3093\u3067\u3057\u305F\u3002twp login \u3092\u3084\u308A\u76F4\u3057\u3066\u304F\u3060\u3055\
|
|
5
5
|
\u3044\u3002`)}};var SUCCESS_HTML=`<!doctype html><html lang="ja"><head><meta charset="utf-8"><title>TWP CLI \u30ED\u30B0\u30A4\u30F3\u5B8C\u4E86</title></head>
|
|
6
6
|
<body style="font-family: sans-serif; text-align: center; padding-top: 4rem; background:#f7f9fc; color:#1b2559">
|
|
7
7
|
<h1 style="font-size:1.4rem">\u2705 \u30ED\u30B0\u30A4\u30F3\u304C\u5B8C\u4E86\u3057\u307E\u3057\u305F</h1>
|
|
@@ -19,10 +19,10 @@ return}const port=address.port;resolveListener({port,redirectUri:`http://127.0.0
|
|
|
19
19
|
function browserCandidates(url,env=process.env,platform=process.platform,wsl=isWsl(env)){const candidates=[];if(env.BROWSER&&env.BROWSER.trim()!==""){const browser=env.BROWSER.trim();if(platform!=="win32"||isWindowsDriveAbsolute(browser)){candidates.push({cmd:browser,args:[url]})}}if(platform==="darwin"){candidates.push({cmd:"open",args:[url]})}else if(platform==="win32"){const cmdExe=system32(env,"cmd.exe");if(cmdExe!==null){candidates.push({cmd:cmdExe,args:["/c","start",'""',escapeForCmd(url)]})}
|
|
20
20
|
const powershellExe=system32(env,"WindowsPowerShell","v1.0","powershell.exe");if(powershellExe!==null){candidates.push({cmd:powershellExe,args:["-NoProfile","-NonInteractive","-Command",`Start-Process '${url.replace(/'/g,"''")}'`]})}}else{candidates.push({cmd:"xdg-open",args:[url]});if(wsl){candidates.push({cmd:"wslview",args:[url]});candidates.push({cmd:"cmd.exe",args:["/c","start",'""',escapeForCmd(url)]});candidates.push({cmd:"powershell.exe",args:["-NoProfile","-NonInteractive","-Command",`S\
|
|
21
21
|
tart-Process '${url.replace(/'/g,"''")}'`]})}}return candidates}function tryCandidate(candidate,settleMs){return new Promise(resolve=>{let child;try{child=spawn(candidate.cmd,candidate.args,{stdio:"ignore",detached:process.platform!=="win32",shell:false})}catch{resolve(false);return}const timer=setTimeout(()=>{child.unref();resolve(true)},settleMs);child.once("error",()=>{clearTimeout(timer);resolve(false)});child.once("exit",code=>{clearTimeout(timer);resolve(code===0)})})}async function openBrowser(url,env=process.
|
|
22
|
-
env,platform=process.platform,settleMs=1500){for(const candidate of browserCandidates(url,env,platform)){if(await tryCandidate(candidate,settleMs))return true}return false}var LoginError=class extends Error{};var OOB_REDIRECT_URI="urn:ietf:wg:oauth:2.0:oob";var defaultIo=cliVersion=>({out:text=>process.stdout.write(stripTerminalControls(text)),fetchImpl:httpFetch,cliVersion});function defaultDeviceName(){let user="unknown";try{user=os.userInfo().username}catch{}return`${user}@${os.hostname()} (${process.platform})`.slice(0,100)}async function parseJson(res){try{return await res.json()}catch{return null}}function describeHttpError(status,body){const pick=()=>{
|
|
23
|
-
error_description)return body.error_description;if(body?.errors){const first=Object.values(body.errors).flat()[0];if(first)return first}if(body?.message)return body.message;return`HTTP ${status}`};return stripTerminalControls(pick())}function toStoredCredentials(body,method,profile){if(typeof body.token!=="string"||body.token===""){throw new LoginError("\u30B5\u30FC\u30D0\u5FDC\u7B54\u306B\u30C8\u30FC\u30AF\u30F3\u304C\
|
|
24
|
-
return{token:body.token,token_expires_at:body.token_expires_at??null,refresh_token:body.refresh_token??null,refresh_token_expires_at:body.refresh_token_expires_at??null,api_url:profile.apiUrl,frontend_url:profile.frontendUrl,relay_url:profile.relayUrl,tenant_code:user?.tenant_code??null,user:user?{id:user.id,name:user.name,email:user.email}:null,method,saved_at:new Date().toISOString()}}function reportLoggedIn(io,profile,creds){
|
|
25
|
-
|
|
22
|
+
env,platform=process.platform,settleMs=1500){for(const candidate of browserCandidates(url,env,platform)){if(await tryCandidate(candidate,settleMs))return true}return false}var LoginError=class extends Error{};var OOB_REDIRECT_URI="urn:ietf:wg:oauth:2.0:oob";var defaultIo=cliVersion=>({out:text=>process.stdout.write(stripTerminalControls(text)),fetchImpl:httpFetch,cliVersion});function defaultDeviceName(){let user="unknown";try{user=os.userInfo().username}catch{}return`${user}@${os.hostname()} (${process.platform})`.slice(0,100)}async function parseJson(res){try{return await res.json()}catch{return null}}function describeHttpError(status,body){const pick=()=>{const detail=errorListMessages(
|
|
23
|
+
body?.error_list)[0];if(body?.error_description&&detail)return`${body.error_description} ${detail}`;if(body?.error_description)return body.error_description;if(detail)return detail;if(body?.errors){const first=Object.values(body.errors).flat()[0];if(first)return first}if(body?.message)return body.message;return`HTTP ${status}`};return stripTerminalControls(pick())}function toStoredCredentials(body,method,profile){if(typeof body.token!=="string"||body.token===""){throw new LoginError("\u30B5\u30FC\u30D0\u5FDC\u7B54\u306B\u30C8\u30FC\u30AF\u30F3\u304C\
|
|
24
|
+
\u542B\u307E\u308C\u3066\u3044\u307E\u305B\u3093\u3002")}const user=body.user;return{token:body.token,token_expires_at:body.token_expires_at??null,refresh_token:body.refresh_token??null,refresh_token_expires_at:body.refresh_token_expires_at??null,api_url:profile.apiUrl,frontend_url:profile.frontendUrl,relay_url:profile.relayUrl,tenant_code:user?.tenant_code??null,user:user?{id:user.id,name:user.name,email:user.email}:null,method,saved_at:new Date().toISOString()}}function reportLoggedIn(io,profile,creds){
|
|
25
|
+
const safe=value=>stripTerminalControls(value??"");const who=creds.user?`${safe(creds.user.name)}\uFF08${safe(creds.user.email)}\uFF09`:"(\u30E6\u30FC\u30B6\u30FC\u60C5\u5831\u306A\u3057)";const tenant=creds.tenant_code?` / \u30C6\u30CA\u30F3\u30C8: ${safe(creds.tenant_code)}`:"";io.out(`
|
|
26
26
|
\u2705 \u30ED\u30B0\u30A4\u30F3\u3057\u307E\u3057\u305F: ${who}${tenant}
|
|
27
27
|
`);io.out(` \u30D7\u30ED\u30D5\u30A1\u30A4\u30EB: ${profile.name} \u2192 ${profile.apiUrl}
|
|
28
28
|
`);if(!creds.refresh_token){io.out(" \u26A0 refresh token \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u30C8\u30FC\u30AF\u30F3\u5931\u52B9\u6642\u306F\u518D\u30ED\u30B0\u30A4\u30F3\u304C\u5FC5\u8981\u3067\u3059\u3002\n")}}function consentUrl(profile,io,challenge,redirectUri,state){const params=new URLSearchParams({code_challenge:challenge,redirect_uri:redirectUri,device:defaultDeviceName(),cli_version:io.cliVersion});if(state)params.set("state",state);return`${profile.frontendUrl}/auth/cli?${params.
|
|
@@ -50,12 +50,12 @@ ${err.hint?`${err.hint}
|
|
|
50
50
|
`);return 1}writeErr(`\u30A8\u30E9\u30FC: ${err.message}
|
|
51
51
|
`);return 1}}async function runLogin(options){return run(async()=>{const profile=resolveProfile(options.profile);const io=makeIo(options.cliVersion);if(options.method==="password"){await passwordLogin(profile,{tenantCode:options.tenant??void 0},process.env,io)}else if(options.method==="token"){await tokenLogin(profile,process.env,io)}else{await browserLogin(profile,process.env,io,{noBrowser:options.noBrowser})}})}async function runLogout(options){return run(async()=>{const profile=resolveProfile(
|
|
52
52
|
options.profile);const creds=loadCredentials(profile.name);if(!creds){writeOut(`\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB\u300C${profile.name}\u300D\u306F\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u3044\u307E\u305B\u3093\u3002
|
|
53
|
-
`);return}const{describeLogoutImpact,findLoopsUsingProfile}=await import("./logout-guard-
|
|
53
|
+
`);return}const{describeLogoutImpact,findLoopsUsingProfile}=await import("./logout-guard-FO7KZL3X.js");const found=findLoopsUsingProfile(profile.name,options.logoutGuard);if(found.users.length>0||found.undetermined.length>0){writeErr(describeLogoutImpact(profile.name,found,options.force===true));if(options.force!==true)throw new LogoutRefusedError}const apiUrl=effectiveApiUrl(profile,creds.api_url);const revoked=await httpFetch(`${apiUrl}/api/v2/auth/logout`,{method:"POST",headers:{Accept:"applic\
|
|
54
54
|
ation/json",Authorization:`Bearer ${creds.token}`}}).then(res=>res.ok,()=>false);await deleteCredentials(profile.name);writeOut(`\u2705 \u30ED\u30B0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\uFF08\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB: ${profile.name} / \u30C8\u30FC\u30AF\u30F3: ${maskToken(creds.token)}\uFF09
|
|
55
55
|
`);if(!revoked){writeOut("\u26A0 \u30B5\u30FC\u30D0\u5074\u306E\u30C8\u30FC\u30AF\u30F3\u5931\u52B9\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08\u30AA\u30D5\u30E9\u30A4\u30F3\u7B49\uFF09\u3002TWP \u306E\u300C\u8A2D\u5B9A > CLI\u7AEF\u672B\u300D\u304B\u3089\u3082\u5931\u52B9\u3067\u304D\u307E\u3059\u3002\n")}})}async function runWhoami(options){return run(async()=>{const profile=resolveProfile(options.profile);const structured=options.output!==void 0||options.query!==void 0;let format=null;if(structured){
|
|
56
56
|
const{resolveOutputFormat,OUTPUT_FORMATS}=await import("./format-NMW6Y2E5.js");format=resolveOutputFormat({...options.output!==void 0?{flag:options.output}:{},isTty:process.stdout.isTTY===true});if(format===null){throw new UsageError(`--output \u306B\u300C${options.output??""}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,`\u6307\u5B9A\u3067\u304D\u308B\u306E\u306F ${OUTPUT_FORMATS.join(" / ")} \u3067\u3059`)}}const stored=loadCredentials(profile.name);const apiUrl=effectiveApiUrl(
|
|
57
57
|
profile,stored?.api_url);const session=new AuthSession(profile.name,apiUrl);const client=new TwpApiClient(apiUrl,session,httpFetch,options.cliVersion);const me=await client.get("/api/v2/user");const user=me.user;const creds=loadCredentials(profile.name);if(format!==null){const value={id:user?.id??null,name:user?.name??null,email:user?.email??null,tenant_code:user?.tenant_code??null,role:user?.role??null,is_admin:user?.is_admin??null,profile:profile.name,api_url:apiUrl,expires_at:creds?.token_expires_at??
|
|
58
|
-
null};const{evaluateQuery}=await import("./query-
|
|
58
|
+
null};const{evaluateQuery}=await import("./query-EEALMOSO.js");const{renderOutput}=await import("./render-K45EOLHX.js");const selected=options.query===void 0?value:await evaluateQuery(options.query,value);const text=renderOutput(selected,format);process.stdout.write(text.endsWith("\n")?text:`${text}
|
|
59
59
|
`);return}writeOut(`\u30E6\u30FC\u30B6\u30FC: ${user?.name??"?"}\uFF08${user?.email??"?"}\uFF09
|
|
60
60
|
`);writeOut(`ID: ${user?.id??"?"}
|
|
61
61
|
`);writeOut(`\u30C6\u30CA\u30F3\u30C8: ${user?.tenant_code??"?"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{cacheNote,createFlags,fieldBody,hasAnyField,idSegment,masterFields,masterItem,masterListOperation,masterRows,referencedDeleteGuidance,resolveRefFields,targetId,updateFlags}from"./chunk-WGVHYTZV.js";import"./chunk-IJLJGDMZ.js";import{DEPARTMENTS_PATH}from"./chunk-QOUFHYK5.js";import"./chunk-II5RVJQN.js";import"./chunk-FTYJZFEK.js";import"./chunk-DMDVLOAY.js";import{withResolved}from"./chunk-ZN5EFDH7.js";import"./chunk-GMBJTG6A.js";import{acknowledgement,
|
|
4
|
+
isRecord,pick}from"./chunk-ZWVYVS2A.js";import"./chunk-J7QYPKVK.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import"./chunk-NHYMHCAT.js";import{ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";var LABEL="\u90E8\u7F72";var LIST_COLUMNS=["id","code","name","parent_id","level","effective_status","valid_from","valid_to","member_count"];var GET_COLUMNS=["id","code","name","name_short","parent_id","level","sort","effective_status","valid_from","valid_to","description"];var TREE_COLUMNS=["depth","name","code","id","effective_status","valid_to"];var MEMBER_COLUMNS=["id","user_id","position_id","job_title_id","start_date","end_date","is_primary","is_current","effective_status"];var REF_FLAG={name:"\
|
|
5
|
+
--department",summary:"\u5BFE\u8C61\u306E\u90E8\u7F72\uFF08\u4F4D\u7F6E\u5F15\u6570\u306E\u4EE3\u308F\u308A\u306B\u4F7F\u3048\u308B\uFF09",takesValue:true,placeholder:"<\u90E8\u7F72>"};var REF_HELP="<\u90E8\u7F72> \u306F\u540D\u524D\u30FB\u30B3\u30FC\u30C9\u30FBID \u306E\u3069\u308C\u3067\u3082\u6307\u5B9A\u3067\u304D\u307E\u3059\uFF08\u540D\u524D\u304C\u8907\u6570\u306B\u4E00\u81F4\u3059\u308C\u3070\u5019\u88DC\u3092\u51FA\u3057\u3066\u6B62\u307E\u308A\u307E\u3059\uFF09\u3002\nID \u4EE5\u5916\u306F\u90E8\u7F72\u4E00\u89A7\uFF08\u65E2\u5B9A10\u5206\u30AD\u30E3\u30C3\u30B7\u30E5\u30FB--refresh \u3067\u53D6\u308A\u76F4\u3057\uFF09\u3068\u7167\u5408\u3057\u307E\u3059\u3002";
|
|
6
|
+
var FIELDS=masterFields(LABEL,[{kind:"text",flag:"--name-short",key:"name_short",label:"\u7565\u79F0",maxChars:50,summary:"\u7565\u79F0"},{kind:"ref",flag:"--parent",key:"parent_id",summary:"\u89AA\u90E8\u7F72\uFF08\u540D\u524D\u30FB\u30B3\u30FC\u30C9\u30FBID\uFF09",placeholder:"<\u90E8\u7F72>",clearFlag:"--no-parent",clearSummary:"\u89AA\u90E8\u7F72\u3092\u5916\u3057\u3066\u6700\u4E0A\u4F4D\u306B\u3059\u308B",resolve:(ctx,ref,flag)=>ctx.resolver.department(ref,flag)},{kind:"integer",flag:"--sor\
|
|
7
|
+
t",key:"sort",label:"\u8868\u793A\u9806",min:0,summary:"\u8868\u793A\u9806\uFF080\u4EE5\u4E0A\u306E\u6574\u6570\uFF09"},{kind:"date",flag:"--valid-from",key:"valid_from",summary:"\u6709\u52B9\u958B\u59CB\u65E5\uFF08YYYY-MM-DD\u30FBnone \u3067\u6D88\u3059\uFF09"},{kind:"date",flag:"--valid-to",key:"valid_to",summary:"\u6709\u52B9\u7D42\u4E86\u65E5\uFF08YYYY-MM-DD\u30FBnone \u3067\u6D88\u3059\uFF09\u3002\u3053\u306E\u65E5\u306E\u7FCC\u65E5\u304B\u3089\u7121\u52B9\u306B\u306A\u308B"},{kind:"boolean",
|
|
8
|
+
flag:"--has-skill-standards",key:"has_skill_standards",summary:"\u30B9\u30AD\u30EB\u57FA\u6E96\u3092\u6301\u3064\u90E8\u7F72\u304B\uFF08true / false\uFF09"},{kind:"boolean",flag:"--can-view-personal-info",key:"can_view_personal_info",summary:"\u6240\u5C5E\u8005\u306E\u500B\u4EBA\u60C5\u5831\u3092\u95B2\u89A7\u3067\u304D\u308B\u304B\uFF08true / false\uFF09"},{kind:"boolean",flag:"--can-view-emergency-contact",key:"can_view_emergency_contact",summary:"\u6240\u5C5E\u8005\u306E\u7DCA\u6025\u9023\u7D61\u5148\u3092\u95B2\u89A7\u3067\u304D\u308B\u304B\uFF08true / false\uFF09"},
|
|
9
|
+
{kind:"text",flag:"--description",key:"description",label:"\u8AAC\u660E",maxChars:1e3,summary:"\u8AAC\u660E"}]);var DISABLE_GUIDANCE="\u4E00\u89A7\u3084\u7D44\u7E54\u56F3\u304B\u3089\u5916\u3059\u3060\u3051\u306A\u3089\u3001\u524A\u9664\u305B\u305A\u306B\u6709\u52B9\u7D42\u4E86\u65E5\u3092\u8A2D\u5B9A\u3057\u3066\u7121\u52B9\u5316\u3057\u3066\u304F\u3060\u3055\u3044:\n twp department update <\u90E8\u7F72> --valid-to <YYYY-MM-DD>\uFF08\u305D\u306E\u65E5\u306E\u7FCC\u65E5\u304B\u3089\u7121\u52B9\u306B\u306A\u308A\u307E\u3059\u3002none \u3067\u53D6\u308A\u6D88\u305B\u307E\u3059\uFF09";
|
|
10
|
+
var CHILDREN_GUIDANCE="\u5148\u306B\u5B50\u90E8\u7F72\u3092\u524A\u9664\u3059\u308B\u304B\u3001\u5225\u306E\u90E8\u7F72\u306E\u4E0B\u3078\u79FB\u3057\u3066\u304F\u3060\u3055\u3044: twp department update <\u5B50\u90E8\u7F72> --parent <\u5225\u306E\u90E8\u7F72>\n\uFF08\u5B50\u90E8\u7F72\u306F twp department tree \u3067\u78BA\u8A8D\u3067\u304D\u307E\u3059\uFF09";var MEMBERS_GUIDANCE="\u6240\u5C5E\u8005\u306F twp department members <\u90E8\u7F72> \u3067\u78BA\u8A8D\u3067\u304D\u307E\u3059\u3002\u524A\u9664\u3059\u308B\u306B\u306F\u3001\u5148\u306B\u6240\u5C5E\u8005\u306E\u6240\u5C5E\u3092\u7D42\u4E86\u3059\u308B\u304B\u5225\u306E\u90E8\u7F72\u3078\u79FB\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u7D44\u7E54\u7BA1\u7406\u306E\u753B\u9762\uFF09\u3002";
|
|
11
|
+
function deleteRejected(server){if(server.includes("\u5B50\u90E8\u7F72\u304C\u5B58\u5728"))return CHILDREN_GUIDANCE;if(server.includes("\u6240\u5C5E\u30E1\u30F3\u30D0\u30FC"))return`${MEMBERS_GUIDANCE}
|
|
12
|
+
${DISABLE_GUIDANCE}`;return referencedDeleteGuidance(DISABLE_GUIDANCE)(server)}var FORBIDDEN="\u7BA1\u7406\u8005\u306E\u6A29\u9650\u304C\u5FC5\u8981\u3067\u3059\u3002\u90E8\u7F72\u306E\u4F5C\u6210\u30FB\u66F4\u65B0\u30FB\u524A\u9664\u306F\u7BA1\u7406\u8005\u3060\u3051\u304C\u884C\u3048\u307E\u3059";async function prepareTarget(input,ctx,usage){return withResolved(input,{id:await targetId(input,{flag:REF_FLAG.name,label:LABEL,usage,resolve:ref=>ctx.resolver.department(ref,"<\u90E8\u7F72>")})})}var itemPath=(input,suffix="")=>`${DEPARTMENTS_PATH}\
|
|
13
|
+
/${idSegment(input,LABEL)}${suffix}`;var item=body=>masterItem(body,"department",LABEL);function treeNodes(body){const tree=isRecord(body)?body["tree"]:void 0;if(!Array.isArray(tree)){throw new ApiResponseError("\u90E8\u7F72\u30C4\u30EA\u30FC\u306E\u5FDC\u7B54\u306B tree \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return tree}function flattenTree(nodes,depth=0,out=[]){for(const node of nodes){const department=isRecord(
|
|
14
|
+
node)&&isRecord(node["department"])?node["department"]:null;if(department===null){throw new ApiResponseError("\u90E8\u7F72\u30C4\u30EA\u30FC\u306E\u5FDC\u7B54\u306B department \u306E\u7121\u3044\u7BC0\u304C\u3042\u308A\u307E\u3059\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}const name=typeof department["name"]==="string"?department["name"]:"";out.push(pick({...department,depth,name:`${" ".repeat(depth)}${name}`},TREE_COLUMNS));const children=isRecord(node)?
|
|
15
|
+
node["children"]:void 0;if(Array.isArray(children))flattenTree(children,depth+1,out)}return out}function isMembersBody(body){return isRecord(body)&&"current"in body&&"past"in body}function memberRows(body){if(isMembersBody(body)){return[...masterRows(body.current,"\u6240\u5C5E\u8005"),...masterRows(body.past,"\u73FE\u5728\u3067\u306A\u3044\u6240\u5C5E")]}return masterRows(body,"\u6240\u5C5E\u8005")}function membersPlan(input,currentOnly=true){return{method:"GET",path:itemPath(input,"/members"),query:{
|
|
16
|
+
current_only:currentOnly?"true":"false"}}}var membersOperation={name:"members",summary:"\u90E8\u7F72\u306B\u6240\u5C5E\u3057\u3066\u3044\u308B\u30E1\u30F3\u30D0\u30FC\uFF08\u6240\u5C5E\uFF09\u3092\u4E00\u89A7\u3059\u308B",usage:"twp department members <\u90E8\u7F72> [--include-past]",description:"\u65E2\u5B9A\u306F\u73FE\u5728\u306E\u6240\u5C5E\u3060\u3051\u3067\u3059\u3002--include-past \u3067\u3001\u73FE\u5728\u3067\u306A\u3044\u6240\u5C5E\uFF08\u7D42\u4E86\u3057\u305F\u6240\u5C5E\u3068\u3001\u958B\u59CB\u65E5\u524D\u306E\u4E88\u7D04\uFF09\u3082\u5F8C\u308D\u306B\u7D9A\u3051\u3066\u51FA\u3057\u307E\u3059\u3002\n\u3069\u3061\u3089\u306B\u5165\u308B\u304B\u306F\u30B5\u30FC\u30D0\u306E is_current \u306B\u5F93\u3044\u307E\u3059\u3002\u5B9F\u969B\u306E\u72B6\u614B\u306F effective_status \u5217\uFF08active / ended / scheduled\uFF09\u3067\u898B\u3066\u304F\u3060\u3055\u3044\u3002\n\u884C\u306F\u6240\u5C5E\uFF08assignment\uFF09\u3067\u3001user_id \u304C\u6240\u5C5E\u8005\u3067\u3059\u3002\u6C0F\u540D\u306F twp us\
|
|
17
|
+
er get <user_id> \u3067\u78BA\u8A8D\u3067\u304D\u307E\u3059\n\uFF08\u4E3B\u6240\u5C5E\u304C\u90E8\u7F72\u306B\u3042\u308B\u4EBA\u3092\u6C0F\u540D\u3064\u304D\u3067\u898B\u308B\u306A\u3089 twp user list --department <\u90E8\u7F72>\uFF09\u3002\n\u3053\u306E API \u306F\u30DA\u30FC\u30B8\u30F3\u30B0\u3092\u6301\u305F\u305A\u3001\u5E38\u306B\u5168\u4EF6\u3092\u8FD4\u3057\u307E\u3059\u3002\n\n"+REF_HELP,flags:[REF_FLAG,{name:"--include-past",summary:"\u73FE\u5728\u3067\u306A\u3044\u6240\u5C5E\uFF08\u7D42\u4E86\u30FB\u958B\u59CB\u524D\uFF09\u3082\u542B\u3081\u308B",
|
|
18
|
+
takesValue:false}],prepare:(input,ctx)=>prepareTarget(input,ctx,"twp department members help"),plan:input=>membersPlan(input),plannedNotes:input=>input.flags.has("--include-past")?["\u3053\u306E\u3042\u3068\u3001\u73FE\u5728\u3067\u306A\u3044\u6240\u5C5E\u3092 current_only=false \u3067 GET \u3057\u307E\u3059\uFF08\u30B5\u30FC\u30D0\u306E false \u306F\u73FE\u5728\u306E\u6240\u5C5E\u3092\u542B\u307E\u306A\u3044\u306E\u3067\u30012\u56DE\u306B\u5206\u3051\u3066\u8DB3\u3057\u5408\u308F\u305B\u307E\u3059\uFF09\u3002"]:
|
|
19
|
+
[],async execute(input,ctx){const current=await ctx.send(membersPlan(input));masterRows(current,"\u6240\u5C5E\u8005");if(!input.flags.has("--include-past"))return current;const past=await ctx.send(membersPlan(input,false));masterRows(past,"\u73FE\u5728\u3067\u306A\u3044\u6240\u5C5E");return{current,past}},summarize:body=>memberRows(body).map(row=>pick(row,MEMBER_COLUMNS)),raw:body=>memberRows(body)};var departmentDomain={name:"department",summary:"\u90E8\u7F72\u30DE\u30B9\u30BF\uFF08\u4E00\u89A7\u30FB\u30C4\u30EA\u30FC\u30FB\u6240\u5C5E\u8005\u30FB\u53D6\u5F97\u30FB\u4F5C\u6210\u30FB\u66F4\u65B0\u30FB\u524A\u9664\uFF09",
|
|
20
|
+
operations:[masterListOperation({name:"department",label:LABEL,path:DEPARTMENTS_PATH,columns:LIST_COLUMNS,note:"--status \u306F\u4FDD\u5B58\u6E08\u307F\u306E\u72B6\u614B\uFF08active: \u6709\u52B9 / inactive: \u7121\u52B9\uFF09\u3067\u7D5E\u308A\u307E\u3059\u3002\u6709\u52B9\u671F\u9593\u306E\u5883\u76EE\u3092\u307E\u305F\u3044\u3060\u76F4\u5F8C\u306F\n\u65E5\u6B21\u306E\u66F4\u65B0\u307E\u30671\u65E5\u305A\u308C\u308B\u3053\u3068\u304C\u3042\u308A\u307E\u3059\u3002\u5B9F\u969B\u306E\u72B6\u614B\u306F effective_status \u5217\u3067\u898B\u3066\u304F\u3060\u3055\u3044\u3002\n\u89AA\u5B50\u95A2\u4FC2\u3092\u898B\u308B\u306A\u3089 twp department tree \u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044\u3002"}),
|
|
21
|
+
{name:"tree",summary:"\u90E8\u7F72\u30C4\u30EA\u30FC\u3092\u8868\u793A\u3059\u308B\uFF08\u73FE\u5728\u6709\u52B9\u306A\u90E8\u7F72\u3060\u3051\uFF09",usage:"twp department tree",description:"\u73FE\u5728\u6709\u52B9\u306A\u90E8\u7F72\u3092\u89AA\u5B50\u306E\u9806\u306B\u4E26\u3079\u307E\u3059\uFF08\u6709\u52B9\u7D42\u4E86\u65E5\u3092\u904E\u304E\u305F\u90E8\u7F72\u30FB\u958B\u59CB\u524D\u306E\u90E8\u7F72\u306F\u51FA\u307E\u305B\u3093\u3002\u5168\u4EF6\u306F twp department list\uFF09\u3002\ntable / text / tsv \u3067\u306F\u6DF1\u3055\uFF08depth\uFF09\u3068\u5B57\u4E0B\u3052\u3057\u305F\u540D\u524D\u3067\u51FA\u3057\u307E\u3059\u3002--output json \u306F\u30B5\u30FC\u30D0\u306E\u6728\u69CB\u9020\n\uFF08[{department, children: [...]}]\uFF09\u3092\u305D\u306E\u307E\u307E\u51FA\u3057\u307E\u3059\u3002",
|
|
22
|
+
flags:[],plan(input){if(input.args.length>0){throw new UsageError(`tree \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,"twp department tree help")}return{method:"GET",path:`${DEPARTMENTS_PATH}/tree`}},summarize:body=>flattenTree(treeNodes(body)),raw:body=>treeNodes(body)},membersOperation,{name:"get",summary:"\u90E8\u7F721\u4EF6\u306E\u8A73\u7D30\u3092\u8868\u793A\u3059\u308B",usage:"twp department get <\u90E8\u7F72>",description:`${REF_HELP}
|
|
23
|
+
|
|
24
|
+
--output json \u306F API \u304C\u8FD4\u3059\u5168\u30D5\u30A3\u30FC\u30EB\u30C9\u3092\u51FA\u3057\u307E\u3059\u3002`,flags:[REF_FLAG],prepare:(input,ctx)=>prepareTarget(input,ctx,"twp department get help"),plan:input=>({method:"GET",path:itemPath(input)}),summarize:body=>pick(item(body),GET_COLUMNS),raw:body=>item(body)},{name:"create",summary:"\u90E8\u7F72\u3092\u4F5C\u6210\u3059\u308B\uFF08\u7BA1\u7406\u8005\u306E\u307F\uFF09",usage:"twp department create --code <\u30B3\u30FC\u30C9> --name <\u90E8\u7F72\u540D> [--parent <\u90E8\
|
|
25
|
+
\u7F72>] [--valid-from <YYYY-MM-DD>] [\u9805\u76EE\u2026]",description:"--code \u3068 --name \u304C\u5FC5\u9808\u3067\u3059\u3002--parent \u3092\u7701\u304F\u3068\u6700\u4E0A\u4F4D\u306E\u90E8\u7F72\u306B\u306A\u308A\u307E\u3059\u3002\n--parent \u306F\u540D\u524D\u30FB\u30B3\u30FC\u30C9\u30FBID \u306E\u3069\u308C\u3067\u3082\u6307\u5B9A\u3067\u304D\u307E\u3059\u3002\n\u90E8\u7F72\u306E\u6709\u52B9\uFF0F\u7121\u52B9\u306F\u6709\u52B9\u671F\u9593\uFF08--valid-from / --valid-to\uFF09\u304B\u3089\u6C7A\u307E\u308A\u307E\u3059\uFF08\u72B6\u614B\u3092\u76F4\u63A5\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\uFF09\u3002\n\n\u4F5C\u6210\u3057\u305F\u90E8\u7F72\u306E ID \u304C\u8FD4\u308A\u307E\u3059\u3002",
|
|
26
|
+
forbidden:FORBIDDEN,flags:createFlags(FIELDS),async prepare(input,ctx){if(input.args.length>0){throw new UsageError(`create \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,"twp department create help")}const body=fieldBody(input,FIELDS);if(body["code"]===void 0)throw new UsageError("--code \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044","twp department create help");if(body["name"]===void 0)throw new UsageError("--name \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
27
|
+
"twp department create help");return resolveRefFields(input,ctx,FIELDS)},plan:input=>({method:"POST",path:DEPARTMENTS_PATH,body:fieldBody(input,FIELDS)}),summarize:body=>pick(item(body),GET_COLUMNS),raw:body=>item(body),notes:()=>[cacheNote(LABEL)]},{name:"update",summary:"\u90E8\u7F72\u3092\u66F4\u65B0\u3059\u308B\uFF08\u7BA1\u7406\u8005\u306E\u307F\uFF09",usage:"twp department update <\u90E8\u7F72> [--name <\u90E8\u7F72\u540D>] [--parent <\u90E8\u7F72> | --no-parent] [--valid-to <YYYY-MM-DD|none>] [\u9805\u76EE\u2026]",
|
|
28
|
+
description:"\u6307\u5B9A\u3057\u305F\u9805\u76EE\u3060\u3051\u3092\u5909\u66F4\u3057\u307E\u3059\uFF08\u6307\u5B9A\u3057\u306A\u304B\u3063\u305F\u9805\u76EE\u306F\u5909\u308F\u308A\u307E\u305B\u3093\uFF09\u3002\u5909\u66F4\u3059\u308B\u9805\u76EE\u30921\u3064\u3082\u6307\u5B9A\u3057\u306A\u3044\u3068\u30A8\u30E9\u30FC\u306B\u306A\u308A\u307E\u3059\u3002\n--parent \u3067\u89AA\u90E8\u7F72\u3092\u4ED8\u3051\u66FF\u3048\u3001--no-parent \u3067\u6700\u4E0A\u4F4D\u3078\u79FB\u3057\u307E\u3059\uFF08\u81EA\u5206\u81EA\u8EAB\u3084\u5B50\u5B6B\u306F\u89AA\u306B\u3067\u304D\u307E\u305B\u3093\u3002\u30B5\u30FC\u30D0\u304C\u65AD\u308A\u307E\u3059\uFF09\u3002\n--valid-to \u3092\u8A2D\u5B9A\u3059\u308B\u3068\u3001\u305D\u306E\u65E5\u306E\u7FCC\u65E5\u304B\u3089\u7121\u52B9\u306B\u306A\u308A\u307E\u3059\u3002--valid-to none \u3067\u53D6\u308A\u6D88\u3059\u3068\u6709\u52B9\u306B\u623B\u308A\u307E\u3059\n\uFF08\u6709\u52B9\u958B\u59CB\u65E5\u304C\u672A\u6765\u306A\u3089\u3001\u305D\u306E\u65E5\u307E\u3067\u306F\u7121\u52B9\u306E\u307E\u307E\u3067\u3059\uFF09\u3002\n\n"+
|
|
29
|
+
REF_HELP,forbidden:FORBIDDEN,flags:[...updateFlags(FIELDS),REF_FLAG],async prepare(input,ctx){if(!hasAnyField(input,FIELDS)){throw new UsageError("\u5909\u66F4\u3059\u308B\u9805\u76EE\u30921\u3064\u4EE5\u4E0A\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044","twp department update help")}fieldBody(input,FIELDS);const target=await prepareTarget(input,ctx,"twp department update help");return resolveRefFields(target,ctx,FIELDS)},plan:input=>({method:"PUT",path:itemPath(input),body:fieldBody(input,FIELDS)}),
|
|
30
|
+
summarize:body=>pick(item(body),GET_COLUMNS),raw:body=>item(body),notes:()=>[cacheNote(LABEL)]},{name:"delete",summary:"\u90E8\u7F72\u3092\u524A\u9664\u3059\u308B\uFF08\u7BA1\u7406\u8005\u306E\u307F\u30FB--yes \u304C\u8981\u308B\uFF09",usage:"twp department delete <\u90E8\u7F72> --yes",description:`\u5B50\u90E8\u7F72\u304C\u3042\u308B\u30FB\u6240\u5C5E\u8005\u304C\u3044\u308B\uFF08\u904E\u53BB\u306E\u6240\u5C5E\u5C65\u6B74\u3092\u542B\u3080\uFF09\u30FB\u539F\u4FA1\u306E\u8CA0\u62C5\u90E8\u7F72\u306B\u6307\u5B9A\u3055\u308C\u3066\u3044\u308B\u90E8\u7F72\u306F\u3001\u30B5\u30FC\u30D0\u304C\u524A\u9664\u3092\u65AD\u308A\u307E\u3059\u3002
|
|
31
|
+
${DISABLE_GUIDANCE}
|
|
32
|
+
|
|
33
|
+
${REF_HELP}`,destructive:true,forbidden:FORBIDDEN,rejected:deleteRejected,flags:[REF_FLAG],prepare:(input,ctx)=>prepareTarget(input,ctx,"twp department delete help"),plan:input=>({method:"DELETE",path:itemPath(input)}),summarize:body=>acknowledgement(body,"\u90E8\u7F72\u524A\u9664"),raw:body=>acknowledgement(body,"\u90E8\u7F72\u524A\u9664"),notes:()=>[cacheNote(LABEL)]}]};export{departmentDomain};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{STATUS_VALUES,flatMasterDomain}from"./chunk-WGVHYTZV.js";import"./chunk-IJLJGDMZ.js";import{JOB_TITLES_PATH}from"./chunk-QOUFHYK5.js";import"./chunk-II5RVJQN.js";import"./chunk-FTYJZFEK.js";import"./chunk-DMDVLOAY.js";import"./chunk-ZN5EFDH7.js";import"./chunk-GMBJTG6A.js";import"./chunk-ZWVYVS2A.js";import"./chunk-J7QYPKVK.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import"./chunk-NHYMHCAT.js";import"./chunk-7WSNIXTQ.js";
|
|
4
|
+
import"./chunk-VSJBJXZO.js";var jobTitleDomain=flatMasterDomain({name:"job-title",label:"\u8077\u4F4D",path:JOB_TITLES_PATH,itemKey:"job_title",summary:"\u8077\u4F4D\u30DE\u30B9\u30BF\uFF08\u4E00\u89A7\u30FB\u53D6\u5F97\u30FB\u4F5C\u6210\u30FB\u66F4\u65B0\u30FB\u524A\u9664\uFF09",listColumns:["id","code","name","sort_order","status","position_id","base_selling_price","base_cost_price"],getColumns:["id","code","name","name_short","sort_order","status","position_id","base_selling_price","base_cost_price","description"],fields:[
|
|
5
|
+
{kind:"text",flag:"--name-short",key:"name_short",label:"\u7565\u79F0",maxChars:50,summary:"\u7565\u79F0"},{kind:"integer",flag:"--sort-order",key:"sort_order",label:"\u8868\u793A\u9806",min:0,max:9999,summary:"\u8868\u793A\u9806\uFF080\u301C9999\uFF09"},{kind:"enum",flag:"--status",key:"status",values:STATUS_VALUES,summary:"\u72B6\u614B\uFF08active: \u6709\u52B9 / inactive: \u7121\u52B9\uFF09"},{kind:"text",flag:"--description",key:"description",label:"\u8AAC\u660E",maxChars:1e3,summary:"\u8AAC\u660E"},
|
|
6
|
+
{kind:"integer",flag:"--base-selling-price",key:"base_selling_price",label:"\u57FA\u6E96\u58F2\u4FA1",min:0,summary:"\u57FA\u6E96\u58F2\u4FA1\uFF080\u4EE5\u4E0A\u306E\u6574\u6570\uFF09"},{kind:"integer",flag:"--base-cost-price",key:"base_cost_price",label:"\u57FA\u6E96\u539F\u4FA1",min:0,summary:"\u57FA\u6E96\u539F\u4FA1\uFF080\u4EE5\u4E0A\u306E\u6574\u6570\uFF09"},{kind:"text",flag:"--skill-requirements",key:"skill_requirements",label:"\u30B9\u30AD\u30EB\u8981\u4EF6",maxChars:5e3,summary:"\u30B9\u30AD\u30EB\u8981\u4EF6"},
|
|
7
|
+
{kind:"ref",flag:"--position",key:"position_id",summary:"\u7D10\u3065\u3051\u308B\u5F79\u8077\uFF08\u540D\u524D\u30FB\u30B3\u30FC\u30C9\u30FBID\uFF09",placeholder:"<\u5F79\u8077>",clearFlag:"--no-position",clearSummary:"\u5F79\u8077\u3068\u306E\u7D10\u3065\u3051\u3092\u5916\u3059",resolve:(ctx,ref,flag)=>ctx.resolver.position(ref,flag)}],resolve:(ctx,ref,flag)=>ctx.resolver.jobTitle(ref,flag),deleteGuidance:"\u4ECA\u5F8C\u4F7F\u308F\u306A\u3044\u8077\u4F4D\u306F\u3001\u524A\u9664\u305B\u305A\u306B\u7121\u52B9\u5316\u3057\u3066\u304F\u3060\u3055\u3044: twp job-title update <\u8077\u4F4D> --status inactive\n\uFF08\u904E\u53BB\u306E\u6240\u5C5E\u306E\u8A18\u9332\u306F\u305D\u306E\u307E\u307E\u6B8B\u308A\u307E\u3059\
|
|
8
|
+
\uFF09"});export{jobTitleDomain};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{defaultIsLoopProcess,readLockOwner,sameTwpHome}from"./chunk-3WHC4FSG.js";import{loopStateDir}from"./chunk-
|
|
3
|
+
import{defaultIsLoopProcess,readLockOwner,sameTwpHome}from"./chunk-3WHC4FSG.js";import{loopStateDir}from"./chunk-UIWGEBWI.js";import"./chunk-N2UVRM3Z.js";import"./chunk-TYNCXQSN.js";import"./chunk-GY7KI5E5.js";import"./chunk-PMOUHEJQ.js";import"./chunk-5WGOHFAS.js";import{twpHomeDir}from"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";import fs from"fs";import path from"path";var PIDLESS_GRACE_MS=6e4;function defaultStateDirs(env){const dirs=[loopStateDir(env),loopStateDir({})].map(d=>path.resolve(d));return[...new Set(dirs)]}function readPidFile(lockDir){try{const raw=fs.readFileSync(path.join(lockDir,"pid"),"utf8").split("\n")[0]?.trim()??"";const n=Number.parseInt(raw,10);return{pid:Number.isInteger(n)&&n>0?n:null,error:null}}catch(err){const code=err.code;return{pid:null,error:code==="ENOENT"?null:code??err.message}}}function findLoopsUsingProfile(profileName,deps={}){
|
|
4
4
|
const env=deps.env??process.env;const now=deps.now??Date.now;const isLoopProcess=deps.isLoopProcess??defaultIsLoopProcess;const myHome=twpHomeDir(env);const result={users:[],undetermined:[]};for(const stateDir of deps.stateDirs??defaultStateDirs(env)){let dirs;try{dirs=fs.readdirSync(stateDir).filter(d=>/^task-loop-.*\.lock\.d$/.test(d))}catch(err){if(err.code==="ENOENT")continue;result.undetermined.push({pid:null,lockDir:stateDir,reason:`\u30ED\u30C3\u30AF\u306E\u7F6E\u304D\u5834\u6240\u3092\u8AAD\u3081\u307E\u305B\u3093\uFF08${err.
|
|
5
5
|
code??err.message}\uFF09`});continue}for(const dir of dirs){const lockDir=path.join(stateDir,dir);const pidFile=readPidFile(lockDir);if(pidFile.error!==null){result.undetermined.push({pid:null,lockDir,reason:`pid \u3092\u8AAD\u3081\u307E\u305B\u3093\uFF08${pidFile.error}\uFF09`});continue}const owner=readLockOwner(lockDir);let pid=pidFile.pid;if(pid===null){if(owner.ok){pid=owner.owner.pid}else{let ageMs=null;try{ageMs=now()-fs.statSync(lockDir).mtimeMs}catch{}if(ageMs!==null&&ageMs>=PIDLESS_GRACE_MS)
|
|
6
6
|
continue;result.undetermined.push({pid:null,lockDir,reason:"\u30ED\u30C3\u30AF\u306B pid \u304C\u3042\u308A\u307E\u305B\u3093\uFF08\u8D77\u52D5\u76F4\u5F8C\u306E\u53EF\u80FD\u6027\uFF09"});continue}}if(!isLoopProcess(pid))continue;if(!owner.ok){result.undetermined.push({pid,lockDir,reason:owner.reason});continue}if(owner.owner.pid!==pid){result.undetermined.push({pid,lockDir,reason:`\u6240\u6709\u8005\u306E\u8A18\u9332\uFF08pid=${owner.owner.pid}\uFF09\u304C\u30ED\u30C3\u30AF\u306E pid \u3068\u4E00\u81F4\u3057\u307E\u305B\u3093`});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{contentTypeFor}from"./chunk-I3YPO7CY.js";import"./chunk-GY7KI5E5.js";import{checkUploadQuota}from"./chunk-DDKZ5IPT.js";import"./chunk-QOUFHYK5.js";import"./chunk-II5RVJQN.js";import"./chunk-FTYJZFEK.js";import{LIST_FLAGS,LIST_PAGING_HELP,envelopePaging,nonEmpty,positiveInteger}from"./chunk-DMDVLOAY.js";import{requireResolved,singleRef,withResolved}from"./chunk-ZN5EFDH7.js";import{isSafePathSegment}from"./chunk-GMBJTG6A.js";import{isRecord,
|
|
4
|
+
pick}from"./chunk-ZWVYVS2A.js";import"./chunk-J7QYPKVK.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import"./chunk-NHYMHCAT.js";import{ApiRejectedError,ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";import crypto from"crypto";import fs from"fs";import path from"path";var SCOPE_PERSONAL="personal";var SCOPE_PROJECT="project";var LIST_COLUMNS=["id","file_name","content_type","file_size","folder_id","public_status","updated_at"];var UPLOAD_COLUMNS=["id","file_name","content_type","file_size","folder_id","scope","content_hash"];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",takesValue:true,placeholder:"<\u30D1\u30B9>"};var NAME_FLAG={
|
|
5
|
+
name:"--name",summary:"\u4FDD\u5B58\u3059\u308B\u30D5\u30A1\u30A4\u30EB\u540D\uFF08\u7701\u7565\u6642\u306F\u30ED\u30FC\u30AB\u30EB\u306E\u30D5\u30A1\u30A4\u30EB\u540D\u3002\u540C\u540D\u304C\u3042\u308B\u3068\u30B5\u30FC\u30D0\u304C\u5225\u540D\u306B\u3057\u307E\u3059\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",
|
|
6
|
+
takesValue:true,placeholder:"<\u578B>"};var FOLDER_FLAG={name:"--folder",summary:"\u30D5\u30A9\u30EB\u30C0ID\uFF08\u7701\u7565\u6642\u306F\u30B9\u30B3\u30FC\u30D7\u306E\u6700\u4E0A\u4F4D\uFF09",takesValue:true,placeholder:"<\u30D5\u30A9\u30EB\u30C0ID>"};var MEDIA_PROJECT_FLAG={name:"--project",summary:"\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u5BFE\u8C61\u306B\u3059\u308B\uFF08\u30B3\u30FC\u30C9\u307E\u305F\u306F ID\uFF09\u3002\u7701\u7565\u6642\u306F\u81EA\u5206\u306E\u500B\u4EBA\u30D5\u30A1\u30A4\u30EB",
|
|
7
|
+
takesValue:true,placeholder:"<\u30B3\u30FC\u30C9|ID>"};var KEYWORD_FLAG={name:"--keyword",summary:"\u30D5\u30A1\u30A4\u30EB\u540D\u30FB\u5185\u5BB9\u306E\u30AD\u30FC\u30EF\u30FC\u30C9\u691C\u7D22\uFF08\u691C\u7D22\u6642\u306F\u30DA\u30FC\u30B8\u30F3\u30B0\u3057\u307E\u305B\u3093\uFF09",takesValue:true,placeholder:"<\u30AD\u30FC\u30EF\u30FC\u30C9>"};var FILE_REF_FLAG={name:"--id",summary:"\u30D5\u30A1\u30A4\u30EBID\u3002\u4F4D\u7F6E\u5F15\u6570\u3068\u540C\u3058\u610F\u5473\uFF08\u4E21\u65B9\u6307\u5B9A\u306F\u30A8\u30E9\u30FC\uFF09",
|
|
8
|
+
takesValue:true,placeholder:"<\u30D5\u30A1\u30A4\u30EBID>"};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 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",
|
|
9
|
+
takesValue:false};var UUID=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function folderId(input){const value=nonEmpty(input.flags,"--folder");if(value!==void 0&&!UUID.test(value)){throw new UsageError(`--folder \u306B\u306F\u30D5\u30A9\u30EB\u30C0ID\uFF08UUID\uFF09\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044: ${value}`)}return value}async function resolveScope(input,ctx){const ref=nonEmpty(input.flags,"--project");if(ref===void 0)return{scope:SCOPE_PERSONAL};return{
|
|
10
|
+
scope:SCOPE_PROJECT,scopeId:await ctx.projectId(ref)}}function fileRef(input,usage){const id=singleRef(input,{flag:"--id",label:"\u30D5\u30A1\u30A4\u30EBID",usage});if(!isSafePathSegment(id))throw new UsageError(`\u30D5\u30A1\u30A4\u30EBID \u306E\u5F62\u5F0F\u304C\u9055\u3044\u307E\u3059: ${id}`);return id}function filePath(id){return`/api/v2/media/files/${encodeURIComponent(id)}`}function listRows(body){const data=isRecord(body)?body["data"]:void 0;if(!Array.isArray(data)){throw new ApiResponseError(
|
|
11
|
+
"\u30E1\u30C7\u30A3\u30A2\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}function dataOf(body,label){const data=isRecord(body)?body["data"]:void 0;if(!isRecord(data)){throw new ApiResponseError(`${label}\u306E\u5FDC\u7B54\u306B data \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}return data}
|
|
12
|
+
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 media upload --file <\u30D1\u30B9>")}if(input.args.length>0){throw new UsageError(`upload \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D7\u3051\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,"twp media upload --file <\u30D1\u30B9>")}const file=path.resolve(raw.trim());let stat;try{stat=fs.statSync(file)}catch{throw new UsageError(`\u30D5\
|
|
13
|
+
\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}`);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=nonEmpty(input.flags,"--name");const name=nameFlag??path.basename(file);const contentType=nonEmpty(input.flags,"--content-ty\
|
|
14
|
+
pe")??contentTypeFor(name);return{file,name,size:stat.size,contentType}}function uploadUrlPlan(input){const resolved=input.resolved??{};const body={file_name:requireResolved(input,"fileName"),content_type:requireResolved(input,"contentType"),file_size:Number(requireResolved(input,"fileSize")),scope:requireResolved(input,"scope")};if(resolved["scopeId"]!==void 0)body["scope_id"]=resolved["scopeId"];const folder=folderId(input);if(folder!==void 0)body["folder_id"]=folder;return{method:"POST",path:"\
|
|
15
|
+
/api/v2/media/files/upload-url",body}}function issued(body){const data=dataOf(body,"\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9URL\u767A\u884C");const id=data["file_id"];const uploadUrl=data["upload_url"];if(!isSafePathSegment(id)||typeof uploadUrl!=="string"||!/^https:\/\//.test(uploadUrl)){throw new ApiResponseError("\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9URL\u767A\u884C\u306E\u5FDC\u7B54\u306B data.file_id / data.upload_url \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
16
|
+
return{id,uploadUrl}}var discardGuidance=id=>` \u7834\u68C4: twp media delete ${id} --yes\uFF08\u30B4\u30DF\u7BB1\u3078\u79FB\u3057\u307E\u3059\u3002\u5B8C\u5168\u306B\u6D88\u3059\u306A\u3089 twp api /v2/media/files/${id}/permanent --method DELETE --yes\uFF09`;function orphanGuidance(id,stage){if(stage==="transfer"){return`\u30D5\u30A1\u30A4\u30EB ${id} \u306F\u4EEE\u767B\u9332\u3055\u308C\u307E\u3057\u305F\u304C\u3001\u30B9\u30C8\u30EC\u30FC\u30B8\u3078\u306E\u8EE2\u9001\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002
|
|
17
|
+
\u30B5\u30FC\u30D0\u306B\u306F\u4E2D\u8EAB\u306E\u7121\u3044\u4EEE\u767B\u9332\u306E\u30D5\u30A1\u30A4\u30EB\u304C\u6B8B\u3063\u3066\u304A\u308A\u3001\u81EA\u52D5\u3067\u306F\u524A\u9664\u3055\u308C\u307E\u305B\u3093\u3002\u7834\u68C4\u3057\u3066\u304B\u3089\u518D\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002
|
|
18
|
+
`+discardGuidance(id)}return`\u30D5\u30A1\u30A4\u30EB ${id} \u306F\u30B9\u30C8\u30EC\u30FC\u30B8\u3078\u306E\u8EE2\u9001\u307E\u3067\u5B8C\u4E86\u3057\u307E\u3057\u305F\u304C\u3001\u5B8C\u4E86\u767B\u9332\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002
|
|
19
|
+
\u30B5\u30FC\u30D0\u306B\u306F\u4EEE\u767B\u9332\u306E\u30D5\u30A1\u30A4\u30EB\u304C\u6B8B\u3063\u3066\u304A\u308A\u3001\u81EA\u52D5\u3067\u306F\u524A\u9664\u3055\u308C\u307E\u305B\u3093\u3002\u6B21\u306E\u3069\u3061\u3089\u304B\u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002
|
|
20
|
+
\u518D\u767B\u9332: twp api /v2/media/files/${id}/complete --method POST --yes
|
|
21
|
+
`+discardGuidance(id)}async function upload(input,ctx){const file=requireResolved(input,"file");const size=Number(requireResolved(input,"fileSize"));const contentType=requireResolved(input,"contentType");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}`)}
|
|
22
|
+
const localHash=crypto.createHash("sha256").update(bytes).digest("hex");await checkUploadQuota(ctx,size);const{id,uploadUrl}=issued(await ctx.send(uploadUrlPlan(input)));try{await ctx.putSigned(uploadUrl,bytes,contentType)}catch(err){ctx.warn(orphanGuidance(id,"transfer"));throw err}let completed;try{completed=dataOf(await ctx.send({method:"POST",path:`${filePath(id)}/complete`,body:{}}),"\u5B8C\u4E86\u767B\u9332")}catch(err){ctx.warn(orphanGuidance(id,"complete"));throw err}const serverHash=completed["\
|
|
23
|
+
content_hash"];if(typeof serverHash==="string"&&serverHash!==""){if(serverHash.toLowerCase()!==localHash){ctx.warn(`\u30D5\u30A1\u30A4\u30EB ${id} \u306F\u30B5\u30FC\u30D0\u306B\u767B\u9332\u6E08\u307F\u306E\u307E\u307E\u6B8B\u3063\u3066\u3044\u307E\u3059\u3002
|
|
24
|
+
${discardGuidance(id)}`);throw new ApiResponseError(`\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3057\u305F\u30D5\u30A1\u30A4\u30EB ${id} \u306E\u5185\u5BB9\u304C\u30ED\u30FC\u30AB\u30EB\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093\uFF08\u30ED\u30FC\u30AB\u30EB sha256 ${localHash} / \u30B5\u30FC\u30D0 ${serverHash}\uFF09\u3002`)}}else{ctx.warn(`\u30B5\u30FC\u30D0\u304C content_hash \u3092\u8FD4\u3055\u306A\u304B\u3063\u305F\u305F\u3081\u3001\u30D5\u30A1\u30A4\u30EB ${id} \u306E\u5185\u5BB9\u306F\u7167\u5408\u3057\u3066\u3044\u307E\u305B\u3093\u3002`)}
|
|
25
|
+
return completed}var BULK_MAX=100;var BULK_DOWNLOAD_MAX=50;function bulkIds(input,usage,max){const ids=input.args.map(arg=>arg.trim()).filter(arg=>arg!=="");if(ids.length===0)throw new UsageError("\u30D5\u30A1\u30A4\u30EBID \u30921\u3064\u4EE5\u4E0A\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",usage);if(ids.length>max)throw new UsageError(`\u4E00\u5EA6\u306B\u6307\u5B9A\u3067\u304D\u308B\u30D5\u30A1\u30A4\u30EB\u306F ${max} \u4EF6\u307E\u3067\u3067\u3059\uFF08${ids.length} \u4EF6\u6307\u5B9A\uFF09`,
|
|
26
|
+
usage);const bad=ids.filter(id=>!UUID.test(id));if(bad.length>0)throw new UsageError(`\u30D5\u30A1\u30A4\u30EBID\uFF08UUID\uFF09\u306E\u5F62\u5F0F\u304C\u9055\u3044\u307E\u3059: ${bad.join(" ")}`,usage);const duplicated=ids.filter((id,index)=>ids.indexOf(id)!==index);if(duplicated.length>0)throw new UsageError(`\u540C\u3058\u30D5\u30A1\u30A4\u30EBID \u304C\u91CD\u8907\u3057\u3066\u3044\u307E\u3059: ${[...new Set(duplicated)].join(" ")}`,usage);return ids}function bulkResult(body,label){const data=dataOf(
|
|
27
|
+
body,label);const{success,failed}=data;const rolledBack=data["rolled_back"]??[];if(!Array.isArray(success)||!Array.isArray(failed)||!Array.isArray(rolledBack)){throw new ApiResponseError(`${label}\u306E\u5FDC\u7B54\u306B data.success / failed \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}return{success:success.map(String),failed:failed.map(row=>({id:String(isRecord(row)?row["id"]??row["file_id"]:row),reason:String(isRecord(
|
|
28
|
+
row)?row["reason"]??row["error"]??"":"")})),rolledBack:rolledBack.map(String)}}function assertBulkSucceeded(result,requested,label,ctx){if(result.failed.length===0)return;const lines=[`${label}: ${requested} \u4EF6\u4E2D ${result.failed.length} \u4EF6\u304C\u5931\u6557\u3057\u307E\u3057\u305F\u3002`];for(const row of result.failed)lines.push(` \u5931\u6557: ${row.id}\uFF08${row.reason}\uFF09`);lines.push(result.success.length===0?" \u9069\u7528\u3055\u308C\u305F\u30D5\u30A1\u30A4\u30EB\u306F\u3042\u308A\u307E\u305B\u3093\u3002":
|
|
29
|
+
` \u9069\u7528\u6E08\u307F\uFF08\u623B\u3055\u308C\u3066\u3044\u306A\u3044\uFF09: ${result.success.join(" ")}`);if(result.rolledBack.length>0)lines.push(` \u5931\u6557\u306E\u305F\u3081\u5143\u306B\u623B\u3057\u305F\u3082\u306E: ${result.rolledBack.join(" ")}`);ctx.warn(lines.join("\n"));throw new ApiRejectedError(`${label}\u306F\u5B8C\u4E86\u3057\u3066\u3044\u307E\u305B\u3093\uFF08${result.failed.length} \u4EF6\u5931\u6557\u30FB${result.success.length} \u4EF6\u9069\u7528\uFF09\u3002`)}function bulkSummary(body){
|
|
30
|
+
const data=isRecord(body)?body["data"]:void 0;const count=key=>isRecord(data)&&Array.isArray(data[key])?data[key].length:0;return{message:isRecord(body)?body["message"]??null:null,success:count("success"),failed:count("failed"),rolled_back:count("rolled_back")}}var BULK_STATUS_OPERATIONS=[{name:"bulk-publish",endpoint:"publish",label:"\u4E00\u62EC\u516C\u958B",summary:"\u8907\u6570\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u516C\u958B\u3059\u308B",description:"\u30D5\u30A1\u30A4\u30EB\u3092\u516C\u958B\u72B6\u614B\u306B\u3057\u307E\u3059\u3002"},
|
|
31
|
+
{name:"bulk-unpublish",endpoint:"unpublish",label:"\u4E00\u62EC\u975E\u516C\u958B",summary:"\u8907\u6570\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u975E\u516C\u958B\u306B\u3059\u308B",description:"\u30D5\u30A1\u30A4\u30EB\u3092\u975E\u516C\u958B\uFF08\u4E0B\u66F8\u304D\uFF09\u306B\u623B\u3057\u307E\u3059\u3002"},{name:"bulk-archive",endpoint:"archive",label:"\u4E00\u62EC\u30A2\u30FC\u30AB\u30A4\u30D6",summary:"\u8907\u6570\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u30A2\u30FC\u30AB\u30A4\u30D6\u3059\u308B",
|
|
32
|
+
description:"\u30D5\u30A1\u30A4\u30EB\u3092\u30A2\u30FC\u30AB\u30A4\u30D6\u72B6\u614B\u306B\u3057\u307E\u3059\uFF08\u524A\u9664\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF09\u3002"},{name:"bulk-restore",endpoint:"restore",label:"\u4E00\u62EC\u5FA9\u5143",summary:"\u30B4\u30DF\u7BB1\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u5FA9\u5143\u3059\u308B",description:"twp media delete / bulk-delete \u3067\u30B4\u30DF\u7BB1\u3078\u79FB\u3057\u305F\u30D5\u30A1\u30A4\u30EB\u3092\u5143\u306B\u623B\u3057\u307E\u3059\uFF08\u30A2\u30FC\u30AB\u30A4\u30D6\u306E\u89E3\u9664\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF09\u3002"}];
|
|
33
|
+
function bulkUsage(name,extra=""){return`twp media ${name} <\u30D5\u30A1\u30A4\u30EBID>...${extra}`}function bulkStatusOperation(spec){const usage=bulkUsage(spec.name);return{name:spec.name,summary:spec.summary,usage,description:`${spec.description}
|
|
34
|
+
\u30D5\u30A1\u30A4\u30EBID\uFF08twp media list \u306E id\uFF09\u3092\u4F4D\u7F6E\u5F15\u6570\u3067\u4E26\u3079\u307E\u3059\uFF08${BULK_MAX} \u4EF6\u307E\u3067\uFF09\u3002
|
|
35
|
+
`+BULK_FAILURE_HELP,flags:[],plan:input=>({method:"POST",path:`/api/v2/media/files/bulk/${spec.endpoint}`,body:{file_ids:bulkIds(input,usage,BULK_MAX)}}),plannedNotes:input=>[`${bulkIds(input,usage,BULK_MAX).length} \u4EF6\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u5BFE\u8C61\u306B\u3057\u307E\u3059\u3002`],execute:(input,ctx)=>runBulk(ctx,bulkIds(input,usage,BULK_MAX),spec.endpoint,spec.label,{}),summarize:bulkSummary,raw:body=>body}}var BULK_FAILURE_HELP="1\u4EF6\u3067\u3082\u5931\u6557\u3059\u308B\u3068\u7D42\u4E86\u30B3\u30FC\u30C9 3 \u3067\u7D42\u308F\u308A\u3001\u5931\u6557\u3057\u305F\u30D5\u30A1\u30A4\u30EB\u3068\u7406\u7531\u30FB\u9069\u7528\u6E08\u307F\u306E\u30D5\u30A1\u30A4\u30EB\u3092\
|
|
36
|
+
stderr \u306B\u51FA\u3057\u307E\u3059\n\uFF08\u30B5\u30FC\u30D0\u306F\u5931\u6557\u304C\u3042\u3063\u3066\u3082 HTTP 200 \u3092\u8FD4\u3059\u305F\u3081\uFF09\u3002bulk-publish / bulk-unpublish / bulk-archive \u306F\n\u5B58\u5728\u3057\u306A\u3044 ID \u304C1\u4EF6\u3067\u3082\u3042\u308B\u3068\u4ED6\u3082\u9069\u7528\u3057\u307E\u305B\u3093\u3002bulk-restore / bulk-move / bulk-delete \u306F1\u4EF6\u305A\u3064\u51E6\u7406\u3057\u3001\n\u5931\u6557\u3057\u305F\u3082\u306E\u4EE5\u5916\u306F\u9069\u7528\u3055\u308C\u307E\u3059\u3002";
|
|
37
|
+
async function runBulk(ctx,ids,endpoint,label,extra){const body=await ctx.send({method:"POST",path:`/api/v2/media/files/bulk/${endpoint}`,body:{file_ids:ids,...extra}});assertBulkSucceeded(bulkResult(body,label),ids.length,label,ctx);return body}var PERMANENT_FLAG={name:"--permanent",summary:"\u30B4\u30DF\u7BB1\u306B\u3042\u308B\u30D5\u30A1\u30A4\u30EB\u3092\u5B8C\u5168\u306B\u524A\u9664\u3059\u308B\uFF08\u5FA9\u5143\u3067\u304D\u307E\u305B\u3093\u3002\u5148\u306B bulk-delete \u3067\u30B4\u30DF\u7BB1\u3078\u79FB\u3059\u3053\u3068\uFF09",
|
|
38
|
+
takesValue:false};var MOVE_FOLDER_FLAG={name:"--folder",summary:"\u79FB\u52D5\u5148\u306E\u30D5\u30A9\u30EB\u30C0ID\uFF08\u7701\u7565\u6642\u306F\u30B9\u30B3\u30FC\u30D7\u306E\u6700\u4E0A\u4F4D\uFF09",takesValue:true,placeholder:"<\u30D5\u30A9\u30EB\u30C0ID>"};var MOVE_PROJECT_FLAG={name:"--project",summary:"\u79FB\u52D5\u5148\u3092\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30D5\u30A1\u30A4\u30EB\u306B\u3059\u308B\uFF08\u30B3\u30FC\u30C9\u307E\u305F\u306F ID\uFF09\u3002\u7701\u7565\u6642\u306F\u81EA\u5206\u306E\u500B\u4EBA\u30D5\u30A1\u30A4\u30EB",
|
|
39
|
+
takesValue:true,placeholder:"<\u30B3\u30FC\u30C9|ID>"};var BULK_DELETE_USAGE=bulkUsage("bulk-delete"," --yes [--permanent]");var BULK_MOVE_USAGE=bulkUsage("bulk-move"," [--project <\u30B3\u30FC\u30C9|ID>] [--folder <\u30D5\u30A9\u30EB\u30C0ID>]");var BULK_DOWNLOAD_USAGE=bulkUsage("bulk-download"," --out <\u30D1\u30B9.zip> [--force]");function bulkDeleteEndpoint(input){return input.flags.has("--permanent")?{endpoint:"permanent-delete",label:"\u4E00\u62EC\u5B8C\u5168\u524A\u9664"}:{endpoint:"delet\
|
|
40
|
+
e",label:"\u4E00\u62EC\u524A\u9664"}}var BULK_OPERATIONS=[...BULK_STATUS_OPERATIONS.map(bulkStatusOperation),{name:"bulk-move",summary:"\u8907\u6570\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u5225\u306E\u30D5\u30A9\u30EB\u30C0\u30FB\u30B9\u30B3\u30FC\u30D7\u3078\u79FB\u3059",usage:BULK_MOVE_USAGE,description:"\u79FB\u52D5\u5148\u306F --project\uFF08\u7121\u3051\u308C\u3070\u81EA\u5206\u306E\u500B\u4EBA\u30D5\u30A1\u30A4\u30EB\uFF09\u3068 --folder\uFF08\u7121\u3051\u308C\u3070\u6700\u4E0A\u4F4D\uFF09\u3067\u6C7A\u307E\u308A\u307E\u3059\u3002\n--project \u3092\u4ED8\u3051\u306A\u3044\u3068\u304D\u3001\u65E2\u5B9A\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\uFF08TWP_PROJECT \u7B49\uFF09\u306F\u4F7F\u3044\u307E\u305B\u3093\uFF08\u500B\u4EBA\u30D5\u30A1\u30A4\u30EB\u3078\u79FB\u3057\u307E\u3059\uFF09\u3002\n"+
|
|
41
|
+
BULK_FAILURE_HELP,flags:[MOVE_PROJECT_FLAG,MOVE_FOLDER_FLAG],async prepare(input,ctx){bulkIds(input,BULK_MOVE_USAGE,BULK_MAX);folderId(input);const scope=await resolveScope(input,ctx);const scopeId=scope["scopeId"]??(await ctx.resolver.currentUser()).id;return withResolved(input,{scope:requireScope(scope),scopeId})},plan:input=>({method:"POST",path:"/api/v2/media/files/bulk/move",body:bulkMoveBody(input)}),plannedNotes:input=>[`${bulkIds(input,BULK_MOVE_USAGE,BULK_MAX).length} \u4EF6\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u79FB\u3057\u307E\u3059\u3002`],
|
|
42
|
+
execute:(input,ctx)=>{const{file_ids:ids,...extra}=bulkMoveBody(input);return runBulk(ctx,ids,"move","\u4E00\u62EC\u79FB\u52D5",extra)},summarize:bulkSummary,raw:body=>body},{name:"bulk-delete",summary:"\u8907\u6570\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u30B4\u30DF\u7BB1\u3078\u79FB\u3059\uFF08--permanent \u3067\u30B4\u30DF\u7BB1\u304B\u3089\u5B8C\u5168\u524A\u9664\uFF09",usage:BULK_DELETE_USAGE,description:"\u65E2\u5B9A\u306F\u30B4\u30DF\u7BB1\u3078\u79FB\u3059\u3060\u3051\u3067\u3001twp media bulk-restore \u3067\u623B\u305B\u307E\u3059\u3002\n--permanent \u3092\u4ED8\u3051\u308B\u3068\u30B4\u30DF\u7BB1\u306B\u3042\u308B\u30D5\u30A1\u30A4\u30EB\u3092\u5B8C\u5168\u306B\u524A\u9664\u3057\u3001\u5FA9\u5143\u3067\u304D\u307E\u305B\u3093\u3002\n\u30B4\u30DF\u7BB1\
|
|
43
|
+
\u306B\u7121\u3044\u30D5\u30A1\u30A4\u30EB\u306F\u5B8C\u5168\u524A\u9664\u3067\u304D\u307E\u305B\u3093\uFF08\u30B5\u30FC\u30D0\u304C\u300C\u5148\u306B\u30B4\u30DF\u7BB1\u306B\u79FB\u52D5\u3057\u3066\u304F\u3060\u3055\u3044\u300D\u3067\u62D2\u5426\u3057\u307E\u3059\uFF09\u3002\n\u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3068\u3057\u3066\u6271\u3046\u305F\u3081 --yes \u304C\u5FC5\u8981\u3067\u3059\u3002\u5BFE\u8C61\u4EF6\u6570\u306F --dry-run \u3067\u78BA\u8A8D\u3067\u304D\u307E\u3059\u3002\n"+BULK_FAILURE_HELP,
|
|
44
|
+
destructive:true,flags:[PERMANENT_FLAG],plan:input=>({method:"POST",path:`/api/v2/media/files/bulk/${bulkDeleteEndpoint(input).endpoint}`,body:{file_ids:bulkIds(input,BULK_DELETE_USAGE,BULK_MAX)}}),plannedNotes:input=>[input.flags.has("--permanent")?`${bulkIds(input,BULK_DELETE_USAGE,BULK_MAX).length} \u4EF6\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u5B8C\u5168\u306B\u524A\u9664\u3057\u307E\u3059\uFF08\u5FA9\u5143\u3067\u304D\u307E\u305B\u3093\uFF09\u3002`:`${bulkIds(input,BULK_DELETE_USAGE,BULK_MAX).
|
|
45
|
+
length} \u4EF6\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u30B4\u30DF\u7BB1\u3078\u79FB\u3057\u307E\u3059\u3002`],execute:(input,ctx)=>{const{endpoint,label}=bulkDeleteEndpoint(input);return runBulk(ctx,bulkIds(input,BULK_DELETE_USAGE,BULK_MAX),endpoint,label,{})},summarize:bulkSummary,raw:body=>body},{name:"bulk-download",summary:"\u8907\u6570\u306E\u30D5\u30A1\u30A4\u30EB\u3092 ZIP \u306B\u307E\u3068\u3081\u3066\u66F8\u304D\u51FA\u3059",usage:BULK_DOWNLOAD_USAGE,description:`\u30B5\u30FC\u30D0\u304C ZIP \u3092\u4F5C\u308A\u3001\u305D\u306E\u7F72\u540DURL\u304B\u3089\u672C\u4F53\u3092\
|
|
46
|
+
\u53D7\u3051\u53D6\u308A\u307E\u3059\uFF08${BULK_DOWNLOAD_MAX} \u4EF6\u307E\u3067\uFF09\u3002
|
|
47
|
+
\u30B5\u30FC\u30D0\u306F\u5B58\u5728\u3057\u306A\u3044\u30FB\u8AAD\u3081\u306A\u3044\u30D5\u30A1\u30A4\u30EB\u3092\u9ED9\u3063\u3066\u9664\u3044\u3066 ZIP \u3092\u4F5C\u308B\u306E\u3067\u3001ZIP \u306B\u5165\u3063\u305F\u4EF6\u6570\u304C
|
|
48
|
+
\u6307\u5B9A\u3088\u308A\u5C11\u306A\u3051\u308C\u3070\u66F8\u304D\u51FA\u3055\u305A\u306B\u7D42\u4E86\u30B3\u30FC\u30C9 3 \u3067\u7D42\u308F\u308A\u307E\u3059\u3002
|
|
49
|
+
\u66F8\u304D\u51FA\u3057\u5148\u306F --out \u3067\u5FC5\u305A\u6307\u5B9A\u3057\u307E\u3059\u3002\u65E2\u5B58\u30D5\u30A1\u30A4\u30EB\u306F --force \u304C\u7121\u3051\u308C\u3070\u4E0A\u66F8\u304D\u3057\u307E\u305B\u3093\u3002`,flags:[OUT_FLAG,FORCE_FLAG],download:{outFlag:"--out",forceFlag:"--force",signedUrl(body,plan){const data=dataOf(body,"\u4E00\u62EC\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9");const requested=isRecord(plan.body)&&Array.isArray(plan.body["file_ids"])?plan.body["file_ids"].length:
|
|
50
|
+
0;const packed=data["file_count"];if(typeof packed==="number"&&packed<requested){throw new ApiRejectedError(`ZIP \u306B\u5165\u3063\u305F\u306E\u306F ${requested} \u4EF6\u4E2D ${packed} \u4EF6\u3067\u3057\u305F\uFF08\u5B58\u5728\u3057\u306A\u3044\u30FB\u8AAD\u3081\u306A\u3044\u30D5\u30A1\u30A4\u30EB\u304C\u9664\u304B\u308C\u3066\u3044\u307E\u3059\uFF09\u3002\u66F8\u304D\u51FA\u3057\u3066\u3044\u307E\u305B\u3093\u3002twp media list \u3067 ID \u3092\u78BA\u304B\u3081\u3066\u6307\u5B9A\u3057\u76F4\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}
|
|
51
|
+
const url=data["download_url"];if(typeof url!=="string"||!/^https:\/\//.test(url)){throw new ApiResponseError("\u4E00\u62EC\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u306E\u5FDC\u7B54\u306B data.download_url \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return url}},plan:input=>({method:"POST",path:"/api/v2/media/files/bulk/download",body:{file_ids:bulkIds(input,BULK_DOWNLOAD_USAGE,BULK_DOWNLOAD_MAX)}}),summarize:body=>body,raw:body=>body}];
|
|
52
|
+
function requireScope(scope){const value=scope["scope"];if(value===void 0)throw new Error("resolveScope \u304C scope \u3092\u8FD4\u3057\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u914D\u7DDA\u306E\u8AA4\u308A\uFF09");return value}function bulkMoveBody(input){const body={file_ids:bulkIds(input,BULK_MOVE_USAGE,BULK_MAX),scope:requireResolved(input,"scope"),scope_id:requireResolved(input,"scopeId")};const folder=folderId(input);if(folder!==void 0)body["folder_id"]=folder;return body}var LIST_USAGE="\
|
|
53
|
+
twp media list [--project <\u30B3\u30FC\u30C9|ID>] [--folder <\u30D5\u30A9\u30EB\u30C0ID>] [--keyword <\u8A9E>]";var UPLOAD_USAGE="twp media upload --file <\u30D1\u30B9> [--project <\u30B3\u30FC\u30C9|ID>] [--folder <\u30D5\u30A9\u30EB\u30C0ID>] [--name <\u540D\u524D>]";var DOWNLOAD_USAGE="twp media download <\u30D5\u30A1\u30A4\u30EBID> --out <\u30D1\u30B9> [--force]";var DELETE_USAGE="twp media delete <\u30D5\u30A1\u30A4\u30EBID> --yes";var mediaDomain={name:"media",summary:"\u30E1\u30C7\u30A3\u30A2\u30E9\u30A4\u30D6\u30E9\u30EA\u306E\u30D5\u30A1\u30A4\u30EB\uFF08\u30A2\u30C3\u30D7\u30ED\
|
|
54
|
+
\u30FC\u30C9\u30FB\u4E00\u89A7\u30FB\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u30FB\u524A\u9664\u30FB\u4E00\u62EC\u64CD\u4F5C\uFF09",operations:[{name:"list",summary:"\u30D5\u30A1\u30A4\u30EB\u3092\u4E00\u89A7\u3059\u308B\uFF08\u65E2\u5B9A\u306F\u81EA\u5206\u306E\u500B\u4EBA\u30D5\u30A1\u30A4\u30EB\uFF09",usage:LIST_USAGE,description:"--project \u3092\u4ED8\u3051\u308B\u3068\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30D5\u30A1\u30A4\u30EB\u3001\u7121\u3051\u308C\u3070\u81EA\u5206\u306E\u500B\u4EBA\u30D5\u30A1\u30A4\u30EB\u3092\u8FD4\u3057\u307E\u3059\u3002\n\u30D5\u30A9\u30EB\u30C0\u3092\u4ED8\u3051\u306A\u3051\u308C\u3070\u30B9\u30B3\u30FC\u30D7\u306E\u6700\u4E0A\u4F4D\u306B\u3042\u308B\u30D5\u30A1\u30A4\u30EB\u3060\u3051\u3067\u3059\uFF08\u4E0B\u4F4D\u30D5\u30A9\u30EB\u30C0\u306F\u542B\u307F\u307E\u305B\u3093\uFF09\u3002\n\n"+
|
|
55
|
+
LIST_PAGING_HELP,flags:[MEDIA_PROJECT_FLAG,FOLDER_FLAG,KEYWORD_FLAG,...LIST_FLAGS],paging:envelopePaging({label:"\u30E1\u30C7\u30A3\u30A2\u4E00\u89A7",itemsKey:"data"}),async prepare(input,ctx){if(input.args.length>0){throw new UsageError(`list \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D7\u3051\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,LIST_USAGE)}return withResolved(input,await resolveScope(input,ctx))},plan(input){const resolved=input.resolved??{};const keyword=nonEmpty(input.flags,
|
|
56
|
+
"--keyword");return{method:"GET",path:"/api/v2/media/files",query:{scope:requireResolved(input,"scope"),scope_id:resolved["scopeId"],folder_id:folderId(input),keyword,limit:positiveInteger(input.flags,"--limit"),cursor:nonEmpty(input.flags,"--cursor")}}},summarize:body=>listRows(body).map(row=>pick(row,LIST_COLUMNS)),raw:body=>listRows(body),notes(body,input){if(nonEmpty(input.flags,"--keyword")===void 0)return[];const meta=isRecord(body)?body["meta"]:void 0;const total=isRecord(meta)?meta["tota\
|
|
57
|
+
l"]:void 0;const shown=listRows(body).length;if(typeof total!=="number"||total<=shown)return[];return[`\u691C\u7D22\u7D50\u679C ${total} \u4EF6\u306E\u3046\u3061 ${shown} \u4EF6\u3060\u3051\u3092\u8868\u793A\u3057\u3066\u3044\u307E\u3059\uFF08\u691C\u7D22\u306F\u30DA\u30FC\u30B8\u30F3\u30B0\u3057\u307E\u305B\u3093\u3002--limit \u3092\u4E0A\u3052\u308B\u304B\u8A9E\u3092\u7D5E\u3063\u3066\u304F\u3060\u3055\u3044\uFF09\u3002`]}},{name:"upload",summary:"\u30ED\u30FC\u30AB\u30EB\u30D5\u30A1\u30A4\u30EB\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3059\u308B\uFF08\u767A\u884C\u30FB\u8EE2\u9001\u30FB\u5B8C\u4E86\u767B\u9332\u30921\u30B3\u30DE\u30F3\u30C9\u3067\uFF09",
|
|
58
|
+
usage:UPLOAD_USAGE,description:"\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\n 0. POST /api/v2/storage/check-upload\uFF08\u30C6\u30CA\u30F3\u30C8\u306E\u5BB9\u91CF\u691C\u67FB\u3002\u8D85\u904E\u306A\u3089\u4F55\u3082\u767B\u9332\u305B\u305A\u306B\u6B62\u307E\u308A\u307E\u3059\uFF09\n 1. POST /api/v2/media/files/upload-url\uFF08\u7F72\u540DURL\u306E\u767A\u884C\u3002\u3053\u3053\u3067\u30D5\u30A1\u30A4\u30EB\u304C\u4EEE\u767B\u9332\u3055\u308C\u307E\u3059\uFF09\n 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\n 3. POST /api/v2/media/files/{id}/complete\uFF08\u5B8C\u4E86\u767B\u9332\uFF09\n\u5B8C\u4E86\u767B\u9332\u306E\u5FDC\u7B54\u306E content_hash\uFF08sha256\uFF09\u3092\u30ED\u30FC\u30AB\u30EB\u306E\u30D5\u30A1\u30A4\u30EB\u3068\u7A81\u304D\u5408\u308F\u305B\u3001\u4E00\u81F4\u3057\u306A\u3051\u308C\u3070\u5931\u6557\u3057\u307E\u3059\u3002\n2\u30FB3 \u304C\u5931\u6557\u3057\u305F\u5834\u5408\u306F\u30D5\u30A1\u30A4\u30EBID\u3068\u518D\u767B\u9332\u30FB\u7834\u68C4\u306E\u624B\u9806\u3092 stderr \u306B\u51FA\u3057\u3066\u5931\u6557\u3057\u307E\u3059\uFF08\u4EEE\u767B\u9332\u306F\u81EA\u52D5\u3067\u306F\u6D88\u3048\u307E\u305B\u3093\uFF09\u3002\n--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",
|
|
59
|
+
flags:[FILE_FLAG,MEDIA_PROJECT_FLAG,FOLDER_FLAG,NAME_FLAG,CONTENT_TYPE_FLAG],async prepare(input,ctx){const local=localFile(input);folderId(input);return withResolved(input,{...await resolveScope(input,ctx),file:local.file,fileName:local.name,fileSize:String(local.size),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(
|
|
60
|
+
input,"fileSize")} \u30D0\u30A4\u30C8\u3092 PUT \u3057\u3001\u5B8C\u4E86\u767B\u9332\uFF08POST \u2026/complete\uFF09\u3092\u9001\u308A\u307E\u3059\u3002`],execute:upload,summarize:body=>pick(body,UPLOAD_COLUMNS),raw:body=>body},{name:"download",summary:"\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u3057\u3066\u30D5\u30A1\u30A4\u30EB\u3078\u66F8\u304D\u51FA\u3059",usage:DOWNLOAD_USAGE,description:"\u30D5\u30A1\u30A4\u30EBID \u306F twp media list \u306E id \u3067\u3059\u3002\n\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u7528\u306E\u7F72\u540DURL\u3092\u53D6\u5F97\u3057\u3066\u304B\u3089\u672C\u4F53\u3092\u53D7\u3051\u53D6\u308A\u307E\u3059\uFF08\u7F72\u540DURL\u3078 TWP \u306E\u8A8D\u8A3C\u60C5\
|
|
61
|
+
\u5831\u306F\u9001\u308A\u307E\u305B\u3093\uFF09\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",flags:[FILE_REF_FLAG,OUT_FLAG,FORCE_FLAG],download:{outFlag:"--out",forceFlag:"--force",signedUrl(body){const url=dataOf(body,"\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9URL\u53D6\u5F97")["\
|
|
62
|
+
download_url"];if(typeof url!=="string"||!/^https:\/\//.test(url)){throw new ApiResponseError("\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9URL\u53D6\u5F97\u306E\u5FDC\u7B54\u306B data.download_url \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return url}},plan:input=>({method:"GET",path:`${filePath(fileRef(input,DOWNLOAD_USAGE))}/download-url`}),summarize:body=>body,raw:body=>body},{name:"delete",summary:"\u30D5\u30A1\u30A4\u30EB\u3092\u30B4\u30DF\u7BB1\u3078\u79FB\u3059",
|
|
63
|
+
usage:DELETE_USAGE,description:"\u30B4\u30DF\u7BB1\u3078\u79FB\u3059\u3060\u3051\u3067\u3001\u753B\u9762\u306E\u30B4\u30DF\u7BB1\u304B\u3089\u5FA9\u5143\u3067\u304D\u307E\u3059\uFF08\u5B8C\u5168\u524A\u9664\u306F\u3057\u307E\u305B\u3093\uFF09\u3002\n\u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3068\u3057\u3066\u6271\u3046\u305F\u3081 --yes \u304C\u5FC5\u8981\u3067\u3059\u3002",destructive:true,flags:[FILE_REF_FLAG],plan:input=>({method:"DELETE",path:filePath(fileRef(input,DELETE_USAGE))}),summarize:body=>body,
|
|
64
|
+
raw:body=>body},...BULK_OPERATIONS]};export{mediaDomain,orphanGuidance};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{activateModeFiles,activatePermissionSettings,buildResidentSet,buildSystemPrompt,createAuditLogger,currentBranch,displayCwd,runTurn}from"./chunk-
|
|
4
|
-
import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";async function runOneShot(opts,deps={}){const out=deps.out??(text=>void process.stdout.write(stripTerminalControls(text)));const err=deps.err??(text=>void process.stderr.write(stripTerminalControls(text)));activateModeFiles(err);const permissionLayers=activatePermissionSettings(err,{...opts.allowedTools?{allowedTools:opts.allowedTools}:{},...opts.disallowedTools?{disallowedTools:opts.disallowedTools}:{}});const prompt=opts.fromStdin?await(deps.readStdin??readStdin)():opts.prompt;if(prompt.trim()===
|
|
3
|
+
import{activateModeFiles,activatePermissionSettings,buildResidentSet,buildSystemPrompt,createAuditLogger,createTwpToolkit,currentBranch,displayCwd,residentInputs,runTurn}from"./chunk-4V4T5ZUS.js";import"./chunk-NZ7WI4RZ.js";import"./chunk-N2UVRM3Z.js";import"./chunk-YVAN3H5W.js";import"./chunk-QOUFHYK5.js";import"./chunk-II5RVJQN.js";import"./chunk-FTYJZFEK.js";import"./chunk-GMBJTG6A.js";import{getMode}from"./chunk-NAUH75MM.js";import{RelayError,
|
|
4
|
+
createRuntime,pickModel}from"./chunk-WOUKWOAR.js";import"./chunk-XNLIEUAW.js";import"./chunk-PMOUHEJQ.js";import"./chunk-J7QYPKVK.js";import{checkMinSupportedVersion,enforceMinSupportedVersion,floorNeedsRefresh}from"./chunk-DXXFUNYN.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";async function runOneShot(opts,deps={}){const out=deps.out??(text=>void process.stdout.write(stripTerminalControls(text)));const err=deps.err??(text=>void process.stderr.write(stripTerminalControls(text)));activateModeFiles(err);const permissionLayers=activatePermissionSettings(err,{...opts.allowedTools?{allowedTools:opts.allowedTools}:{},...opts.disallowedTools?{disallowedTools:opts.disallowedTools}:{}});const prompt=opts.fromStdin?await(deps.readStdin??readStdin)():opts.prompt;if(prompt.trim()===
|
|
5
5
|
""){err('\u30D7\u30ED\u30F3\u30D7\u30C8\u304C\u7A7A\u3067\u3059\u3002`twp -p "\u8CEA\u554F"`\uFF08`-p -` \u3067\u6A19\u6E96\u5165\u529B\uFF09\n');return 2}const runtime=deps.runtime??createRuntime({...opts.profile!==void 0?{profile:opts.profile}:{},...opts.model!==void 0?{model:opts.model}:{},cliVersion:opts.version});const cachedFloor=runtime.loadCachedFloor();if(await checkMinSupportedVersion({current:opts.version,cachedFloor:cachedFloor.minSupportedVersion,refresh:async()=>(await runtime.loadCatalog()).
|
|
6
6
|
minSupportedVersion,write:err})){return 1}if(!runtime.loggedIn){err("\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u3044\u307E\u305B\u3093\u3002`twp login` \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002\n");return 1}let model=runtime.configuredModel??"";let catalog=null;if(model===""){catalog=await runtime.loadCatalog();const picked=pickModel(catalog,void 0);model=picked.model;if(catalog.source!=="server"){err(`\u26A0 \u30E2\u30C7\u30EB\u4E00\u89A7\u3092\u53D6\u5F97\u3067\u304D\u306A\u304B\u3063\u305F\u305F\u3081 ${model}\
|
|
7
7
|
\u3067\u5B9F\u884C\u3057\u307E\u3059\uFF08${catalog.source}\uFF09
|
|
8
|
-
`)}}else if(floorNeedsRefresh(cachedFloor.fetchedAt)){catalog=await runtime.loadCatalog()}if(catalog!==null&&enforceMinSupportedVersion({current:opts.version,floor:catalog.minSupportedVersion,write:err})){return 1}const controller=new AbortController;let interrupted=false;const onSigint=()=>{interrupted=true;controller.abort()};process.on("SIGINT",onSigint);let wroteText=false;let ownedAudit=null;try{const mode=getMode(opts.mode);const
|
|
9
|
-
{permissionMode:opts.permissionMode}:{},permissionLayers});const audit=deps.audit??(ownedAudit=createAuditLogger({mode:mode.id,permissionMode:opts.permissionMode,model,cwd:process.cwd(),cliVersion:opts.version,interactive:false,onOpen:file=>err(`audit: ${file}
|
|
8
|
+
`)}}else if(floorNeedsRefresh(cachedFloor.fetchedAt)){catalog=await runtime.loadCatalog()}if(catalog!==null&&enforceMinSupportedVersion({current:opts.version,floor:catalog.minSupportedVersion,write:err})){return 1}const controller=new AbortController;let interrupted=false;const onSigint=()=>{interrupted=true;controller.abort()};process.on("SIGINT",onSigint);let wroteText=false;let ownedAudit=null;try{const mode=getMode(opts.mode);const toolkit=createTwpToolkit(runtime,opts.version);const resident=buildResidentSet(
|
|
9
|
+
mode,{...residentInputs(toolkit),...opts.permissionMode!==void 0?{permissionMode:opts.permissionMode}:{},permissionLayers});const audit=deps.audit??(ownedAudit=createAuditLogger({mode:mode.id,permissionMode:opts.permissionMode,model,cwd:process.cwd(),cliVersion:opts.version,interactive:false,onOpen:file=>err(`audit: ${file}
|
|
10
10
|
`)}));const result=await runTurn(runtime.client,runtime.context,{input:prompt,model,system:buildSystemPrompt({cwd:displayCwd(),branch:currentBranch(),modeLabel:mode.label,cliVersion:opts.version,toolNames:resident.tools.map(t=>t.name),...mode.prompt!==void 0?{modePrompt:mode.prompt}:{}}),signal:controller.signal,onTextDelta:delta=>{wroteText=true;out(stripTerminalControls(delta))},tools:resident.tools,execute:{mode,ctx:{cwd:process.cwd()},sessionAllow:new Set,permissionLayers,...opts.permissionMode!==
|
|
11
|
-
void 0?{permissionMode:opts.permissionMode}:{},audit},onToolUse:()=>{if(wroteText){out("\n");wroteText=false}},onToolResult:(call,result2)=>err(`tool: ${call.name} \u2192 ${result2.denied===true?"denied":result2.isError===true?"error":"ok"}
|
|
11
|
+
void 0?{permissionMode:opts.permissionMode}:{},resolveTool:toolkit.resolveTool,prepareIndirect:toolkit.prepareIndirect,audit},onToolUse:()=>{if(wroteText){out("\n");wroteText=false}},onToolResult:(call,result2)=>err(`tool: ${call.name} \u2192 ${result2.denied===true?"denied":result2.isError===true?"error":"ok"}
|
|
12
12
|
`)});if(result.text!==""&&!result.text.endsWith("\n"))out("\n");const u=result.usage;err(`usage: model=${model} input=${u.inputTokens} cache_read=${u.cacheReadTokens} cache_write=${u.cacheWriteTokens} output=${u.outputTokens}
|
|
13
13
|
`);if(result.droppedMessages>0){err(`\u26A0 \u30B3\u30F3\u30C6\u30AD\u30B9\u30C8\u4E0A\u9650\u306E\u305F\u3081\u53E4\u3044\u3084\u308A\u53D6\u308A ${result.droppedMessages} \u4EF6\u3092\u843D\u3068\u3057\u307E\u3057\u305F
|
|
14
14
|
`)}if(result.maxStepsReached){err("\u26A0 \u30C4\u30FC\u30EB\u5B9F\u884C\u306E\u5F80\u5FA9\u304C\u4E0A\u9650\u306B\u9054\u3057\u305F\u305F\u3081\u6253\u3061\u5207\u308A\u307E\u3057\u305F\uFF08\u7D9A\u304D\u306F\u540C\u3058\u4F1A\u8A71\u3067\u518D\u5EA6\u6307\u793A\u3057\u3066\u304F\u3060\u3055\u3044\uFF09\n");return 1}if(result.upstreamError!==null){err(`\u30E2\u30C7\u30EB\u306E\u5FDC\u7B54\u304C\u9014\u4E2D\u3067\u7D42\u308F\u308A\u307E\u3057\u305F: ${result.upstreamError}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{STATUS_VALUES,booleanQuery,flatMasterDomain}from"./chunk-WGVHYTZV.js";import"./chunk-IJLJGDMZ.js";import{POSITIONS_PATH}from"./chunk-QOUFHYK5.js";import"./chunk-II5RVJQN.js";import"./chunk-FTYJZFEK.js";import"./chunk-DMDVLOAY.js";import"./chunk-ZN5EFDH7.js";import"./chunk-GMBJTG6A.js";import"./chunk-ZWVYVS2A.js";import"./chunk-J7QYPKVK.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import"./chunk-NHYMHCAT.js";
|
|
4
|
+
import"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";var positionDomain=flatMasterDomain({name:"position",label:"\u5F79\u8077",path:POSITIONS_PATH,itemKey:"position",summary:"\u5F79\u8077\u30DE\u30B9\u30BF\uFF08\u4E00\u89A7\u30FB\u53D6\u5F97\u30FB\u4F5C\u6210\u30FB\u66F4\u65B0\u30FB\u524A\u9664\uFF09",listColumns:["id","code","name","rank","is_manager","status","user_count"],getColumns:["id","code","name","name_short","rank","is_manager","status","description"],fields:[{kind:"text",flag:"--name-short",key:"name_short",label:"\u7565\u79F0",maxChars:50,
|
|
5
|
+
summary:"\u7565\u79F0"},{kind:"integer",flag:"--rank",key:"rank",label:"\u30E9\u30F3\u30AF",min:0,max:9999,summary:"\u30E9\u30F3\u30AF\uFF080\u301C9999\u3002\u5927\u304D\u3044\u307B\u3069\u4E0A\u4F4D\uFF09"},{kind:"boolean",flag:"--manager",key:"is_manager",summary:"\u7BA1\u7406\u8077\u304B\uFF08true / false\uFF09"},{kind:"boolean",flag:"--can-view-personal-info",key:"can_view_personal_info",summary:"\u90E8\u4E0B\u306E\u500B\u4EBA\u60C5\u5831\u3092\u95B2\u89A7\u3067\u304D\u308B\u304B\uFF08true / false\uFF09"},
|
|
6
|
+
{kind:"boolean",flag:"--can-view-emergency-contact",key:"can_view_emergency_contact",summary:"\u90E8\u4E0B\u306E\u7DCA\u6025\u9023\u7D61\u5148\u3092\u95B2\u89A7\u3067\u304D\u308B\u304B\uFF08true / false\uFF09"},{kind:"boolean",flag:"--can-view-work-tel",key:"can_view_work_tel",summary:"\u90E8\u4E0B\u306E\u696D\u52D9\u7528\u96FB\u8A71\u756A\u53F7\u3092\u95B2\u89A7\u3067\u304D\u308B\u304B\uFF08true / false\uFF09"},{kind:"enum",flag:"--status",key:"status",values:STATUS_VALUES,summary:"\u72B6\u614B\uFF08active: \u6709\
|
|
7
|
+
\u52B9 / inactive: \u7121\u52B9\uFF09"},{kind:"text",flag:"--description",key:"description",label:"\u8AAC\u660E",maxChars:1e3,summary:"\u8AAC\u660E"}],listFilters:[{flag:{name:"--manager",summary:"\u7BA1\u7406\u8077\u304B\u3069\u3046\u304B\u3067\u7D5E\u308A\u8FBC\u3080\uFF08true / false\uFF09",takesValue:true,placeholder:"<true|false>"},query:"is_manager",value:raw=>booleanQuery("--manager",raw)}],resolve:(ctx,ref,flag)=>ctx.resolver.position(ref,flag),deleteGuidance:"\u4ECA\u5F8C\u4F7F\u308F\u306A\u3044\u5F79\u8077\u306F\u3001\u524A\u9664\u305B\u305A\u306B\u7121\u52B9\u5316\u3057\u3066\u304F\u3060\u3055\u3044: t\
|
|
8
|
+
wp position update <\u5F79\u8077> --status inactive\n\uFF08\u7121\u52B9\u306B\u3057\u305F\u5F79\u8077\u306F\u3001\u65B0\u3057\u3044\u6240\u5C5E\u306E\u9078\u629E\u80A2\u306B\u51FA\u306A\u304F\u306A\u308A\u307E\u3059\u3002\u904E\u53BB\u306E\u6240\u5C5E\u306E\u8A18\u9332\u306F\u305D\u306E\u307E\u307E\u6B8B\u308A\u307E\u3059\uFF09"});export{positionDomain};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{
|
|
3
|
+
import{LIST_FLAGS,LIST_PAGING_HELP,envelopePaging,nonEmpty,positiveInteger}from"./chunk-DMDVLOAY.js";import{requireResolved,withResolved}from"./chunk-ZN5EFDH7.js";import{collapsesInUrlPath,safeProjectIdPolicy}from"./chunk-GMBJTG6A.js";import{isRecord,pick}from"./chunk-ZWVYVS2A.js";import{ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";var LIST_COLUMNS=["id","code","name","status","effective_status"];var GET_COLUMNS=["id","code","name","status","effective_status","display_flg","closed_flg","task_enabled_flg","start_date","end_date","created_at","updated_at"];var MEMBER_COLUMNS=["user_id","user_name","user_email","role","alias","department_name"];function memberItems(body){const list=isRecord(body)?body["list"]:void 0;if(!Array.isArray(list)){throw new ApiResponseError("\u30E1\u30F3\u30D0\u30FC\u4E00\u89A7\u306E\u5FDC\u7B54\u306B list \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
4
4
|
return list}var listPaging=envelopePaging({label:"\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u4E00\u89A7"});function listItems(body){return listPaging.items(body)}function projectObject(body){const project=isRecord(body)?body["project"]:void 0;if(!isRecord(project)){throw new ApiResponseError("\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u8A73\u7D30\u306E\u5FDC\u7B54\u306B project \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return project}
|
|
5
5
|
var projectDomain={name:"project",summary:"\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u4E00\u89A7\u30FB\u8A73\u7D30",operations:[{name:"list",summary:"\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3092\u4E00\u89A7\u3059\u308B",usage:"twp project list [--all] [--limit <\u4EF6\u6570>] [--cursor <\u30AB\u30FC\u30BD\u30EB>] [--keyword <\u8A9E>] [--status <\u72B6\u614B>]",description:"--output json \u306F API \u304C\u8FD4\u3059\u5168\u30D5\u30A3\u30FC\u30EB\u30C9\u3092\u51FA\u3057\u307E\u3059\u3002\n--output table / text / tsv \u306F\u8981\u7D04\u5217\uFF08id / code / name / status / effective_status\uFF09\u3067\u3059\u3002\n\u6B32\u3057\u3044\u5217\u3060\u3051\u3092\
|
|
6
6
|
\u6A5F\u68B0\u51E6\u7406\u3057\u305F\u3044\u3068\u304D\u306F --query \u3067\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08--query \u306F\u751F\u30C7\u30FC\u30BF\u306B\u5BFE\u3057\u3066\u8A55\u4FA1\u3055\u308C\u307E\u3059\uFF09\u3002\n\n"+LIST_PAGING_HELP,flags:[...LIST_FLAGS,{name:"--keyword",summary:"\u30B3\u30FC\u30C9\u30FB\u540D\u79F0\u306E\u90E8\u5206\u4E00\u81F4\u3067\u7D5E\u308A\u8FBC\u3080",takesValue:true,placeholder:"<\u8A9E>"},{name:"--status",summary:"\u30B9\u30C6\u30FC\u30BF\u30B9\u3067\u7D5E\u308A\u8FBC\u3080\uFF08\u4F8B: active\uFF09",
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{renderOutput}from"./chunk-5Q2CH4E7.js";import"./chunk-YVAN3H5W.js";import"./chunk-K2ONOH3L.js";import"./chunk-WVS4W5FY.js";import"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";export{renderOutput};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{CURATED_PAGING_VOCABULARY,buildPrepareContext,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain}from"./chunk-6NCY4NPV.js";import"./chunk-IOGVQVGD.js";import"./chunk-5Q2CH4E7.js";import"./chunk-YVAN3H5W.js";import"./chunk-QOUFHYK5.js";import"./chunk-II5RVJQN.js";import"./chunk-FTYJZFEK.js";import"./chunk-DMDVLOAY.js";import"./chunk-GMBJTG6A.js";import"./chunk-TAN5I2DP.js";import"./chunk-EJ474UDB.js";
|
|
4
|
+
import"./chunk-QQRJLH6B.js";import"./chunk-XNLIEUAW.js";import"./chunk-J7QYPKVK.js";import"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import"./chunk-K2ONOH3L.js";import"./chunk-WVS4W5FY.js";import"./chunk-NHYMHCAT.js";import"./chunk-GDM2QUBL.js";import"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";export{CURATED_PAGING_VOCABULARY,buildPrepareContext,exitCodeFor,fetchAllPages,outputValue,reportError,requiresYes,resolvePaging,runDomain};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{LoopSettingsApplier,PROMPT_KEYS,formatConfigHash,parseServerSettings,renderStepBudget}from"./chunk-Y2QAP6SU.js";import"./chunk-ODLJ2LNQ.js";import"./chunk-TYNCXQSN.js";import"./chunk-GY7KI5E5.js";import"./chunk-
|
|
3
|
+
import{LoopSettingsApplier,PROMPT_KEYS,formatConfigHash,parseServerSettings,renderStepBudget}from"./chunk-Y2QAP6SU.js";import"./chunk-ODLJ2LNQ.js";import"./chunk-TYNCXQSN.js";import"./chunk-GY7KI5E5.js";import"./chunk-PMOUHEJQ.js";import"./chunk-J7QYPKVK.js";import"./chunk-5WGOHFAS.js";import"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";export{LoopSettingsApplier,PROMPT_KEYS,formatConfigHash,parseServerSettings,renderStepBudget};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{PromptAbortedError,promptText}from"./chunk-L37NS5L2.js";import{detectAiClis,formatDetection,isDetectableAi,isSelectable}from"./chunk-24ZZFFA3.js";import
|
|
3
|
+
import{localConfigPath,parseClaudeLauncher}from"./chunk-UIWGEBWI.js";import{PromptAbortedError,promptText}from"./chunk-L37NS5L2.js";import{detectAiClis,formatDetection,isDetectableAi,isSelectable}from"./chunk-24ZZFFA3.js";import"./chunk-N2UVRM3Z.js";import{AiConfig}from"./chunk-TYNCXQSN.js";import"./chunk-GY7KI5E5.js";import"./chunk-PMOUHEJQ.js";import"./chunk-5WGOHFAS.js";import"./chunk-RZVI6PMW.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";
|
|
4
4
|
import"./chunk-VSJBJXZO.js";import fs from"fs";import path from"path";var RECOMMENDED_ROTATION={complex:["claude"],verify:["claude"],security:["claude"],support:["claude"],triage:["claude"],search:["claude"],simple:["claude"]};var RECOMMENDED_CHAINS={complex:["claude","codex"],verify:["claude","codex","copilot"],security:["claude","codex","copilot"],support:["claude","codex","copilot"],triage:["codex","gemini","copilot","claude"],search:["codex","gemini","copilot","claude"],simple:["codex","gemini","copilot","claude"]};var PREFERENCE=["claude","codex","gemini","co\
|
|
5
5
|
pilot"];function buildAiAssignment(selected){if(selected.length===0)throw new Error("\u9078\u629E\u3055\u308C\u305FAI\u304C\u7A7A\u3067\u3059");const fallbackOrder=PREFERENCE.filter(ai=>selected.includes(ai));for(const ai of selected)if(!fallbackOrder.includes(ai))fallbackOrder.push(ai);const chains={};const rotation={};for(const category of Object.keys(RECOMMENDED_CHAINS)){const filtered=(RECOMMENDED_CHAINS[category]??[]).filter(ai=>selected.includes(ai));const chain=filtered.length>0?filtered:
|
|
6
6
|
[...fallbackOrder];chains[category]=chain;const rot=(RECOMMENDED_ROTATION[category]??[]).filter(ai=>selected.includes(ai));const head=chain[0];rotation[category]=rot.length>0?rot:head===void 0?[...fallbackOrder]:[head]}return{primary_rotation:rotation,fallback_chains:chains}}var SETUP_EXIT_NO_CLI=3;var SETUP_EXIT_ABORTED=130;async function runSetup(opts){const env=opts.env??process.env;const rawOut=opts.out??(t=>void process.stdout.write(t));const rawErr=opts.err??(t=>void process.stderr.write(t));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{checkUploadPlan,checkUploadQuota,storageDomain}from"./chunk-DDKZ5IPT.js";import"./chunk-ZWVYVS2A.js";import"./chunk-7WSNIXTQ.js";import"./chunk-VSJBJXZO.js";export{checkUploadPlan,checkUploadQuota,storageDomain};
|