Skip to content

Commit dd18fe6

Browse files
authored
Merge pull request #16 from OnPoint-Dev-Tools/pr/brain-update
feat: enhance context usage handling and ALOT of Updates
2 parents 2e46f57 + 970599c commit dd18fe6

69 files changed

Lines changed: 2233 additions & 564 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎build/icon.ico‎

25.7 KB
Binary file not shown.

‎build/icon.png‎

94.2 KB
Loading

‎build/icons/256x256.png‎

440 Bytes
Loading

‎build/icons/512x512.png‎

-4.55 KB
Loading

‎docs/agent-activity-overlay.md‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,35 @@ This projection changes only CrewCode visualization. Tool availability and Claud
5454

5555
Human-input request cards are independent of this preference. Approvals, questions, editor requests, and notifications must always render because the provider may be paused waiting for the response. Request rendering therefore takes precedence over both the Todo preference and a previously dismissed todo card.
5656

57-
CrewCoder-mode `crewcoder_clarify` / `crewcoder_propose_plan` is a session workflow gate, not a tool-permission pause. After those tools settle, the overlay shows a dedicated clarification or **Approve plan** card. Approve sends `/approve-plan` as a normal prompt (or follow-up if the turn is still running). It must never reuse Allow/Deny on a permission card — `/approve` is still only for pending tool-call grants. A later user message hides the card: `/approve-plan` or a short CrewCoder approval continues implementation, and a revision such as `yes, but also add logging` waits for the next `crewcoder_propose_plan`. Answering a clarification is not plan approval. The Todo preference must not hide this card.
57+
CrewCoder-mode `crewcoder_clarify` / `crewcoder_propose_plan` is a session workflow gate, not a tool-permission pause. After those tools settle, the overlay shows a dedicated clarification or **Approve plan** card. Approve sends `/approve-plan` as a normal prompt (or follow-up if the turn is still running). It must never reuse Allow/Deny on a permission card — `/approve` is still only for pending tool-call grants. A later user message hides the card: `/approve-plan` or a short CrewCoder approval continues implementation, and a revision such as `yes, but also add logging` waits for the next `crewcoder_propose_plan`. Answering a clarification is not plan approval. The Todo preference must not hide this card. The clarification card has its own reply box and **send reply** button; the reply is sent as an ordinary prompt (follow-up while running) through the same surface's send path as Approve. Surfaces that cannot send a prompt fall back to "Reply in the composer".
58+
59+
## Provider question cards
60+
61+
Structured provider questions pause the turn and render in the shared `AgentRequestCard` (inline chat overlay, Crew lanes/timeline, supervisor, Mission Control, menulet). The card layout follows the question shape:
62+
63+
| Shape | Card |
64+
| --- | --- |
65+
| options only (`kind: 'select'`) | one button per option; a click answers immediately. 2–4 short description-free options (Yes/No) sit on one row |
66+
| options + free text (`kind: 'prompt'` with options) | option buttons plus an "or type your own answer…" input and **send reply** |
67+
| free text only (`prompt` / `editor`) | input (Enter) or textarea (Ctrl/Cmd+Enter) plus **send reply** |
68+
| multi-select (`multiple: true`) | toggle buttons answered with `optionIds` in option order, plus optional typed text |
69+
| secret (`secret: true`) | masked input |
70+
71+
**send reply** stays disabled until there is a non-empty answer. After a click the card locks (`sending…`) and unlocks only on an observed transport failure; success is confirmed by `user_request_resolved`. Cancel is an explicit cancel, never an empty answer.
72+
73+
Provider mapping — only structured, provider-issued questions reach this card:
74+
75+
| Provider | Native question | Free text |
76+
| --- | --- | --- |
77+
| Claude | `AskUserQuestion` via `canUseTool`, one card per question | always, matching Claude's built-in "Other"; `custom: false` / `allowFreeform: false` opts out |
78+
| Codex | app-server `item/tool/requestUserInput` (legacy `tool/requestUserInput` alias), one card per question | when the question sets `isOther` or has no options |
79+
| OpenCode | `question` SSE request | unless `custom: false` |
80+
| Pi | extension UI `select` / `input` / `editor` | per method |
81+
| CrewCoder | `crewcoder_clarify` workflow card (above) | reply box |
82+
83+
Codex answers are returned as `{ answers: { [questionId]: { answers: string[] } } }`. A cancelled, empty, or out-of-contract answer (typed text where Codex offered no "Other") fails the whole request with an explicit JSON-RPC error; Codex never receives a fabricated or empty answer. When Codex settles a request itself (`serverRequest/resolved`, e.g. non-blocking questions) or the app-server exits, the bridge aborts the pending `RequestUserFn` signal: the promise settles as `cancel` and the card is retracted with `user_request_resolved`.
84+
85+
Plain-text questions at the end of an agent reply ("Should I continue?") are not requests: the turn has already ended and nothing is paused, so they are answered in the composer. CrewCode must not guess questions from assistant prose or fabricate a request card for them. Codex MCP `mcpServer/elicitation/request` forms are not yet mapped.
5886

5987
## Surfaces
6088

‎docs/context-usage-meter.md‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Context usage meter
2+
3+
The chat meter divides the latest observed context occupancy by the active
4+
context window. The numerator is the provider's current prompt/context size,
5+
not cumulative billing tokens for the entire conversation.
6+
7+
Clicking the context pill opens a compact usage summary. When the provider
8+
supplies token details, **Token logs** opens a scrollable right sidebar. The
9+
sidebar can be closed with its close button, the backdrop, or Escape. Claude
10+
provides context categories; Codex, OpenCode, and Grok provide request or turn
11+
token counters, while CrewCoder provides session counters and its latest context
12+
input reading. These rows can overlap and must not be added together.
13+
If a provider reports token counts before a context window is known, the usage
14+
strip shows a direct **Token logs** button and the sidebar marks context usage
15+
as unavailable instead of showing a fabricated percentage.
16+
17+
Codex token logs show the latest app-server request's input and output, plus
18+
cached input and reasoning output when reported. OpenCode logs show its latest
19+
assistant message's input, output, reasoning, cache read, and cache write
20+
counts. Grok logs show latest-call input/output and, when present, cache read,
21+
reasoning, and cumulative turn input/output. These providers do not expose
22+
Claude-style system/tool/message context categories through these usage events;
23+
the sidebar labels their rows as provider token counts rather than claiming
24+
they sum to context occupancy.
25+
26+
CrewCoder token logs use the ACP `session/prompt` result's namespaced
27+
`crewcoder/usage` summary, falling back to its top-level `usage` mirror. They
28+
show the latest context input (`lastInputTokens`) separately from cumulative
29+
session input, output, total, cached input, cache write, and reasoning counts
30+
when those fields are reported. The session counters can span multiple models
31+
and requests and do not sum to the current context reading. If CrewCoder omits
32+
`lastInputTokens`, cumulative session totals remain visible in Token logs but
33+
do not become a context occupancy estimate.
34+
35+
## Window sources
36+
37+
Use these sources in order:
38+
39+
1. A full window reported for the active session or turn by the provider bridge.
40+
2. A full window from the provider's model catalog, when it supplies one.
41+
3. A static model-family fallback, when no provider value is available.
42+
43+
Codex app-server usage notifications include `modelContextWindow`. For known
44+
models, this can be smaller than the model's full window because it is the
45+
effective request prompt budget. CrewCode shows the known full model capacity
46+
as the meter denominator and labels the reported smaller value separately as
47+
**Codex prompt budget**. For unknown models, the reported value remains the
48+
only available window and drives the meter. A reported value larger than model
49+
metadata also takes precedence. The full model window can come from provider
50+
catalog metadata or CrewCode's static model fallback; the latter can be stale
51+
if a custom Codex configuration changes capacity. Compaction-drop inference
52+
uses Codex's reported prompt budget as its threshold denominator even when the
53+
displayed model window is larger.
54+
The latest request's input tokens are also treated as an authoritative context
55+
reading, so a decrease after native compaction is not replaced by an old floor.
56+
The app-server `model/list` response discovers models but does not document a
57+
context-window field, so model discovery alone cannot supply the Codex meter.
58+
59+
Claude's SDK `getContextUsage()` supplies the active `maxTokens` (or
60+
`rawMaxTokens`) window. The meter sums its active categories and excludes
61+
deferred categories, unused space, and compaction headroom using each SDK row's
62+
`kind`, with legacy category handling for older Claude binaries. CrewCode
63+
requests `detail: 'full'`, since `summary` uses local estimates rather than
64+
the token-counted `/context` breakdown. The categorized SDK reading is the
65+
source of occupancy; result-message billing usage is separate and aggregates
66+
multiple requests. The static model table can
67+
still supply a window but cannot supply occupancy. Claude's `--help` does not
68+
provide a model-window catalog.
69+
70+
CrewCode asks `getContextUsage()` after each assembled assistant message while
71+
the SDK query is active. It retries at the result only if no valid reading has
72+
arrived, because a result-time call can race query shutdown and a full reading
73+
can involve token-counting API requests. If no control reading succeeds for that turn, the latest
74+
individual assistant message's input and cache token counts provide a bounded
75+
request-context fallback. Only when neither current-turn source exists does
76+
CrewCode reuse an earlier measured reading; with no reading at all, the meter
77+
stays unknown. Result-message usage remains billing-only because it aggregates
78+
multiple requests in one turn.
79+
80+
CrewCoder ACP usage can also include a live `contextWindow` and
81+
`lastInputTokens`; its bridge passes those through to the meter. Providers
82+
that report no usable window can show no percentage if no catalog or static
83+
fallback exists. A fallback percentage is an estimate, not a provider reading.
84+
85+
The latest usage snapshot is persisted for resumed chats. A new provider
86+
report replaces its window; occupancy normalization and compaction handling
87+
are described in [Conversation storage](conversation-storage.md).
88+
89+
## Automatic compaction
90+
91+
Claude's `compact_boundary`, Codex app-server's `contextCompaction` completion,
92+
CrewCoder's `_crewcoder/compaction_update`, and OpenCode's matching
93+
`session.compacted` SSE event are native completion signals. They clear the
94+
previous context reading in the main process, its persisted snapshot, and the
95+
latest visible usage strip. The meter remains unknown until a new provider
96+
usage reading arrives; a pre-compaction reading must not be replayed at turn
97+
end. Historical provider token counters remain in Token logs, while old
98+
Claude context categories are cleared. OpenCode's event is accepted only for
99+
the active session.
100+
101+
When no native boundary is observed, a high-occupancy to large-drop usage
102+
reading can detect compaction for Codex, CrewCoder, OpenCode, and Grok. The
103+
smaller observed reading becomes the new context baseline. Providers without
104+
an observed boundary or trustworthy absolute context reading are not inferred
105+
from silence or a completed turn.

‎docs/conversation-storage.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ and appends a visible compact-summary card, but keeps the full rich display
8585
transcript, provider session id, and live bridge. If CrewCoder reports a skipped
8686
small-session compact, CrewCode leaves replay and usage state unchanged.
8787

88+
Provider-native automatic compaction is also observable. Direct Codex maps its
89+
app-server `contextCompaction` item lifecycle (plus the legacy
90+
`thread/compacted` completion) to the same meter. CrewCoder forwards nested
91+
Codex and Claude native boundaries through `_crewcoder/compaction_update`.
92+
Claude maps `compact_boundary`, and OpenCode maps the selected session's
93+
`session.compacted` SSE event. A native completion clears the previous live
94+
occupancy, its persisted snapshot, and the latest visible usage strip until
95+
new usage arrives. Native boundaries win; live-occupancy drop inference is only
96+
a fallback for Codex, CrewCoder, OpenCode, or Grok turns where no native
97+
boundary was observed, so a single compaction never creates duplicate cards.
98+
8899
### `summary-reset` flow (pi / hermes / older CrewCoder)
89100

90101
Native-session providers keep their context server-side and expose no compaction RPC, so we cannot shrink it directly. Instead:

‎docs/crewcoder-provider.md‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,16 @@ bridge, or seed a replacement session after a successful native compact.
110110

111111
CrewCoder's compaction update is an additive namespaced ACP extension carrying
112112
started/completed/failed status, automatic intent, progress, and a human-readable
113-
message. The bridge treats it as authoritative and does not also infer
114-
compaction from the later context-token drop. Automatic updates omit the summary
115-
body; the compacted summary remains only in CrewCoder's durable session.
113+
message. It covers both CrewCoder's durable-session compaction and compaction
114+
reported by a nested native provider. Codex app-server `contextCompaction` item
115+
lifecycle and `thread/compacted` notifications therefore drive the existing
116+
CrewCode loading bar through CrewCoder; Claude `compact_boundary` drives the
117+
completed state. The bridge treats a native update as authoritative and does not
118+
also infer compaction from the later context-token drop. If a CrewCoder provider
119+
does not expose a native boundary, a verified high-water-to-large-drop occupancy
120+
change produces one after-the-fact detected notification instead of staying
121+
silent. Automatic updates omit the summary body; the compacted summary remains
122+
only in CrewCoder's durable session.
116123
Host-requested `session/compact` returns the authoritative summary and includes
117124
it on the completed update. CrewCode replaces only its provider replay shard
118125
with that summary and appends the visible compact-summary card; it deliberately
@@ -141,6 +148,17 @@ bridge registration; the next composer submission uses normal missing-bridge rec
141148
attempting to write to closed stdin and surfacing `crewcoder acp: process not writable`. When automatic compaction is off, the user explicitly
142149
runs `/compact` before continuing; this policy does not affect Pi or other providers.
143150

151+
For CrewCoder's built-in Codex provider, the nested app-server receives the
152+
same resolved context policy as the outer loop. Sol, Terra, and Luna GPT-5.6
153+
sessions therefore use a 1.05M context and a 630k normal auto-compaction limit,
154+
instead of app-server independently compacting near its smaller default. These
155+
overrides are process-scoped and do not modify the user's Codex configuration.
156+
Every CrewCoder built-in model declares a context window. Claude SDK-native
157+
auto-compaction is disabled so CrewCoder remains the only owner of its durable
158+
compaction boundary. ACP providers such as Grok can report the active window at
159+
runtime; that value supersedes static metadata and recalculates CrewCoder's
160+
percentage threshold for subsequent checks.
161+
144162
A prompt has a ten-minute **inactivity** watchdog rather than a wall-clock turn
145163
limit. Every matching ACP update or agent request resets it, and time awaiting a
146164
Build permission decision is excluded. If CrewCoder becomes genuinely silent,
@@ -149,9 +167,20 @@ settle before emitting the timeout and `turn_end`. If cancellation itself remain
149167
unresponsive, CrewCode terminates that bridge so its replacement starts cleanly;
150168
a second prompt can never overlap the abandoned CrewCoder turn.
151169

152-
Usage prefers `_meta["crewcoder/usage"]`: `lastInputTokens` is the live
153-
`contextTokens` value and `contextWindow` is the context limit. Top-level usage
154-
is only the compatibility fallback.
170+
Usage prefers `_meta["crewcoder/usage"]`: `lastInputTokens` is an authoritative
171+
live `contextTokens` measurement and `contextWindow` is the registered full model
172+
limit (1.05M for the Codex 5.6 family), not Codex app-server's smaller effective
173+
per-request prompt budget. CrewCode accepts measured drops after provider-native
174+
compaction instead of applying its generic monotonic resume floor. The top-level
175+
mirror is the compatibility fallback and preserves the same live fields. Usage is scoped to
176+
one ACP prompt; an errored or metadata-free prompt never inherits the preceding
177+
turn's snapshot.
178+
The chat's Token logs sidebar shows `lastInputTokens` as the latest context
179+
input and labels input, output, total, cache, and reasoning counters from the
180+
same ACP summary as cumulative session counts. These counters can overlap and
181+
must not be added together as context occupancy. If `lastInputTokens` is absent,
182+
the cumulative counters remain available in Token logs without a context
183+
percentage.
155184

156185
ACP `tool_call` updates carry a category `kind` (`read`, `edit`, `think`, …), a
157186
human `title`, and authoritative CrewCoder tool identity in

‎docs/desktop-web-continuity.md‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ a rejected Promise where they require a disposer function.
6969
## Source of truth
7070

7171
On first enable, missing Brain runtime data is seeded from Electron `userData` into
72-
`~/.crewcode/brain/runtime`. Existing Brain files always win for workspaces, keys, and
73-
replay; they are never overwritten. Transcript shards are merged instead: a newer
72+
`~/.crewcode/brain/runtime`. Existing Brain files win for keys and replay; they are
73+
never overwritten. Transcript shards are merged instead: a newer
7474
desktop copy is folded into the Brain shard by message identity so work done locally
7575
before attachment is not stuck on the first seed snapshot. The seed includes
7676
registered workspaces, provider-native resume IDs, provider keys, rich transcripts,
@@ -79,6 +79,15 @@ gets a non-destructive `web:<session>` alias so the first Brain-backed prompt ca
7979
continue the desktop conversation. Provider-native resume IDs remain keyed by both
8080
session and provider.
8181

82+
Every explicit enable also reconciles the current desktop workspace registry into the
83+
Brain before attachment: current desktop entries and ordering win for matching ids or
84+
paths, while genuine browser-created workspaces are retained. Immediately after the
85+
Brain attaches, but before Electron reloads, the foreground renderer sends its exact
86+
current chat/session and workspace-tab catalogue through the owner-loopback desktop
87+
control. This enable-time handoff supersedes an older persisted authority marker, so a
88+
previous Brain run cannot replace the chats, tabs, workspace, and active selections the
89+
owner was using when they selected **Enable**.
90+
8291
After attachment, the Brain store is authoritative for:
8392

8493
- registered, Brain-authorized workspaces;

‎docs/execution-modes.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
CrewCode's composer mode (`ModeLevel`) is a per-session gate with two halves:
44

55
1. **An optional prompt preamble** injected once at session start
6-
(`buildModePreamble` in `src/renderer/src/hooks/chat-session-send.ts`).
6+
(`buildModePreamble` in `src/renderer/src/hooks/chat-session-send.ts`), and
7+
once more on each mid-session mode switch (`buildModeSwitchPreamble`).
78
2. **A real permission policy** applied per provider inside each bridge.
89

910
The preamble is advisory; the bridge policy is the enforcement. Users edit mode
@@ -52,7 +53,14 @@ to true for new and legacy sessions, and is copied when a session is duplicated.
5253
before the first send. The toggle locks after visible history or the delivery
5354
marker proves startup context was committed; provider context cannot be revoked.
5455
- Prompt edits apply only when a session has not sent its startup context.
55-
Existing/restored sessions must not receive the prompt again.
56+
Existing/restored sessions must not receive the startup prompt again.
57+
- Switching mode mid-session sends the new mode's prompt exactly once, on the
58+
next send, behind a short `<system>` notice that the previous mode's
59+
instructions no longer apply. Without it the earlier preamble stays in the
60+
provider transcript as the only mode contract, so an Ask to Build switch
61+
could leave the agent refusing to implement. It never repeats on later turns
62+
in the same mode, and a restored session whose delivery marker is missing is
63+
seeded silently rather than treated as a switch.
5664
- Disabled mode prompts leave provider-native/default system context in place.
5765
Skills, attachments, handoff packets, and delegation context still use their
5866
normal send paths.

0 commit comments

Comments
 (0)