Skip to content

Commit f80bd56

Browse files
author
Gemini MB
committed
feat: add background consolidation first cut
1 parent b3ef42d commit f80bd56

6 files changed

Lines changed: 632 additions & 9 deletions

File tree

README.md

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Multi-agent coordination toolkit for IDE AIs (Claude Code, Codex, Cursor, VS Cod
2121
- [Room Poller](#room-poller)
2222
- [Env Vars (Generic Poller)](#env-vars-generic-poller)
2323
- [Env Vars (Codex Smart Poller)](#env-vars-codex-smart-poller)
24+
- [Background Consolidation](#background-consolidation)
2425
- [Integrations](#integrations)
2526
- [GitHub Webhooks](#github-webhooks-srcwebhook-servermjs)
2627
- [OpenClaw Bot Fleet](#openclaw-bot-fleet-srcopenclaw-mjs)
@@ -70,6 +71,7 @@ Run allowlisted commands in a named tmux session, capture output + exit code.
7071
10. **Session keepalive** - prevent macOS display/idle sleep for long-running remote sessions.
7172
11. **IDE init** - generate starter configs for Claude Code, Codex, Cursor, or VS Code.
7273
12. **ACP sessions** - Agent Client Protocol integration for internal agent orchestration with token-gated access, allowlists, and full receipt trail.
74+
13. **Background consolidation** - optional `light / REM / deep` pass over recent queue items, with append-only sidecars and no effect on the foreground room loop by default.
7375

7476
No dependencies. Node.js ≥ 18 only.
7577

@@ -167,6 +169,72 @@ The **Codex smart poller** (`tools/antigravity_room_autopost.sh`) is also self-c
167169

168170
The **Codex room-duty wrapper** (`tools/codex_room_autopost.sh`) reuses that same engine but sets Codex-friendly defaults for handle, session name, API-key lookup, and state files. Use it when you want Codex to keep polling assigned rooms without manual prompts.
169171

172+
### Background Consolidation
173+
174+
The first dogfoodable consolidation pass is now available behind a separate CLI entrypoint:
175+
176+
```bash
177+
ide-agent-kit background status --config ide-agent-kit.json
178+
ide-agent-kit background run --config ide-agent-kit.json
179+
```
180+
181+
This is intentionally separate from `rooms watch`.
182+
183+
- Foreground room polling remains reactive.
184+
- Background consolidation is opt-in.
185+
- One run executes the three human-readable phases sequentially:
186+
- `light`
187+
- `REM`
188+
- `deep`
189+
- The background job never auto-posts into rooms in this first cut.
190+
191+
What each phase does in the first implementation:
192+
193+
- `light`: reads the last 2 hours of queue events (hard cap 100), stages them into a short-term working set, and writes a sidecar.
194+
- `REM`: synthesizes recurring themes, open threads, and follow-up candidates from the staged set, then writes a sidecar.
195+
- `deep`: promotes only explicit durable facts and decisions into an append-only local memory ledger, then writes a sidecar.
196+
197+
Execution rules:
198+
199+
- Single background job only; no concurrency.
200+
- Independent phase outcomes; one failure does not abort later phases.
201+
- Skip rules:
202+
- `light`: skip if there are no new queue events since the previous run
203+
- `REM`: skip if `light` staged zero items
204+
- `deep`: skip if `REM` produced no durable facts or decisions
205+
206+
Default timeout set:
207+
208+
- `light = 60s`
209+
- `REM = 120s`
210+
- `deep = 120s`
211+
212+
Sidecar output:
213+
214+
- directory: `~/.iak/consolidation/`
215+
- per-phase file pattern: `<run_id>-<phase>.json`
216+
- durable deep-write ledger: `~/.iak/consolidation/deep-memory.jsonl`
217+
218+
Example config:
219+
220+
```json
221+
{
222+
"background": {
223+
"enabled": false,
224+
"interval_sec": 3600,
225+
"recent_window_sec": 7200,
226+
"max_events": 100,
227+
"sidecar_dir": "~/.iak/consolidation",
228+
"lock_file": "/tmp/iak-background.lock",
229+
"timeouts": {
230+
"light_sec": 60,
231+
"rem_sec": 120,
232+
"deep_sec": 120
233+
}
234+
}
235+
}
236+
```
237+
170238
### Env vars (generic poller)
171239

172240
| Variable | Default | Description |
@@ -206,7 +274,7 @@ The **Codex room-duty wrapper** (`tools/codex_room_autopost.sh`) reuses that sam
206274

207275
### User Intent Kit
208276

209-
The User Intent Kit (UIK) gives agents awareness of the user's current state and availability. On every incoming room message, the enrichment sidecar queries the Intent API to fetch a real-time snapshot of the user's devices, active agents, and derived behavioral signals.
277+
The User Intent Kit (UIK) gives agents awareness of the user's current state and availability. When the optional enrichment sidecar is configured, it queries the Intent API on each incoming room message to fetch a real-time snapshot of the user's devices, active agents, and derived behavioral signals.
210278

211279
The intent payload includes:
212280

@@ -219,7 +287,7 @@ The intent payload includes:
219287

220288
Agents can use these signals to adapt their behavior. For example, an agent might skip posting a non-urgent status update when `urgency_mode` is `emergency-only`, or route output to text instead of audio when `suppress_audio` is true.
221289

222-
The intent data is fetched from the GroupMind/Ant Farm API at `GET /intent/{userId}` and injected into every queue event under the `intent` key with `provider: "antfarm"`.
290+
The intent data is fetched from the GroupMind/Ant Farm API at `GET /intent/{userId}` and injected into queue events under the `intent` key with `provider: "antfarm"`.
223291

224292
### Enrichment Configuration
225293

@@ -239,7 +307,7 @@ To enable sidecar enrichment (Memory and Intent), add the following blocks to yo
239307
}
240308
```
241309

242-
*Note: The Intent API integration is now fully LIVE and actively polls for user-intent-kit data upon every incoming message. Ensure your `"apiKey"` uses an `antfarm_...` prefix. The sidecar securely passes `Authorization: Bearer` and injects `urgency_mode` vectors directly into your queued room events.*
310+
*Note: the enrichment path exists and works when configured, but it is still optional. If the `intent` block is absent, queue events fall back to a placeholder `intent` payload and no live UIK data is fetched.*
243311

244312
When enrichment is enabled, each queued room event can be expanded with:
245313

bin/cli.mjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { parseArgs } from 'node:util';
66
import { readFileSync } from 'node:fs';
77
import { loadConfig } from '../src/config.mjs';
88
import { runSanityCheck } from '../src/common/check.mjs';
9+
import { runBackground, backgroundStatus } from '../src/background.mjs';
910

1011
// --- team-relay (generic room/comms) ---
1112
import { tailReceipts } from '../src/team-relay/receipt.mjs';
@@ -72,6 +73,11 @@ Usage:
7273
Long-running room poller. Writes new messages to a notification file and
7374
optional tmux nudge. Uses rooms/apiKey/handle from config.poller section.
7475
76+
ide-agent-kit background <run|status> [--config <path>]
77+
Run or inspect the background consolidation job.
78+
run: executes light -> REM -> deep sequentially and writes sidecars
79+
status: shows whether background mode is enabled and the latest sidecar path
80+
7581
ide-agent-kit poll --rooms <room1,room2> --api-key <key> --handle <@handle> [--interval <sec>] [--config <path>]
7682
(Legacy) Poll Ant Farm rooms with explicit CLI args. Prefer "rooms watch".
7783
@@ -290,6 +296,30 @@ async function main() {
290296
return;
291297
}
292298

299+
// ── Background Consolidation ───────────────────────────
300+
if (command === 'background') {
301+
const opts = parseKV(args, subcommand || 'background');
302+
const config = loadConfig(opts.config);
303+
304+
if (subcommand === 'status') {
305+
console.log(JSON.stringify(backgroundStatus(config), null, 2));
306+
return;
307+
}
308+
309+
if (subcommand === 'run') {
310+
const result = runBackground(config);
311+
if (!result.ok) {
312+
console.error(result.error);
313+
process.exit(1);
314+
}
315+
console.log(JSON.stringify(result, null, 2));
316+
return;
317+
}
318+
319+
console.error('Usage: ide-agent-kit background <run|status> [--config <path>]');
320+
process.exit(1);
321+
}
322+
293323
// ── Rooms ──────────────────────────────────────────────
294324
if (command === 'rooms') {
295325
const opts = parseKV(args, subcommand || 'rooms');

0 commit comments

Comments
 (0)