Skip to content

feat(agent): add run context#2950

Open
get6 wants to merge 2 commits into
multica-ai:mainfrom
get6:hermes/ITT-150-run-context-pr
Open

feat(agent): add run context#2950
get6 wants to merge 2 commits into
multica-ai:mainfrom
get6:hermes/ITT-150-run-context-pr

Conversation

@get6
Copy link
Copy Markdown

@get6 get6 commented May 20, 2026

What does this PR do?

Adds a machine-readable agent run context so Multica agents can read first-class issue/task metadata before parsing prose descriptions or comments. The context is captured at dispatch time, exposed through environment variables, and written to .multica/run/context.json for runtime consumers.

This approach keeps the P0 scope focused on run-time context injection and avoids introducing a broader issue-properties data model change in this PR.

Related Issue

Multica workspace issue: ITT-150

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Refactor / code improvement (no behavior change)
  • Documentation update
  • Tests (adding or improving test coverage)
  • CI / infrastructure

Changes Made

  • server/internal/daemon/execenv/: injects MULTICA_RUN_CONTEXT, MULTICA_ISSUE_*, and MULTICA_TASK_* values into agent runtime environments.
  • server/internal/daemon/: writes .multica/run/context.json and documents that the context is a dispatch-time snapshot.
  • server/internal/runcontext/: adds a shared run context model with task, issue, parent, and properties top-level keys.
  • server/cmd/multica/: adds multica issue context --output json for inspecting the current run context.
  • server/internal/service/ and server/pkg/db/queries/: preserves issue task snapshots in queued task context so the daemon can build run context without schema changes.
  • Tests added/updated across CLI, daemon, execenv, handler, and service paths.

How to Test

  1. Run the focused backend test set:
    cd server
    go test ./cmd/multica ./internal/daemon ./internal/daemon/execenv ./internal/handler ./internal/service
  2. Verify an agent task receives MULTICA_RUN_CONTEXT plus the expected MULTICA_ISSUE_* / MULTICA_TASK_* environment values.
  3. From inside an agent-scoped run, run multica issue context --output json and confirm it returns the run context JSON.

Checklist

  • I have included a thinking path that traces from project context to this change
  • I have run tests locally and they pass
  • I have added or updated tests where applicable
  • If this change affects the UI, I have included before/after screenshots
  • I have updated relevant documentation to reflect my changes
  • If I added a new runtime / coding tool / UI tab, I synced the change to landing copy (apps/web/features/landing/i18n/) and relevant docs (apps/docs/content/docs/)
  • If this PR touches Chinese product copy, I checked it against apps/docs/content/docs/developers/conventions.zh.mdx (terminology, mixed-rule for task / issue / skill)
  • I have considered and documented any risks above
  • I will address all reviewer comments before requesting merge

Notes on non-applicable checklist items: this PR does not change UI, runtime/coding-tool tabs, landing copy, docs content, or Chinese product copy.

Risk: this touches core agent task spawning and context propagation. The implementation intentionally reuses the existing queued task context snapshot instead of adding schema/migration scope, but review should check compatibility with mention tasks, squad leader tasks, quick-create tasks, and future context extensions.

AI Disclosure

AI tool used: Multica Agent / Codex, supervised by Hermes

Prompt / approach:
Implemented from Multica workspace issue ITT-150. Codex produced the initial implementation and tests; Hermes verified the diff, resolved the origin/main conflict around ForceFreshSession, reran the focused backend tests, and opened this PR using the repository PR template.

Screenshots (optional)

N/A — backend/CLI runtime context change only.

Copilot AI review requested due to automatic review settings May 20, 2026 12:50
@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

@get6 is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a machine-readable “agent run context” that is persisted at task enqueue time, returned by the claim endpoint, and injected into the daemon execution environment (env vars + .multica/run/context.json). It also introduces a CLI command to inspect the current run context during agent execution.

Changes:

  • Persist an issue snapshot (issue/parent/properties) into agent_task_queue.context when enqueueing issue/mention tasks, and surface it through the claim response.
  • Add internal/runcontext shared model + parsing/normalization helpers for snapshots and the final run-context file payload.
  • Write .multica/run/context.json and export MULTICA_RUN_CONTEXT + MULTICA_TASK_* / MULTICA_ISSUE_* env vars; add multica issue context --output json and regression tests.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/pkg/db/queries/agent.sql Adds context to the CreateAgentTask insert so snapshots can be stored on enqueue.
server/pkg/db/generated/agent.sql.go Regenerates sqlc code to accept/pass the new context parameter.
server/internal/service/task.go Builds and stores an issue snapshot JSON blob when enqueueing issue/mention tasks.
server/internal/runcontext/runcontext.go New shared run-context model + helpers (identifier formatting, properties normalization, snapshot parsing).
server/internal/handler/daemon.go Parses stored snapshots into claim responses; falls back when missing/orphaned.
server/internal/handler/daemon_test.go Adds coverage ensuring stored snapshots round-trip via the claim endpoint.
server/internal/handler/agent.go Extends AgentTaskResponse to include issue/parent/properties.
server/internal/daemon/types.go Extends daemon task payload shape to carry run-context fields.
server/internal/daemon/execenv/runtime_config.go Documents the new multica issue context command and run-context env/file injection in the meta-skill brief.
server/internal/daemon/execenv/execenv.go Tracks RunContextPath on prepared environments and passes snapshot fields into context-file writing.
server/internal/daemon/execenv/execenv_test.go Adds run-context file assertions and updates workdir entry expectations.
server/internal/daemon/execenv/context.go Writes .multica/run/context.json during context file generation and references it in issue_context.md.
server/internal/daemon/daemon.go Injects run-context env vars and wires run-context fields into the execenv task context.
server/internal/daemon/daemon_test.go Adds unit coverage for env var injection behavior.
server/cmd/multica/help.go Documents MULTICA_RUN_CONTEXT in CLI help text.
server/cmd/multica/cmd_issue_context.go Adds multica issue context --output json to print the current run-context JSON file.
server/cmd/multica/cmd_issue_context_test.go Tests CLI behavior for valid context, missing env, and missing file/orphaned runs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// CR/LF and other whitespace control bytes collapse to a single space; other
// C0 controls and DEL are dropped; markdown structural characters that have
// meaning in inline context (`*`, `_`, `` ` ``, `\`, `[`, `]`, `<`) are
// meaning in inline context (`*`, `_`, ` , `\`, `[`, `]`, `<`) are
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ba45b5b: replaced the smart quotes with a literal backtick in the documented escaping set.

@get6 get6 changed the title feat: ITT-150 add agent run context feat: add agent run context May 20, 2026
@get6 get6 changed the title feat: add agent run context feat(agent): add run context May 20, 2026
@get6 get6 force-pushed the hermes/ITT-150-run-context-pr branch from 0dccf46 to d52acac Compare May 21, 2026 12:16
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.

2 participants