@webpieces/agent-workflow-rules 0.0.0-stage → 0.4.846
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,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuardHintCommands = void 0;
|
|
4
|
+
exports.loadRules = loadRules;
|
|
5
|
+
exports.loadKeylessBashRules = loadKeylessBashRules;
|
|
6
|
+
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
7
|
+
const branch_creation_guard_1 = require("./rules/branch-creation-guard");
|
|
8
|
+
const pr_creation_or_push_guard_1 = require("./rules/pr-creation-or-push-guard");
|
|
9
|
+
const merge_in_progress_guard_1 = require("./rules/merge-in-progress-guard");
|
|
10
|
+
const build_output_pipe_guard_1 = require("./rules/build-output-pipe-guard");
|
|
11
|
+
const wait_spin_guard_1 = require("./rules/wait-spin-guard");
|
|
12
|
+
const pr_merge_guard_1 = require("./rules/pr-merge-guard");
|
|
13
|
+
const redirect_how_to_merge_main_1 = require("./rules/redirect-how-to-merge-main");
|
|
14
|
+
const feature_branch_guard_1 = require("./rules/feature-branch-guard");
|
|
15
|
+
const read_stale_guard_1 = require("./rules/read-stale-guard");
|
|
16
|
+
const merged_branch_bash_guard_1 = require("./rules/merged-branch-bash-guard");
|
|
17
|
+
const stale_main_bash_guard_1 = require("./rules/stale-main-bash-guard");
|
|
18
|
+
const whole_repo_build_guard_1 = require("./rules/whole-repo-build-guard");
|
|
19
|
+
const commit_message_substitution_guard_1 = require("./rules/commit-message-substitution-guard");
|
|
20
|
+
class GuardHintCommands {
|
|
21
|
+
upsertPr;
|
|
22
|
+
mergeComplete;
|
|
23
|
+
constructor(upsertPr, mergeComplete) {
|
|
24
|
+
this.upsertPr = upsertPr;
|
|
25
|
+
this.mergeComplete = mergeComplete;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.GuardHintCommands = GuardHintCommands;
|
|
29
|
+
const BUILT_IN_RULE_MAP = {
|
|
30
|
+
'branch-creation-guard': (c) => [new branch_creation_guard_1.BranchCreationGuardRule(c)],
|
|
31
|
+
// THE TWO COLLAPSED POLICIES. Order inside each array is the order the rules run in, and it is the
|
|
32
|
+
// same order the previous per-key registry produced.
|
|
33
|
+
'pr-lifecycle-guard': (c, hints) => [
|
|
34
|
+
new pr_creation_or_push_guard_1.PrCreationOrPushGuardRule(c, hints.upsertPr),
|
|
35
|
+
new merge_in_progress_guard_1.MergeInProgressGuardRule(c, hints.mergeComplete),
|
|
36
|
+
new pr_merge_guard_1.PrMergeGuardRule(c),
|
|
37
|
+
new redirect_how_to_merge_main_1.RedirectHowToMergeMainRule(c),
|
|
38
|
+
],
|
|
39
|
+
'branch-state-guard': (c) => [
|
|
40
|
+
new feature_branch_guard_1.FeatureBranchGuardRule(c),
|
|
41
|
+
new read_stale_guard_1.ReadStaleGuardRule(c),
|
|
42
|
+
new merged_branch_bash_guard_1.MergedBranchBashGuardRule(c),
|
|
43
|
+
new stale_main_bash_guard_1.StaleMainBashGuardRule(c),
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
// webpieces-disable no-function-outside-class -- the existing stateless guard registry entry point
|
|
47
|
+
function loadRules(config, workspaceRoot, guardHints) {
|
|
48
|
+
void workspaceRoot;
|
|
49
|
+
// webpieces-disable no-any-unknown -- index validated configuration by the registry's declared keys
|
|
50
|
+
const map = config;
|
|
51
|
+
const rules = [];
|
|
52
|
+
for (const key of Object.keys(BUILT_IN_RULE_MAP))
|
|
53
|
+
rules.push(...BUILT_IN_RULE_MAP[key](map[key] ?? new hook_runtime_1.EmptyRuleConfig(), guardHints));
|
|
54
|
+
return rules;
|
|
55
|
+
}
|
|
56
|
+
// webpieces-disable no-function-outside-class -- existing keyless guard factory moved intact
|
|
57
|
+
function loadKeylessBashRules(affectedBuildCommand) {
|
|
58
|
+
return [
|
|
59
|
+
new whole_repo_build_guard_1.WholeRepoBuildGuardRule(affectedBuildCommand),
|
|
60
|
+
new commit_message_substitution_guard_1.CommitMessageSubstitutionGuardRule(),
|
|
61
|
+
new build_output_pipe_guard_1.BuildOutputPipeGuardRule(),
|
|
62
|
+
new wait_spin_guard_1.WaitSpinGuardRule(),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=load-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-rules.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/load-rules.ts"],"names":[],"mappings":";;;AA+CA,8BAOC;AAGD,oDAOC;AA5DD,0DAAgE;AAChE,yEAAwE;AACxE,iFAA8E;AAC9E,6EAA2E;AAC3E,6EAA2E;AAC3E,6DAA4D;AAC5D,2DAA0D;AAC1D,mFAAgF;AAChF,uEAAsE;AACtE,+DAA8D;AAC9D,+EAA6E;AAC7E,yEAAuE;AACvE,2EAAyE;AACzE,iGAA+F;AAE/F,MAAa,iBAAiB;IACL;IAA2B;IAAhD,YAAqB,QAAgB,EAAW,aAAqB;QAAhD,aAAQ,GAAR,QAAQ,CAAQ;QAAW,kBAAa,GAAb,aAAa,CAAQ;IAAG,CAAC;CAC5E;AAFD,8CAEC;AAOD,MAAM,iBAAiB,GAAgC;IACnD,uBAAuB,EAAE,CAAC,CAAiB,EAAE,EAAE,CAAC,CAAC,IAAI,+CAAuB,CAAC,CAA8B,CAAC,CAAC;IAC7G,mGAAmG;IACnG,qDAAqD;IACrD,oBAAoB,EAAE,CAAC,CAAiB,EAAE,KAAwB,EAAE,EAAE,CAAC;QACnE,IAAI,qDAAyB,CAAC,CAA2B,EAAE,KAAK,CAAC,QAAQ,CAAC;QAC1E,IAAI,kDAAwB,CAAC,CAA2B,EAAE,KAAK,CAAC,aAAa,CAAC;QAC9E,IAAI,iCAAgB,CAAC,CAA2B,CAAC;QACjD,IAAI,uDAA0B,CAAC,CAA2B,CAAC;KAC9D;IACD,oBAAoB,EAAE,CAAC,CAAiB,EAAE,EAAE,CAAC;QACzC,IAAI,6CAAsB,CAAC,CAA2B,CAAC;QACvD,IAAI,qCAAkB,CAAC,CAA2B,CAAC;QACnD,IAAI,oDAAyB,CAAC,CAA2B,CAAC;QAC1D,IAAI,8CAAsB,CAAC,CAA2B,CAAC;KAC1D;CACJ,CAAC;AAEF,mGAAmG;AACnG,SAAgB,SAAS,CAAC,MAA4B,EAAE,aAAqB,EAAE,UAA6B;IACxG,KAAK,aAAa,CAAC;IACnB,oGAAoG;IACpG,MAAM,GAAG,GAAG,MAA+D,CAAC;IAC5E,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,8BAAe,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;IACvI,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,6FAA6F;AAC7F,SAAgB,oBAAoB,CAAC,oBAA4B;IAC7D,OAAO;QACH,IAAI,gDAAuB,CAAC,oBAAoB,CAAC;QACjD,IAAI,sEAAkC,EAAE;QACxC,IAAI,kDAAwB,EAAE;QAC9B,IAAI,mCAAiB,EAAE;KAC1B,CAAC;AACN,CAAC","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-sdk';\nimport { WebpiecesRulesConfig } from \"@webpieces/rules-config\";\nimport { BranchCreationGuardConfig, PrLifecycleGuardConfig } from \"../configs/rule-configs\";\nimport { BranchStateGuardConfig } from \"../configs/main-sync-guard-configs\";\nimport { Rule, EmptyRuleConfig } from '@webpieces/hook-runtime';\nimport { BranchCreationGuardRule } from './rules/branch-creation-guard';\nimport { PrCreationOrPushGuardRule } from './rules/pr-creation-or-push-guard';\nimport { MergeInProgressGuardRule } from './rules/merge-in-progress-guard';\nimport { BuildOutputPipeGuardRule } from './rules/build-output-pipe-guard';\nimport { WaitSpinGuardRule } from './rules/wait-spin-guard';\nimport { PrMergeGuardRule } from './rules/pr-merge-guard';\nimport { RedirectHowToMergeMainRule } from './rules/redirect-how-to-merge-main';\nimport { FeatureBranchGuardRule } from './rules/feature-branch-guard';\nimport { ReadStaleGuardRule } from './rules/read-stale-guard';\nimport { MergedBranchBashGuardRule } from './rules/merged-branch-bash-guard';\nimport { StaleMainBashGuardRule } from './rules/stale-main-bash-guard';\nimport { WholeRepoBuildGuardRule } from './rules/whole-repo-build-guard';\nimport { CommitMessageSubstitutionGuardRule } from './rules/commit-message-substitution-guard';\n\nexport class GuardHintCommands {\n constructor(readonly upsertPr: string, readonly mergeComplete: string) {}\n}\n\n/**\n * Each workflow policy key can produce several guards. GuardHintCommands carries the resolved\n * commands.guardHints strings to the guards that print gated commands, separately from BaseRuleConfig.\n */\ntype RuleFactory = (config: BaseRuleConfig, guardHints: GuardHintCommands) => readonly Rule[];\nconst BUILT_IN_RULE_MAP: Record<string, RuleFactory> = {\n 'branch-creation-guard': (c: BaseRuleConfig) => [new BranchCreationGuardRule(c as BranchCreationGuardConfig)],\n // THE TWO COLLAPSED POLICIES. Order inside each array is the order the rules run in, and it is the\n // same order the previous per-key registry produced.\n 'pr-lifecycle-guard': (c: BaseRuleConfig, hints: GuardHintCommands) => [\n new PrCreationOrPushGuardRule(c as PrLifecycleGuardConfig, hints.upsertPr),\n new MergeInProgressGuardRule(c as PrLifecycleGuardConfig, hints.mergeComplete),\n new PrMergeGuardRule(c as PrLifecycleGuardConfig),\n new RedirectHowToMergeMainRule(c as PrLifecycleGuardConfig),\n ],\n 'branch-state-guard': (c: BaseRuleConfig) => [\n new FeatureBranchGuardRule(c as BranchStateGuardConfig),\n new ReadStaleGuardRule(c as BranchStateGuardConfig),\n new MergedBranchBashGuardRule(c as BranchStateGuardConfig),\n new StaleMainBashGuardRule(c as BranchStateGuardConfig),\n ],\n};\n\n// webpieces-disable no-function-outside-class -- the existing stateless guard registry entry point\nexport function loadRules(config: WebpiecesRulesConfig, workspaceRoot: string, guardHints: GuardHintCommands): readonly Rule[] {\n void workspaceRoot;\n // webpieces-disable no-any-unknown -- index validated configuration by the registry's declared keys\n const map = config as unknown as Record<string, BaseRuleConfig | undefined>;\n const rules: Rule[] = [];\n for (const key of Object.keys(BUILT_IN_RULE_MAP)) rules.push(...BUILT_IN_RULE_MAP[key](map[key] ?? new EmptyRuleConfig(), guardHints));\n return rules;\n}\n\n// webpieces-disable no-function-outside-class -- existing keyless guard factory moved intact\nexport function loadKeylessBashRules(affectedBuildCommand: string): Rule[] {\n return [\n new WholeRepoBuildGuardRule(affectedBuildCommand),\n new CommitMessageSubstitutionGuardRule(),\n new BuildOutputPipeGuardRule(),\n new WaitSpinGuardRule(),\n ];\n}\n"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHO is writing — the three fields that make a log filename unique, carried as one value.
|
|
3
|
+
*
|
|
4
|
+
* Data-only (per CLAUDE.md: classes for data, explicit construction). It exists as a class rather
|
|
5
|
+
* than three loose parameters because the identity has to CROSS A PROCESS BOUNDARY: the detached
|
|
6
|
+
* main-sync refresher is a separate node process, and the spawner hands it these three fields on
|
|
7
|
+
* argv so parent and child write ONE stream. A single named carrier is what makes "read it back out
|
|
8
|
+
* of the parent, put it on argv, set it in the child" a three-line round trip instead of three
|
|
9
|
+
* parallel string parameters that can be reordered at either end.
|
|
10
|
+
*/
|
|
11
|
+
export declare class StreamIdentity {
|
|
12
|
+
readonly sessionId: string;
|
|
13
|
+
readonly agentId: string;
|
|
14
|
+
readonly hook: string;
|
|
15
|
+
constructor(sessionId: string, agentId: string, hook: string);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* WHICH LOG FILE does this hook invocation append to?
|
|
19
|
+
*
|
|
20
|
+
* ─── The bug this exists to fix ────────────────────────────────────────────────────────────────────
|
|
21
|
+
* Log paths used to be keyed by the git WORKTREE alone (`<local>/logs/…`). Three separate things share
|
|
22
|
+
* a worktree, so three separate things shared one file:
|
|
23
|
+
*
|
|
24
|
+
* 1. **Parallel hooks.** The hooks reference says "when multiple PreToolUse hooks match a tool call,
|
|
25
|
+
* ALL matching hooks run in parallel". `wp-ai-rules-hook` and `wp-ai-guards-hook` both match
|
|
26
|
+
* Write/Edit/MultiEdit, so on every file edit TWO PROCESSES append to the same file at the same
|
|
27
|
+
* time. (A retired third hook, L-1's `guarantee-root.sh`, once made it three.)
|
|
28
|
+
* 2. **Subagents.** A subagent without worktree isolation shares the coordinator's tree.
|
|
29
|
+
* 3. **Whole sessions.** Four Claude Code windows on one clone are four coordinators, and `agent_id`
|
|
30
|
+
* is absent for every one of them — so agent identity alone cannot tell them apart.
|
|
31
|
+
*
|
|
32
|
+
* `O_APPEND` is indivisible only under `PIPE_BUF`, which is **512 bytes on macOS**. Measured
|
|
33
|
+
* 2026-08-06 across three repos: the invocation stream 208/3306 lines (6.3%) exceed it, max 608 B;
|
|
34
|
+
* the decision stream 209/4097 (5.1%), max 625 B. So this tears TODAY, and the corrupted line
|
|
35
|
+
* is exactly the long one — the `recover=` line a human needs most.
|
|
36
|
+
*
|
|
37
|
+
* ─── The key: the LAYER is the directory, the WRITER is the file ──────────────────────────────────
|
|
38
|
+
* <local>/logs/<stream>/<sessionId>-<agentId | "coordinator">-<hook>.log
|
|
39
|
+
*
|
|
40
|
+
* stream separates the LAYERS ('L0-shim' | 'L1-location' | 'L2-decisions' | …)
|
|
41
|
+
* sessionId separates concurrent Claude Code windows (`session_id`, on every hook payload)
|
|
42
|
+
* agentId separates subagents within one window (`agent_id`, subagent-only — absent = coordinator)
|
|
43
|
+
* hook separates the PARALLEL hooks ('guards' | 'rules')
|
|
44
|
+
*
|
|
45
|
+
* This class owns the FILE half. One writer per file, by construction, so appends cannot interleave
|
|
46
|
+
* and nothing needs a lock — and all three identity dimensions must stay in the filename for that to
|
|
47
|
+
* hold. `hook` especially: Claude Code runs the guards and rules hooks as separate processes IN
|
|
48
|
+
* PARALLEL on one tool call, so folding `hook` into the directory would put two concurrent appenders
|
|
49
|
+
* on one path, which is the tearing measured above.
|
|
50
|
+
*
|
|
51
|
+
* Nesting by STREAM is NOT the nesting this layout rejects. What it rejects is nesting by IDENTITY
|
|
52
|
+
* (`sessions/<id>/<agent>/…`), which turns every cross-session question into a directory walk. The
|
|
53
|
+
* layer is the one axis you almost always want to slice by first, and it was previously not
|
|
54
|
+
* expressible at all: L1 had no stream, so "show me every L1 decision" had no answer. Now
|
|
55
|
+
* `ls logs/L1-location/` is that answer, and a one-level wildcard recovers the flat view —
|
|
56
|
+
* `ls -t logs/[*]/<sid>-*` is still every layer at once, in time order.
|
|
57
|
+
*
|
|
58
|
+
* `transcript_path` is also unique per session, but it is a filesystem PATH — long, and full of
|
|
59
|
+
* separators that would have to be flattened anyway — and `session_id` is its stable identifier, so
|
|
60
|
+
* session_id is the better key.
|
|
61
|
+
*
|
|
62
|
+
* The tree is still visible — every line already carries `root=` / `projectDir=` / `tree=` columns —
|
|
63
|
+
* so nothing is lost by the filename not encoding it.
|
|
64
|
+
*
|
|
65
|
+
* ─── There is no un-split path ─────────────────────────────────────────────────────────────────────
|
|
66
|
+
* Every name is prefixed, always. A caller that never identifies renders as
|
|
67
|
+
* `unknown-coordinator-hook.log` — a distinct, greppable writer, NOT a shared file. Keeping a
|
|
68
|
+
* bare-name fallback would have meant two reachable spellings of one filename, with the tearing one
|
|
69
|
+
* reached by doing nothing; that is the widening-as-absence this whole class exists to remove, so it
|
|
70
|
+
* is not offered.
|
|
71
|
+
*/
|
|
72
|
+
export declare class LogStream {
|
|
73
|
+
private sessionId;
|
|
74
|
+
private agentId;
|
|
75
|
+
private hook;
|
|
76
|
+
/**
|
|
77
|
+
* Called once per invocation by the adapter that parsed the payload. `agentId` is empty for the
|
|
78
|
+
* coordinator — that absence IS the signal — and renders as `coordinator`. Naming the writer file is
|
|
79
|
+
* the ONLY thing this identity is used for; which tree a call acts on is measured from the path (see
|
|
80
|
+
* core/version-sync.ts), never from who is asking.
|
|
81
|
+
* An empty `sessionId` renders as `unknown`: visible, never merged into another stream.
|
|
82
|
+
*/
|
|
83
|
+
identify(identity: StreamIdentity): void;
|
|
84
|
+
/**
|
|
85
|
+
* This process's identity, readable so it can be HANDED TO A CHILD PROCESS.
|
|
86
|
+
*
|
|
87
|
+
* The detached main-sync refresher (main-sync-refresh.ts → sync-main.ts) is a separate node
|
|
88
|
+
* process with a fresh, unidentified `logStream`. Before this existed the parent logged
|
|
89
|
+
* SPAWN_ATTEMPT to its own prefixed stream while the child logged START/FINISH/ERROR to the
|
|
90
|
+
* shared, unidentified `unknown-coordinator-hook` writer — so ONE refresh cycle was split across
|
|
91
|
+
* two files, every agent's child appended to that one shared file (the PIPE_BUF tearing this
|
|
92
|
+
* class exists to remove, still live on that stream), and the documented
|
|
93
|
+
* "SPAWN_ATTEMPT with no START means the child never launched" check read as a false failure on
|
|
94
|
+
* every single cycle. The spawner now reads this and puts it on the child's argv.
|
|
95
|
+
*/
|
|
96
|
+
identity(): StreamIdentity;
|
|
97
|
+
/**
|
|
98
|
+
* This WRITER's file name within a stream directory —
|
|
99
|
+
* `<sessionId>-<agentId|coordinator>-<hook><suffix>`, ALWAYS.
|
|
100
|
+
*
|
|
101
|
+
* The three identity dimensions stay in the FILE while the stream moves to the DIRECTORY
|
|
102
|
+
* (see log-streams.ts), because they are what makes one writer per file true and the stream is not:
|
|
103
|
+
* `wp-ai-guards-hook` and `wp-ai-rules-hook` are separate processes that Claude Code launches in
|
|
104
|
+
* PARALLEL on the same tool call, so dropping `hook` here would put two concurrent appenders on
|
|
105
|
+
* one path — the exact tearing this class exists to remove, reintroduced by a rename.
|
|
106
|
+
*
|
|
107
|
+
* `suffix` carries the extension so the rotation sibling gets the identical writer key: pass
|
|
108
|
+
* `.log`, and separately `.1.log`.
|
|
109
|
+
*/
|
|
110
|
+
writerFile(suffix: string): string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Process-wide instance. The hook adapters identify it once at the top of the invocation and every
|
|
114
|
+
* writer downstream reads it, which is what keeps `logGuardDecision()` / `logRejection()` signatures
|
|
115
|
+
* unchanged — the alternative was threading three more parameters through every call site.
|
|
116
|
+
*/
|
|
117
|
+
export declare const logStream: LogStream;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logStream = exports.LogStream = exports.StreamIdentity = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* WHO is writing — the three fields that make a log filename unique, carried as one value.
|
|
6
|
+
*
|
|
7
|
+
* Data-only (per CLAUDE.md: classes for data, explicit construction). It exists as a class rather
|
|
8
|
+
* than three loose parameters because the identity has to CROSS A PROCESS BOUNDARY: the detached
|
|
9
|
+
* main-sync refresher is a separate node process, and the spawner hands it these three fields on
|
|
10
|
+
* argv so parent and child write ONE stream. A single named carrier is what makes "read it back out
|
|
11
|
+
* of the parent, put it on argv, set it in the child" a three-line round trip instead of three
|
|
12
|
+
* parallel string parameters that can be reordered at either end.
|
|
13
|
+
*/
|
|
14
|
+
class StreamIdentity {
|
|
15
|
+
sessionId;
|
|
16
|
+
agentId;
|
|
17
|
+
hook;
|
|
18
|
+
constructor(sessionId, agentId, hook) {
|
|
19
|
+
this.sessionId = sessionId;
|
|
20
|
+
this.agentId = agentId;
|
|
21
|
+
this.hook = hook;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.StreamIdentity = StreamIdentity;
|
|
25
|
+
/**
|
|
26
|
+
* WHICH LOG FILE does this hook invocation append to?
|
|
27
|
+
*
|
|
28
|
+
* ─── The bug this exists to fix ────────────────────────────────────────────────────────────────────
|
|
29
|
+
* Log paths used to be keyed by the git WORKTREE alone (`<local>/logs/…`). Three separate things share
|
|
30
|
+
* a worktree, so three separate things shared one file:
|
|
31
|
+
*
|
|
32
|
+
* 1. **Parallel hooks.** The hooks reference says "when multiple PreToolUse hooks match a tool call,
|
|
33
|
+
* ALL matching hooks run in parallel". `wp-ai-rules-hook` and `wp-ai-guards-hook` both match
|
|
34
|
+
* Write/Edit/MultiEdit, so on every file edit TWO PROCESSES append to the same file at the same
|
|
35
|
+
* time. (A retired third hook, L-1's `guarantee-root.sh`, once made it three.)
|
|
36
|
+
* 2. **Subagents.** A subagent without worktree isolation shares the coordinator's tree.
|
|
37
|
+
* 3. **Whole sessions.** Four Claude Code windows on one clone are four coordinators, and `agent_id`
|
|
38
|
+
* is absent for every one of them — so agent identity alone cannot tell them apart.
|
|
39
|
+
*
|
|
40
|
+
* `O_APPEND` is indivisible only under `PIPE_BUF`, which is **512 bytes on macOS**. Measured
|
|
41
|
+
* 2026-08-06 across three repos: the invocation stream 208/3306 lines (6.3%) exceed it, max 608 B;
|
|
42
|
+
* the decision stream 209/4097 (5.1%), max 625 B. So this tears TODAY, and the corrupted line
|
|
43
|
+
* is exactly the long one — the `recover=` line a human needs most.
|
|
44
|
+
*
|
|
45
|
+
* ─── The key: the LAYER is the directory, the WRITER is the file ──────────────────────────────────
|
|
46
|
+
* <local>/logs/<stream>/<sessionId>-<agentId | "coordinator">-<hook>.log
|
|
47
|
+
*
|
|
48
|
+
* stream separates the LAYERS ('L0-shim' | 'L1-location' | 'L2-decisions' | …)
|
|
49
|
+
* sessionId separates concurrent Claude Code windows (`session_id`, on every hook payload)
|
|
50
|
+
* agentId separates subagents within one window (`agent_id`, subagent-only — absent = coordinator)
|
|
51
|
+
* hook separates the PARALLEL hooks ('guards' | 'rules')
|
|
52
|
+
*
|
|
53
|
+
* This class owns the FILE half. One writer per file, by construction, so appends cannot interleave
|
|
54
|
+
* and nothing needs a lock — and all three identity dimensions must stay in the filename for that to
|
|
55
|
+
* hold. `hook` especially: Claude Code runs the guards and rules hooks as separate processes IN
|
|
56
|
+
* PARALLEL on one tool call, so folding `hook` into the directory would put two concurrent appenders
|
|
57
|
+
* on one path, which is the tearing measured above.
|
|
58
|
+
*
|
|
59
|
+
* Nesting by STREAM is NOT the nesting this layout rejects. What it rejects is nesting by IDENTITY
|
|
60
|
+
* (`sessions/<id>/<agent>/…`), which turns every cross-session question into a directory walk. The
|
|
61
|
+
* layer is the one axis you almost always want to slice by first, and it was previously not
|
|
62
|
+
* expressible at all: L1 had no stream, so "show me every L1 decision" had no answer. Now
|
|
63
|
+
* `ls logs/L1-location/` is that answer, and a one-level wildcard recovers the flat view —
|
|
64
|
+
* `ls -t logs/[*]/<sid>-*` is still every layer at once, in time order.
|
|
65
|
+
*
|
|
66
|
+
* `transcript_path` is also unique per session, but it is a filesystem PATH — long, and full of
|
|
67
|
+
* separators that would have to be flattened anyway — and `session_id` is its stable identifier, so
|
|
68
|
+
* session_id is the better key.
|
|
69
|
+
*
|
|
70
|
+
* The tree is still visible — every line already carries `root=` / `projectDir=` / `tree=` columns —
|
|
71
|
+
* so nothing is lost by the filename not encoding it.
|
|
72
|
+
*
|
|
73
|
+
* ─── There is no un-split path ─────────────────────────────────────────────────────────────────────
|
|
74
|
+
* Every name is prefixed, always. A caller that never identifies renders as
|
|
75
|
+
* `unknown-coordinator-hook.log` — a distinct, greppable writer, NOT a shared file. Keeping a
|
|
76
|
+
* bare-name fallback would have meant two reachable spellings of one filename, with the tearing one
|
|
77
|
+
* reached by doing nothing; that is the widening-as-absence this whole class exists to remove, so it
|
|
78
|
+
* is not offered.
|
|
79
|
+
*/
|
|
80
|
+
class LogStream {
|
|
81
|
+
// ALWAYS a real identity. There is no "unset" state and no bare-name branch, so there is exactly
|
|
82
|
+
// ONE spelling of a log filename and a writer cannot reach the shared, tearing stream by doing
|
|
83
|
+
// nothing. A caller with no Claude Code payload (the openclaw adapter, library consumers, specs)
|
|
84
|
+
// gets UNIDENTIFIED below — which still prefixes, with `unknown`, so it is a distinct greppable
|
|
85
|
+
// stream rather than a merge point.
|
|
86
|
+
sessionId = 'unknown';
|
|
87
|
+
agentId = '';
|
|
88
|
+
hook = 'hook';
|
|
89
|
+
/**
|
|
90
|
+
* Called once per invocation by the adapter that parsed the payload. `agentId` is empty for the
|
|
91
|
+
* coordinator — that absence IS the signal — and renders as `coordinator`. Naming the writer file is
|
|
92
|
+
* the ONLY thing this identity is used for; which tree a call acts on is measured from the path (see
|
|
93
|
+
* core/version-sync.ts), never from who is asking.
|
|
94
|
+
* An empty `sessionId` renders as `unknown`: visible, never merged into another stream.
|
|
95
|
+
*/
|
|
96
|
+
identify(identity) {
|
|
97
|
+
this.sessionId = identity.sessionId;
|
|
98
|
+
this.agentId = identity.agentId;
|
|
99
|
+
this.hook = identity.hook;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* This process's identity, readable so it can be HANDED TO A CHILD PROCESS.
|
|
103
|
+
*
|
|
104
|
+
* The detached main-sync refresher (main-sync-refresh.ts → sync-main.ts) is a separate node
|
|
105
|
+
* process with a fresh, unidentified `logStream`. Before this existed the parent logged
|
|
106
|
+
* SPAWN_ATTEMPT to its own prefixed stream while the child logged START/FINISH/ERROR to the
|
|
107
|
+
* shared, unidentified `unknown-coordinator-hook` writer — so ONE refresh cycle was split across
|
|
108
|
+
* two files, every agent's child appended to that one shared file (the PIPE_BUF tearing this
|
|
109
|
+
* class exists to remove, still live on that stream), and the documented
|
|
110
|
+
* "SPAWN_ATTEMPT with no START means the child never launched" check read as a false failure on
|
|
111
|
+
* every single cycle. The spawner now reads this and puts it on the child's argv.
|
|
112
|
+
*/
|
|
113
|
+
identity() {
|
|
114
|
+
return new StreamIdentity(this.sessionId, this.agentId, this.hook);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* This WRITER's file name within a stream directory —
|
|
118
|
+
* `<sessionId>-<agentId|coordinator>-<hook><suffix>`, ALWAYS.
|
|
119
|
+
*
|
|
120
|
+
* The three identity dimensions stay in the FILE while the stream moves to the DIRECTORY
|
|
121
|
+
* (see log-streams.ts), because they are what makes one writer per file true and the stream is not:
|
|
122
|
+
* `wp-ai-guards-hook` and `wp-ai-rules-hook` are separate processes that Claude Code launches in
|
|
123
|
+
* PARALLEL on the same tool call, so dropping `hook` here would put two concurrent appenders on
|
|
124
|
+
* one path — the exact tearing this class exists to remove, reintroduced by a rename.
|
|
125
|
+
*
|
|
126
|
+
* `suffix` carries the extension so the rotation sibling gets the identical writer key: pass
|
|
127
|
+
* `.log`, and separately `.1.log`.
|
|
128
|
+
*/
|
|
129
|
+
writerFile(suffix) {
|
|
130
|
+
const agent = segment(this.agentId === '' ? 'coordinator' : this.agentId);
|
|
131
|
+
return `${segment(this.sessionId)}-${agent}-${segment(this.hook)}${suffix}`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.LogStream = LogStream;
|
|
135
|
+
/**
|
|
136
|
+
* One path segment, sanitised. `session_id` and `agent_id` arrive from a JSON payload, so they are
|
|
137
|
+
* UNTRUSTED INPUT being used to build a filesystem path: `../../../etc` must become a harmless name and
|
|
138
|
+
* never escape the logs directory. Everything outside `[A-Za-z0-9._-]` collapses to `_`, a leading dot
|
|
139
|
+
* is neutralised so nothing becomes a hidden file or `..`, and the result is capped and never empty.
|
|
140
|
+
*/
|
|
141
|
+
// webpieces-disable no-function-outside-class -- pure string sanitiser, the module's own leaf helper beside the class it serves
|
|
142
|
+
function segment(raw) {
|
|
143
|
+
const cleaned = raw
|
|
144
|
+
.replace(/[^A-Za-z0-9._-]/g, '_') // kills every separator, so nothing can traverse
|
|
145
|
+
.replace(/\.{2,}/g, '_') // and no run of dots survives, so no segment reads as `..`
|
|
146
|
+
.replace(/^\.+/, '_') // nor becomes a hidden file
|
|
147
|
+
.slice(0, 64);
|
|
148
|
+
return cleaned === '' ? 'unknown' : cleaned;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Process-wide instance. The hook adapters identify it once at the top of the invocation and every
|
|
152
|
+
* writer downstream reads it, which is what keeps `logGuardDecision()` / `logRejection()` signatures
|
|
153
|
+
* unchanged — the alternative was threading three more parameters through every call site.
|
|
154
|
+
*/
|
|
155
|
+
exports.logStream = new LogStream();
|
|
156
|
+
//# sourceMappingURL=log-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-stream.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/log-stream.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,MAAa,cAAc;IACd,SAAS,CAAS;IAClB,OAAO,CAAS;IAChB,IAAI,CAAS;IAEtB,YAAY,SAAiB,EAAE,OAAe,EAAE,IAAY;QACxD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAVD,wCAUC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAa,SAAS;IAClB,iGAAiG;IACjG,+FAA+F;IAC/F,iGAAiG;IACjG,gGAAgG;IAChG,oCAAoC;IAC5B,SAAS,GAAG,SAAS,CAAC;IACtB,OAAO,GAAG,EAAE,CAAC;IACb,IAAI,GAAG,MAAM,CAAC;IAEtB;;;;;;OAMG;IACH,QAAQ,CAAC,QAAwB;QAC7B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;OAWG;IACH,QAAQ;QACJ,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACvE,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,MAAc;QACrB,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1E,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC;IAChF,CAAC;CACJ;AAxDD,8BAwDC;AAED;;;;;GAKG;AACH,gIAAgI;AAChI,SAAS,OAAO,CAAC,GAAW;IACxB,MAAM,OAAO,GAAG,GAAG;SACd,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAG,iDAAiD;SACpF,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAY,2DAA2D;SAC9F,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAe,4BAA4B;SAC/D,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClB,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACU,QAAA,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC","sourcesContent":["/**\n * WHO is writing — the three fields that make a log filename unique, carried as one value.\n *\n * Data-only (per CLAUDE.md: classes for data, explicit construction). It exists as a class rather\n * than three loose parameters because the identity has to CROSS A PROCESS BOUNDARY: the detached\n * main-sync refresher is a separate node process, and the spawner hands it these three fields on\n * argv so parent and child write ONE stream. A single named carrier is what makes \"read it back out\n * of the parent, put it on argv, set it in the child\" a three-line round trip instead of three\n * parallel string parameters that can be reordered at either end.\n */\nexport class StreamIdentity {\n readonly sessionId: string;\n readonly agentId: string;\n readonly hook: string;\n\n constructor(sessionId: string, agentId: string, hook: string) {\n this.sessionId = sessionId;\n this.agentId = agentId;\n this.hook = hook;\n }\n}\n\n/**\n * WHICH LOG FILE does this hook invocation append to?\n *\n * ─── The bug this exists to fix ────────────────────────────────────────────────────────────────────\n * Log paths used to be keyed by the git WORKTREE alone (`<local>/logs/…`). Three separate things share\n * a worktree, so three separate things shared one file:\n *\n * 1. **Parallel hooks.** The hooks reference says \"when multiple PreToolUse hooks match a tool call,\n * ALL matching hooks run in parallel\". `wp-ai-rules-hook` and `wp-ai-guards-hook` both match\n * Write/Edit/MultiEdit, so on every file edit TWO PROCESSES append to the same file at the same\n * time. (A retired third hook, L-1's `guarantee-root.sh`, once made it three.)\n * 2. **Subagents.** A subagent without worktree isolation shares the coordinator's tree.\n * 3. **Whole sessions.** Four Claude Code windows on one clone are four coordinators, and `agent_id`\n * is absent for every one of them — so agent identity alone cannot tell them apart.\n *\n * `O_APPEND` is indivisible only under `PIPE_BUF`, which is **512 bytes on macOS**. Measured\n * 2026-08-06 across three repos: the invocation stream 208/3306 lines (6.3%) exceed it, max 608 B;\n * the decision stream 209/4097 (5.1%), max 625 B. So this tears TODAY, and the corrupted line\n * is exactly the long one — the `recover=` line a human needs most.\n *\n * ─── The key: the LAYER is the directory, the WRITER is the file ──────────────────────────────────\n * <local>/logs/<stream>/<sessionId>-<agentId | \"coordinator\">-<hook>.log\n *\n * stream separates the LAYERS ('L0-shim' | 'L1-location' | 'L2-decisions' | …)\n * sessionId separates concurrent Claude Code windows (`session_id`, on every hook payload)\n * agentId separates subagents within one window (`agent_id`, subagent-only — absent = coordinator)\n * hook separates the PARALLEL hooks ('guards' | 'rules')\n *\n * This class owns the FILE half. One writer per file, by construction, so appends cannot interleave\n * and nothing needs a lock — and all three identity dimensions must stay in the filename for that to\n * hold. `hook` especially: Claude Code runs the guards and rules hooks as separate processes IN\n * PARALLEL on one tool call, so folding `hook` into the directory would put two concurrent appenders\n * on one path, which is the tearing measured above.\n *\n * Nesting by STREAM is NOT the nesting this layout rejects. What it rejects is nesting by IDENTITY\n * (`sessions/<id>/<agent>/…`), which turns every cross-session question into a directory walk. The\n * layer is the one axis you almost always want to slice by first, and it was previously not\n * expressible at all: L1 had no stream, so \"show me every L1 decision\" had no answer. Now\n * `ls logs/L1-location/` is that answer, and a one-level wildcard recovers the flat view —\n * `ls -t logs/[*]/<sid>-*` is still every layer at once, in time order.\n *\n * `transcript_path` is also unique per session, but it is a filesystem PATH — long, and full of\n * separators that would have to be flattened anyway — and `session_id` is its stable identifier, so\n * session_id is the better key.\n *\n * The tree is still visible — every line already carries `root=` / `projectDir=` / `tree=` columns —\n * so nothing is lost by the filename not encoding it.\n *\n * ─── There is no un-split path ─────────────────────────────────────────────────────────────────────\n * Every name is prefixed, always. A caller that never identifies renders as\n * `unknown-coordinator-hook.log` — a distinct, greppable writer, NOT a shared file. Keeping a\n * bare-name fallback would have meant two reachable spellings of one filename, with the tearing one\n * reached by doing nothing; that is the widening-as-absence this whole class exists to remove, so it\n * is not offered.\n */\nexport class LogStream {\n // ALWAYS a real identity. There is no \"unset\" state and no bare-name branch, so there is exactly\n // ONE spelling of a log filename and a writer cannot reach the shared, tearing stream by doing\n // nothing. A caller with no Claude Code payload (the openclaw adapter, library consumers, specs)\n // gets UNIDENTIFIED below — which still prefixes, with `unknown`, so it is a distinct greppable\n // stream rather than a merge point.\n private sessionId = 'unknown';\n private agentId = '';\n private hook = 'hook';\n\n /**\n * Called once per invocation by the adapter that parsed the payload. `agentId` is empty for the\n * coordinator — that absence IS the signal — and renders as `coordinator`. Naming the writer file is\n * the ONLY thing this identity is used for; which tree a call acts on is measured from the path (see\n * core/version-sync.ts), never from who is asking.\n * An empty `sessionId` renders as `unknown`: visible, never merged into another stream.\n */\n identify(identity: StreamIdentity): void {\n this.sessionId = identity.sessionId;\n this.agentId = identity.agentId;\n this.hook = identity.hook;\n }\n\n /**\n * This process's identity, readable so it can be HANDED TO A CHILD PROCESS.\n *\n * The detached main-sync refresher (main-sync-refresh.ts → sync-main.ts) is a separate node\n * process with a fresh, unidentified `logStream`. Before this existed the parent logged\n * SPAWN_ATTEMPT to its own prefixed stream while the child logged START/FINISH/ERROR to the\n * shared, unidentified `unknown-coordinator-hook` writer — so ONE refresh cycle was split across\n * two files, every agent's child appended to that one shared file (the PIPE_BUF tearing this\n * class exists to remove, still live on that stream), and the documented\n * \"SPAWN_ATTEMPT with no START means the child never launched\" check read as a false failure on\n * every single cycle. The spawner now reads this and puts it on the child's argv.\n */\n identity(): StreamIdentity {\n return new StreamIdentity(this.sessionId, this.agentId, this.hook);\n }\n\n /**\n * This WRITER's file name within a stream directory —\n * `<sessionId>-<agentId|coordinator>-<hook><suffix>`, ALWAYS.\n *\n * The three identity dimensions stay in the FILE while the stream moves to the DIRECTORY\n * (see log-streams.ts), because they are what makes one writer per file true and the stream is not:\n * `wp-ai-guards-hook` and `wp-ai-rules-hook` are separate processes that Claude Code launches in\n * PARALLEL on the same tool call, so dropping `hook` here would put two concurrent appenders on\n * one path — the exact tearing this class exists to remove, reintroduced by a rename.\n *\n * `suffix` carries the extension so the rotation sibling gets the identical writer key: pass\n * `.log`, and separately `.1.log`.\n */\n writerFile(suffix: string): string {\n const agent = segment(this.agentId === '' ? 'coordinator' : this.agentId);\n return `${segment(this.sessionId)}-${agent}-${segment(this.hook)}${suffix}`;\n }\n}\n\n/**\n * One path segment, sanitised. `session_id` and `agent_id` arrive from a JSON payload, so they are\n * UNTRUSTED INPUT being used to build a filesystem path: `../../../etc` must become a harmless name and\n * never escape the logs directory. Everything outside `[A-Za-z0-9._-]` collapses to `_`, a leading dot\n * is neutralised so nothing becomes a hidden file or `..`, and the result is capped and never empty.\n */\n// webpieces-disable no-function-outside-class -- pure string sanitiser, the module's own leaf helper beside the class it serves\nfunction segment(raw: string): string {\n const cleaned = raw\n .replace(/[^A-Za-z0-9._-]/g, '_') // kills every separator, so nothing can traverse\n .replace(/\\.{2,}/g, '_') // and no run of dots survives, so no segment reads as `..`\n .replace(/^\\.+/, '_') // nor becomes a hidden file\n .slice(0, 64);\n return cleaned === '' ? 'unknown' : cleaned;\n}\n\n/**\n * Process-wide instance. The hook adapters identify it once at the top of the invocation and every\n * writer downstream reads it, which is what keeps `logGuardDecision()` / `logRejection()` signatures\n * unchanged — the alternative was threading three more parameters through every call site.\n */\nexport const logStream = new LogStream();\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE STREAM DIRECTORIES — `<state>/logs/<stream>/<sessionId>-<agentId|coordinator>-<hook>.log`.
|
|
3
|
+
*
|
|
4
|
+
* The stream is the DIRECTORY and the writer is the FILE. That split is the whole point: it puts the
|
|
5
|
+
* LAYER in the path, so "show me every L1 decision this session" is one glob
|
|
6
|
+
* (`logs/L1-location/<sid>-*`) instead of a question no glob could answer — every layer used to be
|
|
7
|
+
* either a suffix on a flat name or, for L1, nothing at all.
|
|
8
|
+
*
|
|
9
|
+
* These live in agent-workflow-rules beside LogStream, because all FOUR writers are here of this layout and
|
|
10
|
+
* not all of them are TypeScript: the L0 `ai-hook.sh` is POSIX sh
|
|
11
|
+
* rendered from `bin/shim-audit-log.ts`, and it must spell these
|
|
12
|
+
* directories identically or the layers scatter. One constant, four consumers — the same reason
|
|
13
|
+
* LogStream itself lives here.
|
|
14
|
+
*
|
|
15
|
+
* NOT in rules-config, and that is load-bearing rather than tidiness: the `wp-*` bins are SPAWNED as
|
|
16
|
+
* processes with no tsconfig path mapping, so they resolve `@webpieces/rules-config` to the PUBLISHED
|
|
17
|
+
* copy in node_modules — a release behind local source. A stream name defined there would render as
|
|
18
|
+
* `undefined` inside a spawned `wp-upgrade-shim` while the in-process renderer used the real value,
|
|
19
|
+
* and the two shims would differ by exactly the constant. Same-package means same source, always.
|
|
20
|
+
*
|
|
21
|
+
* Nesting by STREAM is not the nesting that was rejected. What `logs/` refused was nesting by
|
|
22
|
+
* IDENTITY (`sessions/<id>/<agent>/…`), which breaks every cross-session question. A one-level
|
|
23
|
+
* wildcard recovers the flat view here — `ls -t logs/[star]/<sid>-*` is still every stream in time
|
|
24
|
+
* order, across every layer at once.
|
|
25
|
+
*/
|
|
26
|
+
export declare const L0_SHIM_STREAM = "L0-shim";
|
|
27
|
+
export declare const L1_LOCATION_STREAM = "L1-location";
|
|
28
|
+
export declare const L2_DECISIONS_STREAM = "L2-decisions";
|
|
29
|
+
export declare const CALLS_STREAM = "calls";
|
|
30
|
+
export declare const ASYNC_REFRESH_STREAM = "async-refresh";
|
|
31
|
+
export declare const REJECTIONS_STREAM = "rejections";
|
|
32
|
+
/**
|
|
33
|
+
* Every stream directory, for the sweeps and specs that must enumerate them rather than name one.
|
|
34
|
+
* A new stream that is not added here is invisible to retention — which is why this is a list and not
|
|
35
|
+
* a doc sentence.
|
|
36
|
+
*/
|
|
37
|
+
export declare const ALL_LOG_STREAMS: readonly string[];
|
|
38
|
+
/**
|
|
39
|
+
* Stream directories an OLDER release wrote and this one never will. Kept beside the live list because a
|
|
40
|
+
* directory that is in neither is invisible to every sweep, so its files would sit on disk forever.
|
|
41
|
+
*
|
|
42
|
+
* `SWEEPABLE_LOG_STREAMS` — live + retired — is what retention and the layout specs must enumerate;
|
|
43
|
+
* `ALL_LOG_STREAMS` stays the answer to "what may be WRITTEN". Keeping the two separate is what stops a
|
|
44
|
+
* retired name from quietly becoming a writable one again.
|
|
45
|
+
*/
|
|
46
|
+
export declare const RETIRED_LOG_STREAMS: readonly string[];
|
|
47
|
+
/** Every directory retention may reap: what this release writes, plus what older ones left behind. */
|
|
48
|
+
export declare const SWEEPABLE_LOG_STREAMS: readonly string[];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SWEEPABLE_LOG_STREAMS = exports.RETIRED_LOG_STREAMS = exports.ALL_LOG_STREAMS = exports.REJECTIONS_STREAM = exports.ASYNC_REFRESH_STREAM = exports.CALLS_STREAM = exports.L2_DECISIONS_STREAM = exports.L1_LOCATION_STREAM = exports.L0_SHIM_STREAM = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* THE STREAM DIRECTORIES — `<state>/logs/<stream>/<sessionId>-<agentId|coordinator>-<hook>.log`.
|
|
6
|
+
*
|
|
7
|
+
* The stream is the DIRECTORY and the writer is the FILE. That split is the whole point: it puts the
|
|
8
|
+
* LAYER in the path, so "show me every L1 decision this session" is one glob
|
|
9
|
+
* (`logs/L1-location/<sid>-*`) instead of a question no glob could answer — every layer used to be
|
|
10
|
+
* either a suffix on a flat name or, for L1, nothing at all.
|
|
11
|
+
*
|
|
12
|
+
* These live in agent-workflow-rules beside LogStream, because all FOUR writers are here of this layout and
|
|
13
|
+
* not all of them are TypeScript: the L0 `ai-hook.sh` is POSIX sh
|
|
14
|
+
* rendered from `bin/shim-audit-log.ts`, and it must spell these
|
|
15
|
+
* directories identically or the layers scatter. One constant, four consumers — the same reason
|
|
16
|
+
* LogStream itself lives here.
|
|
17
|
+
*
|
|
18
|
+
* NOT in rules-config, and that is load-bearing rather than tidiness: the `wp-*` bins are SPAWNED as
|
|
19
|
+
* processes with no tsconfig path mapping, so they resolve `@webpieces/rules-config` to the PUBLISHED
|
|
20
|
+
* copy in node_modules — a release behind local source. A stream name defined there would render as
|
|
21
|
+
* `undefined` inside a spawned `wp-upgrade-shim` while the in-process renderer used the real value,
|
|
22
|
+
* and the two shims would differ by exactly the constant. Same-package means same source, always.
|
|
23
|
+
*
|
|
24
|
+
* Nesting by STREAM is not the nesting that was rejected. What `logs/` refused was nesting by
|
|
25
|
+
* IDENTITY (`sessions/<id>/<agent>/…`), which breaks every cross-session question. A one-level
|
|
26
|
+
* wildcard recovers the flat view here — `ls -t logs/[star]/<sid>-*` is still every stream in time
|
|
27
|
+
* order, across every layer at once.
|
|
28
|
+
*/
|
|
29
|
+
exports.L0_SHIM_STREAM = 'L0-shim';
|
|
30
|
+
exports.L1_LOCATION_STREAM = 'L1-location';
|
|
31
|
+
exports.L2_DECISIONS_STREAM = 'L2-decisions';
|
|
32
|
+
exports.CALLS_STREAM = 'calls';
|
|
33
|
+
exports.ASYNC_REFRESH_STREAM = 'async-refresh';
|
|
34
|
+
exports.REJECTIONS_STREAM = 'rejections';
|
|
35
|
+
/**
|
|
36
|
+
* Every stream directory, for the sweeps and specs that must enumerate them rather than name one.
|
|
37
|
+
* A new stream that is not added here is invisible to retention — which is why this is a list and not
|
|
38
|
+
* a doc sentence.
|
|
39
|
+
*/
|
|
40
|
+
exports.ALL_LOG_STREAMS = [
|
|
41
|
+
exports.L0_SHIM_STREAM, exports.L1_LOCATION_STREAM, exports.L2_DECISIONS_STREAM,
|
|
42
|
+
exports.CALLS_STREAM, exports.ASYNC_REFRESH_STREAM, exports.REJECTIONS_STREAM,
|
|
43
|
+
];
|
|
44
|
+
/**
|
|
45
|
+
* Stream directories an OLDER release wrote and this one never will. Kept beside the live list because a
|
|
46
|
+
* directory that is in neither is invisible to every sweep, so its files would sit on disk forever.
|
|
47
|
+
*
|
|
48
|
+
* `SWEEPABLE_LOG_STREAMS` — live + retired — is what retention and the layout specs must enumerate;
|
|
49
|
+
* `ALL_LOG_STREAMS` stays the answer to "what may be WRITTEN". Keeping the two separate is what stops a
|
|
50
|
+
* retired name from quietly becoming a writable one again.
|
|
51
|
+
*/
|
|
52
|
+
exports.RETIRED_LOG_STREAMS = ['L-1-cd'];
|
|
53
|
+
/** Every directory retention may reap: what this release writes, plus what older ones left behind. */
|
|
54
|
+
exports.SWEEPABLE_LOG_STREAMS = [...exports.ALL_LOG_STREAMS, ...exports.RETIRED_LOG_STREAMS];
|
|
55
|
+
//# sourceMappingURL=log-streams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-streams.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/log-streams.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACU,QAAA,cAAc,GAAG,SAAS,CAAC;AAC3B,QAAA,kBAAkB,GAAG,aAAa,CAAC;AACnC,QAAA,mBAAmB,GAAG,cAAc,CAAC;AACrC,QAAA,YAAY,GAAG,OAAO,CAAC;AACvB,QAAA,oBAAoB,GAAG,eAAe,CAAC;AACvC,QAAA,iBAAiB,GAAG,YAAY,CAAC;AAE9C;;;;GAIG;AACU,QAAA,eAAe,GAAsB;IAC9C,sBAAc,EAAE,0BAAkB,EAAE,2BAAmB;IACvD,oBAAY,EAAE,4BAAoB,EAAE,yBAAiB;CACxD,CAAC;AAEF;;;;;;;GAOG;AACU,QAAA,mBAAmB,GAAsB,CAAC,QAAQ,CAAC,CAAC;AAEjE,sGAAsG;AACzF,QAAA,qBAAqB,GAAsB,CAAC,GAAG,uBAAe,EAAE,GAAG,2BAAmB,CAAC,CAAC","sourcesContent":["/**\n * THE STREAM DIRECTORIES — `<state>/logs/<stream>/<sessionId>-<agentId|coordinator>-<hook>.log`.\n *\n * The stream is the DIRECTORY and the writer is the FILE. That split is the whole point: it puts the\n * LAYER in the path, so \"show me every L1 decision this session\" is one glob\n * (`logs/L1-location/<sid>-*`) instead of a question no glob could answer — every layer used to be\n * either a suffix on a flat name or, for L1, nothing at all.\n *\n * These live in agent-workflow-rules beside LogStream, because all FOUR writers are here of this layout and\n * not all of them are TypeScript: the L0 `ai-hook.sh` is POSIX sh\n * rendered from `bin/shim-audit-log.ts`, and it must spell these\n * directories identically or the layers scatter. One constant, four consumers — the same reason\n * LogStream itself lives here.\n *\n * NOT in rules-config, and that is load-bearing rather than tidiness: the `wp-*` bins are SPAWNED as\n * processes with no tsconfig path mapping, so they resolve `@webpieces/rules-config` to the PUBLISHED\n * copy in node_modules — a release behind local source. A stream name defined there would render as\n * `undefined` inside a spawned `wp-upgrade-shim` while the in-process renderer used the real value,\n * and the two shims would differ by exactly the constant. Same-package means same source, always.\n *\n * Nesting by STREAM is not the nesting that was rejected. What `logs/` refused was nesting by\n * IDENTITY (`sessions/<id>/<agent>/…`), which breaks every cross-session question. A one-level\n * wildcard recovers the flat view here — `ls -t logs/[star]/<sid>-*` is still every stream in time\n * order, across every layer at once.\n */\nexport const L0_SHIM_STREAM = 'L0-shim';\nexport const L1_LOCATION_STREAM = 'L1-location';\nexport const L2_DECISIONS_STREAM = 'L2-decisions';\nexport const CALLS_STREAM = 'calls';\nexport const ASYNC_REFRESH_STREAM = 'async-refresh';\nexport const REJECTIONS_STREAM = 'rejections';\n\n/**\n * Every stream directory, for the sweeps and specs that must enumerate them rather than name one.\n * A new stream that is not added here is invisible to retention — which is why this is a list and not\n * a doc sentence.\n */\nexport const ALL_LOG_STREAMS: readonly string[] = [\n L0_SHIM_STREAM, L1_LOCATION_STREAM, L2_DECISIONS_STREAM,\n CALLS_STREAM, ASYNC_REFRESH_STREAM, REJECTIONS_STREAM,\n];\n\n/**\n * Stream directories an OLDER release wrote and this one never will. Kept beside the live list because a\n * directory that is in neither is invisible to every sweep, so its files would sit on disk forever.\n *\n * `SWEEPABLE_LOG_STREAMS` — live + retired — is what retention and the layout specs must enumerate;\n * `ALL_LOG_STREAMS` stays the answer to \"what may be WRITTEN\". Keeping the two separate is what stops a\n * retired name from quietly becoming a writable one again.\n */\nexport const RETIRED_LOG_STREAMS: readonly string[] = ['L-1-cd'];\n\n/** Every directory retention may reap: what this release writes, plus what older ones left behind. */\nexport const SWEEPABLE_LOG_STREAMS: readonly string[] = [...ALL_LOG_STREAMS, ...RETIRED_LOG_STREAMS];\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE spelling of "how a command or file path is written into a log line's target field".
|
|
3
|
+
*
|
|
4
|
+
* It exists because the format now has a READER as well as a writer. `InvocationLog` and
|
|
5
|
+
* `logGuardDecision` collapse a command to one capped line before appending it; `SessionCallHistory`
|
|
6
|
+
* has to reproduce that byte for byte to recognise the same command coming back. Two private copies of
|
|
7
|
+
* a collapse-and-cap is exactly the second spelling `.claude/rules/no-backwards-compat.md` rejects —
|
|
8
|
+
* and the failure it produces is silent, since a mismatched cap simply means a long command never
|
|
9
|
+
* matches itself and the guard that depends on it quietly never fires.
|
|
10
|
+
*/
|
|
11
|
+
export declare class LogTarget {
|
|
12
|
+
/**
|
|
13
|
+
* Collapse newlines and tabs so one decision is always one log line, and cap the length so a
|
|
14
|
+
* pasted heredoc cannot make a log line unreadable. The ellipsis is part of the stored value.
|
|
15
|
+
*/
|
|
16
|
+
oneLine(value: string): string;
|
|
17
|
+
}
|
|
18
|
+
/** The cap, exported so a spec can assert against it rather than re-typing the number. */
|
|
19
|
+
export declare const MAX_TARGET_LEN = 160;
|
|
20
|
+
/** Process-wide instance: it is a pure function of its input, so there is nothing to construct twice. */
|
|
21
|
+
export declare const logTarget: LogTarget;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logTarget = exports.MAX_TARGET_LEN = exports.LogTarget = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The ONE spelling of "how a command or file path is written into a log line's target field".
|
|
6
|
+
*
|
|
7
|
+
* It exists because the format now has a READER as well as a writer. `InvocationLog` and
|
|
8
|
+
* `logGuardDecision` collapse a command to one capped line before appending it; `SessionCallHistory`
|
|
9
|
+
* has to reproduce that byte for byte to recognise the same command coming back. Two private copies of
|
|
10
|
+
* a collapse-and-cap is exactly the second spelling `.claude/rules/no-backwards-compat.md` rejects —
|
|
11
|
+
* and the failure it produces is silent, since a mismatched cap simply means a long command never
|
|
12
|
+
* matches itself and the guard that depends on it quietly never fires.
|
|
13
|
+
*/
|
|
14
|
+
class LogTarget {
|
|
15
|
+
/**
|
|
16
|
+
* Collapse newlines and tabs so one decision is always one log line, and cap the length so a
|
|
17
|
+
* pasted heredoc cannot make a log line unreadable. The ellipsis is part of the stored value.
|
|
18
|
+
*/
|
|
19
|
+
oneLine(value) {
|
|
20
|
+
const flat = value.replace(/[\t\r\n]+/g, ' ').trim();
|
|
21
|
+
return flat.length <= exports.MAX_TARGET_LEN ? flat : flat.slice(0, exports.MAX_TARGET_LEN) + '…';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.LogTarget = LogTarget;
|
|
25
|
+
/** The cap, exported so a spec can assert against it rather than re-typing the number. */
|
|
26
|
+
exports.MAX_TARGET_LEN = 160;
|
|
27
|
+
/** Process-wide instance: it is a pure function of its input, so there is nothing to construct twice. */
|
|
28
|
+
exports.logTarget = new LogTarget();
|
|
29
|
+
//# sourceMappingURL=log-target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-target.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/log-target.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,MAAa,SAAS;IAClB;;;OAGG;IACH,OAAO,CAAC,KAAa;QACjB,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACrD,OAAO,IAAI,CAAC,MAAM,IAAI,sBAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,sBAAc,CAAC,GAAG,GAAG,CAAC;IACtF,CAAC;CACJ;AATD,8BASC;AAED,0FAA0F;AAC7E,QAAA,cAAc,GAAG,GAAG,CAAC;AAElC,yGAAyG;AAC5F,QAAA,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC","sourcesContent":["/**\n * The ONE spelling of \"how a command or file path is written into a log line's target field\".\n *\n * It exists because the format now has a READER as well as a writer. `InvocationLog` and\n * `logGuardDecision` collapse a command to one capped line before appending it; `SessionCallHistory`\n * has to reproduce that byte for byte to recognise the same command coming back. Two private copies of\n * a collapse-and-cap is exactly the second spelling `.claude/rules/no-backwards-compat.md` rejects —\n * and the failure it produces is silent, since a mismatched cap simply means a long command never\n * matches itself and the guard that depends on it quietly never fires.\n */\nexport class LogTarget {\n /**\n * Collapse newlines and tabs so one decision is always one log line, and cap the length so a\n * pasted heredoc cannot make a log line unreadable. The ellipsis is part of the stored value.\n */\n oneLine(value: string): string {\n const flat = value.replace(/[\\t\\r\\n]+/g, ' ').trim();\n return flat.length <= MAX_TARGET_LEN ? flat : flat.slice(0, MAX_TARGET_LEN) + '…';\n }\n}\n\n/** The cap, exported so a spec can assert against it rather than re-typing the number. */\nexport const MAX_TARGET_LEN = 160;\n\n/** Process-wide instance: it is a pure function of its input, so there is nothing to construct twice. */\nexport const logTarget = new LogTarget();\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type SyncPhase = 'SPAWN_ATTEMPT' | 'START' | 'SKIP_INPROGRESS' | 'FINISH' | 'ERROR';
|
|
2
|
+
export declare class SyncLogEvent {
|
|
3
|
+
phase: SyncPhase;
|
|
4
|
+
pid: number;
|
|
5
|
+
branchArg: string;
|
|
6
|
+
detail: string;
|
|
7
|
+
constructor(phase: SyncPhase, pid: number, branchArg: string, detail: string);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Append one tab-separated line per refresher event to
|
|
11
|
+
* `.webpieces/logs/async-refresh/<writer>.log` (see LogStream for the writer key). `root` is
|
|
12
|
+
* the workspace root holding `.webpieces`. Swallows all errors — logging must never block or fail
|
|
13
|
+
* the refresher (or the hook that spawns it).
|
|
14
|
+
*/
|
|
15
|
+
export declare function logSyncEvent(root: string, event: SyncLogEvent): void;
|
|
16
|
+
export declare function refresherChildStdioPath(root: string): string;
|