@mamdouh-aboammar/agentic-workflow 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +10 -0
- package/.codex-plugin/plugin.json +13 -0
- package/.skills.json +19 -0
- package/AGENTS.md +1344 -0
- package/CLAUDE.md +178 -0
- package/GEMINI.md +102 -0
- package/LICENSE +21 -0
- package/README.md +350 -0
- package/SKILL.md +132 -0
- package/bin/agentic-hooks.sh +79 -0
- package/bin/cli.js +1060 -0
- package/core/__init__.py +52 -0
- package/core/ai_evaluator.py +117 -0
- package/core/autopilot_engine.py +368 -0
- package/core/clean_code_guard.py +188 -0
- package/core/engine_py/__init__.py +29 -0
- package/core/engine_py/agent_worker.py +136 -0
- package/core/engine_py/decider.py +150 -0
- package/core/engine_py/energy.py +45 -0
- package/core/engine_py/event_bus.py +63 -0
- package/core/engine_py/executor.py +186 -0
- package/core/engine_py/models.py +193 -0
- package/core/engine_py/queue.py +314 -0
- package/core/engine_py/runner.py +116 -0
- package/core/engine_py/system_workers.py +70 -0
- package/core/engine_py/toon_adapter.py +586 -0
- package/core/engine_py/verification_controller.py +208 -0
- package/core/engine_py/worker.py +167 -0
- package/core/engine_spec/event_schema.json +65 -0
- package/core/engine_spec/example_workflow.yaml +73 -0
- package/core/engine_spec/workflow_schema.json +127 -0
- package/core/hooks/__init__.py +29 -0
- package/core/hooks/adapters/__init__.py +25 -0
- package/core/hooks/adapters/claude_adapter.py +83 -0
- package/core/hooks/adapters/cli_agent_adapter.py +82 -0
- package/core/hooks/adapters/codex_adapter.py +78 -0
- package/core/hooks/adapters/cursor_adapter.py +73 -0
- package/core/hooks/adapters/gemini_adapter.py +93 -0
- package/core/hooks/adapters/homebrew_adapter.py +69 -0
- package/core/hooks/adapters/mcp_proxy.py +133 -0
- package/core/hooks/adapters/shell_adapter.py +65 -0
- package/core/hooks/dispatcher.py +118 -0
- package/core/hooks/policy_engine.py +375 -0
- package/core/hooks/session_end.py +141 -0
- package/core/hooks/types.py +147 -0
- package/core/integrations/__init__.py +28 -0
- package/core/integrations/installer.py +225 -0
- package/core/integrations/lifecycle_director.py +175 -0
- package/core/integrations/registry.py +105 -0
- package/core/multi_agent_system.py +164 -0
- package/core/skills_indexer.py +742 -0
- package/core/system/__init__.py +25 -0
- package/core/system/announcements.py +72 -0
- package/core/system/dependencies.py +69 -0
- package/core/system/doctor.py +171 -0
- package/core/system/health.py +144 -0
- package/core/system/installer.py +137 -0
- package/core/system/notifications.py +97 -0
- package/core/system/refresher.py +110 -0
- package/core/system/updater.py +167 -0
- package/core/system/version_tracker.py +65 -0
- package/docs/architecture_plan.md +7 -0
- package/docs/guides/failure-recovery.md +714 -0
- package/docs/implementation_summary.md +10 -0
- package/docs/protocols/autopilot-execution.md +148 -0
- package/docs/protocols/code-change-protocol.md +49 -0
- package/docs/protocols/context-preservation-detail.md +114 -0
- package/docs/protocols/quality-gates.md +110 -0
- package/docs/protocols/ulw-mode.md +60 -0
- package/docs/research_findings.md +10 -0
- package/docs/solutions/autonomous-autopilot-engine-architecture.md +38 -0
- package/install.sh +111 -0
- package/marketplace.json +37 -0
- package/package.json +81 -0
- package/skills/agentic-workflow/SKILL.md +132 -0
- package/skills/agentic-workflow/skill-spec.json +100 -0
- package/soul.md +445 -0
- package/src/engine_ts/decider.ts +186 -0
- package/src/engine_ts/event-bus.ts +57 -0
- package/src/engine_ts/executor.ts +262 -0
- package/src/engine_ts/index.ts +12 -0
- package/src/engine_ts/queue.ts +93 -0
- package/src/engine_ts/runner.ts +108 -0
- package/src/engine_ts/skills-indexer.ts +264 -0
- package/src/engine_ts/toon-adapter.ts +91 -0
- package/src/engine_ts/types.ts +134 -0
- package/src/engine_ts/verification-controller.ts +204 -0
- package/src/engine_ts/worker.ts +280 -0
- package/src/hooks/adapters/claude-adapter.ts +54 -0
- package/src/hooks/adapters/cli-agent-adapter.ts +46 -0
- package/src/hooks/adapters/codex-adapter.ts +69 -0
- package/src/hooks/adapters/cursor-adapter.ts +60 -0
- package/src/hooks/adapters/gemini-adapter.ts +71 -0
- package/src/hooks/adapters/homebrew-adapter.ts +36 -0
- package/src/hooks/adapters/mcp-proxy.ts +66 -0
- package/src/hooks/adapters/shell-adapter.ts +42 -0
- package/src/hooks/dispatcher.ts +113 -0
- package/src/hooks/index.ts +16 -0
- package/src/hooks/policy-engine.ts +376 -0
- package/src/hooks/session-end.ts +125 -0
- package/src/hooks/types.ts +61 -0
- package/src/index.d.ts +34 -0
- package/src/index.ts +23 -0
- package/src/integrations/index.ts +7 -0
- package/src/integrations/installer.ts +208 -0
- package/src/integrations/lifecycle-director.ts +139 -0
- package/src/integrations/registry.ts +82 -0
- package/src/system/announcements.ts +143 -0
- package/src/system/dependencies.ts +176 -0
- package/src/system/doctor.ts +374 -0
- package/src/system/health.ts +270 -0
- package/src/system/index.ts +14 -0
- package/src/system/installer.ts +262 -0
- package/src/system/notifications.ts +180 -0
- package/src/system/refresher.ts +207 -0
- package/src/system/types.ts +268 -0
- package/src/system/updater.ts +219 -0
- package/src/system/version-tracker.ts +137 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Deliverable: Implement Core Production Logic
|
|
2
|
+
Synthesized by TypeScript AgentWorker `agent_worker_1` (Role: `engineer`).
|
|
3
|
+
Trace ID: `ts_1788684646384_ej11ei`
|
|
4
|
+
|
|
5
|
+
## Criteria Fulfillments
|
|
6
|
+
- [x] **Pass unit tests**: Addressed with full architectural precision.
|
|
7
|
+
- [x] **Generate comprehensive documentation**: Addressed with full architectural precision.
|
|
8
|
+
|
|
9
|
+
## Implementation Details
|
|
10
|
+
Engineered to satisfy L0 physical existence, L1 functional criteria, and L1.5 pACS confidence.
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Autopilot Execution Protocol
|
|
2
|
+
|
|
3
|
+
> Detailed execution checklist when running workflows in Autopilot Mode.
|
|
4
|
+
> Reference strictly during workflow execution.
|
|
5
|
+
|
|
6
|
+
## Activation Patterns
|
|
7
|
+
|
|
8
|
+
| User Command | Behavior |
|
|
9
|
+
|---|---|
|
|
10
|
+
| "run in autopilot mode", "execute workflow automatically", "fully automated run" | Sets `autopilot.enabled: true` in SOT and starts workflow |
|
|
11
|
+
| "disable autopilot", "switch to manual mode" | Sets `autopilot.enabled: false` in SOT — applies from next `(human)` step |
|
|
12
|
+
|
|
13
|
+
## Checkpoint Behaviors
|
|
14
|
+
|
|
15
|
+
| Checkpoint | Autopilot Behavior |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `(human)` + Slash Command | Generates complete deliverable → auto-approves using quality-maximizing defaults → writes Decision Log |
|
|
18
|
+
| AskUserQuestion | Automatically selects the quality-maximizing option → writes Decision Log |
|
|
19
|
+
| `(hook)` exit code 2 | **NO CHANGE** — strictly blocked, feedback delivered, rework mandated |
|
|
20
|
+
|
|
21
|
+
## Decision Logs
|
|
22
|
+
|
|
23
|
+
Auto-approved decisions are recorded in `autopilot-logs/step-N-decision.md`: step, options, and selection rationale (grounded in Absolute Criterion 1).
|
|
24
|
+
Standard Decision Log Template: `references/autopilot-decision-template.md`.
|
|
25
|
+
|
|
26
|
+
## Runtime Enforcement Mechanisms
|
|
27
|
+
|
|
28
|
+
| Layer | Mechanism | Enforcement Details |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| **Hook** (Deterministic) | `restore_context.py` — SessionStart | Injects 6 execution rules + prior step deliverable validation results into context |
|
|
31
|
+
| **Hook** (Deterministic) | `generate_snapshot_md()` — Snapshot | Preserves Autopilot state + Agent Team state in IMMORTAL priority section |
|
|
32
|
+
| **Hook** (Deterministic) | `generate_context_summary.py` — Stop | Detects auto-approval patterns → backfills missing Decision Logs (safety net) |
|
|
33
|
+
| **Hook** (Deterministic) | `update_work_log.py` — PostToolUse | Tracks step progression via `autopilot_step` field |
|
|
34
|
+
| **Prompt** (Behavioral) | Execution Checklist (below) | Specifies mandatory actions at start, during, and after each step |
|
|
35
|
+
|
|
36
|
+
> The Hook layer accesses the SOT in read-only mode (Absolute Criterion 2 compliant), writing only to `context-snapshots/` and `autopilot-logs/`.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Execution Checklist (MANDATORY)
|
|
41
|
+
|
|
42
|
+
When executing a workflow in Autopilot mode, the following checklist **MUST** be performed at every step:
|
|
43
|
+
|
|
44
|
+
### Before Starting Each Step
|
|
45
|
+
- [ ] Confirm SOT `current_step`
|
|
46
|
+
- [ ] Verify prior step deliverable exists on disk and is non-empty
|
|
47
|
+
- [ ] Verify prior step deliverable path is recorded in SOT `outputs`
|
|
48
|
+
- [ ] Read step `Verification` criteria — internalize the definition of "100% completion" upfront (`AGENTS.md §5.3`)
|
|
49
|
+
|
|
50
|
+
### During Step Execution
|
|
51
|
+
- [ ] Execute all tasks in the step **completely** (no abbreviations — Absolute Criterion 1)
|
|
52
|
+
- [ ] Produce deliverables with **uncompromised quality**
|
|
53
|
+
|
|
54
|
+
### After Step Completion (Verification Gate — steps with `Verification` field)
|
|
55
|
+
- [ ] Persist deliverable file to disk
|
|
56
|
+
- [ ] Self-verify deliverable against each declared `Verification` criterion
|
|
57
|
+
- [ ] If any criterion fails:
|
|
58
|
+
- [ ] Check & increment P1 retry budget: `python3 .claude/hooks/scripts/validate_retry_budget.py --step N --gate verification --project-dir . --check-and-increment`
|
|
59
|
+
- [ ] `can_retry: true` → **Perform Abductive Diagnosis** (see diagnosis subsection) → rerun based on diagnosis
|
|
60
|
+
- [ ] `can_retry: false` → Escalate to user (budget exhausted, counter not incremented)
|
|
61
|
+
- [ ] Verify all criteria evaluate to PASS
|
|
62
|
+
- [ ] Generate `verification-logs/step-N-verify.md`
|
|
63
|
+
- [ ] Run P1 verification: `python3 .claude/hooks/scripts/validate_verification.py --step N --project-dir .`
|
|
64
|
+
- [ ] Confirm P1 verification result is `valid: true` (V1a-V1c passed)
|
|
65
|
+
|
|
66
|
+
### After Step Completion (Cross-Step Traceability — steps requiring traceability)
|
|
67
|
+
- [ ] Ensure deliverable includes >= 3 `[trace:step-N:section-id]` markers
|
|
68
|
+
- [ ] Confirm all markers refer strictly to previous steps (no forward references)
|
|
69
|
+
- [ ] Run P1 verification: `python3 .claude/hooks/scripts/validate_traceability.py --step N --project-dir .`
|
|
70
|
+
- [ ] Confirm P1 verification result is `valid: true` (CT1-CT5 passed)
|
|
71
|
+
- [ ] Re-verify marker precision if CT3 WARNING (unresolved section ID) occurs
|
|
72
|
+
|
|
73
|
+
### After Step Completion (Domain Knowledge Structure — workflows using DKS)
|
|
74
|
+
- [ ] If step builds `domain-knowledge.yaml`: run P1 check `python3 .claude/hooks/scripts/validate_domain_knowledge.py --project-dir .`
|
|
75
|
+
- [ ] Confirm `valid: true` (DK1-DK5 passed)
|
|
76
|
+
- [ ] If step references DKS (`[dks:xxx]` markers): run P1 check `python3 .claude/hooks/scripts/validate_domain_knowledge.py --project-dir . --check-output --step N`
|
|
77
|
+
- [ ] Confirm `valid: true` (DK6-DK7 passed)
|
|
78
|
+
|
|
79
|
+
### After Step Completion (pACS — executed after passing Verification Gate)
|
|
80
|
+
- [ ] Answer all 3 Pre-mortem Protocol questions (`AGENTS.md §5.4`)
|
|
81
|
+
- [ ] Score Faithfulness, Completeness, Logic → calculate pACS = min(F, C, L)
|
|
82
|
+
- [ ] Generate `pacs-logs/step-N-pacs.md`
|
|
83
|
+
- [ ] Update SOT `pacs` field (`current_step_score`, `dimensions`, `weak_dimension`, `history`)
|
|
84
|
+
- [ ] On pACS RED (< 50):
|
|
85
|
+
- [ ] Check & increment P1 retry budget: `python3 .claude/hooks/scripts/validate_retry_budget.py --step N --gate pacs --project-dir . --check-and-increment`
|
|
86
|
+
- [ ] `can_retry: true` → **Perform Abductive Diagnosis** → rework and rescore based on diagnosis
|
|
87
|
+
- [ ] `can_retry: false` → Escalate to user (budget exhausted)
|
|
88
|
+
- [ ] On pACS YELLOW (50-69): Record weak dimension in Decision Log, then proceed
|
|
89
|
+
- [ ] Run P1 validation: `python3 .claude/hooks/scripts/validate_pacs.py --step N --check-l0 --project-dir .`
|
|
90
|
+
- [ ] Confirm P1 validation result is `valid: true` (PA1-PA7 + L0 passed)
|
|
91
|
+
- [ ] Record deliverable path in SOT `outputs`
|
|
92
|
+
- [ ] Increment SOT `current_step` by +1
|
|
93
|
+
- [ ] If `(human)` step: Generate `autopilot-logs/step-N-decision.md`
|
|
94
|
+
- [ ] If `(human)` step: Append to SOT `auto_approved_steps`
|
|
95
|
+
|
|
96
|
+
### Additional Checklist for `(team)` Steps
|
|
97
|
+
- [ ] Immediately after `TeamCreate` → Record SOT `active_team` (`name`, `status`, `tasks_pending`)
|
|
98
|
+
- [ ] Each Teammate self-verifies against assigned task criteria before reporting (L1 — `AGENTS.md §5.3`)
|
|
99
|
+
- [ ] Each Teammate performs pACS self-rating upon passing L1 (L1.5 — include score in report message)
|
|
100
|
+
- [ ] Upon Teammate completion → Team Lead executes comprehensive validation against step criteria (L2) and computes step pACS
|
|
101
|
+
- [ ] On L2 FAIL or Teammate pACS RED → SendMessage with specific actionable feedback and rerun instruction
|
|
102
|
+
- [ ] Upon Teammate completion → Update SOT `active_team.tasks_completed` and `completed_summaries`
|
|
103
|
+
- [ ] Upon all tasks completing → Record SOT `outputs`, increment `current_step` by +1, set `active_team.status` to `all_completed`
|
|
104
|
+
- [ ] Immediately after `TeamDelete` → Move SOT `active_team` to `completed_teams`
|
|
105
|
+
- [ ] Confirm Teammate deliverables contain Decision Rationale and Cross-Reference Cues
|
|
106
|
+
|
|
107
|
+
### After Step Completion (Adversarial Review — steps with `Review: @reviewer|@fact-checker`)
|
|
108
|
+
- [ ] Invoke designated agent as Sub-agent (recommended: `isolation: "worktree"` to protect Orchestrator context; see `reviewer.md § Context Isolation`)
|
|
109
|
+
- [ ] Persist review report to `review-logs/step-N-review.md`
|
|
110
|
+
- [ ] Run P1 validation: `python3 .claude/hooks/scripts/validate_review.py --step N --project-dir . --check-pacs-arithmetic`
|
|
111
|
+
- [ ] Confirm P1 validation result is `valid: true` (R1-R5 passed)
|
|
112
|
+
- [ ] Evaluate verdict:
|
|
113
|
+
- [ ] PASS → Proceed to next step
|
|
114
|
+
- [ ] FAIL → Check & increment P1 retry budget: `python3 .claude/hooks/scripts/validate_retry_budget.py --step N --gate review --project-dir . --check-and-increment`
|
|
115
|
+
- [ ] `can_retry: true` → **Perform Abductive Diagnosis** → rework based on diagnosis
|
|
116
|
+
- [ ] `can_retry: false` → Escalate to user (budget exhausted)
|
|
117
|
+
- [ ] If pACS Delta >= 15 → Record in Decision Log and document recalibration rationale
|
|
118
|
+
- [ ] Never proceed if Review status is FAIL
|
|
119
|
+
|
|
120
|
+
### Abductive Diagnosis on Quality Gate FAIL
|
|
121
|
+
- [ ] Step A — P1 Pre-evidence Collection: `python3 .claude/hooks/scripts/diagnose_context.py --step N --gate {verification|pacs|review} --project-dir .`
|
|
122
|
+
- [ ] Check Fast-Path: if `fast_path.eligible == true` → FP1/FP2 reruns immediately; FP3 escalates to user
|
|
123
|
+
- [ ] If no Fast-Path applies → Step B — LLM Diagnosis: Analyze root causes based on evidence bundle and hypothesis priority
|
|
124
|
+
- [ ] Persist diagnosis log: `diagnosis-logs/step-N-{gate}-{timestamp}.md`
|
|
125
|
+
- [ ] Step C — P1 Post-Validation: `python3 .claude/hooks/scripts/validate_diagnosis.py --step N --gate {verification|pacs|review} --project-dir .`
|
|
126
|
+
- [ ] Confirm P1 result is `valid: true` (AD1-AD10 passed)
|
|
127
|
+
- [ ] Execute rework grounded in the selected hypothesis (H1/H2/H3/H4)
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## NEVER DO
|
|
132
|
+
|
|
133
|
+
- Never increment `current_step` by more than +1 at once.
|
|
134
|
+
- Never proceed to the next step without an existing, verified deliverable on disk.
|
|
135
|
+
- Never abbreviate or cut corners because it is "automated" — direct violation of Absolute Criterion 1.
|
|
136
|
+
- Never ignore a Safety Hook block (`(hook)` exit code 2).
|
|
137
|
+
- Never allow a Teammate in a `(team)` step to directly modify the SOT — only Team Lead updates SOT.
|
|
138
|
+
- Never initialize `active_team` to an empty object upon session restore — always preserve `completed_summaries`.
|
|
139
|
+
- Never proceed to the next step while Verification criteria evaluate to FAIL — retry up to 10 times (15 with ULW), then escalate to user.
|
|
140
|
+
- Never falsely record criteria as "ALL PASS" without concrete verifiable Evidence.
|
|
141
|
+
- Never assign pACS scores without performing the Pre-mortem Protocol.
|
|
142
|
+
- Never perform pACS in isolation without the Verification Gate — L1 PASS is the prerequisite for L1.5.
|
|
143
|
+
- Never grant indiscriminate scores of 90+ across all dimensions — scores must reflect Pre-mortem vulnerabilities.
|
|
144
|
+
- Never mark Review as PASS with 0 identified issues — P1 validation will reject it (R5 check).
|
|
145
|
+
- Never score Reviewer pACS by copying Generator pACS — independent scoring is mandatory.
|
|
146
|
+
- Never retry a failing quality gate with the exact same approach without diagnosis — Abductive Diagnosis or Fast-Path is mandatory.
|
|
147
|
+
- Never record only 1 hypothesis in a diagnosis log — minimum 2 competing hypotheses required (AD8).
|
|
148
|
+
- Never select the same hypothesis 3 consecutive times in diagnosis — triggers FP3 user escalation.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Code Change Protocol (CCP) — Detailed Specification
|
|
2
|
+
|
|
3
|
+
> This document details the procedure for Absolute Criterion 3 (Code Change Protocol).
|
|
4
|
+
> Consult before making any code modifications.
|
|
5
|
+
|
|
6
|
+
## The 3-Step Protocol
|
|
7
|
+
|
|
8
|
+
Before writing, modifying, adding, or deleting code, you must internally perform the following 3 steps.
|
|
9
|
+
Skipping this protocol is a direct violation of the Absolute Criteria.
|
|
10
|
+
The protocol is always performed, with analysis depth scaling proportionally with the scope of the change.
|
|
11
|
+
|
|
12
|
+
### Step 1 — Understand Intent
|
|
13
|
+
- Define the purpose of the change (bug fix, feature addition, refactoring, performance) and constraints (compatibility, tech stack) in 1-2 sentences.
|
|
14
|
+
- For minor changes (typos, comments, formatting), confirm "no ripple effect" and execute immediately.
|
|
15
|
+
|
|
16
|
+
### Step 2 — Ripple Effect Analysis
|
|
17
|
+
- Direct dependencies + Call relationships (caller / callee)
|
|
18
|
+
- Structural relationships (inheritance, composition, reference)
|
|
19
|
+
- Data model / schema / type cascade changes
|
|
20
|
+
- Tests, configuration, documentation, and API specifications
|
|
21
|
+
- If tight coupling or shotgun surgery risks exist, **mandatory** prior notification and discussion with the user.
|
|
22
|
+
|
|
23
|
+
### Step 3 — Change Plan
|
|
24
|
+
- Step-by-step change sequence (which file/function first → dependency propagation → test/doc alignment).
|
|
25
|
+
- Propose refactoring opportunities that reduce coupling / increase cohesion (execute only after user approval).
|
|
26
|
+
|
|
27
|
+
## Proportionality Rule
|
|
28
|
+
|
|
29
|
+
| Change Scope | Applied Depth |
|
|
30
|
+
|---|---|
|
|
31
|
+
| Minor (typos, comments, formatting) | Step 1 only — confirm "no ripple effect" |
|
|
32
|
+
| Standard (functions, logic, files) | Full 3 steps |
|
|
33
|
+
| Large-scale (architecture, public API, cross-cutting) | Full 3 steps + mandatory prior user approval |
|
|
34
|
+
|
|
35
|
+
## Communication Rules
|
|
36
|
+
- Avoid unnecessarily verbose theoretical explanations; focus on actual code and concrete steps.
|
|
37
|
+
- Add concise rationale for important design decisions.
|
|
38
|
+
- If ambiguities exist, do not avoid work — explicitly state "reasonable assumptions" and propose the optimal design.
|
|
39
|
+
|
|
40
|
+
## Coding Anchor Points (CAP)
|
|
41
|
+
|
|
42
|
+
Every step of CCP must internalize the following 4 mindsets:
|
|
43
|
+
|
|
44
|
+
- **CAP-1: Think Before Coding** — Never modify code before reading it. Surface trade-offs. Ask when unclear.
|
|
45
|
+
- **CAP-2: Simplicity First** — Minimal code. No speculative features, premature abstractions, or unnecessary helpers.
|
|
46
|
+
- **CAP-3: Goal-Based Execution** — Define success criteria first, verify after implementation.
|
|
47
|
+
- **CAP-4: Surgical Changes** — Perform only requested changes. No unrelated "improvements".
|
|
48
|
+
|
|
49
|
+
> CAP is subordinate to CCP; when conflicting with Absolute Criterion 1 (Quality), Quality always wins. Details: `AGENTS.md §2`.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Context Preservation System — Detailed Specification
|
|
2
|
+
|
|
3
|
+
> Internal mechanics and architectural details of the Context Preservation System.
|
|
4
|
+
> Consult when modifying, debugging, or extending Hook infrastructure.
|
|
5
|
+
|
|
6
|
+
## Operational Workflow for AI Agents
|
|
7
|
+
|
|
8
|
+
- When `[CONTEXT RECOVERY]` appears at session start, **you must read the indicated snapshot file** using the Read tool to restore prior working context.
|
|
9
|
+
- The latest snapshot is persisted at `.claude/context-snapshots/latest.md`.
|
|
10
|
+
- **Knowledge Archive**: `knowledge-index.jsonl` is a structured index accumulating across sessions. Both the Stop hook and SessionEnd/PreCompact write to it. Each entry captures `completion_summary` (tool success/failure), `git_summary` (repo diffs), `session_duration_entries`, `phase`, `phase_flow` (multi-stage transition flows, e.g., `research → implementation`), `primary_language` (dominant extension), `error_patterns` (Error Taxonomy 12 patterns + resolution matching), `success_patterns` (Edit/Write→Bash success sequences), `tool_sequence` (RLE compressed tool sequence), `final_status` (success/incomplete/error/unknown), and path-based search `tags`. Grep tool provides programmatic exploration (RLM pattern).
|
|
11
|
+
- **Resume Protocol**: The "Recovery Instructions" section in snapshots deterministically provides modified/referenced file paths and session details. `[CONTEXT RECOVERY]` displays tool success/failure counts and git status. **Dynamic RLM Query Hints**: Generates tailored Grep query patterns based on extracted file path tags (`extract_path_tags()`) and recorded error signatures.
|
|
12
|
+
- Hook scripts access the SOT (`state.yaml`) strictly in **read-only** mode (Absolute Criterion 2 compliant). SOT file paths are centrally managed via the `sot_paths()` helper, derived from `SOT_FILENAMES` (`state.yaml`, `state.yml`, `state.json`).
|
|
13
|
+
|
|
14
|
+
## Centralized Truncation Constants
|
|
15
|
+
|
|
16
|
+
10 truncation constants are centrally defined in `_context_lib.py`:
|
|
17
|
+
- `EDIT_PREVIEW_CHARS = 1000` — Preserves edit intent and surrounding context (5 lines x 1000 chars).
|
|
18
|
+
- `ERROR_RESULT_CHARS = 3000` — Preserves full stack traces.
|
|
19
|
+
- `MIN_OUTPUT_SIZE = 100` — Minimum deliverable file size.
|
|
20
|
+
|
|
21
|
+
## Multi-Stage Phase Transition Detection
|
|
22
|
+
|
|
23
|
+
The `detect_phase_transitions()` function uses a sliding window (20 tools, 50% overlap) to deterministically detect in-session workflow stage transitions (e.g. `research → planning → implementation`). Recorded in the Knowledge Archive `phase_flow` field.
|
|
24
|
+
|
|
25
|
+
## Decision Quality Tag Ordering
|
|
26
|
+
|
|
27
|
+
The "Key Design Decisions" section in snapshots (IMMORTAL priority) orders items by quality tags: `[explicit]` > `[decision]` > `[rationale]` > `[intent]`, filling 15 available slots so routine intent statements do not crowd out architectural decisions.
|
|
28
|
+
|
|
29
|
+
## IMMORTAL-Aware Compression
|
|
30
|
+
|
|
31
|
+
When a snapshot exceeds the context budget, Phase 7 hard truncation prioritizes IMMORTAL sections. Non-IMMORTAL sections are trimmed first, and even in extreme cases the head of IMMORTAL text is preserved.
|
|
32
|
+
|
|
33
|
+
**Compression Audit Trail**: Recorded at the end of snapshots as HTML comments (`<!-- compression-audit: ... -->`) documenting characters trimmed across Phases 1-7 and final size.
|
|
34
|
+
|
|
35
|
+
## Error Taxonomy
|
|
36
|
+
|
|
37
|
+
Categorizes tool execution failures across 12 distinct patterns:
|
|
38
|
+
`file_not_found`, `permission`, `syntax`, `timeout`, `dependency`, `edit_mismatch`, `type_error`, `value_error`, `connection`, `memory`, `git_error`, `command_not_found`.
|
|
39
|
+
|
|
40
|
+
Recorded in the Knowledge Archive `error_patterns` field, reducing "unknown" classifications to ~30%. Employs negative lookaheads and qualifying constraints to eliminate false positives.
|
|
41
|
+
|
|
42
|
+
**Error→Resolution Matching**: File-aware matching correlates tool errors with successful tool invocations within 5 subsequent entries, recording resolutions in the `resolution` field. Enables cross-session queries via `Grep "resolution" knowledge-index.jsonl`.
|
|
43
|
+
|
|
44
|
+
## Quality Gate State IMMORTAL Preservation
|
|
45
|
+
|
|
46
|
+
`_extract_quality_gate_state()` extracts the most recent quality gate evaluations from `pacs-logs/`, `review-logs/`, and `verification-logs/`, embedding them into snapshots under an IMMORTAL priority section.
|
|
47
|
+
|
|
48
|
+
## Phase Transition Snapshot Header
|
|
49
|
+
|
|
50
|
+
For sessions where multi-stage transitions are detected, the snapshot header indicates the flow (e.g. `Phase flow: research(12) → implementation(25)`).
|
|
51
|
+
|
|
52
|
+
## Error→Resolution Auto-Surfacing
|
|
53
|
+
|
|
54
|
+
`_extract_recent_error_resolutions()` in `restore_context.py` surfaces up to 3 recent error-resolution patterns from the Knowledge Archive directly in SessionStart output.
|
|
55
|
+
|
|
56
|
+
## Automated Runtime Directory Provisioning
|
|
57
|
+
|
|
58
|
+
`_check_runtime_dirs()` in `setup_init.py` automatically provisions 6 runtime directories when an SOT file exists: `verification-logs/`, `pacs-logs/`, `review-logs/`, `autopilot-logs/`, `translations/`, and `diagnosis-logs/`.
|
|
59
|
+
|
|
60
|
+
## System Command Filtering
|
|
61
|
+
|
|
62
|
+
Filters out system commands such as `/clear` and `/help` from the "Current Task" snapshot section, retaining only genuine user intent.
|
|
63
|
+
|
|
64
|
+
## Autopilot Runtime Enforcement
|
|
65
|
+
|
|
66
|
+
When Autopilot is enabled, SessionStart injects execution rules into context, the snapshot records Autopilot state (IMMORTAL priority), and the Stop hook detects and backfills missing Decision Logs.
|
|
67
|
+
|
|
68
|
+
## ULW Mode Detection & Inheritance
|
|
69
|
+
|
|
70
|
+
`detect_ulw_mode()` detects the `ulw` keyword in transcripts using word-boundary regexes. **Implicit Deactivation**: New sessions (`source=startup`) do not inherit ULW rules even if previous snapshots recorded ULW — only `clear`, `compact`, and `resume` sources inherit ULW.
|
|
71
|
+
|
|
72
|
+
## Predictive Debugging
|
|
73
|
+
|
|
74
|
+
`aggregate_risk_scores()` aggregates `error_patterns` by file with recency decay to generate risk scores. Executed once at SessionStart to populate `risk-scores.json`. `predictive_debug_guard.py` checks this cache before each Edit/Write, issuing warnings when thresholds are exceeded.
|
|
75
|
+
|
|
76
|
+
**Basename Merge**: Merges bare filenames and relative paths sharing the same basename, preventing risk score dilution.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Hook Configuration Map
|
|
81
|
+
|
|
82
|
+
All hooks are unified in `.claude/settings.json`. Cloning the repository applies the hook infrastructure automatically.
|
|
83
|
+
|
|
84
|
+
- **Stop** → `context_guard.py --mode=stop` → `generate_context_summary.py`
|
|
85
|
+
- **PostToolUse** → `context_guard.py --mode=post-tool` → `update_work_log.py` (matcher: `Edit|Write|Bash|Task|NotebookEdit|TeamCreate|SendMessage|TaskCreate|TaskUpdate`)
|
|
86
|
+
- **PreCompact** → `context_guard.py --mode=pre-compact` → `save_context.py --trigger precompact`
|
|
87
|
+
- **SessionStart** → `context_guard.py --mode=restore` → `restore_context.py` (matcher: `clear|compact|resume`)
|
|
88
|
+
- **PreToolUse** → `block_destructive_commands.py` (matcher: `Bash`, standalone execution — preserves exit code 2)
|
|
89
|
+
- **PreToolUse** → `block_test_file_edit.py` (matcher: `Edit|Write`, standalone execution — `.tdd-guard` toggle)
|
|
90
|
+
- **PreToolUse** → `predictive_debug_guard.py` (matcher: `Edit|Write`, standalone execution — warning only)
|
|
91
|
+
- **PostToolUse** → `output_secret_filter.py` (matcher: `Bash|Read`, standalone execution — secret detection, exit 0 warning)
|
|
92
|
+
- **PostToolUse** → `security_sensitive_file_guard.py` (matcher: `Edit|Write`, standalone execution — warning, exit 0)
|
|
93
|
+
- **SessionEnd** → `save_context.py --trigger sessionend` (matcher: `clear`)
|
|
94
|
+
- **Setup (init)** → `setup_init.py` — Infrastructure health check (`claude --init`)
|
|
95
|
+
- **Setup (maintenance)** → `setup_maintenance.py` — Periodic health check (`claude --maintenance`)
|
|
96
|
+
|
|
97
|
+
### Hook Architectural Rationale
|
|
98
|
+
|
|
99
|
+
> **`if test -f; then; fi` Pattern**: All hook commands use the `if test -f; then; fi` pattern, replacing the legacy `|| true` idiom that previously swallowed exit code 2 blocking signals.
|
|
100
|
+
> **Independent PreToolUse Safety Hooks**: `block_destructive_commands.py` and `block_test_file_edit.py` execute independently of `context_guard.py` to ensure exit code 2 signals are cleanly delivered to Claude.
|
|
101
|
+
> **Independent PostToolUse Security Hooks (ADR-050)**: `output_secret_filter.py` and `security_sensitive_file_guard.py` operate on their own streams and data sources independently of `context_guard.py`.
|
|
102
|
+
|
|
103
|
+
### D-7 Intentional Duplication Registry
|
|
104
|
+
|
|
105
|
+
| # | Instance | Location A | Location B |
|
|
106
|
+
|---|---|---|---|
|
|
107
|
+
| 1 | `REQUIRED_SCRIPTS` (20 scripts) | `setup_init.py` | `setup_maintenance.py` |
|
|
108
|
+
| 2 | `RISK_THRESHOLD` / `MIN_SESSIONS` | `predictive_debug_guard.py` | `_context_lib.py` |
|
|
109
|
+
| 3 | `ERROR_TAXONOMY` Types (12 types) | `_classify_error_patterns()` | `_RISK_WEIGHTS` (13 weights) |
|
|
110
|
+
| 4 | ULW Detection Regex | `_gather_retry_history()` | `validate_retry_budget.py` + `restore_context.py` |
|
|
111
|
+
| 5 | Retry Limit Constants | `validate_retry_budget.py` | `_context_lib.py` + `restore_context.py` |
|
|
112
|
+
| 6 | `SOT_FILENAMES` Tuple | `_context_lib.py` | `setup_init.py` + `query_workflow.py` |
|
|
113
|
+
|
|
114
|
+
**Automated Synchronization Check**: `_check_doc_code_sync()` in `setup_maintenance.py` deterministically verifies synchronization across DC-1 through DC-5.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Quality Gates & P1 Validation
|
|
2
|
+
|
|
3
|
+
> This document provides the detailed specification for the 4-layer quality assurance architecture and P1 hallucination containment.
|
|
4
|
+
> Consult when designing, debugging, or extending quality gates.
|
|
5
|
+
|
|
6
|
+
## 4-Layer Quality Assurance Architecture (L0 → L1 → L1.5 → L2)
|
|
7
|
+
|
|
8
|
+
The Orchestrator increments `current_step` strictly sequentially. Each step completion must pass up to 4 verification layers before proceeding:
|
|
9
|
+
|
|
10
|
+
1. **L0 Anti-Skip Guard** (Deterministic) — Deliverable file existence + minimum size (100 bytes). Executed by `validate_step_output()` at the hook layer.
|
|
11
|
+
2. **L1 Verification Gate** (Semantic) — Agent self-verification ensuring the deliverable achieves 100% of the declared `Verification` criteria. On failure, rerun only the failing section (up to 10 retries). Recorded in `verification-logs/step-N-verify.md`.
|
|
12
|
+
3. **L1.5 pACS Self-Rating** (Confidence) — Evaluates Faithfulness / Completeness / Logic (F/C/L) after executing the Pre-mortem Protocol. Recorded in `pacs-logs/step-N-pacs.md`. RED (< 50) mandates rework.
|
|
13
|
+
4. **[L2 Adversarial Review / Calibration]** (Optional / Enhanced) — Independent review by `@reviewer` and `@fact-checker` cross-checking deliverables, claims, and pACS scores for high-risk steps.
|
|
14
|
+
|
|
15
|
+
> Steps without a declared `Verification` field proceed with Anti-Skip Guard only (backward compatibility). Details: `AGENTS.md §5.3`, `§5.4`.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## P1 Hallucination Containment
|
|
20
|
+
|
|
21
|
+
Repetitive tasks requiring 100% accuracy are deterministically enforced via Python code.
|
|
22
|
+
|
|
23
|
+
### (1) Knowledge Index (KI) Schema Validation
|
|
24
|
+
`_validate_session_facts()` guarantees that required RLM keys (session_id, tags, final_status, diagnosis_patterns, etc., 11 items total) exist before writing to `knowledge-index.jsonl` — filling safe defaults if omitted.
|
|
25
|
+
|
|
26
|
+
### (2) Partial Failure Isolation
|
|
27
|
+
In `archive_and_index_session()`, failure to write an archive snapshot never blocks updating `knowledge-index.jsonl`, safeguarding core RLM assets.
|
|
28
|
+
|
|
29
|
+
### (3) SOT Write Pattern Validation
|
|
30
|
+
`_check_sot_write_safety()` in `setup_init.py` scans hook scripts using AST boundary analysis to detect accidental writes to SOT files (Tier 1: blocks non-SOT scripts from referencing SOT paths; Tier 2: verifies function-level write safety in SOT-aware scripts).
|
|
31
|
+
|
|
32
|
+
### (4) SOT Schema Validation
|
|
33
|
+
`validate_sot_schema()` validates structural integrity of workflow `state.yaml` across 8 items:
|
|
34
|
+
- **S1-S6**: `current_step` type & range, `outputs` dict & key format, future step deliverable detection, valid `workflow_status` values, `auto_approved_steps` consistency.
|
|
35
|
+
- **S7**: 5 fields for pACS validation (S7a: dimensions F/C/L 0-100, S7b: `current_step_score` 0-100, S7c: `weak_dimension`, S7d: `history` dictionary, S7e: `pre_mortem_flag` string).
|
|
36
|
+
- **S8**: 5 fields for `active_team` validation (S8a: `name` string, S8b: `status` partial|all_completed, S8c: `tasks_completed` list, S8d: `tasks_pending` list, S8e: `completed_summaries` dict).
|
|
37
|
+
|
|
38
|
+
Runs during both SessionStart and Stop hooks.
|
|
39
|
+
|
|
40
|
+
### (5) Adversarial Review P1 Validation
|
|
41
|
+
`validate_review_output()` validates structural integrity of review reports:
|
|
42
|
+
- R1: File existence
|
|
43
|
+
- R2: Minimum size
|
|
44
|
+
- R3: 4 mandatory sections
|
|
45
|
+
- R4: Explicit PASS / FAIL verdict extraction
|
|
46
|
+
- R5: Issue table has >= 1 row
|
|
47
|
+
|
|
48
|
+
`parse_review_verdict()` — regex extraction of issue severity counts.
|
|
49
|
+
`calculate_pacs_delta()` — Generator vs Reviewer pACS difference (Delta >= 15 triggers recalibration).
|
|
50
|
+
`validate_review_sequence()` — Enforces Review PASS preceding Translation via file timestamps.
|
|
51
|
+
Standalone script: `validate_review.py`.
|
|
52
|
+
|
|
53
|
+
### (6) Terminology & Translation P1 Validation
|
|
54
|
+
`validate_translation_output()` validates translation deliverables across 7 criteria:
|
|
55
|
+
- T1: File existence, T2: Minimum size, T3: English source existence, T4: Deliverable file naming, T5: Non-empty, T6: Heading count matching (+-20%), T7: Code block count equality.
|
|
56
|
+
|
|
57
|
+
`check_glossary_freshness()` — Validates glossary timestamp freshness (T8).
|
|
58
|
+
`verify_pacs_arithmetic()` — Generic min() arithmetic validation across all pACS logs (T9).
|
|
59
|
+
`validate_verification_log()` — Verification log integrity (V1a-V1c).
|
|
60
|
+
Standalone script: `validate_translation.py`.
|
|
61
|
+
|
|
62
|
+
### (7) pACS P1 Validation
|
|
63
|
+
`validate_pacs_output()` validates pACS logs across 6 items:
|
|
64
|
+
- PA1: File existence, PA2: Minimum size (50 bytes), PA3: Dimension scores >= 3 (range 0-100), PA4: Pre-mortem section present, PA5: min() arithmetic accuracy, PA7: RED zone blockage (pACS < 50 triggers FAIL).
|
|
65
|
+
- PA6 (Optional): Score-to-color-zone alignment.
|
|
66
|
+
|
|
67
|
+
Standalone script: `validate_pacs.py`.
|
|
68
|
+
|
|
69
|
+
### (8) L0 Anti-Skip Guard Code Implementation
|
|
70
|
+
`validate_step_output()` — 3 deterministic L0 criteria:
|
|
71
|
+
- L0a: SOT `outputs.step-N` file path exists on disk.
|
|
72
|
+
- L0b: File size >= `MIN_OUTPUT_SIZE` (100 bytes).
|
|
73
|
+
- L0c: Non-whitespace content confirmed.
|
|
74
|
+
|
|
75
|
+
Run pACS + L0 concurrently via `validate_pacs.py --check-l0`.
|
|
76
|
+
|
|
77
|
+
### (9) Predictive Debugging P1 Validation
|
|
78
|
+
`validate_risk_scores()` — Validates `risk-scores.json` across 6 items:
|
|
79
|
+
- RS1: Mandatory keys, RS2: `data_sessions` integer, RS3: `risk_score` range, RS4: `error_count` arithmetic integrity, RS5: `resolution_rate` range, RS6: `top_risk_files` sorted and existent.
|
|
80
|
+
|
|
81
|
+
### (10) Retry Budget P1 Validation
|
|
82
|
+
`validate_retry_budget.py` — Deterministic retry budget evaluation:
|
|
83
|
+
- RB1: Reads counter file, RB2: Detects active ULW mode, RB3: Budget comparison (`retries_used < max_retries`).
|
|
84
|
+
- `max_retries`: 3 when ULW is active, 2 when inactive.
|
|
85
|
+
- Atomic counter increment with `--increment` flag.
|
|
86
|
+
|
|
87
|
+
### (11) Abductive Diagnosis P1 Validation
|
|
88
|
+
`validate_diagnosis_log()` — Validates diagnosis logs across 10 items:
|
|
89
|
+
- AD1: File existence, AD2: Minimum size 100 bytes, AD3: Quality gate field match, AD4: Selected hypothesis present, AD5: Evidence count >= 1, AD6: Action plan present, AD7: No forward references, AD8: Hypotheses count >= 2, AD9: Selected hypothesis consistency, AD10: Prior diagnosis reference on retry > 0.
|
|
90
|
+
|
|
91
|
+
`diagnose_failure_context()` — Pre-evidence collection (retry history, upstream evidence, hypothesis priority, fast-path, raw evidence). Deterministic fast-path shortcuts (FP1-FP3).
|
|
92
|
+
Standalone scripts: `diagnose_context.py` (pre-analysis) and `validate_diagnosis.py` (post-validation).
|
|
93
|
+
|
|
94
|
+
### (12) Cross-Step Traceability P1 Validation
|
|
95
|
+
`validate_cross_step_traceability()` — 5 items:
|
|
96
|
+
- CT1: Trace markers present, CT2: Referenced step deliverables exist, CT3: Section ID resolution (warning), CT4: Minimum density >= 3, CT5: No forward references.
|
|
97
|
+
|
|
98
|
+
Standalone script: `validate_traceability.py`.
|
|
99
|
+
|
|
100
|
+
### (13) Domain Knowledge Structure (DKS) P1 Validation
|
|
101
|
+
`validate_domain_knowledge()` — 7 items:
|
|
102
|
+
- DK1: File existence + valid YAML, DK2: Mandatory metadata keys, DK3: Entities structure, DK4: Referential relation integrity, DK5: Constraints structure, DK6: Deliverable DKS reference resolution, DK7: Constraint non-violation.
|
|
103
|
+
|
|
104
|
+
Standalone script: `validate_domain_knowledge.py`.
|
|
105
|
+
|
|
106
|
+
### (14) Workflow.md DNA Inheritance P1 Validation
|
|
107
|
+
`validate_workflow_md()` — 8 items:
|
|
108
|
+
- W1: File existence, W2: Minimum size 500 bytes, W3: `## Inherited DNA` header, W4: Inherited Patterns table >= 3 rows, W5: Constitutional Principles section, W6: CAP reference, W7: Cross-Step Traceability alignment, W8: DKS validation alignment.
|
|
109
|
+
|
|
110
|
+
Standalone script: `validate_workflow.py`. Invoked after `workflow-generator` completes.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# ULW (Ultrawork) Mode
|
|
2
|
+
|
|
3
|
+
> Detailed specification for Ultrawork (ULW) Mode.
|
|
4
|
+
> Reference when ULW is active.
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
Including `ulw` anywhere in your prompt activates **Ultrawork Mode**. ULW is a **thoroughness intensity overlay orthogonal to Autopilot**.
|
|
9
|
+
|
|
10
|
+
- **Autopilot** = Automation axis (HOW) — skips `(human)` approvals
|
|
11
|
+
- **ULW** = Thoroughness axis (HOW THOROUGHLY) — exhaustive execution, relentless resolution of all errors
|
|
12
|
+
|
|
13
|
+
These two axes are completely independent, enabling any combination:
|
|
14
|
+
|
|
15
|
+
| | **ULW OFF** (Standard) | **ULW ON** (Maximum Rigor) |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| **Autopilot OFF** | Standard interactive | Interactive + Sisyphus Persistence (3 retries) + Mandatory Task Decomposition |
|
|
18
|
+
| **Autopilot ON** | Standard automated workflow | Automated workflow + Sisyphus reinforcement (3 retries) + Team-wide rigor |
|
|
19
|
+
|
|
20
|
+
## 2-Axis Comparison
|
|
21
|
+
|
|
22
|
+
| Axis | Focus | Activation | Deactivation | Scope |
|
|
23
|
+
|---|---|---|---|---|
|
|
24
|
+
| **Autopilot** | Automation (HOW) | SOT `autopilot.enabled: true` | SOT modification | Workflow steps |
|
|
25
|
+
| **ULW** | Thoroughness (HOW THOROUGHLY) | `ulw` keyword in prompt | Implicit (new session without `ulw`) | All tasks (interactive + workflows) |
|
|
26
|
+
|
|
27
|
+
## Activation Patterns
|
|
28
|
+
|
|
29
|
+
| User Command | Behavior |
|
|
30
|
+
|---|---|
|
|
31
|
+
| "ulw do this", "ulw refactor this" | `ulw` detected in transcript regex → ULW mode activated |
|
|
32
|
+
| New session without `ulw` | ULW inactive (implicit deactivation — no explicit toggle needed) |
|
|
33
|
+
|
|
34
|
+
## 3 Intensifier Rules
|
|
35
|
+
|
|
36
|
+
When ULW is active, three intensifier rules are **overlaid onto the current context**:
|
|
37
|
+
|
|
38
|
+
| Intensifier | Description | Interactive Effect | Autopilot Combined Effect |
|
|
39
|
+
|---|---|---|---|
|
|
40
|
+
| **I-1. Sisyphus Persistence** | Up to 3 retries, each using a fundamentally different approach. 100% completion or explicit blocker report. | Try up to 3 alternatives on failure | Quality Gate (Verification/pACS) retry ceiling raised from 10 to 15 |
|
|
41
|
+
| **I-2. Mandatory Task Decomposition** | TaskCreate → TaskUpdate → TaskList mandatory | Enforces task decomposition for all non-trivial tasks | Preserved (Autopilot already tracks via SOT) |
|
|
42
|
+
| **I-3. Bounded Retry Escalation** | No more than 3 consecutive retries on the same target (Quality Gates retain separate budget) — escalate to user when exceeded | Prevents infinite loops | Safety Hook blocks are always strictly respected |
|
|
43
|
+
|
|
44
|
+
## Runtime Enforcement Mechanisms
|
|
45
|
+
|
|
46
|
+
| Layer | Mechanism | Enforcement Details |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| **Hook** (Deterministic) | `_context_lib.py` — `detect_ulw_mode()` | Detects `ulw` via regex over transcript |
|
|
49
|
+
| **Hook** (Deterministic) | `generate_snapshot_md()` — Snapshot | Preserves ULW state in IMMORTAL priority section |
|
|
50
|
+
| **Hook** (Deterministic) | `extract_session_facts()` — Knowledge Archive | Tags `ulw_active: true` → queryable via RLM |
|
|
51
|
+
| **Hook** (Deterministic) | `restore_context.py` — SessionStart | Injects the 3 intensifier rules into context on startup |
|
|
52
|
+
| **Hook** (Deterministic) | `_context_lib.py` — `check_ulw_compliance()` | Deterministically validates compliance → injects warnings into IMMORTAL snapshot |
|
|
53
|
+
| **Hook** (Deterministic) | `generate_context_summary.py` — Stop | ULW Compliance safety net — surfaces stderr warnings on violation |
|
|
54
|
+
|
|
55
|
+
## NEVER DO
|
|
56
|
+
- Never retry more than 3 consecutive times on the same target without alternative hypothesis (I-3 violation; escalate to user).
|
|
57
|
+
- Never override a Safety Hook block (`(hook)` exit code 2) in the name of ULW.
|
|
58
|
+
- Never leave tasks "partially complete" and halt while ULW is active (I-1 violation).
|
|
59
|
+
- Never give up on errors without attempting viable alternative approaches (I-1 violation).
|
|
60
|
+
- Never proceed with non-trivial work implicitly without TaskCreate decomposition (I-2 violation).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Deliverable: Analyze System Architecture and Dependencies
|
|
2
|
+
Synthesized by TypeScript AgentWorker `agent_worker_1` (Role: `researcher`).
|
|
3
|
+
Trace ID: `ts_1788684646384_ej11ei`
|
|
4
|
+
|
|
5
|
+
## Criteria Fulfillments
|
|
6
|
+
- [x] **Analyze architecture patterns**: Addressed with full architectural precision.
|
|
7
|
+
- [x] **Establish baseline**: Addressed with full architectural precision.
|
|
8
|
+
|
|
9
|
+
## Implementation Details
|
|
10
|
+
Engineered to satisfy L0 physical existence, L1 functional criteria, and L1.5 pACS confidence.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Solution Learning: Autonomous Autopilot Engine & Multi-Agent Architecture
|
|
2
|
+
|
|
3
|
+
## Problem Overview
|
|
4
|
+
Building an end-to-end autonomous agentic workflow requires:
|
|
5
|
+
1. Self-governed multi-agent orchestration with role-specific tool authorization.
|
|
6
|
+
2. Self-fueling context and energy management that prevents context exhaustion and handles automated refueling (RLM compaction).
|
|
7
|
+
3. 4-layer verification gates (L0 Anti-Skip, L1 Verification, L1.5 pACS, L2 Review) to guarantee delivery quality without human intervention.
|
|
8
|
+
4. Clean code compliance (24 Clean Code imperatives) and AI evaluation gates (fairness auditing, drift monitoring, injection sanitization).
|
|
9
|
+
|
|
10
|
+
## Architectural Implementation
|
|
11
|
+
|
|
12
|
+
### 1. Multi-Agent System (`core/multi_agent_system.py`)
|
|
13
|
+
- **Topology**: Hierarchical coordination led by Orchestrator delegating to specialized roles (`researcher`, `architect`, `engineer`, `critic`, `fact_checker`).
|
|
14
|
+
- **Least-Privilege Tool Authorization**: Matrix-backed permissions restricting dangerous tools to designated roles.
|
|
15
|
+
- **Circuit Breakers**: States (`CLOSED`, `OPEN`, `HALF_OPEN`) tracking failure streaks. If `failure_streak >= 2`, circuit opens to prevent runaway speculative execution.
|
|
16
|
+
- **Observable Traces**: Structured `.traces/trace_*.jsonl` span logs capturing step transitions, durations, and actor roles.
|
|
17
|
+
|
|
18
|
+
### 2. Autonomous Autopilot Engine (`core/autopilot_engine.py`)
|
|
19
|
+
- **Self-Fueling Energy Budget**: Tracks token consumption against a 150,000 ceiling. When remaining energy falls below 20%, an automated RLM compaction refueling event triggers to refresh execution context.
|
|
20
|
+
- **SOT State Management**: Single Source of Truth (`state.yaml`) with single-write-point exclusivity and JSON fallback resilience.
|
|
21
|
+
- **4-Layer QA Gates**:
|
|
22
|
+
- **L0 Anti-Skip**: Physical file existence and >= 100 bytes minimum payload verification.
|
|
23
|
+
- **L1 Verification**: Criteria completeness check.
|
|
24
|
+
- **L1.5 pACS**: 3D self-calibration scoring (Faithfulness, Completeness, Logic) enforcing $\ge 70$.
|
|
25
|
+
- **L2 Review**: Independent critic evaluation.
|
|
26
|
+
- **Decision Audits**: Automatically recorded into `autopilot-logs/`.
|
|
27
|
+
|
|
28
|
+
### 3. Clean Code Guard (`core/clean_code_guard.py`)
|
|
29
|
+
- AST-based static analysis enforcing function size limits (<= 35 lines), parameter ceilings (<= 4 args), intent-revealing identifier conventions, exception discipline (no bare or swallowed exceptions), and genuine implementation verification (no hardcoded fake return values).
|
|
30
|
+
|
|
31
|
+
### 4. AI Engineering Evaluator (`core/ai_evaluator.py`)
|
|
32
|
+
- **Prompt Injection Boundary Sanitization**: Regex boundary filtering against adversarial jailbreaks.
|
|
33
|
+
- **Fairness & Disparate Impact**: EEOC four-fifths rule validation ($D_I \ge 0.80$).
|
|
34
|
+
- **PSI Drift Estimation**: Population Stability Index monitoring distribution shifts.
|
|
35
|
+
|
|
36
|
+
## Prevention & Operational Guidelines
|
|
37
|
+
- **Always clean test artifacts**: Ensure temporary directories (`.traces`, `autopilot-logs`, `pacs-logs`, `review-logs`, `diagnosis-logs`) are cleaned before commits and excluded in `.gitignore`.
|
|
38
|
+
- **Enforce 0 Hangul**: Run automated regex sweeps to maintain 100% English purity across all code, documentation, and prompt assets.
|