Skip to content

refactor(persona): consolidate trajectories + ai-memory under memory (opt-in)#210

Merged
khaliqgant merged 3 commits into
mainfrom
feat/memory-opt-in-facets
Jun 6, 2026
Merged

refactor(persona): consolidate trajectories + ai-memory under memory (opt-in)#210
khaliqgant merged 3 commits into
mainfrom
feat/memory-opt-in-facets

Conversation

@khaliqgant

Copy link
Copy Markdown
Member

What

Per Khaliq: fold trajectory recording and ai-memory recall into the existing memory object as opt-in facets, replacing the top-level recordTrajectories boolean (which was default-on + enforced).

New shape

memory?: boolean | {
  enabled?: boolean;          // long-form memory adapter (unchanged)
  scopes?: ('workspace'|'user'|'global')[];
  ttlDays?: number; autoPromote?: boolean; dedupMs?: number;
  trajectories?: boolean | { enabled?: boolean; autoCompact?: boolean };  // record the WHY
  aiMemory?:     boolean | { enabled?: boolean; dbPath?: string };        // load ai-hist MCP (WHY+HOW recall)
}
Declaration long-form trajectory recording ai-hist MCP
omitted off off off
true on off off
{ trajectories: true } off on off
{ aiMemory: true } off off on
  • memory.trajectories → runtime records decision trajectories to <root>/<personaId>/compacted/*.json.
  • memory.aiMemory → persona loads the ai-hist MCP (npx -y -p ai-hist ai-hist-mcp) to recall the why+how. Optional dbPath overrides the history DB.

Changes

  • persona-kit: PersonaMemoryConfig gains trajectories/aiMemory; new PersonaTrajectoryConfig + PersonaAiMemoryConfig; parseMemory parses both; new exported resolveTrajectoryRecording / resolveAiMemory helpers; PersonaSpec drops recordTrajectories; PersonaSelection carries memory; schema regenerated. (Injection logic in interactive-spec unchanged — still gated on input.aiHist.)
  • cli + plan: gate ai-hist injection on resolveAiMemory(memory).enabled; honor dbPath.
  • workload-router: carry memory onto the selection.
  • runtime: ctx gates the recorder on resolveTrajectoryRecording(memory); cloud-defaults gates the MCP on resolveAiMemory(memory). Recorder's internal option name kept.
  • deploy: drop the recordTrajectories preflight enforcement (opt-in ⇒ nothing to enforce).

This reverses the earlier enforced-default-on decision per the new opt-in requirement.

Tests / build

  • persona-kit 268, deploy 177; cli + workload-router build clean.
  • ⚠️ Runtime: my local agent-trajectories install is version-shimmed (.ignored_ quirk), so I couldn't fully build runtime here — the only tsc error was a pre-existing workflowId line in untouched code from the shimmed 0.5.6 version; my ctx/cloud-defaults edits produced zero type errors. @claude-1 to confirm the runtime build (82/82) in their env before merge — it's a coupled type change (removing recordTrajectories from PersonaSpec).

🤖 Generated with Claude Code

… opt-in

Replace the top-level `recordTrajectories` boolean (default-on, enforced) with
two opt-in facets on the existing `memory` object. Both default OFF.

  memory: {
    enabled?, scopes?, ttlDays?, autoPromote?, dedupMs?,   // long-form (unchanged)
    trajectories?: boolean | { enabled?, autoCompact? },    // record the WHY
    aiMemory?:     boolean | { enabled?, dbPath? }          // load ai-hist MCP (WHY+HOW recall)
  }

Semantics:
- `memory` omitted → everything off. `memory: true` → long-form only (facets stay off).
- `memory.trajectories` gates runtime decision-trajectory recording.
- `memory.aiMemory` gates injecting the ai-hist MCP (npx -y -p ai-hist ai-hist-mcp).

Changes:
- persona-kit: PersonaMemoryConfig + PersonaTrajectoryConfig + PersonaAiMemoryConfig;
  parseMemory parses both facets; new resolveTrajectoryRecording / resolveAiMemory
  helpers; PersonaSpec drops recordTrajectories; PersonaSelection carries `memory`;
  regenerated schema. interactive-spec injection unchanged (still gated on input.aiHist).
- cli + plan: gate ai-hist injection on resolveAiMemory(memory).enabled; dbPath override.
- workload-router: carry `memory` onto the selection.
- runtime: ctx gates the recorder on resolveTrajectoryRecording(memory); cloud-defaults
  gates ai-hist MCP on resolveAiMemory(memory). Recorder's internal option unchanged.
- deploy: drop the recordTrajectories preflight enforcement (opt-in ⇒ nothing to enforce).

Reverses this session's earlier enforced-default-on decision per the new opt-in requirement.

Tests: persona-kit 268, deploy 177; cli + workload-router build. Runtime build to be
confirmed in claude-1's env (local agent-trajectories install is version-shimmed).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codeant-ai

codeant-ai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR refactors persona memory configuration from a flat recordTrajectories boolean to a structured facet-based model with nested trajectories (decision-trajectory recording) and aiMemory (ai-hist recall) configuration objects. The change propagates through schema definitions, parsing logic, resolver functions, and integration points across the CLI, runtime, and deployment layers.

Changes

Persona Memory Configuration Refactor

Layer / File(s) Summary
Schema and Type Contract
packages/persona-kit/schemas/persona.schema.json, packages/persona-kit/src/types.ts
PersonaMemoryConfig schema and types restructured to include nested trajectories and aiMemory opt-in facets with dedicated config objects (PersonaTrajectoryConfig, PersonaAiMemoryConfig); recordTrajectories removed from PersonaSpec and replaced with memory field in PersonaSelection.
Memory Parsing and Resolution Helpers
packages/persona-kit/src/parse.ts, packages/persona-kit/src/parse.test.ts
parseMemory extended to parse nested trajectories and aiMemory facets; new exported resolvers resolveTrajectoryRecording and resolveAiMemory derive effective runtime configuration from facet declarations; legacy recordTrajectories handling removed from parsePersonaSpec.
Persona Kit Public API Extensions
packages/persona-kit/src/index.ts
New memory configuration types and resolver functions added to public exports.
Persona Plan AI History Integration
packages/persona-kit/src/plan.ts, packages/persona-kit/src/plan.test.ts
buildPersonaSpawnPlan integrates resolveAiMemory to conditionally inject ai-hist MCP only when memory.aiMemory enabled; new resolveAiHistConfig helper builds ai-hist config from memory and environment; tests updated to verify opt-in behavior and environment overrides.
Interactive Spec Documentation
packages/persona-kit/src/interactive-spec.ts
Documentation and comments updated to reflect ai-hist injection gated by memory.aiMemory recall opt-in rather than trajectory recording.
CLI Persona Selection and Harness Config
packages/cli/src/cli.ts
spec.memory threaded into PersonaSelection; recordTrajectories-based ai-hist injection replaced with resolveAiMemory-gated pattern; resolveAiHistConfig helper added for deriving ai-hist config in dry-run and interactive harness builds.
Runtime Context and Trajectory Recording
packages/runtime/src/ctx.ts, packages/runtime/src/types.ts
buildCtx integrates resolveTrajectoryRecording for trajectory recorder configuration; documentation updated to reference memory.trajectories opt-in instead of recordTrajectories: false.
Cloud Harness AI Memory Injection
packages/runtime/src/cloud-defaults.ts
Cloud harness runner derives ai-hist configuration from resolveAiMemory; resolveAiHistFromEnv signature updated to accept optional trajectory root and database path overrides; ai-hist injection only occurs when aiMemory.enabled is true.
Deployment Validation Updates
packages/deploy/src/preflight.ts, packages/deploy/src/deploy.test.ts
Cloud deployment validation that rejected recordTrajectories: false removed; deploy test updated to verify cloud personas can opt into memory facets with preflight output preserving persona.memory structure.
Workload Router Persona Resolution
packages/workload-router/src/index.ts
resolvePersona conditionally includes memory field from built-in persona spec instead of recordTrajectories boolean.
Example Persona Configurations
examples/proactive-issue-resolver/persona.json, examples/review-agent/persona.json
Example personas updated to use new nested memory.trajectories and memory.aiMemory facet structures.

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly Related PRs

  • AgentWorkforce/workforce#100: Both PRs modify packages/runtime/src/ctx.ts's buildCtx logic at the same context-building function; this PR threads persona.memory for trajectory recording while the related PR rewires context exposure and input resolution.

Suggested labels

size:L

Poem

🐰 Memory now flows through nested facets fine,
Trajectories and recall, both opt-in to align!
No more boolean flags at the top of the tree,
Just structured config for recall and decree.
From CLI to cloud, the refactor runs free! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main refactoring change: consolidating trajectory recording and ai-memory functionality under the memory configuration as opt-in features, which is exactly what the changeset accomplishes across all modified files.
Description check ✅ Passed The description is comprehensive and directly related to the changeset. It clearly explains the what, new shape, behavior matrix, and specific changes across each affected package, which aligns perfectly with the detailed file modifications documented in the raw summary.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/memory-opt-in-facets

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- proactive-issue-resolver: boolean form (trajectories: true, aiMemory: true)
- review-agent: object form (trajectories: { autoCompact }, aiMemory: { enabled })
Both compose with the existing long-form memory block. Parse-verified.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the top-level recordTrajectories boolean property in the persona specification with more granular, opt-in memory facets under memory (memory.trajectories and memory.aiMemory), which are now off by default. The CLI, deploy, runtime, and workload-router packages have been updated to parse, resolve, and utilize these new configurations. Feedback was provided to update the return type of resolveAiHistFromEnv in packages/runtime/src/cloud-defaults.ts to AiHistMcpConfig since it can no longer return undefined.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 656 to 660
function resolveAiHistFromEnv(
env: NodeJS.ProcessEnv,
defaultTrajectoryRoot?: string
defaultTrajectoryRoot?: string,
dbPathOverride?: string
): AiHistMcpConfig | undefined {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The function resolveAiHistFromEnv always returns an object of type AiHistMcpConfig (even if empty) and can never return undefined now that the WORKFORCE_AIHIST_DISABLED check has been removed. Updating the return type to AiHistMcpConfig makes the type signature more accurate and avoids unnecessary undefined checks by callers.

Suggested change
function resolveAiHistFromEnv(
env: NodeJS.ProcessEnv,
defaultTrajectoryRoot?: string
defaultTrajectoryRoot?: string,
dbPathOverride?: string
): AiHistMcpConfig | undefined {
function resolveAiHistFromEnv(
env: NodeJS.ProcessEnv,
defaultTrajectoryRoot?: string,
dbPathOverride?: string
): AiHistMcpConfig {

@codeant-ai

codeant-ai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="examples/review-agent/persona.json">

<violation number="1" location="examples/review-agent/persona.json:19">
P2: Enabling `trajectories` and `aiMemory` under `memory` contradicts the README's explicit warning that memory is not wired (`ctx.memory` is a stub in v1). This creates a misleading configuration where the config signals these features are active, but the underlying runtime infrastructure for this persona does not support them.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

"workspace"
]
],
"trajectories": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Enabling trajectories and aiMemory under memory contradicts the README's explicit warning that memory is not wired (ctx.memory is a stub in v1). This creates a misleading configuration where the config signals these features are active, but the underlying runtime infrastructure for this persona does not support them.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At examples/review-agent/persona.json, line 19:

<comment>Enabling `trajectories` and `aiMemory` under `memory` contradicts the README's explicit warning that memory is not wired (`ctx.memory` is a stub in v1). This creates a misleading configuration where the config signals these features are active, but the underlying runtime infrastructure for this persona does not support them.</comment>

<file context>
@@ -15,7 +15,14 @@
       "workspace"
-    ]
+    ],
+    "trajectories": {
+      "enabled": true,
+      "autoCompact": true
</file context>

The b986dba examples edit added memory.trajectories/aiMemory to review-agent;
parse.test 'accepts the Relayfile-VFS example personas' deep-equals that memory
and needed the expectation updated. (Missed because persona-kit tests were run
before the examples commit.) persona-kit 268 pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codeant-ai

codeant-ai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI.

@khaliqgant khaliqgant merged commit c074de1 into main Jun 6, 2026
2 of 3 checks passed
@khaliqgant khaliqgant deleted the feat/memory-opt-in-facets branch June 6, 2026 13:50
@agent-relay-code

Copy link
Copy Markdown
Contributor

Fixed the validated issue in the PR: memory.trajectories and memory.aiMemory object forms now reject arrays instead of treating [] as an enabled empty config.

Added focused coverage:

  • Parser tests for new memory facet resolution and malformed facet configs in parse.test.ts
  • Runtime buildCtx test proving trajectories are off by default and only emit contracts when memory.trajectories is opted in in ctx.test.ts

Validation run:

  • corepack pnpm --filter @agentworkforce/persona-kit test
  • corepack pnpm --filter @agentworkforce/runtime test
  • corepack pnpm --filter @agentworkforce/cli test
  • corepack pnpm --filter @agentworkforce/deploy test
  • corepack pnpm --filter @agentworkforce/workload-router test

@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer applied fixes — committed and pushed 66746c9 to this PR. The notes below describe what changed.

Fixed the validated issue in the PR: memory.trajectories and memory.aiMemory object forms now reject arrays instead of treating [] as an enabled empty config.

Added focused coverage:

  • Parser tests for new memory facet resolution and malformed facet configs in parse.test.ts
  • Runtime buildCtx test proving trajectories are off by default and only emit contracts when memory.trajectories is opted in in ctx.test.ts

Validation run:

  • corepack pnpm --filter @agentworkforce/persona-kit test
  • corepack pnpm --filter @agentworkforce/runtime test
  • corepack pnpm --filter @agentworkforce/cli test
  • corepack pnpm --filter @agentworkforce/deploy test
  • corepack pnpm --filter @agentworkforce/workload-router test

@agent-relay-code

Copy link
Copy Markdown
Contributor

Fixed the validated PR breakage in parse.test.ts: the example persona assertion now expects the new memory.trajectories and memory.aiMemory facet fields added by the PR.

Verified with:
corepack pnpm --filter @agentworkforce/persona-kit test
corepack pnpm --filter @agentworkforce/runtime test
corepack pnpm --filter @agentworkforce/deploy test
corepack pnpm --filter @agentworkforce/cli test
corepack pnpm --filter @agentworkforce/workload-router test
corepack pnpm run typecheck:examples

agent-relay-code Bot added a commit that referenced this pull request Jun 6, 2026
@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer applied fixes — committed and pushed 2090883 to this PR. The notes below describe what changed.

Fixed the validated PR breakage in parse.test.ts: the example persona assertion now expects the new memory.trajectories and memory.aiMemory facet fields added by the PR.

Verified with:
corepack pnpm --filter @agentworkforce/persona-kit test
corepack pnpm --filter @agentworkforce/runtime test
corepack pnpm --filter @agentworkforce/deploy test
corepack pnpm --filter @agentworkforce/cli test
corepack pnpm --filter @agentworkforce/workload-router test
corepack pnpm run typecheck:examples

@agent-relay-code

Copy link
Copy Markdown
Contributor

Reviewed PR #210 against the current checkout. I did not find any validated breakage that required code edits, so I left the source unchanged.

Local verification passed:

  • @agentworkforce/persona-kit tests
  • @agentworkforce/runtime tests
  • @agentworkforce/deploy tests
  • @agentworkforce/workload-router tests
  • @agentworkforce/cli tests
  • typecheck:examples
  • Full repo check via a temporary pnpm shim: lint, typecheck, and tests all passed

@agent-relay-code

Copy link
Copy Markdown
Contributor

ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed.

Reviewed PR #210 against the current checkout. I did not find any validated breakage that required code edits, so I left the source unchanged.

Local verification passed:

  • @agentworkforce/persona-kit tests
  • @agentworkforce/runtime tests
  • @agentworkforce/deploy tests
  • @agentworkforce/workload-router tests
  • @agentworkforce/cli tests
  • typecheck:examples
  • Full repo check via a temporary pnpm shim: lint, typecheck, and tests all passed

@agent-relay-code

Copy link
Copy Markdown
Contributor

Fixed a parser bug in parse.ts: memory.trajectories: [] and memory.aiMemory: [] no longer parse as empty object configs, which previously resolved as enabled. Added focused coverage in parse.test.ts for valid facet configs and malformed array/string/empty-db cases.

Verification:
@agentworkforce/persona-kit, runtime, deploy, cli, and workload-router tests passed individually. Full local repo check also passed via a temporary Corepack pnpm shim: lint, typecheck, examples typecheck, and all package tests.

@agent-relay-code

Copy link
Copy Markdown
Contributor

⚠️ pr-reviewer push failed (exit 1) — fixes were not applied to the PR. The notes below are advisory and were not pushed.

Fixed a parser bug in parse.ts: memory.trajectories: [] and memory.aiMemory: [] no longer parse as empty object configs, which previously resolved as enabled. Added focused coverage in parse.test.ts for valid facet configs and malformed array/string/empty-db cases.

Verification:
@agentworkforce/persona-kit, runtime, deploy, cli, and workload-router tests passed individually. Full local repo check also passed via a temporary Corepack pnpm shim: lint, typecheck, examples typecheck, and all package tests.

@agent-relay-code

Copy link
Copy Markdown
Contributor

Reviewed PR #210 and made one small test-only fix: added coverage in parse.test.ts for the new memory.trajectories / memory.aiMemory parsing and resolver defaults.

Local validation passed:
PATH="/tmp/corepack-shims:$PATH" pnpm run check

Note: the environment did not have a pnpm shim, so I used Corepack to create one in /tmp/corepack-shims for the check run.

@agent-relay-code

Copy link
Copy Markdown
Contributor

⚠️ pr-reviewer push failed (exit 1) — fixes were not applied to the PR. The notes below are advisory and were not pushed.

Reviewed PR #210 and made one small test-only fix: added coverage in parse.test.ts for the new memory.trajectories / memory.aiMemory parsing and resolver defaults.

Local validation passed:
PATH="/tmp/corepack-shims:$PATH" pnpm run check

Note: the environment did not have a pnpm shim, so I used Corepack to create one in /tmp/corepack-shims for the check run.

@agent-relay-code

Copy link
Copy Markdown
Contributor

ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed.

Reviewed PR #210 against the current checkout. I didn’t find any current breakage or stale bot-review fixes to apply, so I left the working tree source unchanged.

Validated locally:
PATH="/tmp/codex-pnpm-shim:$PATH" corepack pnpm run check

That completed successfully: lint, typecheck including examples, and all package tests passed.

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.

1 participant