@unbrained/pm-cli 2026.11.18 → 2026.11.20
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/.claude-plugin/marketplace.json +1 -1
- package/AGENTS.md +1 -1
- package/dist/cli-bundle/bundle-manifest.json +1 -1
- package/dist/cli-bundle/chunks/{chunk-SSZBVRIN.js → chunk-2IZGNOGT.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-T3E3WNHO.js → chunk-3BOR22MC.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-LGWP5D7V.js → chunk-4QQPM3IY.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-TA5VN4ME.js → chunk-4TZW4NLM.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-TS2CZE3O.js → chunk-5LF5QZT3.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-WKHS4QC6.js → chunk-6HRPGEBF.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-FJQCORYR.js → chunk-6X2AGUOT.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-2VH6COJE.js → chunk-7ESF676D.js} +37 -37
- package/dist/cli-bundle/chunks/{chunk-CGTVDSAR.js → chunk-7EZZ4W7O.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-QK7RAN7R.js → chunk-DG2EOOFX.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-YJI2Y5N6.js → chunk-FF4TXJDH.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-7UUPLMCU.js → chunk-FOYRE23V.js} +46 -46
- package/dist/cli-bundle/chunks/{chunk-L2ZLH3LZ.js → chunk-GXGW6KHB.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-7ETRLLK3.js → chunk-HJQ3XPS3.js} +30 -30
- package/dist/cli-bundle/chunks/{chunk-JBPXNG6P.js → chunk-KDDIHGAO.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-KEBLUTC3.js +71 -0
- package/dist/cli-bundle/chunks/{chunk-7LCJA54R.js → chunk-KQSPKWFH.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-VETSGCF4.js → chunk-M5D3CEMY.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-AGU7632B.js → chunk-MGYAJONE.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-CR5GC3VO.js → chunk-OXG5XPC7.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-H64BNM4A.js → chunk-W4TLA5H3.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-S3RMFLEG.js → chunk-XK25TAJZ.js} +4 -4
- package/dist/cli-bundle/chunks/{chunk-XDIJK6VW.js → chunk-ZAO7VGX3.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-MUGGRKK3.js → chunk-ZVEHACE6.js} +2 -2
- package/dist/cli-bundle/chunks/{item-revision-BV5BUBCR.js → item-revision-GE2CQECR.js} +2 -2
- package/dist/cli-bundle/chunks/item-transaction-YSAWJRA2.js +2 -0
- package/dist/cli-bundle/chunks/{mutation-actor-DDYJW5B4.js → mutation-actor-5GYX7LP3.js} +2 -2
- package/dist/cli-bundle/chunks/{mutation-admission-5AWMXMCB.js → mutation-admission-72TYKPGU.js} +2 -2
- package/dist/cli-bundle/chunks/{register-list-query-RJT7YBRF.js → register-list-query-OQZZEWEB.js} +2 -2
- package/dist/cli-bundle/chunks/{register-mutation-6KTMJGYF.js → register-mutation-YZEUZ6XT.js} +2 -2
- package/dist/cli-bundle/chunks/{register-operations-W24TA3HZ.js → register-operations-JNVCF7EW.js} +2 -2
- package/dist/cli-bundle/chunks/{register-setup-QK67WUX6.js → register-setup-LDKULZSD.js} +2 -2
- package/dist/cli-bundle/chunks/{stage-XGWW3T64.js → stage-Q2QZ2IBG.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-IGMFXB5W.js → chunk-3LRSQXCN.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-EZXLY6S4.js → chunk-5VSXKA35.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-LZR3JKYT.js → chunk-7SB6VKEI.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-MTBC32ZR.js → chunk-BZCLW5V7.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-ICEHI4SN.js → chunk-FPKVHC3Q.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-HO2YUD4P.js → chunk-I7XBR2RM.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-XS2YZCT5.js → chunk-JUYJ7NXL.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-ZFUZ4YYN.js → chunk-KQJNJZKP.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-7RF2YPZ5.js → chunk-MJP3TFVW.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-3H3SVHAT.js → chunk-O25KFLLA.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-7Z2NYAK4.js → chunk-PKMDWIP3.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-EO4XM3XJ.js → chunk-PQXTZLK3.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-T3NMYMW4.js → chunk-PRFEOCNZ.js} +24 -24
- package/dist/cli-bundle/focused-chunks/{chunk-A2CLYPDA.js → chunk-PZSTRYTA.js} +40 -40
- package/dist/cli-bundle/focused-chunks/{chunk-PNCCTZKI.js → chunk-QNJQPJWO.js} +23 -23
- package/dist/cli-bundle/focused-chunks/{chunk-5JVB42Z7.js → chunk-SIPDQBJI.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-FPPYE6CY.js → chunk-SJE3PYPI.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-6OZ7BKWJ.js → chunk-TNKI6WKG.js} +55 -54
- package/dist/cli-bundle/focused-chunks/{chunk-ONHUG7IL.js → chunk-TRCXANRR.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-DWCFZVT2.js → chunk-UATP3RK3.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-OPY43DNJ.js → chunk-V55XZFOP.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-OAIAZHRG.js → chunk-ZKGGGU2K.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{item-revision-NS2V4WON.js → item-revision-OXDZHMJ7.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{item-transaction-NENC4HYI.js → item-transaction-54VSTT6L.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{mutation-actor-2SVBO324.js → mutation-actor-6DYIF6NH.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{mutation-admission-DZIBDJAE.js → mutation-admission-2BYXANVJ.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{stage-LVAGKCEE.js → stage-FGHSB3QX.js} +2 -2
- package/dist/cli-bundle/main.js +2 -2
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +1 -1
- package/dist/cli-bundle/sdk-core.js +1 -1
- package/dist/cli-bundle/sdk-governance.js +1 -1
- package/dist/cli-bundle/sdk-graph.js +1 -1
- package/dist/cli-bundle/sdk-merge.js +55 -55
- package/dist/cli-bundle/sdk-query.js +1 -1
- package/dist/cli-bundle/sdk-runtime.js +1 -1
- package/dist/cli-bundle/sdk-testing.js +1 -1
- package/dist/cli-bundle/sdk.js +11 -11
- package/dist/core/fs/file-glob.js +1 -1
- package/dist/core/shared/process-tree.js +3 -0
- package/dist/core/shared/secret-rules.d.ts +12 -1
- package/dist/core/shared/secret-rules.js +2 -2
- package/dist/core/shared/text-normalization.d.ts +9 -0
- package/dist/core/shared/text-normalization.js +1 -1
- package/dist/sdk/context-intent-contracts.js +1 -1
- package/dist/sdk/extension/managed-state.d.ts +3 -1
- package/dist/sdk/extension/managed-state.js +1 -1
- package/dist/sdk/extension/managed-update-status.js +1 -1
- package/dist/sdk/extension/update-check.d.ts +42 -6
- package/dist/sdk/extension/update-check.js +1 -1
- package/dist/sdk/extension.d.ts +3 -1
- package/dist/sdk/extension.js +1 -1
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/mutation-guard.d.ts +121 -1
- package/dist/sdk/mutation-guard.js +1 -1
- package/dist/sdk/public-surface.json +1 -1
- package/dist/sdk/read-output/continuation.d.ts +9 -3
- package/dist/sdk/read-output/continuation.js +1 -1
- package/dist/sdk/read-output-budget.d.ts +44 -3
- package/dist/sdk/read-output-budget.js +1 -1
- package/dist/sdk/read-output-contracts.js +1 -1
- package/dist/sdk/test/execution.js +2 -2
- package/docs/CONFIGURATION.md +1 -0
- package/docs/MUTATION_INTEGRITY.md +72 -0
- package/docs/PACKAGE_EVIDENCE.md +66 -0
- package/docs/READ_OUTPUT_CONTRACTS.md +16 -1
- package/marketplace.json +1 -1
- package/package.json +1 -1
- package/packages/pm-beads/package.json +1 -1
- package/packages/pm-calendar/package.json +1 -1
- package/packages/pm-command-kit/package.json +1 -1
- package/packages/pm-digital-twin/package.json +1 -1
- package/packages/pm-governance-audit/package.json +1 -1
- package/packages/pm-guide-shell/package.json +1 -1
- package/packages/pm-kanban/package.json +1 -1
- package/packages/pm-lifecycle-hooks/package.json +1 -1
- package/packages/pm-linked-test-adapters/package.json +1 -1
- package/packages/pm-search-advanced/package.json +1 -1
- package/packages/pm-templates/package.json +1 -1
- package/packages/pm-todos/package.json +1 -1
- package/packages/pm-vcs/package.json +1 -1
- package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
- package/plugins/pm-claude/package.json +1 -1
- package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/pm-codex/package.json +1 -1
- package/plugins/pm-codex/plugin.json +1 -1
- package/runtime-dependencies.json +1 -1
- package/dist/cli-bundle/chunks/chunk-OD2I3SFQ.js +0 -70
- package/dist/cli-bundle/chunks/item-transaction-E2ST3A3X.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},n=new e.Error().stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6175fcf6-186d-50f6-8642-ba3432cf4b64")}catch{}})();import{SECRET_RULES,acceptsStructuredValue,findSecretRuleMatches,structuredKeyShape}from"../core/shared/secret-rules.js";import{EXIT_CODE}from"../core/shared/constants.js";import{PmCliError}from"../core/shared/errors.js";const PM_MUTATION_ACTION_CONTRACTS=[{action:"append",history_scope:"item"},{action:"claim",history_scope:"item"},{action:"close",history_scope:"item"},{action:"close-many",history_scope:"item"},{action:"close-task",history_scope:"item"},{action:"comments",history_scope:"conditional"},{action:"config",history_scope:"conditional"},{action:"copy",history_scope:"item"},{action:"create",history_scope:"item"},{action:"delete",history_scope:"item"},{action:"deps",history_scope:"conditional"},{action:"discover",history_scope:"item"},{action:"docs",history_scope:"conditional"},{action:"files",history_scope:"conditional"},{action:"focus",history_scope:"conditional"},{action:"gc",history_scope:"conditional"},{action:"history-compact",history_scope:"history"},{action:"history-author-acknowledge",history_scope:"workspace"},{action:"history-redact",history_scope:"history"},{action:"history-repair",history_scope:"history"},{action:"init",history_scope:"workspace"},{action:"install",history_scope:"conditional"},{action:"learnings",history_scope:"conditional"},{action:"notes",history_scope:"conditional"},{action:"package",history_scope:"conditional"},{action:"pause-task",history_scope:"item"},{action:"plan",history_scope:"conditional"},{action:"profile",history_scope:"conditional"},{action:"release",history_scope:"item"},{action:"restore",history_scope:"item"},{action:"schema",history_scope:"conditional"},{action:"start-task",history_scope:"item"},{action:"templates",history_scope:"conditional"},{action:"test",history_scope:"conditional"},{action:"test-all",history_scope:"conditional"},{action:"update",history_scope:"item"},{action:"update-many",history_scope:"item"},{action:"upgrade",history_scope:"conditional"}],MUTATION_ACTION_CONTRACTS_BY_NAME=new Map(PM_MUTATION_ACTION_CONTRACTS.map(contract=>[contract.action,contract])),ARRAY_INDEX=/^(?:0|[1-9]\d*)$/u,MAX_ARRAY_INDEX=2**32-2;function isArrayIndex(key){return ARRAY_INDEX.test(key)&&Number(key)<=MAX_ARRAY_INDEX}function ruleMatches(value){const matches=[];for(const rule of SECRET_RULES){const match=preflightRuleMatch(rule,value);match&&matches.push({rule,match})}return matches}function nameMatches(name,cache){let matches=cache.names.get(name);return matches===void 0&&(matches=ruleMatches(name),cache.names.set(name,matches)),matches}function ownEntries(value,cache){let entries=cache.entries.get(value);return entries===void 0&&(entries=Array.isArray(value)?Object.getOwnPropertyNames(value).filter(isArrayIndex).map(name=>({name,value:value[Number(name)],segment:`[${name}]`,nameMatches:[]})):Object.entries(value).map(([name,entry],position)=>{const matches=nameMatches(name,cache);return{name,value:entry,segment:matches.length>0?`[key ${position}]`:`.${name}`,nameMatches:matches}}),cache.entries.set(value,entries)),entries}function findingFor({rule,match},path,propertyName){const finding={rule:rule.mutationRule,path};return propertyName&&(finding.property_name=!0),match.normalizations&&(finding.normalizations=match.normalizations),match.normalization_incomplete&&(finding.normalization_incomplete=!0),finding}function pushReversed(pending,children){for(let index=children.length-1;index>=0;index-=1)pending.push(children[index])}function preflightRuleMatch(rule,value){try{return firstRuleMatch(rule,value)}catch(error){return judgeTooLarge(error)}}function judgeTooLarge(error){if(!(error instanceof RangeError))throw error;return{index:0,normalization_incomplete:!0}}function firstRuleMatch(rule,value){const matches=findSecretRuleMatches(rule,value),first=matches.next().value;if(!first||rule.mutationRule!=="absolute_home_path"||first.normalization_incomplete)return first;for(const later of matches)if(later.normalization_incomplete)return{...first,normalizations:[...new Set([first.normalizations,later.normalizations].flatMap(kinds=>kinds??[]))],normalization_incomplete:!0};return first}function scanStringLeaves(payload,cache){const findings=[],seen=new WeakSet,pending=[{value:payload,path:"$"}];for(let step=pending.pop();step!==void 0;step=pending.pop()){const{value,path}=step;if(typeof value=="string")for(const match of ruleMatches(value))findings.push(findingFor(match,path,!1));else if(typeof value=="object"&&value!==null&&!seen.has(value)){seen.add(value);const entries=ownEntries(value,cache);for(const entry of entries)for(const match of entry.nameMatches)findings.push(findingFor(match,`${path}${entry.segment}`,!0));pushReversed(pending,entries.map(entry=>({value:entry.value,path:`${path}${entry.segment}`})))}}return findings}const KEY_NAMED_RULES=SECRET_RULES.filter(rule=>"structured"in rule),NO_KEY_CONTEXT=KEY_NAMED_RULES.map(()=>({named:!1,exact:!1})),CAMEL_BOUNDARY=/(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/gu,CREDENTIAL_SUFFIX_WORDS=3;function keyWords(name){return name.replace(CAMEL_BOUNDARY,"_")}function nameSpellings(name){const suffixSplits=[...name.matchAll(CAMEL_BOUNDARY)].map(match=>match.index).slice(-CREDENTIAL_SUFFIX_WORDS).map(boundary=>`${keyWords(name.slice(0,boundary))}_${name.slice(boundary)}`);return[...new Set([name,keyWords(name),...suffixSplits])]}function memberKeyShapes(name){const spellings=nameSpellings(name);return KEY_NAMED_RULES.map(rule=>{const shapes=spellings.map(spelling=>structuredKeyShape(rule,spelling));return shapes.includes("exact")?"exact":shapes.includes("prefixed")?"prefixed":void 0})}const NO_JUDGMENTS=KEY_NAMED_RULES.map(()=>{});function memberChildSteps(value,path,contexts,cache){const entries=ownEntries(value,cache);if(Array.isArray(value)){const judgments=contexts.map(({named,exact})=>exact?"lenient":named?"compact":void 0);return entries.map(entry=>({value:entry.value,path:`${path}${entry.segment}`,contexts,judgments}))}return entries.map(({name,value:entry,segment})=>{const shapes=memberKeyShapes(name);return{value:entry,path:`${path}${segment}`,contexts:contexts.map(({named,exact},index)=>({named:named||shapes[index]!==void 0,exact:exact||shapes[index]==="exact"})),judgments:shapes.map((shape,index)=>shape==="exact"?"lenient":shape==="prefixed"||contexts[index].named?"compact":void 0)}})}function scanPayloadMembers(payload,cache){const findings=[],visited=new WeakMap,pending=[{value:payload,path:"$",contexts:NO_KEY_CONTEXT,judgments:NO_JUDGMENTS}];for(let step=pending.pop();step!==void 0;step=pending.pop()){const{value,path,contexts,judgments}=step;if(typeof value=="string"){judgments.forEach((judgment,index)=>{const rule=KEY_NAMED_RULES[index];if(judgment===void 0)return;let accepted;try{accepted=acceptsStructuredValue(rule,value,judgment==="compact")}catch(error){judgeTooLarge(error),findings.push({rule:rule.mutationRule,path,normalization_incomplete:!0});return}accepted&&findings.push({rule:rule.mutationRule,path})});continue}if(typeof value!="object"||value===null)continue;const signature=contexts.map(({named,exact})=>exact?"e":named?"n":"-").join(""),signatures=visited.get(value)??new Set;signatures.has(signature)||(visited.set(value,signatures.add(signature)),pushReversed(pending,memberChildSteps(value,path,contexts,cache)))}return findings}function scanMutationSecrets(payload){const reported=new Set,cache={entries:new WeakMap,names:new Map};return[...scanStringLeaves(payload,cache),...scanPayloadMembers(payload,cache)].filter(finding=>{const key=`${finding.rule}\0${finding.path}\0${finding.property_name===!0}`;return reported.has(key)?!1:(reported.add(key),!0)})}function evaluateMutationGuard(options){const author=options.author.trim()||"unknown";if(options.settings.require_attributed_author&&author.toLowerCase()==="unknown")throw new PmCliError("Mutation author is required by workspace policy.",EXIT_CODE.USAGE,{code:"mutation_author_required",required:"Pass --author <id>, set PM_AUTHOR, or configure author_default.",nextSteps:["Retry with --author <stable-agent-id>.","Set PM_AUTHOR for this agent session."]});if(options.settings.secret_guard==="off")return{author,findings:[],warnings:[],override_applied:!1};let findings;try{findings=scanMutationSecrets(options.payload)}catch{return{author,findings:[],warnings:["secret_guard_scan_failed_open"],override_applied:!1}}if(findings.length===0)return{author,findings,warnings:[],override_applied:!1};const ruleSummary=[...new Set(findings.map(finding=>finding.rule))].sort().join(",");if(options.settings.secret_guard==="block"&&options.force!==!0)throw new PmCliError(`Mutation blocked by secret guard (${ruleSummary}). No detected value was logged.`,EXIT_CODE.CONFLICT,{code:"mutation_secret_guard_blocked",required:"Remove the credential-shaped content or retry with --force after explicit review.",nextSteps:["Replace the value with a secret-manager reference.","Use pm history-redact if equivalent content already entered history."],recovery:{recovery_mode:"compact",attempted_command:"pm <mutation> [REDACTED]",normalized_args:["[REDACTED]"],suggested_retry:"Remove credential-shaped content, then retry the mutation."}});return{author,findings,warnings:[`secret_guard_detected:${findings.length}:rules=${ruleSummary}`,...options.settings.secret_guard==="block"&&options.force===!0?["secret_guard_force_override"]:[]],override_applied:options.settings.secret_guard==="block"&&options.force===!0}}function isMutationAction(action){return MUTATION_ACTION_CONTRACTS_BY_NAME.has(action.trim().toLowerCase())}function listMutationActions(){return[...MUTATION_ACTION_CONTRACTS_BY_NAME.keys()].sort((left,right)=>left.localeCompare(right))}function getMutationActionContract(action){return MUTATION_ACTION_CONTRACTS_BY_NAME.get(action.trim().toLowerCase())}export{PM_MUTATION_ACTION_CONTRACTS,evaluateMutationGuard,getMutationActionContract,isMutationAction,listMutationActions,scanMutationSecrets};
|
|
1
|
+
(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},n=new e.Error().stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e55d27db-d28f-56da-ac44-2ed6c19f8609")}catch{}})();import{SECRET_RULES,acceptsStructuredValue,findSecretRuleMatches,structuredKeyShape}from"../core/shared/secret-rules.js";import{EXIT_CODE}from"../core/shared/constants.js";import{PmCliError}from"../core/shared/errors.js";const CATEGORY_SETS_MATCH=!0,PM_MUTATION_ACTION_CONTRACTS=[{action:"append",history_scope:"item"},{action:"claim",history_scope:"item"},{action:"close",history_scope:"item"},{action:"close-many",history_scope:"item"},{action:"close-task",history_scope:"item"},{action:"comments",history_scope:"conditional"},{action:"config",history_scope:"conditional"},{action:"copy",history_scope:"item"},{action:"create",history_scope:"item"},{action:"delete",history_scope:"item"},{action:"deps",history_scope:"conditional"},{action:"discover",history_scope:"item"},{action:"docs",history_scope:"conditional"},{action:"files",history_scope:"conditional"},{action:"focus",history_scope:"conditional"},{action:"gc",history_scope:"conditional"},{action:"history-compact",history_scope:"history"},{action:"history-author-acknowledge",history_scope:"workspace"},{action:"history-redact",history_scope:"history"},{action:"history-repair",history_scope:"history"},{action:"init",history_scope:"workspace"},{action:"install",history_scope:"conditional"},{action:"learnings",history_scope:"conditional"},{action:"notes",history_scope:"conditional"},{action:"package",history_scope:"conditional"},{action:"pause-task",history_scope:"item"},{action:"plan",history_scope:"conditional"},{action:"profile",history_scope:"conditional"},{action:"release",history_scope:"item"},{action:"restore",history_scope:"item"},{action:"schema",history_scope:"conditional"},{action:"start-task",history_scope:"item"},{action:"templates",history_scope:"conditional"},{action:"test",history_scope:"conditional"},{action:"test-all",history_scope:"conditional"},{action:"update",history_scope:"item"},{action:"update-many",history_scope:"item"},{action:"upgrade",history_scope:"conditional"}],MUTATION_ACTION_CONTRACTS_BY_NAME=new Map(PM_MUTATION_ACTION_CONTRACTS.map(contract=>[contract.action,contract])),ARRAY_INDEX=/^(?:0|[1-9]\d*)$/u,MAX_ARRAY_INDEX=2**32-2;function isArrayIndex(key){return ARRAY_INDEX.test(key)&&Number(key)<=MAX_ARRAY_INDEX}function ruleMatches(value){const matches=[];for(const rule of SECRET_RULES){const match=preflightRuleMatch(rule,value);match&&matches.push({rule,match})}return matches}function nameMatches(name,cache){let matches=cache.names.get(name);return matches===void 0&&(matches=ruleMatches(name),cache.names.set(name,matches)),matches}function ownEntries(value,cache){let entries=cache.entries.get(value);return entries===void 0&&(entries=Array.isArray(value)?Object.getOwnPropertyNames(value).filter(isArrayIndex).map(name=>({name,value:value[Number(name)],segment:`[${name}]`,nameMatches:[]})):Object.entries(value).map(([name,entry],position)=>{const matches=nameMatches(name,cache);return{name,value:entry,segment:matches.length>0?`[key ${position}]`:`.${name}`,nameMatches:matches}}),cache.entries.set(value,entries)),entries}function findingFor({rule,match},path,propertyName){const finding={rule:rule.mutationRule,path};return propertyName&&(finding.property_name=!0),match.normalizations&&(finding.normalizations=match.normalizations),match.normalization_incomplete&&(finding.normalization_incomplete=!0),finding}function pushReversed(pending,children){for(let index=children.length-1;index>=0;index-=1)pending.push(children[index])}function preflightRuleMatch(rule,value){try{return firstRuleMatch(rule,value)}catch(error){return judgeTooLarge(error)}}function judgeTooLarge(error){if(!(error instanceof RangeError))throw error;return{index:0,normalization_incomplete:!0}}function firstRuleMatch(rule,value){const matches=findSecretRuleMatches(rule,value),first=matches.next().value;if(!first||rule.mutationRule!=="absolute_home_path"||first.normalization_incomplete)return first;for(const later of matches)if(later.normalization_incomplete)return{...first,normalizations:[...new Set([first.normalizations,later.normalizations].flatMap(kinds=>kinds??[]))],normalization_incomplete:!0};return first}function scanStringLeaves(payload,cache){const findings=[],seen=new WeakSet,pending=[{value:payload,path:"$"}];for(let step=pending.pop();step!==void 0;step=pending.pop()){const{value,path}=step;if(typeof value=="string")for(const match of ruleMatches(value))findings.push(findingFor(match,path,!1));else if(typeof value=="object"&&value!==null&&!seen.has(value)){seen.add(value);const entries=ownEntries(value,cache);for(const entry of entries)for(const match of entry.nameMatches)findings.push(findingFor(match,`${path}${entry.segment}`,!0));pushReversed(pending,entries.map(entry=>({value:entry.value,path:`${path}${entry.segment}`})))}}return findings}const KEY_NAMED_RULES=SECRET_RULES.filter(rule=>"structured"in rule),NO_KEY_CONTEXT=KEY_NAMED_RULES.map(()=>({named:!1,exact:!1})),CAMEL_BOUNDARY=/(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/gu,CREDENTIAL_SUFFIX_WORDS=3;function keyWords(name){return name.replace(CAMEL_BOUNDARY,"_")}function nameSpellings(name){const suffixSplits=[...name.matchAll(CAMEL_BOUNDARY)].map(match=>match.index).slice(-CREDENTIAL_SUFFIX_WORDS).map(boundary=>`${keyWords(name.slice(0,boundary))}_${name.slice(boundary)}`);return[...new Set([name,keyWords(name),...suffixSplits])]}function memberKeyShapes(name){const spellings=nameSpellings(name);return KEY_NAMED_RULES.map(rule=>{const shapes=spellings.map(spelling=>structuredKeyShape(rule,spelling));return shapes.includes("exact")?"exact":shapes.includes("prefixed")?"prefixed":void 0})}const NO_JUDGMENTS=KEY_NAMED_RULES.map(()=>{});function memberChildSteps(value,path,contexts,cache){const entries=ownEntries(value,cache);if(Array.isArray(value)){const judgments=contexts.map(({named,exact})=>exact?"lenient":named?"compact":void 0);return entries.map(entry=>({value:entry.value,path:`${path}${entry.segment}`,contexts,judgments}))}return entries.map(({name,value:entry,segment})=>{const shapes=memberKeyShapes(name);return{value:entry,path:`${path}${segment}`,contexts:contexts.map(({named,exact},index)=>({named:named||shapes[index]!==void 0,exact:exact||shapes[index]==="exact"})),judgments:shapes.map((shape,index)=>shape==="exact"?"lenient":shape==="prefixed"||contexts[index].named?"compact":void 0)}})}function scanPayloadMembers(payload,cache){const findings=[],visited=new WeakMap,pending=[{value:payload,path:"$",contexts:NO_KEY_CONTEXT,judgments:NO_JUDGMENTS}];for(let step=pending.pop();step!==void 0;step=pending.pop()){const{value,path,contexts,judgments}=step;if(typeof value=="string"){judgments.forEach((judgment,index)=>{const rule=KEY_NAMED_RULES[index];if(judgment===void 0)return;let accepted;try{accepted=acceptsStructuredValue(rule,value,judgment==="compact")}catch(error){judgeTooLarge(error),findings.push({rule:rule.mutationRule,path,normalization_incomplete:!0});return}accepted&&findings.push({rule:rule.mutationRule,path})});continue}if(typeof value!="object"||value===null)continue;const signature=contexts.map(({named,exact})=>exact?"e":named?"n":"-").join(""),signatures=visited.get(value)??new Set;signatures.has(signature)||(visited.set(value,signatures.add(signature)),pushReversed(pending,memberChildSteps(value,path,contexts,cache)))}return findings}function scanMutationSecrets(payload){const reported=new Set,cache={entries:new WeakMap,names:new Map};return[...scanStringLeaves(payload,cache),...scanPayloadMembers(payload,cache)].filter(finding=>{const key=`${finding.rule}\0${finding.path}\0${finding.property_name===!0}`;return reported.has(key)?!1:(reported.add(key),!0)})}function evaluateMutationGuard(options){const author=options.author.trim()||"unknown";if(options.settings.require_attributed_author&&author.toLowerCase()==="unknown")throw new PmCliError("Mutation author is required by workspace policy.",EXIT_CODE.USAGE,{code:"mutation_author_required",required:"Pass --author <id>, set PM_AUTHOR, or configure author_default.",nextSteps:["Retry with --author <stable-agent-id>.","Set PM_AUTHOR for this agent session."]});if(options.settings.secret_guard==="off")return{author,findings:[],warnings:[],override_applied:!1};let findings;try{findings=scanMutationSecrets(options.payload)}catch{return{author,findings:[],warnings:["secret_guard_scan_failed_open"],override_applied:!1}}if(findings.length===0)return{author,findings,warnings:[],override_applied:!1};const ruleSummary=[...new Set(findings.map(finding=>finding.rule))].sort().join(",");if(options.settings.secret_guard==="block"&&options.force!==!0)throw new PmCliError(`Mutation blocked by secret guard (${ruleSummary}). No detected value was logged.`,EXIT_CODE.CONFLICT,{code:"mutation_secret_guard_blocked",required:"Remove the credential-shaped content or retry with --force after explicit review.",nextSteps:["Replace the value with a secret-manager reference.","Use pm history-redact if equivalent content already entered history."],recovery:{recovery_mode:"compact",attempted_command:"pm <mutation> [REDACTED]",normalized_args:["[REDACTED]"],suggested_retry:"Remove credential-shaped content, then retry the mutation."}});return{author,findings,warnings:[`secret_guard_detected:${findings.length}:rules=${ruleSummary}`,...options.settings.secret_guard==="block"&&options.force===!0?["secret_guard_force_override"]:[]],override_applied:options.settings.secret_guard==="block"&&options.force===!0}}const SECRET_GUARD_RULE_CATEGORIES=Object.freeze(Object.fromEntries(SECRET_RULES.map(rule=>[rule.mutationRule,rule.category])));function secretGuardRuleCategory(rule){return Object.hasOwn(SECRET_GUARD_RULE_CATEGORIES,rule)?SECRET_GUARD_RULE_CATEGORIES[rule]:void 0}function ownPolicyEntry(entries,key){return entries!==void 0&&key!==void 0&&Object.hasOwn(entries,key)?entries[key]:void 0}const OBJECT_PROTOTYPE_KEYS=new Set(Reflect.ownKeys(Object.prototype));function isForeignObjectPrototype(prototype){const keys=Reflect.ownKeys(prototype);if(keys.length!==OBJECT_PROTOTYPE_KEYS.size||!keys.every(key=>OBJECT_PROTOTYPE_KEYS.has(key)))return!1;const constructor=Object.getOwnPropertyDescriptor(prototype,"constructor")?.value;return typeof constructor=="function"&&Object.getOwnPropertyDescriptor(constructor,"prototype")?.value===prototype}function isPlainPropertyMap(value){const prototype=Object.getPrototypeOf(value);return prototype===null||prototype===Object.prototype?!0:Object.getPrototypeOf(prototype)!==null?!1:Reflect.ownKeys(prototype).length===0||isForeignObjectPrototype(prototype)}function ownPolicyEntries(policy,field){const entries=Object.hasOwn(policy,field)?policy[field]:void 0;if(entries!==void 0&&(typeof entries!="object"||entries===null||!isPlainPropertyMap(entries)))throw new TypeError(`Secret guard policy ${field} must be an object keyed by ${field==="rules"?"rule":"category"}.`);return entries}function decideSecretGuardFinding(policy,finding){if(typeof policy!="object"||policy===null||Array.isArray(policy))throw new TypeError("Secret guard policy must be an object with a default decision.");const fallback=Object.hasOwn(policy,"default")?policy.default:void 0;if(fallback===void 0)throw new TypeError("Secret guard policy requires a default decision.");const categories=ownPolicyEntries(policy,"categories"),rules=ownPolicyEntries(policy,"rules"),rule=typeof finding=="object"&&finding!==null?finding.rule:void 0;if(typeof rule!="string")throw new TypeError("Secret guard finding must have a string rule.");const ruleDecision=ownPolicyEntry(rules,rule);if(ruleDecision!==void 0)return ruleDecision;const categoryDecision=ownPolicyEntry(categories,secretGuardRuleCategory(rule));return categoryDecision===void 0?fallback:categoryDecision}function isMutationAction(action){return MUTATION_ACTION_CONTRACTS_BY_NAME.has(action.trim().toLowerCase())}function listMutationActions(){return[...MUTATION_ACTION_CONTRACTS_BY_NAME.keys()].sort((left,right)=>left.localeCompare(right))}function getMutationActionContract(action){return MUTATION_ACTION_CONTRACTS_BY_NAME.get(action.trim().toLowerCase())}export{PM_MUTATION_ACTION_CONTRACTS,SECRET_GUARD_RULE_CATEGORIES,decideSecretGuardFinding,evaluateMutationGuard,getMutationActionContract,isMutationAction,listMutationActions,scanMutationSecrets,secretGuardRuleCategory};
|
|
2
2
|
//# sourceMappingURL=mutation-guard.js.map
|