@webpieces/agent-workflow-rules 0.0.0-stage → 0.0.1
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/README.md +23 -2
- package/package.json +45 -4
- package/src/adapters/agent-response.d.ts +5 -0
- package/src/adapters/agent-response.js +86 -0
- package/src/adapters/agent-response.js.map +1 -0
- package/src/adapters/codex-subagent-guard.d.ts +45 -0
- package/src/adapters/codex-subagent-guard.js +88 -0
- package/src/adapters/codex-subagent-guard.js.map +1 -0
- package/src/adapters/guards-hook.d.ts +3 -0
- package/src/adapters/guards-hook.js +30 -0
- package/src/adapters/guards-hook.js.map +1 -0
- package/src/adapters/hook-app-fixtures.d.ts +68 -0
- package/src/adapters/hook-app-fixtures.js +170 -0
- package/src/adapters/hook-app-fixtures.js.map +1 -0
- package/src/adapters/hook-core.d.ts +22 -0
- package/src/adapters/hook-core.js +359 -0
- package/src/adapters/hook-core.js.map +1 -0
- package/src/adapters/hook-pipeline-evaluator.d.ts +5 -0
- package/src/adapters/hook-pipeline-evaluator.js +18 -0
- package/src/adapters/hook-pipeline-evaluator.js.map +1 -0
- package/src/adapters/review-identity-stamper.d.ts +20 -0
- package/src/adapters/review-identity-stamper.js +34 -0
- package/src/adapters/review-identity-stamper.js.map +1 -0
- package/src/bin/codex-trust.d.ts +105 -0
- package/src/bin/codex-trust.js +205 -0
- package/src/bin/codex-trust.js.map +1 -0
- package/src/bin/dev-hook-install.d.ts +1 -0
- package/src/bin/dev-hook-install.js +80 -0
- package/src/bin/dev-hook-install.js.map +1 -0
- package/src/bin/dev-hook-uninstall.d.ts +1 -0
- package/src/bin/dev-hook-uninstall.js +45 -0
- package/src/bin/dev-hook-uninstall.js.map +1 -0
- package/src/bin/hook-registration.d.ts +429 -0
- package/src/bin/hook-registration.js +661 -0
- package/src/bin/hook-registration.js.map +1 -0
- package/src/bin/install-entry.d.ts +19 -0
- package/src/bin/install-entry.js +128 -0
- package/src/bin/install-entry.js.map +1 -0
- package/src/bin/l0-allowlist.d.ts +46 -0
- package/src/bin/l0-allowlist.js +527 -0
- package/src/bin/l0-allowlist.js.map +1 -0
- package/src/bin/l0-codex-read.d.ts +20 -0
- package/src/bin/l0-codex-read.js +108 -0
- package/src/bin/l0-codex-read.js.map +1 -0
- package/src/bin/l0-decide.d.ts +49 -0
- package/src/bin/l0-decide.js +90 -0
- package/src/bin/l0-decide.js.map +1 -0
- package/src/bin/l0-entry.d.ts +103 -0
- package/src/bin/l0-entry.js +98 -0
- package/src/bin/l0-entry.js.map +1 -0
- package/src/bin/l0-ignored-tools.d.ts +38 -0
- package/src/bin/l0-ignored-tools.js +44 -0
- package/src/bin/l0-ignored-tools.js.map +1 -0
- package/src/bin/managed-env.d.ts +46 -0
- package/src/bin/managed-env.js +50 -0
- package/src/bin/managed-env.js.map +1 -0
- package/src/bin/neighbour-hooks.d.ts +42 -0
- package/src/bin/neighbour-hooks.js +177 -0
- package/src/bin/neighbour-hooks.js.map +1 -0
- package/src/bin/reviewer-agent.d.ts +19 -0
- package/src/bin/reviewer-agent.js +135 -0
- package/src/bin/reviewer-agent.js.map +1 -0
- package/src/bin/settings-shape.d.ts +37 -0
- package/src/bin/settings-shape.js +17 -0
- package/src/bin/settings-shape.js.map +1 -0
- package/src/bin/setup-config.d.ts +20 -0
- package/src/bin/setup-config.js +371 -0
- package/src/bin/setup-config.js.map +1 -0
- package/src/bin/setup.d.ts +78 -0
- package/src/bin/setup.js +411 -0
- package/src/bin/setup.js.map +1 -0
- package/src/bin/shim-audit-log.d.ts +119 -0
- package/src/bin/shim-audit-log.js +286 -0
- package/src/bin/shim-audit-log.js.map +1 -0
- package/src/bin/shim-deny-reason.d.ts +1 -0
- package/src/bin/shim-deny-reason.js +244 -0
- package/src/bin/shim-deny-reason.js.map +1 -0
- package/src/bin/shim-drift-fix.d.ts +1 -0
- package/src/bin/shim-drift-fix.js +73 -0
- package/src/bin/shim-drift-fix.js.map +1 -0
- package/src/bin/shim-testkit.d.ts +107 -0
- package/src/bin/shim-testkit.js +197 -0
- package/src/bin/shim-testkit.js.map +1 -0
- package/src/bin/shim-version-drift.d.ts +1 -0
- package/src/bin/shim-version-drift.js +164 -0
- package/src/bin/shim-version-drift.js.map +1 -0
- package/src/bin/shim.d.ts +16 -0
- package/src/bin/shim.js +641 -0
- package/src/bin/shim.js.map +1 -0
- package/src/bin/upgrade-shim.d.ts +18 -0
- package/src/bin/upgrade-shim.js +283 -0
- package/src/bin/upgrade-shim.js.map +1 -0
- package/src/configs/main-sync-guard-configs.d.ts +38 -0
- package/src/configs/main-sync-guard-configs.js +54 -0
- package/src/configs/main-sync-guard-configs.js.map +1 -0
- package/src/configs/rule-configs.d.ts +47 -0
- package/src/configs/rule-configs.js +96 -0
- package/src/configs/rule-configs.js.map +1 -0
- package/src/core/ai-type-context.d.ts +36 -0
- package/src/core/ai-type-context.js +45 -0
- package/src/core/ai-type-context.js.map +1 -0
- package/src/core/decision-log.d.ts +190 -0
- package/src/core/decision-log.js +409 -0
- package/src/core/decision-log.js.map +1 -0
- package/src/core/excluded-path-escape.d.ts +101 -0
- package/src/core/excluded-path-escape.js +236 -0
- package/src/core/excluded-path-escape.js.map +1 -0
- package/src/core/force-to-root.d.ts +32 -0
- package/src/core/force-to-root.js +60 -0
- package/src/core/force-to-root.js.map +1 -0
- package/src/core/guard-index-doc.d.ts +63 -0
- package/src/core/guard-index-doc.js +172 -0
- package/src/core/guard-index-doc.js.map +1 -0
- package/src/core/instruct-ai-writer.d.ts +1 -0
- package/src/core/instruct-ai-writer.js +6 -0
- package/src/core/instruct-ai-writer.js.map +1 -0
- package/src/core/l0-matrix.d.ts +102 -0
- package/src/core/l0-matrix.js +357 -0
- package/src/core/l0-matrix.js.map +1 -0
- package/src/core/l0-tooling-doc.d.ts +45 -0
- package/src/core/l0-tooling-doc.js +258 -0
- package/src/core/l0-tooling-doc.js.map +1 -0
- package/src/core/l1-doc.d.ts +7 -0
- package/src/core/l1-doc.js +340 -0
- package/src/core/l1-doc.js.map +1 -0
- package/src/core/l1-matrix-doc.d.ts +31 -0
- package/src/core/l1-matrix-doc.js +111 -0
- package/src/core/l1-matrix-doc.js.map +1 -0
- package/src/core/l1-rows.d.ts +167 -0
- package/src/core/l1-rows.js +262 -0
- package/src/core/l1-rows.js.map +1 -0
- package/src/core/l2-doc.d.ts +7 -0
- package/src/core/l2-doc.js +385 -0
- package/src/core/l2-doc.js.map +1 -0
- package/src/core/l2-matrix-doc.d.ts +23 -0
- package/src/core/l2-matrix-doc.js +72 -0
- package/src/core/l2-matrix-doc.js.map +1 -0
- package/src/core/l2-row.d.ts +54 -0
- package/src/core/l2-row.js +75 -0
- package/src/core/l2-row.js.map +1 -0
- package/src/core/l2-rows.d.ts +56 -0
- package/src/core/l2-rows.js +272 -0
- package/src/core/l2-rows.js.map +1 -0
- package/src/core/load-rules.d.ts +9 -0
- package/src/core/load-rules.js +65 -0
- package/src/core/load-rules.js.map +1 -0
- package/src/core/log-stream.d.ts +117 -0
- package/src/core/log-stream.js +156 -0
- package/src/core/log-stream.js.map +1 -0
- package/src/core/log-streams.d.ts +48 -0
- package/src/core/log-streams.js +55 -0
- package/src/core/log-streams.js.map +1 -0
- package/src/core/log-target.d.ts +21 -0
- package/src/core/log-target.js +29 -0
- package/src/core/log-target.js.map +1 -0
- package/src/core/main-sync-log.d.ts +16 -0
- package/src/core/main-sync-log.js +108 -0
- package/src/core/main-sync-log.js.map +1 -0
- package/src/core/main-sync-refresh.d.ts +39 -0
- package/src/core/main-sync-refresh.js +96 -0
- package/src/core/main-sync-refresh.js.map +1 -0
- package/src/core/main-sync-timeout.d.ts +33 -0
- package/src/core/main-sync-timeout.js +95 -0
- package/src/core/main-sync-timeout.js.map +1 -0
- package/src/core/matrix-cures.d.ts +12 -0
- package/src/core/matrix-cures.js +56 -0
- package/src/core/matrix-cures.js.map +1 -0
- package/src/core/missing-directory.d.ts +38 -0
- package/src/core/missing-directory.js +66 -0
- package/src/core/missing-directory.js.map +1 -0
- package/src/core/read-only-inspection.d.ts +34 -0
- package/src/core/read-only-inspection.js +88 -0
- package/src/core/read-only-inspection.js.map +1 -0
- package/src/core/rejection-log.d.ts +9 -0
- package/src/core/rejection-log.js +262 -0
- package/src/core/rejection-log.js.map +1 -0
- package/src/core/rules/branch-creation-guard.d.ts +113 -0
- package/src/core/rules/branch-creation-guard.js +425 -0
- package/src/core/rules/branch-creation-guard.js.map +1 -0
- package/src/core/rules/branch-switch-scan.d.ts +43 -0
- package/src/core/rules/branch-switch-scan.js +132 -0
- package/src/core/rules/branch-switch-scan.js.map +1 -0
- package/src/core/rules/build-output-pipe-guard.d.ts +56 -0
- package/src/core/rules/build-output-pipe-guard.js +120 -0
- package/src/core/rules/build-output-pipe-guard.js.map +1 -0
- package/src/core/rules/build-output-pipe-scan.d.ts +47 -0
- package/src/core/rules/build-output-pipe-scan.js +84 -0
- package/src/core/rules/build-output-pipe-scan.js.map +1 -0
- package/src/core/rules/cap-remedies.d.ts +39 -0
- package/src/core/rules/cap-remedies.js +59 -0
- package/src/core/rules/cap-remedies.js.map +1 -0
- package/src/core/rules/commit-message-substitution-guard.d.ts +72 -0
- package/src/core/rules/commit-message-substitution-guard.js +134 -0
- package/src/core/rules/commit-message-substitution-guard.js.map +1 -0
- package/src/core/rules/commit-message-substitution-scan.d.ts +42 -0
- package/src/core/rules/commit-message-substitution-scan.js +145 -0
- package/src/core/rules/commit-message-substitution-scan.js.map +1 -0
- package/src/core/rules/content-read-scan.d.ts +76 -0
- package/src/core/rules/content-read-scan.js +176 -0
- package/src/core/rules/content-read-scan.js.map +1 -0
- package/src/core/rules/cure-prefix-scan.d.ts +64 -0
- package/src/core/rules/cure-prefix-scan.js +133 -0
- package/src/core/rules/cure-prefix-scan.js.map +1 -0
- package/src/core/rules/feature-branch-guard.d.ts +121 -0
- package/src/core/rules/feature-branch-guard.js +327 -0
- package/src/core/rules/feature-branch-guard.js.map +1 -0
- package/src/core/rules/index.d.ts +1 -0
- package/src/core/rules/index.js +5 -0
- package/src/core/rules/index.js.map +1 -0
- package/src/core/rules/judged-tree.d.ts +66 -0
- package/src/core/rules/judged-tree.js +97 -0
- package/src/core/rules/judged-tree.js.map +1 -0
- package/src/core/rules/main-freshness.d.ts +37 -0
- package/src/core/rules/main-freshness.js +61 -0
- package/src/core/rules/main-freshness.js.map +1 -0
- package/src/core/rules/merge-in-progress-guard.d.ts +17 -0
- package/src/core/rules/merge-in-progress-guard.js +124 -0
- package/src/core/rules/merge-in-progress-guard.js.map +1 -0
- package/src/core/rules/merged-branch-bash-guard.d.ts +62 -0
- package/src/core/rules/merged-branch-bash-guard.js +171 -0
- package/src/core/rules/merged-branch-bash-guard.js.map +1 -0
- package/src/core/rules/merged-branch-message.d.ts +59 -0
- package/src/core/rules/merged-branch-message.js +137 -0
- package/src/core/rules/merged-branch-message.js.map +1 -0
- package/src/core/rules/pr-creation-or-push-guard.d.ts +26 -0
- package/src/core/rules/pr-creation-or-push-guard.js +150 -0
- package/src/core/rules/pr-creation-or-push-guard.js.map +1 -0
- package/src/core/rules/pr-merge-guard.d.ts +36 -0
- package/src/core/rules/pr-merge-guard.js +87 -0
- package/src/core/rules/pr-merge-guard.js.map +1 -0
- package/src/core/rules/read-stale-guard.d.ts +136 -0
- package/src/core/rules/read-stale-guard.js +328 -0
- package/src/core/rules/read-stale-guard.js.map +1 -0
- package/src/core/rules/recovery-allowlist.d.ts +49 -0
- package/src/core/rules/recovery-allowlist.js +187 -0
- package/src/core/rules/recovery-allowlist.js.map +1 -0
- package/src/core/rules/redirect-how-to-merge-main.d.ts +16 -0
- package/src/core/rules/redirect-how-to-merge-main.js +159 -0
- package/src/core/rules/redirect-how-to-merge-main.js.map +1 -0
- package/src/core/rules/stale-main-bash-guard.d.ts +198 -0
- package/src/core/rules/stale-main-bash-guard.js +363 -0
- package/src/core/rules/stale-main-bash-guard.js.map +1 -0
- package/src/core/rules/stale-main-message.d.ts +62 -0
- package/src/core/rules/stale-main-message.js +102 -0
- package/src/core/rules/stale-main-message.js.map +1 -0
- package/src/core/rules/tree-recovery.d.ts +92 -0
- package/src/core/rules/tree-recovery.js +165 -0
- package/src/core/rules/tree-recovery.js.map +1 -0
- package/src/core/rules/wait-spin-guard.d.ts +128 -0
- package/src/core/rules/wait-spin-guard.js +211 -0
- package/src/core/rules/wait-spin-guard.js.map +1 -0
- package/src/core/rules/wait-spin-scan.d.ts +118 -0
- package/src/core/rules/wait-spin-scan.js +203 -0
- package/src/core/rules/wait-spin-scan.js.map +1 -0
- package/src/core/rules/whole-repo-build-guard.d.ts +125 -0
- package/src/core/rules/whole-repo-build-guard.js +257 -0
- package/src/core/rules/whole-repo-build-guard.js.map +1 -0
- package/src/core/rules/whole-repo-build-scan.d.ts +28 -0
- package/src/core/rules/whole-repo-build-scan.js +198 -0
- package/src/core/rules/whole-repo-build-scan.js.map +1 -0
- package/src/core/runner.d.ts +19 -0
- package/src/core/runner.js +482 -0
- package/src/core/runner.js.map +1 -0
- package/src/core/session-call-history.d.ts +44 -0
- package/src/core/session-call-history.js +79 -0
- package/src/core/session-call-history.js.map +1 -0
- package/src/core/sync-main.d.ts +46 -0
- package/src/core/sync-main.js +176 -0
- package/src/core/sync-main.js.map +1 -0
- package/src/core/version-sync.d.ts +219 -0
- package/src/core/version-sync.js +558 -0
- package/src/core/version-sync.js.map +1 -0
- package/src/core/webpieces-versions.d.ts +98 -0
- package/src/core/webpieces-versions.js +206 -0
- package/src/core/webpieces-versions.js.map +1 -0
- package/src/core/workflow-hook-rules.d.ts +5 -0
- package/src/core/workflow-hook-rules.js +15 -0
- package/src/core/workflow-hook-rules.js.map +1 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +28 -0
- package/src/index.js.map +1 -0
- package/src/policy-keys.d.ts +2 -0
- package/src/policy-keys.js +6 -0
- package/src/policy-keys.js.map +1 -0
- package/src/rule-migrations.d.ts +3 -0
- package/src/rule-migrations.js +22 -0
- package/src/rule-migrations.js.map +1 -0
- package/src/rule-pack.d.ts +2 -0
- package/src/rule-pack.js +20 -0
- package/src/rule-pack.js.map +1 -0
- package/src/rule-settings.d.ts +5 -0
- package/src/rule-settings.js +31 -0
- package/src/rule-settings.js.map +1 -0
- package/src/safeguard-catalog.d.ts +3 -0
- package/src/safeguard-catalog.js +16 -0
- package/src/safeguard-catalog.js.map +1 -0
- package/templates/ai-hook.sh +497 -0
- package/templates/claude-settings-hook.json +28 -0
- package/templates/webpieces-reviewer.md +60 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main-sync-guard-configs.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/configs/main-sync-guard-configs.ts"],"names":[],"mappings":";;;AAAA,oDAA+F;AAC/F,oDAA+D;AAClD,QAAA,0BAA0B,GAAG,CAAC,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,sBAAuB,SAAQ,0BAAc;IAEtD,oGAAoG;IACpG,uEAAuE;IACvE,sBAAsB,CAAU;IAChC,oGAAoG;IACpG,wEAAwE;IACxE,kBAAkB,CAAU;IAC5B,6FAA6F;IAC7F,oFAAoF;IACpF,gBAAgB,CAAU;IAE1B,MAAM,CAAU,MAAM,GAAwC;QAC1D,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,wBAAY,CAAC;QAC1C,sBAAsB,EAAE,oBAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACnD,kBAAkB,EAAE,oBAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC/C,gBAAgB,EAAE,IAAI,oBAAQ,CAAC,QAAQ,CAAC;QACxC,GAAG,4BAAgB;KACtB,CAAC;;AAlBN,wDAmBC","sourcesContent":["import { FieldDef, SchemaShape, BaseRuleConfig, BASE_RULE_SCHEMA } from \"@webpieces/rules-sdk\";\nimport { OnOffMode, ON_OFF_MODES } from \"@webpieces/rules-sdk\";\nexport const DEFAULT_MAX_COMMITS_BEHIND = 5;\n\n/**\n * `branch-state-guard` — ONE key, ONE policy: *may I work here, and is what I read current?*\n *\n * Four CLASSES implement it, because the tool wiring genuinely differs (a Read names one file, a Bash\n * command is opaque, and the two Bash halves are not De Morgan duals of each other — see\n * guards/L2-branch-state.md, \"Deliberate divergence\"):\n *\n * | on stale `main` (state A) | on an already-merged branch (state B)\n * Write/Edit | feature-branch-guard | feature-branch-guard\n * Read | read-stale-guard | read-stale-guard\n * Bash | stale-main-bash-guard | merged-branch-bash-guard\n *\n * Those four class NAMES are unchanged and still appear in every decision-log line as `rule=`, so\n * `grep rule=stale-main-bash-guard` over `.webpieces/logs/L2-decisions` keeps working. What merged is\n * the SWITCH: all four read this one config entry (`AbstractRule.configKey`).\n *\n * ## Why one key and not four\n *\n * Four keys made **half a policy representable**: `read-stale-guard: OFF` beside\n * `merged-branch-bash-guard: ON` is \"read the file, yes; `cat` the same file, no\" — the same\n * information, opposite verdicts. Nobody chose that; it was reachable because the config had a knob\n * per class instead of a knob per decision. One key makes it unconstructible.\n *\n * And `hangTimeoutMinutes` was declared four times, read four times, and fed ONE shared refresher for\n * ONE shared cache — with a per-process latch (main-sync-refresh.ts) plus config-blind callers ahead of\n * the guards, so at most one of the four values could ever reach a spawn. Four knobs, one honoured; now\n * one knob, honoured everywhere (runner + hook-core route through this entry too).\n */\nexport class BranchStateGuardConfig extends BaseRuleConfig {\n declare mode?: OnOffMode;\n // Surfaced verbatim in the on-main block's message, so a project's own convention is what the agent\n // is told to follow. Consumed by FeatureBranchGuardRule.onMainMessage.\n branchNamingConvention?: string;\n // Tunes the DETACHED refresher's stale-lock reclaim window (main-sync.lock.json). One value for one\n // refresher writing one cache — which is what it always physically was.\n hangTimeoutMinutes?: number;\n // Maximum cached commit distance tolerated on local main. Required so every repo consciously\n // carries the policy; 5 means 0..5 are allowed and stale-main blocks starting at 6.\n maxCommitsBehind!: number;\n\n static readonly SCHEMA: SchemaShape<BranchStateGuardConfig> = {\n mode: new FieldDef('string', ON_OFF_MODES),\n branchNamingConvention: FieldDef.optional('string'),\n hangTimeoutMinutes: FieldDef.optional('number'),\n maxCommitsBehind: new FieldDef('number'),\n ...BASE_RULE_SCHEMA,\n };\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { OnOffMode } from "@webpieces/rules-sdk";
|
|
2
|
+
import { BaseRuleConfig } from "@webpieces/rules-sdk";
|
|
3
|
+
import { SchemaShape } from "@webpieces/rules-sdk";
|
|
4
|
+
export declare const BRANCH_GUARD_MODES: readonly ["ON", "OFF", "ON_NO_SUBBRANCHES"];
|
|
5
|
+
export type BranchGuardMode = typeof BRANCH_GUARD_MODES[number];
|
|
6
|
+
export declare class BranchCreationGuardConfig extends BaseRuleConfig {
|
|
7
|
+
mode?: BranchGuardMode;
|
|
8
|
+
subBranchNaming: string;
|
|
9
|
+
branchFormat?: string;
|
|
10
|
+
maxLocalBranches?: number;
|
|
11
|
+
maxWorktrees?: number;
|
|
12
|
+
autoReapMergedBranches?: boolean;
|
|
13
|
+
static readonly SCHEMA: SchemaShape<BranchCreationGuardConfig>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `pr-lifecycle-guard` — ONE key, ONE policy: *PRs and merges go through the gated flow.*
|
|
17
|
+
*
|
|
18
|
+
* Four CLASSES implement it, and their names are unchanged (they are the operator identity every
|
|
19
|
+
* decision-log line and every deny report carries):
|
|
20
|
+
*
|
|
21
|
+
* pr-creation-or-push-guard a manual `git push` / `gh pr create|edit` / a raw pulls API call
|
|
22
|
+
* merge-in-progress-guard a PR command while a 3-point merge is half-finished
|
|
23
|
+
* pr-merge-guard a bare `gh pr merge`
|
|
24
|
+
* redirect-how-to-merge-main "how do I get main into my branch?" → the documented flow
|
|
25
|
+
*
|
|
26
|
+
* ## Say this out loud: `"mode": "OFF"` releases the unvalidated-merge gate too
|
|
27
|
+
*
|
|
28
|
+
* Three of the four are pure COMMAND-SHAPE blocks and can never fire spuriously. The fourth,
|
|
29
|
+
* merge-in-progress-guard, is STATE-conditional — it fires only while a 3-point merge is actually in
|
|
30
|
+
* progress, and it is the one state L2 explicitly stands down for. So turning this key OFF to unblock
|
|
31
|
+
* `gh pr merge` ALSO drops the "you have an unfinished merge" gate. That is the honest cost of one key
|
|
32
|
+
* per policy, and it is stated here, in guards/L4-pr-lifecycle.md, and in the error path, rather than
|
|
33
|
+
* being papered over with a granular sub-mode (which would be four knobs wearing one key's name).
|
|
34
|
+
*
|
|
35
|
+
* ## The command strings are NOT here
|
|
36
|
+
*
|
|
37
|
+
* `upsertPrCommand` and `mergeCompleteCommand` used to sit on the two guards, and — being read at the
|
|
38
|
+
* point of use — they BEAT `commands.guardHints`, so `guardHintsWhy`'s claim that renaming a gated
|
|
39
|
+
* command there makes "every guard message follow" was simply false. They are DELETED, not deprecated.
|
|
40
|
+
* `commands.guardHints.prCreationOrPush` / `.mergeInProgress` is the one place those strings live, and
|
|
41
|
+
* the loader hands the resolved values to the two rules directly. A consumer that still sets the old
|
|
42
|
+
* per-guard field gets a RETIRED_FIELD_HINTS error naming the destination.
|
|
43
|
+
*/
|
|
44
|
+
export declare class PrLifecycleGuardConfig extends BaseRuleConfig {
|
|
45
|
+
mode?: OnOffMode;
|
|
46
|
+
static readonly SCHEMA: SchemaShape<PrLifecycleGuardConfig>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrLifecycleGuardConfig = exports.BranchCreationGuardConfig = exports.BRANCH_GUARD_MODES = void 0;
|
|
4
|
+
const rules_sdk_1 = require("@webpieces/rules-sdk");
|
|
5
|
+
const rules_sdk_2 = require("@webpieces/rules-sdk");
|
|
6
|
+
const rules_sdk_3 = require("@webpieces/rules-sdk");
|
|
7
|
+
// branch-creation-guard modes. ON_NO_SUBBRANCHES is the strict variant: it hard-blocks
|
|
8
|
+
// creating a branch off any non-main branch (no sub-branch affordance), pointing the agent
|
|
9
|
+
// back to `git checkout main && git pull && git checkout -b <branch>`. Temporarily overridable
|
|
10
|
+
// via the universal turnOffRuleUntilEpoch escape hatch.
|
|
11
|
+
exports.BRANCH_GUARD_MODES = ['ON', 'OFF', 'ON_NO_SUBBRANCHES'];
|
|
12
|
+
class BranchCreationGuardConfig extends rules_sdk_2.BaseRuleConfig {
|
|
13
|
+
// Naming pattern for stacked SUB-branches only (branches created off another feature branch,
|
|
14
|
+
// which require human approval). Never applied to branches created off main.
|
|
15
|
+
//
|
|
16
|
+
// Schema-REQUIRED (#1017), like `mode` and `autoReapMergedBranches`, and for the same reason: it
|
|
17
|
+
// is BEHAVIOUR, not a knob. This string decides which branch names the guard BLOCKS, and the
|
|
18
|
+
// refusal quotes it back at the agent as the convention to follow — so a repo running webpieces'
|
|
19
|
+
// shipped value is a repo whose branch-naming convention was chosen by a framework author who
|
|
20
|
+
// never saw it. TS-optional but schema-required, the split `mode` uses: absent at RUNTIME means
|
|
21
|
+
// the config never passed validation.
|
|
22
|
+
subBranchNaming;
|
|
23
|
+
// Human-sentence instruction telling the AI how to name a NEW branch off main. Surfaced back
|
|
24
|
+
// to the agent in the guard's fix hints. May mirror no-edit-on-main.branchNamingConvention.
|
|
25
|
+
branchFormat;
|
|
26
|
+
// Hard cap on local feature branches (excluding main). Creating one past the cap is BLOCKED until
|
|
27
|
+
// already-merged branches are reaped, which is what keeps the branch list from growing without
|
|
28
|
+
// bound. Branch creation is the gate because it is the only moment cleanup is both cheap and
|
|
29
|
+
// obviously worth it. See merged-branches.ts for how "already merged" is determined.
|
|
30
|
+
maxLocalBranches;
|
|
31
|
+
// Hard cap on LINKED worktrees (the primary clone is never counted). A separate budget from
|
|
32
|
+
// maxLocalBranches: every worktree holds a branch, so if worktree-held branches also spent the
|
|
33
|
+
// branch budget, five worktrees would leave room for zero branches. Held branches count here;
|
|
34
|
+
// parked branches count against maxLocalBranches. Enforced at `git worktree add`.
|
|
35
|
+
maxWorktrees;
|
|
36
|
+
// Let the detached background refresher DELETE dead branches on its own, instead of only
|
|
37
|
+
// reporting them. Every candidate is provably dead (a MERGED PR — its own, or the PR of the branch
|
|
38
|
+
// it snapshots; nothing else qualifies) and
|
|
39
|
+
// recoverable by the SHA logged to branch-mutations.log — but it is still UNATTENDED deletion,
|
|
40
|
+
// so this is schema-REQUIRED like `mode` and `turnOffRuleUntilEpoch`. "Every built-in rule
|
|
41
|
+
// must be explicitly configured — no silent defaults" (validate-config.ts) applies with extra
|
|
42
|
+
// force here: branches disappearing on a preference nobody ever stated is precisely the kind of
|
|
43
|
+
// default that must not exist. Validation makes each consumer answer the question once.
|
|
44
|
+
//
|
|
45
|
+
// TS-optional but schema-required — the same split `mode` uses. Absent at RUNTIME therefore means
|
|
46
|
+
// the config never passed validation, and the only safe reading of "nobody has answered" is: do
|
|
47
|
+
// not delete anything.
|
|
48
|
+
autoReapMergedBranches;
|
|
49
|
+
static SCHEMA = {
|
|
50
|
+
mode: new rules_sdk_3.FieldDef('string', exports.BRANCH_GUARD_MODES),
|
|
51
|
+
subBranchNaming: new rules_sdk_3.FieldDef('string'),
|
|
52
|
+
branchFormat: rules_sdk_3.FieldDef.optional('string'),
|
|
53
|
+
maxLocalBranches: rules_sdk_3.FieldDef.optional('number'),
|
|
54
|
+
maxWorktrees: rules_sdk_3.FieldDef.optional('number'),
|
|
55
|
+
autoReapMergedBranches: new rules_sdk_3.FieldDef('boolean'),
|
|
56
|
+
...rules_sdk_2.BASE_RULE_SCHEMA,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
exports.BranchCreationGuardConfig = BranchCreationGuardConfig;
|
|
60
|
+
/**
|
|
61
|
+
* `pr-lifecycle-guard` — ONE key, ONE policy: *PRs and merges go through the gated flow.*
|
|
62
|
+
*
|
|
63
|
+
* Four CLASSES implement it, and their names are unchanged (they are the operator identity every
|
|
64
|
+
* decision-log line and every deny report carries):
|
|
65
|
+
*
|
|
66
|
+
* pr-creation-or-push-guard a manual `git push` / `gh pr create|edit` / a raw pulls API call
|
|
67
|
+
* merge-in-progress-guard a PR command while a 3-point merge is half-finished
|
|
68
|
+
* pr-merge-guard a bare `gh pr merge`
|
|
69
|
+
* redirect-how-to-merge-main "how do I get main into my branch?" → the documented flow
|
|
70
|
+
*
|
|
71
|
+
* ## Say this out loud: `"mode": "OFF"` releases the unvalidated-merge gate too
|
|
72
|
+
*
|
|
73
|
+
* Three of the four are pure COMMAND-SHAPE blocks and can never fire spuriously. The fourth,
|
|
74
|
+
* merge-in-progress-guard, is STATE-conditional — it fires only while a 3-point merge is actually in
|
|
75
|
+
* progress, and it is the one state L2 explicitly stands down for. So turning this key OFF to unblock
|
|
76
|
+
* `gh pr merge` ALSO drops the "you have an unfinished merge" gate. That is the honest cost of one key
|
|
77
|
+
* per policy, and it is stated here, in guards/L4-pr-lifecycle.md, and in the error path, rather than
|
|
78
|
+
* being papered over with a granular sub-mode (which would be four knobs wearing one key's name).
|
|
79
|
+
*
|
|
80
|
+
* ## The command strings are NOT here
|
|
81
|
+
*
|
|
82
|
+
* `upsertPrCommand` and `mergeCompleteCommand` used to sit on the two guards, and — being read at the
|
|
83
|
+
* point of use — they BEAT `commands.guardHints`, so `guardHintsWhy`'s claim that renaming a gated
|
|
84
|
+
* command there makes "every guard message follow" was simply false. They are DELETED, not deprecated.
|
|
85
|
+
* `commands.guardHints.prCreationOrPush` / `.mergeInProgress` is the one place those strings live, and
|
|
86
|
+
* the loader hands the resolved values to the two rules directly. A consumer that still sets the old
|
|
87
|
+
* per-guard field gets a RETIRED_FIELD_HINTS error naming the destination.
|
|
88
|
+
*/
|
|
89
|
+
class PrLifecycleGuardConfig extends rules_sdk_2.BaseRuleConfig {
|
|
90
|
+
static SCHEMA = {
|
|
91
|
+
mode: new rules_sdk_3.FieldDef('string', rules_sdk_1.ON_OFF_MODES),
|
|
92
|
+
...rules_sdk_2.BASE_RULE_SCHEMA,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
exports.PrLifecycleGuardConfig = PrLifecycleGuardConfig;
|
|
96
|
+
//# sourceMappingURL=rule-configs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-configs.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/configs/rule-configs.ts"],"names":[],"mappings":";;;AAAA,oDAA+D;AAC/D,oDAAwE;AACxE,oDAA6D;AAC7D,uFAAuF;AACvF,2FAA2F;AAC3F,+FAA+F;AAC/F,wDAAwD;AAC3C,QAAA,kBAAkB,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,mBAAmB,CAAU,CAAC;AAI9E,MAAa,yBAA0B,SAAQ,0BAAc;IAEzD,6FAA6F;IAC7F,6EAA6E;IAC7E,EAAE;IACF,iGAAiG;IACjG,6FAA6F;IAC7F,iGAAiG;IACjG,8FAA8F;IAC9F,gGAAgG;IAChG,sCAAsC;IACtC,eAAe,CAAU;IACzB,6FAA6F;IAC7F,4FAA4F;IAC5F,YAAY,CAAU;IACtB,kGAAkG;IAClG,+FAA+F;IAC/F,6FAA6F;IAC7F,qFAAqF;IACrF,gBAAgB,CAAU;IAC1B,4FAA4F;IAC5F,+FAA+F;IAC/F,8FAA8F;IAC9F,kFAAkF;IAClF,YAAY,CAAU;IACtB,yFAAyF;IACzF,mGAAmG;IACnG,4CAA4C;IAC5C,+FAA+F;IAC/F,2FAA2F;IAC3F,8FAA8F;IAC9F,gGAAgG;IAChG,wFAAwF;IACxF,EAAE;IACF,kGAAkG;IAClG,gGAAgG;IAChG,uBAAuB;IACvB,sBAAsB,CAAW;IAEjC,MAAM,CAAU,MAAM,GAA2C;QAC7D,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,0BAAkB,CAAC;QAChD,eAAe,EAAE,IAAI,oBAAQ,CAAC,QAAQ,CAAC;QACvC,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACzC,gBAAgB,EAAE,oBAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC7C,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACzC,sBAAsB,EAAE,IAAI,oBAAQ,CAAC,SAAS,CAAC;QAC/C,GAAG,4BAAgB;KACtB,CAAC;;AA/CN,8DAgDC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,sBAAuB,SAAQ,0BAAc;IAGtD,MAAM,CAAU,MAAM,GAAwC;QAC1D,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,wBAAY,CAAC;QAC1C,GAAG,4BAAgB;KACtB,CAAC;;AANN,wDAOC","sourcesContent":["import { OnOffMode, ON_OFF_MODES } from \"@webpieces/rules-sdk\";\nimport { BaseRuleConfig, BASE_RULE_SCHEMA } from \"@webpieces/rules-sdk\";\nimport { FieldDef, SchemaShape } from \"@webpieces/rules-sdk\";\n// branch-creation-guard modes. ON_NO_SUBBRANCHES is the strict variant: it hard-blocks\n// creating a branch off any non-main branch (no sub-branch affordance), pointing the agent\n// back to `git checkout main && git pull && git checkout -b <branch>`. Temporarily overridable\n// via the universal turnOffRuleUntilEpoch escape hatch.\nexport const BRANCH_GUARD_MODES = ['ON', 'OFF', 'ON_NO_SUBBRANCHES'] as const;\n\nexport type BranchGuardMode = typeof BRANCH_GUARD_MODES[number];\n\nexport class BranchCreationGuardConfig extends BaseRuleConfig {\n declare mode?: BranchGuardMode;\n // Naming pattern for stacked SUB-branches only (branches created off another feature branch,\n // which require human approval). Never applied to branches created off main.\n //\n // Schema-REQUIRED (#1017), like `mode` and `autoReapMergedBranches`, and for the same reason: it\n // is BEHAVIOUR, not a knob. This string decides which branch names the guard BLOCKS, and the\n // refusal quotes it back at the agent as the convention to follow — so a repo running webpieces'\n // shipped value is a repo whose branch-naming convention was chosen by a framework author who\n // never saw it. TS-optional but schema-required, the split `mode` uses: absent at RUNTIME means\n // the config never passed validation.\n subBranchNaming!: string;\n // Human-sentence instruction telling the AI how to name a NEW branch off main. Surfaced back\n // to the agent in the guard's fix hints. May mirror no-edit-on-main.branchNamingConvention.\n branchFormat?: string;\n // Hard cap on local feature branches (excluding main). Creating one past the cap is BLOCKED until\n // already-merged branches are reaped, which is what keeps the branch list from growing without\n // bound. Branch creation is the gate because it is the only moment cleanup is both cheap and\n // obviously worth it. See merged-branches.ts for how \"already merged\" is determined.\n maxLocalBranches?: number;\n // Hard cap on LINKED worktrees (the primary clone is never counted). A separate budget from\n // maxLocalBranches: every worktree holds a branch, so if worktree-held branches also spent the\n // branch budget, five worktrees would leave room for zero branches. Held branches count here;\n // parked branches count against maxLocalBranches. Enforced at `git worktree add`.\n maxWorktrees?: number;\n // Let the detached background refresher DELETE dead branches on its own, instead of only\n // reporting them. Every candidate is provably dead (a MERGED PR — its own, or the PR of the branch\n // it snapshots; nothing else qualifies) and\n // recoverable by the SHA logged to branch-mutations.log — but it is still UNATTENDED deletion,\n // so this is schema-REQUIRED like `mode` and `turnOffRuleUntilEpoch`. \"Every built-in rule\n // must be explicitly configured — no silent defaults\" (validate-config.ts) applies with extra\n // force here: branches disappearing on a preference nobody ever stated is precisely the kind of\n // default that must not exist. Validation makes each consumer answer the question once.\n //\n // TS-optional but schema-required — the same split `mode` uses. Absent at RUNTIME therefore means\n // the config never passed validation, and the only safe reading of \"nobody has answered\" is: do\n // not delete anything.\n autoReapMergedBranches?: boolean;\n\n static readonly SCHEMA: SchemaShape<BranchCreationGuardConfig> = {\n mode: new FieldDef('string', BRANCH_GUARD_MODES),\n subBranchNaming: new FieldDef('string'),\n branchFormat: FieldDef.optional('string'),\n maxLocalBranches: FieldDef.optional('number'),\n maxWorktrees: FieldDef.optional('number'),\n autoReapMergedBranches: new FieldDef('boolean'),\n ...BASE_RULE_SCHEMA,\n };\n}\n\n/**\n * `pr-lifecycle-guard` — ONE key, ONE policy: *PRs and merges go through the gated flow.*\n *\n * Four CLASSES implement it, and their names are unchanged (they are the operator identity every\n * decision-log line and every deny report carries):\n *\n * pr-creation-or-push-guard a manual `git push` / `gh pr create|edit` / a raw pulls API call\n * merge-in-progress-guard a PR command while a 3-point merge is half-finished\n * pr-merge-guard a bare `gh pr merge`\n * redirect-how-to-merge-main \"how do I get main into my branch?\" → the documented flow\n *\n * ## Say this out loud: `\"mode\": \"OFF\"` releases the unvalidated-merge gate too\n *\n * Three of the four are pure COMMAND-SHAPE blocks and can never fire spuriously. The fourth,\n * merge-in-progress-guard, is STATE-conditional — it fires only while a 3-point merge is actually in\n * progress, and it is the one state L2 explicitly stands down for. So turning this key OFF to unblock\n * `gh pr merge` ALSO drops the \"you have an unfinished merge\" gate. That is the honest cost of one key\n * per policy, and it is stated here, in guards/L4-pr-lifecycle.md, and in the error path, rather than\n * being papered over with a granular sub-mode (which would be four knobs wearing one key's name).\n *\n * ## The command strings are NOT here\n *\n * `upsertPrCommand` and `mergeCompleteCommand` used to sit on the two guards, and — being read at the\n * point of use — they BEAT `commands.guardHints`, so `guardHintsWhy`'s claim that renaming a gated\n * command there makes \"every guard message follow\" was simply false. They are DELETED, not deprecated.\n * `commands.guardHints.prCreationOrPush` / `.mergeInProgress` is the one place those strings live, and\n * the loader hands the resolved values to the two rules directly. A consumer that still sets the old\n * per-guard field gets a RETIRED_FIELD_HINTS error naming the destination.\n */\nexport class PrLifecycleGuardConfig extends BaseRuleConfig {\n declare mode?: OnOffMode;\n\n static readonly SCHEMA: SchemaShape<PrLifecycleGuardConfig> = {\n mode: new FieldDef('string', ON_OFF_MODES),\n ...BASE_RULE_SCHEMA,\n };\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AiType } from '@webpieces/hook-runtime';
|
|
2
|
+
/**
|
|
3
|
+
* WHICH HARNESS this hook process is serving, for the four JS-side audit streams.
|
|
4
|
+
*
|
|
5
|
+
* ─── Why a process-wide holder and not a parameter ────────────────────────────────────────────────
|
|
6
|
+
* One hook process handles exactly one tool call, so the harness is a property of the PROCESS, not of
|
|
7
|
+
* any individual log line. Threading it as a parameter instead would have meant a new argument on
|
|
8
|
+
* `logGuardDecision()`, `logL1Decision()`, `InvocationLog.finish()` and `logRejection()`, which between
|
|
9
|
+
* them are constructed at fourteen call sites across eight guard modules — none of which has any
|
|
10
|
+
* business knowing what a harness is. That is the identical argument `LogStream`'s docblock makes for
|
|
11
|
+
* the session/agent/hook identity, and this is the identical shape: identified ONCE by the adapter that
|
|
12
|
+
* parsed the payload, read by every writer downstream.
|
|
13
|
+
*
|
|
14
|
+
* ─── Why it is NOT folded into StreamIdentity ─────────────────────────────────────────────────────
|
|
15
|
+
* `StreamIdentity` is defined as "the three fields that make a log FILENAME unique", and it crosses a
|
|
16
|
+
* process boundary on argv (the detached main-sync refresher). The harness is neither: it never appears
|
|
17
|
+
* in a filename, and a fourth field would have to be threaded through that argv round trip to mean
|
|
18
|
+
* anything. Two small values with two clear jobs beat one value that answers two different questions.
|
|
19
|
+
*
|
|
20
|
+
* ─── `unknown` is a value ─────────────────────────────────────────────────────────────────────────
|
|
21
|
+
* A writer reached before any payload was parsed — the openclaw plugin, a library consumer, a spec —
|
|
22
|
+
* renders `ai=unknown`, and so does every row written by a release older than this field. That is a real
|
|
23
|
+
* value to count, not an absence and not a back-compat shim: see AI_TYPE_UNKNOWN.
|
|
24
|
+
*/
|
|
25
|
+
export declare class AiTypeContext {
|
|
26
|
+
private aiType;
|
|
27
|
+
/** Called once per invocation, by the adapter that parsed the payload. */
|
|
28
|
+
identify(aiType: AiType): void;
|
|
29
|
+
/** The `ai=` field's value — the harness, or `unknown` when nothing established one. */
|
|
30
|
+
forLog(): string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Process-wide instance, for the reason given above and in LogStream's own docblock: one process, one
|
|
34
|
+
* tool call, one harness.
|
|
35
|
+
*/
|
|
36
|
+
export declare const aiTypeContext: AiTypeContext;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aiTypeContext = exports.AiTypeContext = void 0;
|
|
4
|
+
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
5
|
+
/**
|
|
6
|
+
* WHICH HARNESS this hook process is serving, for the four JS-side audit streams.
|
|
7
|
+
*
|
|
8
|
+
* ─── Why a process-wide holder and not a parameter ────────────────────────────────────────────────
|
|
9
|
+
* One hook process handles exactly one tool call, so the harness is a property of the PROCESS, not of
|
|
10
|
+
* any individual log line. Threading it as a parameter instead would have meant a new argument on
|
|
11
|
+
* `logGuardDecision()`, `logL1Decision()`, `InvocationLog.finish()` and `logRejection()`, which between
|
|
12
|
+
* them are constructed at fourteen call sites across eight guard modules — none of which has any
|
|
13
|
+
* business knowing what a harness is. That is the identical argument `LogStream`'s docblock makes for
|
|
14
|
+
* the session/agent/hook identity, and this is the identical shape: identified ONCE by the adapter that
|
|
15
|
+
* parsed the payload, read by every writer downstream.
|
|
16
|
+
*
|
|
17
|
+
* ─── Why it is NOT folded into StreamIdentity ─────────────────────────────────────────────────────
|
|
18
|
+
* `StreamIdentity` is defined as "the three fields that make a log FILENAME unique", and it crosses a
|
|
19
|
+
* process boundary on argv (the detached main-sync refresher). The harness is neither: it never appears
|
|
20
|
+
* in a filename, and a fourth field would have to be threaded through that argv round trip to mean
|
|
21
|
+
* anything. Two small values with two clear jobs beat one value that answers two different questions.
|
|
22
|
+
*
|
|
23
|
+
* ─── `unknown` is a value ─────────────────────────────────────────────────────────────────────────
|
|
24
|
+
* A writer reached before any payload was parsed — the openclaw plugin, a library consumer, a spec —
|
|
25
|
+
* renders `ai=unknown`, and so does every row written by a release older than this field. That is a real
|
|
26
|
+
* value to count, not an absence and not a back-compat shim: see AI_TYPE_UNKNOWN.
|
|
27
|
+
*/
|
|
28
|
+
class AiTypeContext {
|
|
29
|
+
aiType = null;
|
|
30
|
+
/** Called once per invocation, by the adapter that parsed the payload. */
|
|
31
|
+
identify(aiType) {
|
|
32
|
+
this.aiType = aiType;
|
|
33
|
+
}
|
|
34
|
+
/** The `ai=` field's value — the harness, or `unknown` when nothing established one. */
|
|
35
|
+
forLog() {
|
|
36
|
+
return this.aiType ?? hook_runtime_1.AI_TYPE_UNKNOWN;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.AiTypeContext = AiTypeContext;
|
|
40
|
+
/**
|
|
41
|
+
* Process-wide instance, for the reason given above and in LogStream's own docblock: one process, one
|
|
42
|
+
* tool call, one harness.
|
|
43
|
+
*/
|
|
44
|
+
exports.aiTypeContext = new AiTypeContext();
|
|
45
|
+
//# sourceMappingURL=ai-type-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-type-context.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/ai-type-context.ts"],"names":[],"mappings":";;;AAAA,0DAAkE;AAElE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,aAAa;IACd,MAAM,GAAkB,IAAI,CAAC;IAErC,0EAA0E;IAC1E,QAAQ,CAAC,MAAc;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,wFAAwF;IACxF,MAAM;QACF,OAAO,IAAI,CAAC,MAAM,IAAI,8BAAe,CAAC;IAC1C,CAAC;CACJ;AAZD,sCAYC;AAED;;;GAGG;AACU,QAAA,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC","sourcesContent":["import { AiType, AI_TYPE_UNKNOWN } from '@webpieces/hook-runtime';\n\n/**\n * WHICH HARNESS this hook process is serving, for the four JS-side audit streams.\n *\n * ─── Why a process-wide holder and not a parameter ────────────────────────────────────────────────\n * One hook process handles exactly one tool call, so the harness is a property of the PROCESS, not of\n * any individual log line. Threading it as a parameter instead would have meant a new argument on\n * `logGuardDecision()`, `logL1Decision()`, `InvocationLog.finish()` and `logRejection()`, which between\n * them are constructed at fourteen call sites across eight guard modules — none of which has any\n * business knowing what a harness is. That is the identical argument `LogStream`'s docblock makes for\n * the session/agent/hook identity, and this is the identical shape: identified ONCE by the adapter that\n * parsed the payload, read by every writer downstream.\n *\n * ─── Why it is NOT folded into StreamIdentity ─────────────────────────────────────────────────────\n * `StreamIdentity` is defined as \"the three fields that make a log FILENAME unique\", and it crosses a\n * process boundary on argv (the detached main-sync refresher). The harness is neither: it never appears\n * in a filename, and a fourth field would have to be threaded through that argv round trip to mean\n * anything. Two small values with two clear jobs beat one value that answers two different questions.\n *\n * ─── `unknown` is a value ─────────────────────────────────────────────────────────────────────────\n * A writer reached before any payload was parsed — the openclaw plugin, a library consumer, a spec —\n * renders `ai=unknown`, and so does every row written by a release older than this field. That is a real\n * value to count, not an absence and not a back-compat shim: see AI_TYPE_UNKNOWN.\n */\nexport class AiTypeContext {\n private aiType: AiType | null = null;\n\n /** Called once per invocation, by the adapter that parsed the payload. */\n identify(aiType: AiType): void {\n this.aiType = aiType;\n }\n\n /** The `ai=` field's value — the harness, or `unknown` when nothing established one. */\n forLog(): string {\n return this.aiType ?? AI_TYPE_UNKNOWN;\n }\n}\n\n/**\n * Process-wide instance, for the reason given above and in LogStream's own docblock: one process, one\n * tool call, one harness.\n */\nexport const aiTypeContext = new AiTypeContext();\n"]}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE ACTION CODEBOOK, as a type. These are the five actions GUARD_MATRIX.md numbers 1-5, and they
|
|
3
|
+
* are the vocabulary EVERY layer reports in — so one grep spans L-1, L0, L1 and L2.
|
|
4
|
+
*
|
|
5
|
+
* The three distinctions this exists to make, none of which `'ALLOW' | 'BLOCK'` could:
|
|
6
|
+
*
|
|
7
|
+
* ALLOW no objection — the call was HANDED DOWN to the next layer. A layer saying ALLOW
|
|
8
|
+
* is NOT saying the call ran: the layer below it, or the OTHER parallel hook, may
|
|
9
|
+
* still deny. This is L1's `ACT_DOWN`.
|
|
10
|
+
* ALLOW_EXEMPT out of scope by construction — allowed, and evaluation STOPS here. L1's
|
|
11
|
+
* `ACT_EXEMPT`.
|
|
12
|
+
* ALLOW_FAIL_OPEN state could not be established, so nothing was judged. Keeping this distinct
|
|
13
|
+
* from ALLOW is the entire point of the type: a fail-open allow and a real allow
|
|
14
|
+
* that look identical make it impossible to tell whether the guards are protecting
|
|
15
|
+
* anything or quietly abstaining. It used to be a `' (fail-open)'` SUBSTRING on the
|
|
16
|
+
* reason field, which is exactly why the abstentions were never countable.
|
|
17
|
+
* BLOCK_AI_CURE blocked, and the printed cure is a command the AI can run itself.
|
|
18
|
+
* BLOCK_HUMAN blocked, and it needs a human decision — or a delegation (spawn a subagent) that
|
|
19
|
+
* the blocked agent cannot perform for itself.
|
|
20
|
+
*
|
|
21
|
+
* Hard cut, per `.claude/rules/no-backwards-compat.md`: `'BLOCK'` is GONE rather than aliased, so every
|
|
22
|
+
* construction site fails to
|
|
23
|
+
* compile and has to say which kind of block it is. Before, that question had exactly one wrong
|
|
24
|
+
* answer available — silence.
|
|
25
|
+
*/
|
|
26
|
+
export type Verdict = 'ALLOW' | 'ALLOW_EXEMPT' | 'ALLOW_FAIL_OPEN' | 'BLOCK_AI_CURE' | 'BLOCK_HUMAN';
|
|
27
|
+
/**
|
|
28
|
+
* WHICH ROW of WHICH layer's decision table produced this line. Data-only → a class, per CLAUDE.md.
|
|
29
|
+
*
|
|
30
|
+
* `row` is the row NUMBER from the layer's row array (`L1_ROWS[i].num`, `L2_ROWS[i].num`) — the
|
|
31
|
+
* same number the generated doc prints, because the doc is rendered from that same array. So a log
|
|
32
|
+
* line joins to its matrix row BY NUMBER, and checking observed behaviour against the documented use
|
|
33
|
+
* cases becomes a lookup rather than an investigation.
|
|
34
|
+
*/
|
|
35
|
+
export declare class MatrixRef {
|
|
36
|
+
readonly layer: string;
|
|
37
|
+
readonly row: string;
|
|
38
|
+
constructor(layer: string, row: string);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The layer tokens. EVERY layer now cites a row: L0 through its two decision-matrix rows, L1 through
|
|
42
|
+
* L1_ROWS, and L2 through L2_ROWS (see `matrixL2Row`). This used to say `'-'` was for "a layer with no
|
|
43
|
+
* row array YET (L2 is the un-converted one)" — L2 is converted, and a comment describing a state the
|
|
44
|
+
* code left behind is exactly the kind of doc a reader trusts and should not.
|
|
45
|
+
*
|
|
46
|
+
* `'-'` survives for ONE case, and it is a real one: an L2 reason that no row claims. See matrixL2Row.
|
|
47
|
+
*
|
|
48
|
+
* These are REQUIRED at the constructor, not defaulted: a defaulted `MatrixRef` would make the
|
|
49
|
+
* uncited case reachable by doing nothing and impossible to grep — the same defect this file's own
|
|
50
|
+
* docblock argues against for `'BLOCK'`, where silence was the one wrong answer available.
|
|
51
|
+
*
|
|
52
|
+
* L0 NOW CITES ITS ROW TOO. It used to be `'-'` on the grounds that "L0's faults are a table of letters
|
|
53
|
+
* rather than numbered rows" — but L0 has BOTH: the letter says WHICH fault, and the numbered decision
|
|
54
|
+
* matrix (`renderGuardMatrixDoc`) says which of its three rows was taken. There is one ALLOW row and one
|
|
55
|
+
* BLOCK row, so the pair `row=` + `fault=` pins the decision exactly, and the deny an agent reads now
|
|
56
|
+
* carries the identical pair. That is the join: one grep spans the deny, the log line and the doc.
|
|
57
|
+
* Two constants, not one `MATRIX_L0`, because the two call sites are a cure-bypass ALLOW and an L0
|
|
58
|
+
* BLOCK — one token covering both is what made the row unciteable in the first place.
|
|
59
|
+
*/
|
|
60
|
+
export declare const MATRIX_L0_ALLOW: MatrixRef;
|
|
61
|
+
export declare const MATRIX_L0_BLOCK: MatrixRef;
|
|
62
|
+
/**
|
|
63
|
+
* The L2 reference for one decision, with the row DERIVED FROM THE REASON.
|
|
64
|
+
*
|
|
65
|
+
* There is no `MATRIX_L2` constant any more, and its absence is the point: a single shared instance
|
|
66
|
+
* meant every L2 line in the repo carried `row=-`, which reads as "L2 has no rows" rather than "this
|
|
67
|
+
* decision was not classified". Deleting it makes every construction site name a reason, and the reason
|
|
68
|
+
* is the only thing a call site has that identifies which row it is an instance of.
|
|
69
|
+
*
|
|
70
|
+
* `l2RowForReason` returns null for a reason no row claims, and that renders as `'-'` — visible in the
|
|
71
|
+
* log, not silently absorbed into a default row. l2-matrix.spec.ts reads the four guard sources and
|
|
72
|
+
* fails the build if any reason literal in them is unmapped, so `-` should never appear in practice;
|
|
73
|
+
* when it does, it is a genuine hole in the table and the log says so.
|
|
74
|
+
*/
|
|
75
|
+
export declare function matrixL2Row(reason: string): MatrixRef;
|
|
76
|
+
/**
|
|
77
|
+
* The L2 stream, with NO row — for the two kinds of line that genuinely are not an instance of a row.
|
|
78
|
+
*
|
|
79
|
+
* 1. The runner's AGGREGATE bash lines ("no bash-guard block" / "bash-guard block"). They summarise
|
|
80
|
+
* the whole guard set's answer for one command, not one row's verdict; the per-guard lines that
|
|
81
|
+
* DO cite rows are written alongside them by the guards themselves.
|
|
82
|
+
* 2. `whole-repo-build-guard`, which is not a branch-state policy at all — it is the experimental
|
|
83
|
+
* home-config guard, has no webpieces.config.json entry, and shares this stream only because the
|
|
84
|
+
* stream is "bash decisions", not "L2 rows".
|
|
85
|
+
*
|
|
86
|
+
* A NAMED constant rather than an inline `new MatrixRef('L2', '-')`, so `grep MATRIX_L2_UNROWED` lists
|
|
87
|
+
* every uncited line and the list stays short and arguable. It is deliberately NOT called `MATRIX_L2`:
|
|
88
|
+
* the old name was used by everything and made "L2 has no rows" indistinguishable from "this line is
|
|
89
|
+
* not a row".
|
|
90
|
+
*/
|
|
91
|
+
export declare const MATRIX_L2_UNROWED: MatrixRef;
|
|
92
|
+
export declare class GuardDecision {
|
|
93
|
+
rule: string;
|
|
94
|
+
tool: string;
|
|
95
|
+
target: string;
|
|
96
|
+
branch: string;
|
|
97
|
+
verdict: Verdict;
|
|
98
|
+
reason: string;
|
|
99
|
+
cache: string;
|
|
100
|
+
/**
|
|
101
|
+
* The L0 fault this decision IS, in the codebook's letter (core/l0-fault-codes.ts), or `-` for an
|
|
102
|
+
* ordinary rule decision. The `sh` shim has always stamped `fault=` on its own stream; the three
|
|
103
|
+
* JS-side faults (S/C/Y) reached this one with no label at all, so `grep fault=S` found nothing
|
|
104
|
+
* even while an S storm was blocking every call.
|
|
105
|
+
*/
|
|
106
|
+
fault: string;
|
|
107
|
+
/** Which layer + row decided this. See MatrixRef — it is what joins a log line to the doc. */
|
|
108
|
+
matrix: MatrixRef;
|
|
109
|
+
constructor(rule: string, tool: string, target: string, branch: string, verdict: Verdict, reason: string, cache: string | undefined, fault: string, matrix: MatrixRef);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Append one tab-separated line per L2 decision to `.webpieces/logs/L2-decisions/<writer>.log`, where
|
|
113
|
+
* <writer> is LogStream's `<sessionId>-<agentId|coordinator>-<hook>` key (a caller that never
|
|
114
|
+
* identified renders as `unknown-coordinator-hook` — there is no un-keyed name).
|
|
115
|
+
* `root` is
|
|
116
|
+
* the repo/workspace root that holds `.webpieces` (callers pass workspaceRoot, or a
|
|
117
|
+
* RepoRootFinder-resolved root at the pre-load config-bypass site — never a raw cwd, so a bypass
|
|
118
|
+
* logged from a subdir never scatters a stray `.webpieces`). Swallows all errors — logging must never
|
|
119
|
+
* block or fail a hook.
|
|
120
|
+
*/
|
|
121
|
+
export declare function logGuardDecision(root: string, decision: GuardDecision): void;
|
|
122
|
+
/**
|
|
123
|
+
* The L1 stream — `.webpieces/logs/L1-location/<writer>.log`.
|
|
124
|
+
*
|
|
125
|
+
* L1 had NO stream. Its three blocking paths wrote into L2's file under an implementation name
|
|
126
|
+
* (`force-to-root`, `trinary-version-skew`, `cd-must-be-first`), and its NON-blocking outcomes —
|
|
127
|
+
* the exempt row and the three hand-down rows — wrote nothing at all. So "L1 had no objection" was
|
|
128
|
+
* unobservable, and "show me every L1 decision" had no answer: L1 existed in the trail only as the
|
|
129
|
+
* `root=` / `projectDir=` / `tree=` columns stapled onto somebody else's line.
|
|
130
|
+
*
|
|
131
|
+
* A SIBLING rather than a `base` parameter on logGuardDecision, deliberately: that signature is what
|
|
132
|
+
* the process-wide `logStream` singleton exists to keep unchanged (see LogStream's docblock), and
|
|
133
|
+
* `INVOCATION_LOG_FILE` already establishes the pattern of a second stream owning its own name in
|
|
134
|
+
* this same module.
|
|
135
|
+
*/
|
|
136
|
+
export declare function logL1Decision(root: string, decision: GuardDecision): void;
|
|
137
|
+
/**
|
|
138
|
+
* What the guard SAW on one invocation, captured up front and held until the outcome is known.
|
|
139
|
+
* Data-only (per CLAUDE.md: classes for data, explicit construction).
|
|
140
|
+
*/
|
|
141
|
+
export declare class GuardInvocation {
|
|
142
|
+
readonly root: string;
|
|
143
|
+
readonly timestamp: string;
|
|
144
|
+
readonly tool: string;
|
|
145
|
+
readonly target: string;
|
|
146
|
+
readonly branch: string;
|
|
147
|
+
readonly sync: string;
|
|
148
|
+
readonly projectDir: string;
|
|
149
|
+
constructor(root: string, timestamp: string, tool: string, target: string, branch: string, sync: string, projectDir: string);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The per-INVOCATION stream — `.webpieces/logs/calls/<writer>.log` (see LogStream for the writer
|
|
153
|
+
* key), one line for EVERY guards-hook
|
|
154
|
+
* call (allow or block, bash or file), unlike `L2-decisions/` which records only the calls a
|
|
155
|
+
* rule actually judged. It captures the tool, the command/file, the live git branch, the async-written
|
|
156
|
+
* main-sync-status.json snapshot (branch / merged / fork-point / conflict), and — since this class
|
|
157
|
+
* replaced a bare log-and-forget function — HOW THE CALL ENDED.
|
|
158
|
+
*
|
|
159
|
+
* WHY IT IS TWO CALLS. The line used to be written the moment the hook started, so it could not carry
|
|
160
|
+
* a verdict: the decision had not been made yet. Answering "what happened to this call?" therefore
|
|
161
|
+
* meant joining this file against the L2 decision stream BY TIMESTAMP, which is exactly the kind of
|
|
162
|
+
* reconstruction a log exists to make unnecessary. So {@link begin} now only CAPTURES (including the
|
|
163
|
+
* git/cache reads, which must still happen while the hook is running), and {@link finish} — called
|
|
164
|
+
* from the hook's single terminal boundary, emitAllow/emitDeny — writes the whole line once the
|
|
165
|
+
* outcome is known. The two streams stay distinct in purpose: this one is "every call and how it
|
|
166
|
+
* ended", the decision log remains "every judgement and why".
|
|
167
|
+
*
|
|
168
|
+
* Every error is swallowed: logging must never block or fail a hook.
|
|
169
|
+
*/
|
|
170
|
+
export declare class InvocationLog {
|
|
171
|
+
private pending;
|
|
172
|
+
/**
|
|
173
|
+
* Capture the context of one invocation. `cwd` is the AI's working dir; the repo root that owns
|
|
174
|
+
* `.webpieces` is resolved from it. Writes NOTHING — {@link finish} does that.
|
|
175
|
+
*/
|
|
176
|
+
begin(cwd: string, tool: string, target: string): void;
|
|
177
|
+
/**
|
|
178
|
+
* Write the captured line, now stamped with the outcome. A no-op when nothing was captured (the
|
|
179
|
+
* 'rules' hook, or a terminal boundary reached before begin()), and it clears the pending entry so
|
|
180
|
+
* a second emit cannot double-log.
|
|
181
|
+
*
|
|
182
|
+
* `rule` is the rule that blocked, or '-' when there is none; `fault` is the L0 fault code when this
|
|
183
|
+
* call ended on one (S/C/Y — the JS-side faults), else '-'. FIELD ORDER IS APPEND-ONLY: the five
|
|
184
|
+
* original fields keep their positions (cleanup automation mines this file), and `guards=` /
|
|
185
|
+
* `rule=` / … / `fault=` are added at the end.
|
|
186
|
+
*/
|
|
187
|
+
finish(verdict: Verdict, rule: string, fault?: string): void;
|
|
188
|
+
}
|
|
189
|
+
export declare const invocationLog: InvocationLog;
|
|
190
|
+
export declare function branchForLog(root: string): string;
|