@lsctech/polaris 0.3.22 → 0.3.23

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 (146) hide show
  1. package/dist/cli/adopt-assets.js +13 -0
  2. package/dist/cli/adopt-genesis.js +85 -4
  3. package/dist/cli/adopt-instructions.js +3 -3
  4. package/dist/cli/adopt-report.js +15 -1
  5. package/dist/cli/adopt-rules.js +44 -8
  6. package/dist/cli/adopt-workspace.js +2 -2
  7. package/dist/cli/adoption-inventory.js +5 -2
  8. package/dist/cli/init.js +5 -4
  9. package/dist/config/provider-detect.js +19 -2
  10. package/dist/workspace/.polaris/skills/ROUTING.md +4 -0
  11. package/dist/workspace/.polaris/skills/closeout-librarian/POLARIS.md +9 -8
  12. package/dist/workspace/.polaris/skills/docs-ingest/SKILL.md +2 -2
  13. package/dist/workspace/.polaris/skills/docs-ingest/chain.md +1 -1
  14. package/dist/workspace/.polaris/skills/docs-ingest/steps/04-place-and-link.md +5 -5
  15. package/dist/workspace/.polaris/skills/docs-ingest/steps/05-finalize-ingest.md +1 -1
  16. package/dist/workspace/.polaris/skills/docs-promote/SKILL.md +6 -6
  17. package/dist/workspace/.polaris/skills/docs-promote/chain.md +5 -5
  18. package/dist/workspace/.polaris/skills/docs-promote/steps/04-conflict-surface.md +1 -1
  19. package/dist/workspace/.polaris/skills/docs-promote/steps/06-execute-promote-deprecate.md +3 -3
  20. package/dist/workspace/{workspace/.polaris → .polaris}/skills/docs-review/SKILL.md +1 -1
  21. package/dist/workspace/{workspace/.polaris → .polaris}/skills/docs-triage/SKILL.md +1 -1
  22. package/dist/workspace/{workspace/.polaris → .polaris}/skills/docs-triage/chain.md +1 -1
  23. package/dist/workspace/.polaris/skills/polaris-analyze/SKILL.md +1 -1
  24. package/dist/workspace/.polaris/skills/polaris-analyze/chain.md +2 -2
  25. package/dist/workspace/.polaris/skills/polaris-analyze/issue-reconciliation.md +1 -1
  26. package/dist/workspace/.polaris/skills/polaris-analyze/linked-skills/repo-analysis.md +3 -4
  27. package/dist/workspace/.polaris/skills/polaris-analyze/steps/02-map-affected-code.md +2 -2
  28. package/dist/workspace/.polaris/skills/polaris-catalog/SKILL.md +5 -5
  29. package/dist/workspace/.polaris/skills/polaris-catalog/chain.md +3 -3
  30. package/dist/workspace/.polaris/skills/polaris-catalog/steps/04-classify-and-place.md +3 -3
  31. package/dist/workspace/.polaris/skills/polaris-reconcile/SKILL.md +2 -2
  32. package/dist/workspace/.polaris/skills/polaris-run/SKILL.md +1 -1
  33. package/dist/workspace/.polaris/skills/polaris-run/chain.md +17 -17
  34. package/dist/workspace/.polaris/skills/polaris-run/linked-skills/repo-analysis.md +3 -4
  35. package/dist/workspace/.polaris/skills/polaris-run/steps/01-orient-cluster.md +3 -3
  36. package/dist/workspace/.polaris/skills/polaris-run/steps/03-select-child.md +1 -1
  37. package/dist/workspace/.polaris/skills/polaris-run/steps/06-commit-and-update-linear.md +2 -2
  38. package/dist/workspace/.polaris/skills/polaris-run/steps/07-decide-continuation.md +3 -3
  39. package/dist/workspace/.polaris/skills/polaris-run/steps/08-closeout-librarian.md +1 -1
  40. package/dist/workspace/.polaris/skills/polaris-run/steps/08-final-delivery.md +2 -2
  41. package/dist/workspace/.polaris/skills/polaris-run/steps/09-final-delivery.md +1 -1
  42. package/dist/workspace/.polaris/skills/polaris-tools/README.md +1 -1
  43. package/dist/workspace/POLARIS_RULES.md +169 -0
  44. package/package.json +3 -2
  45. package/dist/workspace/workspace/.polaris/roles/analyst.md +0 -38
  46. package/dist/workspace/workspace/.polaris/roles/closeout-librarian.md +0 -122
  47. package/dist/workspace/workspace/.polaris/roles/cognition-librarian.md +0 -37
  48. package/dist/workspace/workspace/.polaris/roles/finalizer.md +0 -45
  49. package/dist/workspace/workspace/.polaris/roles/foreman.md +0 -165
  50. package/dist/workspace/workspace/.polaris/roles/librarian.md +0 -74
  51. package/dist/workspace/workspace/.polaris/roles/worker.md +0 -119
  52. package/dist/workspace/workspace/.polaris/session-type +0 -1
  53. package/dist/workspace/workspace/.polaris/skills/ROUTING.md +0 -113
  54. package/dist/workspace/workspace/.polaris/skills/caveman/SKILL.md +0 -74
  55. package/dist/workspace/workspace/.polaris/skills/caveman-compress/scripts/compress.py +0 -272
  56. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/POLARIS.md +0 -46
  57. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/SKILL.md +0 -59
  58. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/chain.md +0 -116
  59. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/steps/01-load-cluster-context.md +0 -78
  60. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/steps/02-drift-reconciliation.md +0 -157
  61. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/steps/03-reconcile-polaris-md.md +0 -93
  62. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/steps/04-reconcile-summary-md.md +0 -106
  63. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/steps/05-doc-ingestion.md +0 -114
  64. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/steps/06-link-validation.md +0 -128
  65. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/steps/07-yaml-linking.md +0 -95
  66. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/steps/08-librarian-commit.md +0 -119
  67. package/dist/workspace/workspace/.polaris/skills/closeout-librarian/steps/09-sealed-result.md +0 -118
  68. package/dist/workspace/workspace/.polaris/skills/docs-ingest/SKILL.md +0 -68
  69. package/dist/workspace/workspace/.polaris/skills/docs-ingest/chain.json +0 -23
  70. package/dist/workspace/workspace/.polaris/skills/docs-ingest/chain.md +0 -149
  71. package/dist/workspace/workspace/.polaris/skills/docs-ingest/steps/01-orient-ingest.md +0 -85
  72. package/dist/workspace/workspace/.polaris/skills/docs-ingest/steps/02-classify-batch.md +0 -87
  73. package/dist/workspace/workspace/.polaris/skills/docs-ingest/steps/03-conflict-check.md +0 -66
  74. package/dist/workspace/workspace/.polaris/skills/docs-ingest/steps/04-place-and-link.md +0 -77
  75. package/dist/workspace/workspace/.polaris/skills/docs-ingest/steps/05-finalize-ingest.md +0 -49
  76. package/dist/workspace/workspace/.polaris/skills/docs-promote/SKILL.md +0 -79
  77. package/dist/workspace/workspace/.polaris/skills/docs-promote/chain.json +0 -25
  78. package/dist/workspace/workspace/.polaris/skills/docs-promote/chain.md +0 -80
  79. package/dist/workspace/workspace/.polaris/skills/docs-promote/steps/01-orient-promote.md +0 -53
  80. package/dist/workspace/workspace/.polaris/skills/docs-promote/steps/02-review-candidates.md +0 -51
  81. package/dist/workspace/workspace/.polaris/skills/docs-promote/steps/03-read-linked-code.md +0 -50
  82. package/dist/workspace/workspace/.polaris/skills/docs-promote/steps/04-conflict-surface.md +0 -65
  83. package/dist/workspace/workspace/.polaris/skills/docs-promote/steps/05-await-approval.md +0 -61
  84. package/dist/workspace/workspace/.polaris/skills/docs-promote/steps/06-execute-promote-deprecate.md +0 -65
  85. package/dist/workspace/workspace/.polaris/skills/docs-promote/steps/07-finalize-promote.md +0 -44
  86. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/SKILL.md +0 -94
  87. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/chain.json +0 -20
  88. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/chain.md +0 -105
  89. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/issue-reconciliation.md +0 -149
  90. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/issue-template.md +0 -133
  91. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/linked-skills/repo-analysis.md +0 -55
  92. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/steps/01-fetch-and-orient.md +0 -79
  93. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/steps/02-map-affected-code.md +0 -58
  94. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/steps/03-assess-issue.md +0 -58
  95. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/steps/04-blocker-check.md +0 -60
  96. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/steps/05-create-cluster-plan.md +0 -197
  97. package/dist/workspace/workspace/.polaris/skills/polaris-analyze/steps/06-final-report.md +0 -60
  98. package/dist/workspace/workspace/.polaris/skills/polaris-catalog/SKILL.md +0 -91
  99. package/dist/workspace/workspace/.polaris/skills/polaris-catalog/chain.json +0 -22
  100. package/dist/workspace/workspace/.polaris/skills/polaris-catalog/chain.md +0 -85
  101. package/dist/workspace/workspace/.polaris/skills/polaris-catalog/steps/01-orient-catalog.md +0 -92
  102. package/dist/workspace/workspace/.polaris/skills/polaris-catalog/steps/02-reconcile-polaris-md.md +0 -33
  103. package/dist/workspace/workspace/.polaris/skills/polaris-catalog/steps/03-reconcile-summary-md.md +0 -70
  104. package/dist/workspace/workspace/.polaris/skills/polaris-catalog/steps/04-classify-and-place.md +0 -117
  105. package/dist/workspace/workspace/.polaris/skills/polaris-catalog/steps/05-catalog-commit.md +0 -94
  106. package/dist/workspace/workspace/.polaris/skills/polaris-medic/SKILL.md +0 -52
  107. package/dist/workspace/workspace/.polaris/skills/polaris-medic/chain.md +0 -111
  108. package/dist/workspace/workspace/.polaris/skills/polaris-medic/steps/01-orient-medic.md +0 -75
  109. package/dist/workspace/workspace/.polaris/skills/polaris-medic/steps/02-diagnose.md +0 -79
  110. package/dist/workspace/workspace/.polaris/skills/polaris-medic/steps/03-repair.md +0 -64
  111. package/dist/workspace/workspace/.polaris/skills/polaris-medic/steps/04-validate.md +0 -66
  112. package/dist/workspace/workspace/.polaris/skills/polaris-medic/steps/05-create-chart.md +0 -85
  113. package/dist/workspace/workspace/.polaris/skills/polaris-medic/steps/06-closeout.md +0 -86
  114. package/dist/workspace/workspace/.polaris/skills/polaris-reconcile/SKILL.md +0 -75
  115. package/dist/workspace/workspace/.polaris/skills/polaris-reconcile/chain.json +0 -20
  116. package/dist/workspace/workspace/.polaris/skills/polaris-reconcile/chain.md +0 -67
  117. package/dist/workspace/workspace/.polaris/skills/polaris-reconcile/steps/01-orient-reconcile.md +0 -82
  118. package/dist/workspace/workspace/.polaris/skills/polaris-reconcile/steps/02-reconcile-polaris-md.md +0 -95
  119. package/dist/workspace/workspace/.polaris/skills/polaris-reconcile/steps/03-reconcile-summary-md.md +0 -108
  120. package/dist/workspace/workspace/.polaris/skills/polaris-reconcile/steps/04-reconcile-commit.md +0 -88
  121. package/dist/workspace/workspace/.polaris/skills/polaris-run/SKILL.md +0 -135
  122. package/dist/workspace/workspace/.polaris/skills/polaris-run/chain.json +0 -19
  123. package/dist/workspace/workspace/.polaris/skills/polaris-run/chain.md +0 -298
  124. package/dist/workspace/workspace/.polaris/skills/polaris-run/execution-adapter.md +0 -34
  125. package/dist/workspace/workspace/.polaris/skills/polaris-run/linked-skills/repo-analysis.md +0 -58
  126. package/dist/workspace/workspace/.polaris/skills/polaris-run/steps/01-orient-cluster.md +0 -96
  127. package/dist/workspace/workspace/.polaris/skills/polaris-run/steps/02-prepare-branch.md +0 -53
  128. package/dist/workspace/workspace/.polaris/skills/polaris-run/steps/03-select-child.md +0 -63
  129. package/dist/workspace/workspace/.polaris/skills/polaris-run/steps/04-execute-child.md +0 -75
  130. package/dist/workspace/workspace/.polaris/skills/polaris-run/steps/05-validate-child.md +0 -57
  131. package/dist/workspace/workspace/.polaris/skills/polaris-run/steps/06-commit-and-update-linear.md +0 -74
  132. package/dist/workspace/workspace/.polaris/skills/polaris-run/steps/07-decide-continuation.md +0 -89
  133. package/dist/workspace/workspace/.polaris/skills/polaris-run/steps/08-closeout-librarian.md +0 -146
  134. package/dist/workspace/workspace/.polaris/skills/polaris-run/steps/08-final-delivery.md +0 -91
  135. package/dist/workspace/workspace/.polaris/skills/polaris-run/steps/09-final-delivery.md +0 -104
  136. package/dist/workspace/workspace/.polaris/skills/polaris-tools/README.md +0 -63
  137. package/dist/workspace/workspace/.polaris/skills/polaris-tools/SKILL.md +0 -94
  138. package/dist/workspace/workspace/.polaris/skills/polaris-tools/tools.js +0 -191
  139. package/dist/workspace/workspace/smartdocs/architecture/.gitkeep +0 -0
  140. package/dist/workspace/workspace/smartdocs/audits/.gitkeep +0 -0
  141. package/dist/workspace/workspace/smartdocs/decisions/.gitkeep +0 -0
  142. package/dist/workspace/workspace/smartdocs/doctrine/active/.gitkeep +0 -0
  143. package/dist/workspace/workspace/smartdocs/runtime/.gitkeep +0 -0
  144. package/dist/workspace/workspace/smartdocs/specs/active/.gitkeep +0 -0
  145. package/dist/workspace/workspace/smartdocs/specs/archive/.gitkeep +0 -0
  146. /package/dist/workspace/{workspace/.polaris → .polaris}/skills/docs-review/chain.md +0 -0
@@ -1,113 +0,0 @@
1
- # Polaris Skill Command Hard-Routing
2
-
3
- This document defines the mandatory routing protocol for explicit Polaris skill commands.
4
-
5
- It is **provider-neutral** and applies to all agents: Claude, Codex, Copilot, Gemini, and
6
- future agents. Any agent instruction surface that references `.polaris/` inherits this rule.
7
-
8
- ---
9
-
10
- ## When this rule applies
11
-
12
- This rule applies whenever a user message is an explicit Polaris skill command — that is, any
13
- message whose primary instruction is to invoke a named Polaris skill.
14
-
15
- ### Notation key
16
-
17
- | Notation | Meaning |
18
- |---|---|
19
- | `<CLUSTER-ID>` | Required placeholder — substitute the actual cluster ID as resolved by the tracker adapter (e.g., `POL-257`, `GH-42`, or a local contract ID) |
20
- | `[issue]` | Optional literal word — the word "issue" may be present or absent |
21
-
22
- ### Recognized command patterns
23
-
24
- | User command | Target skill | Skill packet path |
25
- |---|---|---|
26
- | `polaris-analyze <CLUSTER-ID>` | polaris-analyze | `.polaris/skills/polaris-analyze/` |
27
- | `run polaris-analyze on [issue] <CLUSTER-ID>` | polaris-analyze | `.polaris/skills/polaris-analyze/` |
28
- | `polaris-run <CLUSTER-ID>` | polaris-run | `.polaris/skills/polaris-run/` |
29
- | `run polaris-run on [issue] <CLUSTER-ID>` | polaris-run | `.polaris/skills/polaris-run/` |
30
- | `polaris-finalize` | polaris-run | `.polaris/skills/polaris-run/` |
31
- | `run polaris-finalize` | polaris-run | `.polaris/skills/polaris-run/` |
32
- | `polaris-status` | polaris-tools | `.polaris/skills/polaris-tools/` |
33
- | `run polaris-status` | polaris-tools | `.polaris/skills/polaris-tools/` |
34
- | `docs-ingest` | docs-ingest | `.polaris/skills/docs-ingest/` |
35
- | `run docs-ingest` | docs-ingest | `.polaris/skills/docs-ingest/` |
36
- | `docs-triage` | docs-triage | `.polaris/skills/docs-triage/` |
37
- | `run docs-triage` | docs-triage | `.polaris/skills/docs-triage/` |
38
- | `docs-review` | docs-review | `.polaris/skills/docs-review/` |
39
- | `run docs-review` | docs-review | `.polaris/skills/docs-review/` |
40
- | `polaris-reconcile <CLUSTER-ID>` | polaris-reconcile | `.polaris/skills/polaris-reconcile/` |
41
- | `run polaris-reconcile on [issue] <CLUSTER-ID>` | polaris-reconcile | `.polaris/skills/polaris-reconcile/` |
42
- | `polaris-catalog <CLUSTER-ID>` | polaris-catalog | `.polaris/skills/polaris-catalog/` |
43
- | `run polaris-catalog on [issue] <CLUSTER-ID>` | polaris-catalog | `.polaris/skills/polaris-catalog/` |
44
-
45
- > **Note:** `closeout-librarian` is NOT a user-facing command. It is dispatched by the
46
- > Foreman as a bounded session during step 08 of the `polaris-run` chain. Users do not
47
- > invoke it directly. The Foreman generates its packet via `polaris librarian packet <cluster-id>`.
48
- >
49
- > **Note:** `polaris-medic` is NOT a user-facing command. It is dispatched by the Foreman
50
- > as a bounded session when a worker returns a failed result packet. Users do not invoke it
51
- > directly. The Foreman generates its packet internally based on the failed worker result.
52
-
53
- ---
54
-
55
- ## Required routing protocol
56
-
57
- When a recognized command is detected, execute these steps **in order**:
58
-
59
- 1. **Resolve the target skill and load its packet first.**
60
- Look up the command in the routing table above to find the **target skill** (the target skill
61
- may differ from the command name — e.g., `polaris-finalize` → `polaris-run`). Read
62
- `.polaris/skills/<target-skill>/SKILL.md`. Do not investigate the repo, summarize the cluster,
63
- browse runtime files, or invent a process before reading the skill packet. The skill packet is
64
- the authoritative instruction source.
65
-
66
- 2. **Run the skill bootloader.**
67
- Execute the bootloader command specified in the SKILL.md (typically
68
- `polaris skill packet <name>`). Do not begin work until a packet is returned.
69
-
70
- 3. **Execute the chain.**
71
- Follow `chain.md` in strict step order. Do not skip steps, reorder steps, or substitute
72
- general investigation for a defined step.
73
-
74
- 4. **Bind the named cluster.**
75
- If the command specifies a cluster ID (e.g., `POL-257`), bind exactly that cluster.
76
- Do not substitute another cluster or infer a different target.
77
-
78
- 5. **One cluster per invocation (when a cluster is bound).**
79
- When a cluster ID is present, process one cluster per skill invocation. Only process multiple
80
- clusters in a single invocation if the skill's `chain.md` explicitly states it supports batching.
81
- Commands that carry no cluster ID (e.g., `polaris-finalize`) are not subject to this constraint.
82
-
83
- ---
84
-
85
- ## Blocking conditions
86
-
87
- If any of the following conditions occur, **stop immediately** and report the blocking condition.
88
- Do not continue, substitute, or attempt workarounds.
89
-
90
- | Condition | Required response |
91
- |---|---|
92
- | `SKILL.md` not found at `.polaris/skills/<target-skill>/SKILL.md` | `Blocking: skill packet not found at .polaris/skills/<target-skill>/SKILL.md` |
93
- | Runtime packet not returned by the bootloader command | `Blocking: Polaris could not authorize this run.` |
94
- | Named cluster does not match the skill's allowed parent type | Report the mismatch as described in the skill's SKILL.md |
95
-
96
- ---
97
-
98
- ## What this rule prohibits before reading the skill's SKILL.md
99
-
100
- The following actions are prohibited until the target skill's `SKILL.md` has been read and the
101
- bootloader command has returned a runtime packet. The bootloader itself (`polaris skill
102
- packet <name>`, as specified in SKILL.md) is the only Polaris CLI call that is authorized before
103
- the runtime packet is returned.
104
-
105
- - Ad hoc repo inspection (reading source files, grep, find)
106
- - Summarizing the named cluster from a tracker
107
- - Inventing a process or substituting general investigation
108
- - Reading runtime state files (`.taskchain_artifacts/`, `.polaris/runs/`, `.polaris/clusters/`)
109
- - Calling any Polaris CLI command other than the skill bootloader (e.g., `polaris loop continue`,
110
- `polaris loop dispatch`, `polaris finalize`)
111
-
112
- Once the runtime packet is returned, the skill packet's chain defines what the agent may do and
113
- in what order. Nothing outside that chain is authorized.
@@ -1,74 +0,0 @@
1
- ---
2
- name: caveman
3
- description: >
4
- Ultra-compressed communication mode. Cuts token usage ~75% by speaking like caveman
5
- while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra,
6
- wenyan-lite, wenyan-full, wenyan-ultra.
7
- Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens",
8
- "be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested.
9
- ---
10
-
11
- Respond terse like smart caveman. All technical substance stay. Only fluff die.
12
-
13
- ## Persistence
14
-
15
- ACTIVE EVERY RESPONSE. No revert after many turns. No filler drift. Still active if unsure. Off only: "stop caveman" / "normal mode".
16
-
17
- Default: **full**. Switch: `/caveman lite|full|ultra`.
18
-
19
- ## Rules
20
-
21
- Drop: articles (a/an/the), filler (just/really/basically/actually/simply), pleasantries (sure/certainly/of course/happy to), hedging. Fragments OK. Short synonyms (big not extensive, fix not "implement a solution for"). Technical terms exact. Code blocks unchanged. Errors quoted exact.
22
-
23
- Pattern: `[thing] [action] [reason]. [next step].`
24
-
25
- Not: "Sure! I'd be happy to help you with that. The issue you're experiencing is likely caused by..."
26
- Yes: "Bug in auth middleware. Token expiry check use `<` not `<=`. Fix:"
27
-
28
- ## Intensity
29
-
30
- | Level | What change |
31
- |-------|------------|
32
- | **lite** | No filler/hedging. Keep articles + full sentences. Professional but tight |
33
- | **full** | Drop articles, fragments OK, short synonyms. Classic caveman |
34
- | **ultra** | Abbreviate prose words (DB/auth/config/req/res/fn/impl), strip conjunctions, arrows for causality (X → Y), one word when one word enough. Code symbols, function names, API names, error strings: never abbreviate |
35
- | **wenyan-lite** | Semi-classical. Drop filler/hedging but keep grammar structure, classical register |
36
- | **wenyan-full** | Maximum classical terseness. Fully 文言文. 80-90% character reduction. Classical sentence patterns, verbs precede objects, subjects often omitted, classical particles (之/乃/為/其) |
37
- | **wenyan-ultra** | Extreme abbreviation while keeping classical Chinese feel. Maximum compression, ultra terse |
38
-
39
- Example — "Why React component re-render?"
40
- - lite: "Your component re-renders because you create a new object reference each render. Wrap it in `useMemo`."
41
- - full: "New object ref each render. Inline object prop = new ref = re-render. Wrap in `useMemo`."
42
- - ultra: "Inline obj prop → new ref → re-render. `useMemo`."
43
- - wenyan-lite: "組件頻重繪,以每繪新生對象參照故。以 useMemo 包之。"
44
- - wenyan-full: "物出新參照,致重繪。useMemo .Wrap之。"
45
- - wenyan-ultra: "新參照→重繪。useMemo Wrap。"
46
-
47
- Example — "Explain database connection pooling."
48
- - lite: "Connection pooling reuses open connections instead of creating new ones per request. Avoids repeated handshake overhead."
49
- - full: "Pool reuse open DB connections. No new connection per request. Skip handshake overhead."
50
- - ultra: "Pool = reuse DB conn. Skip handshake → fast under load."
51
- - wenyan-full: "池reuse open connection。不每req新開。skip handshake overhead。"
52
- - wenyan-ultra: "池reuse conn。skip handshake → fast。"
53
-
54
- ## Auto-Clarity
55
-
56
- Drop caveman when:
57
- - Security warnings
58
- - Irreversible action confirmations
59
- - Multi-step sequences where fragment order or omitted conjunctions risk misread
60
- - Compression itself creates technical ambiguity (e.g., `"migrate table drop column backup first"` — order unclear without articles/conjunctions)
61
- - User asks to clarify or repeats question
62
-
63
- Resume caveman after clear part done.
64
-
65
- Example — destructive op:
66
- > **Warning:** This will permanently delete all rows in the `users` table and cannot be undone.
67
- > ```sql
68
- > DROP TABLE users;
69
- > ```
70
- > Caveman resume. Verify backup exist first.
71
-
72
- ## Boundaries
73
-
74
- Code/commits/PRs: write normal. "stop caveman" or "normal mode": revert. Level persist until changed or session end.
@@ -1,272 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Caveman Memory Compression Orchestrator
4
-
5
- Usage:
6
- python scripts/compress.py <filepath>
7
- """
8
-
9
- import os
10
- import re
11
- import shutil
12
- import subprocess
13
- from pathlib import Path
14
- from typing import List
15
-
16
- OUTER_FENCE_REGEX = re.compile(
17
- r"\A\s*(`{3,}|~{3,})[^\n]*\n(.*)\n\1\s*\Z", re.DOTALL
18
- )
19
-
20
- # Filenames and paths that almost certainly hold secrets or PII. Compressing
21
- # them ships raw bytes to the Anthropic API — a third-party data boundary that
22
- # developers on sensitive codebases cannot cross. detect.py already skips .env
23
- # by extension, but credentials.md / secrets.txt / ~/.aws/credentials would
24
- # slip through the natural-language filter. This is a hard refuse before read.
25
- SENSITIVE_BASENAME_REGEX = re.compile(
26
- r"(?ix)^("
27
- r"\.env(\..+)?"
28
- r"|\.netrc"
29
- r"|credentials(\..+)?"
30
- r"|secrets?(\..+)?"
31
- r"|passwords?(\..+)?"
32
- r"|id_(rsa|dsa|ecdsa|ed25519)(\.pub)?"
33
- r"|authorized_keys"
34
- r"|known_hosts"
35
- r"|.*\.(pem|key|p12|pfx|crt|cer|jks|keystore|asc|gpg)"
36
- r")$"
37
- )
38
-
39
- SENSITIVE_PATH_COMPONENTS = frozenset({".ssh", ".aws", ".gnupg", ".kube", ".docker"})
40
-
41
- SENSITIVE_NAME_TOKENS = (
42
- "secret", "credential", "password", "passwd",
43
- "apikey", "accesskey", "token", "privatekey",
44
- )
45
-
46
-
47
- def is_sensitive_path(filepath: Path) -> bool:
48
- """Heuristic denylist for files that must never be shipped to a third-party API."""
49
- name = filepath.name
50
- if SENSITIVE_BASENAME_REGEX.match(name):
51
- return True
52
- lowered_parts = {p.lower() for p in filepath.parts}
53
- if lowered_parts & SENSITIVE_PATH_COMPONENTS:
54
- return True
55
- # Normalize separators so "api-key" and "api_key" both match "apikey".
56
- lower = re.sub(r"[_\-\s.]", "", name.lower())
57
- return any(tok in lower for tok in SENSITIVE_NAME_TOKENS)
58
-
59
-
60
- def strip_llm_wrapper(text: str) -> str:
61
- """Strip outer ```markdown ... ``` fence when it wraps the entire output."""
62
- m = OUTER_FENCE_REGEX.match(text)
63
- if m:
64
- return m.group(2)
65
- return text
66
-
67
- try:
68
- from .detect import should_compress
69
- from .validate import validate
70
- except ImportError:
71
- import sys
72
- import os
73
- sys.path.insert(0, os.path.dirname(__file__))
74
- from detect import should_compress # type: ignore[no-redef]
75
- from validate import validate # type: ignore[no-redef]
76
-
77
- MAX_RETRIES = 2
78
-
79
-
80
- # ---------- Claude Calls ----------
81
-
82
-
83
- def call_claude(prompt: str) -> str:
84
- api_key = os.environ.get("ANTHROPIC_API_KEY")
85
- if api_key:
86
- try:
87
- import anthropic
88
-
89
- client = anthropic.Anthropic(api_key=api_key)
90
- msg = client.messages.create(
91
- model=os.environ.get("CAVEMAN_MODEL", "claude-sonnet-4-5"),
92
- max_tokens=8192,
93
- messages=[{"role": "user", "content": prompt}],
94
- )
95
- return strip_llm_wrapper(msg.content[0].text.strip())
96
- except ImportError:
97
- pass # anthropic not installed, fall back to CLI
98
- # Fallback: use claude CLI (handles desktop auth)
99
- claude_bin = os.environ.get("CLAUDE_BIN") or shutil.which("claude")
100
- if claude_bin is None:
101
- raise RuntimeError(
102
- "Claude CLI not found. Set CLAUDE_BIN to the full path, "
103
- "or ensure 'claude' is on your PATH."
104
- )
105
- print(f"Using Claude CLI: {claude_bin}")
106
- try:
107
- result = subprocess.run(
108
- [claude_bin, "--print"],
109
- input=prompt,
110
- text=True,
111
- capture_output=True,
112
- check=True,
113
- timeout=300,
114
- )
115
- return strip_llm_wrapper(result.stdout.strip())
116
- except subprocess.TimeoutExpired as e:
117
- raise RuntimeError("Claude CLI call timed out after 300 seconds.") from e
118
- except subprocess.CalledProcessError as e:
119
- raise RuntimeError(f"Claude call failed:\n{e.stderr}") from e
120
-
121
-
122
- def build_compress_prompt(original: str) -> str:
123
- return f"""
124
- Compress this markdown into caveman format.
125
-
126
- STRICT RULES:
127
- - Do NOT modify anything inside ``` code blocks
128
- - Do NOT modify anything inside inline backticks
129
- - Preserve ALL URLs exactly
130
- - Preserve ALL headings exactly
131
- - Preserve file paths and commands
132
- - Return ONLY the compressed markdown body — do NOT wrap the entire output in a ```markdown fence or any other fence. Inner code blocks from the original stay as-is; do not add a new outer fence around the whole file.
133
-
134
- Only compress natural language.
135
-
136
- TEXT:
137
- {original}
138
- """
139
-
140
-
141
- def build_fix_prompt(original: str, compressed: str, errors: List[str]) -> str:
142
- errors_str = "\n".join(f"- {e}" for e in errors)
143
- return f"""You are fixing a caveman-compressed markdown file. Specific validation errors were found.
144
-
145
- CRITICAL RULES:
146
- - DO NOT recompress or rephrase the file
147
- - ONLY fix the listed errors — leave everything else exactly as-is
148
- - The ORIGINAL is provided as reference only (to restore missing content)
149
- - Preserve caveman style in all untouched sections
150
-
151
- ERRORS TO FIX:
152
- {errors_str}
153
-
154
- HOW TO FIX:
155
- - Missing URL: find it in ORIGINAL, restore it exactly where it belongs in COMPRESSED
156
- - Code block mismatch: find the exact code block in ORIGINAL, restore it in COMPRESSED
157
- - Heading mismatch: restore the exact heading text from ORIGINAL into COMPRESSED
158
- - Do not touch any section not mentioned in the errors
159
-
160
- ORIGINAL (reference only):
161
- {original}
162
-
163
- COMPRESSED (fix this):
164
- {compressed}
165
-
166
- Return ONLY the fixed compressed file. No explanation.
167
- """
168
-
169
-
170
- # ---------- Core Logic ----------
171
-
172
-
173
- def compress_file(filepath: Path) -> bool:
174
- # Resolve and validate path
175
- filepath = filepath.resolve()
176
- MAX_FILE_SIZE = 500_000 # 500KB
177
- if not filepath.exists():
178
- raise FileNotFoundError(f"File not found: {filepath}")
179
- if filepath.stat().st_size > MAX_FILE_SIZE:
180
- raise ValueError(f"File too large to compress safely (max 500KB): {filepath}")
181
-
182
- # Refuse files that look like they contain secrets or PII. Compressing ships
183
- # the raw bytes to the Anthropic API — a third-party boundary — so we fail
184
- # loudly rather than silently exfiltrate credentials or keys. Override is
185
- # intentional: the user must rename the file if the heuristic is wrong.
186
- if is_sensitive_path(filepath):
187
- raise ValueError(
188
- f"Refusing to compress {filepath}: filename looks sensitive "
189
- "(credentials, keys, secrets, or known private paths). "
190
- "Compression sends file contents to the Anthropic API. "
191
- "Rename the file if this is a false positive."
192
- )
193
-
194
- print(f"Processing: {filepath}")
195
-
196
- if not should_compress(filepath):
197
- print("Skipping (not natural language)")
198
- return False
199
-
200
- original_text = filepath.read_text(errors="replace")
201
- backup_path = filepath.with_name(filepath.stem + ".original.md")
202
-
203
- if not original_text.strip():
204
- print("❌ Refusing to compress: file is empty or whitespace-only.")
205
- return False
206
-
207
- # Check if backup already exists to prevent accidental overwriting
208
- if backup_path.exists():
209
- print(f"⚠️ Backup file already exists: {backup_path}")
210
- print("The original backup may contain important content.")
211
- print("Aborting to prevent data loss. Please remove or rename the backup file if you want to proceed.")
212
- return False
213
-
214
- # Step 1: Compress
215
- print("Compressing with Claude...")
216
- compressed = call_claude(build_compress_prompt(original_text))
217
-
218
- if compressed is None or not compressed.strip():
219
- print("❌ Compression aborted: Claude returned an empty response.")
220
- print(" Original file is untouched (no backup created).")
221
- return False
222
-
223
- if compressed.strip() == original_text.strip():
224
- print("❌ Compression aborted: output is identical to input.")
225
- print(" Likely causes: Claude refused, returned the prompt verbatim, or the file is")
226
- print(" already in caveman form. Original file is untouched (no backup created).")
227
- return False
228
-
229
- # Save original as backup, then verify the backup readback before
230
- # touching the input file. If the filesystem dropped bytes (encoding,
231
- # antivirus, disk full), unlink the bad backup and abort instead of
232
- # leaving the user with a corrupt backup + compressed primary.
233
- backup_path.write_text(original_text)
234
- backup_readback = backup_path.read_text(errors="replace")
235
- if backup_readback != original_text:
236
- print(f"❌ Backup write verification failed: {backup_path}")
237
- print(" In-memory original differs from on-disk backup. Aborting before touching the input file.")
238
- try:
239
- backup_path.unlink()
240
- except OSError:
241
- pass
242
- return False
243
- filepath.write_text(compressed)
244
-
245
- # Step 2: Validate + Retry
246
- for attempt in range(MAX_RETRIES):
247
- print(f"\nValidation attempt {attempt + 1}")
248
-
249
- result = validate(backup_path, filepath)
250
-
251
- if result.is_valid:
252
- print("Validation passed")
253
- break
254
-
255
- print("❌ Validation failed:")
256
- for err in result.errors:
257
- print(f" - {err}")
258
-
259
- if attempt == MAX_RETRIES - 1:
260
- # Restore original on failure
261
- filepath.write_text(original_text)
262
- backup_path.unlink(missing_ok=True)
263
- print("❌ Failed after retries — original restored")
264
- return False
265
-
266
- print("Fixing with Claude...")
267
- compressed = call_claude(
268
- build_fix_prompt(original_text, compressed, result.errors)
269
- )
270
- filepath.write_text(compressed)
271
-
272
- return True
@@ -1,46 +0,0 @@
1
- # .polaris/skills/closeout-librarian/
2
-
3
- ## Purpose
4
-
5
- This directory contains the Closeout Librarian skill package.
6
-
7
- The Closeout Librarian is a bounded runtime role dispatched by the Foreman exactly once
8
- per completed cluster, after all children are done and before PR creation.
9
-
10
- ## Contents
11
-
12
- | File | Purpose |
13
- |------|---------|
14
- | `SKILL.md` | Skill entry point — read first, contains bootloader instructions and packet schema reference |
15
- | `chain.md` | Step-order execution map — the Librarian executes this in strict step order |
16
- | `steps/01-load-cluster-context.md` | Build work inventory from packet and cluster evidence |
17
- | `steps/02-reconcile-polaris-md.md` | Update affected POLARIS.md files |
18
- | `steps/03-reconcile-summary-md.md` | Refresh SUMMARY.md as continuation artifact |
19
- | `steps/04-doc-ingestion.md` | Ingest/promote/archive documentation |
20
- | `steps/05-link-validation.md` | Validate and repair broken links |
21
- | `steps/06-yaml-linking.md` | Update YAML references for promoted documents |
22
- | `steps/07-librarian-commit.md` | Commit documentation changes |
23
- | `steps/08-sealed-result.md` | Write sealed result JSON and terminate |
24
-
25
- ## Invocation
26
-
27
- This skill is NOT invoked by user command. It is dispatched by the Foreman during
28
- step 08 of the `polaris-run` chain after cluster-complete is confirmed.
29
-
30
- The Foreman generates the packet via:
31
- ```bash
32
- npm run polaris -- librarian packet <cluster-id>
33
- ```
34
-
35
- Then dispatches the Librarian as a bounded subagent session.
36
-
37
- ## Authority
38
-
39
- The Closeout Librarian may update POLARIS.md, SUMMARY.md, ingest documents, and commit
40
- documentation changes. It may NOT modify source code, runtime state, or create PRs.
41
-
42
- Full authority boundaries: `.polaris/roles/closeout-librarian.md`
43
-
44
- ## Spec Reference
45
-
46
- `smartdocs/specs/active/closeout-librarian-spec.md`
@@ -1,59 +0,0 @@
1
- ---
2
- name: closeout-librarian
3
- description: Reconcile completed cluster work into project cognition and documentation. Runs exactly once per cluster, after all children complete and before PR creation.
4
- role: closeout-librarian
5
- role_file: .polaris/roles/closeout-librarian.md
6
- ---
7
-
8
- ## Entry Points
9
-
10
- This skill is invoked by the Foreman as a dispatched session. It is NOT a user-facing command.
11
-
12
- Invocation: The Foreman dispatches the Closeout Librarian after confirming `cluster-complete` status
13
- and before running `polaris finalize`. The packet path is passed as the session prompt.
14
-
15
- ---
16
-
17
- ## Polaris Skill Bootloader
18
-
19
- This skill does NOT use the standard Polaris skill bootloader. The Closeout Librarian
20
- receives its packet directly from the Foreman — the packet is the sole authoritative
21
- instruction source for this session.
22
-
23
- The Librarian MUST:
24
- 1. Read the packet at the path provided in the dispatch prompt.
25
- 2. Validate the packet schema (role must be `"closeout-librarian"`).
26
- 3. Execute `chain.md` in strict step order.
27
- 4. Write the sealed result to `packet.result_path` before the session ends.
28
-
29
- If the packet cannot be read or fails schema validation, write a failure result immediately
30
- and terminate. Do not attempt to reconstruct the packet from context.
31
-
32
- ---
33
-
34
- ## Authority Reminder
35
-
36
- The Closeout Librarian may NOT modify implementation code, runtime state, or dispatch
37
- any workers. Its sole output is documentation/cognition changes + sealed result JSON.
38
-
39
- Full authority boundaries: `.polaris/roles/closeout-librarian.md`
40
-
41
- ---
42
-
43
- ## Packet Schema
44
-
45
- The packet is a `CloseoutLibrarianPacket`. See:
46
- - `smartdocs/specs/active/closeout-librarian-spec.md` §3 for full schema
47
- - `src/cognition/closeout-librarian-types.ts` for TypeScript types
48
-
49
- Required packet fields: `role`, `run_id`, `dispatch_id`, `cluster_id`,
50
- `completed_children`, `child_summaries`, `affected_folders`, `polaris_md_paths`,
51
- `result_path`, `prohibited_write_paths`, `allowed_write_paths`.
52
-
53
- ---
54
-
55
- ## Execution
56
-
57
- Read `chain.md` and execute steps in strict order.
58
-
59
- Do not skip steps. Do not reorder steps.
@@ -1,116 +0,0 @@
1
- ---
2
- name: closeout-librarian-chain
3
- description: Step-order execution map for the Closeout Librarian. Runs once per completed cluster.
4
- ---
5
-
6
- # Closeout Librarian Chain
7
-
8
- ## Authority
9
-
10
- **The packet is authoritative. Do not infer cluster scope from conversation context.**
11
-
12
- Read the packet before any analysis. Execute steps in strict order.
13
-
14
- ## Scope Contract
15
-
16
- The Closeout Librarian operates on documentation and cognition only.
17
-
18
- **Allowed writes:** POLARIS.md, SUMMARY.md (affected folders), smartdocs ingestion targets,
19
- cognition archive, YAML frontmatter in doc files, sealed result JSON, librarian commit.
20
-
21
- **Prohibited writes:** Source code, runtime state files, telemetry JSONL, cluster plan,
22
- Linear issue status, PR creation.
23
-
24
- ---
25
-
26
- ## Step Traversal Order
27
-
28
- ```text
29
- 01-load-cluster-context ← Read packet, load cluster evidence, build work inventory
30
- 02-drift-reconciliation ← Run formal drift reconciliation checklist
31
- 03-reconcile-polaris-md ← Update affected POLARIS.md files to reflect current reality
32
- 04-reconcile-summary-md ← Refresh SUMMARY.md as continuation artifact
33
- 05-doc-ingestion ← Ingest/promote/archive documentation from completed work
34
- 06-link-validation ← Validate and repair broken links across affected docs
35
- 07-yaml-linking ← Update YAML references for ingested/promoted documents
36
- 08-librarian-commit ← Commit all documentation changes as sealed librarian commit
37
- 09-sealed-result ← Write CloseoutLibrarianResult JSON to result_path, terminate
38
- ```
39
-
40
- All steps must complete in order. Termination after step 09 is mandatory.
41
-
42
- ---
43
-
44
- ## Execution Rules
45
-
46
- ### Step Gate Behavior
47
-
48
- - Each step must complete before the next begins.
49
- - If a step encounters a recoverable error (e.g., one broken link that cannot be repaired),
50
- record the blocker and continue.
51
- - If a step encounters a fatal error (e.g., packet unreadable, commit fails), record
52
- `status: "failure"` in the result and proceed to step 09 (sealed result write).
53
- - Do not skip to step 09 for recoverable errors — complete the remaining steps.
54
-
55
- ### Write Discipline
56
-
57
- Before writing any file, verify it is in `packet.allowed_write_paths`.
58
- If the target file is in `packet.prohibited_write_paths`, skip and record as blocker.
59
-
60
- ### Commit Timing
61
-
62
- All writes occur during steps 03–07. No writes occur during step 08 or after.
63
- Step 08 creates exactly one git commit containing all documentation changes from this session.
64
- If no documentation changed (all steps found everything current), step 08 makes no commit.
65
- The result records `commit_sha: null` in this case — do not create an empty commit.
66
-
67
- ### Result Timing
68
-
69
- Step 09 writes the sealed result JSON and terminates. No further writes are permitted after
70
- the sealed result is written.
71
-
72
- ---
73
-
74
- ## Narration Rules
75
-
76
- The Closeout Librarian does NOT produce user-facing narration during normal execution.
77
-
78
- **Allowed output:**
79
- - The sealed result JSON written to `result_path` (step 08)
80
- - Escalation output if blocked on a decision that requires operator input
81
-
82
- **Prohibited output:**
83
- - Step-by-step progress narration
84
- - Summary of what was found
85
- - Interim status updates
86
-
87
- All communication with the Foreman occurs through the sealed result and the commit record.
88
-
89
- ---
90
-
91
- ## Telemetry Events
92
-
93
- Emit the following structured events to the telemetry file (if path provided in packet):
94
-
95
- | Event | Step | Fields |
96
- |---|---|---|
97
- | `librarian-start` | 01 | `run_id`, `cluster_id`, `dispatch_id`, `timestamp` |
98
- | `librarian-step-complete` | each step | `step`, `run_id`, `timestamp`, `outcome` |
99
- | `librarian-commit` | 08 | `commit_sha`, `files_changed`, `timestamp` |
100
- | `librarian-complete` | 09 | `status`, `run_id`, `timestamp` |
101
-
102
- If no telemetry file is specified in the packet, skip telemetry events silently.
103
-
104
- ---
105
-
106
- ## Failure Handling
107
-
108
- | Condition | Action |
109
- |---|---|
110
- | Packet unreadable | Write failure result to `result_path` if possible, otherwise stderr. Terminate. |
111
- | Packet schema invalid | Write failure result, terminate |
112
- | POLARIS.md has unresolvable conflict | Record blocker, skip that file, continue |
113
- | Commit fails | Status: failure, record commit error, proceed to step 09 |
114
- | Result write fails | Stderr only. Cannot recover. |
115
- | All blockers, no writes | Status: `"blocked"`, list blockers, commit nothing |
116
- | Some work done, some blocked | Status: `"partial"`, describe both |