feat(cli): inject system prompt, AGENTS.md, and environment into TUI - #531
Merged
Conversation
Move the read-only workspace-instructions scan + prompt builder into packages/runtime/src/system-prompt so the CLI/TUI can reuse it. Desktop keeps the workspace-instruction file-management surface (open/create/template) and re-exports the read-only builders; behavior unchanged.
Move the personalization prompt fragment (display name + assistant tone sanitizer + warning collector) into packages/runtime/src/system-prompt. Desktop imports it from @maka/runtime; behavior unchanged.
…nt builders Move resolveProjectGitInfo/resolveProjectRoot and the per-turn session-environment prompt builder into packages/runtime/src/system-prompt. They go together because session-environment imports the ProjectGitInfo type from project-context. Desktop imports them from @maka/runtime; behavior unchanged.
…kend The CLI AiSdkBackend was created without systemPrompt, so the TUI agent ran with no system message, no AGENTS.md project instructions, and no session environment. Wire buildCliSystemPrompt (personalization + gated workspace instructions) as the durable system prompt and buildCliTurnTailPrompt (cwd/git/platform/date) as the per-turn tail. Skills and local memory are intentionally out of scope here. Driven by cli-system-prompt.test.ts (RED -> GREEN).
…ructions isInside() only checked for `..` escape, but path.relative returns the target unchanged (absolute) when root and target are on different Windows drives, so a symlink/junction to another drive's file was treated as inside the workspace and could leak its content into the system prompt. Extract isPathInside(root, target, pathApi) which rejects an absolute relative() result (cross-drive / different root) before the `..` check; the runtime scan and the desktop open/create management surface both use it. Driven by workspace-instructions.test.ts (RED -> GREEN) covering cross-drive, same-drive-outside, parent escape, and under-root cases.
…apes in isPathInside
isPathInside rejected any relative() result starting with "..", but "..rules" (a legitimate directory name starting with two dots) is not a parent reference — it was wrongly blocked, so an internal symlink pointing to .../..rules/AGENTS.md would not be injected. Narrow the check to reject only the exact ".." segment or a path starting with `..${sep}`, and drop the redundant startsWith("..") / includes() combination (path.relative normalizes intermediate ".." away, so the includes() check was dead). Driven by a RED -> GREEN test for POSIX /repo/..rules/AGENTS.md and Windows C:\repo\..rules\AGENTS.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
apps/desktop/src/mainintopackages/runtime/src/system-prompt, shared by the desktop app and the CLI/TUI.systemPrompt(personalization + gated workspace instructions) and a per-turnturnTailPrompt(cwd/git/platform/date) into the CLI/TUI'sAiSdkBackend. Previously the TUI agent ran with no system message at all.Why
The CLI created its
AiSdkBackendwithout asystemPrompt, so the agent had no AGENTS.md project instructions, no personalization, and no session environment — it ran "naked". Desktop already built these fragments inapps/desktop/src/main, butpackages/clicannot import fromapps/desktop, so the logic had to be shared at the runtime layer.Scope
4 commits, each independently revertible (dependency chain below):
refactor(runtime,desktop): sink workspace-instructions prompt builder— runtime file + index export + desktopworkspace-instructions.ts(re-export read-only builder + keep open/create management surface)refactor(runtime,desktop): sink personalization prompt builder— runtime file + index export + delete desktoppersonalization-prompt.ts+system-prompt-main/settings-ipc-helpers/tests import from@maka/runtimerefactor(runtime,desktop): sink project-context and session-environment builders— sunk together (session-environmentimportsProjectGitInfofromproject-context, must move together) +system-prompt-main/main/2 tests import changedfeat(cli): inject system prompt and per-turn environment into TUI backend—cli-system-prompt.ts+ tests +runtime-bootstrapwiringDependencies and revert:
Not included (intentional, follow-up PRs):
buildSkillAgentToolwiring; another contributor is working on the skills module)LocalMemoryServicefor the CLI (stateful, desktop-only; sunk as an injected fragment in a later PR)buildSystemPrompt(after skills + memory are also sunk, desktop/CLI share one assembler)Verification
cli-system-prompt.test.tswritten first (RED: stub threwnot implemented), then implemented (GREEN: 6 tests pass). Covers the settings gate (enabled/disabled), AGENTS.md injection, personalization, the empty case, joining, and the turn-tail environment.build:maingreen; commit 4 cli test 74 pass.build:main(the working-treemain.tsis in final state and would falsely break, but the staged state is self-consistent); commit 3's desktopbuild:maingreen covers the final state. Per-commit empirical verification can be backfilled withgit stash --keep-indexif wanted.User-facing impact
The TUI agent now receives the cwd's AGENTS.md/CLAUDE.md/GEMINI.md (gated by
settings.workspaceInstructions.enabled), the user's personalization preferences, and a per-turn environment block (cwd/git/branch/platform/date). No desktop behavior change. Skills and local memory are not yet available in the TUI (follow-up PRs).Reviewer notes
settings.json, so disabling workspaceInstructions in desktop also disables it in the TUI.turnTailPrompt(per-turn), not in the durable system prompt, matching desktop, to avoid churning the system-prefix hash when date/branch change.@maka/runtimedoes not import@maka/storage: settings are read by the CLI caller and injected intobuildCliSystemPrompt(per layering review).workspace-instructions.tsre-exports read-only + keeps management).