Skip to content
This repository was archived by the owner on Aug 17, 2026. It is now read-only.

feat(grunt/tui): persist peer-id on session row — gruntcode -s alone recovers identity - #13

Merged
terrxo merged 1 commit into
devfrom
grunt-feat/persist-peer-id-on-session-row
May 27, 2026
Merged

terrxo merged 1 commit into
devfrom
grunt-feat/persist-peer-id-on-session-row

Conversation

@terrxo

@terrxo terrxo commented May 27, 2026

Copy link
Copy Markdown

Refs hivemind anomalyco#229 follow-up. Closes the 'I have to remember --peer-id every restart' ergonomics gap.

Behavior

  • First launch: gruntcode --peer-id nik-coord-main --project ~/foo creates session row with peer_id='nik-coord-main'
  • Every restart after: gruntcode -s ses_xyz reads peer_id from the row, sets OPENCODE_PEER_ID env BEFORE worker spawn → MCP child auto-announces correctly

Resolution priority

  1. Explicit --peer-id flag (always wins)
  2. peer_id stored on the session row (when --session <id> is used)
  3. Unset → MCP child falls back to <cwd>#<pid>

Backfill

When both --peer-id AND --session are given, the explicit flag is also UPDATEd onto the row. Pre-existing sessions get caught up on next resume that includes the flag.

Schema

ALTER TABLE session ADD peer_id text (drizzle migration: migration/20260527000333_add_session_peer_id/migration.sql). Info schema gains optional peerID; fromRow/toRow round-trip it; Session.createNext captures getPeerID() into the new row.

Files

File Change
packages/opencode/src/session/session.sql.ts Adds peer_id column
packages/opencode/migration/20260527000333_add_session_peer_id/ New migration
packages/opencode/src/session/session.ts Info schema + fromRow/toRow + createNext capture
packages/opencode/src/cli/cmd/tui/thread.ts DB read for --session resume; backfill on --peer-id + --session

Verified

bun typecheck clean. scripts/install-local.sh builds + signs + installs. Bin reports v1.15.10-grunt.7-6-g1e35d2514-dirty-local.

… alone recovers identity

Refs hivemind anomalyco#229 follow-up — Nik's observation: 'I still had to use
gruntcode -s ses_... but we are here only thing is I guess I'd have to
run the -s and -id right'.

Today --peer-id is a flag you have to remember to type every restart.
Without it the MCP child registers under `<cwd>#<pid>` which churns every
restart and breaks wakeable continuity.

## The fix

Persist peer_id on the session row. So:
- First launch of a tab: `gruntcode --peer-id nik-coord-main --project ~/foo`
  (creates session row with peer_id='nik-coord-main')
- Every subsequent restart: `gruntcode -s ses_xyz` (reads peer_id from row,
  sets env before worker spawn → MCP child auto-announces correctly)

## Resolution priority in thread.ts

1. Explicit --peer-id flag (always wins; lets a user re-launch with a NEW
   identity, also catches up backfilling onto pre-existing session rows)
2. peer_id stored on the session row (when --session <id> is used to resume)
3. unset → MCP child falls back to <cwd>#<pid>

Backfill: when both --peer-id AND --session are given, the explicit flag is
also UPDATEd onto the row so old sessions get caught up on next resume.

## Schema

ALTER TABLE `session` ADD `peer_id` text (drizzle migration generated:
migration/20260527000333_add_session_peer_id/migration.sql).

Info schema gains optional `peerID` field; fromRow/toRow round-trip it;
Session.createNext captures getPeerID() into result.peerID at creation.

## Verified

bun typecheck clean. scripts/install-local.sh builds + signs + installs
without errors. Bin reports v1.15.10-grunt.7-6-g1e35d2514-dirty-local.
@github-actions

Copy link
Copy Markdown

Hey! Your PR title feat(grunt/tui): persist peer-id on session row — gruntcode -s alone recovers identity doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@terrxo
terrxo merged commit 5573d83 into dev May 27, 2026
3 of 10 checks passed
@terrxo
terrxo deleted the grunt-feat/persist-peer-id-on-session-row branch May 27, 2026 00:07
terrxo added a commit that referenced this pull request May 28, 2026
… alone recovers identity (#13)

Refs hivemind anomalyco#229 follow-up — Nik's observation: 'I still had to use
gruntcode -s ses_... but we are here only thing is I guess I'd have to
run the -s and -id right'.

Today --peer-id is a flag you have to remember to type every restart.
Without it the MCP child registers under `<cwd>#<pid>` which churns every
restart and breaks wakeable continuity.

## The fix

Persist peer_id on the session row. So:
- First launch of a tab: `gruntcode --peer-id nik-coord-main --project ~/foo`
  (creates session row with peer_id='nik-coord-main')
- Every subsequent restart: `gruntcode -s ses_xyz` (reads peer_id from row,
  sets env before worker spawn → MCP child auto-announces correctly)

## Resolution priority in thread.ts

1. Explicit --peer-id flag (always wins; lets a user re-launch with a NEW
   identity, also catches up backfilling onto pre-existing session rows)
2. peer_id stored on the session row (when --session <id> is used to resume)
3. unset → MCP child falls back to <cwd>#<pid>

Backfill: when both --peer-id AND --session are given, the explicit flag is
also UPDATEd onto the row so old sessions get caught up on next resume.

## Schema

ALTER TABLE `session` ADD `peer_id` text (drizzle migration generated:
migration/20260527000333_add_session_peer_id/migration.sql).

Info schema gains optional `peerID` field; fromRow/toRow round-trip it;
Session.createNext captures getPeerID() into result.peerID at creation.

## Verified

bun typecheck clean. scripts/install-local.sh builds + signs + installs
without errors. Bin reports v1.15.10-grunt.7-6-g1e35d2514-dirty-local.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant