opencode-wait-a-minute 0.0.0-stage → 1.1.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +318 -2
- package/index.js +1836 -0
- package/package.json +70 -4
- package/skills/codebase-design/SKILL.md +114 -0
- package/skills/design-contract/SKILL.md +27 -0
- package/skills/design-critique/SKILL.md +19 -0
- package/skills/design-system/SKILL.md +17 -0
- package/skills/design-system/references/image-analysis.md +14 -0
- package/skills/design-system/references/tokens.md +32 -0
- package/skills/design-system/references/ui-rules.md +14 -0
- package/skills/diagnosing-bugs/SKILL.md +138 -0
- package/skills/frontend-design/SKILL.md +36 -0
- package/skills/handoff/SKILL.md +16 -0
- package/skills/improve-codebase-architecture/SKILL.md +71 -0
- package/skills/linter-negative/SKILL.md +74 -0
- package/skills/no-slop-ui/SKILL.md +26 -0
- package/skills/prototype/SKILL.md +26 -0
- package/skills/registry.json +44087 -0
- package/skills/tastemaker/SKILL.md +8 -0
- package/skills/tastemaker/references/tastemaker.md +14 -0
- package/skills/tdd/SKILL.md +38 -0
- package/skills/visual-review/SKILL.md +103 -0
- package/skills/visual-review/references/review-gates.md +42 -0
- package/skills/visual-review/references/surface-archetypes.md +37 -0
- package/skills/wizard/SKILL.md +44 -0
- package/skills/writing-for-agents/SKILL.md +81 -0
- package/src/cognition/cognition-store.js +251 -0
- package/src/cognition/cognitive-state.js +126 -0
- package/src/cognition/hypothesis-manager.js +113 -0
- package/src/cognition/observation-engine.js +112 -0
- package/src/cognition/observation-provenance.js +268 -0
- package/src/context/active-context-boundary.js +68 -0
- package/src/context/assembly.js +494 -0
- package/src/context/assessment-rules.js +55 -0
- package/src/context/capsule-staleness.js +267 -0
- package/src/context/capsules.js +2 -0
- package/src/context/compare-array.js +98 -0
- package/src/context/compare-object.js +89 -0
- package/src/context/compare-values.js +42 -0
- package/src/context/context-assembly-contract.js +71 -0
- package/src/context/context-budget-manager.js +232 -0
- package/src/context/context-builder.js +49 -0
- package/src/context/context-cache.js +55 -0
- package/src/context/context-capture.js +243 -0
- package/src/context/context-classification.js +199 -0
- package/src/context/context-compaction.js +179 -0
- package/src/context/context-decision-audit.js +267 -0
- package/src/context/context-demotion.js +173 -0
- package/src/context/context-dictionary.js +106 -0
- package/src/context/context-drift-detection.js +225 -0
- package/src/context/context-evaluation.js +374 -0
- package/src/context/context-event-ingress.js +100 -0
- package/src/context/context-event-normalization.js +224 -0
- package/src/context/context-feedback-loop.js +216 -0
- package/src/context/context-freshness.js +21 -0
- package/src/context/context-graph-builder.js +71 -0
- package/src/context/context-graph.js +451 -0
- package/src/context/context-history-relevance.js +321 -0
- package/src/context/context-interception.js +145 -0
- package/src/context/context-invalidation-events.js +154 -0
- package/src/context/context-lifecycle.js +170 -0
- package/src/context/context-loop-prevention.js +347 -0
- package/src/context/context-manager.js +340 -0
- package/src/context/context-memory-layers.js +265 -0
- package/src/context/context-minimality.js +166 -0
- package/src/context/context-normalization.js +130 -0
- package/src/context/context-optimization-metrics.js +434 -0
- package/src/context/context-output-policy.js +135 -0
- package/src/context/context-pack-authority.js +157 -0
- package/src/context/context-promotion.js +172 -0
- package/src/context/context-query-contract.js +101 -0
- package/src/context/context-ranking.js +164 -0
- package/src/context/context-rate-distortion.js +261 -0
- package/src/context/context-recovery.js +209 -0
- package/src/context/context-retrieval-integration.js +60 -0
- package/src/context/context-retrieval.js +93 -0
- package/src/context/context-router.js +457 -0
- package/src/context/context-routing-evaluation.js +331 -0
- package/src/context/context-routing-observability.js +296 -0
- package/src/context/context-routing-shadow.js +237 -0
- package/src/context/context-scope.js +181 -0
- package/src/context/context-snapshot.js +226 -0
- package/src/context/context-source-registry.js +95 -0
- package/src/context/context-sufficiency-gate.js +120 -0
- package/src/context/context-sufficiency-oracle.js +167 -0
- package/src/context/context-telemetry.js +176 -0
- package/src/context/context.js +633 -0
- package/src/context/dependency-closure.js +246 -0
- package/src/context/page-fault-tracker.js +275 -0
- package/src/context/prompt-engine.js +74 -0
- package/src/context/runtime-context-graph.js +260 -0
- package/src/context/selection.js +2 -0
- package/src/context/session.js +2 -0
- package/src/context/sufficiency-contract.js +300 -0
- package/src/context/tokenizer.js +17 -0
- package/src/context-benchmark-router.mjs +125 -0
- package/src/evidence/evidence-engine.js +161 -0
- package/src/evidence/evidence-factory.js +3 -0
- package/src/evidence/evidence-freshness.js +463 -0
- package/src/evidence/evidence-gap.js +76 -0
- package/src/evidence/evidence-lineage.js +525 -0
- package/src/evidence/evidence.js +136 -0
- package/src/evidence/freshness-validation.js +187 -0
- package/src/evidence/lineage.js +4 -0
- package/src/execution/action-evaluation.js +179 -0
- package/src/execution/circuit-breaker.js +70 -0
- package/src/execution/claim-interception.js +63 -0
- package/src/execution/execution-engine.js +258 -0
- package/src/execution/execution-intent.js +69 -0
- package/src/execution/execution-state.js +89 -0
- package/src/execution/formatting.js +60 -0
- package/src/execution/l1-sanitize.js +16 -0
- package/src/execution/l2-resource-guards.js +19 -0
- package/src/execution/l3-invariant-checker.js +5 -0
- package/src/execution/l4-containment.js +6 -0
- package/src/execution/runtime-guards.js +106 -0
- package/src/execution/strategy-identity.js +162 -0
- package/src/execution/tool-interceptor.js +7 -0
- package/src/execution/tool-result-classifier.js +63 -0
- package/src/integration/canary-deploy.js +143 -0
- package/src/integration/collector.js +59 -0
- package/src/integration/error-recovery.js +6 -0
- package/src/integration/event-bus.js +66 -0
- package/src/integration/health-checker.js +57 -0
- package/src/integration/logger.js +39 -0
- package/src/integration/message-handler.js +611 -0
- package/src/integration/opencode-db.js +153 -0
- package/src/integration/orchestration.js +419 -0
- package/src/integration/part-provenance.js +65 -0
- package/src/integration/rate-limiter.js +55 -0
- package/src/integration/release-gate.js +336 -0
- package/src/integration/rollback-manager.js +164 -0
- package/src/integration/router-adapter.js +269 -0
- package/src/integration/telemetry.js +45 -0
- package/src/integration/update-checker.js +10 -0
- package/src/persistence/event-sourcing.js +75 -0
- package/src/persistence/memory.js +501 -0
- package/src/persistence/migration-runner.js +16 -0
- package/src/persistence/persistence-manager.js +39 -0
- package/src/persistence/transaction-log.js +157 -0
- package/src/policy/action-capabilities.js +116 -0
- package/src/policy/action-policy.js +4 -0
- package/src/policy/assessment-engine.js +104 -0
- package/src/policy/assumption-tracking.js +66 -0
- package/src/policy/budget-enforcer.js +7 -0
- package/src/policy/config-validator.js +102 -0
- package/src/policy/execution-assessment.js +142 -0
- package/src/policy/failure-classification.js +5 -0
- package/src/policy/feature-flags.js +65 -0
- package/src/policy/governance-enforcement.js +118 -0
- package/src/policy/locale.js +15 -0
- package/src/policy/multi-signer.js +151 -0
- package/src/policy/policy-state-machine.js +97 -0
- package/src/policy/ponytail-constraint.js +38 -0
- package/src/policy/project-inspector.js +93 -0
- package/src/policy/query-builder.js +14 -0
- package/src/policy/request-classifier.js +79 -0
- package/src/policy/risk-engine.js +266 -0
- package/src/policy/scope-enforcement.js +140 -0
- package/src/policy/secret-scanner.js +68 -0
- package/src/policy/skill-routing.js +104 -0
- package/src/policy/strategy-capabilities.js +211 -0
- package/src/policy/strategy.js +6 -0
- package/src/policy/uncertainty.js +117 -0
- package/src/shared/container.js +44 -0
- package/src/shared/decision-types.js +24 -0
- package/src/shared/simple-test.js +160 -0
- package/src/shared/wam-events.js +52 -0
- package/src/skills/engine.js +1705 -0
- package/src/skills/skill-registry.js +19 -0
- package/src/skills/skill-routing.js +340 -0
- package/src/state/lifecycle-manager.js +113 -0
- package/src/state/operational-state.js +198 -0
- package/src/state/projections.js +47 -0
- package/src/state/replay-engine.js +5 -0
- package/src/state/requirement-ownership.js +20 -0
- package/src/state/requirement-state.js +152 -0
- package/src/state/run-event-identity.js +172 -0
- package/src/state/state-engine.js +19 -0
- package/src/state/state-machine.js +119 -0
- package/src/state/state-schema.js +318 -0
- package/src/state/state-store.js +335 -0
- package/src/state/state-transition.js +84 -0
- package/src/state/task-dependencies.js +287 -0
- package/src/state/task-execution.js +217 -0
- package/src/state/task-lifecycle.js +59 -0
- package/src/state/task-runs.js +361 -0
- package/src/state/task-state-file.js +86 -0
- package/src/state/task-state.js +41 -0
- package/src/state/task-status.js +54 -0
- package/src/state/task-store.js +48 -0
- package/src/state/wam-state.js +148 -0
- package/src/verification/completion-gate-simple.js +8 -0
- package/src/verification/completion-gate.js +183 -0
- package/src/verification/contract.js +9 -0
- package/src/verification/contradiction-resolution.js +255 -0
- package/src/verification/diagnostic-engine.js +659 -0
- package/src/verification/false-completion-prevention.js +100 -0
- package/src/verification/hook-validator.js +6 -0
- package/src/verification/requirements.js +6 -0
- package/src/verification/verification-context.js +162 -0
- package/src/verification/verification-lifecycle.js +66 -0
- package/src/verification/verification-model.js +89 -0
- package/src/verification/verification-persistence.js +129 -0
- package/src/verification/verification-policy.js +127 -0
- package/src/verification/verification.js +415 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Tastemaker
|
|
2
|
+
|
|
3
|
+
## Definition
|
|
4
|
+
Tastemaker is the curatorial layer that ensures the UI isn't just "correct" (functional/accessible) but "refined" (high taste/premium feel).
|
|
5
|
+
|
|
6
|
+
## Taste Profiles
|
|
7
|
+
- **Minimalist**: Max whitespace, monochromatic with 1 accent, extreme typographic hierarchy.
|
|
8
|
+
- **Enterprise**: Compact density, high utility, strict alignment, neutral palette.
|
|
9
|
+
- **Playful**: Bold colors, softer radii, micro-animations, asymmetrical elements.
|
|
10
|
+
|
|
11
|
+
## Application Process
|
|
12
|
+
1. **Profile Selection**: Identify the desired taste profile for the project.
|
|
13
|
+
2. **Audit**: Review current UI against profile characteristics.
|
|
14
|
+
3. **Refine**: Adjust tokens (spacing, radii, color contrast) to align with the profile.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tdd
|
|
3
|
+
description: Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Test-Driven Development
|
|
7
|
+
|
|
8
|
+
TDD is the red → green loop. This skill is the reference that makes that loop produce tests worth keeping: what a good test is, where tests go, the anti-patterns, and the rules of the loop. Every section applies on every cycle: consult them before and during the loop, not after.
|
|
9
|
+
|
|
10
|
+
When exploring the codebase, read `GLOSSARY.md` (if it exists) so test names and interface vocabulary match the project's domain language, and respect ADRs in the area you're touching.
|
|
11
|
+
|
|
12
|
+
## What a good test is
|
|
13
|
+
|
|
14
|
+
Tests verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't. A good test reads like a specification: "user can checkout with valid cart" tells you exactly what capability exists, and it survives refactors because it doesn't care about internal structure.
|
|
15
|
+
|
|
16
|
+
See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.
|
|
17
|
+
|
|
18
|
+
## Seams: where tests go
|
|
19
|
+
|
|
20
|
+
A **seam** is the public boundary you test at: the interface where you observe behavior without reaching inside. Tests live at seams, never against internals.
|
|
21
|
+
|
|
22
|
+
**Test only at pre-agreed seams.** Before writing any test, write down the seams under test and confirm them with the user. No test is written at an unconfirmed seam. You can't test everything, so agreeing the seams up front is how testing effort lands on the critical paths and complex logic instead of every edge case.
|
|
23
|
+
|
|
24
|
+
Ask: "What's the public interface, and which seams should we test?" Give each proposed seam a one-line note on what it catches and what it misses.
|
|
25
|
+
|
|
26
|
+
When the shape of that interface is itself in question (how deep the module is, where the seam belongs, what the interface should expose), call the Skill tool with "codebase-design" for the vocabulary. It is the shared source of the module, interface, depth, seam, adapter, leverage and locality terms, and it is a reference to consult, not a session to run.
|
|
27
|
+
|
|
28
|
+
## Anti-patterns
|
|
29
|
+
|
|
30
|
+
- **Implementation-coupled**: mocks internal collaborators, tests private methods, or verifies through a side channel (querying the database instead of using the interface). The tell: the test breaks when you refactor but behavior hasn't changed.
|
|
31
|
+
- **Tautological**: the assertion recomputes the expected value the way the code does (`expect(add(a, b)).toBe(a + b)`, a snapshot derived by hand the same way, a constant asserted equal to itself), so it passes by construction and can never disagree with the code. Expected values must come from an independent source of truth: a known-good literal, a worked example, the spec.
|
|
32
|
+
- **Horizontal slicing**: writing all tests first, then all implementation. Bulk tests verify _imagined_ behavior: you test the _shape_ of things rather than user-facing behavior, the tests go insensitive to real changes, and you commit to test structure before understanding the implementation. Work in **vertical slices** instead: one test → one implementation → repeat, each test a **tracer bullet** that responds to what the last cycle taught you.
|
|
33
|
+
|
|
34
|
+
## Rules of the loop
|
|
35
|
+
|
|
36
|
+
- **Red before green.** Write the failing test first, then only enough code to pass it. Don't anticipate future tests or add speculative features.
|
|
37
|
+
- **One slice at a time.** One seam, one test, one minimal implementation per cycle.
|
|
38
|
+
- **Refactoring is not part of the loop.** It belongs to the review stage (see the `code-review` skill), not the red → green implementation cycle.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: design-visual-frontend
|
|
3
|
+
description: Design, build, redesign, or critically review distinctive frontend interfaces with strong composition, domain authenticity, responsive behavior, component coherence, and browser-verified visual quality. Use for websites, landing pages, login and form flows, dashboards, admin tools, product pages, portfolios, visual UI reviews, anti-template redesigns, or any request where frontend aesthetics and usability both matter.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Design Visual Frontend
|
|
7
|
+
|
|
8
|
+
Create frontend UI whose composition, content, and interaction fit the actual subject and user task. Do not treat visual quality as a list of fashionable effects. Diagnose the page structure first, implement from a compact design decision sheet, and verify rendered evidence across the required viewports.
|
|
9
|
+
|
|
10
|
+
## Core Workflow
|
|
11
|
+
|
|
12
|
+
1. Inspect the brief, existing project, assets, stack, and user-provided references.
|
|
13
|
+
2. Classify the dominant surface using `references/surface-archetypes.md`.
|
|
14
|
+
3. Write the compact decision sheet below before UI code.
|
|
15
|
+
4. Read only the references routed by the task.
|
|
16
|
+
5. Build from tokens and reusable component rules.
|
|
17
|
+
6. When browser tooling is available, render the real page at the viewport matrix below and inspect the result visually.
|
|
18
|
+
7. Apply every hard gate in `references/review-gates.md`; rebuild when a gate fails.
|
|
19
|
+
8. Verify interaction, focus, errors, loading, reduced motion, and realistic content. When browser tooling is unavailable, inspect the implementation and give the user a concise manual visual-check list instead of claiming rendered verification.
|
|
20
|
+
|
|
21
|
+
For reviews or diagnosis requests, stop after evidence-backed findings unless the user also asks for changes.
|
|
22
|
+
|
|
23
|
+
## Compact Decision Sheet
|
|
24
|
+
|
|
25
|
+
Keep this short. It is a decision artifact, not a design essay.
|
|
26
|
+
|
|
27
|
+
1. `Surface`: archetype, primary user, and single primary job.
|
|
28
|
+
2. `P1 / P2 / P3 / Action`: first read, supporting context, proof/detail, and next action.
|
|
29
|
+
3. `Content truth`: real assets/data, user-provided content, public facts, or omitted claims.
|
|
30
|
+
4. `Composition`: one mobile and one wide ASCII wireframe with named region roles.
|
|
31
|
+
5. `System`: palette roles, type roles, spacing rhythm, radius, border/elevation, icon family.
|
|
32
|
+
6. `Signature`: one subject-specific memorable device and why it belongs.
|
|
33
|
+
7. `Cliche budget`: generic visual motifs used; one may be used without special justification, while additional motifs need distinct subject-specific jobs.
|
|
34
|
+
8. `Failure risks`: the two most likely structural failures and how browser evidence will detect them.
|
|
35
|
+
|
|
36
|
+
If the task is open-ended and a materially different composition could better serve the user, compare two directions. They must differ in protagonist, region roles, evidence, and interaction attitude. Do not generate directions that differ only in palette or decoration. Ask the user to choose only when the alternatives change the product relationship or brand position; otherwise select using brief evidence and proceed.
|
|
37
|
+
|
|
38
|
+
## Reference Routing
|
|
39
|
+
|
|
40
|
+
Always read:
|
|
41
|
+
|
|
42
|
+
- `references/core-design.md`
|
|
43
|
+
- `references/surface-archetypes.md`
|
|
44
|
+
- `references/review-gates.md`
|
|
45
|
+
|
|
46
|
+
Read when applicable:
|
|
47
|
+
|
|
48
|
+
- Forms, controls, dashboards, navigation, UI copy, or state: `references/components-content.md`
|
|
49
|
+
- Recognizable industry or institution: `references/domain-guidance.md`
|
|
50
|
+
- Frontend implementation or browser verification: `references/frontend-implementation.md`
|
|
51
|
+
|
|
52
|
+
Do not load every reference by default. Avoid re-reading a reference already read in the current task unless the design changes substantially.
|
|
53
|
+
|
|
54
|
+
## Hard Composition Rules
|
|
55
|
+
|
|
56
|
+
- The dominant user job determines the protagonist. A login page foregrounds authentication; a dashboard foregrounds state and actions; a product page foregrounds the product.
|
|
57
|
+
- Every major desktop region must have a functional, evidentiary, narrative, or perceptual role.
|
|
58
|
+
- A full-height divider is a strong visual object. Use it only when both sides are meaningful peers or interaction crosses the boundary. Do not divide marketing atmosphere from a small task panel.
|
|
59
|
+
- On wide screens, fixed-width content must not become stranded inside expanding empty fields.
|
|
60
|
+
- For compact task surfaces such as login, search, booking, and checkout, keep required inputs and the primary action visible at `390x844` when the task length permits.
|
|
61
|
+
- Brand display type, illustrations, ambient motion, or product marks must not outweigh the active task on task-led screens.
|
|
62
|
+
- Use one leading signature device. Grids, particles, giant rings, neon glow, pseudo-terminal text, glass, bento grids, huge type, noise, and decorative telemetry are generic motifs, not evidence of a subject.
|
|
63
|
+
- Treat one generic motif as the default budget. Additional motifs must perform different, visible content or interaction jobs and must be supported by the brief; otherwise remove them.
|
|
64
|
+
- Never use fake metrics, testimonials, logos, legal identifiers, certifications, contact details, screenshots, or operational data to make a design feel credible.
|
|
65
|
+
|
|
66
|
+
## Visual Verification Matrix
|
|
67
|
+
|
|
68
|
+
When browser automation or browser control is available, capture and inspect the actual rendered UI:
|
|
69
|
+
|
|
70
|
+
| Viewport | Required use |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `390x844` | Mobile order, task visibility, touch targets, wrapping |
|
|
73
|
+
| `768x1024` | Tablet transition and intermediate breakpoints |
|
|
74
|
+
| `1440x900` | Standard desktop composition |
|
|
75
|
+
| `1920x1080` | Wide desktop space roles |
|
|
76
|
+
| `2560x1080` | Required for full-bleed, split-screen, fixed-width, or cinematic layouts |
|
|
77
|
+
|
|
78
|
+
The `2560x1080` check cannot be replaced by a `1440px` screenshot. Wide-screen failures often remain invisible at standard desktop sizes.
|
|
79
|
+
|
|
80
|
+
Use browser automation or browser control already available in the environment. Prefer a real viewport API over browser window sizing. Inspect screenshots at 100% scale and interact with the page rather than judging HTML alone.
|
|
81
|
+
|
|
82
|
+
Do not install a browser, automation framework, runtime, or audit dependency solely to satisfy this skill unless the user asks for it. If no browser capability is available, state that rendered visual verification was not performed and hand the viewport matrix to the user for manual inspection.
|
|
83
|
+
|
|
84
|
+
## Implementation Contract
|
|
85
|
+
|
|
86
|
+
- Preserve the existing stack and local patterns when present.
|
|
87
|
+
- Encode choices as tokens or reusable classes/components.
|
|
88
|
+
- Use one icon family and accessible controls.
|
|
89
|
+
- Provide real states: default, hover, focus, active, disabled, loading, error, empty, permission, or offline where relevant.
|
|
90
|
+
- Keep visible copy inside the product's world. Put implementation notes in comments or delivery notes.
|
|
91
|
+
- Respect reduced motion and avoid expensive continuous effects.
|
|
92
|
+
- Do not substitute static linting, source inspection, or an accessibility checklist for visual browser evidence.
|
|
93
|
+
|
|
94
|
+
## Completion Standard
|
|
95
|
+
|
|
96
|
+
Do not declare completion when any hard gate fails. Do not average severe problems into a passing score. The weakest critical dimension controls readiness.
|
|
97
|
+
|
|
98
|
+
Report:
|
|
99
|
+
|
|
100
|
+
- what was built or reviewed;
|
|
101
|
+
- which viewports and interactions were verified, or which require manual inspection because browser tooling was unavailable;
|
|
102
|
+
- the weakest remaining dimension and its visible evidence;
|
|
103
|
+
- any limitation that could not be tested.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Review Gates
|
|
2
|
+
|
|
3
|
+
Apply these gates to browser evidence when browser tooling is available. They are non-compensating: one failed critical gate means the design is not ready, regardless of strengths elsewhere. When browser tooling is unavailable, use the gates to identify implementation risks, clearly label them as unverified, and hand them to the user for manual visual inspection.
|
|
4
|
+
|
|
5
|
+
## Gate A: Five-Second Clarity
|
|
6
|
+
|
|
7
|
+
At each required viewport, identify:
|
|
8
|
+
|
|
9
|
+
- what the surface is;
|
|
10
|
+
- who or what it belongs to;
|
|
11
|
+
- the primary subject/job;
|
|
12
|
+
- the next action or continuation.
|
|
13
|
+
|
|
14
|
+
Fail when decoration, a logo, a giant headline, or empty space delays the answer on a task, command, inspection, or conversion surface.
|
|
15
|
+
|
|
16
|
+
## Gate B: Protagonist and Action
|
|
17
|
+
|
|
18
|
+
The protagonist must match the surface archetype. The primary action must read as part of the same visual event.
|
|
19
|
+
|
|
20
|
+
Task-led hard checks:
|
|
21
|
+
|
|
22
|
+
- short tasks show required inputs and primary action at `390x844`;
|
|
23
|
+
- the task remains the strongest working object at desktop and wide desktop;
|
|
24
|
+
- brand or atmosphere does not receive more visual weight than the task.
|
|
25
|
+
|
|
26
|
+
## Gate C: Spatial Completion
|
|
27
|
+
|
|
28
|
+
Name the role of every major region at `1440`, `1920`, and `2560` when applicable.
|
|
29
|
+
|
|
30
|
+
Fail when:
|
|
31
|
+
|
|
32
|
+
- a fixed panel is surrounded by expanding unused fields;
|
|
33
|
+
- cropping the outer 25% removes no meaningful context;
|
|
34
|
+
- a full-height divider becomes the strongest vertical object without representing real peer regions;
|
|
35
|
+
- large gutters have no functional, evidentiary, narrative, or perceptual consequence.
|
|
36
|
+
|
|
37
|
+
## Gate D: Cliche Budget and Authenticity
|
|
38
|
+
|
|
39
|
+
Count generic motifs: grid, particles, giant ring, neon glow, pseudo-terminal, glass, noise, bento, huge headline, decorative telemetry.
|
|
40
|
+
|
|
41
|
+
- `0-1`: acceptable when coherent with the surface archetype.
|
|
42
|
+
- `2+`: fail, regardless of aesthetic execution.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Surface Archetypes
|
|
2
|
+
|
|
3
|
+
Choose the dominant archetype from the user's primary job. Mixed pages may contain secondary archetypes, but the first viewport needs one leader.
|
|
4
|
+
|
|
5
|
+
## Task-Led
|
|
6
|
+
|
|
7
|
+
Examples: login, signup, checkout, booking, search, upload, application, submission, recovery.
|
|
8
|
+
|
|
9
|
+
Protagonist: the task, its context, and current state.
|
|
10
|
+
|
|
11
|
+
Required regions:
|
|
12
|
+
|
|
13
|
+
- inputs, selectors, or provider actions;
|
|
14
|
+
- selected account, organization, product, appointment, or target when relevant;
|
|
15
|
+
- primary action and recovery path;
|
|
16
|
+
- error, denied, locked, loading, success, and retry states as appropriate;
|
|
17
|
+
- support, policy, device, session, deadline, or consequence context when useful.
|
|
18
|
+
|
|
19
|
+
## Command-Led
|
|
20
|
+
|
|
21
|
+
Examples: dashboards, admin tools, monitors, editors, operational consoles.
|
|
22
|
+
|
|
23
|
+
Protagonist: current state plus available action.
|
|
24
|
+
|
|
25
|
+
Required regions: orientation, toolbar, filters, status, data/table/chart, selection, detail, feedback.
|
|
26
|
+
|
|
27
|
+
## Inspection-Led
|
|
28
|
+
|
|
29
|
+
Examples: product details, report preview, documentation, article, portfolio item, profile, invoice.
|
|
30
|
+
|
|
31
|
+
Protagonist: the entity, its data, and its story.
|
|
32
|
+
|
|
33
|
+
## Conversion-Led
|
|
34
|
+
|
|
35
|
+
Examples: landing pages, product overview, services page, marketing home.
|
|
36
|
+
|
|
37
|
+
Protagonist: the value proposition and the call to action.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wizard
|
|
3
|
+
description: Generate an interactive bash wizard that walks a human through steps only they can perform. Use when provisioning infrastructure, setting up credentials or CI secrets, walking an unfamiliar third-party dashboard, or running a one-off migration or cutover. Don't invoke this for steps the agent can perform itself.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Wizard
|
|
7
|
+
|
|
8
|
+
A **wizard** is a bash script that walks a human, step by step, through a manual procedure that's tedious to do by hand and tedious to re-explain to an AI every time. It opens each URL, says exactly what to click and copy, captures the values, writes them where they belong (`.env`, GitHub secrets), confirms at every stage, and shows how many stages are left. It might configure third-party services, run a one-off migration, or move the project from one state to another.
|
|
9
|
+
|
|
10
|
+
The delightful UX is already solved by [template.sh](template.sh): stage-by-stage progress, confirmation gates, cross-platform URL opening (including WSL), hidden secret entry, idempotent `.env` upserts, `gh secret`/`gh variable` writes, and a closing summary. **Your job is only to scope the procedure and author its stages.** The library above the `STAGES` marker is identical in every wizard; that consistency is the point: never hand-edit it.
|
|
11
|
+
|
|
12
|
+
A wizard is ephemeral by default: built for one run, saved to a scratch or `scripts/` path, deleted when the job's done. Commit it only when the user wants a repeatable setup path that should live in the repo.
|
|
13
|
+
|
|
14
|
+
## Process
|
|
15
|
+
|
|
16
|
+
### 1. Scope the procedure
|
|
17
|
+
|
|
18
|
+
Work out every manual step the human must take and every value that gets captured along the way. Read the repo first, don't ask cold:
|
|
19
|
+
|
|
20
|
+
- For setup: `.env`, `.env.example`, `.env.*`, `README`, `docker-compose*`, framework config, and `.github/workflows/*` (every `secrets.*` / `vars.*` reference is a value the wizard must produce).
|
|
21
|
+
- For a migration or transition: the current state, the target state, and the irreversible actions between them.
|
|
22
|
+
|
|
23
|
+
Then show the user the ordered list of stages and the values each produces, and confirm: they may add, drop, or reorder.
|
|
24
|
+
|
|
25
|
+
**Done when:** every stage is named in order, and for each captured value you know (a) where the human gets it, (b) where it's written (`.env`, a GitHub secret, both, or nowhere; some stages are pure actions), and (c) whether it's secret (hidden entry) or public.
|
|
26
|
+
|
|
27
|
+
### 2. Map each stage's journey
|
|
28
|
+
|
|
29
|
+
For each stage, write the precise path a human follows: which URL to open, what to do there, where a value is shown, which variable it fills: e.g. "Dashboard → Developers → API keys → Reveal test key → copy". Where you don't actually know the current UI or the exact command, say so and ask the user or check the docs: never invent steps that may not exist.
|
|
30
|
+
|
|
31
|
+
**Done when:** every stage traces to concrete instructions a stranger could follow.
|
|
32
|
+
|
|
33
|
+
### 3. Author the wizard
|
|
34
|
+
|
|
35
|
+
Copy `template.sh` to the target path. Replace the example stage with one `stage` per step, in dependency order. Use the library helpers: `stage`, `say`/`step`, `open_url`, `ask`/`ask_secret`, `write_env`, `set_secret`/`set_var`, `pause`/`confirm`. Set `TOTAL_STAGES` to the number of stages you wrote.
|
|
36
|
+
|
|
37
|
+
Hold the bar the template sets: open the URL before asking for its value, use `ask_secret` for anything secret, `write_env` every persisted value, `set_secret` only the values CI actually needs, and `confirm` before any irreversible action. Each `stage` clears the screen so only the current step is visible: keep a stage to one focused task so nothing the human needs scrolls away. Don't touch the library above the marker.
|
|
38
|
+
|
|
39
|
+
### 4. Verify and hand off
|
|
40
|
+
|
|
41
|
+
- `bash -n <script>`; run `shellcheck` if available.
|
|
42
|
+
- `chmod +x <script>`.
|
|
43
|
+
- Don't run it end-to-end yourself: it opens browsers and blocks on human input. Trace it statically instead: every value from step 1 is captured and lands where step 1 said, and every `set_secret` name exactly matches a `secrets.*` reference in CI.
|
|
44
|
+
- Tell the user how to run it. If it's a repeatable setup path, commit it and link it from the README so the next person runs the script instead of asking an AI.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: writing-for-agents
|
|
3
|
+
description: Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Reference for writing any document an agent consumes: a skill, an `AGENTS.md` / `CLAUDE.md`, a doc reached by a pointer. The packaging differs; the writing does not: the same levers make each one predictable, since the agent takes the same _process_ every run rather than producing the same output.
|
|
7
|
+
|
|
8
|
+
When the document you're writing is a skill, read [`SKILL-MECHANICS.md`](SKILL-MECHANICS.md) for frontmatter, invocation choice, and router skills.
|
|
9
|
+
|
|
10
|
+
## Context pointers
|
|
11
|
+
|
|
12
|
+
A **context pointer** is a reference held in the agent's context that names some out-of-context material and encodes the condition for reaching it. A skill's description is one; a line in `AGENTS.md` naming a doc is the same object. The pointer's _wording_, not its target, decides when the agent reaches the material, and how reliably. A must-have target behind a weakly worded pointer is a variance bug: sharpen the wording first, and inline the material only if sharpening fails.
|
|
13
|
+
|
|
14
|
+
A pointer does two jobs: state what the material is, and list the **branches** that should trigger reaching it (a branch is a distinct case the document handles, so different runs take different paths through it). Every word of an always-loaded pointer costs on every turn, so it earns even harder pruning than the body:
|
|
15
|
+
|
|
16
|
+
- **Front-load the leading word**: the pointer is where it does its triggering work.
|
|
17
|
+
- **One trigger per branch.** Synonyms that rename a single branch are one branch written twice; collapse them and keep only genuinely distinct branches.
|
|
18
|
+
- **Cut identity the body already carries.**
|
|
19
|
+
|
|
20
|
+
## The two loads
|
|
21
|
+
|
|
22
|
+
Every document and pointer you add spends one of two budgets:
|
|
23
|
+
|
|
24
|
+
- **Context load** is the cost of always-loaded material on the agent's window: an `AGENTS.md` line, a skill description, anything sitting in context every turn, spending tokens and attention whether or not it fires.
|
|
25
|
+
- **Cognitive load** is the cost on the human: which documents exist and when to reach for each. The human is the index. Not a cost to minimise: it is the price of human agency; spend it where human judgement matters, remove it where it does not.
|
|
26
|
+
|
|
27
|
+
Material reached only through a pointer escapes context load at the price of the pointer's own line; material with no pointer at all rides entirely on cognitive load.
|
|
28
|
+
|
|
29
|
+
## Information hierarchy
|
|
30
|
+
|
|
31
|
+
A document is built from two content types: **steps** (the ordered actions the agent performs) and **reference** (definitions, rules, facts consulted on demand). The two mix freely: all steps (a recipe), all reference (a review's rules, this skill), or both. The core decision is where each piece sits on the **information hierarchy**, a ladder ranked by how immediately the agent needs the material:
|
|
32
|
+
|
|
33
|
+
1. **In-file step** is the primary tier: what the agent does, in order.
|
|
34
|
+
2. **In-file reference** is consulted on demand. Often a legitimately flat peer-set (every rule of a review on one rung), which is a fine arrangement, not a smell.
|
|
35
|
+
3. **Disclosed reference** is pushed out into a separate file, reached by a context pointer, loaded only when the pointer fires. Spans a sibling file in the same folder through fully external reference that lives anywhere and any document can point at.
|
|
36
|
+
|
|
37
|
+
Push too little down and the top bloats; push too much and you hide material the agent actually needs. That tension is the whole decision.
|
|
38
|
+
|
|
39
|
+
**Progressive disclosure** is the move down the ladder (out of the main file and behind a pointer) so the top stays legible. Not primarily a token optimisation: it is how the hierarchy is protected. Branching is the cleanest disclosure test: inline what every branch needs, and push behind a pointer what only some branches reach. When a document has steps, in-file reference that should be disclosed buries them and turns attending to them into a coin-flip: a variance lever, not just a legibility one.
|
|
40
|
+
|
|
41
|
+
**Co-location** is the within-file companion: where the ladder decides _how far down_ a piece sits, co-location decides _what sits beside it_ once there. Keep a concept's definition, rules, and caveats under one heading rather than scattered, so reading one part brings its neighbours with it. The test: the document should read like documentation written for the agent. Grouped material reads that way; scattered material does not. (Distinct from duplication: that repeats one meaning in two places; scattering fragments one meaning across many.)
|
|
42
|
+
|
|
43
|
+
**Sprawl** is the failure mode here: a document simply too long, even when every line is live and unique. Attention thins across the excess, and every extra line is one more to keep relevant. The cure is the ladder: disclose reference behind pointers, and split by branch or sequence so each path carries only what it needs.
|
|
44
|
+
|
|
45
|
+
## Steps and completion criteria
|
|
46
|
+
|
|
47
|
+
Every step ends on a **completion criterion**, the condition that tells the agent the work is done. Two properties make it a lever:
|
|
48
|
+
|
|
49
|
+
- **Clarity**: can the agent tell done from not-done? A vague bound ("understanding reached") invites **premature completion**: ending the step before it is genuinely done, attention slipping to _being done_. The visible steps still ahead (the **post-completion steps**) supply the pull; the criterion's clarity is the resistance. Defend in order: **sharpen the bound first** (local and cheap); only if it is irreducibly fuzzy _and_ you observe the rush, hide the later steps by splitting the sequence. Hiding only works across a real context boundary (a hand-off or a subagent dispatch; an inline call leaves the later steps in context and clears nothing).
|
|
50
|
+
- **Demand**: how much it requires. "Every modified model accounted for" forces thorough work where "produce a change list" does not. Demand drives **legwork** (the digging the agent does within the work, latent in the wording rather than written as its own step), and it is not step-bound: "every rule applied" binds a body of flat reference just as "every step done" binds a sequence, which is how an all-reference document still carries an exhaustiveness bar.
|
|
51
|
+
|
|
52
|
+
The strongest criteria are both checkable and exhaustive.
|
|
53
|
+
|
|
54
|
+
## When to split
|
|
55
|
+
|
|
56
|
+
Splitting one document into two spends one of the two loads, so split only when the cut earns it:
|
|
57
|
+
|
|
58
|
+
- **By sequence**: split a run of steps where the post-completion steps tempt the agent to rush the one in front of it. Keeping them out of view drives more legwork on the current task. Beware the reverse: merging sequences exposes each step's later steps to what follows, inviting premature completion.
|
|
59
|
+
- **By invocation**, skill-specific: see [`SKILL-MECHANICS.md`](SKILL-MECHANICS.md).
|
|
60
|
+
|
|
61
|
+
## Leading words
|
|
62
|
+
|
|
63
|
+
A **leading word** is a compact concept already living in the model's pretraining that the agent thinks with while running the document (_lesson_, _fog of war_, _tracer bullets_). Repeated as a token, never as a sentence, it accumulates a distributed definition and anchors a whole region of behaviour in the fewest tokens, by recruiting priors the model already holds. Coining your own works if you define it clearly, but a made-up word recruits no priors: you pay in definition tokens what a pretrained word gives free; reach for an existing word first.
|
|
64
|
+
|
|
65
|
+
It anchors twice. In the body, _execution_: the agent reaches for the same behaviour every time the word appears, and inside flat reference it focuses attention on a class of thing to look for. In a pointer, _invocation_: when the same word lives in your prompts, your docs, and your codebase, the agent links that shared language to the material and reaches it more reliably.
|
|
66
|
+
|
|
67
|
+
Hunt for opportunities to refactor with leading words. A triad spelled out at three sites, a pointer spending a sentence to gesture at one idea. Each is a passage begging to collapse into a single token:
|
|
68
|
+
|
|
69
|
+
- "fast, deterministic, low-overhead" → _tight_ (a _tight_ loop).
|
|
70
|
+
- "a loop you believe in" → _red_, turning a fuzzy gate into a binary observable state (the loop goes _red_ on the bug, or it doesn't).
|
|
71
|
+
|
|
72
|
+
You win twice: fewer tokens, and a sharper hook for the agent to hang its thinking on. Assume every document is carrying restatements that leading words retire. Go find them.
|
|
73
|
+
|
|
74
|
+
**Negation** is the failure mode beside this lever: steering by prohibition drags the forbidden behaviour into context and makes it _more_ available, not less. _Don't think of an elephant_, and the elephant is all there is; the negation is a weak modifier the strongly-activated concept overruns, so the ban half-reads as an instruction to do the thing. Prompt the **positive**: state the target behaviour ("write one-line comments") so the banned one is never spoken. A prohibition earns its place only as a hard guardrail you cannot phrase positively; even then, pair it with the positive target so attention lands on what to do.
|
|
75
|
+
|
|
76
|
+
## Pruning
|
|
77
|
+
|
|
78
|
+
- Keep each meaning in a **single source of truth**: one authoritative place, so changing the behaviour is a one-place edit. **Duplication** (the same meaning in more than one place) costs maintenance and tokens, and inflates a meaning's prominence on the ladder past its real rank. (The accidental inverse of a leading word, which repeats a token on purpose, never the meaning.)
|
|
79
|
+
- The **environment** is a source of truth too (`package.json` scripts, config files, the directory layout, `--help` output), and a document that restates it is a **cache**: a copy of a lookup, earning its load only when the lookup is expensive. Cache what the agent cannot find by looking: the unwritten convention, the reason behind a choice, the gotcha no config confesses. Leave the one-file, one-command lookups to the environment, where they cannot go stale.
|
|
80
|
+
- Check every line for **relevance**: does it still bear on what the document does? A line loses relevance by never bearing on the task (mere exposition, or a branch that should be disclosed) or by going stale as the behaviour or world it describes changes. Shorter documents are easier to keep relevant. Without a pruning discipline the default fate is **sediment**: stale layers that settle because adding feels safe and removing feels risky, until you must core down through them to find what is still live.
|
|
81
|
+
- Hunt **no-ops** sentence by sentence: an instruction the model already obeys by default pays load to say nothing. The test (does it change behaviour versus the default?) is model-relative, not reader-relative: two people disagreeing about a no-op disagree about the default, and settle it by running the document, not by debate. When a sentence fails, delete the whole sentence rather than trim words from it. The test also grades leading words: a word too weak to beat the default (_be thorough_ when the agent is already thorough-ish) is a no-op, and the fix is a stronger word (_relentless_), not a different technique.
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cognition Store — persistent runtime support for hypothesis-driven problem solving.
|
|
3
|
+
*
|
|
4
|
+
* Implementa spec: hypothesis-experiment-loop.
|
|
5
|
+
*
|
|
6
|
+
* Almacena hipótesis, experimentos y observaciones como append-only JSONL
|
|
7
|
+
* bajo `.wam/tasks/<taskId>/cognition/`. Permite continuar tras compaction
|
|
8
|
+
* sin re-intentar estrategias fallidas.
|
|
9
|
+
*
|
|
10
|
+
* Source of truth para datos cognitivos del task. Cualquier lectura/escritura
|
|
11
|
+
* de hipótesis, experimentos u observaciones debe pasar por este módulo.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
|
|
17
|
+
const COGNITION_DIR = "cognition";
|
|
18
|
+
const FILES = {
|
|
19
|
+
hypotheses: "hypotheses.jsonl",
|
|
20
|
+
experiments: "experiments.jsonl",
|
|
21
|
+
observations: "observations.jsonl",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** U1: never unlink cognition records. Archive via status append. */
|
|
25
|
+
export const DELETION_POLICY = "soft-archive";
|
|
26
|
+
|
|
27
|
+
// -- Status constants (single source of truth) --
|
|
28
|
+
// Hypotheses lifecycle: PROPOSED → TESTING → SUPPORTED | REJECTED → ARCHIVED
|
|
29
|
+
export const HYPOTHESIS_STATUS = Object.freeze({
|
|
30
|
+
PROPOSED: "proposed",
|
|
31
|
+
TESTING: "testing",
|
|
32
|
+
SUPPORTED: "supported",
|
|
33
|
+
REJECTED: "rejected",
|
|
34
|
+
ARCHIVED: "archived",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Experiment lifecycle: proposed → completed | failed
|
|
38
|
+
export const EXPERIMENT_STATUS = Object.freeze({
|
|
39
|
+
PROPOSED: "proposed",
|
|
40
|
+
COMPLETED: "completed",
|
|
41
|
+
FAILED: "failed",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export function migrateLegacyCognition(taskRoot, taskId) {
|
|
45
|
+
const legacyFile = path.join(taskRoot, ".wam", "tasks", taskId, "cognition.json");
|
|
46
|
+
if (!fs.existsSync(legacyFile)) return false;
|
|
47
|
+
|
|
48
|
+
const data = JSON.parse(fs.readFileSync(legacyFile, "utf-8"));
|
|
49
|
+
const dir = cognitionRoot(taskRoot, taskId);
|
|
50
|
+
ensureDir(dir);
|
|
51
|
+
|
|
52
|
+
if (data.hypotheses) {
|
|
53
|
+
data.hypotheses.forEach(h => appendLine(path.join(dir, FILES.hypotheses), h));
|
|
54
|
+
}
|
|
55
|
+
if (data.experiments) {
|
|
56
|
+
data.experiments.forEach(e => appendLine(path.join(dir, FILES.experiments), e));
|
|
57
|
+
}
|
|
58
|
+
if (data.observations) {
|
|
59
|
+
data.observations.forEach(o => appendLine(path.join(dir, FILES.observations), o));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fs.renameSync(legacyFile, legacyFile + ".migrated");
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function archiveHypothesis(taskRoot, taskId, hypothesisId, reason = "archived") {
|
|
67
|
+
const dir = cognitionRoot(taskRoot, taskId);
|
|
68
|
+
const file = path.join(dir, FILES.hypotheses);
|
|
69
|
+
appendLine(file, {
|
|
70
|
+
id: hypothesisId,
|
|
71
|
+
status: HYPOTHESIS_STATUS.ARCHIVED,
|
|
72
|
+
reason,
|
|
73
|
+
archivedAt: Date.now(),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function hasRepetitiveFailure(taskRoot, taskId, { hypothesisId, actionDescription } = {}) {
|
|
78
|
+
const experiments = listExperiments(taskRoot, taskId);
|
|
79
|
+
return experiments.some(
|
|
80
|
+
(e) =>
|
|
81
|
+
e.hypothesisId === hypothesisId &&
|
|
82
|
+
e.actionDescription === actionDescription &&
|
|
83
|
+
(e.status === EXPERIMENT_STATUS.FAILED),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function cognitionRoot(taskRoot, taskId) {
|
|
88
|
+
return path.join(taskRoot, ".wam", "tasks", taskId, COGNITION_DIR);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function ensureDir(dir) {
|
|
92
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function genId(prefix) {
|
|
96
|
+
return `${prefix}${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function appendLine(filePath, obj) {
|
|
100
|
+
ensureDir(path.dirname(filePath));
|
|
101
|
+
const line = JSON.stringify({ ...obj, createdAt: obj.createdAt || Date.now() }) + "\n";
|
|
102
|
+
fs.appendFileSync(filePath, line, "utf-8");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function readAll(filePath) {
|
|
106
|
+
if (!fs.existsSync(filePath)) return [];
|
|
107
|
+
const seen = new Map();
|
|
108
|
+
fs.readFileSync(filePath, "utf-8")
|
|
109
|
+
.split("\n")
|
|
110
|
+
.filter(Boolean)
|
|
111
|
+
.map((l) => { try { return JSON.parse(l); } catch { return null; } })
|
|
112
|
+
.filter(Boolean)
|
|
113
|
+
.forEach((obj) => { if (obj.id) seen.set(obj.id, obj); });
|
|
114
|
+
return Array.from(seen.values());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// -- Hypotheses --
|
|
118
|
+
|
|
119
|
+
export function createHypothesis(taskRoot, taskId, { statement, confidence = 0.5 }) {
|
|
120
|
+
const dir = cognitionRoot(taskRoot, taskId);
|
|
121
|
+
const file = path.join(dir, FILES.hypotheses);
|
|
122
|
+
const h = {
|
|
123
|
+
id: genId("H"),
|
|
124
|
+
statement,
|
|
125
|
+
confidence,
|
|
126
|
+
status: HYPOTHESIS_STATUS.PROPOSED,
|
|
127
|
+
};
|
|
128
|
+
appendLine(file, h);
|
|
129
|
+
return h;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function listHypotheses(taskRoot, taskId) {
|
|
133
|
+
const file = path.join(cognitionRoot(taskRoot, taskId), FILES.hypotheses);
|
|
134
|
+
return readAll(file);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function updateHypothesisStatus(taskRoot, taskId, id, status) {
|
|
138
|
+
const file = path.join(cognitionRoot(taskRoot, taskId), FILES.hypotheses);
|
|
139
|
+
if (!fs.existsSync(file)) return null;
|
|
140
|
+
const lines = readAll(file);
|
|
141
|
+
const target = lines.find((h) => h.id === id);
|
|
142
|
+
if (!target) return null;
|
|
143
|
+
appendLine(file, { ...target, status, updatedAt: Date.now() });
|
|
144
|
+
return { ...target, status, updatedAt: Date.now() };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function getActiveHypotheses(taskRoot, taskId) {
|
|
148
|
+
return listHypotheses(taskRoot, taskId)
|
|
149
|
+
.filter((h) =>
|
|
150
|
+
h.status === HYPOTHESIS_STATUS.PROPOSED ||
|
|
151
|
+
h.status === HYPOTHESIS_STATUS.TESTING
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// -- Experiments --
|
|
156
|
+
|
|
157
|
+
export function createExperiment(taskRoot, taskId, { hypothesisId, actionDescription, risk = "SAFE", reversible = true, expectedObservation }) {
|
|
158
|
+
const dir = cognitionRoot(taskRoot, taskId);
|
|
159
|
+
const file = path.join(dir, FILES.experiments);
|
|
160
|
+
const e = {
|
|
161
|
+
id: genId("E"),
|
|
162
|
+
hypothesisId,
|
|
163
|
+
actionDescription,
|
|
164
|
+
risk,
|
|
165
|
+
reversible,
|
|
166
|
+
expectedObservation,
|
|
167
|
+
status: EXPERIMENT_STATUS.PROPOSED,
|
|
168
|
+
};
|
|
169
|
+
appendLine(file, e);
|
|
170
|
+
return e;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function listExperiments(taskRoot, taskId) {
|
|
174
|
+
const file = path.join(cognitionRoot(taskRoot, taskId), FILES.experiments);
|
|
175
|
+
return readAll(file);
|
|
176
|
+
}
|
|
177
|
+
export function getExperiment(taskRoot, taskId, id) {
|
|
178
|
+
return listExperiments(taskRoot, taskId).find((e) => e.id === id) || null;
|
|
179
|
+
}
|
|
180
|
+
export function getHypothesis(taskRoot, taskId, id) {
|
|
181
|
+
return listHypotheses(taskRoot, taskId).find((h) => h.id === id) || null;
|
|
182
|
+
}
|
|
183
|
+
export function getObservation(taskRoot, taskId, id) {
|
|
184
|
+
return listObservations(taskRoot, taskId).find((o) => o.id === id) || null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function completeExperiment(taskRoot, taskId, id, { result = "ok" } = {}) {
|
|
188
|
+
return updateExperiment(taskRoot, taskId, id, { status: EXPERIMENT_STATUS.COMPLETED, result });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function failExperiment(taskRoot, taskId, id, reason = "") {
|
|
192
|
+
return updateExperiment(taskRoot, taskId, id, { status: EXPERIMENT_STATUS.FAILED, reason });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function updateExperiment(taskRoot, taskId, id, patch) {
|
|
196
|
+
const file = path.join(cognitionRoot(taskRoot, taskId), FILES.experiments);
|
|
197
|
+
if (!fs.existsSync(file)) return null;
|
|
198
|
+
const lines = readAll(file);
|
|
199
|
+
const target = lines.find((e) => e.id === id);
|
|
200
|
+
if (!target) return null;
|
|
201
|
+
appendLine(file, { ...target, ...patch, updatedAt: Date.now() });
|
|
202
|
+
return { ...target, ...patch, updatedAt: Date.now() };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function findRepeatedExperiment(taskRoot, taskId, { hypothesisId, actionDescription }) {
|
|
206
|
+
const all = listExperiments(taskRoot, taskId);
|
|
207
|
+
return all.filter((e) =>
|
|
208
|
+
e.hypothesisId === hypothesisId &&
|
|
209
|
+
e.actionDescription === actionDescription &&
|
|
210
|
+
(e.status === EXPERIMENT_STATUS.COMPLETED || e.status === EXPERIMENT_STATUS.FAILED)
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// -- Observations --
|
|
215
|
+
|
|
216
|
+
export function recordObservation(taskRoot, taskId, { experimentId, hypothesisId, result, facts = [], actual, unexpected, provenance }) {
|
|
217
|
+
const dir = cognitionRoot(taskRoot, taskId);
|
|
218
|
+
const file = path.join(dir, FILES.observations);
|
|
219
|
+
const o = { id: genId("O"), experimentId, hypothesisId, result, facts };
|
|
220
|
+
if (actual !== undefined) o.actual = actual;
|
|
221
|
+
if (unexpected !== undefined) o.unexpected = unexpected;
|
|
222
|
+
if (provenance !== undefined) o.provenance = provenance;
|
|
223
|
+
appendLine(file, o);
|
|
224
|
+
return o;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function listObservations(taskRoot, taskId) {
|
|
228
|
+
const file = path.join(cognitionRoot(taskRoot, taskId), FILES.observations);
|
|
229
|
+
return readAll(file);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function getObservationsForExperiment(taskRoot, taskId, experimentId) {
|
|
233
|
+
return listObservations(taskRoot, taskId).filter((o) => o.experimentId === experimentId);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// -- Compact state (for context packs) --
|
|
237
|
+
|
|
238
|
+
export function buildCompactState(taskRoot, taskId) {
|
|
239
|
+
const hypotheses = listHypotheses(taskRoot, taskId);
|
|
240
|
+
return {
|
|
241
|
+
activeHypotheses: hypotheses.filter((h) =>
|
|
242
|
+
h.status === HYPOTHESIS_STATUS.PROPOSED ||
|
|
243
|
+
h.status === HYPOTHESIS_STATUS.TESTING
|
|
244
|
+
),
|
|
245
|
+
supportedHypotheses: hypotheses.filter((h) => h.status === HYPOTHESIS_STATUS.SUPPORTED),
|
|
246
|
+
rejectedHypotheses: hypotheses.filter((h) => h.status === HYPOTHESIS_STATUS.REJECTED),
|
|
247
|
+
archivedHypotheses: hypotheses.filter((h) => h.status === HYPOTHESIS_STATUS.ARCHIVED),
|
|
248
|
+
recentExperiments: listExperiments(taskRoot, taskId).slice(-5),
|
|
249
|
+
recentObservations: listObservations(taskRoot, taskId).slice(-5),
|
|
250
|
+
};
|
|
251
|
+
}
|