Skip to content

Commit 9c9f220

Browse files
refactor: compact generated agents context (#944)
Co-authored-by: homeboy-ci[bot] <266378653+homeboy-ci[bot]@users.noreply.github.com>
1 parent 397798c commit 9c9f220

4 files changed

Lines changed: 71 additions & 306 deletions

File tree

inc/Runtime/AgentsMdSections.php

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -93,36 +93,15 @@ private static function register_datamachine_section( string $wp ): void {
9393
$workspace_policy_intro = self::render_workspace_policy_intro($workspace_path);
9494
$workspace_policy_section = self::render_workspace_policy_section($workspace_path, $wp);
9595

96-
// Generate DMC's own command surface from reflection so the lists
97-
// never drift from the registered truth (see #671, #734). The
98-
// fallback pipe-lists are only used if a command class is somehow
99-
// unavailable in this compose context. Core's `datamachine`
100-
// namespace is NOT narrated here — core registers its own
101-
// reflected AGENTS.md section (data-machine#2640); hand-copying it
102-
// here is a layer inversion that silently drifts (e.g. the removed
103-
// `datamachine analytics` line, now owned by data-machine-business).
104-
$workspace_subcmds = CommandIntrospector::pipe_list(
105-
'\\DataMachineCode\\Cli\\Commands\\WorkspaceCommand',
106-
'adopt|clone|list|show|path|hygiene|remove|worktree|read|write|grep|edit|git|patch|ls'
107-
);
108-
$worktree_subcmds = CommandIntrospector::match_arm_pipe_list(
109-
'\\DataMachineCode\\Cli\\Commands\\WorkspaceCommand',
110-
'worktree',
111-
'add|list|remove|prune|cleanup|cleanup-artifacts|reconcile-metadata|refresh-context|finalize|mark-cleanup-eligible'
112-
);
113-
$github_subcmds = CommandIntrospector::pipe_list(
114-
'\\DataMachineCode\\Cli\\Commands\\GitHubCommand',
115-
'issues|pulls|repos|status|view|close|review-flow|comment'
116-
);
11796
return <<<MD
11897
## Data Machine Code
11998
12099
{$workspace_policy_intro}DMC owns workspace lifecycle, evidence capture, and GitHub workflow glue; file CRUD inside a worktree uses whatever tool is fastest. Core's `datamachine` operating layer (memory, automation, communication, content ops, system) is documented in its own AGENTS.md section — run `{$wp} datamachine --help` to discover it.
121100
122101
- Workspace root: `{$workspace_path}`
123-
- **Workspace:** `{$wp} datamachine-code workspace {$workspace_subcmds}` — lifecycle (clone/adopt/list/show/path/hygiene/remove/worktree), plus the file-I/O surface you work through inside a worktree (`read`, `write`, `grep`, `edit`, `patch`, `ls`, `git`). Keeps the on-disk registry consistent and enforces the `<repo>@<slug>` handle convention.
124-
- **Worktrees:** `{$wp} datamachine-code workspace worktree {$worktree_subcmds}` — create isolated branches, refresh agent context, attach lifecycle metadata, and clean up safely.
125-
- **GitHub:** `{$wp} datamachine-code github {$github_subcmds}` — list/read GitHub state, manage issues and PRs, install review flows, and comment on reviews.
102+
- **Workspace:** `{$wp} datamachine-code workspace --help` is the live lifecycle and file-I/O command reference. It enforces `<repo>@<slug>` handles and maintains workspace registry state.
103+
- **Worktrees:** `{$wp} datamachine-code workspace worktree --help` is the live branch lifecycle reference.
104+
- **GitHub:** `{$wp} datamachine-code github --help` is the live GitHub command reference.
126105
- **Editing inside a worktree:** any tool. Local agents on the same disk should use native file I/O and raw `git`; routing edits through workspace abilities is ceremony, not safety.
127106
- **Workspace lifecycle:** use `workspace clone` for primary checkout adoption/cloning and `workspace worktree add` for isolated branches. Use the CLI `--help` output for current flags and subcommands.
128107
{$workspace_policy_section}
@@ -365,17 +344,20 @@ private static function render_workspace_inventory_section( string $wp ): string
365344

366345
ksort($by_repo, SORT_NATURAL | SORT_FLAG_CASE);
367346

368-
$mode = apply_filters('datamachine_code_workspace_inventory_mode', 'compact');
369-
if ( ! in_array($mode, array( 'compact', 'full' ), true) ) {
370-
$mode = 'compact';
347+
// Full snapshots remain available to sites that explicitly need them.
348+
$mode = apply_filters('datamachine_code_workspace_inventory_mode', 'summary');
349+
if ( ! in_array($mode, array( 'summary', 'full' ), true) ) {
350+
$mode = 'summary';
371351
}
372352

373353
$lines = array();
374354
$attention_lines = array();
355+
$worktree_count = 0;
375356
foreach ( $by_repo as $repo => $bucket ) {
376357
$primary = is_array($bucket['primary']) ? $bucket['primary'] : array();
377358
$worktrees = $bucket['worktrees'];
378359
$wt_count = count($worktrees);
360+
$worktree_count += $wt_count;
379361
$branch = $primary['branch'] ?? null;
380362
$remote = $primary['remote'] ?? null;
381363
$branch_str = ( null !== $branch && '' !== $branch ) ? sprintf(' (`%s`)', $branch) : '';
@@ -386,17 +368,7 @@ private static function render_workspace_inventory_section( string $wp ): string
386368
$attention_lines[] = $attention;
387369
}
388370

389-
if ( 'compact' === $mode ) {
390-
$suffix_parts = array();
391-
$suffix_parts[] = sprintf('%d %s', $wt_count, 1 === $wt_count ? 'worktree' : 'worktrees');
392-
if ( null !== $remote && '' !== $remote ) {
393-
$suffix_parts[] = $remote;
394-
}
395-
$freshness_badge = self::format_primary_freshness_badge($freshness);
396-
if ( '' !== $freshness_badge ) {
397-
$suffix_parts[] = $freshness_badge;
398-
}
399-
$lines[] = sprintf('- **%s**%s — %s', $repo, $branch_str, implode(' · ', $suffix_parts));
371+
if ( 'summary' === $mode ) {
400372
continue;
401373
}
402374

@@ -427,25 +399,56 @@ private static function render_workspace_inventory_section( string $wp ): string
427399
}
428400

429401
$body = implode("\n", $lines);
430-
$attention_block = self::render_primary_freshness_attention_block($attention_lines);
431-
$generated_at = gmdate('c');
402+
$attention_block = 'full' === $mode
403+
? self::render_primary_freshness_attention_block($attention_lines)
404+
: self::render_primary_freshness_summary($attention_lines, $wp);
432405
$workspace_path = $listing['path'];
433406
$agent_slug = self::resolve_agent_slug();
434407
$agent_suffix = '' !== $agent_slug ? ' --agent=' . $agent_slug : '';
435408

409+
if ( 'summary' === $mode ) {
410+
$primary_count = count($by_repo);
411+
$primary_label = 1 === $primary_count ? 'checkout' : 'checkouts';
412+
$worktree_label = 1 === $worktree_count ? 'worktree' : 'worktrees';
413+
return <<<MD
414+
## Workspace Inventory
415+
416+
Live workspace state is intentionally not embedded here. Run `{$wp} datamachine-code workspace list` for the authoritative inventory, `{$wp} datamachine-code workspace show <repo>` for one checkout, or `{$wp} datamachine-code workspace hygiene` for freshness and cleanup diagnostics.
417+
418+
Snapshot summary: {$primary_count} primary {$primary_label} and {$worktree_count} {$worktree_label} under `{$workspace_path}`.
419+
420+
{$attention_block}
421+
MD;
422+
}
423+
436424
return <<<MD
437425
## Workspace Inventory
438426
439-
Generated {$generated_at} from cloned repos in `{$workspace_path}`. This section can be stale; `{$wp} datamachine-code workspace list` is the source of truth for current worktrees and branches.
427+
Detailed snapshot from cloned repos in `{$workspace_path}`. `{$wp} datamachine-code workspace list` remains the source of truth for current worktrees and branches.
440428
441-
Refresh this file with `{$wp} datamachine memory compose AGENTS.md{$agent_suffix}` after workspace changes if the inventory looks stale.
429+
Refresh this file with `{$wp} datamachine memory compose AGENTS.md{$agent_suffix}` after workspace changes.
442430
443431
{$attention_block}
444432
445433
{$body}
446434
MD;
447435
}
448436

437+
private static function render_primary_freshness_summary( array $attention_lines, string $wp ): string {
438+
$count = count($attention_lines);
439+
if ( 0 === $count ) {
440+
return '';
441+
}
442+
443+
return sprintf(
444+
'Primary checkout attention: %d %s need%s inspection. Run `%s datamachine-code workspace list` for details.',
445+
$count,
446+
1 === $count ? 'checkout' : 'checkouts',
447+
1 === $count ? 's' : '',
448+
$wp
449+
);
450+
}
451+
449452
private static function primary_freshness_needs_attention( ?array $freshness ): bool {
450453
if ( null === $freshness ) {
451454
return false;

inc/Runtime/CommandIntrospector.php

Lines changed: 0 additions & 250 deletions
This file was deleted.

0 commit comments

Comments
 (0)