Skip to content

feat(tool): allow human-readable slugs as task_id#32122

Open
rafaelchavesfreitas wants to merge 5 commits into
anomalyco:devfrom
hacklabr:feature/human-readable-task_id
Open

feat(tool): allow human-readable slugs as task_id#32122
rafaelchavesfreitas wants to merge 5 commits into
anomalyco:devfrom
hacklabr:feature/human-readable-task_id

Conversation

@rafaelchavesfreitas

Copy link
Copy Markdown

Issue for this PR

Closes #32118

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The Task tool's task_id parameter now accepts human-readable slugs (e.g. "explore-auth") in addition to opaque ses_ session IDs.

The problem: Task tool outputs IDs like ses_14209ee2affeovRO3QEIAheNCH. These are designed for DB sort order, not for LLM recall. When an LLM needs to resume a subagent, it must reproduce this string exactly across turns — which it routinely fails at, creating new sessions instead and losing all prior context.

How it works: When task_id doesn't start with ses_, it's treated as a slug. The tool derives a deterministic session ID by combining a 4-char hash of the root session ID with the slug: ses_a3f2_explore-auth. It then looks up that ID — if it exists, the session is resumed; if not, a new one is created with that ID. When task_id starts with ses_, the original lookup-by-ID behavior is unchanged.

The slug is scoped to the root session (the top-level session without a parent). A new Session.root() method walks the parentID chain to find it. This means subagents sharing the same root session can reference each other's named tasks — enabling cross-agent collaboration within a conversation. Subagents in different root sessions are isolated.

Changes:

  • session.ts: Added root() method (traverses parentID chain to root session), added optional id parameter to create() / CreateInput / Interface so a session can be created with a specific ID
  • task.ts: Added isSlug() and deriveSlugSessionID() helpers, modified the session lookup/creation flow to detect slugs, derive IDs, and pass them through on creation
  • task.txt: Updated the task tool description that LLMs read, documenting the slug support

How did you verify your code works?

  • bun typecheck passes in packages/opencode
  • Verified that existing ses_... task_id values follow the same code path (the slug branch only activates when task_id doesn't start with ses_)
  • The Session.root() loop uses the same while + let pattern as the existing findMessage method in the same file

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The task tool now accepts human-readable slugs (e.g. "explore-auth")
as task_id, making it easy for LLMs to create and resume named task
sessions without carrying opaque ses_ IDs across turns.

If the slug hasn't been used in the current root session, a new session
is created with a derived ID (ses_<hash>_<slug>). If it already exists,
the session is resumed with full context.

Closes anomalyco#32118
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 25, 2026
Accept a human-readable slug as the task tool's task_id: it is resolved to a
deterministic session ID derived from the root session, so passing the same
slug resumes the named task and a new slug creates one. Full "ses_..." IDs
still resume directly. Adds Session.create({ id }) and Session.root().

Ported from anomalyco#32122 (adapted for the Effect layer).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 25, 2026
Add an experimental `mcp_lazy` config flag. When enabled, MCP tools are no
longer loaded into the model context automatically; instead a new mcp_search
tool (list/search/describe/call) discovers and invokes MCP tools on demand,
and the prompt loop advertises connected MCP servers in the system prompt.
mcp_search is only registered when the flag is set and MCP is available.

Ported from anomalyco#12520 (adapted for the Effect layer: the server advert is built
inline in the prompt loop rather than via a SystemPrompt service method, and
Config is provided at the SessionTools.resolve call site). The TUI "Lazy"
status badge from the original PR is omitted (its dialog moved packages and
the badge is cosmetic). SDK regeneration also includes the session-create
`id` field from anomalyco#32122.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 25, 2026
Add an experimental subagent-interrupt capability (behind
OPENCODE_EXPERIMENTAL_SUBAGENT_INTERRUPT): an Interrupt service with
pending/terminal state, task_steer/task_cancel/task_abort tools (gated by a
new `interrupt` permission), a POST /session/:id/interrupt endpoint, and a
turn-boundary consume in the prompt loop that injects an escaped steer/cancel
frame plus a visible transcript marker. Cancel records a terminal reason and
force-breaks after a grace window; abort writes a marker, records the
terminal, and cancels the BackgroundJob immediately. The TUI gains an
esc-with-reason flow, footer button, and distinct interrupt markers.

Ported from anomalyco#32425 (adapted for the Effect layer; merged with the prior
task.ts/registry.ts/prompt.ts changes from anomalyco#29447/anomalyco#32122/anomalyco#12520/anomalyco#32192/anomalyco#19961).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 25, 2026
The task tool's task_id description changed in the slug-resume port (anomalyco#32122);
update the JSON Schema wire-shape snapshot to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 25, 2026
Accept a human-readable slug as the task tool's task_id: it is resolved to a
deterministic session ID derived from the root session, so passing the same
slug resumes the named task and a new slug creates one. Full "ses_..." IDs
still resume directly. Adds Session.create({ id }) and Session.root().

Ported from anomalyco#32122 (adapted for the Effect layer).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 25, 2026
Add an experimental `mcp_lazy` config flag. When enabled, MCP tools are no
longer loaded into the model context automatically; instead a new mcp_search
tool (list/search/describe/call) discovers and invokes MCP tools on demand,
and the prompt loop advertises connected MCP servers in the system prompt.
mcp_search is only registered when the flag is set and MCP is available.

Ported from anomalyco#12520 (adapted for the Effect layer: the server advert is built
inline in the prompt loop rather than via a SystemPrompt service method, and
Config is provided at the SessionTools.resolve call site). The TUI "Lazy"
status badge from the original PR is omitted (its dialog moved packages and
the badge is cosmetic). SDK regeneration also includes the session-create
`id` field from anomalyco#32122.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 25, 2026
Add an experimental subagent-interrupt capability (behind
OPENCODE_EXPERIMENTAL_SUBAGENT_INTERRUPT): an Interrupt service with
pending/terminal state, task_steer/task_cancel/task_abort tools (gated by a
new `interrupt` permission), a POST /session/:id/interrupt endpoint, and a
turn-boundary consume in the prompt loop that injects an escaped steer/cancel
frame plus a visible transcript marker. Cancel records a terminal reason and
force-breaks after a grace window; abort writes a marker, records the
terminal, and cancels the BackgroundJob immediately. The TUI gains an
esc-with-reason flow, footer button, and distinct interrupt markers.

Ported from anomalyco#32425 (adapted for the Effect layer; merged with the prior
task.ts/registry.ts/prompt.ts changes from anomalyco#29447/anomalyco#32122/anomalyco#12520/anomalyco#32192/anomalyco#19961).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 25, 2026
The task tool's task_id description changed in the slug-resume port (anomalyco#32122);
update the JSON Schema wire-shape snapshot to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 30, 2026
Accept a human-readable slug as the task tool's task_id: it is resolved to a
deterministic session ID derived from the root session, so passing the same
slug resumes the named task and a new slug creates one. Full "ses_..." IDs
still resume directly. Adds Session.create({ id }) and Session.root().

Ported from anomalyco#32122 (adapted for the Effect layer).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 30, 2026
Add an experimental `mcp_lazy` config flag. When enabled, MCP tools are no
longer loaded into the model context automatically; instead a new mcp_search
tool (list/search/describe/call) discovers and invokes MCP tools on demand,
and the prompt loop advertises connected MCP servers in the system prompt.
mcp_search is only registered when the flag is set and MCP is available.

Ported from anomalyco#12520 (adapted for the Effect layer: the server advert is built
inline in the prompt loop rather than via a SystemPrompt service method, and
Config is provided at the SessionTools.resolve call site). The TUI "Lazy"
status badge from the original PR is omitted (its dialog moved packages and
the badge is cosmetic). SDK regeneration also includes the session-create
`id` field from anomalyco#32122.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 30, 2026
Add an experimental subagent-interrupt capability (behind
OPENCODE_EXPERIMENTAL_SUBAGENT_INTERRUPT): an Interrupt service with
pending/terminal state, task_steer/task_cancel/task_abort tools (gated by a
new `interrupt` permission), a POST /session/:id/interrupt endpoint, and a
turn-boundary consume in the prompt loop that injects an escaped steer/cancel
frame plus a visible transcript marker. Cancel records a terminal reason and
force-breaks after a grace window; abort writes a marker, records the
terminal, and cancels the BackgroundJob immediately. The TUI gains an
esc-with-reason flow, footer button, and distinct interrupt markers.

Ported from anomalyco#32425 (adapted for the Effect layer; merged with the prior
task.ts/registry.ts/prompt.ts changes from anomalyco#29447/anomalyco#32122/anomalyco#12520/anomalyco#32192/anomalyco#19961).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 30, 2026
The task tool's task_id description changed in the slug-resume port (anomalyco#32122);
update the JSON Schema wire-shape snapshot to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Allow human-readable slugs as task_id in the Task tool

1 participant