@chanlerdev/scorel 0.0.1

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 (80) hide show
  1. package/README.md +110 -0
  2. package/dist/index.js +6675 -0
  3. package/dist/index.js.map +7 -0
  4. package/docs/CHANGELOG.md +12 -0
  5. package/docs/README.md +116 -0
  6. package/docs/ROADMAP.md +669 -0
  7. package/docs/SHIP.md +242 -0
  8. package/docs/spec/channels.md +156 -0
  9. package/docs/spec/client.md +326 -0
  10. package/docs/spec/daemon.md +408 -0
  11. package/docs/spec/events.md +423 -0
  12. package/docs/spec/extensions.md +255 -0
  13. package/docs/spec/relay.md +391 -0
  14. package/docs/spec/runtime.md +251 -0
  15. package/docs/spec/session.md +380 -0
  16. package/docs/spec/ship/S0001-docs-baseline.md +41 -0
  17. package/docs/spec/ship/S0002-package-skeleton.md +56 -0
  18. package/docs/spec/ship/S0003-protocol-contracts.md +49 -0
  19. package/docs/spec/ship/S0004-session-core.md +50 -0
  20. package/docs/spec/ship/S0005-runtime-loop.md +48 -0
  21. package/docs/spec/ship/S0006-embedded-daemon-client.md +51 -0
  22. package/docs/spec/ship/S0007-cli-alpha.md +49 -0
  23. package/docs/spec/ship/S0008-coding-tools.md +107 -0
  24. package/docs/spec/ship/S0009-code-discovery-tools.md +82 -0
  25. package/docs/spec/ship/S0010-todo-tool-and-cli.md +81 -0
  26. package/docs/spec/ship/S0011-coding-agent-alpha-smoke.md +110 -0
  27. package/docs/spec/ship/S0012-coding-tools-maturity.md +143 -0
  28. package/docs/spec/ship/S0013-local-daemon-protocol.md +57 -0
  29. package/docs/spec/ship/S0014-local-daemon-lifecycle.md +64 -0
  30. package/docs/spec/ship/S0015-local-attach-and-broadcast.md +58 -0
  31. package/docs/spec/ship/S0016-local-daemon-resync-smoke.md +60 -0
  32. package/docs/spec/ship/S0017-grep-files-output-mode.md +49 -0
  33. package/docs/spec/ship/S0018-daemon-entrypoint-smoke.md +48 -0
  34. package/docs/spec/ship/S0019-remote-transport-contract.md +59 -0
  35. package/docs/spec/ship/S0020-remote-websocket-server.md +56 -0
  36. package/docs/spec/ship/S0021-remote-websocket-client-transport.md +55 -0
  37. package/docs/spec/ship/S0022-remote-daemon-cli-lifecycle.md +60 -0
  38. package/docs/spec/ship/S0023-remote-control-e2e-validation.md +66 -0
  39. package/docs/spec/ship/S0024-remote-attach-interactive-stream.md +49 -0
  40. package/docs/spec/ship/S0025-remote-attach-session-event-view.md +57 -0
  41. package/docs/spec/ship/S0026-attach-project-cache-and-dual-seq-reconnect.md +87 -0
  42. package/docs/spec/ship/S0027-session-diagnostics-log.md +77 -0
  43. package/docs/spec/ship/S0028-client-attach-diagnostics-log.md +70 -0
  44. package/docs/spec/ship/S0029-project-index-for-session-lookup.md +119 -0
  45. package/docs/spec/ship/S0030-webui-product-intent.md +73 -0
  46. package/docs/spec/ship/S0031-daemon-projectslug-rule.md +72 -0
  47. package/docs/spec/ship/S0032-daemon-protocol-completion.md +123 -0
  48. package/docs/spec/ship/S0033-webui-skeleton-routing.md +92 -0
  49. package/docs/spec/ship/S0034-webui-device-settings.md +121 -0
  50. package/docs/spec/ship/S0035-webui-device-handshake.md +83 -0
  51. package/docs/spec/ship/S0036-webui-project-session-sync.md +70 -0
  52. package/docs/spec/ship/S0037-webui-chatbox-v1.md +97 -0
  53. package/docs/spec/ship/S0038-webui-cancel-multiclient.md +65 -0
  54. package/docs/spec/ship/S0039-webui-e2e-newchat.md +74 -0
  55. package/docs/spec/ship/S0040-webui-codex-visual-tokens.md +227 -0
  56. package/docs/spec/ship/S0041-webui-markdown-and-tool-block.md +248 -0
  57. package/docs/spec/ship/S0042-webui-streaming-ux-autoscroll.md +130 -0
  58. package/docs/spec/ship/S0043-startup-ergonomics.md +278 -0
  59. package/docs/spec/ship/S0044-webui-chatbox-rebuild.md +556 -0
  60. package/docs/spec/ship/S0045-webui-card-sidebar-and-session-fixes.md +469 -0
  61. package/docs/spec/ship/S0046-webui-empty-composer-and-lazy-session.md +428 -0
  62. package/docs/spec/ship/S0047-webui-project-hover-newchat-and-dynamic-greeting.md +176 -0
  63. package/docs/spec/ship/S0048-device-level-host-project-registry.md +253 -0
  64. package/docs/spec/ship/S0049-webui-add-project-directory-browser.md +217 -0
  65. package/docs/spec/ship/S0050-instruction-snapshot-and-agents-assembly.md +338 -0
  66. package/docs/spec/ship/S0051-harness-item-and-system-reminder.md +190 -0
  67. package/docs/spec/ship/S0052-follow-up-queue-and-dual-loop.md +195 -0
  68. package/docs/spec/ship/S0053-skill-index-and-skill-tool.md +252 -0
  69. package/docs/spec/ship/S0054-webui-running-message-behavior.md +72 -0
  70. package/docs/spec/ship/S0055-webui-composer-acceptance-and-queue-strip.md +68 -0
  71. package/docs/spec/ship/S0056-relay-and-hosted-webui-contract.md +106 -0
  72. package/docs/spec/ship/S0057-relay-service-protocol-skeleton.md +161 -0
  73. package/docs/spec/ship/S0058-host-outbound-relay-and-pair-command.md +138 -0
  74. package/docs/spec/ship/S0059-relay-transport-and-hosted-webui-connector.md +140 -0
  75. package/docs/spec/ship/S0060-relay-hosted-webui-e2e-validation.md +132 -0
  76. package/docs/spec/ship/S0060-relay-hosted-webui-e2e-validation.verification.md +90 -0
  77. package/docs/spec/ship/S0061-hosted-defaults-and-cli-command-surface.md +208 -0
  78. package/docs/spec/ship/S0062-npm-package-and-release-workflow.md +166 -0
  79. package/docs/spec/tools.md +173 -0
  80. package/package.json +51 -0
@@ -0,0 +1,49 @@
1
+ # S0007: CLI Alpha
2
+
3
+ ## Goal
4
+
5
+ Expose the M1 product experience: `scorel chat` starts the embedded path, streams assistant output, and resumes a persisted local session.
6
+
7
+ ## Deliverable
8
+
9
+ - `scorel chat` command in `apps/cli`.
10
+ - Local session create/resume behavior.
11
+ - Prompt input loop for minimal multi-turn chat.
12
+ - Streaming assistant output.
13
+ - Basic status/error output.
14
+ - Real provider runtime path for manual/product validation.
15
+
16
+ ## Success Criteria
17
+
18
+ - A user can run `scorel chat`, send multiple prompts, see assistant output, exit, and continue the same session.
19
+ - CLI uses `@scorel/client` plus embedded daemon wiring; it does not call runtime/session directly.
20
+ - Session files are written through daemon-owned persistence.
21
+ - The CLI remains simple enough to replace with TUI/WebUI later without moving domain logic into the app.
22
+
23
+ ## Boundaries
24
+
25
+ - No slash command suite.
26
+ - No remote `attach`.
27
+ - No standalone daemon command behavior beyond entrypoint shell if already created.
28
+ - No checkpoint, rewind, compact, permission, MCP management, or GUI.
29
+ - No polished TUI. Plain terminal interaction is enough.
30
+
31
+ ## Verification
32
+
33
+ - `pnpm --filter @scorel/app-cli test`
34
+ - End-to-end validation runs CLI against a real provider and verifies multi-turn persistence.
35
+ - `pnpm -r typecheck`
36
+ - `pnpm -r test`
37
+
38
+ ## Affected Paths
39
+
40
+ - `apps/cli/`
41
+ - `packages/client/`
42
+ - `packages/daemon/`
43
+ - `packages/core/`
44
+ - `packages/protocol/`
45
+
46
+ ## Risks
47
+
48
+ - Putting UX shortcuts directly into CLI can bypass daemon/client and invalidate the architecture.
49
+ - Mock-only validation can make the CLI look complete while no real model can run. Keep deterministic unit coverage, but product completion requires real-provider validation.
@@ -0,0 +1,107 @@
1
+ # S0008: File And Shell Coding Tools
2
+
3
+ ## Goal
4
+
5
+ Expose the first coding-agent tool surface through the existing runtime, daemon, client, and CLI path: `Read`, `Write`, `Edit`, and `Bash`.
6
+
7
+ This is M2.1. It makes `scorel chat` capable of reading files, editing files, writing files, and running verification commands in a real workspace. Search tools and Todo are intentionally separate follow-up specs.
8
+
9
+ ## Deliverable
10
+
11
+ - Built-in `Read` tool.
12
+ - Built-in `Write` tool.
13
+ - Built-in `Edit` tool.
14
+ - Built-in `Bash` tool.
15
+ - Tool registration path for the default `coding` preset.
16
+ - Runtime loop support for emitting tool call and tool result messages through daemon/client events.
17
+ - Session persistence for tool calls and tool results.
18
+ - CLI-visible tool progress / result output that is plain and debuggable.
19
+
20
+ ## Tool Semantics
21
+
22
+ ### `Read`
23
+
24
+ - Reads a file from the local filesystem.
25
+ - Accepts an absolute or cwd-relative file path; paths resolve under the CLI working directory unless absolute.
26
+ - Does not read directories.
27
+ - Supports `offset` and `limit` by line.
28
+ - Returns content with stable 1-based line numbers.
29
+ - Fails predictably for missing files, directories, unreadable files, and oversized reads that require `offset` / `limit`.
30
+ - Records enough read state for `Write` / `Edit` stale checks.
31
+
32
+ ### `Write`
33
+
34
+ - Creates a new file or fully rewrites a file.
35
+ - Existing files must be read first in the current session before `Write`.
36
+ - If the file changes after the recorded read, `Write` must fail instead of overwriting.
37
+ - Prefer `Edit` for normal modifications to existing files.
38
+ - Creates parent directories only when explicitly requested by args or implementation contract; do not silently create broad directory trees.
39
+
40
+ ### `Edit`
41
+
42
+ - Performs exact string replacement.
43
+ - Existing files must be read first in the current session before `Edit`.
44
+ - If the file changes after the recorded read, `Edit` must fail instead of applying stale changes.
45
+ - `old_string` must match exactly once unless `replace_all` is true.
46
+ - `old_string === new_string`, missing matches, and ambiguous matches must fail with clear tool-result errors.
47
+ - Creating new files through `Edit` is not required for M2; use `Write`.
48
+
49
+ ### `Bash`
50
+
51
+ - Executes a command in a specified cwd.
52
+ - Has a default timeout and a hard maximum timeout.
53
+ - Truncates large stdout/stderr while preserving exit code and enough diagnostic tail.
54
+ - Returns non-zero exits as tool results, not thrown runtime failures.
55
+ - Is for commands, tests, builds, git status, and project scripts.
56
+ - Must not be encouraged as the primary path for reading or editing files; use `Read`, `Write`, and `Edit`.
57
+
58
+ ## Scope
59
+
60
+ - Keep tools in `@scorel/core`.
61
+ - Keep execution owned by runtime / daemon, not CLI.
62
+ - Keep CLI as an entrypoint that displays events.
63
+ - Keep tool errors as data visible to the model and user.
64
+
65
+ ## Not In Scope
66
+
67
+ - Snapshot-based recovery.
68
+ - Permission approval UI or policy.
69
+ - Sandbox execution.
70
+ - `Grep`, `Glob`, `Todo`, `LS`, notebook editing, image/PDF reading.
71
+ - MCP tool loading.
72
+ - Remote daemon or reconnect semantics beyond existing M1 path.
73
+ - Rewind / compact / cancel / steer / followUp UX.
74
+
75
+ ## Acceptance Criteria
76
+
77
+ - `scorel chat` can use the built-in tools through the daemon/client path.
78
+ - A real-provider smoke can trigger `Read`, `Write`, `Edit`, and `Bash` through model tool calls.
79
+ - Tool call and tool result events are persisted in JSONL and restored into context.
80
+ - `Write` and `Edit` reject existing-file changes when the file was not read first.
81
+ - `Write` and `Edit` reject stale writes after external file modification.
82
+ - `Edit` rejects missing and ambiguous `old_string` matches.
83
+ - `Bash` enforces timeout and output truncation.
84
+ - CLI-facing code does not import session/runtime internals directly.
85
+
86
+ ## Verification
87
+
88
+ - `pnpm --filter @scorel/core test -- tools`
89
+ - `pnpm --filter @scorel/daemon test`
90
+ - `pnpm --filter @scorel/client test`
91
+ - `pnpm --filter @scorel/app-cli test`
92
+ - `pnpm typecheck && pnpm test`
93
+
94
+ ## Affected Paths
95
+
96
+ - `packages/core/src/tools/`
97
+ - `packages/core/src/runtime/`
98
+ - `packages/daemon/`
99
+ - `packages/client/`
100
+ - `apps/cli/`
101
+ - `packages/protocol/src/`
102
+
103
+ ## Risks
104
+
105
+ - Overbuilding Bash permissions will stall M2. Use minimal local execution constraints first: cwd, timeout, truncation, and structured errors.
106
+ - Letting Bash replace file tools will make edits harder to inspect and test. Tool descriptions must strongly prefer `Read` / `Write` / `Edit` for file operations.
107
+ - Skipping stale checks on `Write` / `Edit` can overwrite user edits. Pre-read state is mandatory for existing-file writes.
@@ -0,0 +1,82 @@
1
+ # S0009: Code Discovery Tools
2
+
3
+ ## Goal
4
+
5
+ Expose structured code discovery tools through the existing runtime, daemon, client, and CLI path: `Glob` and `Grep`.
6
+
7
+ This is M2.2. It keeps common code search out of ad hoc shell output so tool results are easier to display, persist, replay, and summarize.
8
+
9
+ ## Deliverable
10
+
11
+ - Built-in `Glob` tool.
12
+ - Built-in `Grep` tool.
13
+ - Tool registration in the default `coding` preset.
14
+ - Tool registration in the `readonly` preset.
15
+ - Structured result shape for matched paths and content hits.
16
+ - CLI-visible search progress / result output that is compact and debuggable.
17
+
18
+ ## Tool Semantics
19
+
20
+ ### `Glob`
21
+
22
+ - Finds files by glob pattern under a cwd.
23
+ - Returns stable, normalized paths.
24
+ - Sorts results predictably.
25
+ - Enforces a maximum result count.
26
+ - Fails predictably for invalid patterns and inaccessible cwd.
27
+
28
+ ### `Grep`
29
+
30
+ - Searches file contents using ripgrep-compatible semantics.
31
+ - Supports regex patterns.
32
+ - Supports glob/type filtering when practical.
33
+ - Supports output modes for matching files and matching lines.
34
+ - Enforces maximum result count and output size.
35
+ - Fails predictably for invalid regex, inaccessible cwd, and missing ripgrep.
36
+
37
+ ## Scope
38
+
39
+ - Keep search tools in `@scorel/core`.
40
+ - Keep execution owned by runtime / daemon, not CLI.
41
+ - Persist tool calls and tool results in session JSONL.
42
+ - Keep errors as tool-result data visible to the model and user.
43
+
44
+ ## Not In Scope
45
+
46
+ - Full file indexing.
47
+ - LSP symbol search.
48
+ - Web search.
49
+ - Directory listing as a standalone `LS` tool.
50
+ - MCP search tools.
51
+
52
+ ## Acceptance Criteria
53
+
54
+ - `scorel chat` can use `Glob` and `Grep` through the daemon/client path.
55
+ - A real-provider smoke can trigger both tools through model tool calls.
56
+ - `Glob` returns stable path lists and respects result limits.
57
+ - `Grep` returns structured matches and respects result/output limits.
58
+ - Tool calls and results are persisted in JSONL and restored into context.
59
+ - CLI-facing code does not import session/runtime internals directly.
60
+
61
+ ## Verification
62
+
63
+ - `pnpm --filter @scorel/core test -- tools`
64
+ - `pnpm --filter @scorel/daemon test`
65
+ - `pnpm --filter @scorel/client test`
66
+ - `pnpm --filter @scorel/app-cli test`
67
+ - `pnpm typecheck && pnpm test`
68
+
69
+ ## Affected Paths
70
+
71
+ - `packages/core/src/tools/`
72
+ - `packages/core/src/runtime/`
73
+ - `packages/daemon/`
74
+ - `packages/client/`
75
+ - `apps/cli/`
76
+ - `packages/protocol/src/`
77
+
78
+ ## Risks
79
+
80
+ - If `Grep` just wraps arbitrary shell text, search results will be hard to display and replay. Keep the output structured.
81
+ - If result limits are missing, a large repository can flood the session context.
82
+ - If Bash remains the preferred search route, the model will learn the wrong tool habit.
@@ -0,0 +1,81 @@
1
+ # S0010: Todo Tool And CLI
2
+
3
+ ## Goal
4
+
5
+ Expose a normal Todo List tool and make Todo state changes visible in the CLI.
6
+
7
+ This is M2.3. It gives coding sessions a lightweight progress backbone without introducing plan mode, subagents, or workflow orchestration.
8
+
9
+ ## Deliverable
10
+
11
+ - Built-in `Todo` tool.
12
+ - Todo item model with `id`, `content`, and `status`.
13
+ - Supported statuses: `pending`, `in_progress`, `completed`.
14
+ - Replace/update semantics for the current session's Todo list.
15
+ - Session persistence for Todo state changes.
16
+ - Daemon/client events for Todo changes.
17
+ - CLI rendering for the current Todo list and status transitions.
18
+
19
+ ## Tool Semantics
20
+
21
+ ### `Todo`
22
+
23
+ - Maintains a session-scoped Todo list.
24
+ - Creates, updates, reorders, and deletes Todo items.
25
+ - Allows at most one `in_progress` item at a time.
26
+ - Treats Todo changes as structured state, not free-form assistant text.
27
+ - Emits clear errors for invalid ids, invalid statuses, duplicate `in_progress` items, and malformed updates.
28
+
29
+ ## CLI Semantics
30
+
31
+ - CLI displays Todo list changes when they happen.
32
+ - CLI shows status transitions clearly enough for the user to understand current progress.
33
+ - CLI output stays plain terminal text; no TUI is required.
34
+ - Resume should reconstruct the latest Todo state from session JSONL.
35
+
36
+ ## Scope
37
+
38
+ - Keep Todo state session-scoped.
39
+ - Keep Todo owned by runtime / daemon, not CLI-local memory.
40
+ - Persist Todo changes in JSONL.
41
+ - Keep Todo visible to the user and available to the model as useful context.
42
+
43
+ ## Not In Scope
44
+
45
+ - Plan mode.
46
+ - Dependencies between Todo items.
47
+ - Owners, teams, subagents, or delegation.
48
+ - Cross-session Todo storage.
49
+ - Calendar/reminder automation.
50
+
51
+ ## Acceptance Criteria
52
+
53
+ - `scorel chat` can use `Todo` through the daemon/client path.
54
+ - Todo changes are persisted in JSONL and restored on resume.
55
+ - CLI visibly updates when Todo items are created, completed, deleted, or moved to `in_progress`.
56
+ - Invalid Todo updates return structured tool-result errors.
57
+ - A test verifies that two items cannot both be `in_progress`.
58
+ - CLI-facing code does not import session/runtime internals directly.
59
+
60
+ ## Verification
61
+
62
+ - `pnpm --filter @scorel/core test -- todo`
63
+ - `pnpm --filter @scorel/daemon test`
64
+ - `pnpm --filter @scorel/client test`
65
+ - `pnpm --filter @scorel/app-cli test`
66
+ - `pnpm typecheck && pnpm test`
67
+
68
+ ## Affected Paths
69
+
70
+ - `packages/core/src/tools/`
71
+ - `packages/core/src/runtime/`
72
+ - `packages/daemon/`
73
+ - `packages/client/`
74
+ - `apps/cli/`
75
+ - `packages/protocol/src/`
76
+
77
+ ## Risks
78
+
79
+ - If Todo is only assistant text, resume and UI state become unreliable. Store it as structured session state.
80
+ - If Todo becomes a workflow engine, M2 will stall. Keep it to a plain list.
81
+ - If CLI hides Todo changes, the user loses trust in long-running coding tasks.
@@ -0,0 +1,110 @@
1
+ # S0011: Coding Agent Alpha Smoke
2
+
3
+ ## Goal
4
+
5
+ Validate M2 as a complete Coding Agent Alpha rather than a collection of isolated tools.
6
+
7
+ This is M2.4. It proves `scorel chat` can complete a small coding task in a real temporary repository using search, read, edit/write, bash verification, Todo progress, session persistence, and resume.
8
+
9
+ ## Deliverable
10
+
11
+ - End-to-end real-provider coding smoke test.
12
+ - Strict config schema for pi-ai builtin/custom model selection.
13
+ - Fixed Scorel user root and session path: `~/.scorel` and `~/.scorel/sessions`.
14
+ - Temporary repository fixture with source files and a test command.
15
+ - Scripted task that requires `Glob` or `Grep`, `Read`, `Edit` or `Write`, `Bash`, and `Todo`.
16
+ - Assertions for CLI-visible tool output and Todo status changes.
17
+ - Assertions that tool calls, tool results, and Todo state persist to JSONL.
18
+ - Resume assertion that the latest context includes prior tool results and Todo state.
19
+
20
+ ## Scenario
21
+
22
+ The smoke should use a small real workspace, for example:
23
+
24
+ 1. User asks Scorel to fix a failing function.
25
+ 2. Model creates a Todo list.
26
+ 3. Model uses `Grep` or `Glob` to find the target file.
27
+ 4. Model uses `Read` to inspect the file.
28
+ 5. Model uses `Edit` or `Write` to change it.
29
+ 6. Model uses `Bash` to run the relevant test.
30
+ 7. Model marks Todo items complete.
31
+ 8. CLI output shows tool calls, command result, and Todo transitions.
32
+ 9. Session JSONL can be loaded again and used for resume.
33
+
34
+ ## Scope
35
+
36
+ - Use pi-ai for real provider protocol handling in product validation.
37
+ - Keep fixed product paths out of config; config only covers variable model/provider settings.
38
+ - Keep pi-ai builtin models and custom compatible endpoints as separate config branches.
39
+ - Verify the full daemon/client/CLI path.
40
+ - Keep the fixture small and fast.
41
+ - Treat this spec as M2 completion proof.
42
+
43
+ ## Not In Scope
44
+
45
+ - Mock-only or scripted fake-provider validation as completion proof.
46
+ - Broad benchmark suite.
47
+ - Permission approval, sandbox, checkpoint, remote daemon, MCP, GUI.
48
+ - Complex multi-file refactors.
49
+
50
+ ## Acceptance Criteria
51
+
52
+ - The end-to-end smoke fails before the integrated real-provider M2 path is complete.
53
+ - The smoke passes after S0008, S0009, and S0010 are implemented.
54
+ - CLI output includes visible Todo transitions and tool progress/result output.
55
+ - JSONL contains the expected user message, assistant/tool events, and Todo state changes.
56
+ - Resume loads enough context for the model to continue from the completed task.
57
+ - `pnpm typecheck && pnpm test` passes.
58
+
59
+ ## Config Shape
60
+
61
+ Builtin pi-ai model:
62
+
63
+ ```toml
64
+ [model]
65
+ type = "builtin"
66
+ provider = "openai"
67
+ id = "gpt-5.4-mini"
68
+ apiKeyEnv = "SCOREL_API_KEY"
69
+ ```
70
+
71
+ Custom compatible endpoint:
72
+
73
+ ```toml
74
+ [model]
75
+ type = "custom"
76
+ api = "openai-completions"
77
+ provider = "chanleramp"
78
+ id = "gpt-5.4-mini"
79
+ baseUrl = "https://amp.chanler.dev/v1"
80
+ apiKeyEnv = "SCOREL_API_KEY"
81
+ contextWindow = 400000
82
+ maxTokens = 128000
83
+ reasoning = true
84
+ ```
85
+
86
+ Supported custom `api` values for M2 are `openai-completions`, `openai-responses`, `google-generative-ai`, and `anthropic-messages`.
87
+
88
+ ## Verification
89
+
90
+ - `pnpm --filter @scorel/app-cli test -- coding-agent-alpha`
91
+ - `pnpm --filter @scorel/core test -- tools`
92
+ - `pnpm --filter @scorel/daemon test`
93
+ - `pnpm --filter @scorel/client test`
94
+ - `pnpm typecheck && pnpm test`
95
+
96
+ ## Affected Paths
97
+
98
+ - `apps/cli/`
99
+ - `apps/cli/src/index.test.ts`
100
+ - `packages/core/src/tools/`
101
+ - `packages/core/src/runtime/`
102
+ - `packages/daemon/`
103
+ - `packages/client/`
104
+ - `packages/protocol/src/`
105
+
106
+ ## Risks
107
+
108
+ - A smoke that only checks isolated tool calls will not prove product value. It must go through CLI-visible daemon/client flow.
109
+ - A mock-only smoke can hide the product failure mode where `scorel chat` cannot actually call an LLM. Completion proof must include a real provider run.
110
+ - If resume is skipped, Scorel loses its product distinction from a disposable coding chat.
@@ -0,0 +1,143 @@
1
+ # S0012: Coding Tools Maturity
2
+
3
+ ## Goal
4
+
5
+ Mature the M2 coding tool surface by aligning the contracts with Claude Code / pi-coding-agent style behavior while keeping the current daemon/client/runtime path unchanged.
6
+
7
+ This is a tool-semantics hardening spec, not a checkpoint, sandbox, permission UI, LSP, subagent, or remote daemon spec.
8
+
9
+ ## Deliverable
10
+
11
+ - Replace `Todo` with `TodoWrite`.
12
+ - Keep the user-visible tool set to `Read` / `Write` / `Edit` / `Bash` / `Glob` / `Grep` / `TodoWrite`.
13
+ - Harden `Read` state so writes require complete coverage of the current file version.
14
+ - Truncate long default `Read` results and report returned line count, total line count, truncation, and continuation offset.
15
+ - Harden `Write` as full-file create/update with pre-read coverage and stale checks for existing files.
16
+ - Harden `Edit` as exact single replacement with pre-read coverage and stale checks.
17
+ - Move `Glob` and `Grep` to ripgrep-backed implementations.
18
+ - Keep tool errors visible as tool results through the existing runtime/daemon/client path.
19
+ - Update pi-ai tool schemas and CLI smoke to use `TodoWrite`.
20
+
21
+ ## Tool Semantics
22
+
23
+ ### `Read`
24
+
25
+ - Arguments: `file_path`, `offset?`, `limit?`, `full?`.
26
+ - Reads one file from the local workspace.
27
+ - Supports `offset` and `limit`.
28
+ - Defaults to returning at most 2,000 complete lines.
29
+ - Also enforces a dynamic output budget of 1% of the current model context window by removing whole lines from the end of the result.
30
+ - `full: true` uses a larger 10% context-window budget.
31
+ - If no model context window is available, the fallback context window is 200,000 tokens.
32
+ - Token usage is estimated on the line-numbered tool result text, conservatively as roughly one token per three characters until a model tokenizer is available.
33
+ - Never truncates inside a line. If one line exceeds the output budgets, `Read` fails instead of returning a partial line.
34
+ - Returns `startLine`, `endLine`, `totalLines`, `truncated`, `nextOffset`, `canWrite`, `estimatedTokens`, and `tokenBudget`.
35
+ - Returns stable 1-based line numbers.
36
+ - Rejects binary files and document/media types that are not yet supported by a dedicated reader path.
37
+ - Read ranges are accumulated for the current file version.
38
+ - `canWrite` becomes true once the accumulated ranges cover the full current file.
39
+ - Truncated reads do not unlock `Write` / `Edit` until follow-up reads cover the remaining lines.
40
+ - `full: true` requests the full file and cannot be combined with `offset` or `limit`; it is still subject to the 10% dynamic token budget.
41
+ - Directories fail with a hint to use `Glob`.
42
+
43
+ ### `Write`
44
+
45
+ - Arguments: `file_path`, `content`.
46
+ - Creates new files without a prior read.
47
+ - Updating existing files requires prior read coverage of the full current file.
48
+ - Updating existing files fails if the file changed since the read.
49
+ - Writes are full-file replacements.
50
+ - Successful writes update the read snapshot to the new full content.
51
+ - Model-facing result is lightweight: success text plus `type`, `filePath`, and `bytes`; full old/new contents are not returned.
52
+
53
+ ### `Edit`
54
+
55
+ - Arguments: `file_path`, `old_string`, `new_string`, `replace_all?`.
56
+ - Requires prior read coverage of the full current file.
57
+ - Fails if the file changed since read.
58
+ - Fails if `old_string === new_string`.
59
+ - Fails if `old_string` is missing.
60
+ - Fails if `old_string` matches multiple times unless `replace_all` is true.
61
+ - Successful edits update the read snapshot to the new full content.
62
+ - Model-facing result is lightweight: success text plus file path and replacement counts; full diffs and file contents are reserved for UI/event metadata.
63
+
64
+ ### `Bash`
65
+
66
+ - Arguments: `command`, `cwd?`, `timeout?`, `maxOutputBytes?`, `description?`.
67
+ - Runs in the workspace or a workspace subdirectory.
68
+ - Enforces timeout and output truncation.
69
+ - Non-zero exits return tool results, not runtime crashes.
70
+ - Timeout returns a tool error visible to the model.
71
+
72
+ ### `Glob`
73
+
74
+ - Arguments: `pattern`, `path?`, `head_limit?`, `offset?`.
75
+ - Uses ripgrep file discovery (`rg --files`) plus `--glob` filters.
76
+ - Defaults to current workspace when `path` is omitted.
77
+ - Returns relative file paths.
78
+ - Applies pagination and truncation metadata.
79
+
80
+ ### `Grep`
81
+
82
+ - Arguments: `pattern`, `path?`, `glob?`, `output_mode?`, `-B?`, `-A?`, `-C?`, `context?`, `-n?`, `-i?`, `type?`, `head_limit?`, `offset?`, `multiline?`.
83
+ - Uses ripgrep for content search.
84
+ - Default `output_mode` is `files`.
85
+ - Supports `content`, `files`, and `count`.
86
+ - Adds result limits by default.
87
+ - Uses ripgrep `--max-columns 500` to avoid noisy minified/base64 lines.
88
+ - Returns relative paths and pagination metadata.
89
+
90
+ ### `TodoWrite`
91
+
92
+ - Arguments: complete `todos` array.
93
+ - Each todo has `content`, `status`, and optional `activeForm`.
94
+ - Status is `pending`, `in_progress`, or `completed`.
95
+ - Allows at most one `in_progress`.
96
+ - Replaces the session todo list as a whole.
97
+ - If all provided todos are `completed`, the stored current list becomes empty.
98
+ - Result includes only `oldTodos` and `currentTodos`; a text reminder may explain automatic clearing.
99
+
100
+ ## Not In Scope
101
+
102
+ - `MultiEdit`.
103
+ - Permission approval UI.
104
+ - Sandbox execution.
105
+ - Checkpoint / rollback.
106
+ - LSP.
107
+ - Background Bash / monitor.
108
+ - Web tools.
109
+ - MCP tool loading.
110
+
111
+ ## Acceptance Criteria
112
+
113
+ - `TodoWrite` is registered and exposed to pi-ai instead of `Todo`.
114
+ - `TodoWrite` returns old/current todo lists and clears stored current todos when all requested todos are completed.
115
+ - Default `Read` truncates long files by complete lines and returns the current line range and total line count.
116
+ - `Read` enforces line and dynamic estimated-token budgets without returning partial lines.
117
+ - `Read` rejects binary/document/media files until dedicated readers are implemented.
118
+ - Partial reads can unlock `Write` or `Edit` only after their accumulated ranges cover the full current file.
119
+ - Any covered read unlocks `Write` and `Edit` only while the file is unchanged.
120
+ - `Write` creates new files without pre-read and updates existing files only after complete read coverage.
121
+ - `Edit` rejects missing, ambiguous, unchanged, stale, and incomplete-coverage edits.
122
+ - `Write` and `Edit` do not return full file contents in model-facing tool results.
123
+ - `Glob` returns ripgrep-backed file results with pagination metadata.
124
+ - `Grep` returns ripgrep-backed search results for `files`, `content`, and `count`.
125
+ - CLI smoke uses `TodoWrite` and still verifies search, read, edit, bash, persistence, and resume.
126
+ - `pnpm --filter @scorel/core test -- tools`
127
+ - `pnpm --filter @scorel/app-cli test -- coding-agent-alpha`
128
+ - `pnpm typecheck && pnpm test` or equivalent per-package commands pass.
129
+
130
+ ## Affected Paths
131
+
132
+ - `packages/core/src/tools/coding-tools.ts`
133
+ - `packages/core/src/tools/coding-tools.test.ts`
134
+ - `packages/core/src/provider/pi-ai.ts`
135
+ - `apps/cli/src/index.test.ts`
136
+ - `docs/spec/tools.md`
137
+ - `docs/ROADMAP.md`
138
+
139
+ ## Risks
140
+
141
+ - Ripgrep availability can fail outside developer machines. Return a clear tool error instead of falling back to slow ad hoc scanning.
142
+ - Renaming `Todo` to `TodoWrite` changes model-facing tool calls and tests; keep this as S0012 rather than mixing with unrelated features.
143
+ - Coverage-based write unlocks is more complex than Claude Code's partial-view rejection; keep tests focused on stale detection and full-file coverage so long-file pagination does not become unsafe.
@@ -0,0 +1,57 @@
1
+ # S0013: Local Daemon Protocol
2
+
3
+ ## Goal
4
+
5
+ Prepare the protocol and package boundaries needed for M3 local daemon work without starting a real background process yet.
6
+
7
+ This spec turns the existing embedded-only daemon/client path into a transport-ready contract for local standalone daemon work.
8
+
9
+ ## Scope
10
+
11
+ - Align `@scorel/protocol` wire types with M3 local daemon needs.
12
+ - Define the Node-only socket transport surface as a client subpath contract.
13
+ - Keep `@scorel/client` browser-safe at its root export.
14
+ - Add tests that protect `@scorel/client` from importing `@scorel/core`, `@scorel/daemon`, or Node-only socket modules through the root export.
15
+ - Add daemon-side tests for connect, subscribe, resync, and per-session `lastSeq` behavior through the protocol interface.
16
+ - Document any small contract changes in `docs/spec/client.md` or `docs/spec/daemon.md` if the implementation changes public names.
17
+
18
+ ## Not In Scope
19
+
20
+ - A standalone `scorel daemon start` process.
21
+ - Unix socket / named pipe server implementation.
22
+ - `scorel attach` command.
23
+ - Process discovery files, PID files, or daemon state files.
24
+ - Remote WebSocket transport.
25
+ - Token persistence or token refresh commands.
26
+
27
+ ## Acceptance Criteria
28
+
29
+ - `DaemonTransport` remains the only transport interface consumed by `DaemonClient`.
30
+ - Root `@scorel/client` export remains browser-safe and has no Node API imports.
31
+ - A Node socket transport entrypoint is reserved for local daemon work, without leaking into browser-safe imports.
32
+ - `connect`, `subscribe_events`, `resync_events`, `get_status`, and `disconnect` have protocol-level tests covering request/response shape and event delivery expectations.
33
+ - Per-session `lastSeq` behavior is tested at the daemon/client boundary.
34
+ - Existing embedded daemon/client CLI tests still pass.
35
+
36
+ ## Tests
37
+
38
+ - `pnpm --filter @scorel/protocol test`
39
+ - `pnpm --filter @scorel/client test`
40
+ - `pnpm --filter @scorel/daemon test`
41
+ - `pnpm typecheck && pnpm test`
42
+
43
+ ## Affected Paths
44
+
45
+ - `packages/protocol/src/transport.ts`
46
+ - `packages/protocol/src/wire.ts`
47
+ - `packages/client/src/`
48
+ - `packages/daemon/src/`
49
+ - `docs/spec/client.md`
50
+ - `docs/spec/daemon.md`
51
+ - `docs/ROADMAP.md`
52
+
53
+ ## Risks And Boundaries
54
+
55
+ - If the socket contract is overfit to Unix sockets, Windows named pipe support will be harder later. Keep the protocol interface transport-neutral.
56
+ - If Node-only code leaks through `@scorel/client`, WebUI support will be compromised. Protect this with package boundary tests.
57
+ - Do not add remote auth or WebSocket behavior here; M3 is local daemon only.