@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.
Files changed (118) hide show
  1. package/.claude-plugin/plugin.json +10 -0
  2. package/.codex-plugin/plugin.json +13 -0
  3. package/.skills.json +19 -0
  4. package/AGENTS.md +1344 -0
  5. package/CLAUDE.md +178 -0
  6. package/GEMINI.md +102 -0
  7. package/LICENSE +21 -0
  8. package/README.md +350 -0
  9. package/SKILL.md +132 -0
  10. package/bin/agentic-hooks.sh +79 -0
  11. package/bin/cli.js +1060 -0
  12. package/core/__init__.py +52 -0
  13. package/core/ai_evaluator.py +117 -0
  14. package/core/autopilot_engine.py +368 -0
  15. package/core/clean_code_guard.py +188 -0
  16. package/core/engine_py/__init__.py +29 -0
  17. package/core/engine_py/agent_worker.py +136 -0
  18. package/core/engine_py/decider.py +150 -0
  19. package/core/engine_py/energy.py +45 -0
  20. package/core/engine_py/event_bus.py +63 -0
  21. package/core/engine_py/executor.py +186 -0
  22. package/core/engine_py/models.py +193 -0
  23. package/core/engine_py/queue.py +314 -0
  24. package/core/engine_py/runner.py +116 -0
  25. package/core/engine_py/system_workers.py +70 -0
  26. package/core/engine_py/toon_adapter.py +586 -0
  27. package/core/engine_py/verification_controller.py +208 -0
  28. package/core/engine_py/worker.py +167 -0
  29. package/core/engine_spec/event_schema.json +65 -0
  30. package/core/engine_spec/example_workflow.yaml +73 -0
  31. package/core/engine_spec/workflow_schema.json +127 -0
  32. package/core/hooks/__init__.py +29 -0
  33. package/core/hooks/adapters/__init__.py +25 -0
  34. package/core/hooks/adapters/claude_adapter.py +83 -0
  35. package/core/hooks/adapters/cli_agent_adapter.py +82 -0
  36. package/core/hooks/adapters/codex_adapter.py +78 -0
  37. package/core/hooks/adapters/cursor_adapter.py +73 -0
  38. package/core/hooks/adapters/gemini_adapter.py +93 -0
  39. package/core/hooks/adapters/homebrew_adapter.py +69 -0
  40. package/core/hooks/adapters/mcp_proxy.py +133 -0
  41. package/core/hooks/adapters/shell_adapter.py +65 -0
  42. package/core/hooks/dispatcher.py +118 -0
  43. package/core/hooks/policy_engine.py +375 -0
  44. package/core/hooks/session_end.py +141 -0
  45. package/core/hooks/types.py +147 -0
  46. package/core/integrations/__init__.py +28 -0
  47. package/core/integrations/installer.py +225 -0
  48. package/core/integrations/lifecycle_director.py +175 -0
  49. package/core/integrations/registry.py +105 -0
  50. package/core/multi_agent_system.py +164 -0
  51. package/core/skills_indexer.py +742 -0
  52. package/core/system/__init__.py +25 -0
  53. package/core/system/announcements.py +72 -0
  54. package/core/system/dependencies.py +69 -0
  55. package/core/system/doctor.py +171 -0
  56. package/core/system/health.py +144 -0
  57. package/core/system/installer.py +137 -0
  58. package/core/system/notifications.py +97 -0
  59. package/core/system/refresher.py +110 -0
  60. package/core/system/updater.py +167 -0
  61. package/core/system/version_tracker.py +65 -0
  62. package/docs/architecture_plan.md +7 -0
  63. package/docs/guides/failure-recovery.md +714 -0
  64. package/docs/implementation_summary.md +10 -0
  65. package/docs/protocols/autopilot-execution.md +148 -0
  66. package/docs/protocols/code-change-protocol.md +49 -0
  67. package/docs/protocols/context-preservation-detail.md +114 -0
  68. package/docs/protocols/quality-gates.md +110 -0
  69. package/docs/protocols/ulw-mode.md +60 -0
  70. package/docs/research_findings.md +10 -0
  71. package/docs/solutions/autonomous-autopilot-engine-architecture.md +38 -0
  72. package/install.sh +111 -0
  73. package/marketplace.json +37 -0
  74. package/package.json +81 -0
  75. package/skills/agentic-workflow/SKILL.md +132 -0
  76. package/skills/agentic-workflow/skill-spec.json +100 -0
  77. package/soul.md +445 -0
  78. package/src/engine_ts/decider.ts +186 -0
  79. package/src/engine_ts/event-bus.ts +57 -0
  80. package/src/engine_ts/executor.ts +262 -0
  81. package/src/engine_ts/index.ts +12 -0
  82. package/src/engine_ts/queue.ts +93 -0
  83. package/src/engine_ts/runner.ts +108 -0
  84. package/src/engine_ts/skills-indexer.ts +264 -0
  85. package/src/engine_ts/toon-adapter.ts +91 -0
  86. package/src/engine_ts/types.ts +134 -0
  87. package/src/engine_ts/verification-controller.ts +204 -0
  88. package/src/engine_ts/worker.ts +280 -0
  89. package/src/hooks/adapters/claude-adapter.ts +54 -0
  90. package/src/hooks/adapters/cli-agent-adapter.ts +46 -0
  91. package/src/hooks/adapters/codex-adapter.ts +69 -0
  92. package/src/hooks/adapters/cursor-adapter.ts +60 -0
  93. package/src/hooks/adapters/gemini-adapter.ts +71 -0
  94. package/src/hooks/adapters/homebrew-adapter.ts +36 -0
  95. package/src/hooks/adapters/mcp-proxy.ts +66 -0
  96. package/src/hooks/adapters/shell-adapter.ts +42 -0
  97. package/src/hooks/dispatcher.ts +113 -0
  98. package/src/hooks/index.ts +16 -0
  99. package/src/hooks/policy-engine.ts +376 -0
  100. package/src/hooks/session-end.ts +125 -0
  101. package/src/hooks/types.ts +61 -0
  102. package/src/index.d.ts +34 -0
  103. package/src/index.ts +23 -0
  104. package/src/integrations/index.ts +7 -0
  105. package/src/integrations/installer.ts +208 -0
  106. package/src/integrations/lifecycle-director.ts +139 -0
  107. package/src/integrations/registry.ts +82 -0
  108. package/src/system/announcements.ts +143 -0
  109. package/src/system/dependencies.ts +176 -0
  110. package/src/system/doctor.ts +374 -0
  111. package/src/system/health.ts +270 -0
  112. package/src/system/index.ts +14 -0
  113. package/src/system/installer.ts +262 -0
  114. package/src/system/notifications.ts +180 -0
  115. package/src/system/refresher.ts +207 -0
  116. package/src/system/types.ts +268 -0
  117. package/src/system/updater.ts +219 -0
  118. package/src/system/version-tracker.ts +137 -0
package/AGENTS.md ADDED
@@ -0,0 +1,1344 @@
1
+ # AgenticWorkflow — Common Directive for AI Agents
2
+
3
+ > This file defines the rules that **all AI agents working on this project must follow, regardless of model or tool**.
4
+ > Whether you use Claude Code, Cursor, Copilot, Codex, or any other tool, the rules in this document apply.
5
+
6
+ ---
7
+
8
+ ## 1. Project Definition
9
+
10
+ An agent-based workflow automation project. Its purpose is to systematically design complex tasks as workflows and actually implement those workflows so that they run.
11
+
12
+ ### Final Goal — A 2-Stage Process
13
+
14
+ | Stage | Deliverable | Nature |
15
+ |-------|-------------|--------|
16
+ | **Phase 1: Workflow Design** | `workflow.md` | Intermediate deliverable (blueprint) |
17
+ | **Phase 2: Workflow Implementation** | A system where agents, scripts, and automation actually run | **Final deliverable** |
18
+
19
+ > Creating `workflow.md` is only half the journey. **The final goal is that the content described in it actually runs.**
20
+
21
+ ### Reason for Existence — DNA Inheritance
22
+
23
+ AgenticWorkflow is a **parent organism that gives birth to child agentic workflow systems**. Whatever domain the child belongs to, it structurally embeds the entire parent genome.
24
+
25
+ | Genome Component | Form Embedded in Child |
26
+ |------------------|-----------------------|
27
+ | 3 Absolute Criteria | `Inherited DNA` section of workflow.md — contextualized per domain |
28
+ | SOT pattern | `state.yaml` — single file + single write point |
29
+ | 3-stage structure | Structural constraint: Research → Planning → Implementation |
30
+ | 4-layer verification | L0 Anti-Skip → L1 Verification → L1.5 pACS → L2 Review |
31
+ | P1 containment | Python deterministic validation scripts |
32
+ | Safety Hook | Dangerous command blocking + TDD Guard |
33
+ | Adversarial Review | `@reviewer` + `@fact-checker` Generator-Critic pattern |
34
+ | Decision Log | Recording the rationale for auto-approval decisions |
35
+ | Context Preservation | Cross-session memory preservation + Knowledge Archive + RLM pattern |
36
+ | TOON Protocol | Token-Oriented Object Notation (v4.1) — 30-60% token reduction across all agent dialogues & deliverables |
37
+
38
+ > Inheritance is not optional — it is **structural**. The child does not "reference" the parent's DNA, it **embeds** it. Details: `soul.md §0`.
39
+
40
+ > **12→9 Mapping**: Of the 12 components in soul.md §0, the 9 above are structurally embedded in the child as `inherited_dna`. The remaining 3 — Design Principles P1-P4 (included in the Absolute Criteria), Sisyphus/Error→Resolution (behavioral pattern, not a structure), and RLM theory (theoretical foundation, not a structure) — are implicitly reflected in the child as internal mechanisms of the parent organism, but are not separated as distinct `inherited_dna` items. soul.md itself is a meta-document (the definition of inheritance), so it is not an inheritance target.
41
+
42
+ ### Basic Workflow Structure
43
+
44
+ Every workflow consists of three stages:
45
+
46
+ 1. **Research** — Information gathering and analysis
47
+ 2. **Planning** — Plan formulation, structuring, human review/approval
48
+ 3. **Implementation** — Actual execution and deliverable generation
49
+
50
+ Each stage specifies:
51
+ - The task performed (Task)
52
+ - The responsible agent
53
+ - Data pre-processing / post-processing
54
+ - Deliverable (Output)
55
+ - Human intervention point (if applicable)
56
+
57
+ ---
58
+
59
+ ## 2. Absolute Criteria
60
+
61
+ > **These are the top-level rules applied to every design, implementation, and modification decision in this project.**
62
+ > They sit above all principles, guidelines, and conventions below.
63
+ > Whatever principle it is, if it conflicts with an Absolute Criterion, the Absolute Criterion wins.
64
+
65
+ ### Absolute Criterion 1: Quality of the Final Deliverable
66
+
67
+ > **Speed, token cost, workload, and length limits are completely ignored.**
68
+ > The only criterion for every decision is the **quality of the final deliverable**.
69
+ > Rather than making things fast by reducing steps, we choose the direction that raises quality even if that means adding steps.
70
+
71
+ Applied examples:
72
+ - If quality rises with more workflow stages → add stages
73
+ - If using more agents raises quality → add agents
74
+ - If repeated verification stages improve the deliverable → allow repetition
75
+
76
+ ### Absolute Criterion 2: Single-File SOT + Hierarchical Memory Structure
77
+
78
+ > **Under the design of a single-file SOT (Single Source of Truth) + hierarchical memory structure, no data inconsistency occurs even when dozens of agents operate simultaneously.**
79
+
80
+ Design rules:
81
+ - **State concentration**: All shared state of a workflow is concentrated in a **single file** (e.g., `state.json`, `state.yaml`). Do not scatter state across multiple files.
82
+ - **Single write point**: Only the Orchestrator (or one designated agent) has write permission to the SOT file. Other agents access it read-only and produce their results as separate output files.
83
+ - **Conflict prevention**: Do not design structures in which multiple agents modify the same file simultaneously.
84
+
85
+ ```
86
+ Bad: Agent A → directly modifies state.json
87
+ Agent B → directly modifies state.json → data conflict
88
+
89
+ Good: Agent A → produces output-a.md → reports to Orchestrator
90
+ Agent B → produces output-b.md → reports to Orchestrator
91
+ Orchestrator → merges into state.json → single write point
92
+ ```
93
+
94
+ ### Absolute Criterion 3: Code Change Protocol (CCP)
95
+
96
+ > **Before writing, modifying, adding, or deleting code, you must internally perform the 3 steps below.**
97
+ > Skipping this protocol is a violation of the Absolute Criteria.
98
+
99
+ If Absolute Criterion 1 (Quality) defines "what we optimize for," and Absolute Criterion 2 (SOT) defines "how we structure data," then Absolute Criterion 3 defines **"how we behave when changing code."** High-quality code emerges from a rigorous process that analyzes dependencies, coupling, and ripple effects of changes in advance.
100
+
101
+ #### Coding Anchor Points (CAP-1~4)
102
+
103
+ If CCP defines "what to perform" (procedure), then CAP defines **"what attitude to perform with"** (mindset). Every step of CCP is performed while internalizing the 4 anchor points below.
104
+
105
+ - **CAP-1: Think Before Coding** — Do not assume. Do not modify code before reading it; surface trade-offs when they exist; ask when unclear.
106
+ - **CAP-2: Simplicity First** — Write only the minimum code needed to satisfy the current requirement. Do not create speculative features, premature abstractions, or unnecessary helpers.
107
+ - **CAP-3: Goal-Based Execution** — Define success criteria before implementation, and verify after (e.g., tests, manual checks).
108
+ - **CAP-4: Surgical Changes** — Perform only the requested change. Do not "improve" unrelated code, and do not add comments, types, or documentation to code you did not touch.
109
+
110
+ > CAP is a subordinate set of attitude norms under CCP, so when it conflicts with Absolute Criterion 1 (Quality), quality wins. Example: when CAP-2 (Simplicity) undermines quality — complexity required for quality is allowed.
111
+
112
+ **Step 1 — Understand Intent:**
113
+ - Have you accurately understood the implementation the user requested? You should be able to explain it clearly in 1-2 sentences.
114
+ - Have you accurately understood the purpose of the change (bug fix, refactoring, performance, feature addition, etc.) and the constraints (compatibility preservation, tech stack, etc.)?
115
+
116
+ **Step 2 — Ripple Effect Analysis:**
117
+
118
+ Investigate the impact that writing new code or modifying existing code has on the entire codebase:
119
+ - **Direct dependencies**: Functions / classes / modules / files where the target is defined
120
+ - **Call relationships**: Other code that calls this code, or that this code calls
121
+ - **Structural relationships**: Inheritance / implementation (inheritance, interface), composition, association / reference
122
+ - **Data model / schema**: Types / fields / validation logic that must change together
123
+ - **Test code**: Unit tests, integration tests, snapshot tests, etc.
124
+ - **Configuration / environment / build**: config, DI settings, routing, dependency injection, etc.
125
+ - **Documentation / comments / API specs**: comments, README, API documents, type definitions, etc.
126
+
127
+ Investigate at an expert level: "Since we're changing here, how far can this change ripple?" If there are highly coupled areas (tight coupling, change coupling, possibility of shotgun surgery), you **must** flag them in advance and discuss with the user.
128
+
129
+ **Step 3 — Change Plan:**
130
+ - Before updating the actual related code, propose a step-by-step change plan:
131
+ - Step 1: Which file / class / function to modify first
132
+ - Step 2: What changes to propagate to downstream dependencies / callers
133
+ - Step 3: How to align tests / docs / configuration
134
+ - If you see a refactoring opportunity toward a better structure from the perspective of reducing coupling / increasing cohesion, propose it along with the plan (execute only after user approval).
135
+
136
+ **Proportionality Rule — Always perform the protocol, but scale analysis depth to the scope of the change:**
137
+
138
+ | Scope | Criterion | Depth Applied |
139
+ |-------|-----------|---------------|
140
+ | **Minor** | Typos, comments, formatting, logic-irrelevant changes | Step 1 only — confirm "no ripple effect" in one sentence and execute immediately |
141
+ | **Standard** | Function / logic changes, file addition / deletion | Full 3 steps |
142
+ | **Large-scale** | Architecture, public API, cross-cutting changes | Full 3 steps + **mandatory** prior user approval |
143
+
144
+ Applied examples:
145
+
146
+ ```
147
+ Bad: "User requests function modification → only modifies that function → 6 callers hit runtime errors"
148
+ Good: "User requests function modification → checks 6 call sites → reports impact scope → proposes step-by-step change plan → executes after approval"
149
+ ```
150
+
151
+ **Communication Rules:**
152
+ - Avoid unnecessarily verbose theoretical explanations; focus on actual code and concrete steps.
153
+ - Add brief reasons for important design choices.
154
+ - Even when parts are ambiguous, do not avoid the work — state "reasonable assumptions" explicitly and propose the best design.
155
+
156
+ ### Priority Among Absolute Criteria
157
+
158
+ > **Absolute Criterion 1 (Quality) is the highest. Absolute Criterion 2 (SOT) and Absolute Criterion 3 (CCP) are co-equal means to guarantee quality.**
159
+
160
+ ```
161
+ Absolute Criterion 1 (Quality) — Highest. The reason every criterion exists.
162
+ ├── Absolute Criterion 2 (SOT) — Means of guaranteeing data integrity
163
+ └── Absolute Criterion 3 (CCP) — Means of guaranteeing code-change quality
164
+ ```
165
+
166
+ Absolute Criteria 2 (SOT) and 3 (CCP) operate on different dimensions, so direct conflict between them is unlikely. Whichever criterion it is, when it conflicts with Absolute Criterion 1 (Quality), quality wins. Both SOT and CCP are **means** of guaranteeing quality, not **ends** that constrain quality.
167
+
168
+ Conflict scenarios and resolutions:
169
+ - The SOT single write point causes an information bottleneck and agents work with stale data → **allow direct reference between agents' outputs** (adjust the SOT structure)
170
+ - State complexity of the SOT grows due to added stages for quality improvement → **accept it** (Absolute Criterion 1 > 2)
171
+ - SOT is unnecessary for fully independent parallel work (no shared state between agents) → **allow lightweight SOT** (document the rationale)
172
+ - Full CCP analysis is excessive overhead for trivial changes → **apply the Proportionality Rule** (Step 1 only for minor changes)
173
+
174
+ ---
175
+
176
+ ## 3. Design Principles
177
+
178
+ These are subordinate principles under the Absolute Criteria.
179
+
180
+ ### P1. Data Refinement for Accuracy
181
+
182
+ Passing large data directly to AI drops accuracy through noise.
183
+
184
+ - Specify **pre-processing** at each stage: remove noise before handing off to the agent
185
+ - Specify **post-processing** at each stage: refine the deliverable before passing to the next stage
186
+ - Relationships computable in code are pre-processed → the AI focuses on judgment and analysis
187
+
188
+ ```
189
+ Bad: "Pass the entire collected HTML of the web page to the agent"
190
+ Good: "Extract only the body text via a Python script → pass only the essential text to the agent"
191
+ ```
192
+
193
+ ### P2. Expertise-Based Delegation Structure
194
+
195
+ Maximize quality by delegating each task to the specialized agent that can best perform it. The Orchestrator coordinates overall quality, while specialized agents focus deeply on their respective domains.
196
+
197
+ ```
198
+ Orchestrator (quality coordination + flow management)
199
+ ├→ Agent A: Specialized research (optimized for the domain)
200
+ ├→ Agent B: In-depth analysis (focused only on analysis)
201
+ └→ Agent C: Verification and quality gate
202
+ ```
203
+
204
+ #### Orchestrator Role Definition
205
+
206
+ **Orchestrator = main Claude session**. It is not a separate agent file; the main session executing the workflow plays the Orchestrator role. In `(team)` stages, **the Orchestrator also serves as the Team Lead**.
207
+
208
+ | Role | Actor | SOT Write | Start Time |
209
+ |------|-------|-----------|------------|
210
+ | Orchestrator | Main Claude session | **Writable** (sole) | At workflow start |
211
+ | Team Lead | Orchestrator (same entity) | **Writable** | On entering a `(team)` stage |
212
+ | Sub-agent | Created via the `Task` tool | **Read-only** | When Orchestrator invokes |
213
+ | Teammate | Created via `Task` + `TeamCreate` | **Read-only** | When Team Lead assigns |
214
+
215
+ #### Sub-agent Invocation Protocol
216
+
217
+ Standard protocol for the Orchestrator to invoke a Sub-agent (`@translator`, `@reviewer`, `@fact-checker`):
218
+
219
+ **1. How to invoke**: specify the agent name via the `subagent_type` parameter of the `Task` tool
220
+ ```
221
+ Task(subagent_type="translator", prompt="...", ...)
222
+ ```
223
+
224
+ **2. Context that must be included in the prompt**:
225
+ - Workflow step number (step N)
226
+ - Input deliverable file paths (absolute paths)
227
+ - Verification criteria for that step (if any)
228
+ - SOT `outputs.step-N` path (where to save the deliverable)
229
+ - Reference file paths (glossary.yaml, previous step deliverables, etc.)
230
+
231
+ **3. Receiving results**: when the Sub-agent exits, the `Task` tool returns the result.
232
+ - The Orchestrator checks that the deliverable file was created on disk
233
+ - Runs the P1 validation scripts (validate_review.py, validate_translation.py, etc.)
234
+ - Records the path in SOT `outputs.step-N` (performed by the Orchestrator)
235
+
236
+ **4. `(team)` stage Task Lifecycle**:
237
+ ```
238
+ Team Lead (= Orchestrator)
239
+ 1. TeamCreate → records SOT active_team
240
+ 2. TaskCreate (subject, description, owner=@teammate)
241
+ 3. Task(subagent_type, team_name, ...) → creates Teammate
242
+ 4. Teammate: performs work → L1 self-verification → L1.5 pACS self-scoring
243
+ 5. Teammate: SendMessage (report + pACS score) → TaskUpdate (completed)
244
+ 6. Team Lead: receives report → L2 comprehensive verification → updates SOT
245
+ 7. TeamDelete → SOT active_team → moves to completed_teams
246
+ ```
247
+
248
+ **Dense Checkpoint Pattern (DCP)**: Insert intermediate checkpoints (CP-1/2/3) into Tasks with turn count > 10. Details: `references/claude-code-patterns.md §DCP`
249
+
250
+ ### P3. Resource Accuracy
251
+
252
+ For stages that require images, files, or external resources, specify exact paths. Placeholders may not be omitted.
253
+
254
+ ### P4. Question Design Rules
255
+
256
+ When asking the user questions:
257
+ - At most 4 questions
258
+ - Each question offers roughly 3 options
259
+ - If there is no ambiguity, proceed without questions
260
+
261
+ ---
262
+
263
+ ## 4. Project Structure
264
+
265
+ ```
266
+ AgenticWorkflow/
267
+ ├── CLAUDE.md ← Claude Code-specific directive
268
+ ├── AGENTS.md ← This file (model-agnostic common directive)
269
+ ├── README.md ← Project introduction
270
+ ├── AGENTICWORKFLOW-USER-MANUAL.md ← User manual
271
+ ├── AGENTICWORKFLOW-ARCHITECTURE-AND-PHILOSOPHY.md ← Design philosophy and architecture overview
272
+ ├── DECISION-LOG.md ← Project design decision log (ADR)
273
+ ├── COPYRIGHT.md ← Copyright
274
+ ├── .claude/
275
+ │ ├── settings.json ← Hook settings (Setup + SessionEnd)
276
+ │ ├── agents/ ← Sub-agent definitions
277
+ │ │ ├── translator.md (English→Korean translation specialist — glossary-based terminology consistency)
278
+ │ │ ├── reviewer.md (Adversarial Review — critical analysis of code/deliverables, read-only)
279
+ │ │ └── fact-checker.md (Adversarial Review — external fact verification, web access)
280
+ │ ├── commands/ ← Slash Commands
281
+ │ │ ├── install.md (Setup Init validation result analysis — /install)
282
+ │ │ └── maintenance.md (Setup Maintenance health check — /maintenance)
283
+ │ ├── hooks/scripts/ ← Context Preservation System + Setup Hooks + Safety Hooks
284
+ │ │ ├── context_guard.py (Hook unified dispatcher — single entry point for 4 events)
285
+ │ │ ├── _context_lib.py (shared library — parsing, generation, SOT capture, Smart Throttling, Autopilot state reading/validation, ULW detection/compliance verification, centralization of truncation constants, sot_paths() path unification, multi-stage transition detection, decision-quality tag ordering, Error Taxonomy 12 patterns + Resolution matching, Success Patterns (extracting successful Edit/Write→Bash sequences), IMMORTAL-aware compression + audit trail, E5 Guard centralization (is_rich_snapshot + update_latest_with_guard), Knowledge Archive integration (archive_and_index_session — partial failure isolation), path tag extraction (extract_path_tags), KI schema validation (_validate_session_facts — ensuring RLM-required keys), SOT schema validation (validate_sot_schema — structural integrity of workflow state.yaml verified across 8 items: S1-S6 basic + S7 pacs 5 fields (dimensions, current_step_score, weak_dimension, history, pre_mortem_flag) + S8 active_team 5 fields (name, status (partial|all_completed), tasks_completed, tasks_pending, completed_summaries)), Adversarial Review P1 validation (validate_review_output R1-R5, parse_review_verdict, calculate_pacs_delta, validate_review_sequence), Translation P1 validation (validate_translation_output T1-T7, check_glossary_freshness T8, verify_pacs_arithmetic T9 generic, validate_verification_log V1a-V1c), Predictive Debugging P1 (aggregate_risk_scores + validate_risk_scores RS1-RS6 + _RISK_WEIGHTS 13 weights + _RECENCY_DECAY_DAYS decay), pACS P1 validation (validate_pacs_output PA1-PA6 — structural integrity of pACS log: file existence, minimum size, dimension scores, Pre-mortem, min() arithmetic, Color Zone), L0 Anti-Skip Guard (validate_step_output L0a-L0c — deliverable file existence + minimum size + non-empty), Team Summaries KI archive (_extract_team_summaries — SOT active_team.completed_summaries → preserved in KI), Abductive Diagnosis Layer (diagnose_failure_context pre-evidence collection + validate_diagnosis_log AD1-AD10 post-validation + _extract_diagnosis_patterns KA archiving + Fast-Path FP1-FP3 + hypothesis priority H1/H2/H3), module-level regex compilation (9+8+8+4+5 patterns — once per process))
286
+ │ │ ├── save_context.py (save engine)
287
+ │ │ ├── restore_context.py (restore — RLM pointer + completion/Git state + Predictive Debugging risk score cache generation)
288
+ │ │ ├── update_work_log.py (work log accumulation — tracking 9 tools)
289
+ │ │ ├── generate_context_summary.py (incremental snapshot + Knowledge Archive + E5 Guard + Autopilot Decision Log safety net + ULW Compliance safety net)
290
+ │ │ ├── setup_init.py (Setup Init — infrastructure health verification + SOT write pattern validation (P1 hallucination containment), --init trigger)
291
+ │ │ ├── setup_maintenance.py (Setup Maintenance — periodic health check, --maintenance trigger)
292
+ │ │ ├── block_destructive_commands.py (PreToolUse Safety Hook — blocks dangerous commands (P1 hallucination containment), blocks with exit code 2 + Claude self-correction)
293
+ │ │ ├── block_test_file_edit.py (PreToolUse TDD Guard — blocks test file modification (.tdd-guard toggle), blocks with exit code 2 + directs to implementation code modification)
294
+ │ │ ├── predictive_debug_guard.py (PreToolUse Predictive Debug — warns about risky files based on error history, exit code 0 warning only)
295
+ │ │ ├── output_secret_filter.py (PostToolUse secret detection — 3-tier extraction (tool_response→file read→transcript), 25+ regex patterns, 2-pass scanning (raw + base64/URL), fcntl-locked audit log, exit code 0 warning only)
296
+ │ │ ├── security_sensitive_file_guard.py (PostToolUse security-sensitive file warning — .env/PEM/credentials/cloud/K8s/terraform, etc. 12 patterns, session dedup, exit code 0 warning only)
297
+ │ │ ├── diagnose_context.py (Abductive Diagnosis pre-evidence collection — generates an evidence bundle on quality gate FAIL, manually invoked by the Orchestrator)
298
+ │ │ ├── query_workflow.py (workflow observability — 4 modes: dashboard/weakest/retry/blocked, P1 SOT schema validation + context-aware pACS extraction)
299
+ │ │ ├── validate_pacs.py (pACS P1 validation + L0 Anti-Skip Guard — PA1-PA7, standalone script, JSON output)
300
+ │ │ ├── validate_review.py (Adversarial Review P1 validation — R1-R5, standalone script, JSON output)
301
+ │ │ ├── validate_translation.py (Translation P1 validation — T1-T9 + glossary validation, JSON output)
302
+ │ │ ├── validate_verification.py (Verification Log P1 validation — V1a-V1c structural integrity, JSON output)
303
+ │ │ ├── validate_diagnosis.py (Abductive Diagnosis P1 post-validation — AD1-AD10, JSON output)
304
+ │ │ ├── validate_traceability.py (Cross-Step Traceability P1 validation — CT1-CT5, JSON output)
305
+ │ │ ├── validate_domain_knowledge.py (Domain Knowledge P1 validation — DK1-DK7, JSON output)
306
+ │ │ ├── validate_workflow.py (DNA inheritance P1 validation — W1-W8, JSON output)
307
+ │ │ ├── validate_retry_budget.py (Retry Budget P1 validation — RB1-RB3 retry budget decision (ULW-aware), JSON output)
308
+ │ │ ├── _test_secret_filter.py (output_secret_filter tests — 44 cases)
309
+ │ │ ├── _test_sensitive_file_guard.py (security_sensitive_file_guard tests — 44 cases)
310
+ │ │ └── _test_block_destructive.py (block_destructive_commands tests — 43 cases)
311
+ │ ├── context-snapshots/ ← runtime snapshots (gitignored)
312
+ │ └── skills/
313
+ │ ├── workflow-generator/ ← workflow design and generation
314
+ │ │ ├── SKILL.md (skill definition + Absolute Criteria)
315
+ │ │ └── references/ (implementation patterns, templates, document analysis guide)
316
+ │ └── doctoral-writing/ ← doctoral-level academic writing
317
+ │ ├── SKILL.md (skill definition + Absolute Criteria)
318
+ │ └── references/ (checklists, common errors, revision examples, discipline-specific guides)
319
+ ├── prompt/ ← prompt materials
320
+ │ ├── crystalize-prompt.md (prompt compression techniques)
321
+ │ ├── distill-partner.md (essence extraction and optimization)
322
+ │ └── crawling-skill-sample.md (crawling skill sample)
323
+ └── coding-resource/ ← reference materials
324
+ ```
325
+
326
+ ### Context Preservation System
327
+
328
+ An automatic save/restore system that prevents the loss of work context when the context window is exhausted, the session is reset, or the context is compacted.
329
+
330
+ **Core principles:**
331
+ - RLM pattern applied: work history is persisted as an **external memory object** (MD file), and restored in a new session via pointers
332
+ - P1 principle followed: transcript parsing and statistics are performed deterministically by Python code. The AI focuses only on semantic interpretation
333
+ - Absolute Criterion 2 followed: the SOT file (`state.yaml`) is accessed **read-only**. Snapshots are stored in a separate directory (`context-snapshots/`)
334
+ - **Knowledge Archive**: Cross-session knowledge accumulation — session facts are deterministically extracted and accumulated in `knowledge-index.jsonl`. Recorded by both the Stop hook and SessionEnd/PreCompact, guaranteeing 100% indexing of the session. Each entry includes completion_summary (tool success/failure), git_summary (change status), session_duration_entries (session length), phase (session phase), phase_flow (multi-stage transition flow), primary_language (primary file extension), error_patterns (Error Taxonomy 12-pattern classification + resolution matching), tool_sequence (RLE-compressed tool sequence), final_status (success/incomplete/error/unknown), tags (path-based search tags — CamelCase/snake_case split + extension mapping). AI searches programmatically with Grep (RLM pattern)
335
+ - **Resume Protocol**: Snapshot includes deterministic restoration instructions — list of modified/referenced files, session metadata, completion state (tool success/failure), Git change state. **Dynamic RLM query hints**: Based on tags extracted from the modified file paths (`extract_path_tags()`) and error information, session-specific tailored Grep query examples are auto-generated. Guarantees a floor level for restoration quality
336
+ - **Autopilot runtime reinforcement**: When Autopilot is active, the snapshot includes an Autopilot state section (IMMORTAL priority), and on session restoration execution rules are injected into context. The Stop hook detects and compensates for missing Decision Logs
337
+ - **ULW mode detection / preservation**: `detect_ulw_mode()` detects the `ulw` keyword in the transcript using word-boundary regex. When active, the snapshot includes a ULW state section (IMMORTAL priority), and SessionStart injects the 3 reinforcement rules (Intensifiers) into context. `check_ulw_compliance()` deterministically verifies compliance. Tagged as `ulw_active: true` in the Knowledge Archive
338
+ - **Decision-quality tag ordering**: The "key design decisions" section of the snapshot is ordered `[explicit]` > `[decision]` > `[rationale]` > `[intent]`, so that high-signal decisions are placed first in the 15 slots. Comparison / trade-off / selection patterns are also extracted
339
+ - **IMMORTAL-aware compression**: When the snapshot exceeds size, IMMORTAL sections are preserved with priority and non-IMMORTAL content is truncated first. In extreme cases, the beginning of IMMORTAL text is still preserved. **Compression audit trail**: The number of characters removed in each compression Phase is recorded at the end of the snapshot as an HTML comment (`<!-- compression-audit: ... -->`) (per-Phase deltas for Phases 1~7 + final size)
340
+ - **Error Taxonomy**: Tool errors are classified into 12 patterns (file_not_found, permission, syntax, timeout, dependency, edit_mismatch, type_error, value_error, connection, memory, git_error, command_not_found). Negative-lookahead and qualifier matching are applied to prevent false positives. Recorded in the error_patterns field of the Knowledge Archive. **Error→Resolution matching**: Successful tool invocations within 5 entries after an error are detected via file-aware matching and recorded in the `resolution` field (tool name + file name). Cross-session exploration of resolution patterns is possible via `Grep "resolution" knowledge-index.jsonl`
341
+ - **System command filtering**: In the snapshot's "current work" section, system commands such as `/clear`, `/help` are filtered out so that only actual work intent is captured
342
+ - **Crash-safe writes**: The atomic write pattern (temp → rename) is applied to all file writes (snapshots, archives, log cleanup). Prevents partial writes on process crash
343
+ - **P1 Hallucination Prevention**: Tasks that must be 100% accurate repeatedly are enforced by Python code. (1) **KI schema validation**: `_validate_session_facts()` guarantees the presence of RLM-required keys (session_id, tags, final_status, etc. — 10 items) right before writing to knowledge-index — fills with safe defaults if missing. (2) **Partial failure isolation**: In `archive_and_index_session()`, failure to write the archive file does not block knowledge-index update — protects the core RLM asset. (3) **SOT write pattern validation**: `_check_sot_write_safety()` in `setup_init.py` detects the coexistence of SOT file names + write patterns in Hook scripts, based on AST function boundaries. (4) **SOT schema validation**: `validate_sot_schema()` validates the structural integrity of the workflow state.yaml across 8 items (S1-S6 basic + S7 pacs 5 fields + S8 active_team 5 fields). (5) **Adversarial Review P1 validation**: `validate_review_output()` R1-R5, `parse_review_verdict()`, `calculate_pacs_delta()`, `validate_review_sequence()` deterministically guarantee review quality
344
+
345
+ **Data flow:**
346
+
347
+ ```
348
+ Work in progress ─→ [PostToolUse] update_work_log.py ─→ accumulates work_log.jsonl (tracking 9 tools)
349
+ ├→ [PostToolUse] output_secret_filter.py ─→ secret detection on Bash|Read output (3-tier extraction, 25+ patterns, standalone)
350
+ └→ [PostToolUse] security_sensitive_file_guard.py ─→ Edit|Write sensitive file warning (standalone)
351
+ │ (when token > 75%)
352
+
353
+ Response complete ─→ [Stop] generate_context_summary.py ─→ saves latest.md (30s throttling)
354
+ │ + accumulates knowledge-index.jsonl
355
+ │ + archives to sessions/
356
+ │ + E5 Empty Snapshot Guard
357
+
358
+ Session end/compact ─→ [SessionEnd/PreCompact] save_context.py ─→ saves latest.md
359
+ │ + accumulates knowledge-index.jsonl
360
+ │ + archives to sessions/
361
+
362
+ New session start ──→ [SessionStart] restore_context.py ───────→ emits pointer + summary + completion state + Git state
363
+ AI restores the full content via Read tool
364
+ ```
365
+
366
+ ---
367
+
368
+ ## 5. Implementation Element Mapping
369
+
370
+ When designing a workflow, combine the implementation elements below. Tools may use different names, but the concepts are the same.
371
+
372
+ | Workflow Element | Concept | Selection Criterion |
373
+ |------------------|---------|--------------------|
374
+ | **Specialized agent** | A single agent focused on one specific domain | When keeping deep context is the key to quality |
375
+ | **Agent group** | Multiple agents working independently in parallel | When multi-perspective analysis / cross-verification raises quality |
376
+ | **Human intervention point** | User interaction for review / approval / selection | When judgment that cannot be automated is required |
377
+ | **Automated verification** | Quality gate, format check, security check | For automating repeated verifications |
378
+ | **Reusable module** | Encapsulates domain knowledge and repeated patterns | For applying validated patterns consistently |
379
+ | **External integration** | API, DB, external service integration | When external data/functionality is needed |
380
+ | **Dynamic question collection** | Collects information during execution via structured questions to the user | Applies P4 rule. When options cannot be predefined and dynamic judgment is needed |
381
+ | **Task allocation / tracking** | Task creation, allocation, dependency, progress tracking when using an agent group | Does not replace SOT. When coordinating work across agents is required |
382
+
383
+ > **The sole criterion for agent selection is "which structure best raises the quality of the final deliverable."**
384
+ > Do not choose an agent group just because parallelism is fast.
385
+ > Do not choose a specialized agent just because it uses fewer tokens.
386
+
387
+ #### Specialized Agent vs Agent Group — Quality Judgment Matrix
388
+
389
+ Decide the structure along 5 quality factors. "Because it's faster" or "because it's cheaper" is not a criterion:
390
+
391
+ | Quality Factor | Specialized Agent advantage | Agent Group advantage | Judgment Question |
392
+ |----------------|----------------------------|----------------------|------------------|
393
+ | **Context depth** | When results of prior stages must be deeply referenced | When each task requires independent expertise | "Does quality drop if nuance from the previous stage is lost?" |
394
+ | **Cross-verification** | When a single viewpoint ensures consistency | When multi-viewpoint analysis removes bias | "Does another perspective raise the credibility of the result?" |
395
+ | **Deliverable consistency** | When uniform style / tone matters | When each deliverable is independently complete | "Is tone inconsistency across deliverables a quality issue?" |
396
+ | **Error isolation** | When errors must be caught in the full context | When a failed task must not affect others | "Does one failure contaminate the whole?" |
397
+ | **Information transfer loss** | When there is high risk of nuance loss when transferred via files | When structured data transfer is sufficient | "Does contextual summarization cause information loss?" |
398
+
399
+ **Judgment rules:**
400
+ 1. If specialized-agent advantage wins on 3 or more of the 5 factors → **Specialized agent**
401
+ 2. If agent-group advantage wins on 3 or more factors → **Agent group**
402
+ 3. Tie (2:2 + 1 undecidable) → **Context depth** acts as tiebreaker (context retention is generally safer)
403
+ 4. When in doubt → **Specialized agent** (safe default — guarantees context retention)
404
+
405
+ #### Model Level Selection — Quality-Based Judgment
406
+
407
+ | Model Level | Selection Criterion | Fitting Tasks |
408
+ |-------------|---------------------|--------------|
409
+ | **Top tier** | Core tasks — directly impact final quality | Core analysis, final writing, strategic judgment, code architecture |
410
+ | **Stable tier** | Repetitive tasks — patterns are established | Data collection, format conversion, standardized classification |
411
+ | **Auxiliary tier** | Simple tasks — minimal judgment | Format validation, simple filtering, label extraction |
412
+
413
+ **Judgment procedure:**
414
+ 1. How directly does this task affect the quality of the final deliverable?
415
+ 2. Is the quality difference between model levels meaningful?
416
+ - If meaningful → higher-tier model
417
+ - If not meaningful → lower-tier model is permitted
418
+ 3. When in doubt → **higher-tier model** (quality-guarantee principle — Absolute Criterion 1)
419
+
420
+ ### 5.1 Autopilot Mode
421
+
422
+ A mode that enables uninterrupted workflow execution by automatically approving **human-in-the-loop** points.
423
+
424
+ **Core principles:**
425
+ - Autopilot only performs **automatic approval** of human intervention points
426
+ - Every workflow stage is **fully executed** — stage skipping is forbidden
427
+ - Every deliverable is produced at **full quality** — abbreviation is forbidden
428
+ - Automated verification (Hook exit code 2) **still blocks** under Autopilot
429
+
430
+ **Target distinction:**
431
+
432
+ | Mechanism | Autopilot Behavior | Rationale |
433
+ |-----------|--------------------|-----------|
434
+ | Human intervention point `(human)` | Auto-approve — select the quality-maximizing default | AI proxies human judgment |
435
+ | Dynamic question collection | Auto-respond — select the quality-maximizing option | AI proxies human selection |
436
+ | Automated verification `(hook)` exit code 2 | **No change — still blocks** | Deterministic verification; not a target for AI proxying |
437
+
438
+ **Anti-Pattern:**
439
+ 1. Autopilot ≠ stage skipping: every stage is fully executed in sequence
440
+ 2. Autopilot ≠ abbreviated output: every agent produces deliverables of the same quality and length as it would under human review
441
+
442
+ **Anti-Skip Guard (runtime verification):**
443
+
444
+ The deterministic verification performed by the Orchestrator on each stage completion:
445
+ 1. Is the deliverable file recorded as a path in SOT `outputs`?
446
+ 2. Does that file exist on disk?
447
+ 3. Is the file size ≥ 100 bytes (ensuring meaningful content)?
448
+
449
+ > In Claude Code's Hook system, the `validate_step_output()` function of `_context_lib.py` performs this verification deterministically. In other tools, implement equivalent file validation logic.
450
+
451
+ **SOT record:**
452
+ ```yaml
453
+ workflow:
454
+ name: "my-workflow"
455
+ current_step: 3
456
+ status: "running"
457
+ outputs:
458
+ step-1: "research/raw-contents.md"
459
+ step-2: "analysis/insights-list.md"
460
+ autopilot:
461
+ enabled: true
462
+ activated_at: "ISO-8601"
463
+ auto_approved_steps: [3, 6]
464
+ ```
465
+
466
+ - `autopilot.enabled`: Boolean — whether Autopilot is active
467
+ - `autopilot.auto_approved_steps`: list of step numbers that were auto-approved
468
+ - `outputs`: per-step deliverable paths — the targets verified by Anti-Skip Guard
469
+ - Auto-approval decisions are recorded in a separate log file (`autopilot-logs/step-N-decision.md`) (transparency guarantee)
470
+ - Decision Log standard template: see Claude Code's `references/autopilot-decision-template.md`
471
+
472
+ **Runtime reinforcement (Claude Code implementation):**
473
+
474
+ | Layer | Mechanism | Reinforcement |
475
+ |-------|-----------|---------------|
476
+ | **Hook** | SessionStart context injection | On session start/restore, injects the Autopilot execution rules + previous-stage verification results into the prompt |
477
+ | **Hook** | Snapshot Autopilot section | Preserves Autopilot state at IMMORTAL priority across session boundaries |
478
+ | **Hook** | Stop Decision Log safety net | Detects auto-approval patterns → compensates for missing Decision Logs |
479
+ | **Hook** | PostToolUse progress tracking | Records step progress in work_log via the `autopilot_step` field |
480
+ | **Prompt** | Execution Checklist | Mandatory actions for the start / execution / completion of each stage defined below (Claude Code details: `docs/protocols/autopilot-execution.md`) |
481
+
482
+ > The Hook layer accesses SOT **read-only** (Absolute Criterion 2).
483
+
484
+ **Autopilot Execution Checklist (tool-common):**
485
+
486
+ Mandatory actions that must be performed per stage when executing a workflow under Autopilot in any tool:
487
+
488
+ | Timing | Mandatory Action |
489
+ |--------|------------------|
490
+ | **Before stage start** | Check SOT `current_step`, verify that previous-stage deliverable files exist and are non-empty, read `Verification` criteria |
491
+ | **During stage execution** | Fully execute every task (no abbreviation — Absolute Criterion 1), produce full-quality deliverables |
492
+ | **After stage completion** | Save deliverable to disk, self-verify against `Verification` criteria, re-execute only the failed parts on failure (up to 10 times, 15 when ULW is active — §5.1.1), record the path in SOT `outputs`, `current_step` +1, create Decision Log |
493
+ | **Absolutely forbidden** | Incrementing `current_step` by 2 or more at once, proceeding without a deliverable, abbreviating "because it's automated," proceeding while Verification is FAIL |
494
+
495
+ > **Claude Code details**: `docs/protocols/autopilot-execution.md` defines additional Claude Code-specific checklists for `(team)` stages, translation, Hook integration, etc.
496
+
497
+ **Activation:** Default is inactive (interactive). Activated by specifying `Autopilot: enabled` in the workflow Overview or by user instruction at execution time. Can be toggled during execution.
498
+
499
+ ### 5.1.1 ULW Mode (Claude Code)
500
+
501
+ **ULW (Ultrawork)** is a **thoroughness-intensity overlay** orthogonal to Autopilot. It is activated by including `ulw` in the prompt.
502
+
503
+ - **Autopilot** = automation axis (HOW) — skip `(human)` approvals
504
+ - **ULW** = thoroughness axis (HOW THOROUGHLY) — nothing omitted, perfect completion through error resolution
505
+
506
+ **2x2 matrix:**
507
+
508
+ | | **ULW OFF** | **ULW ON** |
509
+ |---|---|---|
510
+ | **Autopilot OFF** | Standard interactive | Interactive + Sisyphus Persistence (3 retries) + mandatory task decomposition |
511
+ | **Autopilot ON** | Standard automated workflow | Automated workflow + Sisyphus reinforcement (3 retries) + team thoroughness |
512
+
513
+ **3 reinforcement rules (Intensifiers):**
514
+ 1. **I-1. Sisyphus Persistence** — Up to 3 retries, each with a different approach. 100% completion, or report impossibility.
515
+ 2. **I-2. Mandatory Task Decomposition** — TaskCreate → TaskUpdate → TaskList mandatory
516
+ 3. **I-3. Bounded Retry Escalation** — No more than 3 retries on the same target (quality gates have a separate budget); when exceeded, escalate to the user
517
+
518
+ **Deterministic reinforcement:** A Python Hook deterministically verifies compliance with the 3 reinforcement rules (Compliance Guard). On violation, a warning is recorded in the IMMORTAL section of the snapshot.
519
+
520
+ > **Combination rule**: ULW **reinforces** Autopilot — the Autopilot quality-gate retry limit is raised 10→15. Safety Hook blocks are always respected.
521
+
522
+ Details: `docs/protocols/ulw-mode.md`
523
+
524
+ ### 5.2 English-First Execution and Translation Protocol
525
+
526
+ When **executing** a workflow, every agent **works in English** and produces **deliverables in English**. Because AI performs best in English, English-first execution is a direct realization of **Absolute Criterion 1 (Quality)**.
527
+
528
+ #### Language Boundaries
529
+
530
+ | Activity | Language | Rationale |
531
+ |----------|----------|-----------|
532
+ | Workflow design (workflow-generator skill) | Korean | Conversation with the user |
533
+ | Agent definitions (`.claude/agents/*.md`) | English | Maximize agent prompt quality |
534
+ | Workflow execution (agent work) | **English** | Maximize AI performance |
535
+ | Deliverable translation | English → Korean | `@translator` specialized sub-agent |
536
+ | SOT records | Language-agnostic | Structural data such as paths and numbers |
537
+
538
+ > **Design documents (`workflow.md`) remain in Korean.** Since it is a blueprint that the user reads and reviews, it uses the user's language. Language transitions occur at the **design → execution** boundary.
539
+
540
+ #### Determining Translation Targets
541
+
542
+ Not every stage requires translation:
543
+
544
+ | Deliverable Type | Translate? | Example |
545
+ |------------------|-----------|---------|
546
+ | Text content (analysis, report, summary) | **Translate** | `.md`, `.txt` |
547
+ | Code file | Do not translate | `.py`, `.js`, `.ts` |
548
+ | Data file | Do not translate | `.json`, `.csv` |
549
+ | Config file | Do not translate | `.yaml` config, `.env` |
550
+
551
+ When designing a workflow, specify `Translation: @translator` or `Translation: none` per stage to decide whether translation applies.
552
+
553
+ #### Translation Execution Protocol
554
+
555
+ **Rationale for sub-agent selection**: Because terminology consistency and context accumulation are key to translation quality, a **specialized Sub-agent** has a quality advantage over an agent group (factors "context depth" + "deliverable consistency" in the §5 quality matrix).
556
+
557
+ **Execution order**:
558
+
559
+ ```
560
+ Step N English deliverable complete
561
+ → record in SOT outputs.step-N + Anti-Skip Guard verification
562
+ → invoke @translator sub-agent (only for stages with Translation: @translator)
563
+ ① Read translations/glossary.yaml (terminology — RLM external persistent state)
564
+ ② Read the full English source
565
+ ③ Fully translate using established terms (no abbreviation — Absolute Criterion 1)
566
+ ④ Self-review: compare against the source, check terminology consistency
567
+ ⑤ Update glossary.yaml (add new terms)
568
+ ⑥ Generate *.ko.md file
569
+ → record in SOT outputs.step-N-ko
570
+ → confirm the translation file exists and is non-empty
571
+ → P1 validation: python3 .claude/hooks/scripts/validate_translation.py --step N --project-dir . --check-pacs --check-sequence
572
+ → proceed to Step N+1
573
+ ```
574
+
575
+ #### Terminology Glossary
576
+
577
+ `translations/glossary.yaml` is the translation agent's **persistent external memory** (RLM pattern). Together with `memory: project` (ADR-051), it forms a 2-layer memory: glossary.yaml = explicit terminology mapping, persistent memory = implicit style/tone pattern accumulation.
578
+
579
+ ```yaml
580
+ # translations/glossary.yaml
581
+ terms:
582
+ "Single Source of Truth": "Single Source of Truth (SOT)"
583
+ "Anti-Skip Guard": "Anti-Skip Guard" # kept in English
584
+ "workflow step": "Workflow Step"
585
+ ```
586
+
587
+ **Architectural consistency**:
588
+ - The glossary is **not an SOT** — it is a local work file of the translation agent
589
+ - Not managed by the Orchestrator — managed by the translation agent itself
590
+ - No concurrent-write risk — translation runs sequentially (once after each stage)
591
+ - Hierarchical memory: glossary.yaml (explicit terminology) + `memory: project` (implicit experience accumulation) as 2 layers (ADR-051)
592
+
593
+ #### SOT Recording Rules
594
+
595
+ ```yaml
596
+ outputs:
597
+ step-1: "research/raw-contents.md" # English source
598
+ step-1-ko: "research/raw-contents.ko.md" # Korean translation
599
+ step-2: "data/processed.json" # translation unnecessary → no -ko
600
+ step-3: "analysis/report.md"
601
+ step-3-ko: "analysis/report.ko.md"
602
+ ```
603
+
604
+ - The `step-N-ko` key follows the suffix convention: it is automatically skipped by Anti-Skip Guard's `.isdigit()` guard
605
+ - Anti-Skip Guard validates only `step-N` (the English source) → translation verification is performed by the Orchestrator checklist
606
+ - Stages without translation do not generate `-ko` keys
607
+
608
+ #### Translation in `(team)` Stages
609
+
610
+ The translation targets in agent-group stages are **only the official deliverables recorded in SOT `outputs.step-N`**:
611
+
612
+ 1. Team Lead merges all Teammate deliverables
613
+ 2. Records in SOT `outputs.step-N` + Anti-Skip Guard verification
614
+ 3. Team Lead invokes `@translator` (on the merged official deliverable)
615
+ 4. Records in SOT `outputs.step-N-ko`
616
+
617
+ > Individual Teammate deliverables are intermediate artifacts (not recorded in SOT), and therefore are not translated.
618
+
619
+ #### Independent Translation Verification (optional — for final deliverables)
620
+
621
+ By default, the translator's **self-review** is sufficient. For stages where quality is especially critical, such as final deliverables, an independent verification sub-agent can be added:
622
+
623
+ ```
624
+ @translator → output.ko.md
625
+ → @translation-verifier (separate sub-agent)
626
+ ① Read English source and Korean translation simultaneously
627
+ ② Verify accuracy, completeness, terminology consistency, naturalness
628
+ ③ Pass/Fail verdict + feedback
629
+ → On Fail: request re-translation from @translator with feedback
630
+ ```
631
+
632
+ This pattern is applied optionally in workflow design.
633
+
634
+ ### 5.3 Verification Protocol (Work Verification)
635
+
636
+ A protocol that verifies whether each stage deliverable of the workflow has **100% achieved the functional goal**.
637
+
638
+ **Core principle:**
639
+ > **"Declare the definition of done first, verify after execution, and re-execute on failure."**
640
+
641
+ Anti-Skip Guard (file existence + ≥ 100 bytes) guarantees **physical existence**, and the Verification Protocol guarantees **content completeness**. The two layers operate independently, and both must pass before proceeding to the next stage.
642
+
643
+ ```
644
+ Quality-guarantee layer structure:
645
+
646
+ Anti-Skip Guard (Hook — deterministic)
647
+ "Does the file exist and have meaningful size?"
648
+ ↓ PASS
649
+ Verification Gate (Agent — semantic)
650
+ "Has the functional goal been 100% achieved?"
651
+ ↓ PASS
652
+ Update SOT + proceed to next stage
653
+ ```
654
+
655
+ #### Declaring Verification Criteria
656
+
657
+ Define a `Verification` field in each stage of the workflow. **Place it before the Task** so that the agent starts work after first recognizing "what constitutes completion."
658
+
659
+ ```markdown
660
+ ### N. [Step Name]
661
+ - **Verification**:
662
+ - [ ] [specific, measurable criterion]
663
+ - [ ] [specific, measurable criterion]
664
+ - **Task**: [task description]
665
+ ```
666
+
667
+ #### Verification Criterion Types (5)
668
+
669
+ | Type | Verification Target | Good Example | Bad Example |
670
+ |------|---------------------|--------------|-------------|
671
+ | **Structural completeness** | Internal structure of the deliverable | "All 5 sections (Intro, Analysis, Comparison, Recommendation, References) are included" | "Well-organized" |
672
+ | **Functional goal** | Achievement of the task goal | "Each competitor pricing data includes ≥ 3 tiers + exact amounts" | "Pricing info exists" |
673
+ | **Data integrity** | Data accuracy | "All URLs are valid and contain no placeholder/example.com" | "Links checked" |
674
+ | **Pipeline connection** | Compatibility with next stage input | "Contains competitor_name, pricing_tiers, feature_list fields required by the Step 4 analysis agent" | "Next stage compatible" |
675
+ | **Cross-step traceability** | Logical derivation from previous-stage data | "≥ 80% of analysis claims are traceable via the [trace:step-N] marker to their source" | "Data-based" |
676
+
677
+ > **Criterion-writing rule**: Each criterion must be **mechanically pass/fail judgeable by a third party**. Subjective judgments ("good quality," "sufficient depth") must not be used as criteria. Subjective quality judgments are handled by the existing `(human)` checkpoints.
678
+
679
+ #### Domain Knowledge Structure (DKS)
680
+
681
+ A pattern for verifying the validity of domain-specialized reasoning. In the Research stage, build `domain-knowledge.yaml`, and in the Implementation stage, use it as verification criteria. Optional — not required for every domain. Validation script: `validate_domain_knowledge.py` (DK1-DK7).
682
+
683
+ **DKS necessity criteria**:
684
+
685
+ | Domain | DKS Necessity | Reason |
686
+ |--------|---------------|--------|
687
+ | Medicine/clinical, law | High | Validity of domain-specialized reasoning (symptom→disease, precedent→principle) must be verified |
688
+ | Competitive analysis, market research | Medium | Structuring entity relationships (dominance, competition) improves quality |
689
+ | Blog/content, code generation | Low | Type systems / tests substitute, or domain reasoning is unnecessary |
690
+
691
+ #### Execution Protocol
692
+
693
+ ```
694
+ 1. Read verification criteria — agent first recognizes the definition of "100% complete"
695
+ 2. Execute stage — produce the full-quality deliverable (Absolute Criterion 1)
696
+ 3. Anti-Skip Guard — file existence + ≥ 100 bytes (deterministic)
697
+ 4. Verification Gate — self-verify deliverable against each criterion (semantic)
698
+ ├─ All criteria PASS → create verification-logs/step-N-verify.md → update SOT → proceed
699
+ └─ Even one FAIL:
700
+ ├─ Identify the failure cause + re-execute only the failing part (not full rework)
701
+ ├─ Re-verify (up to 10 retries)
702
+ └─ If still FAIL after 10 → escalate to user
703
+ 5. Update SOT — record outputs, `current_step` +1
704
+ ```
705
+
706
+ > **Scope of Self-Verification**: The verification in this protocol is a **completeness** check — "Was what had to be executed executed?" Subjective **quality judgment** is handled by the existing `(human)` checkpoints, and the Verification Protocol does not replace them.
707
+
708
+ #### Verification Log Format
709
+
710
+ Recorded in `verification-logs/step-N-verify.md`:
711
+
712
+ ```markdown
713
+ # Verification Report — Step {N}: {Step Name}
714
+
715
+ ## Criteria Check
716
+ | # | Criterion | Status | Evidence |
717
+ |---|-----------|--------|----------|
718
+ | 1 | [criterion text] | PASS | [specific evidence from the deliverable] |
719
+ | 2 | [criterion text] | FAIL→PASS | [first-round failure reason] → [evidence after re-execution] |
720
+
721
+ ## Result: PASS (retry: 1)
722
+ ## Verified Output: research/insights.md (2,847 bytes)
723
+ ```
724
+
725
+ #### 3-Layer Verification for (team) Stages
726
+
727
+ Agent-group stages perform a 3-layer verification:
728
+
729
+ | Layer | Performer | Verification Target | SOT Write |
730
+ |-------|-----------|---------------------|-----------|
731
+ | **L1** | Teammate (self-verification) | Verification criteria of own Task | **None** — completed inside the session |
732
+ | **L1.5** | Teammate (pACS) | Confidence of own Task deliverable | **None** — score is included in the report message |
733
+ | **L2** | Team Lead (comprehensive verification + stage pACS) | Verification criteria of the whole stage | **Yes** — update SOT outputs + pacs |
734
+
735
+ ```
736
+ Teammate: Execute Task → self-verify (L1) → pACS self-score (L1.5)
737
+ → On PASS + GREEN/YELLOW: report to Team Lead (include pACS score)
738
+ → On FAIL or RED: self-correct, then re-verify/re-score
739
+
740
+ Team Lead: Receive Teammate deliverables + pACS scores
741
+ → Comprehensive verification against stage criteria (L2)
742
+ → Stage pACS = min(each Teammate pACS) — apply min-score principle
743
+ → On PASS: update SOT (outputs + pacs)
744
+ → On FAIL: SendMessage with concrete feedback + re-execution directive
745
+ ```
746
+
747
+ > **SOT compatibility**: Teammate still produces only deliverable files and does not write to SOT. Self-verification and pACS self-scoring are completed inside the Teammate's session and conveyed to the Team Lead via the report message (Absolute Criterion 2). Only the Team Lead records in `pacs-logs/` and updates the SOT.
748
+
749
+ #### Backward Compatibility
750
+
751
+ | Situation | Behavior |
752
+ |-----------|----------|
753
+ | `Verification` field **present** | Verification Gate active — verify against criteria before proceeding |
754
+ | `Verification` field **absent** | Existing behavior — proceed using only Anti-Skip Guard |
755
+
756
+ When creating new workflows, include the `Verification` field as mandatory. Existing workflows can add it incrementally.
757
+
758
+ #### SOT Impact
759
+
760
+ **None.** The Verification Protocol is an agent-execution protocol (prompt layer) and does not change the SOT structure. Advancement of `current_step` already implicitly means that verification has completed, and the verification details are recorded in `verification-logs/` files.
761
+
762
+ ### 5.4 pACS — predicted Agent Confidence Score (Self-Confidence Rating)
763
+
764
+ A protocol where an agent **structurally self-rates the confidence of its own deliverable** during workflow execution. Inspired by AlphaFold's pLDDT (predicted Local Distance Difference Test).
765
+
766
+ **Core principle:**
767
+ > **"Before assigning a score, speak about the weaknesses first."** (Pre-mortem Protocol)
768
+
769
+ While the Verification Protocol (§5.3) verifies "completeness" — was what had to be executed executed? — pACS **quantifies "confidence" — how much can we believe the result?** The two protocols guarantee quality on different dimensions and operate independently.
770
+
771
+ #### 3 Evaluation Dimensions (Orthogonal Dimensions)
772
+
773
+ | Dimension | Target of Measurement | Signs of Low Score |
774
+ |-----------|----------------------|--------------------|
775
+ | **F — Factual Grounding** | Robustness of factual grounding | Unknown sources, memory-based inference, unverified assumptions |
776
+ | **C — Completeness** | No omissions against requirements | Some items skipped, insufficient analysis depth |
777
+ | **L — Logical Coherence** | Internal consistency of argument / structure | Contradictions, leaps, mismatch between evidence and conclusion |
778
+
779
+ > **Reason for limiting to 3 dimensions**: Agent self-rating is a subjective estimate without calibration data. The more dimensions, the larger the precision illusion and the greater the interference between dimensions. 3 orthogonal dimensions is the practical upper bound.
780
+
781
+ #### Min-Score Principle
782
+
783
+ > **pACS = min(F, C, L)**
784
+
785
+ Weighted averaging is not used. If any one dimension is low, the overall confidence is low. The weakest link determines overall quality.
786
+
787
+ #### Pre-mortem Protocol (Mandatory — perform before scoring)
788
+
789
+ A mechanism that structurally prevents score inflation. The agent must answer the 3 questions below **before** scoring:
790
+
791
+ 1. **"Where is the most uncertain part of this deliverable?"** — areas where sources are unverified, recency is unclear, or reliance on estimation exists
792
+ 2. **"What is most likely to have been omitted?"** — partial requirement unmet, edge cases unconsidered, data gaps
793
+ 3. **"Where is the weakest link in this argument?"** — evidence→conclusion leaps, insufficient premise verification, unexplored alternatives
794
+
795
+ If the Pre-mortem responses reveal serious issues, you cannot assign a high score to the corresponding dimension.
796
+
797
+ #### Action Triggers
798
+
799
+ | Grade | Score Range | Action | Rationale |
800
+ |-------|-------------|--------|-----------|
801
+ | **GREEN** | pACS ≥ 70 | Automatic progression | High agent confidence — normal quality |
802
+ | **YELLOW** | 50 ≤ pACS < 70 | Proceed but flag weaknesses | Partial uncertainty — subject to post-review |
803
+ | **RED** | pACS < 50 | Rework or escalation | Untrustworthy — re-execution of that part is mandatory |
804
+
805
+ #### Quality-Guarantee Layer Structure (4 Layers)
806
+
807
+ ```
808
+ L0 Anti-Skip Guard (Hook — deterministic)
809
+ "Does the file exist and have meaningful size?"
810
+ ↓ PASS
811
+ L1 Verification Gate (Agent — semantic)
812
+ "Has the functional goal been 100% achieved?"
813
+ ↓ PASS
814
+ L1.5 pACS Self-Rating (Agent — confidence)
815
+ Pre-mortem → score F, C, L → min(F,C,L) = pACS
816
+ ↓ GREEN/YELLOW: proceed (YELLOW flagged)
817
+ ↓ RED: rework or escalation
818
+ L2 Adversarial Review (Enhanced — stages with a Review: field)
819
+ @reviewer / @fact-checker independently reviews the deliverable adversarially (§5.5)
820
+ ```
821
+
822
+ > **Relationship between L1 and L1.5**: The Verification Gate is "checklist item PASS/FAIL" — a binary judgment. pACS is "overall confidence 0-100" — a continuous self-rating. Even when every Verification item is PASS, pACS can still be low (e.g., every item was addressed but source quality is low).
823
+
824
+ #### SOT Record
825
+
826
+ ```yaml
827
+ workflow:
828
+ # ... existing fields ...
829
+ pacs:
830
+ current_step_score: 72 # pACS of current stage
831
+ dimensions: {F: 72, C: 85, L: 78}
832
+ weak_dimension: "F" # min-score dimension
833
+ pre_mortem_flag: "Step 3: 2 data sources unverified"
834
+ history: # per-stage history
835
+ step-1: {score: 85, weak: "C"}
836
+ step-2: {score: 72, weak: "F"}
837
+ ```
838
+
839
+ - The `pacs` field is **append-only** to the existing SOT schema — independent of existing `workflow`, `autopilot`, `outputs`, `active_team` fields
840
+ - SOT without `pacs` still functions normally (backward compatible)
841
+ - Because the Hook's `capture_sot()` includes the entire SOT in the snapshot, the `pacs` field is also automatically preserved across session boundaries
842
+
843
+ #### Translation pACS (for Translation Deliverables)
844
+
845
+ Additional 3 dimensions for the `@translator` sub-agent's translation deliverables:
846
+
847
+ | Dimension | Target of Measurement | Signs of Low Score |
848
+ |-----------|----------------------|--------------------|
849
+ | **Ft — Fidelity** | Accurate transfer of source meaning | Over-paraphrasing, meaning distortion, terminology inconsistency |
850
+ | **Ct — Translation Completeness** | No omissions vs. source | Paragraphs/sentences/footnotes omitted |
851
+ | **Nt — Naturalness** | Natural Korean rather than translationese | English word-order literalisms, translation tone |
852
+
853
+ Translation pACS = min(Ft, Ct, Nt). Action triggers are identical (GREEN/YELLOW/RED).
854
+
855
+ #### L2 Adversarial Review (Enhanced — stages with a Review: field)
856
+
857
+ An enhanced quality-verification layer that replaces the previous L2 Calibration. `@reviewer` (critical analysis of code/deliverables, read-only) and `@fact-checker` (external fact verification, web access) independently review the deliverable. Review results are deterministically guaranteed in quality via P1 validation (`validate_review.py`).
858
+
859
+ Applied to stages where the workflow design specifies `Review: @reviewer` or `Review: @reviewer + @fact-checker`. Default is self-rating (L1.5) only.
860
+
861
+ Details: see §5.5 Adversarial Review.
862
+
863
+ #### pACS Log Format
864
+
865
+ Recorded in `pacs-logs/step-N-pacs.md`:
866
+
867
+ ```markdown
868
+ # pACS Report — Step {N}: {Step Name}
869
+
870
+ ## Pre-mortem
871
+ 1. **Most uncertain**: [the uncertain part]
872
+ 2. **Likely omission**: [possible omission]
873
+ 3. **Weakest link**: [the weakest argumentative link]
874
+
875
+ ## Scores
876
+ | Dimension | Score | Rationale |
877
+ |-----------|-------|-----------|
878
+ | F (Factual Grounding) | {0-100} | [specific evidence] |
879
+ | C (Completeness) | {0-100} | [specific evidence] |
880
+ | L (Logical Coherence) | {0-100} | [specific evidence] |
881
+
882
+ ## Result: pACS = {min(F,C,L)} → {GREEN|YELLOW|RED}
883
+ ## Weak Dimension: {F|C|L} — {description of weakness}
884
+ ```
885
+
886
+ #### pACS Under Autopilot
887
+
888
+ - pACS GREEN → automatic progression
889
+ - pACS YELLOW → automatic progression + record weak dimension in Decision Log
890
+ - pACS RED → automatic rework (up to 10 times). If still RED after → escalate to user
891
+ - Add `pacs_score`, `weak_dimension` fields to the Autopilot Decision Log
892
+
893
+ #### Backward Compatibility
894
+
895
+ | Situation | Behavior |
896
+ |-----------|----------|
897
+ | No pACS reference in the workflow | Proceed with only existing L0 + L1 |
898
+ | No `pacs` field in SOT | Normal operation — ignored by both Hook and agent |
899
+ | pACS alone without Verification | Not permitted — pACS is performed only after Verification Gate passes |
900
+
901
+ > **Design decision**: pACS in isolation without Verification is forbidden. Performing confidence rating (L1.5) without completeness verification (L1) can lead to the contradictory state of "everything omitted, but confidence high."
902
+
903
+ ### 5.5 Adversarial Review (Enhanced L2 — Adversarial Review)
904
+
905
+ An enhanced quality-verification layer that replaces the previous L2 Calibration. Deliverables are independently reviewed using the Generator-Critic pattern.
906
+
907
+ #### Quality Layer Architecture
908
+
909
+ ```
910
+ L0 Anti-Skip Guard (Hook — deterministic)
911
+ L1 Verification Gate (Agent self-check)
912
+ L1.5 pACS Self-Rating (Agent confidence)
913
+ L2 Adversarial Review (Enhanced L2) ← this section
914
+ ├── Content critical analysis (LLM — @reviewer / @fact-checker)
915
+ ├── Independent pACS scoring (LLM → Python validates)
916
+ └── P1 deterministic validation (Python — validate_review.py)
917
+ ```
918
+
919
+ #### Agent Definitions
920
+
921
+ | Agent | Tools | Role | Model |
922
+ |-------|-------|------|-------|
923
+ | `@reviewer` | Read, Glob, Grep (read-only) | Critical analysis of code/deliverables — flaws, logical gaps, completeness review | opus |
924
+ | `@fact-checker` | Read, Glob, Grep, WebSearch, WebFetch | Fact verification — claim-by-claim confirmation against independent sources | opus |
925
+
926
+ - **Rationale for tool separation (P2)**: `@reviewer` reviews internal logic of code/docs, so it only needs read access. `@fact-checker` needs web access because external fact verification is required. Principle of least privilege.
927
+ - **Rationale for Sub-agent selection**: Single reviewer = Sub-agent (synchronous feedback loop). Since review results must be reflected immediately, this is more efficient than an Agent Team asynchronous pattern.
928
+
929
+ #### Execution Protocol
930
+
931
+ 1. Generator produces the deliverable → passes L0/L1/L1.5
932
+ 2. Orchestrator invokes the agent specified in the `Review:` field as a Sub-agent
933
+ 3. The reviewer agent produces the review report (returned via stdout)
934
+ 4. Orchestrator saves the report to `review-logs/step-N-review.md`
935
+ 5. P1 validation: `python3 .claude/hooks/scripts/validate_review.py --step N --project-dir .`
936
+ 6. Proceed based on verdict:
937
+
938
+ ```
939
+ PASS → Translation (if any) → SOT update → next stage
940
+ FAIL → Rework (up to 10 times) → Re-review
941
+ ↓ after 10
942
+ Escalate to user
943
+ ```
944
+
945
+ #### Review Field Syntax
946
+
947
+ Specify the `Review:` attribute per stage in the workflow:
948
+
949
+ ```markdown
950
+ ### Step 3: Analysis Report (agent)
951
+ - Agent: @analyst
952
+ - Review: @reviewer ← code/deliverable review
953
+ - Translation: @translator
954
+ - Verification:
955
+ - [ ] ...
956
+ ```
957
+
958
+ | Review Value | Behavior |
959
+ |--------------|----------|
960
+ | `@reviewer` | Critical analysis of code/deliverable |
961
+ | `@fact-checker` | Fact verification (against external sources) |
962
+ | `@reviewer + @fact-checker` | Both run (high-risk stages) |
963
+ | `none` or unspecified | Skip review (up to L1.5 only) |
964
+
965
+ #### Rubber-stamp Prevention (4-Layer Defense)
966
+
967
+ | Defense Layer | Mechanism |
968
+ |---------------|-----------|
969
+ | 1. Adversarial Persona | "Critic, not validator" identity embedded in the agent definition |
970
+ | 2. Pre-mortem | Writing 3 failure hypotheses before analysis is mandatory — prevents confirmation bias |
971
+ | 3. Minimum 1 Issue | P1 validation auto-rejects reviews with 0 issues (R5 check) |
972
+ | 4. Independent pACS | Reviewer scores independently → compared with Generator (Delta ≥ 15 → arbitration) |
973
+
974
+ #### P1 Hallucination Containment
975
+
976
+ 5 tasks that must be 100% accurate in the review system are enforced by Python code:
977
+
978
+ | Check | Function | Location |
979
+ |-------|----------|----------|
980
+ | R1: Review file existence | `validate_review_output()` | `_context_lib.py` |
981
+ | R2: Minimum size (100 bytes) | `validate_review_output()` | `_context_lib.py` |
982
+ | R3: 4 required sections exist | `validate_review_output()` | `_context_lib.py` |
983
+ | R4: Explicit extraction of PASS/FAIL | `parse_review_verdict()` | `_context_lib.py` |
984
+ | R5: Issue table ≥ 1 row | `validate_review_output()` | `_context_lib.py` |
985
+ | pACS Delta computation | `calculate_pacs_delta()` | `_context_lib.py` |
986
+ | Review → Translation order | `validate_review_sequence()` | `_context_lib.py` |
987
+
988
+ Standalone script: `python3 .claude/hooks/scripts/validate_review.py --step N --project-dir .`
989
+ Output: JSON `{"valid": true, "verdict": "PASS", "critical_count": 0, ...}`
990
+
991
+ #### Translation P1 Hallucination Containment
992
+
993
+ 9 tasks that must be 100% accurate for translation deliverables are enforced by Python code:
994
+
995
+ | Check | Function | Location |
996
+ |-------|----------|----------|
997
+ | T1: Translation file existence | `validate_translation_output()` | `_context_lib.py` |
998
+ | T2: Minimum size (100 bytes) | `validate_translation_output()` | `_context_lib.py` |
999
+ | T3: English source existence | `validate_translation_output()` | `_context_lib.py` |
1000
+ | T4: .ko.md extension | `validate_translation_output()` | `_context_lib.py` |
1001
+ | T5: Non-whitespace content | `validate_translation_output()` | `_context_lib.py` |
1002
+ | T6: Heading count ±20% | `validate_translation_output()` | `_context_lib.py` |
1003
+ | T7: Code block count match | `validate_translation_output()` | `_context_lib.py` |
1004
+ | T8: Glossary timestamp freshness | `check_glossary_freshness()` | `_context_lib.py` |
1005
+ | T9: pACS min() arithmetic correctness (generic) | `verify_pacs_arithmetic()` | `_context_lib.py` |
1006
+
1007
+ Standalone script: `python3 .claude/hooks/scripts/validate_translation.py --step N --project-dir . --check-pacs --check-sequence`
1008
+ Output: JSON `{"valid": true, "checks": {"T1": true, ...}, "pacs_valid": true}`
1009
+
1010
+ #### Verification Log P1 Hallucination Containment
1011
+
1012
+ Structural integrity of the verification log is enforced by Python code across 3 items:
1013
+
1014
+ | Check | Function | Location |
1015
+ |-------|----------|----------|
1016
+ | V1a: Verification log file existence | `validate_verification_log()` | `_context_lib.py` |
1017
+ | V1b: Per-criterion PASS/FAIL explicit | `validate_verification_log()` | `_context_lib.py` |
1018
+ | V1c: Logical consistency (if any FAIL, overall PASS is impossible) | `validate_verification_log()` | `_context_lib.py` |
1019
+
1020
+ Standalone script: `python3 .claude/hooks/scripts/validate_verification.py --step N --project-dir .`
1021
+ Output: JSON `{"valid": true, "checks": {"V1a": true, "V1b": true, "V1c": true}}`
1022
+
1023
+ #### Issue Severity Classification
1024
+
1025
+ | Severity | Definition | Verdict Impact |
1026
+ |----------|------------|----------------|
1027
+ | **Critical** | Factual error, missing required content, logical flaw, security vulnerability | → FAIL |
1028
+ | **Warning** | Incomplete coverage, weak argument, style inconsistency, minor inaccuracy | → PASS (recorded) |
1029
+ | **Suggestion** | Improvement opportunity, alternative approach, readability improvement | → PASS (optional) |
1030
+
1031
+ #### Review Report Format
1032
+
1033
+ Recorded in `review-logs/step-N-review.md`:
1034
+
1035
+ ```markdown
1036
+ # Adversarial Review — Step {N}: {Step Name}
1037
+ Reviewer: @{reviewer|fact-checker}
1038
+
1039
+ ## Pre-mortem (MANDATORY — before analysis)
1040
+ 1. **Most likely critical flaw**: [...]
1041
+ 2. **Most likely factual error**: [...]
1042
+ 3. **Most likely logical weakness**: [...]
1043
+
1044
+ ## Issues Found
1045
+ | # | Severity | Location | Problem | Suggested Fix |
1046
+ |---|----------|----------|---------|---------------|
1047
+ | 1 | Critical | file:line | [...] | [...] |
1048
+
1049
+ ## Independent pACS (Reviewer's Assessment)
1050
+ | Dimension | Score | Rationale |
1051
+ |-----------|-------|-----------|
1052
+ | F | {0-100} | [...] |
1053
+ | C | {0-100} | [...] |
1054
+ | L | {0-100} | [...] |
1055
+
1056
+ Reviewer pACS = min(F,C,L) = {score}
1057
+ Generator pACS = {score}
1058
+ Delta = |Reviewer - Generator| = {N}
1059
+
1060
+ ## Verdict: {PASS|FAIL}
1061
+ ```
1062
+
1063
+ #### Adversarial Review Under Autopilot
1064
+
1065
+ - Review PASS → automatic progression (including Translation)
1066
+ - Review FAIL → automatic rework (up to 10 times, escalate to user on exceeding)
1067
+ - pACS Delta ≥ 15 → record in Decision Log + recommend recalibration
1068
+ - Review Decision Log: include review result in `autopilot-logs/step-N-decision.md`
1069
+
1070
+ #### Execution Order Constraint
1071
+
1072
+ ```
1073
+ Task → L0 → L1 → L1.5 → Review(L2) → PASS → Translation → SOT update
1074
+ ```
1075
+
1076
+ - Translation is executed only after Review PASS (enforced by P1 `validate_review_sequence()`)
1077
+ - Translation execution is forbidden while Review is FAIL
1078
+ - Stages with Review unspecified (`none`) can proceed directly to Translation after L1.5
1079
+
1080
+ #### Backward Compatibility
1081
+
1082
+ | Situation | Behavior |
1083
+ |-----------|----------|
1084
+ | Workflow has no `Review:` specified | Proceed with only existing L0 + L1 + L1.5 |
1085
+ | `review-logs/` does not exist | Normal operation — P1 functions fail gracefully |
1086
+ | `@reviewer`/`@fact-checker` agents undefined | On Sub-agent invocation failure, escalate to user |
1087
+
1088
+ > **Design decision**: Adversarial Review is positioned as the Enhanced version of the existing L2 Calibration. The "cross-verification" of L2 Calibration is strengthened to "adversarial review," while the existing L0/L1/L1.5 layers are not changed at all. Stages without the `Review:` field behave identically to before.
1089
+
1090
+ ---
1091
+
1092
+ ### 5.6 Abductive Diagnosis Protocol
1093
+
1094
+ When a quality gate (Verification Gate, pACS, Adversarial Review) fails, instead of retrying immediately, pass through a **3-step diagnosis** to raise retry quality. The existing 4-layer QA (L0→L1→L1.5→L2) is not changed; this is an additional layer inserted **between** FAIL and retry.
1095
+
1096
+ #### 3-Step Process
1097
+
1098
+ | Step | Actor | Input | Output | Nature |
1099
+ |------|-------|-------|--------|--------|
1100
+ | **Step A — P1 pre-evidence collection** | `diagnose_context.py` | SOT, log files, retry history | Structured evidence bundle (JSON) | Deterministic |
1101
+ | **Step B — LLM diagnosis** | Orchestrator (Claude) | Evidence bundle + hypothesis priority | Diagnosis log (`diagnosis-logs/step-N-gate-timestamp.md`) | Judgmental |
1102
+ | **Step C — P1 post-validation** | `validate_diagnosis.py` | Diagnosis log | AD1-AD10 structural integrity (JSON) | Deterministic |
1103
+
1104
+ #### Hypothesis System (H1/H2/H3/H4)
1105
+
1106
+ | Hypothesis | Label | Priority Determination Criterion |
1107
+ |------------|-------|----------------------------------|
1108
+ | **H1** | Upstream data quality issue | Top priority when prior-stage deliverables are missing/under-delivered |
1109
+ | **H2** | Current-stage execution gap | Default top priority (most frequent) |
1110
+ | **H3** | Criteria interpretation error | Priority rises at Review gates |
1111
+ | **H4** | Capability gap — missing tools/scripts/infrastructure | Auto-promoted when H2 fails to resolve in 2 consecutive iterations |
1112
+
1113
+ #### Fast-Path (FP1-FP3)
1114
+
1115
+ Deterministic shortcut paths that skip LLM diagnosis:
1116
+
1117
+ | ID | Condition | Diagnosis | Action |
1118
+ |----|-----------|-----------|--------|
1119
+ | **FP1** | Deliverable file missing | "File not created" | Immediate re-execution |
1120
+ | **FP2** | Deliverable size < 100B | "Incomplete creation" | Immediate re-execution |
1121
+ | **FP3** | Same hypothesis selected 2 times in a row | "Approach lock-in" | Escalate to user |
1122
+
1123
+ #### P1 Post-Validation (AD1-AD10)
1124
+
1125
+ | Check | Description |
1126
+ |-------|-------------|
1127
+ | AD1 | Diagnosis log file exists |
1128
+ | AD2 | Minimum size ≥ 100 bytes |
1129
+ | AD3 | Gate field matches |
1130
+ | AD4 | Selected hypothesis exists (H1/H2/H3/H4) |
1131
+ | AD5 | Evidence items ≥ 1 |
1132
+ | AD6 | Action Plan section exists |
1133
+ | AD7 | Forward step references forbidden |
1134
+ | AD8 | Hypotheses ≥ 2 (alternatives considered) |
1135
+ | AD9 | Selected hypothesis is one of the listed hypotheses |
1136
+ | AD10 | References previous diagnosis (when retry > 0) |
1137
+
1138
+ #### Backward Compatibility
1139
+
1140
+ | Situation | Behavior |
1141
+ |-----------|----------|
1142
+ | `diagnosis-logs/` does not exist | Existing behavior — retry without diagnosis |
1143
+ | Retry executed without diagnosis | Normal operation — safety net only emits a stderr warning |
1144
+ | Fast-Path applies | Skip LLM diagnosis — decide immediately with only P1 pre-evidence |
1145
+
1146
+ > **Design decision**: Abductive Diagnosis is an additional layer that does not change the existing 4-layer QA. Diagnosis results are recorded only in `diagnosis-logs/` and SOT is not modified. They are archived to the Knowledge Archive as `diagnosis_patterns`, enabling cross-session learning.
1147
+
1148
+ ### 5.7 TOON Protocol (Token-Oriented Object Notation & Density Enforcement)
1149
+
1150
+ > **All agents, workflows, subagents, and tools in this system MUST enforce the TOON (Token-Oriented Object Notation v4.1) style for all structured data exchange, dialogue turns, task payloads, deliverables, and tabular summaries.**
1151
+
1152
+ Reference Specification: [TOON Specification v4.1 (toon-format/spec)](https://github.com/toon-format/spec)
1153
+
1154
+ #### 1. Core Motivation & 30-60% Token Savings
1155
+ Standard JSON and verbose markdown tables consume excessive tokens due to repeated field keys, curly braces, quotes, and whitespace padding. TOON achieves **30% to 60% token reduction** while preserving the full JSON data model, lossless round-trip decoding, and clean human readability.
1156
+
1157
+ #### 2. Structural Formatting Rules
1158
+ 1. **Uniform Object Arrays (Tabular Form §9.3)**:
1159
+ When transmitting lists of objects sharing the same fields, declare the field list once in the header, followed by delimiter-separated rows:
1160
+ ```toon
1161
+ users[2]{id,name,role}:
1162
+ 1,Ada,admin
1163
+ 2,Bob,user
1164
+ ```
1165
+ 2. **Primitive Arrays (Inline Form §9.1)**:
1166
+ Emit primitive sequences on a single header line:
1167
+ ```toon
1168
+ tags[3]: research,benchmark,evaluation
1169
+ ```
1170
+ 3. **Uniform Mappings (Keyed Tabular Form §9.5)**:
1171
+ Objects whose values share a uniform shape declare keys per row:
1172
+ ```toon
1173
+ services[2:]{port,status}:
1174
+ web: 8080,healthy
1175
+ db: 5432,healthy
1176
+ ```
1177
+ 4. **Hierarchical & Nested Objects (§8)**:
1178
+ Use 2-space indentation instead of braces; strings are quoted only when required (§7).
1179
+
1180
+ #### 3. Agent Communication & Deliverable Contracts
1181
+ - **Verification Logs & Quality Gate Reports**:
1182
+ ```toon
1183
+ verdict: PASS
1184
+ pacs_score: 92
1185
+ dimensions[3]{dimension,score,evidence}:
1186
+ faithfulness,95,"Aligned 100% with spec v4.1"
1187
+ completeness,90,"All edge cases and delimiters handled"
1188
+ logic,92,"Deterministic round-trip parity"
1189
+ ```
1190
+ - **Inter-Agent Task Payloads**:
1191
+ All subagents, teammates, and orchestrators exchange structured outputs via TOON.
1192
+ - **Native Runtime Adapters**:
1193
+ - Python: `core/engine_py/toon_adapter.py` (`encode_toon`, `decode_toon`, `format_conversation_turns`)
1194
+ - TypeScript/Bun: `src/engine_ts/toon-adapter.ts` (powered by `@toon-format/toon`)
1195
+
1196
+ ### 5.8 Supportive Tools Ecosystem & Sequential Operational Lifecycle Director
1197
+
1198
+ > **The workflow runtime automatically provisions supportive tools upon installation and directs their operation sequentially across every phase. The user never needs to manually decide when or how to invoke each supportive integration.**
1199
+
1200
+ #### 1. The 4 Foundation Supportive Tools
1201
+
1202
+ | Tool / Framework | Role & Categorization | Designated Lifecycle Phase |
1203
+ |---|---|---|
1204
+ | **Ponytail** (`DietrichGebert/ponytail`) | **Simplicity Governor & Anti-Bloat**<br>Enforces the lazy senior dev ladder (fewest files, shortest working diff, deletion over addition). | **Planning & Implementation** (Rung 1-3 in planning; Rung 4-7 in implementation; Anti-debt audit in verification) |
1205
+ | **TOON** (`toon-format/toon`) | **Token-Oriented Object Notation (v4.1)**<br>High-density tabular serialization saving 30-60% tokens. | **Continuous Protocol** across all data exchanges, deliverables, and state archives |
1206
+ | **Fable** (`imMamdouhaboammar/get-fable`) | **Autonomous Lifecycle Harness & Continuation**<br>Circuit breaker protection, multi-pass verification, and durable state handoffs (`.fable/state.json`). | **Harness & Continuation** (Circuit breaker during implementation; 3-pass verification; handoff compaction) |
1207
+ | **Caveman** (`JuliusBrussee/caveman`) | **Terse Communication Mode**<br>Cuts output tokens by 65-75% by eliminating pleasantries and conversational filler while preserving exact code and errors. | **Continuous Protocol** across agent thoughts, logs, and subagent coordination |
1208
+
1209
+ #### 2. The Sequential Operational Lifecycle
1210
+
1211
+ ```
1212
+ ┌─────────────────────────────────────────────────────────────────────────────┐
1213
+ │ AGENTIC WORKFLOW OPERATIONAL LIFECYCLE │
1214
+ ├─────────────────────────────────────────────────────────────────────────────┤
1215
+ │ CONTINUOUS PROTOCOL LAYER (Always Active): │
1216
+ │ • TOON Protocol (v4.1): Dense structured data, logs, & inter-agent state │
1217
+ │ • Caveman Mode: Ultra-terse, zero-slop agent dialogues & telemetry logs │
1218
+ ├─────────────────────────────────────────────────────────────────────────────┤
1219
+ │ PHASE 1: RESEARCH & DISCOVERY │
1220
+ │ • Skills Mesh Auto-Discovery: Resolve matching skills, tools & playbooks │
1221
+ │ • Fable Discover & Context Packets: Ground requirements in ground truth │
1222
+ │ • Output in TOON format to conserve context window for later phases │
1223
+ ├─────────────────────────────────────────────────────────────────────────────┤
1224
+ │ PHASE 2: ARCHITECTURE & PLANNING │
1225
+ │ • Ponytail Ladder (Rung 1-3): YAGNI check, stdlib-first, question whether │
1226
+ │ speculative scaffolding needs to exist. Strips over-engineering early! │
1227
+ │ • Fable Plan: Formulates verifiable plan with explicit success criteria │
1228
+ ├─────────────────────────────────────────────────────────────────────────────┤
1229
+ │ PHASE 3: PRODUCTION IMPLEMENTATION │
1230
+ │ • Ponytail Implementation (Rung 4-7): Shortest working diff, fewest files, │
1231
+ │ boring over clever, root-cause fix over symptom patches │
1232
+ │ • Fable Circuit Breaker: Tracks failure streaks, halts if streak >= 2 │
1233
+ ├─────────────────────────────────────────────────────────────────────────────┤
1234
+ │ PHASE 4: VERIFICATION & CLEAN CODE GUARD │
1235
+ │ • L0 Anti-Skip + L1 Verification + L1.5 pACS + L2 Review │
1236
+ │ • Ponytail Audit: Audits code for over-engineering debt & bloat │
1237
+ │ • Fable Multi-Pass Verification (Unit, Integration, Security/Taste) │
1238
+ ├─────────────────────────────────────────────────────────────────────────────┤
1239
+ │ PHASE 5: HANDOFF & CONTINUATION STATE │
1240
+ │ • Fable Handoff: Compacts state into .fable/state.json & PROGRESS.md │
1241
+ │ • TOON Serialization of run summary and audit ledger │
1242
+ └─────────────────────────────────────────────────────────────────────────────┘
1243
+ ```
1244
+
1245
+ #### 3. Automatic Provisioning & Dynamic Extensibility
1246
+ - **Automated Provisioning**: Running `./install.sh` or `agentic-workflow init` automatically verifies and provisions all supportive tools across `~/.claude`, `~/.gemini`, `~/.codex`, and `~/.agents`.
1247
+ - **Extensible Registry (`integrations.json`)**: Sibling tools can be added dynamically at any time without modifying core code:
1248
+ ```bash
1249
+ agentic-workflow integrations add <github-repo-url>
1250
+ ```
1251
+ - **Lifecycle Director Inspection**:
1252
+ ```bash
1253
+ agentic-workflow integrations status
1254
+ agentic-workflow integrations phase <planning|implementation|verification|handoff>
1255
+ ```
1256
+
1257
+ ---
1258
+
1259
+ ## 6. Skill System
1260
+
1261
+ ### workflow-generator
1262
+
1263
+ A skill that designs and generates the workflow definition file (`workflow.md`).
1264
+
1265
+ - **Triggers**: "Make a workflow," "design an automation pipeline," "define a task flow"
1266
+ - **Entry point**: `.claude/skills/workflow-generator/SKILL.md`
1267
+ - **Two cases**: (1) idea only → interactive Q&A, (2) description document available → document analysis first
1268
+
1269
+ ### doctoral-writing
1270
+
1271
+ A skill for writing with doctoral-level academic rigor and clarity.
1272
+
1273
+ - **Triggers**: "Write in thesis style," "academic writing," "polish paper sentences"
1274
+ - **Entry point**: `.claude/skills/doctoral-writing/SKILL.md`
1275
+ - **Core principles**: Clarity, conciseness, academic rigor, logical flow
1276
+
1277
+ ---
1278
+
1279
+ ## 7. Skill Development Rules
1280
+
1281
+ When creating a new skill or modifying an existing skill:
1282
+
1283
+ 1. **All Absolute Criteria must be included** — contextualized per domain (for non-code-change domains, Absolute Criterion 3 may be N/A)
1284
+ 2. **Role separation between files** — skill definition (WHY), reference material (WHAT/HOW/VERIFY)
1285
+ 3. **Explicitly specify conflict scenarios among the Absolute Criteria** — concrete field judgments, not abstract rules
1286
+ 4. **Mandatory reflection after modification** — do not merely insert wording; check for conflicts with existing content
1287
+
1288
+ ---
1289
+
1290
+ ## 8. Language and Style
1291
+
1292
+ - **Framework documents / user conversation**: Korean
1293
+ - **Workflow execution**: English (maximize AI performance — Absolute Criterion 1 basis). Details: §5.2
1294
+ - **Final deliverables**: English source + Korean translation pair
1295
+ - **Technical terminology**: Keep in English (SOT, Agent, Orchestrator, Hooks, etc.)
1296
+ - **Visualization**: Prefer Mermaid diagrams
1297
+ - **Narrative depth**: Prefer comprehensive, data-driven narration over brief summaries
1298
+ - **Code comments**: Korean (framework code) / English (workflow execution code)
1299
+
1300
+ ---
1301
+
1302
+ ## 9. Universal System-Prompt System (Hub-and-Spoke)
1303
+
1304
+ This project is designed so that **the same methodology is applied automatically regardless of which AI CLI tool is used**.
1305
+
1306
+ ### Architecture
1307
+
1308
+ ```
1309
+ AGENTS.md (Hub — methodology SOT)
1310
+ / | | \ \ \
1311
+ CLAUDE GEMINI .cursor .github/
1312
+ .md .md /rules copilot-
1313
+ (Spoke) instructions.md
1314
+ ```
1315
+
1316
+ - **Hub (AGENTS.md)**: Sole definition point for Absolute Criteria, design principles, and workflow structure
1317
+ - **Spoke (tool-specific files)**: Reference the Hub while providing implementation mappings tailored to each tool's own functionality
1318
+
1319
+ ### Tool File Mapping
1320
+
1321
+ | AI CLI Tool | System-Prompt File | Auto-Read | AGENTS.md Recognition |
1322
+ |-------------|--------------------|-----------|----------------------|
1323
+ | **Claude Code** | `CLAUDE.md` | Yes | Separate file |
1324
+ | **Gemini CLI** | `GEMINI.md` | Yes | Loaded additionally by config |
1325
+ | **Codex CLI** | `AGENTS.md` (directly) | Yes | Native |
1326
+ | **Copilot CLI** | `.github/copilot-instructions.md` | Yes | Auto-recognized |
1327
+ | **Cursor** | `.cursor/rules/agenticworkflow.mdc` | Yes (alwaysApply) | Recognized |
1328
+
1329
+ ### Spoke File Principles
1330
+
1331
+ 1. **Inline Absolute Criteria + reference details**: Each Spoke includes the core definitions of the Absolute Criteria (1-2 sentences) inline, and delegates the details to `AGENTS.md §2`.
1332
+ 2. **Tool implementation mapping**: Specifies the correspondence between the tool's own functionality (Hook, Agent, Plugin, etc.) and AgenticWorkflow concepts.
1333
+ 3. **Context Preservation alternatives**: For tools that cannot use Claude Code's Context Preservation System, guide to the alternatives available in that tool.
1334
+
1335
+ ### Conflict Resolution
1336
+
1337
+ > **AGENTS.md's Absolute Criteria take precedence over every Spoke.** When tool-dependent implementation conflicts with a principle, the principle wins.
1338
+
1339
+ ### Synchronization Upon Changes to the Absolute Criteria
1340
+
1341
+ When the Absolute Criteria in AGENTS.md change, every Spoke file's inline duplicates must also be synchronized:
1342
+ - `CLAUDE.md`, `GEMINI.md` — modify directly
1343
+ - `.cursor/rules/` — modify the inline portion
1344
+ - `.github/copilot-instructions.md` — modify the inline portion