selftune 0.2.8 → 0.2.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.
Files changed (140) hide show
  1. package/README.md +35 -35
  2. package/apps/local-dashboard/dist/assets/index-BZVLv70T.js +16 -0
  3. package/apps/local-dashboard/dist/assets/{index-CRtLkBTi.css → index-Bs3Y4ixf.css} +1 -1
  4. package/apps/local-dashboard/dist/assets/{vendor-react-BQH_6WrG.js → vendor-react-BXP54cYo.js} +4 -4
  5. package/apps/local-dashboard/dist/assets/{vendor-table-dK1QMLq9.js → vendor-table-DTF_SXoy.js} +1 -1
  6. package/apps/local-dashboard/dist/assets/{vendor-ui-CO2mrx6e.js → vendor-ui-CWU0d1wd.js} +66 -66
  7. package/apps/local-dashboard/dist/index.html +15 -15
  8. package/bin/selftune.cjs +1 -1
  9. package/cli/selftune/activation-rules.ts +37 -18
  10. package/cli/selftune/agent-guidance.ts +16 -16
  11. package/cli/selftune/alpha-identity.ts +1 -2
  12. package/cli/selftune/alpha-upload/build-payloads.ts +18 -2
  13. package/cli/selftune/alpha-upload/flush.ts +2 -2
  14. package/cli/selftune/alpha-upload/stage-canonical.ts +106 -3
  15. package/cli/selftune/auth/device-code.ts +32 -0
  16. package/cli/selftune/auto-update.ts +12 -0
  17. package/cli/selftune/badge/badge.ts +1 -0
  18. package/cli/selftune/canonical-export.ts +5 -0
  19. package/cli/selftune/claude-agents.ts +154 -0
  20. package/cli/selftune/contribute/bundle.ts +2 -0
  21. package/cli/selftune/contribute/contribute.ts +1 -0
  22. package/cli/selftune/cron/setup.ts +2 -2
  23. package/cli/selftune/dashboard-contract.ts +1 -1
  24. package/cli/selftune/dashboard-server.ts +11 -52
  25. package/cli/selftune/eval/hooks-to-evals.ts +13 -6
  26. package/cli/selftune/eval/import-skillsbench.ts +1 -0
  27. package/cli/selftune/eval/synthetic-evals.ts +2 -3
  28. package/cli/selftune/eval/unit-test.ts +1 -0
  29. package/cli/selftune/evolution/deploy-proposal.ts +1 -0
  30. package/cli/selftune/evolution/evolve-body.ts +93 -6
  31. package/cli/selftune/evolution/evolve.ts +0 -1
  32. package/cli/selftune/evolution/propose-body.ts +3 -2
  33. package/cli/selftune/evolution/propose-routing.ts +3 -2
  34. package/cli/selftune/evolution/refine-body.ts +3 -2
  35. package/cli/selftune/export.ts +1 -0
  36. package/cli/selftune/grading/auto-grade.ts +1 -0
  37. package/cli/selftune/grading/grade-session.ts +9 -0
  38. package/cli/selftune/hooks/auto-activate.ts +6 -0
  39. package/cli/selftune/hooks/evolution-guard.ts +12 -15
  40. package/cli/selftune/hooks/prompt-log.ts +1 -0
  41. package/cli/selftune/hooks/session-stop.ts +34 -40
  42. package/cli/selftune/hooks/skill-change-guard.ts +1 -0
  43. package/cli/selftune/hooks/skill-eval.ts +1 -1
  44. package/cli/selftune/index.ts +23 -14
  45. package/cli/selftune/ingestors/claude-replay.ts +1 -0
  46. package/cli/selftune/ingestors/codex-rollout.ts +1 -0
  47. package/cli/selftune/ingestors/codex-wrapper.ts +1 -0
  48. package/cli/selftune/ingestors/openclaw-ingest.ts +1 -0
  49. package/cli/selftune/ingestors/opencode-ingest.ts +1 -0
  50. package/cli/selftune/init.ts +197 -96
  51. package/cli/selftune/localdb/db.ts +1 -0
  52. package/cli/selftune/localdb/direct-write.ts +93 -12
  53. package/cli/selftune/localdb/materialize.ts +2 -0
  54. package/cli/selftune/localdb/queries.ts +210 -0
  55. package/cli/selftune/localdb/schema.ts +72 -1
  56. package/cli/selftune/monitoring/watch.ts +1 -0
  57. package/cli/selftune/normalization.ts +4 -0
  58. package/cli/selftune/observability.ts +14 -7
  59. package/cli/selftune/orchestrate.ts +15 -37
  60. package/cli/selftune/repair/skill-usage.ts +7 -3
  61. package/cli/selftune/routes/orchestrate-runs.ts +1 -0
  62. package/cli/selftune/routes/overview.ts +1 -0
  63. package/cli/selftune/routes/skill-report.ts +1 -0
  64. package/cli/selftune/sync.ts +31 -1
  65. package/cli/selftune/types.ts +2 -2
  66. package/cli/selftune/uninstall.ts +412 -0
  67. package/cli/selftune/utils/canonical-log.ts +2 -0
  68. package/cli/selftune/utils/jsonl.ts +1 -0
  69. package/cli/selftune/utils/llm-call.ts +131 -3
  70. package/cli/selftune/utils/skill-log.ts +1 -0
  71. package/cli/selftune/utils/transcript.ts +1 -0
  72. package/cli/selftune/utils/trigger-check.ts +1 -1
  73. package/cli/selftune/workflows/skill-md-writer.ts +5 -5
  74. package/cli/selftune/workflows/workflows.ts +1 -0
  75. package/package.json +38 -33
  76. package/packages/telemetry-contract/fixtures/golden.test.ts +1 -0
  77. package/packages/telemetry-contract/package.json +3 -3
  78. package/packages/telemetry-contract/src/index.ts +0 -1
  79. package/packages/telemetry-contract/src/schemas.ts +6 -24
  80. package/packages/telemetry-contract/tests/compatibility.test.ts +1 -0
  81. package/packages/ui/README.md +35 -34
  82. package/packages/ui/package.json +3 -3
  83. package/packages/ui/src/components/ActivityTimeline.tsx +49 -42
  84. package/packages/ui/src/components/EvidenceViewer.tsx +306 -182
  85. package/packages/ui/src/components/EvolutionTimeline.tsx +83 -72
  86. package/packages/ui/src/components/InfoTip.tsx +4 -3
  87. package/packages/ui/src/components/OrchestrateRunsPanel.tsx +60 -53
  88. package/packages/ui/src/components/section-cards.tsx +19 -24
  89. package/packages/ui/src/components/skill-health-grid.tsx +213 -193
  90. package/packages/ui/src/lib/constants.tsx +1 -0
  91. package/packages/ui/src/primitives/badge.tsx +12 -15
  92. package/packages/ui/src/primitives/button.tsx +7 -7
  93. package/packages/ui/src/primitives/card.tsx +15 -26
  94. package/packages/ui/src/primitives/checkbox.tsx +7 -8
  95. package/packages/ui/src/primitives/collapsible.tsx +5 -5
  96. package/packages/ui/src/primitives/dropdown-menu.tsx +45 -55
  97. package/packages/ui/src/primitives/label.tsx +6 -6
  98. package/packages/ui/src/primitives/select.tsx +28 -37
  99. package/packages/ui/src/primitives/table.tsx +17 -44
  100. package/packages/ui/src/primitives/tabs.tsx +14 -21
  101. package/packages/ui/src/primitives/tooltip.tsx +10 -22
  102. package/skill/SKILL.md +72 -59
  103. package/skill/Workflows/AlphaUpload.md +4 -4
  104. package/skill/Workflows/AutoActivation.md +11 -6
  105. package/skill/Workflows/Badge.md +22 -16
  106. package/skill/Workflows/Baseline.md +34 -36
  107. package/skill/Workflows/Composability.md +16 -11
  108. package/skill/Workflows/Contribute.md +26 -21
  109. package/skill/Workflows/Cron.md +23 -22
  110. package/skill/Workflows/Dashboard.md +40 -40
  111. package/skill/Workflows/Doctor.md +40 -34
  112. package/skill/Workflows/Evals.md +48 -47
  113. package/skill/Workflows/EvolutionMemory.md +31 -21
  114. package/skill/Workflows/Evolve.md +84 -82
  115. package/skill/Workflows/EvolveBody.md +58 -47
  116. package/skill/Workflows/Grade.md +16 -13
  117. package/skill/Workflows/ImportSkillsBench.md +9 -6
  118. package/skill/Workflows/Ingest.md +36 -21
  119. package/skill/Workflows/Initialize.md +138 -97
  120. package/skill/Workflows/Orchestrate.md +22 -16
  121. package/skill/Workflows/Replay.md +12 -7
  122. package/skill/Workflows/Rollback.md +13 -6
  123. package/skill/Workflows/Schedule.md +6 -6
  124. package/skill/Workflows/Sync.md +18 -11
  125. package/skill/Workflows/UnitTest.md +28 -17
  126. package/skill/Workflows/Watch.md +28 -21
  127. package/skill/agents/diagnosis-analyst.md +11 -0
  128. package/skill/agents/evolution-reviewer.md +15 -1
  129. package/skill/agents/integration-guide.md +10 -0
  130. package/skill/agents/pattern-analyst.md +12 -1
  131. package/skill/references/grading-methodology.md +23 -24
  132. package/skill/references/interactive-config.md +7 -7
  133. package/skill/references/invocation-taxonomy.md +22 -20
  134. package/skill/references/logs.md +20 -6
  135. package/skill/references/setup-patterns.md +4 -2
  136. package/.claude/agents/diagnosis-analyst.md +0 -156
  137. package/.claude/agents/evolution-reviewer.md +0 -180
  138. package/.claude/agents/integration-guide.md +0 -212
  139. package/.claude/agents/pattern-analyst.md +0 -160
  140. package/apps/local-dashboard/dist/assets/index-Bk9vSHHd.js +0 -15
@@ -18,12 +18,12 @@ selftune eval import --dir <path> --skill <name> --output <path> [options]
18
18
 
19
19
  ## Options
20
20
 
21
- | Flag | Description | Default |
22
- |------|-------------|---------|
23
- | `--dir <path>` | Path to SkillsBench tasks directory | Required |
24
- | `--skill <name>` | Target skill to match tasks against | Required |
25
- | `--output <path>` | Output eval set JSON file | Required |
26
- | `--match-strategy <type>` | Matching strategy: `exact` or `fuzzy` | `exact` |
21
+ | Flag | Description | Default |
22
+ | ------------------------- | ------------------------------------- | -------- |
23
+ | `--dir <path>` | Path to SkillsBench tasks directory | Required |
24
+ | `--skill <name>` | Target skill to match tasks against | Required |
25
+ | `--output <path>` | Output eval set JSON file | Required |
26
+ | `--match-strategy <type>` | Matching strategy: `exact` or `fuzzy` | `exact` |
27
27
 
28
28
  ## Match Strategies
29
29
 
@@ -108,10 +108,13 @@ corpus. Use the merged set with `selftune evolve --eval-set merged-evals.json`.
108
108
  ## Common Patterns
109
109
 
110
110
  **"Import SkillsBench tasks for Research"**
111
+
111
112
  > `selftune eval import --dir /path/tasks --skill Research --output bench-evals.json`
112
113
 
113
114
  **"Use fuzzy matching for broader coverage"**
115
+
114
116
  > `selftune eval import --dir /path/tasks --skill pptx --output bench-evals.json --match-strategy fuzzy`
115
117
 
116
118
  **"Enrich my eval set with external benchmarks"**
119
+
117
120
  > Import with `eval import`, then pass the output to `evolve --eval-set`.
@@ -8,13 +8,13 @@ Covers five sub-commands: `ingest claude`, `ingest codex`, `ingest opencode`,
8
8
 
9
9
  ## When to Use Each
10
10
 
11
- | Sub-command | Platform | Mode | When |
12
- |-------------|----------|------|------|
13
- | `ingest claude` | Claude Code | Batch | Backfill logs from existing Claude Code transcripts |
14
- | `ingest codex` | Codex | Batch | Import existing Codex rollout logs |
15
- | `ingest opencode` | OpenCode | Batch | Import existing OpenCode sessions |
16
- | `ingest openclaw` | OpenClaw | Batch | Import existing OpenClaw agent sessions |
17
- | `ingest wrap-codex` | Codex | Real-time | Wrap `codex exec` to capture telemetry live |
11
+ | Sub-command | Platform | Mode | When |
12
+ | ------------------- | ----------- | --------- | --------------------------------------------------- |
13
+ | `ingest claude` | Claude Code | Batch | Backfill logs from existing Claude Code transcripts |
14
+ | `ingest codex` | Codex | Batch | Import existing Codex rollout logs |
15
+ | `ingest opencode` | OpenCode | Batch | Import existing OpenCode sessions |
16
+ | `ingest openclaw` | OpenClaw | Batch | Import existing OpenClaw agent sessions |
17
+ | `ingest wrap-codex` | Codex | Real-time | Wrap `codex exec` to capture telemetry live |
18
18
 
19
19
  ---
20
20
 
@@ -30,13 +30,13 @@ selftune ingest claude
30
30
 
31
31
  ### Options
32
32
 
33
- | Flag | Description |
34
- |------|-------------|
35
- | `--since <date>` | Only ingest sessions modified after this date (e.g., `2026-01-01`) |
36
- | `--dry-run` | Show what would be ingested without writing to logs |
37
- | `--force` | Re-ingest all sessions, ignoring the marker file |
38
- | `--verbose` | Show per-file progress during ingestion |
39
- | `--projects-dir <path>` | Override default `~/.claude/projects/` directory |
33
+ | Flag | Description |
34
+ | ----------------------- | ------------------------------------------------------------------ |
35
+ | `--since <date>` | Only ingest sessions modified after this date (e.g., `2026-01-01`) |
36
+ | `--dry-run` | Show what would be ingested without writing to logs |
37
+ | `--force` | Re-ingest all sessions, ignoring the marker file |
38
+ | `--verbose` | Show per-file progress during ingestion |
39
+ | `--projects-dir <path>` | Override default `~/.claude/projects/` directory |
40
40
 
41
41
  ### Source
42
42
 
@@ -46,6 +46,7 @@ transcript files Claude Code automatically saves for every session.
46
46
  ### Output
47
47
 
48
48
  Writes to:
49
+
49
50
  - `~/.claude/all_queries_log.jsonl` -- extracted user queries (one per query, not just last)
50
51
  - `~/.claude/session_telemetry_log.jsonl` -- per-session metrics with `source: "claude_code_replay"`
51
52
  - `~/.claude/skill_usage_log.jsonl` -- skill triggers with `source: "claude_code_replay"`
@@ -88,6 +89,7 @@ JSONL format. See `references/logs.md` for the Codex rollout format.
88
89
  ### Output
89
90
 
90
91
  Writes to:
92
+
91
93
  - `~/.claude/all_queries_log.jsonl` -- extracted user queries
92
94
  - `~/.claude/session_telemetry_log.jsonl` -- per-session metrics with `source: "codex_rollout"`
93
95
 
@@ -124,6 +126,7 @@ See `references/logs.md` for the OpenCode message format.
124
126
  ### Output
125
127
 
126
128
  Writes to:
129
+
127
130
  - `~/.claude/all_queries_log.jsonl` -- extracted user queries
128
131
  - `~/.claude/session_telemetry_log.jsonl` -- per-session metrics with `source: "opencode"` or `"opencode_json"`
129
132
 
@@ -149,23 +152,25 @@ selftune ingest openclaw
149
152
 
150
153
  ### Options
151
154
 
152
- | Flag | Description |
153
- |------|-------------|
154
- | `--agents-dir <path>` | Override default `~/.openclaw/agents/` directory |
155
- | `--since <date>` | Only ingest sessions modified after this date (e.g., `2026-01-01`) |
156
- | `--dry-run` | Show what would be ingested without writing to logs |
157
- | `--force` | Re-ingest all sessions, ignoring the marker file |
158
- | `--verbose` / `-v` | Show per-session progress during ingestion |
155
+ | Flag | Description |
156
+ | --------------------- | ------------------------------------------------------------------ |
157
+ | `--agents-dir <path>` | Override default `~/.openclaw/agents/` directory |
158
+ | `--since <date>` | Only ingest sessions modified after this date (e.g., `2026-01-01`) |
159
+ | `--dry-run` | Show what would be ingested without writing to logs |
160
+ | `--force` | Re-ingest all sessions, ignoring the marker file |
161
+ | `--verbose` / `-v` | Show per-session progress during ingestion |
159
162
 
160
163
  ### Source
161
164
 
162
165
  Reads from `~/.openclaw/agents/<agentId>/sessions/*.jsonl`. Each JSONL file contains:
166
+
163
167
  - Line 1 (session header): `{"type":"session","version":5,"id":"<uuid>","timestamp":"<iso>","cwd":"<path>"}`
164
168
  - Line 2+ (messages): `{"role":"user|assistant|toolResult","content":[...],"timestamp":<ms>}`
165
169
 
166
170
  ### Output
167
171
 
168
172
  Writes to:
173
+
169
174
  - `~/.claude/all_queries_log.jsonl` -- extracted user queries
170
175
  - `~/.claude/session_telemetry_log.jsonl` -- per-session metrics with `source: "openclaw"`
171
176
  - `~/.claude/skill_usage_log.jsonl` -- skill triggers with `source: "openclaw"`
@@ -210,6 +215,7 @@ selftune ingest wrap-codex -- --model o3 "Fix the failing tests"
210
215
  ### Output
211
216
 
212
217
  Writes to:
218
+
213
219
  - `~/.claude/all_queries_log.jsonl` -- the user query
214
220
  - `~/.claude/session_telemetry_log.jsonl` -- session metrics with `source: "codex"`
215
221
 
@@ -233,30 +239,39 @@ through hooks.
233
239
  ## Common Patterns
234
240
 
235
241
  **"Backfill Claude Code sessions"**
242
+
236
243
  > Run `selftune ingest claude`. No options needed. Reads from `~/.claude/projects/`.
237
244
 
238
245
  **"Replay only recent Claude Code sessions"**
246
+
239
247
  > Run `selftune ingest claude --since 2026-02-01` with an appropriate date.
240
248
 
241
249
  **"Ingest codex logs"**
250
+
242
251
  > Run `selftune ingest codex`. No options needed. Reads from `$CODEX_HOME/sessions/`.
243
252
 
244
253
  **"Import opencode sessions"**
254
+
245
255
  > Run `selftune ingest opencode`. Reads from the SQLite database automatically.
246
256
 
247
257
  **"Ingest OpenClaw sessions"**
258
+
248
259
  > Run `selftune ingest openclaw`. Reads from `~/.openclaw/agents/` automatically.
249
260
 
250
261
  **"Import only recent OpenClaw sessions"**
262
+
251
263
  > Run `selftune ingest openclaw --since 2026-02-01` with an appropriate date.
252
264
 
253
265
  **"Run codex through selftune"**
266
+
254
267
  > Use `selftune ingest wrap-codex -- <codex args>` instead of `codex exec <args>` directly.
255
268
 
256
269
  **"Batch ingest vs real-time"**
270
+
257
271
  > Use `selftune ingest codex` or `selftune ingest opencode` for historical sessions.
258
272
  > Use `selftune ingest wrap-codex` for ongoing sessions. Both produce the same log format.
259
273
 
260
274
  **"How do I know it worked?"**
275
+
261
276
  > Run `selftune doctor` after ingestion. Check that log files exist and are parseable.
262
277
  > Run `selftune eval generate --list-skills` to see if the ingested sessions appear.
@@ -18,18 +18,19 @@ selftune init --no-alpha [--force]
18
18
 
19
19
  ## Options
20
20
 
21
- | Flag | Description | Default |
22
- |------|-------------|---------|
23
- | `--agent <type>` | Agent platform: `claude_code`, `codex`, `opencode`, `openclaw` | Auto-detected |
24
- | `--cli-path <path>` | Override auto-detected CLI entry-point path | Auto-detected |
25
- | `--force` | Reinitialize even if config already exists | Off |
26
- | `--enable-autonomy` | Enable autonomous scheduling during init | Off |
27
- | `--schedule-format <fmt>` | Schedule format: `cron`, `launchd`, `systemd` | Auto-detected |
28
- | `--alpha` | Enroll in the selftune alpha program | Off |
29
- | `--no-alpha` | Unenroll from the alpha program (preserves user_id) | Off |
30
- | `--alpha-email <email>` | Email for alpha enrollment (required with `--alpha`) | - |
31
- | `--alpha-name <name>` | Display name for alpha enrollment | - |
32
- | `--alpha-key <key>` | API key for cloud uploads (`st_live_*` format) | - |
21
+ | Flag | Description | Default |
22
+ | ------------------------- | ------------------------------------------------------------------------- | ------------- |
23
+ | `--agent <type>` | Agent platform: `claude_code`, `codex`, `opencode`, `openclaw` | Auto-detected |
24
+ | `--cli-path <path>` | Override auto-detected CLI entry-point path | Auto-detected |
25
+ | `--force` | Reinitialize even if config already exists | Off |
26
+ | `--no-sync` | Skip historical transcript backfill during init | Sync on |
27
+ | `--no-autonomy` | Skip autonomous scheduling setup during init | Autonomy on |
28
+ | `--enable-autonomy` | (Deprecated alias) Enable autonomous scheduling now on by default | On |
29
+ | `--schedule-format <fmt>` | Schedule format: `cron`, `launchd`, `systemd` | Auto-detected |
30
+ | `--alpha` | Enroll in the selftune alpha program (opens browser for device-code auth) | Off |
31
+ | `--no-alpha` | Unenroll from the alpha program (preserves user_id) | Off |
32
+ | `--alpha-email <email>` | Email for alpha enrollment (required with `--alpha`) | - |
33
+ | `--alpha-name <name>` | Display name for alpha enrollment | - |
33
34
 
34
35
  ## Output Format
35
36
 
@@ -46,29 +47,35 @@ Creates `~/.selftune/config.json`:
46
47
  "alpha": {
47
48
  "enrolled": true,
48
49
  "user_id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
50
+ "cloud_user_id": "cloud-uuid-...",
51
+ "cloud_org_id": "org-uuid-...",
49
52
  "email": "user@example.com",
50
53
  "display_name": "User Name",
51
- "consent_timestamp": "2026-02-28T10:00:00Z"
54
+ "consent_timestamp": "2026-02-28T10:00:00Z",
55
+ "api_key": "<provisioned automatically via device-code flow>"
52
56
  }
53
57
  }
54
58
  ```
55
59
 
56
60
  ### Field Descriptions
57
61
 
58
- | Field | Type | Description |
59
- |-------|------|-------------|
60
- | `agent_type` | string | Detected or specified agent platform |
61
- | `cli_path` | string | Absolute path to the CLI entry point |
62
- | `llm_mode` | string | How LLM calls are made: `agent` or `api` |
63
- | `agent_cli` | string | CLI binary name for the detected agent |
64
- | `hooks_installed` | boolean | Whether telemetry hooks are installed |
65
- | `initialized_at` | string | ISO 8601 timestamp |
66
- | `alpha` | object? | Alpha program enrollment (present only if enrolled) |
67
- | `alpha.enrolled` | boolean | Whether the user is currently enrolled |
68
- | `alpha.user_id` | string | Stable UUID, generated once, preserved across reinits |
69
- | `alpha.email` | string? | Email provided at enrollment |
70
- | `alpha.display_name` | string? | Optional display name |
71
- | `alpha.consent_timestamp` | string | ISO 8601 timestamp of consent |
62
+ | Field | Type | Description |
63
+ | ------------------------- | ------- | ----------------------------------------------------------------- |
64
+ | `agent_type` | string | Detected or specified agent platform |
65
+ | `cli_path` | string | Absolute path to the CLI entry point |
66
+ | `llm_mode` | string | How LLM calls are made: `agent` or `api` |
67
+ | `agent_cli` | string | CLI binary name for the detected agent |
68
+ | `hooks_installed` | boolean | Whether telemetry hooks are installed |
69
+ | `initialized_at` | string | ISO 8601 timestamp |
70
+ | `alpha` | object? | Alpha program enrollment (present only if enrolled) |
71
+ | `alpha.enrolled` | boolean | Whether the user is currently enrolled |
72
+ | `alpha.user_id` | string | Stable UUID, generated once, preserved across reinits |
73
+ | `alpha.cloud_user_id` | string? | Cloud account UUID (set by device-code flow) |
74
+ | `alpha.cloud_org_id` | string? | Cloud organization UUID (set by device-code flow) |
75
+ | `alpha.email` | string? | Email provided at enrollment |
76
+ | `alpha.display_name` | string? | Optional display name |
77
+ | `alpha.consent_timestamp` | string | ISO 8601 timestamp of consent |
78
+ | `alpha.api_key` | string? | Upload credential (provisioned automatically by device-code flow) |
72
79
 
73
80
  ## Steps
74
81
 
@@ -112,22 +119,29 @@ The init output will report what was installed, e.g.:
112
119
  [INFO] Installed 4 selftune hook(s) into ~/.claude/settings.json: UserPromptSubmit, PreToolUse, PostToolUse, Stop
113
120
  ```
114
121
 
122
+ For Claude Code, `selftune init` also syncs selftune's bundled specialized
123
+ agents from `skill/agents/` into `~/.claude/agents/`. The bundled files remain
124
+ the source of truth; the `~/.claude/agents/` copies exist only so native Claude
125
+ Code subagent calls stay up to date.
126
+
115
127
  **Hook reference** (for troubleshooting):
116
128
 
117
- | Hook | Script | Purpose |
118
- |------|--------|---------|
119
- | `UserPromptSubmit` | `hooks/prompt-log.ts` | Log every user query |
120
- | `UserPromptSubmit` | `hooks/auto-activate.ts` | Suggest skills before prompt processing |
121
- | `PreToolUse` (Write/Edit) | `hooks/skill-change-guard.ts` | Detect uncontrolled skill edits |
122
- | `PreToolUse` (Write/Edit) | `hooks/evolution-guard.ts` | Block SKILL.md edits on monitored skills |
123
- | `PostToolUse` (Read/Skill) | `hooks/skill-eval.ts` | Track skill triggers and Skill tool invocations |
124
- | `Stop` | `hooks/session-stop.ts` | Capture session telemetry |
129
+ | Hook | Script | Purpose |
130
+ | -------------------------- | ----------------------------- | ----------------------------------------------- |
131
+ | `UserPromptSubmit` | `hooks/prompt-log.ts` | Log every user query |
132
+ | `UserPromptSubmit` | `hooks/auto-activate.ts` | Suggest skills before prompt processing |
133
+ | `PreToolUse` (Write/Edit) | `hooks/skill-change-guard.ts` | Detect uncontrolled skill edits |
134
+ | `PreToolUse` (Write/Edit) | `hooks/evolution-guard.ts` | Block SKILL.md edits on monitored skills |
135
+ | `PostToolUse` (Read/Skill) | `hooks/skill-eval.ts` | Track skill triggers and Skill tool invocations |
136
+ | `Stop` | `hooks/session-stop.ts` | Capture session telemetry |
125
137
 
126
138
  **Codex agents:**
139
+
127
140
  - Use `selftune ingest wrap-codex` for real-time telemetry capture (see `Workflows/Ingest.md`)
128
141
  - Or batch-ingest existing sessions with `selftune ingest codex`
129
142
 
130
143
  **OpenCode agents:**
144
+
131
145
  - Use `selftune ingest opencode` to import sessions from the SQLite database
132
146
  - See `Workflows/Ingest.md` for details
133
147
 
@@ -140,6 +154,7 @@ mkdir -p ~/.selftune/memory
140
154
  ```
141
155
 
142
156
  The memory system stores three files at `~/.selftune/memory/`:
157
+
143
158
  - `context.md` -- active evolution state and session context
144
159
  - `decisions.md` -- evolution decisions and rollback history
145
160
  - `plan.md` -- current priorities and evolution strategy
@@ -166,12 +181,61 @@ selftune doctor
166
181
  Parse the JSON output. All checks should pass. If any fail, address the
167
182
  reported issues before proceeding.
168
183
 
184
+ ### 8. Sync Historical Transcripts
185
+
186
+ Init automatically runs `selftune sync` to backfill existing session
187
+ transcripts into the SQLite database. This replays Claude Code transcripts,
188
+ Codex rollouts, OpenCode sessions, and OpenClaw sessions so the eval set
189
+ and evolution pipeline have data to work with immediately.
190
+
191
+ The sync step is fail-open — if it encounters errors, init continues.
192
+ Skip with `--no-sync` if you only want hooks for forward-looking data.
193
+
194
+ ### 9. Autonomy Scheduling
195
+
196
+ Init automatically installs OS-level scheduling (launchd on macOS, cron/systemd
197
+ on Linux) so `selftune orchestrate` runs in the background. This is equivalent
198
+ to running `selftune cron setup` manually.
199
+
200
+ Skip with `--no-autonomy` if you prefer manual orchestration only.
201
+
202
+ ### 10. Offer Alpha Enrollment
203
+
204
+ After local setup passes, always offer alpha enrollment before ending the setup
205
+ workflow.
206
+
207
+ Use the `AskUserQuestion` tool to ask:
208
+
209
+ - `Would you like to enroll in the selftune alpha program for cloud-synced analytics?`
210
+
211
+ Options:
212
+
213
+ - `Yes — enable alpha uploads and richer cloud analytics`
214
+ - `No — keep local-only selftune`
215
+
216
+ If the user chooses yes, continue with the Alpha Enrollment steps below. If they
217
+ choose no, explicitly confirm that local-only setup is complete.
218
+
219
+ ### 11. Initial Data Upload
220
+
221
+ After alpha enrollment succeeds and sync has backfilled historical data, init
222
+ automatically triggers an upload cycle to push data to the cloud immediately.
223
+ This ensures the cloud has data from the moment the user finishes setup — they
224
+ don't have to wait for the next scheduled orchestrate run.
225
+
226
+ The upload is fail-open — if it fails, init still completes successfully.
227
+
228
+ Additionally, every `selftune sync` run now triggers an upload cycle when alpha
229
+ is enrolled, so data flows to the cloud every 30 minutes (matching the sync
230
+ schedule) rather than waiting for the 2-hour orchestrate cycle.
231
+
169
232
  ## Integration Guide
170
233
 
171
234
  For project-type-specific setup (single-skill, multi-skill, monorepo, Codex,
172
235
  OpenCode, mixed agents), see [docs/integration-guide.md](../../docs/integration-guide.md).
173
236
 
174
237
  Templates for each project type are bundled with the skill:
238
+
175
239
  - `skill/settings_snippet.json` — hooks for Claude Code projects
176
240
  - `assets/activation-rules-default.json` — default auto-activation rule configuration
177
241
 
@@ -188,86 +252,73 @@ workflow covers.
188
252
  Enroll the user in the selftune alpha program for early access features.
189
253
 
190
254
  Before running the alpha command:
191
- 1. Ask whether the user wants to opt into the selftune alpha data-sharing program
255
+
256
+ 1. Use `AskUserQuestion` to ask whether the user wants to opt into the selftune alpha data-sharing program
257
+ Options:
258
+ - `Yes — enable cloud-synced analytics and alpha uploads`
259
+ - `No — keep local-only selftune`
192
260
  2. If they opt in, ask for their email and optional display name
193
261
  3. If they decline, skip alpha enrollment and continue with plain `selftune init`
194
262
 
195
263
  The CLI stays non-interactive. The agent is responsible for collecting consent
196
264
  and the required `--alpha-email` value before invoking the command.
197
265
 
198
- ## Alpha Enrollment (Agent-First Flow)
266
+ ## Alpha Enrollment (Device-Code Flow)
199
267
 
200
268
  The alpha program sends canonical telemetry to the selftune cloud for analysis.
201
- Setup is agent-firstthe cloud app is a one-time control-plane handoff, not the main UX.
269
+ Enrollment uses a device-code flow one command, one browser approval, fully automatic.
202
270
 
203
271
  ### Setup Sequence
204
272
 
205
273
  1. **Check local config**: Run `selftune status` — look for the "Alpha Upload" section
206
- 2. **If not linked**: Tell the user:
207
- > To join the selftune alpha program, you need to create an account at https://app.selftune.dev and issue an upload credential. This is a one-time step — afterwards everything runs locally through the CLI.
208
- 3. **User completes cloud enrollment**: Signs in, enrolls, copies the `st_live_*` credential
209
- 4. **Store credential locally**:
274
+ 2. **If not linked**: First use `AskUserQuestion` for the opt-in decision. Only if the user says yes, collect their email and run:
210
275
 
211
276
  ```bash
212
- selftune init --alpha --alpha-email <user-email> --alpha-key <st_live_credential>
277
+ selftune init --alpha --alpha-email <user-email> --force
213
278
  ```
214
279
 
215
- 5. **Verify readiness**: The init command prints a readiness check. If all checks pass, alpha upload is active.
216
- The readiness JSON now includes a `guidance` object with:
280
+ 3. **Browser opens automatically**: The CLI requests a device code, opens the verification URL in the browser with the code pre-filled, and polls for approval.
281
+ 4. **User approves in browser**: One click to authorize.
282
+ 5. **CLI receives credentials**: API key, cloud_user_id, and org_id are automatically provisioned and stored in `~/.selftune/config.json` with `0600` permissions.
283
+ 6. **Verify readiness**: The init command prints a readiness check. If all checks pass, alpha upload is active.
284
+ The readiness JSON includes a `guidance` object with:
217
285
  - `message`
218
286
  - `next_command`
219
287
  - `suggested_commands[]`
220
288
  - `blocking`
221
- 6. **If readiness fails**: Run `selftune doctor` to diagnose. Common issues:
222
- - `api_key not set` → re-run init with `--alpha-key`
223
- - `api_key has invalid format` credential must start with `st_live_` or `st_test_`
224
- - `not enrolled` → re-run init with `--alpha --alpha-email <email> --alpha-key <key>`
289
+ 7. **If readiness fails**: Run `selftune doctor` to diagnose. Common issues:
290
+ - `not enrolled` → re-run `selftune init --alpha --alpha-email <email> --force`
291
+ - Device-code expired re-run the init command (codes expire after ~15 minutes)
225
292
 
226
293
  ### Key Principle
227
294
 
228
- The cloud app is used **only** for:
229
- - Sign-in
230
- - Alpha enrollment
231
- - Upload credential issuance
232
-
233
- All other selftune operations happen through the local CLI and this agent.
295
+ The cloud app is used **only** for the one-time browser approval during device-code auth. All other selftune operations happen through the local CLI and this agent.
234
296
 
235
297
  ### Enroll
236
298
 
237
299
  ```bash
238
300
  selftune init --alpha --alpha-email user@example.com --alpha-name "User Name" --force
239
- selftune init --alpha-key st_live_abc123... # after enrollment, store the API key
240
301
  ```
241
302
 
242
303
  The `--alpha-email` flag is required. The command will:
304
+
243
305
  1. Generate a stable UUID (preserved across reinits)
244
- 2. Write the alpha block to `~/.selftune/config.json`
245
- 3. Print an `alpha_enrolled` JSON message to stdout
246
- 4. Print the consent notice to stderr
247
- 5. If an `--alpha-key` is provided, chmod `~/.selftune/config.json` to `0600`
306
+ 2. Request a device code from the cloud API
307
+ 3. Open the browser to the verification URL
308
+ 4. Poll until the user approves
309
+ 5. Receive and store the API key, cloud_user_id, and org_id automatically
310
+ 6. Write the alpha block to `~/.selftune/config.json` with `0600` permissions
311
+ 7. Print an `alpha_enrolled` JSON message to stdout
312
+ 8. Print the consent notice to stderr
248
313
 
249
314
  The consent notice explicitly states that the friendly alpha cohort shares raw
250
315
  prompt/query text in addition to skill/session/evolution metadata.
251
316
 
252
- ### API Key Provisioning
253
-
254
- After enrollment, users need to configure an API key for cloud uploads:
255
-
256
- 1. Create a cloud account at the selftune web app
257
- 2. Generate an API key (format: `st_live_*`)
258
- 3. Store the key locally:
259
-
260
- ```bash
261
- selftune init --alpha --alpha-email <email> --alpha-key st_live_abc123... --force
262
- ```
263
-
264
- Without an API key, alpha enrollment is recorded locally but no uploads are attempted. When a key is stored, selftune tightens the local config file permissions to `0600`.
265
-
266
317
  ### Upload Behavior
267
318
 
268
- Once enrolled and an API key is configured, `selftune orchestrate` automatically
269
- uploads new session, invocation, and evolution data to the cloud API at the end of
270
- each run. This upload step is fail-open -- errors never block the orchestrate loop.
319
+ Once enrolled, `selftune orchestrate` automatically uploads new session,
320
+ invocation, and evolution data to the cloud API at the end of each run.
321
+ This upload step is fail-open -- errors never block the orchestrate loop.
271
322
  Use `selftune alpha upload` for manual uploads or `selftune alpha upload --dry-run`
272
323
  to preview what would be sent.
273
324
 
@@ -298,40 +349,30 @@ If `--alpha` is passed without `--alpha-email`, the CLI throws a JSON error:
298
349
  }
299
350
  ```
300
351
 
301
- When alpha readiness is evaluated after `selftune init --alpha`, the CLI emits:
302
-
303
- ```json
304
- {
305
- "alpha_readiness": {
306
- "ready": false,
307
- "missing": ["api_key not set"],
308
- "guidance": {
309
- "code": "alpha_credential_required",
310
- "message": "Alpha enrollment exists, but the local upload credential is missing or invalid.",
311
- "next_command": "selftune init --alpha --alpha-email user@example.com --alpha-key <st_live_key> --force",
312
- "suggested_commands": ["selftune status", "selftune doctor"],
313
- "blocking": true
314
- }
315
- }
316
- }
317
- ```
352
+ If the device-code flow fails (network error, timeout, user denied), the CLI throws
353
+ with a descriptive error message. The agent should relay this to the user and suggest
354
+ retrying with `selftune init --alpha --alpha-email <email> --force`.
318
355
 
319
356
  ## Common Patterns
320
357
 
321
358
  **User asks to set up or initialize selftune**
359
+
322
360
  > Run `which selftune` to check installation. If missing, install with
323
361
  > `npm install -g selftune`. Run `selftune init`, then verify with
324
362
  > `selftune doctor`. Report results to the user.
325
363
 
326
364
  **User wants alpha enrollment**
327
- > Ask whether they want to opt into alpha data sharing. If yes, collect email
328
- > and optional display name, then run `selftune init --alpha --alpha-email ...`.
329
- > If no, continue with plain `selftune init`.
365
+
366
+ > Use `AskUserQuestion` for the yes or no opt-in decision. If yes, collect email
367
+ > and optional display name in chat, then run `selftune init --alpha --alpha-email ...`.
368
+ > The browser opens automatically for approval. No manual key management needed.
330
369
 
331
370
  **Hooks not capturing data**
371
+
332
372
  > Run `selftune doctor` to check hook installation. Parse the JSON output
333
373
  > for failed hook checks. If paths are wrong, update
334
374
  > `~/.claude/settings.json` to point to actual files.
335
375
 
336
376
  **Config exists but appears stale**
377
+
337
378
  > Run `selftune init --force` to reinitialize. Verify with `selftune doctor`.
@@ -22,17 +22,17 @@ selftune orchestrate
22
22
 
23
23
  ## Flags
24
24
 
25
- | Flag | Description | Default |
26
- |------|-------------|---------|
27
- | `--dry-run` | Plan and validate without deploying changes | Off |
28
- | `--review-required` | Keep validated changes in review mode instead of deploying | Off |
29
- | `--auto-approve` | *(Deprecated)* Autonomous mode is now the default | — |
30
- | `--skill <name>` | Limit the loop to one skill | All skills |
31
- | `--max-skills <n>` | Cap how many candidates are processed in one run | `5` |
32
- | `--recent-window <hours>` | Window for post-deploy watch/rollback checks | `48` |
33
- | `--sync-force` | Force a full source replay before candidate selection | Off |
34
- | `--loop` | Run as a long-lived process that cycles continuously | Off |
35
- | `--loop-interval <seconds>` | Pause between cycles (minimum 60) | `3600` |
25
+ | Flag | Description | Default |
26
+ | --------------------------- | ---------------------------------------------------------- | ---------- |
27
+ | `--dry-run` | Plan and validate without deploying changes | Off |
28
+ | `--review-required` | Keep validated changes in review mode instead of deploying | Off |
29
+ | `--auto-approve` | _(Deprecated)_ Autonomous mode is now the default | — |
30
+ | `--skill <name>` | Limit the loop to one skill | All skills |
31
+ | `--max-skills <n>` | Cap how many candidates are processed in one run | `5` |
32
+ | `--recent-window <hours>` | Window for post-deploy watch/rollback checks | `48` |
33
+ | `--sync-force` | Force a full source replay before candidate selection | Off |
34
+ | `--loop` | Run as a long-lived process that cycles continuously | Off |
35
+ | `--loop-interval <seconds>` | Pause between cycles (minimum 60) | `3600` |
36
36
 
37
37
  ## Default Behavior
38
38
 
@@ -46,22 +46,27 @@ Use `--review-required` only when you want a stricter policy for a specific run.
46
46
  ## Common Patterns
47
47
 
48
48
  **User asks to improve skills or run the full loop**
49
+
49
50
  > Run `selftune orchestrate`. Parse the JSON output from stdout and the
50
51
  > phased report from stderr. Report the summary to the user.
51
52
 
52
53
  **User wants to preview changes before deploying**
54
+
53
55
  > Run `selftune orchestrate --dry-run`. Report the planned actions without
54
56
  > making any changes.
55
57
 
56
58
  **User wants to focus on a single skill**
59
+
57
60
  > Run `selftune orchestrate --skill <name>`. This limits the loop to the
58
61
  > specified skill only.
59
62
 
60
63
  **User wants manual review before deployment**
64
+
61
65
  > Run `selftune orchestrate --review-required`. Validated changes stay in
62
66
  > review mode instead of auto-deploying.
63
67
 
64
68
  **Agent needs fresh source data before orchestrating**
69
+
65
70
  > Run `selftune orchestrate --sync-force`. This forces a full source replay
66
71
  > before candidate selection.
67
72
 
@@ -94,11 +99,11 @@ This is the recommended runtime for recurring autonomous scheduling.
94
99
 
95
100
  `selftune orchestrate` runs in two contexts with different callers:
96
101
 
97
- | Context | Caller | Token cost | When |
98
- |---------|--------|------------|------|
99
- | **Interactive** | Agent (user says "improve my skills") | Uses agent subscription | On demand |
100
- | **Automated (cron)** | OS scheduler (cron/launchd/systemd) | No agent session; LLM cost only if evolution triggers | Every 6 hours |
101
- | **Automated (loop)** | `selftune orchestrate --loop` | No agent session; LLM cost only if evolution triggers | Configurable interval |
102
+ | Context | Caller | Token cost | When |
103
+ | -------------------- | ------------------------------------- | ----------------------------------------------------- | --------------------- |
104
+ | **Interactive** | Agent (user says "improve my skills") | Uses agent subscription | On demand |
105
+ | **Automated (cron)** | OS scheduler (cron/launchd/systemd) | No agent session; LLM cost only if evolution triggers | Every 6 hours |
106
+ | **Automated (loop)** | `selftune orchestrate --loop` | No agent session; LLM cost only if evolution triggers | Configurable interval |
102
107
 
103
108
  In automated mode, the OS calls the CLI binary directly. No agent session
104
109
  is created. LLM calls only happen during the evolution step (proposing and
@@ -123,6 +128,7 @@ reactive path complements the scheduled cron/loop modes by responding to signals
123
128
  immediately after the session that produced them.
124
129
 
125
130
  Guard rails:
131
+
126
132
  - Only spawns if unconsumed signals exist in `improvement_signals.jsonl`
127
133
  - Respects the orchestrate lock file — skips if another run started within 30 minutes
128
134
  - Fire-and-forget: the hook exits immediately, orchestrate runs independently