Compare commits
151 Commits
feat/pi-ex
...
fix/smoke-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed54aa1464 | ||
| a783869e7c | |||
|
|
527983d87e | ||
|
|
24f202cb79 | ||
| 5415060de6 | |||
|
|
fe00f42bce | ||
| 7bf9d49a02 | |||
|
|
7b70c91c41 | ||
| 23c8218811 | |||
|
|
b2aaa9d18d | ||
| 45b875ae2c | |||
|
|
979e9720c0 | ||
| f9ef4ebcb9 | |||
|
|
1180bbdc1d | ||
|
|
709068ce68 | ||
|
|
c1f0117b80 | ||
| 0515f99e17 | |||
|
|
6fbd9c19fc | ||
| 0076fa0d37 | |||
|
|
859150770f | ||
| 3e534854f4 | |||
|
|
61e52403a3 | ||
|
|
70bc7f1598 | ||
| ad00e49262 | |||
|
|
22d8e13390 | ||
| b5d0234d0b | |||
|
|
0e12637271 | ||
| 33d7007af5 | |||
| bc7eb5a0ad | |||
| cd20d8b980 | |||
| 47d7c779d0 | |||
| 08b451b7aa | |||
| 14eb2623bc | |||
| 89db09a12d | |||
| b6e270ee48 | |||
| 0eca4148e3 | |||
| c06c34f0a2 | |||
| c2a419b4f7 | |||
| 2c90f5971d | |||
| a87c4faf21 | |||
|
|
b4ad95ca66 | ||
| bbd31883e8 | |||
|
|
c014fcdd82 | ||
| 7fbb827aa5 | |||
|
|
eb0e97e76e | ||
|
|
065ce02a60 | ||
| 9c5d0d1861 | |||
|
|
c16d7964c9 | ||
| 7716e424f9 | |||
|
|
f097c0f4d5 | ||
| c79bdab51b | |||
|
|
913c0fbdc6 | ||
| beb57baf58 | |||
|
|
0a83f71648 | ||
| f25616f720 | |||
|
|
ec35e1cc36 | ||
| 13421008c7 | |||
|
|
ef9ba6fb8d | ||
| fef26a9f81 | |||
|
|
0793285105 | ||
|
|
370fd0a034 | ||
|
|
f8427959e5 | ||
| 85e53e8d1e | |||
|
|
7b5136491f | ||
| eb3e558a44 | |||
|
|
545e7745da | ||
|
|
fe9987cefd | ||
|
|
0fbfc72d68 | ||
|
|
bd3e1134c9 | ||
|
|
553834dbb1 | ||
|
|
6d38953a96 | ||
|
|
2a85447fac | ||
|
|
5fb1154190 | ||
|
|
b022f322f0 | ||
|
|
f0ba6e8096 | ||
|
|
c66502e590 | ||
|
|
740ce31469 | ||
|
|
ac9423e9c8 | ||
|
|
821c45b2ec | ||
| b6983f036d | |||
|
|
21aadf6d82 | ||
| 35d506df77 | |||
|
|
03350856ea | ||
|
|
8c359902c7 | ||
|
|
8a31121e30 | ||
| db38de7e09 | |||
|
|
ac5dee906e | ||
| d4c33baf03 | |||
|
|
bbd2195c64 | ||
|
|
5a8185d7c9 | ||
| ae5a6203f8 | |||
|
|
822c1bb047 | ||
| cd94e855aa | |||
|
|
b8cedd6262 | ||
| 13f1ff28eb | |||
|
|
96e27c8716 | ||
|
|
dd29f98f82 | ||
|
|
b07287baf2 | ||
|
|
bb4b0b910f | ||
|
|
2a7bba11ea | ||
|
|
2a305f7045 | ||
| 2b87cfdbf1 | |||
|
|
be7fabd467 | ||
| e4e2e063f1 | |||
|
|
a158e49ec2 | ||
|
|
60db1be531 | ||
|
|
4515eb4517 | ||
|
|
a869f77070 | ||
|
|
732ca98ccc | ||
|
|
1a28cc5098 | ||
|
|
fc524583b1 | ||
|
|
f2239852a1 | ||
|
|
b6f3ff8a26 | ||
|
|
00373d2b27 | ||
|
|
1220b974dc | ||
|
|
d9535bc51f | ||
|
|
b2547429ca | ||
|
|
ff0e71da05 | ||
|
|
cbd3b95d97 | ||
|
|
5f5efd1144 | ||
|
|
300c42b404 | ||
|
|
a7094c01c6 | ||
|
|
292506ec98 | ||
|
|
c79477d7fe | ||
|
|
80fa8a3c7e | ||
|
|
888b72b26c | ||
|
|
b7c0de2bf0 | ||
|
|
53507e876a | ||
|
|
834aa704ed | ||
|
|
a9fcd83ed8 | ||
|
|
77c45a2715 | ||
|
|
b3a062ce28 | ||
|
|
d7055a0953 | ||
|
|
c5ea39e959 | ||
|
|
a1f22f46ef | ||
|
|
b0233918ff | ||
|
|
99f881dd67 | ||
|
|
be2a5cb189 | ||
|
|
2513da33c3 | ||
|
|
772c25f605 | ||
|
|
b70300d389 | ||
|
|
05abe3522c | ||
|
|
da4752b90f | ||
|
|
7f64316d59 | ||
|
|
909506317e | ||
|
|
ffcd0f985b | ||
|
|
fceb3cfb95 | ||
|
|
a186d95a85 | ||
|
|
797df2299d | ||
|
|
d24c30761b | ||
|
|
5e1c6b3681 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -47,3 +47,6 @@ test-mcp.sh
|
||||
|
||||
# Claude Code local state
|
||||
.claude/scheduled_tasks.lock
|
||||
|
||||
# Agent worktrees — scratch checkouts, never part of the tree
|
||||
.claude/worktrees/
|
||||
|
||||
808
.taskmaster/docs/prd-agentic-teams.md
Normal file
808
.taskmaster/docs/prd-agentic-teams.md
Normal file
@@ -0,0 +1,808 @@
|
||||
# PRD: Agentic Teams — Foundation
|
||||
|
||||
## Overview
|
||||
|
||||
mcpctl today orchestrates MCP servers, projects, prompts, skills, and chat agents. It does not
|
||||
orchestrate *work*. This PRD adds the foundation that lets human developers and autonomous agents
|
||||
be peers in the same project: a versioned vision layer (Epic → epictask → task), git repositories
|
||||
attached to projects, agents as many-to-many project members, ephemeral per-session pods where
|
||||
agents do real work, a swappable agent runtime, a task lifecycle with QA/Security/SRE gates, and a
|
||||
single human accept gate that fires a merge through the git provider's API.
|
||||
|
||||
The design record is `docs/agentic-teams.md`. This PRD converts §16 steps 1–3 of that document
|
||||
into an implementation spec. Steps 4–8 are named as deferred work at the end, deliberately
|
||||
without detail — they depend on open design questions (`docs/agentic-teams.md` §15) that are not
|
||||
closed.
|
||||
|
||||
## Problem
|
||||
|
||||
Two failure classes motivate this work.
|
||||
|
||||
**Nothing tracks work.** There is no Epic, EpicTask, Task, Repository, or AgentProject model in
|
||||
`src/db/prisma/schema.prisma`, and no repository, service, route, or CLI code for any of them.
|
||||
Agents can chat and call tools, but there is no unit of work to assign, no lifecycle to advance,
|
||||
no branch or PR to attach, and no gate for a human to accept.
|
||||
|
||||
**Completed tasks do not add up to the vision.** From the design doc: you have a grand vision, you
|
||||
split it into tasks, you complete all the tasks, and you are left with a stick with wheels instead
|
||||
of a car. The root cause is not execution — it is that decomposition is lossy, tasks are graded
|
||||
mechanically ("compiles / lint / renders") rather than against intent, and integration is nobody's
|
||||
job. The fix is an authoritative, versioned Epic that every task can walk up to, so "what am I
|
||||
serving, and what does done-for-this look like" is always answerable.
|
||||
|
||||
A third, practical problem shapes the ordering: the design document's "don't rebuild, delegate"
|
||||
principle is correct in spirit, but several primitives it assumes do not exist in mcpctl yet.
|
||||
Those are enumerated under **Execution Substrate Changes** and must land before any agent can work
|
||||
a task.
|
||||
|
||||
## Scope & Non-Goals
|
||||
|
||||
**In scope** (design doc §16 steps 1–3):
|
||||
|
||||
1. Epic / EpicTask / Task / CodeRepo entities + AgentProject membership, with project linkage,
|
||||
mcpd CRUD, CLI verbs, RBAC, backup, docs, and tests.
|
||||
2. An `AgentRuntime` adapter interface and a first implementation running a headless coding agent
|
||||
inside an ephemeral per-session pod. Prove: pod spawn → clone repos → work a task branch →
|
||||
push → report.
|
||||
3. Task lifecycle with QA / Security / SRE stages, PR linkage, the human accept gate, and merge
|
||||
through the git provider API, with post-merge failure reopening the task.
|
||||
|
||||
**Explicitly out of scope** — these are named in *Deferred* below and get placeholder tasks only:
|
||||
the Tier-2 design/product critic and Epic-comparison loop; collaboration modes (standup, joint
|
||||
`exec` sessions as a workflow); the confidence signal and escalation dashboard; per-persona memory
|
||||
and the coverage ledger; script artifacts and the baseline scorecard.
|
||||
|
||||
**Not being built at all:** a permission engine. mcpctl enforces coarse gates (who may transition
|
||||
a task, what RBAC a session needs); fine-grained per-tool approval stays inside the agent runtime.
|
||||
|
||||
## Decisions Already Made
|
||||
|
||||
| Decision | Choice | Rationale |
|
||||
|---|---|---|
|
||||
| Work-item RBAC name | Work items take `tasks`; the inference queue moves to `inference-tasks` | Matches the design doc's vocabulary. The `inference-tasks` alias already exists, so the URL prefix `/api/v1/inference-tasks` is unchanged |
|
||||
| Roadmap-node spelling | Model `EpicTask`, resource `epictasks`, aliases `epictask`, `et` | Design doc §15 Q2; one word, matches the doc's own usage |
|
||||
| Git-repo resource name | Model `CodeRepo`, resource `repos`, aliases `repo`, `repository`, `repositories` | Avoids `repository.repository.ts` and the collision with the data-access-layer term used throughout `src/mcpd/src/repositories/` |
|
||||
| Epic revisions | Epic joins the existing `ResourceRevision` system as `resourceType: 'epic'` | The Epic is the auditable source of truth for "is this done"; scope changes must be visible. `ResourceType` is a string union by design, so this is a non-migration change |
|
||||
| Agent membership | New `AgentProject` junction; `Agent.projectId` retained and kept in sync for one release | Design doc §4. `ProjectMember` was deliberately dropped in migration `20260223120000_remove_project_members`; this is a narrower reversal — agent membership only, not human membership, which stays RBAC-driven |
|
||||
| Invariants | Enforced in the service layer, not CHECK constraints | See *Deployment constraint* below |
|
||||
| Agent brain | Home brain (`Agent.llmId`) for bare chat; the project's `llmProvider`/`llmModel` when the agent acts inside a project; optional per-membership override on `AgentProject.llmId` | Design doc §15 Q1 leans this way. **This is the one open question that blocks the data model** — the `AgentProject.llmId` column exists so the decision can be reversed without a migration |
|
||||
|
||||
### Deployment constraint (affects every schema task)
|
||||
|
||||
`deploy/entrypoint.sh` provisions the database with `prisma db push --accept-data-loss`, not
|
||||
`prisma migrate deploy`. Hand-written SQL in `src/db/prisma/migrations/` therefore **never runs in
|
||||
production**. The single existing CHECK constraint, `ChatThread_agent_xor_project` (migration
|
||||
`20260717234728_add_project_chat_threads`), is absent from any `db push`-provisioned database and
|
||||
is enforced only by `ChatService`.
|
||||
|
||||
Consequence: every invariant introduced here must be either expressible in the Prisma schema
|
||||
(unique constraints, non-null columns, enums, foreign keys) or enforced in the service layer with
|
||||
a test. Do not write CHECK constraints and assume they hold.
|
||||
|
||||
## Core Concepts
|
||||
|
||||
### The vision layer
|
||||
|
||||
```
|
||||
Epic (the vision — project-scoped, versioned, revision-tracked)
|
||||
└── EpicTask — a roadmap node; chains to other epictasks (dependency graph)
|
||||
└── Task — the unit of work, with its own lifecycle
|
||||
```
|
||||
|
||||
An **Epic** holds the agreed done-criteria written at vision time, its scope-change history, and
|
||||
accepted-tradeoff decisions. An Epic is done only when 100% of the vision is delivered, **or** the
|
||||
user explicitly accepted the tradeoffs — recorded so "done" is honest and auditable.
|
||||
|
||||
An **EpicTask** is a roadmap node. EpicTasks chain to one another, so visualising them yields a
|
||||
dependency graph rather than a flat sequence. Each carries the decomposed subset of the Epic's
|
||||
acceptance criteria, so per-node completeness is computable.
|
||||
|
||||
A **Task** is the unit of work, owned by an EpicTask. Because Task → EpicTask → Epic, every task
|
||||
can resolve what it is serving by walking up the chain.
|
||||
|
||||
### Two-level verification
|
||||
|
||||
| Level | Checks | Who | When |
|
||||
|---|---|---|---|
|
||||
| Tier 1 — correctness / security / ops | Builds, runs, passes tests, stays secure, and the deployment-as-code is right for this project's real infrastructure | Developer + QA + Security + SRE personas | Inside the task's own lifecycle, before Done |
|
||||
| Tier 2 — vision fidelity | Does the assembled result match the vision | Design/product critic | At the Epic level — **deferred, not in this PRD** |
|
||||
|
||||
Tier 1 stages are gates *inside* the task loop. Their feedback bounces the task back to
|
||||
`InProgress`. They are not post-submit reviewers.
|
||||
|
||||
The **SRE/Release stage** reviews the deployment-as-code — is it targeting the right
|
||||
infrastructure, by the right method, with the right tooling. It reviews the deployment
|
||||
*definition*; it does not deploy. It exists because a large share of failures come from implicit
|
||||
operational rules a developer LLM does not know. Concrete example: this cluster runs default-deny
|
||||
network policies, so any new workload needs explicit egress and ingress rules. A developer LLM
|
||||
watching a connection fail will deep-dive the network-debugging path when the real cause is a
|
||||
missing egress policy silently dropping traffic. The SRE persona, holding per-project infra
|
||||
knowledge, flags that in review.
|
||||
|
||||
### Agents as people
|
||||
|
||||
An agent exists independently of any project — a persistent identity with a name, description,
|
||||
system prompt, and a home brain. It joins zero, one, or many projects. Per-project role and
|
||||
scope hang off the membership junction, not off the agent.
|
||||
|
||||
### Pod per session
|
||||
|
||||
Each agent session gets its own ephemeral pod. The pod *is* the workspace: an init container
|
||||
clones the project's repositories, the session is attached to project prompts, MCP tools, and
|
||||
scoped secrets, and the pod dies at session end. Agents do not share a live filesystem with each
|
||||
other — handoffs happen via git (branch + diff + verdict pinned to a commit). A single human may
|
||||
share one agent's environment via `exec`.
|
||||
|
||||
## Schema Changes
|
||||
|
||||
All new models follow existing house conventions: `id String @id @default(cuid())`,
|
||||
`version Int @default(1)` as an optimistic-concurrency counter bumped unconditionally in the
|
||||
repository layer (see `agent.repository.ts` `updateData.version = { increment: 1 }`), plus
|
||||
`createdAt` / `updatedAt`.
|
||||
|
||||
### Epic
|
||||
|
||||
```prisma
|
||||
model Epic {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
description String @default("")
|
||||
// The agreed statement of the vision. Body of the Epic.
|
||||
content String @db.Text
|
||||
// Checkable outcomes + intent/quality attributes that define 100% delivery.
|
||||
// Array of { id, text, kind: 'outcome' | 'quality', met: boolean }.
|
||||
doneCriteria Json @default("[]")
|
||||
// Accepted-tradeoff records: { what, why, who, deScopedBy, at }.
|
||||
acceptedTradeoffs Json @default("[]")
|
||||
projectId String
|
||||
status EpicStatus @default(open)
|
||||
semver String @default("0.1.0")
|
||||
currentRevisionId String?
|
||||
ownerId String
|
||||
version Int @default(1)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
|
||||
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
epicTasks EpicTask[]
|
||||
|
||||
@@unique([name, projectId])
|
||||
@@index([projectId])
|
||||
@@index([name])
|
||||
}
|
||||
|
||||
enum EpicStatus {
|
||||
open
|
||||
delivered // 100% of doneCriteria met
|
||||
delivered_with_tradeoffs
|
||||
cancelled
|
||||
}
|
||||
```
|
||||
|
||||
### EpicTask
|
||||
|
||||
```prisma
|
||||
model EpicTask {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
description String @default("")
|
||||
epicId String
|
||||
// Decomposed subset of the Epic's doneCriteria this node is responsible for.
|
||||
doneCriteria Json @default("[]")
|
||||
status EpicTaskStatus @default(todo)
|
||||
ownerId String
|
||||
version Int @default(1)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
epic Epic @relation(fields: [epicId], references: [id], onDelete: Cascade)
|
||||
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
tasks Task[]
|
||||
dependsOn EpicTaskEdge[] @relation("EpicTaskEdgeFrom")
|
||||
blocks EpicTaskEdge[] @relation("EpicTaskEdgeTo")
|
||||
|
||||
@@unique([name, epicId])
|
||||
@@index([epicId])
|
||||
}
|
||||
|
||||
// Chaining between roadmap nodes. Modelled as an explicit edge table rather
|
||||
// than a self-referencing array so the graph can be walked in both directions
|
||||
// and edges can later carry a type.
|
||||
model EpicTaskEdge {
|
||||
id String @id @default(cuid())
|
||||
fromId String // the dependent node
|
||||
toId String // the prerequisite node
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
from EpicTask @relation("EpicTaskEdgeFrom", fields: [fromId], references: [id], onDelete: Cascade)
|
||||
to EpicTask @relation("EpicTaskEdgeTo", fields: [toId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([fromId, toId])
|
||||
@@index([fromId])
|
||||
@@index([toId])
|
||||
}
|
||||
|
||||
enum EpicTaskStatus {
|
||||
todo
|
||||
in_progress
|
||||
done
|
||||
cancelled
|
||||
}
|
||||
```
|
||||
|
||||
Cycle prevention in the edge graph is a service-layer check (see *Deployment constraint*): before
|
||||
creating an edge, walk `to`'s transitive dependencies and reject if `from` is reachable.
|
||||
|
||||
### Task
|
||||
|
||||
```prisma
|
||||
model Task {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
title String
|
||||
description String @default("") @db.Text
|
||||
epicTaskId String
|
||||
repoId String?
|
||||
// The agent currently responsible. Null while unassigned.
|
||||
assigneeId String?
|
||||
state TaskState @default(todo)
|
||||
// Drives how much Tier-1 verification is engaged: trivial work may pass on a
|
||||
// light self-check; risky work engages QA / Security / SRE.
|
||||
risk TaskRisk @default(normal)
|
||||
// Git linkage, populated when the agent pushes.
|
||||
branch String?
|
||||
headCommit String?
|
||||
prUrl String?
|
||||
prNumber Int?
|
||||
// Free-form reviewer comment attached at the accept gate.
|
||||
reviewNote String? @db.Text
|
||||
ownerId String
|
||||
version Int @default(1)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
epicTask EpicTask @relation(fields: [epicTaskId], references: [id], onDelete: Cascade)
|
||||
repo CodeRepo? @relation(fields: [repoId], references: [id], onDelete: SetNull)
|
||||
assignee Agent? @relation(fields: [assigneeId], references: [id], onDelete: SetNull)
|
||||
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
verdicts TaskVerdict[]
|
||||
sessions AgentSession[]
|
||||
events TaskEvent[]
|
||||
|
||||
@@unique([name, epicTaskId])
|
||||
@@index([epicTaskId])
|
||||
@@index([state])
|
||||
@@index([assigneeId])
|
||||
}
|
||||
|
||||
enum TaskState {
|
||||
todo
|
||||
in_progress
|
||||
building // compile, run, smoke
|
||||
self_testing // developer's own tests
|
||||
qa_review
|
||||
security_review
|
||||
sre_review
|
||||
done // leaves the developer's loop
|
||||
awaiting_review // human accept gate
|
||||
merged
|
||||
reopened // post-merge failure
|
||||
cancelled
|
||||
}
|
||||
|
||||
enum TaskRisk {
|
||||
trivial // docs, formatting — light self-check may suffice
|
||||
normal
|
||||
high // auth, secrets, migrations, cross-contract
|
||||
}
|
||||
|
||||
// A Tier-1 persona's verdict, pinned to the commit it judged. Immutable —
|
||||
// this is the provenance record the design doc calls "QA verified 3f2ab".
|
||||
model TaskVerdict {
|
||||
id String @id @default(cuid())
|
||||
taskId String
|
||||
stage TaskState // qa_review | security_review | sre_review
|
||||
agentId String?
|
||||
commit String
|
||||
passed Boolean
|
||||
summary String @db.Text
|
||||
// Structured findings: [{ severity, message, path?, line? }]
|
||||
findings Json @default("[]")
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
|
||||
agent Agent? @relation(fields: [agentId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([taskId])
|
||||
@@index([taskId, stage])
|
||||
}
|
||||
|
||||
// Append-only transition log. Every state change writes one row.
|
||||
model TaskEvent {
|
||||
id String @id @default(cuid())
|
||||
taskId String
|
||||
fromState TaskState?
|
||||
toState TaskState
|
||||
actorType String // 'user' | 'agent' | 'system'
|
||||
actorId String?
|
||||
note String? @db.Text
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([taskId, createdAt])
|
||||
}
|
||||
```
|
||||
|
||||
### CodeRepo
|
||||
|
||||
```prisma
|
||||
model CodeRepo {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
projectId String
|
||||
// Clone URL. https for token auth, ssh for key auth.
|
||||
url String
|
||||
defaultBranch String @default("main")
|
||||
// Relative path under the session workspace root. Defaults to `name`.
|
||||
path String @default("")
|
||||
// Git provider, for PR/merge API calls. 'gitea' is the only driver in v1.
|
||||
provider String @default("gitea")
|
||||
// Secret holding the provider credential. Resolved through SecretService at
|
||||
// session-provision time — never stored in plaintext on the row.
|
||||
credSecretId String?
|
||||
credSecretKey String?
|
||||
ownerId String
|
||||
version Int @default(1)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
|
||||
cred Secret? @relation(fields: [credSecretId], references: [id])
|
||||
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
tasks Task[]
|
||||
|
||||
@@unique([name, projectId])
|
||||
@@index([projectId])
|
||||
}
|
||||
```
|
||||
|
||||
### AgentProject
|
||||
|
||||
Mirrors `ProjectServer` (`schema.prisma`): explicit join model with its own cuid `id`, `createdAt`,
|
||||
cascade on both sides, `@@unique([a, b])`. Indexes on both columns follow `PersonalityPrompt`,
|
||||
because both reverse lookups are needed ("agents of project", "projects of agent").
|
||||
|
||||
```prisma
|
||||
model AgentProject {
|
||||
id String @id @default(cuid())
|
||||
agentId String
|
||||
projectId String
|
||||
// Per-project persona role. TEXT, not an enum, so adding a role later is a
|
||||
// non-migration change (same reasoning as ResourceProposal.resourceType).
|
||||
// v1 values: 'developer' | 'qa' | 'security' | 'sre'.
|
||||
role String @default("developer")
|
||||
// Optional per-membership brain override. Present so the open question in
|
||||
// docs/agentic-teams.md §15 Q1 can be answered either way without a migration.
|
||||
llmId String?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
|
||||
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
|
||||
llm Llm? @relation(fields: [llmId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@unique([agentId, projectId])
|
||||
@@index([agentId])
|
||||
@@index([projectId])
|
||||
}
|
||||
```
|
||||
|
||||
`Agent.projectId` is **retained** and written in sync with the junction for one release, so
|
||||
existing `prepareContext` / `findByProjectId` paths keep working. A follow-up removes it.
|
||||
|
||||
### AgentSession
|
||||
|
||||
```prisma
|
||||
model AgentSession {
|
||||
id String @id @default(cuid())
|
||||
agentId String
|
||||
projectId String
|
||||
taskId String?
|
||||
// Orchestrator handle — pod name on k8s, container id on docker.
|
||||
containerId String?
|
||||
state SessionState @default(pending)
|
||||
image String
|
||||
// Reaped when now() > expiresAt. Swept by the same style of GC loop as the
|
||||
// inference-task sweep in main.ts.
|
||||
expiresAt DateTime
|
||||
lastError String? @db.Text
|
||||
ownerId String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
endedAt DateTime?
|
||||
|
||||
agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
|
||||
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
|
||||
task Task? @relation(fields: [taskId], references: [id], onDelete: SetNull)
|
||||
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([state])
|
||||
@@index([taskId])
|
||||
@@index([agentId])
|
||||
}
|
||||
|
||||
enum SessionState {
|
||||
pending
|
||||
provisioning
|
||||
running
|
||||
ended
|
||||
failed
|
||||
}
|
||||
```
|
||||
|
||||
### Back-relations on existing models
|
||||
|
||||
Prisma requires both sides of every relation. The blocks above show only the owning side; the
|
||||
following fields must be added to existing models or `prisma generate` fails:
|
||||
|
||||
| Model | Fields to add |
|
||||
|---|---|
|
||||
| `Project` | `epics Epic[]`, `codeRepos CodeRepo[]`, `agentMemberships AgentProject[]`, `sessions AgentSession[]` |
|
||||
| `User` | `ownedEpics Epic[]`, `ownedEpicTasks EpicTask[]`, `ownedTasks Task[]`, `ownedRepos CodeRepo[]`, `ownedSessions AgentSession[]` |
|
||||
| `Agent` | `projectMemberships AgentProject[]`, `assignedTasks Task[]`, `verdicts TaskVerdict[]`, `sessions AgentSession[]` |
|
||||
| `Llm` | `agentProjects AgentProject[]` |
|
||||
| `Secret` | `codeRepos CodeRepo[]` |
|
||||
|
||||
`Agent.projectId` and its `project Project?` relation stay as-is during the transition release, so
|
||||
`Project` carries both `agents Agent[]` (existing) and `agentMemberships AgentProject[]` (new).
|
||||
|
||||
### Test helper
|
||||
|
||||
`src/db/tests/helpers.ts` `clearAllTables` must gain `deleteMany` calls for every new model —
|
||||
globals with nullable foreign keys do not cascade.
|
||||
|
||||
## API Changes
|
||||
|
||||
All routes sit under `/api/v1`, follow the existing Fastify + zod-in-the-service pattern, and
|
||||
resolve `project` / `agent` name strings to ids at the route layer (as `routes/skills.ts` does).
|
||||
|
||||
### New endpoints
|
||||
|
||||
```
|
||||
# Vision layer
|
||||
GET|POST /api/v1/epics ?project=<name>
|
||||
GET|PUT|DELETE /api/v1/epics/:id
|
||||
GET /api/v1/epics/:id/roadmap → epictask graph + per-node completeness
|
||||
POST /api/v1/epics/:id/tradeoffs → append an accepted-tradeoff record
|
||||
|
||||
GET|POST /api/v1/epictasks ?epic=<name>&project=<name>
|
||||
GET|PUT|DELETE /api/v1/epictasks/:id
|
||||
POST|DELETE /api/v1/epictasks/:id/edges → { toId } add/remove a dependency edge
|
||||
|
||||
# Work items
|
||||
GET|POST /api/v1/tasks ?project=&epictask=&state=&assignee=
|
||||
GET|PUT|DELETE /api/v1/tasks/:id
|
||||
POST /api/v1/tasks/:id/transition → { toState, note? }
|
||||
POST /api/v1/tasks/:id/verdict → record a QA/Security/SRE verdict
|
||||
POST /api/v1/tasks/:id/accept → { note? } human accept gate → merge
|
||||
POST /api/v1/tasks/:id/reject → { note } → back to in_progress
|
||||
GET /api/v1/tasks/:id/events
|
||||
|
||||
# Repositories
|
||||
GET|POST /api/v1/repos ?project=<name>
|
||||
GET|PUT|DELETE /api/v1/repos/:id
|
||||
|
||||
# Agent membership
|
||||
GET /api/v1/agents/:name/projects
|
||||
POST|DELETE /api/v1/agents/:name/projects/:project → { role?, llm? }
|
||||
GET /api/v1/projects/:name/agents
|
||||
|
||||
# Sessions & exec
|
||||
GET|POST /api/v1/sessions ?project=&agent=&task=
|
||||
GET|DELETE /api/v1/sessions/:id
|
||||
POST /api/v1/sessions/:id/exec → one-shot exec, returns { exitCode, stdout, stderr }
|
||||
GET /api/v1/sessions/:id/attach → WebSocket, bidirectional stdio
|
||||
|
||||
# Git provider webhook
|
||||
POST /api/v1/webhooks/git/:provider → post-merge failure reopens the task
|
||||
```
|
||||
|
||||
### Changed endpoints
|
||||
|
||||
`/api/v1/inference-tasks/*` is unchanged in shape. Only its RBAC resource name changes (see
|
||||
below).
|
||||
|
||||
## RBAC Changes
|
||||
|
||||
### The `tasks` namespace split
|
||||
|
||||
`src/mcpd/src/validation/rbac-definition.schema.ts` currently declares `tasks` in
|
||||
`RBAC_RESOURCES` and aliases `task`, `inference-task`, and `inference-tasks` all onto it — with
|
||||
the comment "the only 'task' we have is inference for now". That is no longer true.
|
||||
|
||||
Required changes:
|
||||
|
||||
1. `RBAC_RESOURCES` gains `epics`, `epictasks`, `tasks` (now meaning work items), `repos`,
|
||||
`sessions`, and `inference-tasks`.
|
||||
2. `RESOURCE_ALIASES` maps `task → tasks`, `epic → epics`, `epictask → epictasks`,
|
||||
`et → epictasks`, `repo → repos`, `repository → repos`, `repositories → repos`,
|
||||
`session → sessions`, and `inference-task → inference-tasks`. The entry
|
||||
`'inference-tasks': 'tasks'` is **removed**.
|
||||
3. `mapUrlToPermission` in `src/mcpd/src/main.ts` gains `epics`, `epictasks`, `tasks`, `repos`,
|
||||
`sessions`, and maps `/api/v1/inference-tasks` to `inference-tasks`. Non-CRUD verbs need
|
||||
explicit cases above the map: `POST /tasks/:id/accept|reject|transition` → `run:tasks:<name>`,
|
||||
`POST /sessions/:id/exec` and `GET /sessions/:id/attach` → `run:sessions:<name>`.
|
||||
4. `nameResolvers` (`main.ts`) gains `epics`, `epictasks`, `tasks`, `repos`, `sessions` so
|
||||
name-scoped grants match when the URL carries a cuid.
|
||||
|
||||
### One-shot binding backfill
|
||||
|
||||
`ResourceBindingSchema` transforms `resource` through `normalizeResource` **at parse time** and
|
||||
stores the normalized string, so existing `RbacDefinition.roleBindings` rows already contain the
|
||||
literal `"tasks"` meaning *inference*. After the split, those grants would silently become
|
||||
work-item grants.
|
||||
|
||||
A one-shot startup migration must rewrite `resource: "tasks"` → `"inference-tasks"` across all
|
||||
`RbacDefinition` rows. Model the walk on `migrateAdminRole` in `src/mcpd/src/main.ts` (it iterates
|
||||
`rbacRepo.findAll()` and rewrites `roleBindings` in place).
|
||||
|
||||
It must be **guarded so it runs exactly once** — a blanket rewrite on every boot would clobber
|
||||
legitimate new work-item grants. Use the existing system-settings pattern: a boolean key in the
|
||||
`mcpctl-system-settings` Secret (`SYSTEM_SETTINGS_SECRET` in
|
||||
`src/mcpd/src/bootstrap/system-settings.ts`), read before the walk and written after. Wildcard
|
||||
bindings (`resource: '*'`) are untouched — they already cover both.
|
||||
|
||||
Document the rename in `docs/inference-tasks.md`.
|
||||
|
||||
## CLI Changes
|
||||
|
||||
Two project rules govern every resource added here:
|
||||
|
||||
- Everything settable via `apply -f` **must** also be a `create` flag.
|
||||
- `mcpctl get RESOURCE NAME -o yaml` **must** round-trip through `mcpctl apply -f`.
|
||||
|
||||
### New commands
|
||||
|
||||
```
|
||||
mcpctl get epics|epictasks|tasks|repos|sessions [--project NAME]
|
||||
mcpctl describe epic|epictask|task|repo|session NAME
|
||||
mcpctl create epic|epictask|task|repo ...
|
||||
mcpctl edit epic|epictask|task|repo NAME
|
||||
mcpctl delete epic|epictask|task|repo NAME
|
||||
|
||||
mcpctl describe epic NAME # roadmap: epictask graph + per-node completeness
|
||||
mcpctl tasks accept NAME [--note ..] # human accept gate → merge via provider API
|
||||
mcpctl tasks reject NAME --note .. # → back to in_progress
|
||||
mcpctl exec --project NAME AGENT -- bash
|
||||
```
|
||||
|
||||
`mcpctl exec` semantics (design doc §10): exec drops the human into the **working environment** —
|
||||
the cloned repos, branches, tools, and deps. It does **not** attach to the agent's reasoning loop.
|
||||
The agent remains a separate process the human can still talk to.
|
||||
|
||||
### Files to touch
|
||||
|
||||
| Concern | File |
|
||||
|---|---|
|
||||
| Resource aliases | `src/cli/src/commands/shared.ts` `RESOURCE_ALIASES` |
|
||||
| `get` columns + yaml kind | `src/cli/src/commands/get.ts` — row interfaces, `getColumnsForResource`, `RESOURCE_KIND`, `toApplyDocs` strip blocks |
|
||||
| `describe` formatters | `src/cli/src/commands/describe.ts` — clean sections and tables, not key-value dumps |
|
||||
| `create` subcommands | `src/cli/src/commands/create.ts` |
|
||||
| `apply -f` | `src/cli/src/commands/apply.ts` — spec schemas, `ApplyConfigSchema` keys, `KIND_TO_RESOURCE`, dry-run counts, apply loops |
|
||||
| `edit` | `src/cli/src/commands/edit.ts` `validResources` |
|
||||
| Scoped fetch | `src/cli/src/index.ts` `fetchResource` / `fetchSingleResource` for `--project` scoping |
|
||||
| Completions | `scripts/generate-completions.ts` `CANONICAL_RESOURCES` + `ALIAS_ENTRIES`, then `pnpm completions:generate` |
|
||||
|
||||
Completions are generated, never hand-edited; `src/cli/tests/completions.test.ts` runs the
|
||||
generator with `--check` and fails on drift.
|
||||
|
||||
## Execution Substrate Changes
|
||||
|
||||
These are the primitives the design document assumes but mcpctl does not have. They gate step 2.
|
||||
|
||||
### 1. Ephemeral pods
|
||||
|
||||
`ContainerSpec` in `src/mcpd/src/services/orchestrator.ts` has only image, name, command, env,
|
||||
ports, limits, labels, and network. `generatePodSpec` in
|
||||
`src/mcpd/src/services/k8s/manifest-generator.ts` hardcodes `restartPolicy: 'Always'`, and no code
|
||||
anywhere uses the Kubernetes Job API.
|
||||
|
||||
`ContainerSpec` must gain:
|
||||
|
||||
- `restartPolicy?: 'Always' | 'Never' | 'OnFailure'`
|
||||
- `workdir?: string`
|
||||
- `volumes?: Array<{ name: string; mountPath: string; kind: 'emptyDir' }>` — the session
|
||||
workspace
|
||||
- `initContainers?: Array<{ name; image; command; env?; volumeMounts? }>` — the repo-clone step
|
||||
|
||||
Both backends implement them: `KubernetesOrchestrator` and `DockerContainerManager`.
|
||||
|
||||
### 2. Session provisioning
|
||||
|
||||
A `SessionService` that: creates the `AgentSession` row; resolves the project's `CodeRepo` list and
|
||||
their credentials through `SecretService` (resolution failure is fatal for the attempt, matching
|
||||
`InstanceService.attemptStart`); builds a spec with an init container that clones each repo to its
|
||||
`path` under the workspace volume and checks out the task branch; starts the pod; and transitions
|
||||
the row to `running`.
|
||||
|
||||
Reaping runs as a GC sweep in the same style as the existing inference-task sweep in
|
||||
`src/mcpd/src/main.ts`: sessions past `expiresAt` are stopped, removed, and marked `ended`. Note
|
||||
these loops assume a single mcpd replica — there is no leader election, and this inherits that.
|
||||
|
||||
### 3. Exec surface
|
||||
|
||||
The hard part already exists. `McpOrchestrator` declares `execInContainer`, `execInteractive`, and
|
||||
`attachInteractive`; `KubernetesOrchestrator` implements the latter two over `k8s.Exec` and
|
||||
`k8s.Attach`, and `src/mcpd/src/services/transport/persistent-stdio.ts` uses them in production
|
||||
today. This work is an **API and CLI surface over a proven primitive**: a one-shot exec route, a
|
||||
WebSocket attach route with terminal resize and proper exit-code propagation, and the
|
||||
`mcpctl exec` client.
|
||||
|
||||
### 4. Git provider client
|
||||
|
||||
No Gitea or GitHub API client, PR creation, or webhook handling exists in product code. PRs are
|
||||
made today by the root-level `pr.sh` (curl against the Gitea API) or by an agent calling the
|
||||
`gitea-mcp-server` MCP tool.
|
||||
|
||||
A `GitProvider` interface in mcpd with a Gitea driver: `createPullRequest`, `getPullRequest`,
|
||||
`getCombinedStatus`, `mergePullRequest`. Credentials resolve from the `CodeRepo`'s Secret.
|
||||
`pr.sh` is the reference for the endpoint shapes (`POST /api/v1/repos/:owner/:repo/pulls`).
|
||||
A webhook receiver validates the provider signature and reopens the task on post-merge failure.
|
||||
|
||||
## AgentRuntime Interface
|
||||
|
||||
mcpctl builds an *interface*, not a runtime. `ChatService` is not a candidate — its tool loop is
|
||||
capped at `MAX_ITERATIONS = 12` (clamped 1..50), which is a soft-DoS guard appropriate for chat
|
||||
and far too small for a coding task.
|
||||
|
||||
```ts
|
||||
export interface AgentRuntime {
|
||||
startSession(opts: RuntimeSessionOpts): Promise<RuntimeSession>;
|
||||
send(sessionId: string, message: string): Promise<void>;
|
||||
status(sessionId: string): Promise<RuntimeStatus>;
|
||||
result(sessionId: string): Promise<RuntimeResult>; // branch, head commit, summary
|
||||
endSession(sessionId: string): Promise<void>;
|
||||
}
|
||||
```
|
||||
|
||||
Implementation #1 runs a battle-tested headless coding agent inside the session pod. It already
|
||||
solves per-tool permission approval, git and branch mechanics, subagents, streaming, and MCP
|
||||
client behaviour — all things the design document explicitly declines to rebuild. The persona is
|
||||
delivered as prompt files in the container, which suits a file-aware coding runtime.
|
||||
|
||||
A second adapter is explicitly deferred; the interface exists so it stays possible.
|
||||
|
||||
## Task Lifecycle
|
||||
|
||||
```
|
||||
todo → in_progress → building → self_testing
|
||||
→ qa_review (feedback → in_progress)
|
||||
→ security_review (feedback → in_progress)
|
||||
→ sre_review (feedback → in_progress)
|
||||
→ done → awaiting_review
|
||||
accept → merged
|
||||
reject → in_progress
|
||||
merged --post-merge failure (webhook)--> reopened
|
||||
```
|
||||
|
||||
Verification effort scales with `Task.risk`: `trivial` work may pass on a light self-check;
|
||||
`high` engages all three review stages. The stages decide their own depth.
|
||||
|
||||
Transitions are guarded by a table of legal `(from, to)` pairs and applied as **compare-and-swap**
|
||||
— `updateMany` with the expected `state` in the `where` clause, then check the affected-row count.
|
||||
This is the same idiom `InferenceTaskRepository` uses so two racing claimants cannot both win.
|
||||
Every transition appends a `TaskEvent`.
|
||||
|
||||
The human approval gate is **not** a per-tool tri-state. It is a task-level yes/no plus a comment
|
||||
on the resolved outcome, and accepting it fires the merge. The human should not have to go to git.
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
### Unit — `src/db/tests/`
|
||||
- Schema tests per model (pattern: `skill-schema.test.ts`): create, unique constraints, cascade
|
||||
behaviour on project/epic/task delete, `AgentProject` uniqueness.
|
||||
- `clearAllTables` in `helpers.ts` covers every new model.
|
||||
|
||||
### Unit — `src/mcpd/tests/`
|
||||
- Service tests: Epic done-criteria roll-up; EpicTask edge cycle rejection; task transition table
|
||||
including every illegal pair; compare-and-swap under concurrent transition.
|
||||
- Route tests per resource (pattern: `prompt-routes.test.ts`, `agent-routes.test.ts`).
|
||||
- RBAC: the `tasks` → `inference-tasks` backfill runs once and is idempotent on a second boot;
|
||||
a pre-existing `view:tasks` grant still authorizes `/api/v1/inference-tasks` afterwards and does
|
||||
**not** authorize `/api/v1/tasks`; name-scoped grants resolve for all new resources.
|
||||
- Orchestrator: `generatePodSpec` emits `restartPolicy`, workdir, volumes, and init containers.
|
||||
- Git provider: Gitea driver against a mocked HTTP server.
|
||||
|
||||
### Unit — `src/cli/tests/`
|
||||
- `get -o yaml` → `apply -f` round-trip for every new resource.
|
||||
- `create` flag coverage: every field settable in `apply` has a matching flag.
|
||||
- `completions.test.ts` assertions for the new resource words.
|
||||
|
||||
### Smoke — `src/mcplocal/tests/smoke/`
|
||||
Every feature ships smoke tests. Follow the CRUD pattern in `personality.smoke.test.ts`: a
|
||||
`Date.now().toString(36)` name suffix, a `healthz()` preflight that **skips rather than fails**
|
||||
when the daemon is unreachable, `mcpctl --direct` shelling, and explicit `afterAll` cleanup.
|
||||
|
||||
- `epic.smoke.test.ts` — Epic → EpicTask → Task create/list/describe/delete against live mcpd.
|
||||
- `repo.smoke.test.ts` — CodeRepo CRUD, credential reference resolves.
|
||||
- `session.smoke.test.ts` — provision a session pod against the real cluster, confirm the repo is
|
||||
cloned, exec a command, confirm the pod is reaped.
|
||||
- `task-lifecycle.smoke.test.ts` — drive a task through the full transition chain including a
|
||||
rejected accept-gate bounce.
|
||||
|
||||
When a smoke test fails, fix the environment (deploy, backend, RBAC) — never weaken the assertion.
|
||||
|
||||
## Deferred
|
||||
|
||||
Named here so the boundary is explicit. Each gets a single placeholder task with no detail, to be
|
||||
expanded once the corresponding open questions in `docs/agentic-teams.md` §15 are closed.
|
||||
|
||||
- **Tier-2 vision critic and Epic-comparison.** A review-only, non-executing design/product
|
||||
persona that judges the assembled result against the Epic in its native medium, producing
|
||||
reopen / new-task / `exec` outcomes. Blocked on §15 Q13 (does this need render/screenshot
|
||||
infrastructure, or can a design-aware persona judge from a structured artifact?).
|
||||
- **Collaboration modes.** On-demand async standup (`mcpctl standup --project NAME`) and `exec`
|
||||
as a workflow rather than a command. Blocked on §15 Q4 and Q5.
|
||||
- **Confidence signal and escalation dashboard.** Evidence-anchored confidence (retrieve K similar
|
||||
past tasks with their *outcomes*, ask how confident we are this resolves cleanly), thresholds
|
||||
driving autonomy, and a single cross-project human decision queue. Blocked on §15 Q12
|
||||
(web / TUI / CLI?). Retrieval quality is the crux — weak retrieval quietly poisons the model.
|
||||
- **Memory and the coverage ledger.** Global per-agent memory plus per-project knowledge, and a
|
||||
commit-pinned coverage ledger enabling delta-verification. Non-negotiable prerequisite:
|
||||
invalidation when a covered region changes, or the ledger becomes false confidence. Keep the
|
||||
trust boundary — the ledger is platform-verified machine fact; agent prose notes are opinion and
|
||||
never the gate.
|
||||
- **Script artifacts and the baseline scorecard.** Reusable executable `script` artifacts at task,
|
||||
project, and agent scope, plus a provisioned baseline-rules scorecard. Blocked on §15 Q15 and
|
||||
Q16. Watch the incentive integrity risk: reward *reused* tools, not tool proliferation.
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
**Phase A — foundation (blocks everything)**
|
||||
1. RBAC `tasks` namespace split, alias repoint, and the one-shot guarded binding backfill.
|
||||
2. Prisma models Epic, EpicTask, EpicTaskEdge, Task, TaskVerdict, TaskEvent, CodeRepo,
|
||||
AgentSession + enums + migration + `clearAllTables`.
|
||||
3. `AgentProject` junction, with `Agent.projectId` kept in sync for one release.
|
||||
|
||||
**Phase B — mcpd CRUD**
|
||||
4. Epic resource: repository, service, zod validation, routes, `main.ts` wiring, revision opt-in.
|
||||
5. EpicTask resource plus the edge graph and cycle rejection.
|
||||
6. Task resource plus the transition table and compare-and-swap transitions.
|
||||
7. CodeRepo resource with credential resolution.
|
||||
8. RBAC wiring for all new resources: `mapUrlToPermission`, `nameResolvers`, non-CRUD verb cases.
|
||||
9. Backup and YAML kinds for the new resources — `BACKUP_KINDS`, `APPLY_ORDER`, `kindMap`, the
|
||||
export loop, `serializeResource`, and `main.ts` `kindFromSegment` / `importResource` /
|
||||
`deleteResource`. Fix the pre-existing gap where `skill` is missing from the latter two.
|
||||
|
||||
**Phase C — CLI**
|
||||
10. `get` columns and `describe` formatters for all new resources.
|
||||
11. `create`, `apply -f`, `edit`, `delete`, with the yaml round-trip test.
|
||||
12. Shell completions and their guard test.
|
||||
13. Roadmap view: `describe epic` rendering the epictask graph with per-node completeness.
|
||||
|
||||
**Phase D — execution substrate**
|
||||
14. Extend `ContainerSpec` and both orchestrator backends with restart policy, workdir, volumes,
|
||||
and init containers.
|
||||
15. `SessionService`: provisioning, repo-clone init container, credential resolution, TTL and GC.
|
||||
16. `AgentRuntime` interface plus adapter #1 running a headless coding agent in-pod.
|
||||
17. Exec surface: one-shot exec route, WebSocket attach, and `mcpctl exec`.
|
||||
|
||||
**Phase E — lifecycle and PR**
|
||||
18. Task lifecycle state machine, transition API, and `TaskEvent` log.
|
||||
19. `GitProvider` interface plus the Gitea driver.
|
||||
20. PR linkage and the human accept gate firing merge through the provider API.
|
||||
21. QA / Security / SRE stage verdicts, risk-scaled, pinned to a commit.
|
||||
22. Post-merge failure webhook reopening the task.
|
||||
|
||||
**Phase F — cross-cutting**
|
||||
23. Documentation: `docs/epics.md`, `docs/tasks.md`, `docs/repos.md`, `docs/sessions.md`, the
|
||||
README resources table, and the CLAUDE.md resource cheatsheet.
|
||||
24. Smoke tests for every new resource plus the session and lifecycle flows.
|
||||
|
||||
**Phase G — deferred placeholders**
|
||||
25. Tier-2 vision critic and Epic-comparison loop.
|
||||
26. Collaboration modes: async standup and `exec` joint sessions.
|
||||
27. Confidence signal and escalation dashboard.
|
||||
28. Per-agent memory and the coverage ledger.
|
||||
29. Script artifacts and the baseline scorecard.
|
||||
35
.taskmaster/tasks/task_025.md
Normal file
35
.taskmaster/tasks/task_025.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Task ID: 25
|
||||
|
||||
**Title:** Rename local-proxy to mcplocal
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Rename the src/local-proxy directory to src/mcplocal and update all package references, imports, and build configurations throughout the monorepo.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Rename directory: `mv src/local-proxy src/mcplocal`
|
||||
2. Update package.json name from `@mcpctl/local-proxy` to `@mcpctl/mcplocal`
|
||||
3. Update pnpm-workspace.yaml if needed
|
||||
4. Update all imports in other packages that reference local-proxy:
|
||||
- Search for `@mcpctl/local-proxy` and replace with `@mcpctl/mcplocal`
|
||||
- Check tsconfig references and path mappings
|
||||
5. Update any scripts in package.json root that reference local-proxy
|
||||
6. Update docker-compose files in deploy/ if they reference local-proxy
|
||||
7. Update documentation and README references
|
||||
8. Run `pnpm install` to regenerate lockfile with new package name
|
||||
9. Verify TypeScript compilation succeeds: `pnpm build`
|
||||
10. Run existing tests to ensure nothing broke: `pnpm test`
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Verify directory rename completed: `ls src/mcplocal`
|
||||
2. Verify package.json has correct name
|
||||
3. Run `pnpm install` - should complete without errors
|
||||
4. Run `pnpm build` - all packages should compile
|
||||
5. Run `pnpm test` - all existing tests should pass
|
||||
6. Grep codebase for 'local-proxy' - should find no stale references except git history
|
||||
46
.taskmaster/tasks/task_026.md
Normal file
46
.taskmaster/tasks/task_026.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Task ID: 26
|
||||
|
||||
**Title:** Add HTTP REST server to mcplocal
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 25 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Add a Fastify HTTP server to mcplocal that runs alongside the existing stdio server, providing REST endpoints for mcpctl management commands.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add Fastify dependency to mcplocal package.json: `@fastify/cors`, `fastify`
|
||||
2. Create `src/mcplocal/src/http/server.ts` with Fastify app setup:
|
||||
```typescript
|
||||
import Fastify from 'fastify';
|
||||
import cors from '@fastify/cors';
|
||||
|
||||
export async function createHttpServer(config: HttpServerConfig) {
|
||||
const app = Fastify({ logger: true });
|
||||
await app.register(cors, { origin: true });
|
||||
// Register routes
|
||||
return app;
|
||||
}
|
||||
```
|
||||
3. Create `src/mcplocal/src/http/routes/` directory structure
|
||||
4. Create health check endpoint: `GET /health`
|
||||
5. Create config types in `src/mcplocal/src/config.ts`:
|
||||
- `httpPort`: number (default 3200)
|
||||
- `httpHost`: string (default '127.0.0.1')
|
||||
- `mcpdUrl`: string (default 'http://localhost:3100')
|
||||
6. Update mcplocal entry point to start both servers:
|
||||
- stdio server for Claude MCP protocol
|
||||
- HTTP server for mcpctl REST API
|
||||
7. Add graceful shutdown handling for both servers
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Unit test: HTTP server starts on configured port
|
||||
2. Unit test: Health endpoint returns 200 OK
|
||||
3. Integration test: Both stdio and HTTP servers can run simultaneously
|
||||
4. Test graceful shutdown stops both servers cleanly
|
||||
5. Test CORS headers are present on responses
|
||||
6. Manual test: curl http://localhost:3200/health
|
||||
130
.taskmaster/tasks/task_027.md
Normal file
130
.taskmaster/tasks/task_027.md
Normal file
@@ -0,0 +1,130 @@
|
||||
# Task ID: 27
|
||||
|
||||
**Title:** Implement mcplocal management proxy routes
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 26 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Add REST endpoints to mcplocal that mirror mcpd's API and proxy management requests to mcpd without LLM processing. All requests must include proper authentication to mcpd using a Bearer token read from mcplocal config.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create HTTP client for mcpd communication with auth: `src/local-proxy/src/http/mcpd-client.ts`
|
||||
```typescript
|
||||
export class McpdClient {
|
||||
private token: string;
|
||||
|
||||
constructor(private baseUrl: string, token: string) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
private getHeaders(): Record<string, string> {
|
||||
return {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${this.token}`
|
||||
};
|
||||
}
|
||||
|
||||
async get<T>(path: string): Promise<T> {
|
||||
const response = await fetch(`${this.baseUrl}${path}`, {
|
||||
method: 'GET',
|
||||
headers: this.getHeaders()
|
||||
});
|
||||
await this.handleAuthError(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async post<T>(path: string, body: unknown): Promise<T> {
|
||||
const response = await fetch(`${this.baseUrl}${path}`, {
|
||||
method: 'POST',
|
||||
headers: this.getHeaders(),
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
await this.handleAuthError(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async put<T>(path: string, body: unknown): Promise<T> {
|
||||
const response = await fetch(`${this.baseUrl}${path}`, {
|
||||
method: 'PUT',
|
||||
headers: this.getHeaders(),
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
await this.handleAuthError(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async delete<T>(path: string): Promise<T> {
|
||||
const response = await fetch(`${this.baseUrl}${path}`, {
|
||||
method: 'DELETE',
|
||||
headers: this.getHeaders()
|
||||
});
|
||||
await this.handleAuthError(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
private async handleAuthError(response: Response): Promise<void> {
|
||||
if (response.status === 401) {
|
||||
throw new AuthenticationError('Invalid or expired token. Please check mcplocal config.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class AuthenticationError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'AuthenticationError';
|
||||
}
|
||||
}
|
||||
```
|
||||
2. Add token to mcplocal config type (extend ProxyConfig or similar):
|
||||
```typescript
|
||||
export interface McpdAuthConfig {
|
||||
/** Bearer token for mcpd API authentication */
|
||||
mcpdToken: string;
|
||||
}
|
||||
```
|
||||
3. Create proxy routes in `src/local-proxy/src/http/routes/`:
|
||||
- `servers.ts`: GET/POST /api/v1/servers, GET/PUT/DELETE /api/v1/servers/:id
|
||||
- `profiles.ts`: GET/POST /api/v1/profiles, GET/PUT/DELETE /api/v1/profiles/:id
|
||||
- `instances.ts`: GET/POST /api/v1/instances, GET/POST/DELETE /api/v1/instances/:id, etc.
|
||||
- `projects.ts`: GET/POST /api/v1/projects, etc.
|
||||
- `audit.ts`: GET /api/v1/audit-logs
|
||||
- `backup.ts`: POST /api/v1/backup, POST /api/v1/restore
|
||||
4. Each route handler forwards to mcpd with auth:
|
||||
```typescript
|
||||
app.get('/api/v1/servers', async (req, reply) => {
|
||||
try {
|
||||
const result = await mcpdClient.get('/api/v1/servers');
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (error instanceof AuthenticationError) {
|
||||
return reply.status(401).send({ error: error.message });
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
```
|
||||
5. Add comprehensive error handling:
|
||||
- If mcpd is unreachable, return 503 Service Unavailable
|
||||
- If mcpd returns 401, return 401 with clear message about token configuration
|
||||
- Forward other HTTP errors from mcpd with appropriate status codes
|
||||
6. Add request/response logging for debugging
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Unit test: McpdClient attaches Authorization header to all request methods (GET, POST, PUT, DELETE)
|
||||
2. Unit test: McpdClient throws AuthenticationError on 401 response from mcpd
|
||||
3. Unit test: Each proxy route forwards requests correctly with auth headers
|
||||
4. Unit test: Error handling when mcpd is unreachable (503 response)
|
||||
5. Unit test: Error handling when mcpd returns 401 (clear error message returned)
|
||||
6. Integration test: Full request flow mcpctl -> mcplocal -> mcpd with valid token
|
||||
7. Integration test: Full request flow with invalid token returns 401
|
||||
8. Test query parameters are forwarded correctly
|
||||
9. Test request body is forwarded correctly for POST/PUT
|
||||
10. Test path parameters (:id) are passed through correctly
|
||||
11. Mock mcpd responses and verify mcplocal returns them unchanged
|
||||
12. Test token is read correctly from mcplocal config
|
||||
149
.taskmaster/tasks/task_028.md
Normal file
149
.taskmaster/tasks/task_028.md
Normal file
@@ -0,0 +1,149 @@
|
||||
# Task ID: 28
|
||||
|
||||
**Title:** Add MCP proxy endpoint to mcpd
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create a new endpoint in mcpd at /api/v1/mcp/proxy that accepts MCP tool call requests and executes them on managed MCP server instances. Also add authentication endpoints (login/logout) that mcpctl will use to authenticate users.
|
||||
|
||||
**Details:**
|
||||
|
||||
## MCP Proxy Endpoint
|
||||
|
||||
1. Create new route file: `src/mcpd/src/routes/mcp-proxy.ts`
|
||||
2. Define request schema:
|
||||
```typescript
|
||||
interface McpProxyRequest {
|
||||
serverId: string; // or instanceId
|
||||
method: string; // e.g., 'tools/call', 'resources/read'
|
||||
params: Record<string, unknown>;
|
||||
}
|
||||
```
|
||||
3. Create McpProxyService in `src/mcpd/src/services/mcp-proxy-service.ts`:
|
||||
- Look up instance by serverId (auto-start if profile allows)
|
||||
- Connect to the container via stdio or HTTP (depending on transport type)
|
||||
- Execute the MCP JSON-RPC call
|
||||
- Return the result
|
||||
4. Handle MCP JSON-RPC protocol:
|
||||
```typescript
|
||||
async executeCall(instanceId: string, method: string, params: unknown) {
|
||||
const instance = await this.instanceService.getInstance(instanceId);
|
||||
const connection = await this.getOrCreateConnection(instance);
|
||||
const result = await connection.call(method, params);
|
||||
return result;
|
||||
}
|
||||
```
|
||||
5. Connection pooling: maintain persistent connections to running instances
|
||||
6. Add route: `POST /api/v1/mcp/proxy` (must be behind auth middleware)
|
||||
7. Add audit logging for all MCP proxy calls - include authenticated userId from request.userId
|
||||
8. Handle errors: instance not found, instance not running, MCP call failed
|
||||
|
||||
## Authentication Endpoints
|
||||
|
||||
9. Create auth routes file: `src/mcpd/src/routes/auth.ts`
|
||||
10. Implement `POST /api/v1/auth/login`:
|
||||
- Request body: `{ username: string, password: string }`
|
||||
- Validate credentials against User table (use bcrypt for password comparison)
|
||||
- Create new Session record with token (use crypto.randomUUID or similar)
|
||||
- Response: `{ token: string, expiresAt: string }`
|
||||
11. Implement `POST /api/v1/auth/logout`:
|
||||
- Requires Bearer token in Authorization header
|
||||
- Delete/invalidate the Session record
|
||||
- Response: `{ success: true }`
|
||||
|
||||
## Auth Integration Notes
|
||||
|
||||
- Existing auth middleware in `src/mcpd/src/middleware/auth.ts` validates Bearer tokens against Session table
|
||||
- It sets `request.userId` on successful authentication
|
||||
- MCP proxy endpoint MUST use this auth middleware
|
||||
- Auth endpoints (login) should NOT require auth middleware
|
||||
- Logout endpoint SHOULD require auth middleware to validate the session being invalidated
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Unit test: Proxy service looks up correct instance
|
||||
2. Unit test: JSON-RPC call is formatted correctly
|
||||
3. Integration test: Full flow with a mock MCP server container
|
||||
4. Test error handling: non-existent server returns 404
|
||||
5. Test error handling: stopped instance returns appropriate error
|
||||
6. Test audit log entries include authenticated userId
|
||||
7. Test connection reuse for multiple calls to same instance
|
||||
8. Test login endpoint: valid credentials return session token
|
||||
9. Test login endpoint: invalid credentials return 401
|
||||
10. Test logout endpoint: valid session is invalidated
|
||||
11. Test logout endpoint: invalid/missing token returns 401
|
||||
12. Test MCP proxy endpoint without auth token returns 401
|
||||
13. Test MCP proxy endpoint with expired token returns 401
|
||||
14. Test MCP proxy endpoint with valid token succeeds and logs userId in audit
|
||||
|
||||
## Subtasks
|
||||
|
||||
### 28.1. Create auth routes with login/logout endpoints
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** None
|
||||
|
||||
Create src/mcpd/src/routes/auth.ts with POST /api/v1/auth/login and POST /api/v1/auth/logout endpoints for mcpctl authentication.
|
||||
|
||||
**Details:**
|
||||
|
||||
Implement login endpoint: validate username/password against User table using bcrypt, create Session record with generated token and expiry. Implement logout endpoint: require auth middleware, delete/invalidate Session record. Login does NOT require auth, logout DOES require auth. Export registerAuthRoutes function and update routes/index.ts.
|
||||
|
||||
### 28.2. Create MCP proxy route file with auth middleware
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 28.1
|
||||
|
||||
Create src/mcpd/src/routes/mcp-proxy.ts with POST /api/v1/mcp/proxy endpoint protected by auth middleware.
|
||||
|
||||
**Details:**
|
||||
|
||||
Define McpProxyRequest interface (serverId, method, params). Register route handler that extracts userId from request.userId (set by auth middleware). Apply auth middleware using preHandler hook. Validate request body schema.
|
||||
|
||||
### 28.3. Create McpProxyService for instance lookup and connection
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** None
|
||||
|
||||
Create src/mcpd/src/services/mcp-proxy-service.ts to handle instance lookup, connection management, and MCP call execution.
|
||||
|
||||
**Details:**
|
||||
|
||||
Implement getInstance to look up by serverId, auto-start if profile allows. Implement getOrCreateConnection for connection pooling. Handle both stdio and HTTP transports. Implement executeCall method that formats JSON-RPC call and returns result.
|
||||
|
||||
### 28.4. Implement MCP JSON-RPC call execution
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 28.3
|
||||
|
||||
Implement the core JSON-RPC call logic in McpProxyService to execute tool calls on MCP server instances.
|
||||
|
||||
**Details:**
|
||||
|
||||
Format JSON-RPC 2.0 request with method and params. Send request over established connection (stdio/HTTP). Parse JSON-RPC response and handle errors. Return result or throw appropriate error for failed calls.
|
||||
|
||||
### 28.5. Add audit logging with userId for MCP proxy calls
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 28.2, 28.4
|
||||
|
||||
Ensure all MCP proxy calls are logged to audit log including the authenticated userId from the session.
|
||||
|
||||
**Details:**
|
||||
|
||||
Use existing audit middleware/service. Include userId from request.userId in audit log entry. Log serverId, method, and outcome (success/failure). Log any errors that occur during MCP call execution.
|
||||
|
||||
### 28.6. Integrate auth and proxy routes into server.ts
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 28.1, 28.2, 28.5
|
||||
|
||||
Register the new auth and mcp-proxy routes in the Fastify server with proper auth middleware wiring.
|
||||
|
||||
**Details:**
|
||||
|
||||
Update server.ts to register auth routes (no auth required for login). Register mcp-proxy routes with auth middleware. Ensure auth middleware is wired with findSession dependency from Prisma. Update routes/index.ts exports.
|
||||
74
.taskmaster/tasks/task_029.md
Normal file
74
.taskmaster/tasks/task_029.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# Task ID: 29
|
||||
|
||||
**Title:** Implement LLM pre-processing pipeline in mcplocal
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 25 ✓, 27 ✓, 28 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the core LLM pre-processing pipeline that intercepts MCP tool calls, uses a local LLM to optimize requests before sending to mcpd, and filters responses before returning to Claude.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create `src/mcplocal/src/llm/processor.ts` - the core pipeline:
|
||||
```typescript
|
||||
export class LlmProcessor {
|
||||
constructor(
|
||||
private providerRegistry: ProviderRegistry,
|
||||
private config: LlmProcessorConfig
|
||||
) {}
|
||||
|
||||
async preprocessRequest(toolName: string, params: unknown): Promise<ProcessedRequest> {
|
||||
// Use LLM to interpret and optimize the request
|
||||
const prompt = this.buildRequestPrompt(toolName, params);
|
||||
const result = await this.providerRegistry.getActiveProvider().complete({
|
||||
systemPrompt: REQUEST_OPTIMIZATION_SYSTEM_PROMPT,
|
||||
userPrompt: prompt
|
||||
});
|
||||
return this.parseOptimizedRequest(result);
|
||||
}
|
||||
|
||||
async filterResponse(toolName: string, originalRequest: unknown, rawResponse: unknown): Promise<FilteredResponse> {
|
||||
// Use LLM to filter/summarize the response
|
||||
const prompt = this.buildFilterPrompt(toolName, originalRequest, rawResponse);
|
||||
const result = await this.providerRegistry.getActiveProvider().complete({
|
||||
systemPrompt: RESPONSE_FILTER_SYSTEM_PROMPT,
|
||||
userPrompt: prompt
|
||||
});
|
||||
return this.parseFilteredResponse(result);
|
||||
}
|
||||
}
|
||||
```
|
||||
2. Create system prompts in `src/mcplocal/src/llm/prompts.ts`:
|
||||
- REQUEST_OPTIMIZATION_SYSTEM_PROMPT: instruct LLM to generate optimal queries
|
||||
- RESPONSE_FILTER_SYSTEM_PROMPT: instruct LLM to extract relevant information
|
||||
3. Integrate into router.ts - wrap tools/call handler:
|
||||
```typescript
|
||||
async handleToolsCall(request: JsonRpcRequest) {
|
||||
if (this.shouldPreprocess(request.params.name)) {
|
||||
const processed = await this.llmProcessor.preprocessRequest(...);
|
||||
// Call mcpd with processed request
|
||||
const rawResponse = await this.callMcpd(processed);
|
||||
const filtered = await this.llmProcessor.filterResponse(...);
|
||||
return filtered;
|
||||
}
|
||||
return this.callMcpd(request.params);
|
||||
}
|
||||
```
|
||||
4. Add configuration options:
|
||||
- `enablePreprocessing`: boolean
|
||||
- `preprocessingExclude`: string[] (tool names to skip)
|
||||
- `preferredProvider`: string (ollama, gemini, deepseek, etc.)
|
||||
5. Add bypass logic for simple operations (list, create, delete)
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Unit test: Request preprocessing generates optimized queries
|
||||
2. Unit test: Response filtering reduces data volume
|
||||
3. Unit test: Bypass logic works for excluded tools
|
||||
4. Integration test: Full pipeline with mock LLM provider
|
||||
5. Test error handling: LLM failure falls back to unfiltered pass-through
|
||||
6. Test configuration options are respected
|
||||
7. Measure: response size reduction percentage
|
||||
61
.taskmaster/tasks/task_030.md
Normal file
61
.taskmaster/tasks/task_030.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# Task ID: 30
|
||||
|
||||
**Title:** Add Gemini CLI LLM provider
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 25 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Implement a new LLM provider that uses the Gemini CLI binary for local, free LLM inference as the preferred provider for pre-processing.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create `src/mcplocal/src/providers/gemini-cli.ts`:
|
||||
```typescript
|
||||
import { spawn } from 'child_process';
|
||||
|
||||
export class GeminiCliProvider implements LlmProvider {
|
||||
readonly name = 'gemini-cli';
|
||||
private binaryPath: string;
|
||||
|
||||
constructor(config: GeminiCliConfig) {
|
||||
this.binaryPath = config.binaryPath || 'gemini';
|
||||
}
|
||||
|
||||
async isAvailable(): Promise<boolean> {
|
||||
// Check if gemini binary exists and is executable
|
||||
try {
|
||||
await this.runCommand(['--version']);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async complete(options: CompletionOptions): Promise<CompletionResult> {
|
||||
const input = this.formatPrompt(options);
|
||||
const output = await this.runCommand(['--prompt', input]);
|
||||
return { content: output, model: 'gemini-cli' };
|
||||
}
|
||||
|
||||
private async runCommand(args: string[]): Promise<string> {
|
||||
// Spawn gemini CLI process and capture output
|
||||
}
|
||||
}
|
||||
```
|
||||
2. Research actual Gemini CLI interface and adjust implementation
|
||||
3. Add to provider registry with high priority (prefer over API providers)
|
||||
4. Add configuration: `geminiCliBinaryPath`
|
||||
5. Handle timeout for slow inference
|
||||
6. Add fallback to next provider if Gemini CLI fails
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Unit test: Provider correctly detects CLI availability
|
||||
2. Unit test: Prompt formatting is correct
|
||||
3. Unit test: Output parsing handles various formats
|
||||
4. Integration test: Full completion with actual Gemini CLI (if available)
|
||||
5. Test timeout handling for slow responses
|
||||
6. Test fallback when CLI is not installed
|
||||
59
.taskmaster/tasks/task_031.md
Normal file
59
.taskmaster/tasks/task_031.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Task ID: 31
|
||||
|
||||
**Title:** Add DeepSeek API LLM provider
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 25 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Implement DeepSeek API provider as a cheap cloud-based fallback when local LLMs are unavailable.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create `src/mcplocal/src/providers/deepseek.ts`:
|
||||
```typescript
|
||||
export class DeepSeekProvider implements LlmProvider {
|
||||
readonly name = 'deepseek';
|
||||
private apiKey: string;
|
||||
private baseUrl = 'https://api.deepseek.com/v1';
|
||||
|
||||
constructor(config: DeepSeekConfig) {
|
||||
this.apiKey = config.apiKey || process.env.DEEPSEEK_API_KEY;
|
||||
}
|
||||
|
||||
async isAvailable(): Promise<boolean> {
|
||||
return !!this.apiKey;
|
||||
}
|
||||
|
||||
async complete(options: CompletionOptions): Promise<CompletionResult> {
|
||||
// DeepSeek uses OpenAI-compatible API
|
||||
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.apiKey}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: 'deepseek-chat',
|
||||
messages: [{ role: 'user', content: options.userPrompt }]
|
||||
})
|
||||
});
|
||||
// Parse and return
|
||||
}
|
||||
}
|
||||
```
|
||||
2. Add DEEPSEEK_API_KEY to configuration
|
||||
3. Register in provider registry with medium priority
|
||||
4. Support both deepseek-chat and deepseek-coder models
|
||||
5. Add rate limiting handling
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Unit test: Provider correctly checks API key availability
|
||||
2. Unit test: Request formatting matches DeepSeek API spec
|
||||
3. Unit test: Response parsing handles all fields
|
||||
4. Integration test: Full completion with actual API (with valid key)
|
||||
5. Test error handling for rate limits
|
||||
6. Test error handling for invalid API key
|
||||
70
.taskmaster/tasks/task_032.md
Normal file
70
.taskmaster/tasks/task_032.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# Task ID: 32
|
||||
|
||||
**Title:** Implement smart context optimization
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 29 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add token counting and decision logic to intelligently skip LLM filtering when responses are small enough, and cache filtering decisions for repeated queries.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create `src/mcplocal/src/llm/token-counter.ts`:
|
||||
```typescript
|
||||
export function estimateTokens(text: string): number {
|
||||
// Simple estimation: ~4 chars per token for English
|
||||
// More accurate: use tiktoken or similar library
|
||||
return Math.ceil(text.length / 4);
|
||||
}
|
||||
```
|
||||
2. Create `src/mcplocal/src/llm/filter-cache.ts`:
|
||||
```typescript
|
||||
export class FilterCache {
|
||||
private cache: LRUCache<string, FilterDecision>;
|
||||
|
||||
shouldFilter(toolName: string, params: unknown, responseSize: number): boolean {
|
||||
const key = this.computeKey(toolName, params);
|
||||
const cached = this.cache.get(key);
|
||||
if (cached) return cached.shouldFilter;
|
||||
// No cache hit - use default threshold logic
|
||||
return responseSize > this.tokenThreshold;
|
||||
}
|
||||
|
||||
recordDecision(toolName: string, params: unknown, decision: FilterDecision): void {
|
||||
const key = this.computeKey(toolName, params);
|
||||
this.cache.set(key, decision);
|
||||
}
|
||||
}
|
||||
```
|
||||
3. Add configuration options:
|
||||
- `tokenThreshold`: number (default 1000 tokens)
|
||||
- `filterCacheSize`: number (default 1000 entries)
|
||||
- `filterCacheTtl`: number (default 3600 seconds)
|
||||
4. Integrate into LlmProcessor:
|
||||
```typescript
|
||||
async filterResponse(...) {
|
||||
const tokens = estimateTokens(JSON.stringify(rawResponse));
|
||||
if (tokens < this.config.tokenThreshold) {
|
||||
// Not worth filtering - return as-is
|
||||
return { filtered: false, response: rawResponse };
|
||||
}
|
||||
// Proceed with LLM filtering
|
||||
}
|
||||
```
|
||||
5. Add metrics tracking:
|
||||
- Total tokens processed
|
||||
- Tokens saved by filtering
|
||||
- Filter cache hit rate
|
||||
- Average latency added by filtering
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Unit test: Token estimation is reasonably accurate
|
||||
2. Unit test: Cache correctly stores and retrieves decisions
|
||||
3. Unit test: Threshold logic skips filtering for small responses
|
||||
4. Unit test: Cache TTL expiration works correctly
|
||||
5. Integration test: Metrics are recorded accurately
|
||||
6. Performance test: Cache improves latency for repeated queries
|
||||
171
.taskmaster/tasks/task_033.md
Normal file
171
.taskmaster/tasks/task_033.md
Normal file
@@ -0,0 +1,171 @@
|
||||
# Task ID: 33
|
||||
|
||||
**Title:** Update mcpctl to use mcplocal as daemon
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 27 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Modify mcpctl CLI to connect to mcplocal instead of mcpd directly, update configuration options, add dual connectivity status checking, and implement authentication commands (login/logout) with secure credential storage.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `src/cli/src/config/schema.ts`:
|
||||
```typescript
|
||||
export interface McpctlConfig {
|
||||
mcplocalUrl: string; // NEW: default 'http://localhost:3200'
|
||||
mcpdUrl: string; // Keep for reference/direct access if needed
|
||||
// ... other fields
|
||||
}
|
||||
```
|
||||
2. Update `src/cli/src/config/defaults.ts`:
|
||||
- Change default daemonUrl to http://localhost:3200 (mcplocal)
|
||||
3. Update `src/cli/src/api-client.ts`:
|
||||
- Default baseUrl now points to mcplocal
|
||||
4. Add new config commands in `src/cli/src/commands/config.ts`:
|
||||
```typescript
|
||||
.command('set-mcplocal-url <url>')
|
||||
.command('set-mcpd-url <url>')
|
||||
.command('get-mcplocal-url')
|
||||
.command('get-mcpd-url')
|
||||
```
|
||||
5. Update `src/cli/src/commands/status.ts` to show both connections and auth status:
|
||||
```
|
||||
$ mcpctl status
|
||||
mcplocal: connected (localhost:3200)
|
||||
mcpd: connected (nas.local:3100) via mcplocal
|
||||
Auth: logged in as user@example.com
|
||||
LLM Provider: ollama (llama3.2)
|
||||
Token savings: 45% (last 24h)
|
||||
```
|
||||
6. Update CLI --daemon-url flag to point to mcplocal
|
||||
7. Add --direct flag to bypass mcplocal and talk to mcpd directly (for debugging)
|
||||
8. Create `src/cli/src/commands/auth.ts` with login/logout commands:
|
||||
- `mcpctl login`: Prompt for mcpd URL (if not configured) and credentials
|
||||
- Call POST /api/v1/auth/login with { email, password }
|
||||
- Store session token in ~/.mcpctl/credentials with 0600 permissions
|
||||
- `mcpctl logout`: Invalidate session and delete stored token
|
||||
9. Create `src/cli/src/auth/credentials.ts` for secure token storage:
|
||||
- Use fs.chmod to set 0600 permissions on credentials file
|
||||
- Token format: { token: string, mcpdUrl: string, user: string, expiresAt?: string }
|
||||
10. Update api-client.ts to include stored token in requests to mcplocal
|
||||
- mcplocal passes this token to mcpd for authentication
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Unit test: Default config points to mcplocal URL
|
||||
2. Unit test: Config commands update correct fields
|
||||
3. Integration test: CLI commands work through mcplocal proxy
|
||||
4. Test status command shows both mcplocal and mcpd status
|
||||
5. Test --direct flag bypasses mcplocal
|
||||
6. Test backward compatibility with existing config files
|
||||
7. Unit test: login command stores token with correct permissions (0600)
|
||||
8. Unit test: logout command removes credentials file
|
||||
9. Integration test: login flow with POST /api/v1/auth/login
|
||||
10. Test status command shows auth status (logged in as user)
|
||||
11. Test token is passed to mcplocal in API requests
|
||||
12. Test invalid credentials return appropriate error message
|
||||
13. Test expired token handling
|
||||
|
||||
## Subtasks
|
||||
|
||||
### 33.1. Update config schema for mcplocal and mcpd URLs
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** None
|
||||
|
||||
Modify McpctlConfigSchema in src/cli/src/config/schema.ts to include separate mcplocalUrl and mcpdUrl fields with appropriate defaults.
|
||||
|
||||
**Details:**
|
||||
|
||||
Update the Zod schema to add mcplocalUrl (default: http://localhost:3200) and mcpdUrl (default: http://localhost:3100). Update DEFAULT_CONFIG and ensure backward compatibility with existing daemonUrl field by mapping it to mcplocalUrl.
|
||||
|
||||
### 33.2. Create auth credentials storage module
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** None
|
||||
|
||||
Create src/cli/src/auth/credentials.ts to handle secure storage and retrieval of session tokens in ~/.mcpctl/credentials.
|
||||
|
||||
**Details:**
|
||||
|
||||
Implement saveCredentials(token, mcpdUrl, user), loadCredentials(), and deleteCredentials() functions. Use fs.chmod to set 0600 permissions. Store JSON format: { token, mcpdUrl, user, expiresAt }. Handle file not found gracefully in loadCredentials.
|
||||
|
||||
### 33.3. Implement login command
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 33.2
|
||||
|
||||
Create src/cli/src/commands/auth.ts with mcpctl login command that prompts for mcpd URL and credentials, calls POST /api/v1/auth/login, and stores the session token.
|
||||
|
||||
**Details:**
|
||||
|
||||
Use inquirer or prompts library for interactive credential input (email, password). If mcpdUrl not configured, prompt for it. Call POST /api/v1/auth/login with credentials. On success, save token using credentials module. Display 'Logged in as {user}' on success. Handle errors (invalid credentials, network errors) with clear messages.
|
||||
|
||||
### 33.4. Implement logout command
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 33.2
|
||||
|
||||
Add mcpctl logout command to auth.ts that invalidates the session and removes stored credentials.
|
||||
|
||||
**Details:**
|
||||
|
||||
Load stored credentials, optionally call a logout endpoint on mcpd to invalidate server-side session, then delete the local credentials file. Display 'Logged out successfully' or 'Not logged in' as appropriate.
|
||||
|
||||
### 33.5. Update api-client to include auth token
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 33.2
|
||||
|
||||
Modify src/cli/src/api-client.ts to load and include stored session token in Authorization header for requests to mcplocal.
|
||||
|
||||
**Details:**
|
||||
|
||||
Import loadCredentials from auth module. Add Authorization: Bearer {token} header to requests when credentials exist. Handle expired token by returning appropriate error suggesting re-login.
|
||||
|
||||
### 33.6. Update status command to show auth status
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 33.2, 33.5
|
||||
|
||||
Modify src/cli/src/commands/status.ts to display authentication status (logged in as user X or not logged in) along with mcplocal and mcpd connectivity.
|
||||
|
||||
**Details:**
|
||||
|
||||
Load credentials and display auth status line: 'Auth: logged in as {user}' or 'Auth: not logged in'. Update status output format to show mcplocal and mcpd status separately with the auth info.
|
||||
|
||||
### 33.7. Add config commands for mcplocal and mcpd URLs
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 33.1
|
||||
|
||||
Add set-mcplocal-url, set-mcpd-url, get-mcplocal-url, and get-mcpd-url commands to src/cli/src/commands/config.ts.
|
||||
|
||||
**Details:**
|
||||
|
||||
Add four new subcommands to the config command for setting and getting the mcplocal and mcpd URLs independently. Update the generic 'set' command to handle these new schema fields.
|
||||
|
||||
### 33.8. Add --direct flag for mcpd bypass
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 33.1, 33.5
|
||||
|
||||
Add --direct flag to CLI commands that bypasses mcplocal and connects directly to mcpd for debugging purposes.
|
||||
|
||||
**Details:**
|
||||
|
||||
Add global --direct option to the main CLI. When set, api-client uses mcpdUrl instead of mcplocalUrl. Useful for debugging connectivity issues between mcplocal and mcpd.
|
||||
|
||||
### 33.9. Register auth commands in CLI entry point
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** 33.3, 33.4
|
||||
|
||||
Import and register the login and logout commands in src/cli/src/index.ts.
|
||||
|
||||
**Details:**
|
||||
|
||||
Import createAuthCommand from commands/auth.ts and add it to the main program with program.addCommand(createAuthCommand()).
|
||||
63
.taskmaster/tasks/task_034.md
Normal file
63
.taskmaster/tasks/task_034.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Task ID: 34
|
||||
|
||||
**Title:** Connect mcplocal MCP router to mcpd proxy endpoint
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 28 ✓, 29 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Update mcplocal's MCP router to forward tool calls to mcpd's new /api/v1/mcp/proxy endpoint instead of connecting to MCP servers directly.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `src/mcplocal/src/router.ts` to use mcpd proxy:
|
||||
```typescript
|
||||
class Router {
|
||||
private mcpdClient: McpdClient;
|
||||
|
||||
async handleToolsCall(request: JsonRpcRequest) {
|
||||
const { name, arguments: args } = request.params;
|
||||
const [serverName, toolName] = name.split('/');
|
||||
|
||||
// Pre-process with LLM if enabled
|
||||
const processedArgs = this.config.enablePreprocessing
|
||||
? await this.llmProcessor.preprocessRequest(toolName, args)
|
||||
: args;
|
||||
|
||||
// Call mcpd proxy endpoint
|
||||
const result = await this.mcpdClient.post('/api/v1/mcp/proxy', {
|
||||
serverId: serverName,
|
||||
method: 'tools/call',
|
||||
params: { name: toolName, arguments: processedArgs }
|
||||
});
|
||||
|
||||
// Post-process response with LLM if enabled
|
||||
return this.config.enablePreprocessing
|
||||
? await this.llmProcessor.filterResponse(toolName, args, result)
|
||||
: result;
|
||||
}
|
||||
}
|
||||
```
|
||||
2. Update upstream configuration:
|
||||
- Remove direct upstream connections for managed servers
|
||||
- Keep option for local/unmanaged upstreams
|
||||
3. Add server discovery from mcpd:
|
||||
```typescript
|
||||
async refreshServerList() {
|
||||
const servers = await this.mcpdClient.get('/api/v1/servers');
|
||||
this.updateAvailableTools(servers);
|
||||
}
|
||||
```
|
||||
4. Handle tools/list by aggregating from mcpd servers
|
||||
5. Handle resources/list and prompts/list similarly
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Unit test: Tool calls are forwarded to mcpd proxy correctly
|
||||
2. Unit test: Server name is extracted from namespaced tool name
|
||||
3. Integration test: Full flow Claude -> mcplocal -> mcpd -> container
|
||||
4. Test tools/list aggregates from all mcpd servers
|
||||
5. Test error handling when mcpd is unreachable
|
||||
6. Test LLM preprocessing is applied when enabled
|
||||
64
.taskmaster/tasks/task_035.md
Normal file
64
.taskmaster/tasks/task_035.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# Task ID: 35
|
||||
|
||||
**Title:** Implement health monitoring across all tiers
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 33 ✓, 34 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Extend health monitoring to track connectivity and status across mcplocal, mcpd, and individual MCP server instances.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update mcplocal health monitor in `src/mcplocal/src/health.ts`:
|
||||
```typescript
|
||||
export class TieredHealthMonitor {
|
||||
async checkHealth(): Promise<TieredHealthStatus> {
|
||||
return {
|
||||
mcplocal: {
|
||||
status: 'healthy',
|
||||
llmProvider: await this.checkLlmProvider(),
|
||||
uptime: process.uptime()
|
||||
},
|
||||
mcpd: await this.checkMcpdHealth(),
|
||||
instances: await this.checkInstancesHealth()
|
||||
};
|
||||
}
|
||||
|
||||
private async checkMcpdHealth(): Promise<McpdHealth> {
|
||||
try {
|
||||
const health = await this.mcpdClient.get('/api/v1/health');
|
||||
return { status: 'connected', ...health };
|
||||
} catch {
|
||||
return { status: 'disconnected' };
|
||||
}
|
||||
}
|
||||
|
||||
private async checkInstancesHealth(): Promise<InstanceHealth[]> {
|
||||
const instances = await this.mcpdClient.get('/api/v1/instances');
|
||||
return instances.map(i => ({
|
||||
name: i.name,
|
||||
status: i.status,
|
||||
lastHealthCheck: i.lastHealthCheck
|
||||
}));
|
||||
}
|
||||
}
|
||||
```
|
||||
2. Add health endpoint to mcplocal HTTP server: `GET /health`
|
||||
3. Update mcpctl status command to display tiered health
|
||||
4. Add degraded state detection:
|
||||
- LLM provider unavailable but mcpd reachable
|
||||
- Some instances down but others healthy
|
||||
5. Add health event notifications for state transitions
|
||||
6. Add configurable health check intervals
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Unit test: Health check correctly identifies all states
|
||||
2. Unit test: Degraded state is detected correctly
|
||||
3. Integration test: Full health check across all tiers
|
||||
4. Test health endpoint returns correct format
|
||||
5. Test mcpctl status displays health correctly
|
||||
6. Test state transition events are emitted
|
||||
58
.taskmaster/tasks/task_036.md
Normal file
58
.taskmaster/tasks/task_036.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# Task ID: 36
|
||||
|
||||
**Title:** End-to-end integration testing
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 29 ✓, 33 ✓, 34 ✓, 35 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create comprehensive integration tests that validate the full data flow from mcpctl through mcplocal to mcpd to MCP server containers and back.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create test fixtures in `src/mcplocal/test/fixtures/`:
|
||||
- Mock MCP server that returns predictable responses
|
||||
- Test configuration files
|
||||
- Sample tool call payloads
|
||||
2. Create integration test suite in `src/mcplocal/test/integration/`:
|
||||
```typescript
|
||||
describe('End-to-end flow', () => {
|
||||
it('mcpctl -> mcplocal -> mcpd -> mcp_server', async () => {
|
||||
// Start mock MCP server
|
||||
// Start mcpd with test config
|
||||
// Start mcplocal pointing to mcpd
|
||||
// Execute mcpctl command
|
||||
// Verify response flows back correctly
|
||||
});
|
||||
|
||||
it('LLM pre-processing reduces response size', async () => {
|
||||
// Send query that returns large dataset
|
||||
// Verify LLM filtering reduces token count
|
||||
// Verify relevant data is preserved
|
||||
});
|
||||
|
||||
it('credentials never leave mcpd', async () => {
|
||||
// Monitor all traffic from mcplocal
|
||||
// Verify no credentials appear in requests/responses
|
||||
});
|
||||
});
|
||||
```
|
||||
3. Test scenarios:
|
||||
- Management commands (get servers, instances, etc.)
|
||||
- MCP tool calls with LLM preprocessing
|
||||
- MCP tool calls without preprocessing
|
||||
- Error handling (mcpd down, instance down, LLM failure)
|
||||
- Health monitoring accuracy
|
||||
4. Add CI integration test workflow
|
||||
5. Create docker-compose.test.yml for test environment
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. All integration tests pass in CI environment
|
||||
2. Test coverage includes happy path and error scenarios
|
||||
3. Performance benchmarks: measure latency at each tier
|
||||
4. Security test: verify credential isolation
|
||||
5. Load test: multiple concurrent requests
|
||||
6. Chaos test: random component failures
|
||||
36
.taskmaster/tasks/task_037.md
Normal file
36
.taskmaster/tasks/task_037.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Task ID: 37
|
||||
|
||||
**Title:** Add priority, summary, chapters, and linkTarget fields to Prompt schema
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Extend the Prisma schema for the Prompt model to include priority (integer 1-10, default 5), summary (nullable string), chapters (nullable JSON array), and linkTarget (nullable string for prompt links).
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/src/db/prisma/schema.prisma` to add fields to the Prompt model:
|
||||
- `priority Int @default(5)` with check constraint 1-10
|
||||
- `summary String? @db.Text`
|
||||
- `chapters Json?` (stored as JSON array of strings)
|
||||
- `linkTarget String?` (format: `project/server:resource-uri`)
|
||||
|
||||
2. Create Prisma migration:
|
||||
```bash
|
||||
pnpm --filter db exec prisma migrate dev --name add-prompt-priority-summary-chapters-link
|
||||
```
|
||||
|
||||
3. Update TypeScript types in shared package to reflect new fields
|
||||
|
||||
4. Add validation for priority range (1-10) at the database level if possible, otherwise enforce in application layer
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Verify migration creates columns with correct types and defaults
|
||||
- Unit test: Verify priority default is 5
|
||||
- Unit test: Verify nullable fields accept null
|
||||
- Unit test: Verify chapters stores/retrieves JSON arrays correctly
|
||||
- Integration test: Create prompt with all new fields, retrieve and verify values
|
||||
35
.taskmaster/tasks/task_038.md
Normal file
35
.taskmaster/tasks/task_038.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Task ID: 38
|
||||
|
||||
**Title:** Add priority field to PromptRequest schema
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 37 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Extend the Prisma schema for the PromptRequest model to include the priority field (integer 1-10, default 5) to match the Prompt model.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/src/db/prisma/schema.prisma` to add to PromptRequest:
|
||||
- `priority Int @default(5)`
|
||||
|
||||
2. Create Prisma migration:
|
||||
```bash
|
||||
pnpm --filter db exec prisma migrate dev --name add-promptrequest-priority
|
||||
```
|
||||
|
||||
3. Update the `CreatePromptRequestSchema` in `/src/mcpd/src/validation/prompt.schema.ts` to include priority validation:
|
||||
```typescript
|
||||
priority: z.number().int().min(1).max(10).default(5).optional(),
|
||||
```
|
||||
|
||||
4. Update TypeScript types in shared package
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Migration creates priority column with default 5
|
||||
- Unit test: PromptRequest creation with explicit priority
|
||||
- Unit test: PromptRequest creation uses default priority when not specified
|
||||
- Unit test: Validation rejects priority outside 1-10 range
|
||||
38
.taskmaster/tasks/task_039.md
Normal file
38
.taskmaster/tasks/task_039.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# Task ID: 39
|
||||
|
||||
**Title:** Add gated field to Project schema
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Extend the Prisma schema for the Project model to include the gated boolean field (default true) that controls whether sessions go through the keyword-driven prompt retrieval flow.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/src/db/prisma/schema.prisma` to add to Project:
|
||||
- `gated Boolean @default(true)`
|
||||
|
||||
2. Create Prisma migration:
|
||||
```bash
|
||||
pnpm --filter db exec prisma migrate dev --name add-project-gated
|
||||
```
|
||||
|
||||
3. Update project-related TypeScript types
|
||||
|
||||
4. Update project validation schemas to include gated field:
|
||||
```typescript
|
||||
gated: z.boolean().default(true).optional(),
|
||||
```
|
||||
|
||||
5. Update project API routes to accept and return the gated field
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Migration creates gated column with default true
|
||||
- Unit test: Project creation with gated=false
|
||||
- Unit test: Project creation uses default gated=true when not specified
|
||||
- Unit test: Project update can toggle gated field
|
||||
- Integration test: GET /api/v1/projects/:name returns gated field
|
||||
49
.taskmaster/tasks/task_040.md
Normal file
49
.taskmaster/tasks/task_040.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Task ID: 40
|
||||
|
||||
**Title:** Update Prompt CRUD API to handle priority and linkTarget
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 37 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Modify prompt API endpoints to accept, validate, and return the priority and linkTarget fields. LinkTarget should be immutable after creation.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/src/mcpd/src/validation/prompt.schema.ts`:
|
||||
```typescript
|
||||
export const CreatePromptSchema = z.object({
|
||||
name: z.string().min(1).max(100).regex(/^[a-z0-9-]+$/),
|
||||
content: z.string().min(1).max(50000),
|
||||
projectId: z.string().optional(),
|
||||
priority: z.number().int().min(1).max(10).default(5).optional(),
|
||||
linkTarget: z.string().regex(/^[a-z0-9-]+\/[a-z0-9-]+:[\S]+$/).optional(),
|
||||
});
|
||||
|
||||
export const UpdatePromptSchema = z.object({
|
||||
content: z.string().min(1).max(50000).optional(),
|
||||
priority: z.number().int().min(1).max(10).optional(),
|
||||
// Note: linkTarget is NOT included - links are immutable
|
||||
});
|
||||
```
|
||||
|
||||
2. Update `/src/mcpd/src/routes/prompts.ts`:
|
||||
- POST /api/v1/prompts: Accept priority, linkTarget
|
||||
- PUT /api/v1/prompts/:id: Accept priority only (not linkTarget)
|
||||
- GET endpoints: Return priority, linkTarget in response
|
||||
|
||||
3. Update repository layer to handle new fields
|
||||
|
||||
4. Add linkTarget format validation: `project/server:resource-uri`
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: POST /api/v1/prompts with priority creates prompt with correct priority
|
||||
- Unit test: POST /api/v1/prompts with linkTarget creates linked prompt
|
||||
- Unit test: PUT /api/v1/prompts/:id with priority updates priority
|
||||
- Unit test: PUT /api/v1/prompts/:id rejects linkTarget (immutable)
|
||||
- Unit test: GET /api/v1/prompts returns priority and linkTarget fields
|
||||
- Unit test: Invalid linkTarget format rejected (validation error)
|
||||
- Unit test: Priority outside 1-10 range rejected
|
||||
42
.taskmaster/tasks/task_041.md
Normal file
42
.taskmaster/tasks/task_041.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# Task ID: 41
|
||||
|
||||
**Title:** Update PromptRequest API to handle priority
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 38 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Modify prompt request API endpoints to accept, validate, and return the priority field for proposed prompts.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update validation in `/src/mcpd/src/validation/prompt.schema.ts`:
|
||||
```typescript
|
||||
export const CreatePromptRequestSchema = z.object({
|
||||
name: z.string().min(1).max(100).regex(/^[a-z0-9-]+$/),
|
||||
content: z.string().min(1).max(50000),
|
||||
projectId: z.string().optional(),
|
||||
createdBySession: z.string().optional(),
|
||||
createdByUserId: z.string().optional(),
|
||||
priority: z.number().int().min(1).max(10).default(5).optional(),
|
||||
});
|
||||
```
|
||||
|
||||
2. Update `/src/mcpd/src/routes/prompts.ts` for PromptRequest endpoints:
|
||||
- POST /api/v1/promptrequests: Accept priority
|
||||
- GET /api/v1/promptrequests: Return priority
|
||||
- POST /api/v1/promptrequests/:id/approve: Preserve priority when creating Prompt
|
||||
|
||||
3. Update PromptService.approve() to copy priority from request to prompt
|
||||
|
||||
4. Update repository layer
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: POST /api/v1/promptrequests with priority creates request with correct priority
|
||||
- Unit test: POST /api/v1/promptrequests uses default priority 5 when not specified
|
||||
- Unit test: GET /api/v1/promptrequests returns priority field
|
||||
- Unit test: Approve preserves priority from request to created prompt
|
||||
- Unit test: Priority validation (1-10 range)
|
||||
58
.taskmaster/tasks/task_042.md
Normal file
58
.taskmaster/tasks/task_042.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# Task ID: 42
|
||||
|
||||
**Title:** Implement prompt summary generation service
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 37 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create a service that auto-generates summary (20 words) and chapters (key sections) for prompts, using fast LLM when available or regex fallback.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create `/src/mcpd/src/services/prompt-summary.service.ts`:
|
||||
```typescript
|
||||
export class PromptSummaryService {
|
||||
constructor(
|
||||
private llmClient: LlmClient | null,
|
||||
private promptRepo: IPromptRepository
|
||||
) {}
|
||||
|
||||
async generateSummary(content: string): Promise<{ summary: string; chapters: string[] }> {
|
||||
if (this.llmClient) {
|
||||
return this.generateWithLlm(content);
|
||||
}
|
||||
return this.generateWithRegex(content);
|
||||
}
|
||||
|
||||
private async generateWithLlm(content: string): Promise<...> {
|
||||
// Send content to fast LLM with prompt:
|
||||
// "Generate a 20-word summary and extract key section topics..."
|
||||
}
|
||||
|
||||
private generateWithRegex(content: string): { summary: string; chapters: string[] } {
|
||||
// summary: first sentence of content (truncated to ~20 words)
|
||||
// chapters: extract markdown headings via regex /^#+\s+(.+)$/gm
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Integrate with PromptService:
|
||||
- Call generateSummary on prompt create
|
||||
- Call generateSummary on prompt update (when content changes)
|
||||
- Cache results on the prompt record
|
||||
|
||||
3. Handle LLM availability check via existing LlmConfig patterns
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: generateWithRegex extracts first sentence as summary
|
||||
- Unit test: generateWithRegex extracts markdown headings as chapters
|
||||
- Unit test: generateWithLlm calls LLM with correct prompt (mock LLM)
|
||||
- Unit test: generateSummary uses LLM when available
|
||||
- Unit test: generateSummary falls back to regex when no LLM
|
||||
- Unit test: Empty content handled gracefully
|
||||
- Unit test: Content without headings returns empty chapters array
|
||||
- Integration test: Creating prompt triggers summary generation
|
||||
41
.taskmaster/tasks/task_043.md
Normal file
41
.taskmaster/tasks/task_043.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Task ID: 43
|
||||
|
||||
**Title:** Add regenerate-summary API endpoint
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 42 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Create POST /api/v1/prompts/:id/regenerate-summary endpoint to force re-generation of summary and chapters for a prompt.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add route in `/src/mcpd/src/routes/prompts.ts`:
|
||||
```typescript
|
||||
fastify.post('/api/v1/prompts/:id/regenerate-summary', async (request, reply) => {
|
||||
const { id } = request.params as { id: string };
|
||||
const prompt = await promptService.findById(id);
|
||||
if (!prompt) {
|
||||
return reply.status(404).send({ error: 'Prompt not found' });
|
||||
}
|
||||
|
||||
const { summary, chapters } = await summaryService.generateSummary(prompt.content);
|
||||
const updated = await promptService.updateSummary(id, summary, chapters);
|
||||
|
||||
return reply.send(updated);
|
||||
});
|
||||
```
|
||||
|
||||
2. Add `updateSummary(id, summary, chapters)` method to PromptRepository and PromptService
|
||||
|
||||
3. Return the updated prompt with new summary/chapters in response
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: POST to valid prompt ID regenerates summary
|
||||
- Unit test: Returns updated prompt with new summary/chapters
|
||||
- Unit test: 404 for non-existent prompt ID
|
||||
- Unit test: Uses LLM when available, regex fallback otherwise
|
||||
- Integration test: End-to-end regeneration updates database
|
||||
48
.taskmaster/tasks/task_044.md
Normal file
48
.taskmaster/tasks/task_044.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# Task ID: 44
|
||||
|
||||
**Title:** Create prompt-index API endpoint
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 42 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Create GET /api/v1/projects/:name/prompt-index endpoint that returns a compact index of prompts (name, priority, summary, chapters) for a project.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add route in `/src/mcpd/src/routes/prompts.ts`:
|
||||
```typescript
|
||||
fastify.get('/api/v1/projects/:name/prompt-index', async (request, reply) => {
|
||||
const { name } = request.params as { name: string };
|
||||
const project = await projectService.findByName(name);
|
||||
if (!project) {
|
||||
return reply.status(404).send({ error: 'Project not found' });
|
||||
}
|
||||
|
||||
const prompts = await promptService.findByProject(project.id);
|
||||
const index = prompts.map(p => ({
|
||||
name: p.name,
|
||||
priority: p.priority,
|
||||
summary: p.summary,
|
||||
chapters: p.chapters,
|
||||
linkTarget: p.linkTarget,
|
||||
}));
|
||||
|
||||
return reply.send({ prompts: index });
|
||||
});
|
||||
```
|
||||
|
||||
2. Consider adding global prompts to the index (inherited by all projects)
|
||||
|
||||
3. Sort by priority descending in response
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Returns compact index for valid project
|
||||
- Unit test: Index contains name, priority, summary, chapters, linkTarget
|
||||
- Unit test: 404 for non-existent project
|
||||
- Unit test: Empty array for project with no prompts
|
||||
- Unit test: Results sorted by priority descending
|
||||
- Integration test: End-to-end retrieval matches database state
|
||||
73
.taskmaster/tasks/task_045.md
Normal file
73
.taskmaster/tasks/task_045.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# Task ID: 45
|
||||
|
||||
**Title:** Implement tag-matching algorithm for prompt selection
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 44 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create a deterministic keyword-based tag matching algorithm as the no-LLM fallback for prompt selection, with byte-budget allocation and priority weighting.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create `/src/mcplocal/src/services/tag-matcher.service.ts`:
|
||||
```typescript
|
||||
interface MatchedPrompt {
|
||||
prompt: PromptIndex;
|
||||
score: number;
|
||||
matchedTags: string[];
|
||||
}
|
||||
|
||||
export class TagMatcherService {
|
||||
constructor(private byteBudget: number = 8192) {}
|
||||
|
||||
matchPrompts(tags: string[], promptIndex: PromptIndex[]): {
|
||||
fullContent: PromptIndex[]; // Prompts to include in full
|
||||
indexOnly: PromptIndex[]; // Prompts to include as index entries
|
||||
remaining: PromptIndex[]; // Non-matched prompts (names only)
|
||||
} {
|
||||
// 1. Priority 10 prompts: always included (score = Infinity)
|
||||
// 2. For each prompt, compute score:
|
||||
// - Check tags against summary + chapters (case-insensitive substring)
|
||||
// - score = matching_tags_count * priority
|
||||
// 3. Sort by score descending
|
||||
// 4. Fill byte budget from top:
|
||||
// - Include full content until budget exhausted
|
||||
// - Remaining matched: include as index entries
|
||||
// - Non-matched: names only
|
||||
}
|
||||
|
||||
private computeScore(tags: string[], prompt: PromptIndex): number {
|
||||
if (prompt.priority === 10) return Infinity;
|
||||
const matchingTags = tags.filter(tag =>
|
||||
this.matchesPrompt(tag.toLowerCase(), prompt)
|
||||
);
|
||||
return matchingTags.length * prompt.priority;
|
||||
}
|
||||
|
||||
private matchesPrompt(tag: string, prompt: PromptIndex): boolean {
|
||||
const searchText = [
|
||||
prompt.summary || '',
|
||||
...(prompt.chapters || [])
|
||||
].join(' ').toLowerCase();
|
||||
return searchText.includes(tag);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Handle edge cases: empty tags, no prompts, all priority 10, etc.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Priority 10 prompts always included regardless of tags
|
||||
- Unit test: Score calculation: matching_tags * priority
|
||||
- Unit test: Case-insensitive matching
|
||||
- Unit test: Substring matching in summary and chapters
|
||||
- Unit test: Byte budget exhaustion stops full content inclusion
|
||||
- Unit test: Matched prompts beyond budget become index entries
|
||||
- Unit test: Non-matched prompts listed as names only
|
||||
- Unit test: Sorting by score descending
|
||||
- Unit test: Empty tags returns priority 10 only
|
||||
- Unit test: No prompts returns empty result
|
||||
59
.taskmaster/tasks/task_046.md
Normal file
59
.taskmaster/tasks/task_046.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Task ID: 46
|
||||
|
||||
**Title:** Implement LLM-based prompt selection service
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 45 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create a service that uses the heavy LLM to intelligently select relevant prompts based on tags and the full prompt index, understanding synonyms and context.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create `/src/mcplocal/src/services/llm-prompt-selector.service.ts`:
|
||||
```typescript
|
||||
export class LlmPromptSelectorService {
|
||||
constructor(
|
||||
private llmClient: LlmClient,
|
||||
private fastLlmClient: LlmClient | null,
|
||||
private tagMatcher: TagMatcherService // fallback
|
||||
) {}
|
||||
|
||||
async selectPrompts(tags: string[], promptIndex: PromptIndex[]): Promise<{
|
||||
selected: Array<{ name: string; reason: string }>;
|
||||
priority10: PromptIndex[]; // Always included
|
||||
}> {
|
||||
// 1. Extract priority 10 prompts (always included)
|
||||
// 2. Generate missing summaries using fast LLM if needed
|
||||
// 3. Send to heavy LLM:
|
||||
const prompt = `
|
||||
Given these keywords: ${tags.join(', ')}
|
||||
And this prompt index:
|
||||
${promptIndex.map(p => `- ${p.name}: ${p.summary}`).join('\n')}
|
||||
|
||||
Select the most relevant prompts for someone working on tasks
|
||||
related to these keywords. Consider synonyms and related concepts.
|
||||
Return a ranked JSON array: [{name: string, reason: string}]
|
||||
`;
|
||||
// 4. Parse LLM response
|
||||
// 5. On LLM error, fall back to tag matcher
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Handle LLM timeouts and errors gracefully with fallback
|
||||
|
||||
3. Validate LLM response format
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Priority 10 prompts always returned regardless of LLM selection
|
||||
- Unit test: LLM called with correct prompt format (mock)
|
||||
- Unit test: LLM response parsed correctly
|
||||
- Unit test: Invalid LLM response falls back to tag matcher
|
||||
- Unit test: LLM timeout falls back to tag matcher
|
||||
- Unit test: Missing summaries trigger fast LLM generation
|
||||
- Unit test: No LLM available uses tag matcher directly
|
||||
- Integration test: End-to-end selection with mock LLM
|
||||
61
.taskmaster/tasks/task_047.md
Normal file
61
.taskmaster/tasks/task_047.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# Task ID: 47
|
||||
|
||||
**Title:** Implement session state management for gating
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 39 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Extend the McpRouter to track per-session gating state including gated status, accumulated tags, and retrieved prompts set.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/src/mcplocal/src/router.ts` to add session state:
|
||||
```typescript
|
||||
interface SessionState {
|
||||
gated: boolean; // starts true if project is gated
|
||||
tags: string[]; // accumulated from begin_session + read_prompts
|
||||
retrievedPrompts: Set<string>; // prompts already sent (avoid duplicates)
|
||||
}
|
||||
|
||||
export class McpRouter {
|
||||
private sessionStates: Map<string, SessionState> = new Map();
|
||||
|
||||
getSessionState(sessionId: string): SessionState {
|
||||
if (!this.sessionStates.has(sessionId)) {
|
||||
this.sessionStates.set(sessionId, {
|
||||
gated: this.projectConfig?.gated ?? true,
|
||||
tags: [],
|
||||
retrievedPrompts: new Set(),
|
||||
});
|
||||
}
|
||||
return this.sessionStates.get(sessionId)!;
|
||||
}
|
||||
|
||||
ungateSession(sessionId: string): void {
|
||||
const state = this.getSessionState(sessionId);
|
||||
state.gated = false;
|
||||
}
|
||||
|
||||
addRetrievedPrompts(sessionId: string, names: string[]): void {
|
||||
const state = this.getSessionState(sessionId);
|
||||
names.forEach(n => state.retrievedPrompts.add(n));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Clean up session state when session closes
|
||||
|
||||
3. Handle session state for non-gated projects (gated=false from start)
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: New session starts with gated=true for gated project
|
||||
- Unit test: New session starts with gated=false for non-gated project
|
||||
- Unit test: ungateSession changes gated to false
|
||||
- Unit test: addRetrievedPrompts adds to set
|
||||
- Unit test: retrievedPrompts prevents duplicates
|
||||
- Unit test: Session state isolated per sessionId
|
||||
- Unit test: Session cleanup removes state
|
||||
67
.taskmaster/tasks/task_048.md
Normal file
67
.taskmaster/tasks/task_048.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Task ID: 48
|
||||
|
||||
**Title:** Implement begin_session tool for gated sessions
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 46 ✓, 47 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the begin_session MCP tool that accepts 5 keywords, triggers prompt selection, returns matched content with encouragement, and ungates the session.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add begin_session tool definition in `/src/mcplocal/src/router.ts`:
|
||||
```typescript
|
||||
private getBeginSessionTool(): Tool {
|
||||
return {
|
||||
name: 'begin_session',
|
||||
description: 'Start your session by providing 5 keywords that describe your current task. You\'ll receive relevant project context, policies, and guidelines. Required before using other tools.',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
tags: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
maxItems: 10,
|
||||
description: '5 keywords describing your current task'
|
||||
}
|
||||
},
|
||||
required: ['tags']
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
2. Implement begin_session handler:
|
||||
- Validate tags array (1-10 items)
|
||||
- Call LlmPromptSelector or TagMatcher based on LLM availability
|
||||
- Fetch full content for selected prompts
|
||||
- Build response with matched content + index + encouragement
|
||||
- Ungate session
|
||||
- Send `notifications/tools/list_changed`
|
||||
|
||||
3. Response format:
|
||||
```
|
||||
[Priority 10 prompts - full content]
|
||||
|
||||
[Tag-matched prompts - full content, priority-ordered]
|
||||
|
||||
Other prompts available that may become relevant...
|
||||
- name: summary
|
||||
...
|
||||
If any seem related, request them with read_prompts({ tags: [...] }).
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: begin_session with valid tags returns matched prompts
|
||||
- Unit test: begin_session includes priority 10 prompts always
|
||||
- Unit test: begin_session response includes encouragement text
|
||||
- Unit test: begin_session response includes prompt index
|
||||
- Unit test: Session ungated after successful begin_session
|
||||
- Unit test: notifications/tools/list_changed sent after ungating
|
||||
- Unit test: Empty tags handled (returns priority 10 only)
|
||||
- Unit test: Invalid tags rejected with error
|
||||
- Unit test: begin_session while already ungated returns error
|
||||
58
.taskmaster/tasks/task_049.md
Normal file
58
.taskmaster/tasks/task_049.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# Task ID: 49
|
||||
|
||||
**Title:** Implement read_prompts tool for ongoing retrieval
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 48 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the read_prompts MCP tool that allows clients to request additional context by keywords after the session is ungated.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add read_prompts tool definition:
|
||||
```typescript
|
||||
private getReadPromptsTool(): Tool {
|
||||
return {
|
||||
name: 'read_prompts',
|
||||
description: 'Request additional project context by keywords. Use this whenever you need guidelines, policies, or conventions related to your current work.',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
tags: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
description: 'Keywords describing what context you need'
|
||||
}
|
||||
},
|
||||
required: ['tags']
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
2. Implement read_prompts handler:
|
||||
- Always use keyword matching (not LLM) for precision
|
||||
- Exclude already-retrieved prompts from response
|
||||
- Add newly retrieved prompts to session state
|
||||
- Include reminder about more prompts available
|
||||
|
||||
3. Response format:
|
||||
```
|
||||
[Matched prompt content - deduplicated]
|
||||
|
||||
Remember: you can request more prompts at any time with read_prompts({ tags: [...] }).
|
||||
The project may have additional guidelines relevant to your current approach.
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: read_prompts returns matched prompts by keyword
|
||||
- Unit test: Already retrieved prompts excluded from response
|
||||
- Unit test: Newly retrieved prompts added to session state
|
||||
- Unit test: Response includes reminder text
|
||||
- Unit test: read_prompts while gated returns error
|
||||
- Unit test: Empty tags returns empty response
|
||||
- Unit test: Uses keyword matching not LLM
|
||||
55
.taskmaster/tasks/task_050.md
Normal file
55
.taskmaster/tasks/task_050.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# Task ID: 50
|
||||
|
||||
**Title:** Implement progressive tool exposure for gated sessions
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 48 ✓, 49 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Modify tools/list behavior to only expose begin_session while gated, and expose all tools plus read_prompts after ungating.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update tools/list handling in `/src/mcplocal/src/router.ts`:
|
||||
```typescript
|
||||
async handleToolsList(sessionId: string): Promise<Tool[]> {
|
||||
const state = this.getSessionState(sessionId);
|
||||
|
||||
if (state.gated) {
|
||||
// Only show begin_session while gated
|
||||
return [this.getBeginSessionTool()];
|
||||
}
|
||||
|
||||
// After ungating: all upstream tools + read_prompts
|
||||
const upstreamTools = await this.discoverTools();
|
||||
return [...upstreamTools, this.getReadPromptsTool()];
|
||||
}
|
||||
```
|
||||
|
||||
2. Block direct tool calls while gated:
|
||||
```typescript
|
||||
async handleToolCall(sessionId: string, toolName: string, args: any): Promise<any> {
|
||||
const state = this.getSessionState(sessionId);
|
||||
|
||||
if (state.gated && toolName !== 'begin_session') {
|
||||
// Intercept: extract keywords, match prompts, inject briefing
|
||||
return this.handleInterceptedCall(sessionId, toolName, args);
|
||||
}
|
||||
|
||||
// Normal routing
|
||||
return this.routeToolCall(toolName, args);
|
||||
}
|
||||
```
|
||||
|
||||
3. Ensure notifications/tools/list_changed is sent after ungating
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: tools/list while gated returns only begin_session
|
||||
- Unit test: tools/list after ungating returns all tools + read_prompts
|
||||
- Unit test: begin_session not visible after ungating
|
||||
- Unit test: Tool call while gated (not begin_session) triggers intercept
|
||||
- Unit test: Tool call after ungating routes normally
|
||||
- Unit test: notifications/tools/list_changed sent on ungate
|
||||
54
.taskmaster/tasks/task_051.md
Normal file
54
.taskmaster/tasks/task_051.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Task ID: 51
|
||||
|
||||
**Title:** Implement keyword extraction from tool calls
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Create a service that extracts keywords from tool names and arguments for the intercept fallback path when clients skip begin_session.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create `/src/mcplocal/src/services/keyword-extractor.service.ts`:
|
||||
```typescript
|
||||
export class KeywordExtractorService {
|
||||
extractKeywords(toolName: string, args: Record<string, any>): string[] {
|
||||
const keywords: string[] = [];
|
||||
|
||||
// Extract from tool name (split on / and -)
|
||||
// e.g., "home-assistant/get_entities" -> ["home", "assistant", "get", "entities"]
|
||||
keywords.push(...this.extractFromName(toolName));
|
||||
|
||||
// Extract from argument values
|
||||
// e.g., { domain: "light", entity_id: "light.kitchen" } -> ["light", "kitchen"]
|
||||
keywords.push(...this.extractFromArgs(args));
|
||||
|
||||
// Deduplicate and sanitize
|
||||
return [...new Set(keywords.map(k => this.sanitize(k)))];
|
||||
}
|
||||
|
||||
private sanitize(keyword: string): string {
|
||||
// Remove special characters, lowercase, limit length
|
||||
return keyword.toLowerCase().replace(/[^a-z0-9]/g, '').slice(0, 50);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Handle various argument types: strings, arrays, nested objects
|
||||
|
||||
3. Prevent injection by sanitizing extracted keywords
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Extracts keywords from tool name with /
|
||||
- Unit test: Extracts keywords from tool name with -
|
||||
- Unit test: Extracts keywords from string argument values
|
||||
- Unit test: Extracts keywords from array argument values
|
||||
- Unit test: Handles nested object arguments
|
||||
- Unit test: Sanitizes special characters
|
||||
- Unit test: Deduplicates keywords
|
||||
- Unit test: Handles empty arguments
|
||||
- Unit test: Limits keyword length to prevent abuse
|
||||
63
.taskmaster/tasks/task_052.md
Normal file
63
.taskmaster/tasks/task_052.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Task ID: 52
|
||||
|
||||
**Title:** Implement tool call intercept with briefing injection
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 50 ✓, 51 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** When a gated session calls a tool without first calling begin_session, intercept the call, extract keywords, match prompts, and inject the briefing alongside the real tool result.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Implement handleInterceptedCall in `/src/mcplocal/src/router.ts`:
|
||||
```typescript
|
||||
async handleInterceptedCall(
|
||||
sessionId: string,
|
||||
toolName: string,
|
||||
args: any
|
||||
): Promise<ToolResult> {
|
||||
// 1. Extract keywords from tool call
|
||||
const keywords = this.keywordExtractor.extractKeywords(toolName, args);
|
||||
|
||||
// 2. Match prompts using keywords
|
||||
const { fullContent, indexOnly, remaining } =
|
||||
await this.promptSelector.selectPrompts(keywords, this.promptIndex);
|
||||
|
||||
// 3. Execute the actual tool call
|
||||
const actualResult = await this.routeToolCall(toolName, args);
|
||||
|
||||
// 4. Build briefing with intercept preamble
|
||||
const briefing = this.buildBriefing(fullContent, indexOnly, remaining, 'intercept');
|
||||
|
||||
// 5. Ungate session
|
||||
this.ungateSession(sessionId);
|
||||
|
||||
// 6. Send notifications/tools/list_changed
|
||||
await this.sendToolsListChanged();
|
||||
|
||||
// 7. Return combined result
|
||||
return {
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: `${briefing}\n\n---\n\n${actualResult.content[0].text}`
|
||||
}]
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
2. Use gate-intercept-preamble system prompt for the briefing prefix
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Tool call while gated triggers intercept
|
||||
- Unit test: Keywords extracted from tool name and args
|
||||
- Unit test: Prompts matched using extracted keywords
|
||||
- Unit test: Actual tool still executes and returns result
|
||||
- Unit test: Briefing prepended to tool result
|
||||
- Unit test: Session ungated after intercept
|
||||
- Unit test: notifications/tools/list_changed sent
|
||||
- Unit test: Intercept preamble included in briefing
|
||||
- Integration test: End-to-end intercept flow
|
||||
54
.taskmaster/tasks/task_053.md
Normal file
54
.taskmaster/tasks/task_053.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Task ID: 53
|
||||
|
||||
**Title:** Add prompt index to initialize instructions
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 47 ✓, 44 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Modify the initialize handler to include the compact prompt index and gate message in instructions for gated projects.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update initialize handling in `/src/mcplocal/src/router.ts`:
|
||||
```typescript
|
||||
async handleInitialize(sessionId: string): Promise<InitializeResult> {
|
||||
const state = this.getSessionState(sessionId);
|
||||
|
||||
let instructions = this.projectConfig.prompt || '';
|
||||
|
||||
if (state.gated) {
|
||||
// Add gate instructions
|
||||
const gateInstructions = await this.getSystemPrompt('gate-instructions');
|
||||
|
||||
// Build prompt index (cap at 50, priority 7+ if over)
|
||||
const index = this.buildPromptIndex();
|
||||
|
||||
instructions += `\n\n${gateInstructions.replace('{{prompt_index}}', index)}`;
|
||||
}
|
||||
|
||||
return {
|
||||
protocolVersion: '2024-11-05',
|
||||
capabilities: { ... },
|
||||
serverInfo: { ... },
|
||||
instructions,
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
2. Build prompt index with cap:
|
||||
- If <= 50 prompts: include all
|
||||
- If > 50 prompts: include only priority 7+
|
||||
- Format: `- <name>: <summary>` (~100 chars per entry)
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Gated project includes gate instructions in initialize
|
||||
- Unit test: Prompt index included in instructions
|
||||
- Unit test: Index capped at 50 entries
|
||||
- Unit test: Over 50 prompts shows priority 7+ only
|
||||
- Unit test: Non-gated project skips gate instructions
|
||||
- Unit test: {{prompt_index}} template replaced
|
||||
- Integration test: End-to-end initialize with gated project
|
||||
58
.taskmaster/tasks/task_054.md
Normal file
58
.taskmaster/tasks/task_054.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# Task ID: 54
|
||||
|
||||
**Title:** Create mcpctl-system project with system prompts
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 40 ✓, 39 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Implement bootstrap logic to create the mcpctl-system project and its required system prompts on first startup, with protection against deletion.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create seed migration or startup hook:
|
||||
```typescript
|
||||
async function bootstrapSystemProject() {
|
||||
const systemProject = await projectRepo.findByName('mcpctl-system');
|
||||
if (systemProject) return; // Already exists
|
||||
|
||||
// Create mcpctl-system project
|
||||
const project = await projectRepo.create({
|
||||
name: 'mcpctl-system',
|
||||
description: 'System prompts for mcpctl gating and encouragement',
|
||||
gated: false, // System project is not gated
|
||||
ownerId: SYSTEM_USER_ID,
|
||||
});
|
||||
|
||||
// Create required system prompts
|
||||
const systemPrompts = [
|
||||
{ name: 'gate-instructions', priority: 10, content: GATE_INSTRUCTIONS },
|
||||
{ name: 'gate-encouragement', priority: 10, content: GATE_ENCOURAGEMENT },
|
||||
{ name: 'read-prompts-reminder', priority: 10, content: READ_PROMPTS_REMINDER },
|
||||
{ name: 'gate-intercept-preamble', priority: 10, content: GATE_INTERCEPT_PREAMBLE },
|
||||
{ name: 'session-greeting', priority: 10, content: SESSION_GREETING },
|
||||
];
|
||||
|
||||
for (const p of systemPrompts) {
|
||||
await promptRepo.create({ ...p, projectId: project.id });
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Add delete protection in prompt delete endpoint:
|
||||
- Check if prompt belongs to mcpctl-system
|
||||
- Return 403 error if attempting to delete system prompt
|
||||
|
||||
3. Define default content for each system prompt per PRD
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: System project created on first startup
|
||||
- Unit test: All 5 system prompts created
|
||||
- Unit test: Subsequent startups don't duplicate
|
||||
- Unit test: Delete system prompt returns 403
|
||||
- Unit test: System prompts have priority 10
|
||||
- Unit test: mcpctl-system project has gated=false
|
||||
- Integration test: End-to-end bootstrap flow
|
||||
61
.taskmaster/tasks/task_055.md
Normal file
61
.taskmaster/tasks/task_055.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# Task ID: 55
|
||||
|
||||
**Title:** Implement system prompt fetching and caching in mcplocal
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 54 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Add functionality to mcplocal router to fetch system prompts from mcpd and cache them with 60s TTL, supporting template variable replacement.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add system prompt fetching in `/src/mcplocal/src/router.ts`:
|
||||
```typescript
|
||||
private systemPromptCache: Map<string, { content: string; expiresAt: number }> = new Map();
|
||||
|
||||
async getSystemPrompt(name: string): Promise<string> {
|
||||
const cached = this.systemPromptCache.get(name);
|
||||
if (cached && cached.expiresAt > Date.now()) {
|
||||
return cached.content;
|
||||
}
|
||||
|
||||
const prompts = await this.mcpdClient.fetch(
|
||||
'/api/v1/projects/mcpctl-system/prompts/visible'
|
||||
);
|
||||
const prompt = prompts.find(p => p.name === name);
|
||||
if (!prompt) {
|
||||
throw new Error(`System prompt not found: ${name}`);
|
||||
}
|
||||
|
||||
this.systemPromptCache.set(name, {
|
||||
content: prompt.content,
|
||||
expiresAt: Date.now() + 60000, // 60s TTL
|
||||
});
|
||||
|
||||
return prompt.content;
|
||||
}
|
||||
```
|
||||
|
||||
2. Add template variable replacement:
|
||||
```typescript
|
||||
replaceTemplateVariables(content: string, vars: Record<string, string>): string {
|
||||
return content
|
||||
.replace(/\{\{prompt_index\}\}/g, vars.prompt_index || '')
|
||||
.replace(/\{\{project_name\}\}/g, vars.project_name || '')
|
||||
.replace(/\{\{matched_prompts\}\}/g, vars.matched_prompts || '')
|
||||
.replace(/\{\{remaining_prompts\}\}/g, vars.remaining_prompts || '');
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: System prompt fetched from mcpd
|
||||
- Unit test: Cached prompt returned within TTL
|
||||
- Unit test: Cache miss triggers fresh fetch
|
||||
- Unit test: Missing system prompt throws error
|
||||
- Unit test: Template variables replaced correctly
|
||||
- Unit test: Unknown template variables left as-is
|
||||
- Integration test: End-to-end fetch and cache
|
||||
67
.taskmaster/tasks/task_056.md
Normal file
67
.taskmaster/tasks/task_056.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Task ID: 56
|
||||
|
||||
**Title:** Implement prompt link resolution service
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 40 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Create a service that fetches linked prompt content from source MCP servers using the project's service account, with dead link detection.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Create `/src/mcplocal/src/services/link-resolver.service.ts`:
|
||||
```typescript
|
||||
export class LinkResolverService {
|
||||
constructor(private mcpdClient: McpdClient) {}
|
||||
|
||||
async resolveLink(linkTarget: string): Promise<{
|
||||
content: string | null;
|
||||
status: 'alive' | 'dead' | 'unknown';
|
||||
error?: string;
|
||||
}> {
|
||||
// Parse linkTarget: project/server:resource-uri
|
||||
const { project, server, uri } = this.parseLink(linkTarget);
|
||||
|
||||
try {
|
||||
// Use service account for source project
|
||||
const content = await this.fetchResource(project, server, uri);
|
||||
return { content, status: 'alive' };
|
||||
} catch (error) {
|
||||
this.logDeadLink(linkTarget, error);
|
||||
return {
|
||||
content: null,
|
||||
status: 'dead',
|
||||
error: error.message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private parseLink(linkTarget: string): { project: string; server: string; uri: string } {
|
||||
const match = linkTarget.match(/^([^/]+)\/([^:]+):(.+)$/);
|
||||
if (!match) throw new Error('Invalid link format');
|
||||
return { project: match[1], server: match[2], uri: match[3] };
|
||||
}
|
||||
|
||||
private async fetchResource(project: string, server: string, uri: string): Promise<string> {
|
||||
// Call mcpd to fetch resource via service account
|
||||
// mcpd routes to the source project's MCP server
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Log dead links as errors
|
||||
|
||||
3. Cache resolution results
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Valid link parsed correctly
|
||||
- Unit test: Invalid link format throws error
|
||||
- Unit test: Successful resolution returns content and status='alive'
|
||||
- Unit test: Failed resolution returns status='dead' with error
|
||||
- Unit test: Dead link logged as error
|
||||
- Unit test: Service account header included in request
|
||||
- Integration test: End-to-end link resolution
|
||||
50
.taskmaster/tasks/task_057.md
Normal file
50
.taskmaster/tasks/task_057.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# Task ID: 57
|
||||
|
||||
**Title:** Add linkStatus to prompt GET responses
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 56 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Modify the GET /api/v1/prompts endpoint to include linkStatus (alive/dead/unknown) for linked prompts by checking link health.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/src/mcpd/src/routes/prompts.ts` GET endpoint:
|
||||
```typescript
|
||||
fastify.get('/api/v1/prompts', async (request, reply) => {
|
||||
const prompts = await promptService.findAll(filter);
|
||||
|
||||
// Check link status for linked prompts
|
||||
const promptsWithStatus = await Promise.all(
|
||||
prompts.map(async (p) => {
|
||||
if (!p.linkTarget) {
|
||||
return { ...p, linkStatus: null };
|
||||
}
|
||||
const status = await linkResolver.checkLinkHealth(p.linkTarget);
|
||||
return { ...p, linkStatus: status };
|
||||
})
|
||||
);
|
||||
|
||||
return reply.send(promptsWithStatus);
|
||||
});
|
||||
```
|
||||
|
||||
2. Consider caching link health to avoid repeated checks
|
||||
|
||||
3. Add `linkStatus` field to prompt response schema:
|
||||
- `null` for non-linked prompts
|
||||
- `'alive'` for working links
|
||||
- `'dead'` for broken links
|
||||
- `'unknown'` for unchecked links
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Non-linked prompt has linkStatus=null
|
||||
- Unit test: Linked prompt with working link has linkStatus='alive'
|
||||
- Unit test: Linked prompt with broken link has linkStatus='dead'
|
||||
- Unit test: Link health cached to avoid repeated checks
|
||||
- Unit test: All prompts in response have linkStatus field
|
||||
- Integration test: End-to-end GET with linked prompts
|
||||
55
.taskmaster/tasks/task_058.md
Normal file
55
.taskmaster/tasks/task_058.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# Task ID: 58
|
||||
|
||||
**Title:** Add RBAC for prompt link creation
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 56 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Implement RBAC checks requiring edit permission on the target project to create prompt links, and auto-create service account permission on the source project.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update prompt creation in `/src/mcpd/src/services/prompt.service.ts`:
|
||||
```typescript
|
||||
async createPrompt(data: CreatePromptInput, userId: string): Promise<Prompt> {
|
||||
if (data.linkTarget) {
|
||||
// Verify user has edit permission on target project RBAC
|
||||
const hasPermission = await this.rbacService.checkPermission(
|
||||
userId, data.projectId, 'edit'
|
||||
);
|
||||
if (!hasPermission) {
|
||||
throw new ForbiddenError('Edit permission required to create prompt links');
|
||||
}
|
||||
|
||||
// Parse link target
|
||||
const { project: sourceProject, server, uri } = this.parseLink(data.linkTarget);
|
||||
|
||||
// Create service account permission on source project
|
||||
await this.rbacService.createServiceAccountPermission(
|
||||
data.projectId, // target project
|
||||
sourceProject, // source project
|
||||
server,
|
||||
uri,
|
||||
'read'
|
||||
);
|
||||
}
|
||||
|
||||
return this.promptRepo.create(data);
|
||||
}
|
||||
```
|
||||
|
||||
2. Clean up service account permission when link is deleted
|
||||
|
||||
3. Handle permission denied from source project
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Link creation requires edit permission
|
||||
- Unit test: Link creation without permission throws 403
|
||||
- Unit test: Service account permission created on source project
|
||||
- Unit test: Service account permission deleted when link deleted
|
||||
- Unit test: Non-link prompts skip RBAC checks
|
||||
- Integration test: End-to-end link creation with RBAC
|
||||
64
.taskmaster/tasks/task_059.md
Normal file
64
.taskmaster/tasks/task_059.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# Task ID: 59
|
||||
|
||||
**Title:** Update CLI create prompt command for priority and link
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 40 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Extend the mcpctl create prompt command to accept --priority (1-10) and --link (project/server:uri) flags.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/src/cli/src/commands/create.ts` for prompt:
|
||||
```typescript
|
||||
.command('prompt <name>')
|
||||
.description('Create a new prompt')
|
||||
.option('-p, --project <name>', 'Project to create prompt in')
|
||||
.option('--priority <number>', 'Priority level (1-10, default: 5)', '5')
|
||||
.option('--link <target>', 'Link to MCP resource (project/server:uri)')
|
||||
.option('-f, --file <path>', 'Read content from file')
|
||||
.action(async (name, options) => {
|
||||
const priority = parseInt(options.priority, 10);
|
||||
if (priority < 1 || priority > 10) {
|
||||
console.error('Priority must be between 1 and 10');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let content = '';
|
||||
if (options.link) {
|
||||
// Linked prompts don't need content (fetched from source)
|
||||
content = `[Link: ${options.link}]`;
|
||||
} else if (options.file) {
|
||||
content = await fs.readFile(options.file, 'utf-8');
|
||||
} else {
|
||||
content = await promptForContent();
|
||||
}
|
||||
|
||||
const body = {
|
||||
name,
|
||||
content,
|
||||
projectId: options.project,
|
||||
priority,
|
||||
linkTarget: options.link,
|
||||
};
|
||||
|
||||
await api.post('/api/v1/prompts', body);
|
||||
});
|
||||
```
|
||||
|
||||
2. Validate link format: `project/server:resource-uri`
|
||||
|
||||
3. Add shell completions for new flags
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: --priority flag sets prompt priority
|
||||
- Unit test: --priority validation (1-10 range)
|
||||
- Unit test: --link flag sets linkTarget
|
||||
- Unit test: --link validation (format check)
|
||||
- Unit test: Linked prompt skips content prompt
|
||||
- Unit test: Default priority is 5
|
||||
- Integration test: End-to-end create with flags
|
||||
54
.taskmaster/tasks/task_060.md
Normal file
54
.taskmaster/tasks/task_060.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Task ID: 60
|
||||
|
||||
**Title:** Update CLI get prompt command for -A flag and link columns
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 57 ✓, 59 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Extend the mcpctl get prompt command with -A (all projects) flag and add link target and status columns to output.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/src/cli/src/commands/get.ts` for prompt:
|
||||
```typescript
|
||||
.command('prompt [name]')
|
||||
.option('-A, --all-projects', 'Show prompts from all projects')
|
||||
.option('-p, --project <name>', 'Filter by project')
|
||||
.action(async (name, options) => {
|
||||
let url = '/api/v1/prompts';
|
||||
if (options.allProjects) {
|
||||
url += '?all=true';
|
||||
} else if (options.project) {
|
||||
url += `?project=${options.project}`;
|
||||
}
|
||||
|
||||
const prompts = await api.get(url);
|
||||
|
||||
// Format table with new columns
|
||||
formatPromptsTable(prompts, {
|
||||
columns: ['PROJECT', 'NAME', 'PRIORITY', 'LINK', 'STATUS']
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
2. Update table formatter to handle link columns:
|
||||
```
|
||||
PROJECT NAME PRIORITY LINK STATUS
|
||||
homeautomation security-policies 8 - -
|
||||
homeautomation architecture-adr 6 system-public/docmost-mcp:docmost://pages/a1 alive
|
||||
```
|
||||
|
||||
3. Add shell completions for -A flag
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: -A flag shows all projects
|
||||
- Unit test: --project flag filters by project
|
||||
- Unit test: PRIORITY column displayed
|
||||
- Unit test: LINK column shows linkTarget or -
|
||||
- Unit test: STATUS column shows linkStatus or -
|
||||
- Unit test: Table formatted correctly
|
||||
- Integration test: End-to-end get with flags
|
||||
49
.taskmaster/tasks/task_061.md
Normal file
49
.taskmaster/tasks/task_061.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Task ID: 61
|
||||
|
||||
**Title:** Update CLI describe project command for gated status
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 44 ✓, 54 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Extend mcpctl describe project to show gated status, session greeting, and prompt table with priority and link information.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/src/cli/src/commands/get.ts` describe project:
|
||||
```typescript
|
||||
async function describeProject(name: string) {
|
||||
const project = await api.get(`/api/v1/projects/${name}`);
|
||||
const prompts = await api.get(`/api/v1/projects/${name}/prompt-index`);
|
||||
const greeting = await getSessionGreeting(name);
|
||||
|
||||
console.log(`Name: ${project.name}`);
|
||||
console.log(`Gated: ${project.gated}`);
|
||||
console.log(`LLM Provider: ${project.llmProvider || '-'}`);
|
||||
console.log(`...`);
|
||||
console.log();
|
||||
console.log(`Session greeting:`);
|
||||
console.log(` ${greeting}`);
|
||||
console.log();
|
||||
console.log(`Prompts:`);
|
||||
console.log(` NAME PRIORITY TYPE LINK`);
|
||||
for (const p of prompts) {
|
||||
const type = p.linkTarget ? 'link' : 'local';
|
||||
const link = p.linkTarget || '-';
|
||||
console.log(` ${p.name.padEnd(20)} ${p.priority.toString().padEnd(9)} ${type.padEnd(7)} ${link}`);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Fetch session greeting from system prompts or project config
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Gated status displayed
|
||||
- Unit test: Session greeting displayed
|
||||
- Unit test: Prompt table with PRIORITY, TYPE, LINK columns
|
||||
- Unit test: TYPE shows 'local' or 'link'
|
||||
- Unit test: LINK shows target or -
|
||||
- Integration test: End-to-end describe project
|
||||
51
.taskmaster/tasks/task_062.md
Normal file
51
.taskmaster/tasks/task_062.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Task ID: 62
|
||||
|
||||
**Title:** Update CLI edit project command for gated field
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 39 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Extend mcpctl edit project to allow editing the gated boolean field.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/src/cli/src/commands/edit.ts` for project:
|
||||
```typescript
|
||||
async function editProject(name: string) {
|
||||
const project = await api.get(`/api/v1/projects/${name}`);
|
||||
|
||||
// Add gated to editable fields
|
||||
const yaml = `
|
||||
name: ${project.name}
|
||||
description: ${project.description}
|
||||
gated: ${project.gated}
|
||||
llmProvider: ${project.llmProvider || ''}
|
||||
...`;
|
||||
|
||||
const edited = await openEditor(yaml);
|
||||
const parsed = YAML.parse(edited);
|
||||
|
||||
// Validate gated is boolean
|
||||
if (typeof parsed.gated !== 'boolean') {
|
||||
console.error('gated must be true or false');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await api.put(`/api/v1/projects/${name}`, parsed);
|
||||
}
|
||||
```
|
||||
|
||||
2. Update project validation schema to accept gated
|
||||
|
||||
3. Handle conversion from string 'true'/'false' to boolean
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Unit test: Gated field appears in editor YAML
|
||||
- Unit test: Gated field saved on edit
|
||||
- Unit test: Boolean validation (true/false only)
|
||||
- Unit test: String 'true'/'false' converted to boolean
|
||||
- Integration test: End-to-end edit project gated
|
||||
68
.taskmaster/tasks/task_063.md
Normal file
68
.taskmaster/tasks/task_063.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# Task ID: 63
|
||||
|
||||
**Title:** Add unit tests for prompt priority and link CRUD
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 40 ✓, 41 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create comprehensive unit tests for all prompt CRUD operations with the new priority and linkTarget fields.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add tests in `/src/mcpd/tests/services/prompt-service.test.ts`:
|
||||
```typescript
|
||||
describe('Prompt Priority', () => {
|
||||
it('creates prompt with explicit priority', async () => {
|
||||
const prompt = await service.createPrompt({ ...data, priority: 8 });
|
||||
expect(prompt.priority).toBe(8);
|
||||
});
|
||||
|
||||
it('uses default priority 5 when not specified', async () => {
|
||||
const prompt = await service.createPrompt(data);
|
||||
expect(prompt.priority).toBe(5);
|
||||
});
|
||||
|
||||
it('validates priority range 1-10', async () => {
|
||||
await expect(service.createPrompt({ ...data, priority: 11 }))
|
||||
.rejects.toThrow();
|
||||
});
|
||||
|
||||
it('updates priority', async () => {
|
||||
const updated = await service.updatePrompt(id, { priority: 3 });
|
||||
expect(updated.priority).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Prompt Links', () => {
|
||||
it('creates linked prompt', async () => {
|
||||
const prompt = await service.createPrompt({
|
||||
...data,
|
||||
linkTarget: 'project/server:uri'
|
||||
});
|
||||
expect(prompt.linkTarget).toBe('project/server:uri');
|
||||
});
|
||||
|
||||
it('rejects invalid link format', async () => {
|
||||
await expect(service.createPrompt({
|
||||
...data,
|
||||
linkTarget: 'invalid'
|
||||
})).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('linkTarget is immutable on update', async () => {
|
||||
// linkTarget not accepted in update schema
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
This task IS the test implementation. Verify:
|
||||
- All priority CRUD tests pass
|
||||
- All link CRUD tests pass
|
||||
- Validation tests cover edge cases
|
||||
- Tests use proper mocking patterns
|
||||
- Coverage meets project standards
|
||||
58
.taskmaster/tasks/task_064.md
Normal file
58
.taskmaster/tasks/task_064.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# Task ID: 64
|
||||
|
||||
**Title:** Add unit tests for tag matching algorithm
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 45 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create comprehensive unit tests for the deterministic tag matching algorithm covering score calculation, byte budget, and priority handling.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add tests in `/src/mcplocal/tests/services/tag-matcher.test.ts`:
|
||||
```typescript
|
||||
describe('TagMatcherService', () => {
|
||||
describe('score calculation', () => {
|
||||
it('priority 10 prompts have infinite score', () => {
|
||||
const score = matcher.computeScore(['any'], { priority: 10, ... });
|
||||
expect(score).toBe(Infinity);
|
||||
});
|
||||
|
||||
it('score = matching_tags * priority', () => {
|
||||
const score = matcher.computeScore(
|
||||
['tag1', 'tag2'],
|
||||
{ priority: 5, summary: 'tag1 tag2', chapters: [] }
|
||||
);
|
||||
expect(score).toBe(10); // 2 tags * 5 priority
|
||||
});
|
||||
});
|
||||
|
||||
describe('matching', () => {
|
||||
it('matches case-insensitively', () => {
|
||||
const matches = matcher.matchesPrompt('ZIGBEE', { summary: 'zigbee setup' });
|
||||
expect(matches).toBe(true);
|
||||
});
|
||||
|
||||
it('matches substring in summary', () => { ... });
|
||||
it('matches substring in chapters', () => { ... });
|
||||
});
|
||||
|
||||
describe('byte budget', () => {
|
||||
it('includes full content until budget exhausted', () => { ... });
|
||||
it('matched prompts beyond budget become index entries', () => { ... });
|
||||
it('non-matched prompts listed as names only', () => { ... });
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
This task IS the test implementation. Verify:
|
||||
- Score calculation tests pass
|
||||
- Matching tests cover all cases
|
||||
- Byte budget tests verify allocation
|
||||
- Edge cases handled (empty tags, no prompts, etc.)
|
||||
- Tests are deterministic
|
||||
63
.taskmaster/tasks/task_065.md
Normal file
63
.taskmaster/tasks/task_065.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Task ID: 65
|
||||
|
||||
**Title:** Add unit tests for gating state machine
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 50 ✓, 52 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create comprehensive unit tests for the session gating state machine covering all transitions and edge cases.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add tests in `/src/mcplocal/tests/router-gating.test.ts`:
|
||||
```typescript
|
||||
describe('Gating State Machine', () => {
|
||||
describe('initial state', () => {
|
||||
it('starts gated for gated project', () => {
|
||||
const router = createRouter({ gated: true });
|
||||
const state = router.getSessionState('session1');
|
||||
expect(state.gated).toBe(true);
|
||||
});
|
||||
|
||||
it('starts ungated for non-gated project', () => {
|
||||
const router = createRouter({ gated: false });
|
||||
const state = router.getSessionState('session1');
|
||||
expect(state.gated).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('begin_session transition', () => {
|
||||
it('ungates session on successful begin_session', async () => {
|
||||
const router = createGatedRouter();
|
||||
await router.handleBeginSession('session1', { tags: ['test'] });
|
||||
expect(router.getSessionState('session1').gated).toBe(false);
|
||||
});
|
||||
|
||||
it('returns matched prompts', async () => { ... });
|
||||
it('sends notifications/tools/list_changed', async () => { ... });
|
||||
});
|
||||
|
||||
describe('intercept transition', () => {
|
||||
it('ungates session on tool call intercept', async () => { ... });
|
||||
it('extracts keywords from tool call', async () => { ... });
|
||||
it('injects briefing with tool result', async () => { ... });
|
||||
});
|
||||
|
||||
describe('tools/list behavior', () => {
|
||||
it('returns only begin_session while gated', async () => { ... });
|
||||
it('returns all tools + read_prompts after ungating', async () => { ... });
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
This task IS the test implementation. Verify:
|
||||
- Initial state tests pass
|
||||
- Transition tests cover happy paths
|
||||
- Edge case tests (already ungated, etc.)
|
||||
- Notification tests verify signals sent
|
||||
- Tests use proper mocking
|
||||
61
.taskmaster/tasks/task_066.md
Normal file
61
.taskmaster/tasks/task_066.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# Task ID: 66
|
||||
|
||||
**Title:** Add unit tests for LLM prompt selection
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 46 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create unit tests for the LLM-based prompt selection service covering LLM interactions, fallback behavior, and priority 10 handling.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add tests in `/src/mcplocal/tests/services/llm-prompt-selector.test.ts`:
|
||||
```typescript
|
||||
describe('LlmPromptSelectorService', () => {
|
||||
describe('priority 10 handling', () => {
|
||||
it('always includes priority 10 prompts', async () => {
|
||||
const result = await selector.selectPrompts(['unrelated'], promptIndex);
|
||||
expect(result.priority10).toContain(priority10Prompt);
|
||||
});
|
||||
});
|
||||
|
||||
describe('LLM selection', () => {
|
||||
it('sends tags and index to heavy LLM', async () => {
|
||||
await selector.selectPrompts(['zigbee', 'mqtt'], promptIndex);
|
||||
expect(mockLlm.complete).toHaveBeenCalledWith(
|
||||
expect.stringContaining('zigbee')
|
||||
);
|
||||
});
|
||||
|
||||
it('parses LLM response correctly', async () => {
|
||||
mockLlm.complete.mockResolvedValue(
|
||||
'[{"name": "prompt1", "reason": "relevant"}]'
|
||||
);
|
||||
const result = await selector.selectPrompts(['test'], promptIndex);
|
||||
expect(result.selected[0].name).toBe('prompt1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('fallback behavior', () => {
|
||||
it('falls back to tag matcher on LLM error', async () => { ... });
|
||||
it('falls back on LLM timeout', async () => { ... });
|
||||
it('falls back when no LLM available', async () => { ... });
|
||||
});
|
||||
|
||||
describe('summary generation', () => {
|
||||
it('generates missing summaries with fast LLM', async () => { ... });
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
This task IS the test implementation. Verify:
|
||||
- Priority 10 tests pass
|
||||
- LLM interaction tests use proper mocks
|
||||
- Fallback tests cover all error scenarios
|
||||
- Summary generation tests pass
|
||||
- Response parsing handles edge cases
|
||||
64
.taskmaster/tasks/task_067.md
Normal file
64
.taskmaster/tasks/task_067.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# Task ID: 67
|
||||
|
||||
**Title:** Add integration tests for gated session flow
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 65 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create end-to-end integration tests for the complete gated session flow including connect, begin_session, tool calls, and read_prompts.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add tests in `/src/mcplocal/tests/integration/gated-flow.test.ts`:
|
||||
```typescript
|
||||
describe('Gated Session Flow Integration', () => {
|
||||
let app: FastifyInstance;
|
||||
let mcpClient: McpClient;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await createTestApp();
|
||||
// Seed test project with gated=true and test prompts
|
||||
});
|
||||
|
||||
describe('end-to-end gated flow', () => {
|
||||
it('connect → begin_session with tags → tools available → correct prompts', async () => {
|
||||
// 1. Connect to MCP endpoint
|
||||
const session = await mcpClient.connect(app, 'test-project');
|
||||
|
||||
// 2. Verify only begin_session available
|
||||
const toolsBefore = await session.listTools();
|
||||
expect(toolsBefore.map(t => t.name)).toEqual(['begin_session']);
|
||||
|
||||
// 3. Call begin_session
|
||||
const briefing = await session.callTool('begin_session', {
|
||||
tags: ['test', 'integration']
|
||||
});
|
||||
expect(briefing).toContain('matched prompt content');
|
||||
|
||||
// 4. Verify all tools now available
|
||||
const toolsAfter = await session.listTools();
|
||||
expect(toolsAfter.map(t => t.name)).toContain('read_prompts');
|
||||
});
|
||||
});
|
||||
|
||||
describe('end-to-end intercept flow', () => {
|
||||
it('connect → skip begin_session → call tool → keywords extracted → briefing injected', async () => { ... });
|
||||
});
|
||||
|
||||
describe('end-to-end read_prompts', () => {
|
||||
it('after ungating → request more context → additional prompts → no duplicates', async () => { ... });
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
This task IS the test implementation. Verify:
|
||||
- Happy path tests pass
|
||||
- Intercept path tests pass
|
||||
- read_prompts deduplication works
|
||||
- Tests use realistic data
|
||||
- Tests clean up properly
|
||||
58
.taskmaster/tasks/task_068.md
Normal file
58
.taskmaster/tasks/task_068.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# Task ID: 68
|
||||
|
||||
**Title:** Add integration tests for prompt links
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 57 ✓, 58 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Create end-to-end integration tests for prompt link creation, resolution, and dead link detection.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add tests in `/src/mcplocal/tests/integration/prompt-links.test.ts`:
|
||||
```typescript
|
||||
describe('Prompt Links Integration', () => {
|
||||
describe('link creation', () => {
|
||||
it('creates link with RBAC permission', async () => {
|
||||
// Setup: user with edit permission on target project
|
||||
const prompt = await api.post('/api/v1/prompts', {
|
||||
name: 'linked-prompt',
|
||||
content: '[Link]',
|
||||
projectId: targetProject.id,
|
||||
linkTarget: 'source-project/server:uri'
|
||||
});
|
||||
expect(prompt.linkTarget).toBe('source-project/server:uri');
|
||||
});
|
||||
|
||||
it('rejects link creation without RBAC permission', async () => { ... });
|
||||
});
|
||||
|
||||
describe('link resolution', () => {
|
||||
it('fetches content from source server', async () => { ... });
|
||||
it('uses service account for RBAC', async () => { ... });
|
||||
});
|
||||
|
||||
describe('dead link lifecycle', () => {
|
||||
it('detects dead link when source unavailable', async () => {
|
||||
// Kill source server
|
||||
const prompts = await api.get('/api/v1/prompts');
|
||||
const linked = prompts.find(p => p.linkTarget);
|
||||
expect(linked.linkStatus).toBe('dead');
|
||||
});
|
||||
|
||||
it('recovers when source restored', async () => { ... });
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
This task IS the test implementation. Verify:
|
||||
- RBAC tests cover permission scenarios
|
||||
- Resolution tests verify content fetched
|
||||
- Dead link tests cover full lifecycle
|
||||
- Tests properly mock/control source servers
|
||||
- Tests clean up resources
|
||||
59
.taskmaster/tasks/task_069.md
Normal file
59
.taskmaster/tasks/task_069.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Task ID: 69
|
||||
|
||||
**Title:** Add CLI unit tests for new prompt and project flags
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 59 ✓, 60 ✓, 61 ✓, 62 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Create unit tests for the new CLI flags: --priority, --link for prompts, -A for get, and gated field for projects.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Add tests in `/src/cli/tests/commands/prompt.test.ts`:
|
||||
```typescript
|
||||
describe('create prompt command', () => {
|
||||
it('--priority sets prompt priority', async () => {
|
||||
await cli('create prompt test --priority 8');
|
||||
expect(mockApi.post).toHaveBeenCalledWith(
|
||||
'/api/v1/prompts',
|
||||
expect.objectContaining({ priority: 8 })
|
||||
);
|
||||
});
|
||||
|
||||
it('--priority validates range 1-10', async () => {
|
||||
await expect(cli('create prompt test --priority 15'))
|
||||
.rejects.toThrow('Priority must be between 1 and 10');
|
||||
});
|
||||
|
||||
it('--link sets linkTarget', async () => {
|
||||
await cli('create prompt test --link proj/srv:uri');
|
||||
expect(mockApi.post).toHaveBeenCalledWith(
|
||||
'/api/v1/prompts',
|
||||
expect.objectContaining({ linkTarget: 'proj/srv:uri' })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get prompt command', () => {
|
||||
it('-A shows all projects', async () => {
|
||||
await cli('get prompt -A');
|
||||
expect(mockApi.get).toHaveBeenCalledWith('/api/v1/prompts?all=true');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
2. Add tests for project gated field editing
|
||||
|
||||
3. Add tests for describe project output
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
This task IS the test implementation. Verify:
|
||||
- Flag parsing tests pass
|
||||
- Validation tests cover edge cases
|
||||
- API call tests verify correct parameters
|
||||
- Output formatting tests verify columns
|
||||
- Tests mock API properly
|
||||
37
.taskmaster/tasks/task_070.md
Normal file
37
.taskmaster/tasks/task_070.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Task ID: 70
|
||||
|
||||
**Title:** Add shell completions for new CLI flags
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 59 ✓, 60 ✓
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Update shell completion scripts (bash, zsh, fish) to include completions for new flags: --priority, --link, -A, and gated values.
|
||||
|
||||
**Details:**
|
||||
|
||||
1. Update `/completions/mcpctl.fish`:
|
||||
```fish
|
||||
# create prompt completions
|
||||
complete -c mcpctl -n '__fish_seen_subcommand_from create; and __fish_seen_subcommand_from prompt' -l priority -d 'Priority level (1-10)' -a '(seq 1 10)'
|
||||
complete -c mcpctl -n '__fish_seen_subcommand_from create; and __fish_seen_subcommand_from prompt' -l link -d 'Link to MCP resource (project/server:uri)'
|
||||
|
||||
# get prompt completions
|
||||
complete -c mcpctl -n '__fish_seen_subcommand_from get; and __fish_seen_subcommand_from prompt' -s A -l all-projects -d 'Show prompts from all projects'
|
||||
```
|
||||
|
||||
2. Update bash completions similarly
|
||||
|
||||
3. Update zsh completions similarly
|
||||
|
||||
4. Add dynamic completion for priority values (1-10)
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
- Manual test: Fish completions suggest --priority with values 1-10
|
||||
- Manual test: Fish completions suggest --link flag
|
||||
- Manual test: Fish completions suggest -A/--all-projects
|
||||
- Manual test: Bash completions work similarly
|
||||
- Manual test: Zsh completions work similarly
|
||||
70
.taskmaster/tasks/task_071.md
Normal file
70
.taskmaster/tasks/task_071.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# Task ID: 71
|
||||
|
||||
**Title:** Define ProxyModel Public Type Contract
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the core TypeScript types for the ProxyModel framework that stages will import from `mcpctl/proxymodel`. This establishes the public API contract that stage authors write against.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/types.ts` with:
|
||||
|
||||
```typescript
|
||||
export interface StageHandler {
|
||||
(content: string, ctx: StageContext): Promise<StageResult>;
|
||||
}
|
||||
|
||||
export interface StageContext {
|
||||
contentType: 'prompt' | 'toolResult' | 'resource';
|
||||
sourceName: string;
|
||||
projectName: string;
|
||||
sessionId: string;
|
||||
originalContent: string;
|
||||
llm: LLMProvider;
|
||||
cache: CacheProvider;
|
||||
log: Logger;
|
||||
config: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface StageResult {
|
||||
content: string;
|
||||
sections?: Section[];
|
||||
metadata?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface Section {
|
||||
id: string;
|
||||
title: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface LLMProvider {
|
||||
complete(prompt: string, options?: { system?: string; maxTokens?: number }): Promise<string>;
|
||||
available(): boolean;
|
||||
}
|
||||
|
||||
export interface CacheProvider {
|
||||
getOrCompute(key: string, compute: () => Promise<string>): Promise<string>;
|
||||
hash(content: string): string;
|
||||
get(key: string): Promise<string | null>;
|
||||
set(key: string, value: string): Promise<void>;
|
||||
}
|
||||
|
||||
export interface Logger {
|
||||
debug(msg: string): void;
|
||||
info(msg: string): void;
|
||||
warn(msg: string): void;
|
||||
error(msg: string): void;
|
||||
}
|
||||
```
|
||||
|
||||
Also create `src/mcplocal/src/proxymodel/index.ts` as the public entrypoint that re-exports these types. Update `package.json` exports to expose `mcpctl/proxymodel`.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests verifying type exports are accessible from the public entrypoint. Create a sample stage file that imports from `mcpctl/proxymodel` and verify it compiles without errors.
|
||||
49
.taskmaster/tasks/task_072.md
Normal file
49
.taskmaster/tasks/task_072.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Task ID: 72
|
||||
|
||||
**Title:** Implement LLMProvider Adapter
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 71 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create an adapter that wraps the existing ProviderRegistry to implement the StageContext.llm interface, providing stages with a simplified LLM access API.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/llm-adapter.ts`:
|
||||
|
||||
```typescript
|
||||
import type { LLMProvider } from './types';
|
||||
import type { ProviderRegistry } from '../providers/registry';
|
||||
|
||||
export function createLLMAdapter(registry: ProviderRegistry, projectName: string): LLMProvider {
|
||||
return {
|
||||
async complete(prompt: string, options?: { system?: string; maxTokens?: number }): Promise<string> {
|
||||
const provider = registry.getProvider('heavy');
|
||||
if (!provider) throw new Error('No LLM provider configured');
|
||||
|
||||
const messages = options?.system
|
||||
? [{ role: 'system', content: options.system }, { role: 'user', content: prompt }]
|
||||
: [{ role: 'user', content: prompt }];
|
||||
|
||||
const result = await provider.complete({
|
||||
messages,
|
||||
maxTokens: options?.maxTokens ?? 1000,
|
||||
});
|
||||
return result.content;
|
||||
},
|
||||
|
||||
available(): boolean {
|
||||
return registry.getProvider('heavy') !== null;
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
This adapter uses the 'heavy' tier from the existing registry, preserving the project-level LLM configuration.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit test with mocked ProviderRegistry verifying complete() calls are delegated correctly. Test available() returns false when no provider is configured. Integration test with a real provider.
|
||||
67
.taskmaster/tasks/task_073.md
Normal file
67
.taskmaster/tasks/task_073.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Task ID: 73
|
||||
|
||||
**Title:** Implement In-Memory CacheProvider
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 71 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the CacheProvider implementation that stages use for caching expensive computations. Start with in-memory cache for Phase 1, with content-addressed keys.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/cache-provider.ts`:
|
||||
|
||||
```typescript
|
||||
import { createHash } from 'crypto';
|
||||
import type { CacheProvider } from './types';
|
||||
|
||||
export class InMemoryCacheProvider implements CacheProvider {
|
||||
private cache = new Map<string, { value: string; timestamp: number }>();
|
||||
private maxSize: number;
|
||||
private ttlMs: number;
|
||||
|
||||
constructor(options: { maxSize?: number; ttlMs?: number } = {}) {
|
||||
this.maxSize = options.maxSize ?? 1000;
|
||||
this.ttlMs = options.ttlMs ?? 3600000; // 1 hour default
|
||||
}
|
||||
|
||||
hash(content: string): string {
|
||||
return createHash('sha256').update(content).digest('hex').slice(0, 16);
|
||||
}
|
||||
|
||||
async get(key: string): Promise<string | null> {
|
||||
const entry = this.cache.get(key);
|
||||
if (!entry) return null;
|
||||
if (Date.now() - entry.timestamp > this.ttlMs) {
|
||||
this.cache.delete(key);
|
||||
return null;
|
||||
}
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
async set(key: string, value: string): Promise<void> {
|
||||
if (this.cache.size >= this.maxSize) this.evictOldest();
|
||||
this.cache.set(key, { value, timestamp: Date.now() });
|
||||
}
|
||||
|
||||
async getOrCompute(key: string, compute: () => Promise<string>): Promise<string> {
|
||||
const cached = await this.get(key);
|
||||
if (cached !== null) return cached;
|
||||
const value = await compute();
|
||||
await this.set(key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private evictOldest(): void {
|
||||
const oldest = [...this.cache.entries()].sort((a, b) => a[1].timestamp - b[1].timestamp)[0];
|
||||
if (oldest) this.cache.delete(oldest[0]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests for: hash() produces consistent output, get() returns null for missing keys, set()/get() round-trip works, TTL expiration works, LRU eviction triggers at maxSize, getOrCompute() caches and returns cached values.
|
||||
57
.taskmaster/tasks/task_074.md
Normal file
57
.taskmaster/tasks/task_074.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# Task ID: 74
|
||||
|
||||
**Title:** Implement Content Type Detection
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create a utility that detects content type (JSON, YAML, XML, code, prose) for structural splitting in the section-split stage.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/content-detection.ts`:
|
||||
|
||||
```typescript
|
||||
export type ContentType = 'json' | 'yaml' | 'xml' | 'code' | 'prose';
|
||||
|
||||
export function detectContentType(content: string): ContentType {
|
||||
const trimmed = content.trimStart();
|
||||
|
||||
// JSON detection
|
||||
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
||||
try {
|
||||
JSON.parse(content);
|
||||
return 'json';
|
||||
} catch { /* not valid JSON, continue */ }
|
||||
}
|
||||
|
||||
// XML detection
|
||||
if (trimmed.startsWith('<?xml') || /^<[a-zA-Z][^>]*>/.test(trimmed)) {
|
||||
return 'xml';
|
||||
}
|
||||
|
||||
// YAML detection (key: value at start of lines)
|
||||
if (/^[a-zA-Z_][a-zA-Z0-9_]*:\s/m.test(trimmed) && !trimmed.includes('{')) {
|
||||
return 'yaml';
|
||||
}
|
||||
|
||||
// Code detection (common patterns)
|
||||
const codePatterns = [
|
||||
/^(function |class |def |const |let |var |import |export |package |pub fn |fn |impl )/m,
|
||||
/^#include\s+[<"]/m,
|
||||
/^(public |private |protected )?(static )?(void |int |string |bool )/m,
|
||||
];
|
||||
if (codePatterns.some(p => p.test(trimmed))) {
|
||||
return 'code';
|
||||
}
|
||||
|
||||
return 'prose';
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests with sample content for each type: valid JSON objects/arrays, XML documents, YAML configs, code snippets in multiple languages (JS, Python, Rust, Go, Java), and prose markdown. Edge cases: JSON-like strings that aren't valid JSON, mixed content.
|
||||
77
.taskmaster/tasks/task_075.md
Normal file
77
.taskmaster/tasks/task_075.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# Task ID: 75
|
||||
|
||||
**Title:** Implement section-split Stage
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 71 ✓, 74 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the built-in section-split stage that splits content based on detected content type, using structural boundaries for JSON/YAML/XML and headers for prose.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/stages/section-split.ts`:
|
||||
|
||||
```typescript
|
||||
import type { StageHandler, Section } from '../types';
|
||||
import { detectContentType } from '../content-detection';
|
||||
|
||||
const handler: StageHandler = async (content, ctx) => {
|
||||
const minSize = (ctx.config.minSectionSize as number) ?? 2000;
|
||||
const maxSize = (ctx.config.maxSectionSize as number) ?? 15000;
|
||||
const contentType = detectContentType(content);
|
||||
|
||||
let sections: Section[];
|
||||
|
||||
switch (contentType) {
|
||||
case 'json':
|
||||
sections = splitJson(content, minSize, maxSize);
|
||||
break;
|
||||
case 'yaml':
|
||||
sections = splitYaml(content, minSize, maxSize);
|
||||
break;
|
||||
case 'xml':
|
||||
sections = splitXml(content, minSize, maxSize);
|
||||
break;
|
||||
case 'code':
|
||||
sections = splitCode(content, minSize);
|
||||
break;
|
||||
default:
|
||||
sections = splitProse(content, minSize);
|
||||
}
|
||||
|
||||
if (sections.length === 0) {
|
||||
return { content, sections: [{ id: 'main', title: 'Content', content }] };
|
||||
}
|
||||
|
||||
const toc = sections.map((s, i) => `[${s.id}] ${s.title}`).join('\n');
|
||||
return {
|
||||
content: `${sections.length} sections (${contentType}):\n${toc}`,
|
||||
sections,
|
||||
};
|
||||
};
|
||||
|
||||
function splitJson(content: string, minSize: number, maxSize: number): Section[] {
|
||||
const parsed = JSON.parse(content);
|
||||
if (Array.isArray(parsed)) {
|
||||
return parsed.map((item, i) => ({
|
||||
id: item.id ?? item.name ?? `item-${i}`,
|
||||
title: item.label ?? item.title ?? item.name ?? `Item ${i}`,
|
||||
content: JSON.stringify(item, null, 2),
|
||||
}));
|
||||
}
|
||||
return Object.entries(parsed).map(([key, value]) => ({
|
||||
id: key,
|
||||
title: key,
|
||||
content: JSON.stringify(value, null, 2),
|
||||
}));
|
||||
}
|
||||
|
||||
// Similar implementations for splitYaml, splitXml, splitCode, splitProse
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests for each content type: JSON arrays split by element, JSON objects split by key, YAML split by top-level keys, XML split by elements, prose split by markdown headers. Test minSize/maxSize thresholds. Test fallback when content can't be parsed.
|
||||
84
.taskmaster/tasks/task_076.md
Normal file
84
.taskmaster/tasks/task_076.md
Normal file
@@ -0,0 +1,84 @@
|
||||
# Task ID: 76
|
||||
|
||||
**Title:** Implement summarize-tree Stage
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 71 ✓, 72 ✓, 73 ✓, 74 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the built-in summarize-tree stage that recursively summarizes sections, using structural summaries for programmatic content and LLM summaries for prose.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/stages/summarize-tree.ts`:
|
||||
|
||||
```typescript
|
||||
import type { StageHandler, Section, StageContext } from '../types';
|
||||
import { detectContentType } from '../content-detection';
|
||||
|
||||
const handler: StageHandler = async (content, ctx) => {
|
||||
const maxTokens = (ctx.config.maxSummaryTokens as number) ?? 200;
|
||||
const maxGroup = (ctx.config.maxGroupSize as number) ?? 5;
|
||||
const maxDepth = (ctx.config.maxDepth as number) ?? 3;
|
||||
|
||||
// Parse sections from previous stage or create single section
|
||||
const inputSections = parseSectionsFromContent(content);
|
||||
|
||||
const tree = await buildTree(inputSections, ctx, { maxTokens, maxGroup, maxDepth, depth: 0 });
|
||||
|
||||
const toc = tree.map(s =>
|
||||
`[${s.id}] ${s.title} — ${s.metadata?.summary ?? ''}` +
|
||||
(s.sections?.length ? `\n → ${s.sections.length} sub-sections` : '')
|
||||
).join('\n');
|
||||
|
||||
return {
|
||||
content: `${tree.length} sections:\n${toc}\n\nUse section parameter to read details.`,
|
||||
sections: tree,
|
||||
};
|
||||
};
|
||||
|
||||
async function buildTree(
|
||||
sections: Section[],
|
||||
ctx: StageContext,
|
||||
opts: { maxTokens: number; maxGroup: number; maxDepth: number; depth: number }
|
||||
): Promise<Section[]> {
|
||||
for (const section of sections) {
|
||||
const contentType = detectContentType(section.content);
|
||||
|
||||
// Structural summary for programmatic content (no LLM needed)
|
||||
if (contentType !== 'prose') {
|
||||
section.metadata = { summary: generateStructuralSummary(section.content, contentType) };
|
||||
} else {
|
||||
// LLM summary for prose (cached)
|
||||
const cacheKey = `summary:${ctx.cache.hash(section.content)}:${opts.maxTokens}`;
|
||||
const summary = await ctx.cache.getOrCompute(cacheKey, () =>
|
||||
ctx.llm.complete(
|
||||
`Summarize in ${opts.maxTokens} tokens, preserve MUST/REQUIRED items:\n\n${section.content}`
|
||||
)
|
||||
);
|
||||
section.metadata = { summary };
|
||||
}
|
||||
|
||||
// Recurse if large and not at max depth
|
||||
if (section.content.length > 5000 && opts.depth < opts.maxDepth) {
|
||||
section.sections = await buildTree(
|
||||
splitContent(section.content),
|
||||
ctx,
|
||||
{ ...opts, depth: opts.depth + 1 }
|
||||
);
|
||||
}
|
||||
}
|
||||
return sections;
|
||||
}
|
||||
|
||||
function generateStructuralSummary(content: string, type: string): string {
|
||||
// Generate summary from structure: key names, array lengths, types
|
||||
// No LLM needed for JSON/YAML/XML/code
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests: prose content gets LLM summary (mock LLM), JSON content gets structural summary without LLM call, recursive splitting triggers at 5000 chars, maxDepth is respected, cache is used for repeated content. Integration test with real LLM provider.
|
||||
63
.taskmaster/tasks/task_077.md
Normal file
63
.taskmaster/tasks/task_077.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Task ID: 77
|
||||
|
||||
**Title:** Implement passthrough and paginate Stages
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 71 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the built-in passthrough (no-op) and paginate (large response splitting) stages that form the default proxymodel.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/stages/passthrough.ts`:
|
||||
|
||||
```typescript
|
||||
import type { StageHandler } from '../types';
|
||||
|
||||
const handler: StageHandler = async (content, ctx) => {
|
||||
return { content };
|
||||
};
|
||||
export default handler;
|
||||
```
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/stages/paginate.ts`:
|
||||
|
||||
```typescript
|
||||
import type { StageHandler, Section } from '../types';
|
||||
|
||||
const handler: StageHandler = async (content, ctx) => {
|
||||
const pageSize = (ctx.config.pageSize as number) ?? 8000;
|
||||
|
||||
if (content.length <= pageSize) {
|
||||
return { content };
|
||||
}
|
||||
|
||||
const pages: Section[] = [];
|
||||
let offset = 0;
|
||||
let pageNum = 1;
|
||||
|
||||
while (offset < content.length) {
|
||||
const pageContent = content.slice(offset, offset + pageSize);
|
||||
pages.push({
|
||||
id: `page-${pageNum}`,
|
||||
title: `Page ${pageNum}`,
|
||||
content: pageContent,
|
||||
});
|
||||
offset += pageSize;
|
||||
pageNum++;
|
||||
}
|
||||
|
||||
return {
|
||||
content: `Content split into ${pages.length} pages (${content.length} chars total). Use section parameter to read specific pages.`,
|
||||
sections: pages,
|
||||
};
|
||||
};
|
||||
export default handler;
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
passthrough: verify content returned unchanged. paginate: verify content under threshold returns unchanged, content over threshold splits correctly, page boundaries are correct, section IDs are sequential.
|
||||
78
.taskmaster/tasks/task_078.md
Normal file
78
.taskmaster/tasks/task_078.md
Normal file
@@ -0,0 +1,78 @@
|
||||
# Task ID: 78
|
||||
|
||||
**Title:** Create ProxyModel YAML Schema and Loader
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 71 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Define the YAML schema for proxymodel definitions and implement the loader that reads from ~/.mcpctl/proxymodels/ and merges with built-ins.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/schema.ts`:
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ProxyModelSchema = z.object({
|
||||
kind: z.literal('ProxyModel'),
|
||||
metadata: z.object({
|
||||
name: z.string(),
|
||||
}),
|
||||
spec: z.object({
|
||||
controller: z.string().optional().default('gate'),
|
||||
controllerConfig: z.record(z.unknown()).optional(),
|
||||
stages: z.array(z.object({
|
||||
type: z.string(),
|
||||
config: z.record(z.unknown()).optional(),
|
||||
})),
|
||||
appliesTo: z.array(z.enum(['prompts', 'toolResults', 'resource'])).optional(),
|
||||
cacheable: z.boolean().optional().default(true),
|
||||
}),
|
||||
});
|
||||
|
||||
export type ProxyModelDefinition = z.infer<typeof ProxyModelSchema>;
|
||||
```
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/loader.ts`:
|
||||
|
||||
```typescript
|
||||
import { readdir, readFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { parse as parseYaml } from 'yaml';
|
||||
import { ProxyModelSchema, type ProxyModelDefinition } from './schema';
|
||||
import { getBuiltInProxyModels } from './built-in-models';
|
||||
|
||||
const PROXYMODELS_DIR = join(process.env.HOME ?? '', '.mcpctl', 'proxymodels');
|
||||
|
||||
export async function loadProxyModels(): Promise<Map<string, ProxyModelDefinition>> {
|
||||
const models = new Map<string, ProxyModelDefinition>();
|
||||
|
||||
// Load built-ins first
|
||||
for (const [name, model] of getBuiltInProxyModels()) {
|
||||
models.set(name, model);
|
||||
}
|
||||
|
||||
// Load local (overrides built-ins)
|
||||
try {
|
||||
const files = await readdir(PROXYMODELS_DIR);
|
||||
for (const file of files.filter(f => f.endsWith('.yaml') || f.endsWith('.yml'))) {
|
||||
const content = await readFile(join(PROXYMODELS_DIR, file), 'utf-8');
|
||||
const parsed = parseYaml(content);
|
||||
const validated = ProxyModelSchema.parse(parsed);
|
||||
models.set(validated.metadata.name, validated);
|
||||
}
|
||||
} catch (e) {
|
||||
// Directory doesn't exist or can't be read - use built-ins only
|
||||
}
|
||||
|
||||
return models;
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests: valid YAML parses correctly, invalid YAML throws validation error, local models override built-ins with same name, missing directory doesn't throw. Create test fixtures for various YAML configurations.
|
||||
68
.taskmaster/tasks/task_079.md
Normal file
68
.taskmaster/tasks/task_079.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# Task ID: 79
|
||||
|
||||
**Title:** Implement Stage Registry and Dynamic Loader
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 71 ✓, 75 ✓, 76 ✓, 77 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the stage registry that resolves stage names to handlers, loading from ~/.mcpctl/stages/ for custom stages and falling back to built-ins.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/stage-registry.ts`:
|
||||
|
||||
```typescript
|
||||
import { readdir, stat } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import type { StageHandler } from './types';
|
||||
|
||||
const STAGES_DIR = join(process.env.HOME ?? '', '.mcpctl', 'stages');
|
||||
|
||||
const builtInStages: Map<string, StageHandler> = new Map();
|
||||
const customStages: Map<string, StageHandler> = new Map();
|
||||
|
||||
// Register built-ins at module load
|
||||
import passthrough from './stages/passthrough';
|
||||
import paginate from './stages/paginate';
|
||||
import sectionSplit from './stages/section-split';
|
||||
import summarizeTree from './stages/summarize-tree';
|
||||
|
||||
builtInStages.set('passthrough', passthrough);
|
||||
builtInStages.set('paginate', paginate);
|
||||
builtInStages.set('section-split', sectionSplit);
|
||||
builtInStages.set('summarize-tree', summarizeTree);
|
||||
|
||||
export async function loadCustomStages(): Promise<void> {
|
||||
customStages.clear();
|
||||
try {
|
||||
const files = await readdir(STAGES_DIR);
|
||||
for (const file of files.filter(f => f.endsWith('.ts') || f.endsWith('.js'))) {
|
||||
const name = file.replace(/\.(ts|js)$/, '');
|
||||
const module = await import(join(STAGES_DIR, file));
|
||||
customStages.set(name, module.default);
|
||||
}
|
||||
} catch { /* directory doesn't exist */ }
|
||||
}
|
||||
|
||||
export function getStage(name: string): StageHandler | null {
|
||||
return customStages.get(name) ?? builtInStages.get(name) ?? null;
|
||||
}
|
||||
|
||||
export function listStages(): { name: string; source: 'built-in' | 'local' }[] {
|
||||
const result: { name: string; source: 'built-in' | 'local' }[] = [];
|
||||
for (const name of builtInStages.keys()) {
|
||||
result.push({ name, source: customStages.has(name) ? 'local' : 'built-in' });
|
||||
}
|
||||
for (const name of customStages.keys()) {
|
||||
if (!builtInStages.has(name)) result.push({ name, source: 'local' });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests: built-in stages are registered, getStage() returns correct handler, custom stages override built-ins, listStages() shows correct sources, missing stages return null. Integration test with actual stage files in temp directory.
|
||||
90
.taskmaster/tasks/task_080.md
Normal file
90
.taskmaster/tasks/task_080.md
Normal file
@@ -0,0 +1,90 @@
|
||||
# Task ID: 80
|
||||
|
||||
**Title:** Implement Pipeline Executor
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 71 ✓, 72 ✓, 73 ✓, 79 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the pipeline executor that runs content through a sequence of stages, managing context, caching, and error handling.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/executor.ts`:
|
||||
|
||||
```typescript
|
||||
import type { StageContext, StageResult, Section } from './types';
|
||||
import type { ProxyModelDefinition } from './schema';
|
||||
import { getStage } from './stage-registry';
|
||||
import { createLLMAdapter } from './llm-adapter';
|
||||
import { InMemoryCacheProvider } from './cache-provider';
|
||||
import type { ProviderRegistry } from '../providers/registry';
|
||||
|
||||
export interface ExecuteOptions {
|
||||
content: string;
|
||||
contentType: 'prompt' | 'toolResult' | 'resource';
|
||||
sourceName: string;
|
||||
projectName: string;
|
||||
sessionId: string;
|
||||
proxyModel: ProxyModelDefinition;
|
||||
providerRegistry: ProviderRegistry;
|
||||
cache?: InMemoryCacheProvider;
|
||||
}
|
||||
|
||||
export async function executePipeline(opts: ExecuteOptions): Promise<StageResult> {
|
||||
const { content, proxyModel, providerRegistry } = opts;
|
||||
const cache = opts.cache ?? new InMemoryCacheProvider();
|
||||
const llm = createLLMAdapter(providerRegistry, opts.projectName);
|
||||
|
||||
let currentContent = content;
|
||||
let sections: Section[] | undefined;
|
||||
let metadata: Record<string, unknown> = {};
|
||||
|
||||
for (const stageConfig of proxyModel.spec.stages) {
|
||||
const handler = getStage(stageConfig.type);
|
||||
if (!handler) {
|
||||
console.warn(`Stage '${stageConfig.type}' not found, skipping`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const ctx: StageContext = {
|
||||
contentType: opts.contentType,
|
||||
sourceName: opts.sourceName,
|
||||
projectName: opts.projectName,
|
||||
sessionId: opts.sessionId,
|
||||
originalContent: content,
|
||||
llm,
|
||||
cache,
|
||||
log: createLogger(stageConfig.type),
|
||||
config: stageConfig.config ?? {},
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await handler(currentContent, ctx);
|
||||
currentContent = result.content;
|
||||
if (result.sections) sections = result.sections;
|
||||
if (result.metadata) metadata = { ...metadata, ...result.metadata };
|
||||
} catch (err) {
|
||||
console.error(`Stage '${stageConfig.type}' failed:`, err);
|
||||
// Continue with previous content on error
|
||||
}
|
||||
}
|
||||
|
||||
return { content: currentContent, sections, metadata };
|
||||
}
|
||||
|
||||
function createLogger(stageName: string) {
|
||||
return {
|
||||
debug: (msg: string) => console.debug(`[${stageName}] ${msg}`),
|
||||
info: (msg: string) => console.info(`[${stageName}] ${msg}`),
|
||||
warn: (msg: string) => console.warn(`[${stageName}] ${msg}`),
|
||||
error: (msg: string) => console.error(`[${stageName}] ${msg}`),
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests: single stage executes correctly, multiple stages chain output to input, originalContent preserved across stages, missing stage logs warning and continues, stage error doesn't break pipeline, sections/metadata accumulate correctly.
|
||||
59
.taskmaster/tasks/task_081.md
Normal file
59
.taskmaster/tasks/task_081.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Task ID: 81
|
||||
|
||||
**Title:** Define Built-in ProxyModels (default, subindex)
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 78 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create the built-in proxymodel definitions for 'default' (current behavior) and 'subindex' (hierarchical navigation).
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/built-in-models.ts`:
|
||||
|
||||
```typescript
|
||||
import type { ProxyModelDefinition } from './schema';
|
||||
|
||||
export function getBuiltInProxyModels(): Map<string, ProxyModelDefinition> {
|
||||
const models = new Map<string, ProxyModelDefinition>();
|
||||
|
||||
models.set('default', {
|
||||
kind: 'ProxyModel',
|
||||
metadata: { name: 'default' },
|
||||
spec: {
|
||||
controller: 'gate',
|
||||
controllerConfig: { byteBudget: 8192 },
|
||||
stages: [
|
||||
{ type: 'passthrough' },
|
||||
{ type: 'paginate', config: { pageSize: 8000 } },
|
||||
],
|
||||
appliesTo: ['prompts', 'toolResults'],
|
||||
cacheable: false,
|
||||
},
|
||||
});
|
||||
|
||||
models.set('subindex', {
|
||||
kind: 'ProxyModel',
|
||||
metadata: { name: 'subindex' },
|
||||
spec: {
|
||||
controller: 'gate',
|
||||
controllerConfig: { byteBudget: 8192 },
|
||||
stages: [
|
||||
{ type: 'section-split', config: { minSectionSize: 2000, maxSectionSize: 15000 } },
|
||||
{ type: 'summarize-tree', config: { maxSummaryTokens: 200, maxGroupSize: 5, maxDepth: 3 } },
|
||||
],
|
||||
appliesTo: ['prompts', 'toolResults'],
|
||||
cacheable: true,
|
||||
},
|
||||
});
|
||||
|
||||
return models;
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests: both models are returned by getBuiltInProxyModels(), 'default' has passthrough+paginate stages, 'subindex' has section-split+summarize-tree stages, both schemas validate correctly.
|
||||
66
.taskmaster/tasks/task_082.md
Normal file
66
.taskmaster/tasks/task_082.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# Task ID: 82
|
||||
|
||||
**Title:** Integrate Pipeline Executor into Router
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 80 ✓, 81 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Modify the McpRouter to route content through the proxymodel pipeline, keeping the gating logic cleanly separated from content processing.
|
||||
|
||||
**Details:**
|
||||
|
||||
Modify `src/mcplocal/src/router.ts` to:
|
||||
|
||||
1. Add proxyModel resolution during router creation:
|
||||
```typescript
|
||||
import { loadProxyModels } from './proxymodel/loader';
|
||||
import { executePipeline } from './proxymodel/executor';
|
||||
|
||||
interface RouterOptions {
|
||||
proxyModelName?: string;
|
||||
// ... existing options
|
||||
}
|
||||
|
||||
async function createRouter(opts: RouterOptions): Promise<McpRouter> {
|
||||
const proxyModels = await loadProxyModels();
|
||||
const proxyModel = proxyModels.get(opts.proxyModelName ?? 'default');
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
2. Add content processing method:
|
||||
```typescript
|
||||
async processContent(
|
||||
content: string,
|
||||
type: 'prompt' | 'toolResult',
|
||||
sourceName: string,
|
||||
sessionId: string
|
||||
): Promise<StageResult> {
|
||||
if (!this.proxyModel) return { content };
|
||||
|
||||
const appliesTo = this.proxyModel.spec.appliesTo ?? ['prompts', 'toolResults'];
|
||||
if (!appliesTo.includes(type === 'prompt' ? 'prompts' : 'toolResults')) {
|
||||
return { content };
|
||||
}
|
||||
|
||||
return executePipeline({
|
||||
content,
|
||||
contentType: type,
|
||||
sourceName,
|
||||
projectName: this.projectName,
|
||||
sessionId,
|
||||
proxyModel: this.proxyModel,
|
||||
providerRegistry: this.providerRegistry,
|
||||
cache: this.cache,
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
3. Call processContent at the appropriate points in the request flow (prompt serving, tool result handling) WITHOUT interweaving with gating logic.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Integration tests: default proxymodel passes content through unchanged, subindex proxymodel produces summaries, appliesTo filtering works correctly, gating still works as before with proxymodel processing happening at the right stage.
|
||||
49
.taskmaster/tasks/task_083.md
Normal file
49
.taskmaster/tasks/task_083.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Task ID: 83
|
||||
|
||||
**Title:** Implement Section Drill-Down for Prompts
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 82 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Extend read_prompts to support section parameter for drilling into specific sections produced by proxymodel stages.
|
||||
|
||||
**Details:**
|
||||
|
||||
Modify the read_prompts handler in `src/mcplocal/src/router.ts`:
|
||||
|
||||
```typescript
|
||||
// In the read_prompts tool handler
|
||||
if (args.section) {
|
||||
// Look up section in the processed result
|
||||
const sectionId = args.section;
|
||||
const cachedResult = this.sectionCache.get(promptName);
|
||||
if (cachedResult?.sections) {
|
||||
const section = findSection(cachedResult.sections, sectionId);
|
||||
if (section) {
|
||||
return { content: [{ type: 'text', text: section.content }] };
|
||||
}
|
||||
return { content: [{ type: 'text', text: `Section '${sectionId}' not found` }], isError: true };
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to find section by ID (supports nested sections)
|
||||
function findSection(sections: Section[], id: string): Section | null {
|
||||
for (const s of sections) {
|
||||
if (s.id === id) return s;
|
||||
if (s.sections) {
|
||||
const nested = findSection(s.sections, id);
|
||||
if (nested) return nested;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
```
|
||||
|
||||
Also add a sectionCache Map to store processed results with their sections for drill-down.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Integration tests: read_prompts with section parameter returns correct section content, nested section lookup works, missing section returns error, section cache populated after initial processing.
|
||||
47
.taskmaster/tasks/task_084.md
Normal file
47
.taskmaster/tasks/task_084.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Task ID: 84
|
||||
|
||||
**Title:** Implement Section Drill-Down for Tool Results
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 82 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Extend tool result handling to support _section parameter for drilling into specific sections of large tool responses.
|
||||
|
||||
**Details:**
|
||||
|
||||
Modify tool call handling in `src/mcplocal/src/router.ts`:
|
||||
|
||||
```typescript
|
||||
// When processing tool calls
|
||||
if (args._section) {
|
||||
const sectionId = args._section;
|
||||
delete args._section; // Don't pass to upstream
|
||||
|
||||
// Check cache for previous full result
|
||||
const cacheKey = `tool:${serverName}/${toolName}:${JSON.stringify(args)}`;
|
||||
const cachedResult = this.toolResultCache.get(cacheKey);
|
||||
|
||||
if (cachedResult?.sections) {
|
||||
const section = findSection(cachedResult.sections, sectionId);
|
||||
if (section) {
|
||||
return { content: [{ type: 'text', text: section.content }] };
|
||||
}
|
||||
}
|
||||
// If no cache, make the full call and process, then serve section
|
||||
}
|
||||
|
||||
// After receiving tool result, process through pipeline
|
||||
const processed = await this.processContent(result, 'toolResult', `${serverName}/${toolName}`, sessionId);
|
||||
if (processed.sections) {
|
||||
this.toolResultCache.set(cacheKey, processed);
|
||||
}
|
||||
```
|
||||
|
||||
Add a toolResultCache Map with appropriate TTL.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Integration tests: large tool result gets processed into sections, _section parameter returns specific section, _section removed before upstream call, cache hit serves from cache, cache miss processes and caches.
|
||||
65
.taskmaster/tasks/task_085.md
Normal file
65
.taskmaster/tasks/task_085.md
Normal file
@@ -0,0 +1,65 @@
|
||||
# Task ID: 85
|
||||
|
||||
**Title:** Implement Hot-Reload for Stages
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 79 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add file watching for ~/.mcpctl/stages/ to automatically reload custom stages when they change without restarting mcplocal.
|
||||
|
||||
**Details:**
|
||||
|
||||
Modify `src/mcplocal/src/proxymodel/stage-registry.ts`:
|
||||
|
||||
```typescript
|
||||
import { watch, FSWatcher } from 'fs';
|
||||
import { join, basename } from 'path';
|
||||
|
||||
let watcher: FSWatcher | null = null;
|
||||
const stageFileHashes: Map<string, string> = new Map();
|
||||
|
||||
export function startStageWatcher(): void {
|
||||
if (watcher) return;
|
||||
|
||||
try {
|
||||
watcher = watch(STAGES_DIR, async (eventType, filename) => {
|
||||
if (!filename || (!filename.endsWith('.ts') && !filename.endsWith('.js'))) return;
|
||||
|
||||
const name = filename.replace(/\.(ts|js)$/, '');
|
||||
const fullPath = join(STAGES_DIR, filename);
|
||||
|
||||
if (eventType === 'rename') {
|
||||
// File added or removed
|
||||
await loadCustomStages();
|
||||
console.info(`[proxymodel] Stages reloaded due to ${filename} change`);
|
||||
} else if (eventType === 'change') {
|
||||
// File modified - invalidate module cache and reload
|
||||
delete require.cache[require.resolve(fullPath)];
|
||||
try {
|
||||
const module = await import(fullPath + '?t=' + Date.now());
|
||||
customStages.set(name, module.default);
|
||||
console.info(`[proxymodel] Stage '${name}' hot-reloaded`);
|
||||
} catch (err) {
|
||||
console.error(`[proxymodel] Failed to reload stage '${name}':`, err);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
// Directory doesn't exist - no watching needed
|
||||
}
|
||||
}
|
||||
|
||||
export function stopStageWatcher(): void {
|
||||
watcher?.close();
|
||||
watcher = null;
|
||||
}
|
||||
```
|
||||
|
||||
Call startStageWatcher() during mcplocal initialization.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Integration tests: modify a stage file and verify the new version is loaded without restart, add a new stage file and verify it becomes available, remove a stage file and verify it's no longer available, syntax errors in stage file don't crash the watcher.
|
||||
57
.taskmaster/tasks/task_086.md
Normal file
57
.taskmaster/tasks/task_086.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# Task ID: 86
|
||||
|
||||
**Title:** Implement Hot-Reload for ProxyModels
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 78 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add file watching for ~/.mcpctl/proxymodels/ to automatically reload proxymodel definitions when they change.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/model-watcher.ts`:
|
||||
|
||||
```typescript
|
||||
import { watch, FSWatcher } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { readFile } from 'fs/promises';
|
||||
import { parse as parseYaml } from 'yaml';
|
||||
import { ProxyModelSchema } from './schema';
|
||||
|
||||
const PROXYMODELS_DIR = join(process.env.HOME ?? '', '.mcpctl', 'proxymodels');
|
||||
let watcher: FSWatcher | null = null;
|
||||
const modelUpdateCallbacks: Set<() => void> = new Set();
|
||||
|
||||
export function onModelUpdate(callback: () => void): () => void {
|
||||
modelUpdateCallbacks.add(callback);
|
||||
return () => modelUpdateCallbacks.delete(callback);
|
||||
}
|
||||
|
||||
export function startModelWatcher(): void {
|
||||
if (watcher) return;
|
||||
|
||||
try {
|
||||
watcher = watch(PROXYMODELS_DIR, async (eventType, filename) => {
|
||||
if (!filename || (!filename.endsWith('.yaml') && !filename.endsWith('.yml'))) return;
|
||||
|
||||
console.info(`[proxymodel] Model file ${filename} changed, reloading...`);
|
||||
|
||||
// Notify all subscribers to reload their models
|
||||
for (const cb of modelUpdateCallbacks) {
|
||||
try { cb(); } catch (err) { console.error('Model update callback failed:', err); }
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
// Directory doesn't exist
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Integrate with router to reload proxymodels when files change.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Integration tests: modify a proxymodel YAML and verify changes take effect, add a new proxymodel and verify it becomes available, invalid YAML logs error but doesn't crash.
|
||||
48
.taskmaster/tasks/task_087.md
Normal file
48
.taskmaster/tasks/task_087.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# Task ID: 87
|
||||
|
||||
**Title:** Add proxyModel Field to Project Schema
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Extend the Project database schema and API to support proxyModel field and proxyModelOverrides for per-content-type configuration.
|
||||
|
||||
**Details:**
|
||||
|
||||
Update `src/db/prisma/schema.prisma`:
|
||||
|
||||
```prisma
|
||||
model Project {
|
||||
// ... existing fields
|
||||
proxyModel String? @default("default")
|
||||
proxyModelOverrides Json? // { prompts: { "prompt-name": "model" }, toolResults: { "server/tool": "model" } }
|
||||
}
|
||||
```
|
||||
|
||||
Run `npx prisma migrate dev --name add_proxymodel_field`.
|
||||
|
||||
Update `src/mcpd/src/routes/projects.ts` to include the new fields in CRUD operations.
|
||||
|
||||
Update `src/cli/src/commands/get.ts` and `describe.ts` to display proxyModel.
|
||||
|
||||
Update `src/cli/src/commands/patch.ts` to support `--set proxyModel=<name>`.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Database migration test: verify migration applies cleanly. API tests: verify proxyModel field is returned in project GET, can be updated via PATCH. CLI tests: verify `mcpctl describe project <name>` shows proxyModel.
|
||||
|
||||
## Subtasks
|
||||
|
||||
### 87.1. Minimal placeholder subtask
|
||||
|
||||
**Status:** pending
|
||||
**Dependencies:** None
|
||||
|
||||
This task requires complete rewrite before expansion.
|
||||
|
||||
**Details:**
|
||||
|
||||
Task 87 has been marked as DO NOT EXPAND and needs to be completely rewritten first. No subtasks should be generated until the task is properly redefined.
|
||||
38
.taskmaster/tasks/task_088.md
Normal file
38
.taskmaster/tasks/task_088.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# Task ID: 88
|
||||
|
||||
**Title:** Rename proxyMode: filtered to proxyMode: proxy
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 87 ✗
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Rename the existing proxyMode value 'filtered' to 'proxy' for clarity, with backwards compatibility for existing configs.
|
||||
|
||||
**Details:**
|
||||
|
||||
Update `src/db/prisma/schema.prisma`:
|
||||
|
||||
```prisma
|
||||
enum ProxyMode {
|
||||
direct
|
||||
proxy // renamed from 'filtered'
|
||||
}
|
||||
```
|
||||
|
||||
Create migration that updates existing 'filtered' values to 'proxy':
|
||||
```sql
|
||||
UPDATE Project SET proxyMode = 'proxy' WHERE proxyMode = 'filtered';
|
||||
```
|
||||
|
||||
Update all code references from 'filtered' to 'proxy':
|
||||
- `src/mcplocal/src/http/project-mcp-endpoint.ts`
|
||||
- `src/cli/src/commands/create.ts`
|
||||
- Documentation and help text
|
||||
|
||||
For backwards compatibility in config files, add a normalization step that treats 'filtered' as 'proxy'.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Migration test: existing projects with proxyMode='filtered' are updated to 'proxy'. Config parsing test: both 'filtered' and 'proxy' values work. CLI test: help text shows 'proxy' not 'filtered'.
|
||||
53
.taskmaster/tasks/task_089.md
Normal file
53
.taskmaster/tasks/task_089.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Task ID: 89
|
||||
|
||||
**Title:** Implement mcpctl get proxymodels Command
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 78 ✓, 79 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add CLI command to list all available proxymodels (built-in + local) with source, stages, and requirements.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/get-proxymodels.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { loadProxyModels } from 'mcplocal/proxymodel/loader';
|
||||
import { listStages } from 'mcplocal/proxymodel/stage-registry';
|
||||
import Table from 'cli-table3';
|
||||
|
||||
export function registerGetProxymodels(program: Command): void {
|
||||
program
|
||||
.command('get proxymodels')
|
||||
.description('List all available proxymodels')
|
||||
.action(async () => {
|
||||
const models = await loadProxyModels();
|
||||
const stageInfo = new Map(listStages().map(s => [s.name, s]));
|
||||
|
||||
const table = new Table({
|
||||
head: ['NAME', 'SOURCE', 'STAGES', 'REQUIRES-LLM', 'CACHEABLE'],
|
||||
});
|
||||
|
||||
for (const [name, model] of models) {
|
||||
const source = isBuiltIn(name) ? 'built-in' : 'local';
|
||||
const stages = model.spec.stages.map(s => s.type).join(',');
|
||||
const requiresLlm = model.spec.stages.some(s => stageRequiresLlm(s.type));
|
||||
const cacheable = model.spec.cacheable ? 'yes' : 'no';
|
||||
|
||||
table.push([name, source, stages, requiresLlm ? 'yes' : 'no', cacheable]);
|
||||
}
|
||||
|
||||
console.log(table.toString());
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
Register in `src/cli/src/commands/get.ts` as a subcommand.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: `mcpctl get proxymodels` outputs table with expected columns. Test with only built-ins, test with local overrides, verify correct source detection.
|
||||
47
.taskmaster/tasks/task_090.md
Normal file
47
.taskmaster/tasks/task_090.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Task ID: 90
|
||||
|
||||
**Title:** Implement mcpctl get stages Command
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 79 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add CLI command to list all available stages (built-in + custom) with source and LLM requirements.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/get-stages.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { listStages } from 'mcplocal/proxymodel/stage-registry';
|
||||
import Table from 'cli-table3';
|
||||
|
||||
const LLM_REQUIRING_STAGES = ['summarize', 'summarize-tree', 'enhance', 'compress'];
|
||||
|
||||
export function registerGetStages(program: Command): void {
|
||||
program
|
||||
.command('get stages')
|
||||
.description('List all available stages')
|
||||
.action(async () => {
|
||||
const stages = listStages();
|
||||
|
||||
const table = new Table({
|
||||
head: ['NAME', 'SOURCE', 'REQUIRES-LLM'],
|
||||
});
|
||||
|
||||
for (const stage of stages) {
|
||||
const requiresLlm = LLM_REQUIRING_STAGES.includes(stage.name);
|
||||
table.push([stage.name, stage.source, requiresLlm ? 'yes' : 'no']);
|
||||
}
|
||||
|
||||
console.log(table.toString());
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: `mcpctl get stages` outputs table with expected columns. Test with only built-ins, test with custom stages in ~/.mcpctl/stages/, verify custom overrides show 'local' source.
|
||||
57
.taskmaster/tasks/task_091.md
Normal file
57
.taskmaster/tasks/task_091.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# Task ID: 91
|
||||
|
||||
**Title:** Implement mcpctl describe proxymodel Command
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 78 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add CLI command to show detailed information about a specific proxymodel including full stage configuration.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/describe-proxymodel.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { loadProxyModels } from 'mcplocal/proxymodel/loader';
|
||||
import { stringify as yamlStringify } from 'yaml';
|
||||
|
||||
export function registerDescribeProxymodel(program: Command): void {
|
||||
program
|
||||
.command('describe proxymodel <name>')
|
||||
.description('Show detailed information about a proxymodel')
|
||||
.action(async (name: string) => {
|
||||
const models = await loadProxyModels();
|
||||
const model = models.get(name);
|
||||
|
||||
if (!model) {
|
||||
console.error(`Proxymodel '${name}' not found`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Name: ${model.metadata.name}`);
|
||||
console.log(`Source: ${isBuiltIn(name) ? 'built-in' : 'local'}`);
|
||||
console.log(`Controller: ${model.spec.controller ?? 'gate'}`);
|
||||
console.log(`Cacheable: ${model.spec.cacheable ? 'yes' : 'no'}`);
|
||||
console.log(`Applies to: ${(model.spec.appliesTo ?? ['prompts', 'toolResults']).join(', ')}`);
|
||||
console.log('');
|
||||
console.log('Stages:');
|
||||
for (const stage of model.spec.stages) {
|
||||
console.log(` - ${stage.type}`);
|
||||
if (stage.config) {
|
||||
console.log(` config:`);
|
||||
for (const [k, v] of Object.entries(stage.config)) {
|
||||
console.log(` ${k}: ${JSON.stringify(v)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: `mcpctl describe proxymodel default` shows expected output. Test with proxymodel that has stage configs, verify all fields displayed correctly.
|
||||
57
.taskmaster/tasks/task_092.md
Normal file
57
.taskmaster/tasks/task_092.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# Task ID: 92
|
||||
|
||||
**Title:** Implement mcpctl describe stage Command
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 79 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add CLI command to show detailed information about a specific stage including its source location.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/describe-stage.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { listStages, getStage } from 'mcplocal/proxymodel/stage-registry';
|
||||
import { join } from 'path';
|
||||
|
||||
const STAGES_DIR = join(process.env.HOME ?? '', '.mcpctl', 'stages');
|
||||
|
||||
const STAGE_DESCRIPTIONS: Record<string, string> = {
|
||||
'passthrough': 'Returns content unchanged. No processing.',
|
||||
'paginate': 'Splits large content into pages with navigation.',
|
||||
'section-split': 'Splits content on structural boundaries (headers, JSON keys, etc.).',
|
||||
'summarize-tree': 'Recursively summarizes sections with hierarchical navigation.',
|
||||
};
|
||||
|
||||
export function registerDescribeStage(program: Command): void {
|
||||
program
|
||||
.command('describe stage <name>')
|
||||
.description('Show detailed information about a stage')
|
||||
.action(async (name: string) => {
|
||||
const stages = listStages();
|
||||
const stageInfo = stages.find(s => s.name === name);
|
||||
|
||||
if (!stageInfo) {
|
||||
console.error(`Stage '${name}' not found`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Name: ${name}`);
|
||||
console.log(`Source: ${stageInfo.source}`);
|
||||
if (stageInfo.source === 'local') {
|
||||
console.log(`Path: ${join(STAGES_DIR, name + '.ts')}`);
|
||||
}
|
||||
console.log(`Description: ${STAGE_DESCRIPTIONS[name] ?? 'Custom stage'}`);
|
||||
console.log(`Requires LLM: ${requiresLlm(name) ? 'yes' : 'no'}`);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: `mcpctl describe stage passthrough` shows expected output. Test with custom stage, verify path is shown correctly.
|
||||
73
.taskmaster/tasks/task_093.md
Normal file
73
.taskmaster/tasks/task_093.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# Task ID: 93
|
||||
|
||||
**Title:** Implement mcpctl create stage Command
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 71 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add CLI command to scaffold a new custom stage with boilerplate TypeScript code.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/create-stage.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { mkdir, writeFile, access } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
|
||||
const STAGES_DIR = join(process.env.HOME ?? '', '.mcpctl', 'stages');
|
||||
|
||||
const STAGE_TEMPLATE = `import type { StageHandler } from 'mcpctl/proxymodel';
|
||||
|
||||
/**
|
||||
* Custom stage: {{name}}
|
||||
*
|
||||
* Modify this handler to transform content as needed.
|
||||
* Available in ctx:
|
||||
* - ctx.llm.complete(prompt) - call the configured LLM
|
||||
* - ctx.cache.getOrCompute(key, fn) - cache expensive computations
|
||||
* - ctx.config - stage configuration from proxymodel YAML
|
||||
* - ctx.originalContent - raw content before any stage processing
|
||||
* - ctx.log - structured logging
|
||||
*/
|
||||
const handler: StageHandler = async (content, ctx) => {
|
||||
// TODO: Implement your transformation
|
||||
return { content };
|
||||
};
|
||||
|
||||
export default handler;
|
||||
`;
|
||||
|
||||
export function registerCreateStage(program: Command): void {
|
||||
program
|
||||
.command('create stage <name>')
|
||||
.description('Create a new custom stage')
|
||||
.action(async (name: string) => {
|
||||
await mkdir(STAGES_DIR, { recursive: true });
|
||||
|
||||
const filePath = join(STAGES_DIR, `${name}.ts`);
|
||||
|
||||
try {
|
||||
await access(filePath);
|
||||
console.error(`Stage '${name}' already exists at ${filePath}`);
|
||||
process.exit(1);
|
||||
} catch {
|
||||
// File doesn't exist, good
|
||||
}
|
||||
|
||||
const code = STAGE_TEMPLATE.replace(/\{\{name\}\}/g, name);
|
||||
await writeFile(filePath, code);
|
||||
|
||||
console.log(`Created ${filePath}`);
|
||||
console.log('Edit the file to implement your stage logic.');
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: `mcpctl create stage my-filter` creates file at expected path with correct template. Test error when stage already exists. Verify generated code compiles.
|
||||
66
.taskmaster/tasks/task_094.md
Normal file
66
.taskmaster/tasks/task_094.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# Task ID: 94
|
||||
|
||||
**Title:** Implement mcpctl create proxymodel Command
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 78 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add CLI command to scaffold a new proxymodel YAML file with specified stages.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/create-proxymodel.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { mkdir, writeFile, access } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { stringify as yamlStringify } from 'yaml';
|
||||
|
||||
const PROXYMODELS_DIR = join(process.env.HOME ?? '', '.mcpctl', 'proxymodels');
|
||||
|
||||
export function registerCreateProxymodel(program: Command): void {
|
||||
program
|
||||
.command('create proxymodel <name>')
|
||||
.description('Create a new proxymodel')
|
||||
.option('--stages <stages>', 'Comma-separated list of stage names', 'passthrough')
|
||||
.option('--controller <controller>', 'Session controller (gate or none)', 'gate')
|
||||
.action(async (name: string, opts) => {
|
||||
await mkdir(PROXYMODELS_DIR, { recursive: true });
|
||||
|
||||
const filePath = join(PROXYMODELS_DIR, `${name}.yaml`);
|
||||
|
||||
try {
|
||||
await access(filePath);
|
||||
console.error(`Proxymodel '${name}' already exists at ${filePath}`);
|
||||
process.exit(1);
|
||||
} catch {
|
||||
// File doesn't exist, good
|
||||
}
|
||||
|
||||
const stages = opts.stages.split(',').map((s: string) => ({ type: s.trim() }));
|
||||
|
||||
const model = {
|
||||
kind: 'ProxyModel',
|
||||
metadata: { name },
|
||||
spec: {
|
||||
controller: opts.controller,
|
||||
stages,
|
||||
appliesTo: ['prompts', 'toolResults'],
|
||||
cacheable: true,
|
||||
},
|
||||
};
|
||||
|
||||
await writeFile(filePath, yamlStringify(model));
|
||||
|
||||
console.log(`Created ${filePath}`);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: `mcpctl create proxymodel my-pipeline --stages summarize,compress` creates valid YAML. Test default values. Verify generated YAML validates against schema.
|
||||
70
.taskmaster/tasks/task_095.md
Normal file
70
.taskmaster/tasks/task_095.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# Task ID: 95
|
||||
|
||||
**Title:** Implement mcpctl proxymodel validate Command
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 78 ✓, 79 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add CLI command to validate a proxymodel definition, checking that all stages resolve and config is valid.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/proxymodel-validate.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { loadProxyModels } from 'mcplocal/proxymodel/loader';
|
||||
import { getStage, loadCustomStages } from 'mcplocal/proxymodel/stage-registry';
|
||||
|
||||
export function registerProxymodelValidate(program: Command): void {
|
||||
program
|
||||
.command('proxymodel validate <name>')
|
||||
.description('Validate a proxymodel definition')
|
||||
.action(async (name: string) => {
|
||||
await loadCustomStages();
|
||||
const models = await loadProxyModels();
|
||||
const model = models.get(name);
|
||||
|
||||
if (!model) {
|
||||
console.error(`Proxymodel '${name}' not found`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let valid = true;
|
||||
const errors: string[] = [];
|
||||
|
||||
// Check all stages resolve
|
||||
for (const stageConfig of model.spec.stages) {
|
||||
const stage = getStage(stageConfig.type);
|
||||
if (!stage) {
|
||||
errors.push(`Stage '${stageConfig.type}' not found`);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check controller is valid
|
||||
const validControllers = ['gate', 'none'];
|
||||
if (model.spec.controller && !validControllers.includes(model.spec.controller)) {
|
||||
errors.push(`Unknown controller '${model.spec.controller}'`);
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
console.log(`✓ Proxymodel '${name}' is valid`);
|
||||
} else {
|
||||
console.error(`✗ Proxymodel '${name}' has errors:`);
|
||||
for (const err of errors) {
|
||||
console.error(` - ${err}`);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: valid proxymodel passes, proxymodel with unknown stage fails with clear error, proxymodel with unknown controller fails. Test with both built-in and custom stages.
|
||||
53
.taskmaster/tasks/task_096.md
Normal file
53
.taskmaster/tasks/task_096.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Task ID: 96
|
||||
|
||||
**Title:** Implement mcpctl delete stage Command
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 79 ✓
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Add CLI command to delete a custom stage file (cannot delete built-ins).
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/delete-stage.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { unlink, access } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { listStages } from 'mcplocal/proxymodel/stage-registry';
|
||||
|
||||
const STAGES_DIR = join(process.env.HOME ?? '', '.mcpctl', 'stages');
|
||||
|
||||
export function registerDeleteStage(program: Command): void {
|
||||
program
|
||||
.command('delete stage <name>')
|
||||
.description('Delete a custom stage')
|
||||
.action(async (name: string) => {
|
||||
const stages = listStages();
|
||||
const stageInfo = stages.find(s => s.name === name);
|
||||
|
||||
if (!stageInfo) {
|
||||
console.error(`Stage '${name}' not found`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (stageInfo.source === 'built-in') {
|
||||
console.error(`Cannot delete built-in stage '${name}'`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const filePath = join(STAGES_DIR, `${name}.ts`);
|
||||
await unlink(filePath);
|
||||
|
||||
console.log(`Deleted ${filePath}`);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: can delete custom stage, cannot delete built-in stage (error message), deleting non-existent stage shows error.
|
||||
64
.taskmaster/tasks/task_097.md
Normal file
64
.taskmaster/tasks/task_097.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# Task ID: 97
|
||||
|
||||
**Title:** Implement mcpctl delete proxymodel Command
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 78 ✓
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Add CLI command to delete a local proxymodel YAML file (cannot delete built-ins).
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/delete-proxymodel.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { unlink, access } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { loadProxyModels } from 'mcplocal/proxymodel/loader';
|
||||
import { getBuiltInProxyModels } from 'mcplocal/proxymodel/built-in-models';
|
||||
|
||||
const PROXYMODELS_DIR = join(process.env.HOME ?? '', '.mcpctl', 'proxymodels');
|
||||
|
||||
export function registerDeleteProxymodel(program: Command): void {
|
||||
program
|
||||
.command('delete proxymodel <name>')
|
||||
.description('Delete a local proxymodel')
|
||||
.action(async (name: string) => {
|
||||
const models = await loadProxyModels();
|
||||
const builtIns = getBuiltInProxyModels();
|
||||
|
||||
if (!models.has(name)) {
|
||||
console.error(`Proxymodel '${name}' not found`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const filePath = join(PROXYMODELS_DIR, `${name}.yaml`);
|
||||
|
||||
try {
|
||||
await access(filePath);
|
||||
} catch {
|
||||
if (builtIns.has(name)) {
|
||||
console.error(`Cannot delete built-in proxymodel '${name}'`);
|
||||
} else {
|
||||
console.error(`Proxymodel '${name}' file not found at ${filePath}`);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await unlink(filePath);
|
||||
console.log(`Deleted ${filePath}`);
|
||||
|
||||
if (builtIns.has(name)) {
|
||||
console.log(`Note: Built-in '${name}' will still be available`);
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: can delete local proxymodel, cannot delete built-in (error message), deleting local override shows note about built-in fallback.
|
||||
79
.taskmaster/tasks/task_098.md
Normal file
79
.taskmaster/tasks/task_098.md
Normal file
@@ -0,0 +1,79 @@
|
||||
# Task ID: 98
|
||||
|
||||
**Title:** Implement Persistent File Cache for Stages
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 73 ✓
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Extend CacheProvider with file-based persistence in ~/.mcpctl/cache/proxymodel/ for cross-session caching.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/file-cache.ts`:
|
||||
|
||||
```typescript
|
||||
import { mkdir, readFile, writeFile, readdir, stat, unlink } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { createHash } from 'crypto';
|
||||
import type { CacheProvider } from './types';
|
||||
|
||||
const CACHE_DIR = join(process.env.HOME ?? '', '.mcpctl', 'cache', 'proxymodel');
|
||||
|
||||
export class FileCacheProvider implements CacheProvider {
|
||||
private memCache = new Map<string, string>();
|
||||
private maxSizeBytes: number;
|
||||
|
||||
constructor(options: { maxSizeBytes?: number } = {}) {
|
||||
this.maxSizeBytes = options.maxSizeBytes ?? 100 * 1024 * 1024; // 100MB default
|
||||
}
|
||||
|
||||
hash(content: string): string {
|
||||
return createHash('sha256').update(content).digest('hex').slice(0, 16);
|
||||
}
|
||||
|
||||
private keyToPath(key: string): string {
|
||||
const safeKey = key.replace(/[^a-zA-Z0-9-_]/g, '_');
|
||||
return join(CACHE_DIR, safeKey);
|
||||
}
|
||||
|
||||
async get(key: string): Promise<string | null> {
|
||||
// Check memory first
|
||||
if (this.memCache.has(key)) return this.memCache.get(key)!;
|
||||
|
||||
// Check file
|
||||
try {
|
||||
const content = await readFile(this.keyToPath(key), 'utf-8');
|
||||
this.memCache.set(key, content); // Warm memory cache
|
||||
return content;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async set(key: string, value: string): Promise<void> {
|
||||
await mkdir(CACHE_DIR, { recursive: true });
|
||||
this.memCache.set(key, value);
|
||||
await writeFile(this.keyToPath(key), value);
|
||||
await this.enforceMaxSize();
|
||||
}
|
||||
|
||||
async getOrCompute(key: string, compute: () => Promise<string>): Promise<string> {
|
||||
const cached = await this.get(key);
|
||||
if (cached !== null) return cached;
|
||||
const value = await compute();
|
||||
await this.set(key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private async enforceMaxSize(): Promise<void> {
|
||||
// LRU eviction based on file mtime when cache exceeds maxSizeBytes
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests: file-based persistence survives process restart, memory cache is warmed on file read, LRU eviction works when size exceeded, concurrent access is safe. Integration test with real filesystem.
|
||||
61
.taskmaster/tasks/task_099.md
Normal file
61
.taskmaster/tasks/task_099.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# Task ID: 99
|
||||
|
||||
**Title:** Add Cache Key with Stage File Hash
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 98 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Include the stage file hash in cache keys so cached artifacts are automatically invalidated when stage code changes.
|
||||
|
||||
**Details:**
|
||||
|
||||
Modify `src/mcplocal/src/proxymodel/executor.ts`:
|
||||
|
||||
```typescript
|
||||
import { readFile, stat } from 'fs/promises';
|
||||
import { createHash } from 'crypto';
|
||||
import { join } from 'path';
|
||||
|
||||
const STAGES_DIR = join(process.env.HOME ?? '', '.mcpctl', 'stages');
|
||||
const stageFileHashes: Map<string, string> = new Map();
|
||||
|
||||
async function getStageFileHash(stageName: string): Promise<string> {
|
||||
// Check if custom stage file exists
|
||||
const filePath = join(STAGES_DIR, `${stageName}.ts`);
|
||||
try {
|
||||
const content = await readFile(filePath, 'utf-8');
|
||||
const hash = createHash('sha256').update(content).digest('hex').slice(0, 8);
|
||||
stageFileHashes.set(stageName, hash);
|
||||
return hash;
|
||||
} catch {
|
||||
// Built-in stage, use version-based hash or fixed value
|
||||
return 'builtin-v1';
|
||||
}
|
||||
}
|
||||
|
||||
// In executePipeline, compute cache key:
|
||||
const stageHash = await getStageFileHash(stageConfig.type);
|
||||
const cacheKey = [
|
||||
'stage',
|
||||
stageConfig.type,
|
||||
stageHash,
|
||||
cache.hash(currentContent),
|
||||
cache.hash(JSON.stringify(stageConfig.config ?? {})),
|
||||
].join(':');
|
||||
|
||||
// Use pipeline-level cache wrapping:
|
||||
if (proxyModel.spec.cacheable) {
|
||||
const cached = await cache.get(cacheKey);
|
||||
if (cached) {
|
||||
currentContent = cached;
|
||||
continue; // Skip stage execution
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests: changing stage file content changes the hash, built-in stages have stable hash, cache miss when stage file changes, cache hit when stage file unchanged.
|
||||
77
.taskmaster/tasks/task_100.md
Normal file
77
.taskmaster/tasks/task_100.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# Task ID: 100
|
||||
|
||||
**Title:** Implement mcpctl cache list Command
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 98 ✓
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Add CLI command to list cached proxymodel artifacts with size and age information.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/cache-list.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { readdir, stat } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import Table from 'cli-table3';
|
||||
|
||||
const CACHE_DIR = join(process.env.HOME ?? '', '.mcpctl', 'cache', 'proxymodel');
|
||||
|
||||
export function registerCacheList(program: Command): void {
|
||||
program
|
||||
.command('cache list')
|
||||
.description('List cached proxymodel artifacts')
|
||||
.option('--project <name>', 'Filter by project')
|
||||
.action(async (opts) => {
|
||||
try {
|
||||
const files = await readdir(CACHE_DIR);
|
||||
|
||||
const table = new Table({
|
||||
head: ['KEY', 'SIZE', 'AGE'],
|
||||
});
|
||||
|
||||
let totalSize = 0;
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = join(CACHE_DIR, file);
|
||||
const stats = await stat(filePath);
|
||||
const age = formatAge(Date.now() - stats.mtimeMs);
|
||||
const size = formatSize(stats.size);
|
||||
totalSize += stats.size;
|
||||
|
||||
if (opts.project && !file.includes(opts.project)) continue;
|
||||
|
||||
table.push([file, size, age]);
|
||||
}
|
||||
|
||||
console.log(table.toString());
|
||||
console.log(`Total: ${formatSize(totalSize)}`);
|
||||
} catch {
|
||||
console.log('No cache entries found');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function formatSize(bytes: number): string {
|
||||
if (bytes < 1024) return `${bytes}B`;
|
||||
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
||||
return `${(bytes / 1024 / 1024).toFixed(1)}MB`;
|
||||
}
|
||||
|
||||
function formatAge(ms: number): string {
|
||||
const mins = Math.floor(ms / 60000);
|
||||
if (mins < 60) return `${mins}m`;
|
||||
const hours = Math.floor(mins / 60);
|
||||
if (hours < 24) return `${hours}h`;
|
||||
return `${Math.floor(hours / 24)}d`;
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: list shows cache entries with correct format, --project filter works, empty cache shows appropriate message, size/age formatting is correct.
|
||||
61
.taskmaster/tasks/task_101.md
Normal file
61
.taskmaster/tasks/task_101.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# Task ID: 101
|
||||
|
||||
**Title:** Implement mcpctl cache clear Command
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 98 ✓
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Add CLI command to clear the proxymodel cache, optionally filtered by project.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/cache-clear.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { readdir, unlink, rmdir } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
|
||||
const CACHE_DIR = join(process.env.HOME ?? '', '.mcpctl', 'cache', 'proxymodel');
|
||||
|
||||
export function registerCacheClear(program: Command): void {
|
||||
program
|
||||
.command('cache clear')
|
||||
.description('Clear the proxymodel cache')
|
||||
.option('--project <name>', 'Clear only cache for a specific project')
|
||||
.option('--force', 'Skip confirmation', false)
|
||||
.action(async (opts) => {
|
||||
try {
|
||||
const files = await readdir(CACHE_DIR);
|
||||
const toDelete = opts.project
|
||||
? files.filter(f => f.includes(opts.project))
|
||||
: files;
|
||||
|
||||
if (toDelete.length === 0) {
|
||||
console.log('No cache entries to clear');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!opts.force) {
|
||||
console.log(`This will delete ${toDelete.length} cache entries.`);
|
||||
// Add confirmation prompt
|
||||
}
|
||||
|
||||
for (const file of toDelete) {
|
||||
await unlink(join(CACHE_DIR, file));
|
||||
}
|
||||
|
||||
console.log(`Cleared ${toDelete.length} cache entries`);
|
||||
} catch {
|
||||
console.log('Cache directory does not exist');
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: clears all entries without --project, clears filtered entries with --project, confirmation required without --force, --force skips confirmation.
|
||||
60
.taskmaster/tasks/task_102.md
Normal file
60
.taskmaster/tasks/task_102.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# Task ID: 102
|
||||
|
||||
**Title:** Implement mcpctl cache stats Command
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 98 ✓
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Add CLI command to show cache statistics including hit rates, total size, and entry counts.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/cache-stats.ts`:
|
||||
|
||||
```typescript
|
||||
import { Command } from 'commander';
|
||||
import { readdir, stat } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
|
||||
const CACHE_DIR = join(process.env.HOME ?? '', '.mcpctl', 'cache', 'proxymodel');
|
||||
|
||||
export function registerCacheStats(program: Command): void {
|
||||
program
|
||||
.command('cache stats')
|
||||
.description('Show cache statistics')
|
||||
.action(async () => {
|
||||
try {
|
||||
const files = await readdir(CACHE_DIR);
|
||||
|
||||
let totalSize = 0;
|
||||
let oldest = Date.now();
|
||||
let newest = 0;
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = join(CACHE_DIR, file);
|
||||
const stats = await stat(filePath);
|
||||
totalSize += stats.size;
|
||||
oldest = Math.min(oldest, stats.mtimeMs);
|
||||
newest = Math.max(newest, stats.mtimeMs);
|
||||
}
|
||||
|
||||
console.log(`Entries: ${files.length}`);
|
||||
console.log(`Total size: ${formatSize(totalSize)}`);
|
||||
console.log(`Oldest entry: ${formatAge(Date.now() - oldest)} ago`);
|
||||
console.log(`Newest entry: ${formatAge(Date.now() - newest)} ago`);
|
||||
|
||||
// Note: hit rate tracking would require runtime instrumentation
|
||||
console.log('\nNote: Hit rate statistics require runtime instrumentation.');
|
||||
} catch {
|
||||
console.log('No cache data available');
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
CLI test: shows correct stats for populated cache, handles empty cache gracefully, size formatting is correct.
|
||||
47
.taskmaster/tasks/task_103.md
Normal file
47
.taskmaster/tasks/task_103.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Task ID: 103
|
||||
|
||||
**Title:** Add Shell Completions for ProxyModel Commands
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 89 ✗, 90 ✗, 91 ✗, 92 ✗, 93 ✗, 94 ✗, 95 ✗, 96 ✗, 97 ✗, 100 ✓, 101 ✓, 102 ✓
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Extend shell completions to include all new proxymodel-related commands, resources, and flags.
|
||||
|
||||
**Details:**
|
||||
|
||||
Update `src/cli/src/completions.ts` to add completions for:
|
||||
|
||||
```typescript
|
||||
// Resource types
|
||||
const RESOURCE_TYPES = [...existing, 'proxymodels', 'stages'];
|
||||
|
||||
// Command completions
|
||||
const COMMANDS = {
|
||||
'get': ['proxymodels', 'stages', ...existing],
|
||||
'describe': ['proxymodel', 'stage', ...existing],
|
||||
'create': ['proxymodel', 'stage', ...existing],
|
||||
'delete': ['proxymodel', 'stage', ...existing],
|
||||
'proxymodel': ['validate'],
|
||||
'cache': ['list', 'clear', 'stats'],
|
||||
};
|
||||
|
||||
// Dynamic completions for proxymodel/stage names
|
||||
async function completeProxymodelName(partial: string): Promise<string[]> {
|
||||
const models = await loadProxyModels();
|
||||
return [...models.keys()].filter(n => n.startsWith(partial));
|
||||
}
|
||||
|
||||
async function completeStageName(partial: string): Promise<string[]> {
|
||||
const stages = listStages();
|
||||
return stages.map(s => s.name).filter(n => n.startsWith(partial));
|
||||
}
|
||||
```
|
||||
|
||||
Generate completion scripts for bash, zsh, and fish.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Manual test: completions work in bash/zsh/fish for all new commands. Test proxymodel name completion, stage name completion, subcommand completion.
|
||||
67
.taskmaster/tasks/task_104.md
Normal file
67
.taskmaster/tasks/task_104.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Task ID: 104
|
||||
|
||||
**Title:** Extend Traffic Events for ProxyModel Processing
|
||||
|
||||
**Status:** cancelled
|
||||
|
||||
**Dependencies:** 80 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add new traffic event types for proxymodel processing: content_original, content_transformed, stage timing, cache hits/misses.
|
||||
|
||||
**Details:**
|
||||
|
||||
Modify `src/mcplocal/src/http/traffic.ts`:
|
||||
|
||||
```typescript
|
||||
export type TrafficEventType =
|
||||
| 'client_request'
|
||||
| 'client_response'
|
||||
| 'upstream_request'
|
||||
| 'upstream_response'
|
||||
| 'client_notification'
|
||||
// New proxymodel events:
|
||||
| 'content_original'
|
||||
| 'content_transformed'
|
||||
| 'stage_executed'
|
||||
| 'stage_cache_hit'
|
||||
| 'stage_cache_miss';
|
||||
|
||||
export interface ContentOriginalEvent {
|
||||
eventType: 'content_original';
|
||||
sessionId: string;
|
||||
contentType: 'prompt' | 'toolResult';
|
||||
sourceName: string;
|
||||
content: string;
|
||||
charCount: number;
|
||||
}
|
||||
|
||||
export interface ContentTransformedEvent {
|
||||
eventType: 'content_transformed';
|
||||
sessionId: string;
|
||||
contentType: 'prompt' | 'toolResult';
|
||||
sourceName: string;
|
||||
content: string;
|
||||
charCount: number;
|
||||
proxyModel: string;
|
||||
stages: string[];
|
||||
durationMs: number;
|
||||
}
|
||||
|
||||
export interface StageExecutedEvent {
|
||||
eventType: 'stage_executed';
|
||||
sessionId: string;
|
||||
stageName: string;
|
||||
inputChars: number;
|
||||
outputChars: number;
|
||||
durationMs: number;
|
||||
cacheHit: boolean;
|
||||
}
|
||||
```
|
||||
|
||||
Emit these events from the pipeline executor.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests: events emitted at correct points in pipeline execution, event payloads contain correct data, cache hit/miss events distinguish correctly. Integration test with inspector showing new events.
|
||||
83
.taskmaster/tasks/task_105.md
Normal file
83
.taskmaster/tasks/task_105.md
Normal file
@@ -0,0 +1,83 @@
|
||||
# Task ID: 105
|
||||
|
||||
**Title:** Implement Model Studio TUI Base
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 104 ✗
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Create the base TUI for mcpctl console --model-studio that extends --inspect with original vs transformed view.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/cli/src/commands/console/model-studio.tsx`:
|
||||
|
||||
```typescript
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Box, Text, useInput } from 'ink';
|
||||
import { TrafficEvent } from './types';
|
||||
|
||||
interface ModelStudioProps {
|
||||
projectName: string;
|
||||
events: TrafficEvent[];
|
||||
}
|
||||
|
||||
export function ModelStudio({ projectName, events }: ModelStudioProps) {
|
||||
const [selectedIdx, setSelectedIdx] = useState(0);
|
||||
const [viewMode, setViewMode] = useState<'original' | 'transformed' | 'diff'>('transformed');
|
||||
const [pauseMode, setPauseMode] = useState(false);
|
||||
|
||||
useInput((input, key) => {
|
||||
if (input === 'j') setSelectedIdx(i => Math.min(i + 1, events.length - 1));
|
||||
if (input === 'k') setSelectedIdx(i => Math.max(i - 1, 0));
|
||||
if (input === 'o') setViewMode(m => m === 'original' ? 'transformed' : m === 'transformed' ? 'diff' : 'original');
|
||||
if (input === 'p') setPauseMode(p => !p);
|
||||
if (input === 'G') setSelectedIdx(events.length - 1);
|
||||
});
|
||||
|
||||
const selected = events[selectedIdx];
|
||||
const isContentEvent = selected?.eventType === 'content_original' || selected?.eventType === 'content_transformed';
|
||||
|
||||
return (
|
||||
<Box flexDirection="column" height="100%">
|
||||
<Box borderStyle="single" padding={1}>
|
||||
<Text>Model Studio: {projectName}</Text>
|
||||
<Text> | </Text>
|
||||
<Text>View: {viewMode}</Text>
|
||||
<Text> | </Text>
|
||||
<Text color={pauseMode ? 'red' : 'green'}>{pauseMode ? '⏸ PAUSED' : '▶ LIVE'}</Text>
|
||||
</Box>
|
||||
|
||||
<Box flexGrow={1} flexDirection="row">
|
||||
{/* Event list sidebar */}
|
||||
<Box width="30%" borderStyle="single">
|
||||
{events.map((e, i) => (
|
||||
<Text key={i} inverse={i === selectedIdx}>
|
||||
{formatEventLine(e)}
|
||||
</Text>
|
||||
))}
|
||||
</Box>
|
||||
|
||||
{/* Content view */}
|
||||
<Box width="70%" borderStyle="single">
|
||||
{isContentEvent && (
|
||||
<ContentView event={selected} mode={viewMode} />
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Box borderStyle="single">
|
||||
<Text>[o] toggle view [p] pause [j/k] navigate [G] latest [q] quit</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Add --model-studio flag to console command.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Manual test: TUI renders correctly, keyboard navigation works, original/transformed/diff views switch correctly, pause indicator shows correctly.
|
||||
97
.taskmaster/tasks/task_106.md
Normal file
97
.taskmaster/tasks/task_106.md
Normal file
@@ -0,0 +1,97 @@
|
||||
# Task ID: 106
|
||||
|
||||
**Title:** Implement Pause Queue for Model Studio
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 105 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add a pause queue in mcplocal that holds outgoing responses when model studio pause mode is active.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/src/proxymodel/pause-queue.ts`:
|
||||
|
||||
```typescript
|
||||
interface PausedResponse {
|
||||
id: string;
|
||||
sessionId: string;
|
||||
contentType: 'prompt' | 'toolResult';
|
||||
sourceName: string;
|
||||
original: string;
|
||||
transformed: string;
|
||||
resolve: (content: string) => void;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
class PauseQueue {
|
||||
private paused = false;
|
||||
private queue: PausedResponse[] = [];
|
||||
private listeners = new Set<(items: PausedResponse[]) => void>();
|
||||
|
||||
setPaused(paused: boolean): void {
|
||||
this.paused = paused;
|
||||
if (!paused) {
|
||||
// Release all paused items with their transformed content
|
||||
for (const item of this.queue) {
|
||||
item.resolve(item.transformed);
|
||||
}
|
||||
this.queue = [];
|
||||
}
|
||||
this.notifyListeners();
|
||||
}
|
||||
|
||||
isPaused(): boolean {
|
||||
return this.paused;
|
||||
}
|
||||
|
||||
async enqueue(item: Omit<PausedResponse, 'resolve' | 'id' | 'timestamp'>): Promise<string> {
|
||||
if (!this.paused) return item.transformed;
|
||||
|
||||
return new Promise(resolve => {
|
||||
this.queue.push({
|
||||
...item,
|
||||
id: crypto.randomUUID(),
|
||||
timestamp: Date.now(),
|
||||
resolve,
|
||||
});
|
||||
this.notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
editAndRelease(id: string, editedContent: string): void {
|
||||
const idx = this.queue.findIndex(q => q.id === id);
|
||||
if (idx >= 0) {
|
||||
const item = this.queue.splice(idx, 1)[0];
|
||||
item.resolve(editedContent);
|
||||
this.notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
releaseOne(id: string): void {
|
||||
const idx = this.queue.findIndex(q => q.id === id);
|
||||
if (idx >= 0) {
|
||||
const item = this.queue.splice(idx, 1)[0];
|
||||
item.resolve(item.transformed);
|
||||
this.notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
dropOne(id: string): void {
|
||||
const idx = this.queue.findIndex(q => q.id === id);
|
||||
if (idx >= 0) {
|
||||
const item = this.queue.splice(idx, 1)[0];
|
||||
item.resolve(''); // Empty response
|
||||
this.notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const pauseQueue = new PauseQueue();
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests: enqueue returns immediately when not paused, enqueue blocks when paused, releaseOne/editAndRelease/dropOne work correctly, setPaused(false) releases all.
|
||||
70
.taskmaster/tasks/task_107.md
Normal file
70
.taskmaster/tasks/task_107.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# Task ID: 107
|
||||
|
||||
**Title:** Implement Edit Mode for Model Studio
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 106 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add inline editing capability to model studio for modifying paused responses before release.
|
||||
|
||||
**Details:**
|
||||
|
||||
Extend `src/cli/src/commands/console/model-studio.tsx`:
|
||||
|
||||
```typescript
|
||||
import { spawn } from 'child_process';
|
||||
import { writeFileSync, readFileSync, unlinkSync } from 'fs';
|
||||
import { tmpdir } from 'os';
|
||||
import { join } from 'path';
|
||||
|
||||
async function editContent(original: string): Promise<string> {
|
||||
const editor = process.env.EDITOR ?? 'vim';
|
||||
const tmpFile = join(tmpdir(), `mcpctl-edit-${Date.now()}.txt`);
|
||||
|
||||
writeFileSync(tmpFile, original);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const proc = spawn(editor, [tmpFile], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
proc.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
const edited = readFileSync(tmpFile, 'utf-8');
|
||||
unlinkSync(tmpFile);
|
||||
resolve(edited);
|
||||
} else {
|
||||
unlinkSync(tmpFile);
|
||||
reject(new Error(`Editor exited with code ${code}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// In the TUI component:
|
||||
useInput(async (input, key) => {
|
||||
if (input === 'e' && pauseMode && selectedPausedItem) {
|
||||
const edited = await editContent(selectedPausedItem.transformed);
|
||||
pauseQueue.editAndRelease(selectedPausedItem.id, edited);
|
||||
|
||||
// Emit correction event
|
||||
trafficCapture.emit({
|
||||
eventType: 'content_edited',
|
||||
sessionId: selectedPausedItem.sessionId,
|
||||
contentType: selectedPausedItem.contentType,
|
||||
sourceName: selectedPausedItem.sourceName,
|
||||
original: selectedPausedItem.original,
|
||||
transformed: selectedPausedItem.transformed,
|
||||
edited,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Integration test: pressing 'e' opens editor with content, saving and closing applies edit, edit event is emitted with correct before/after content.
|
||||
75
.taskmaster/tasks/task_108.md
Normal file
75
.taskmaster/tasks/task_108.md
Normal file
@@ -0,0 +1,75 @@
|
||||
# Task ID: 108
|
||||
|
||||
**Title:** Implement Model Switch for Model Studio
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 105 ✓, 82 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Add ability to switch the active proxymodel for a project mid-session from model studio.
|
||||
|
||||
**Details:**
|
||||
|
||||
Extend `src/cli/src/commands/console/model-studio.tsx`:
|
||||
|
||||
```typescript
|
||||
function ModelPicker({ models, current, onSelect }: {
|
||||
models: string[];
|
||||
current: string;
|
||||
onSelect: (name: string) => void;
|
||||
}) {
|
||||
const [selectedIdx, setSelectedIdx] = useState(models.indexOf(current));
|
||||
|
||||
useInput((input, key) => {
|
||||
if (key.upArrow) setSelectedIdx(i => Math.max(0, i - 1));
|
||||
if (key.downArrow) setSelectedIdx(i => Math.min(models.length - 1, i + 1));
|
||||
if (key.return) onSelect(models[selectedIdx]);
|
||||
});
|
||||
|
||||
return (
|
||||
<Box flexDirection="column" borderStyle="single">
|
||||
<Text bold>Select ProxyModel:</Text>
|
||||
{models.map((m, i) => (
|
||||
<Text key={m} inverse={i === selectedIdx}>
|
||||
{m === current ? '✓ ' : ' '}{m}
|
||||
</Text>
|
||||
))}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
// Add to main component:
|
||||
const [showModelPicker, setShowModelPicker] = useState(false);
|
||||
const [activeModel, setActiveModel] = useState('default');
|
||||
|
||||
useInput((input) => {
|
||||
if (input === 'm') setShowModelPicker(true);
|
||||
});
|
||||
|
||||
async function switchModel(name: string) {
|
||||
// Call mcplocal API to switch model
|
||||
await fetch(`http://localhost:${port}/projects/${projectName}/proxymodel`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ proxyModel: name }),
|
||||
});
|
||||
setActiveModel(name);
|
||||
setShowModelPicker(false);
|
||||
|
||||
// Emit model_switched event
|
||||
trafficCapture.emit({
|
||||
eventType: 'model_switched',
|
||||
projectName,
|
||||
previousModel: activeModel,
|
||||
newModel: name,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
Add PUT endpoint to mcplocal for switching proxymodel.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Integration test: 'm' opens model picker, selecting a model updates the active model, subsequent content flows through new model, model_switched event is emitted.
|
||||
94
.taskmaster/tasks/task_109.md
Normal file
94
.taskmaster/tasks/task_109.md
Normal file
@@ -0,0 +1,94 @@
|
||||
# Task ID: 109
|
||||
|
||||
**Title:** Implement Studio MCP Server Tools
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 104 ✗, 106 ✓, 107 ✓, 108 ✓
|
||||
|
||||
**Priority:** medium
|
||||
|
||||
**Description:** Create MCP tools for Claude Monitor to observe traffic, get corrections, switch models, and modify stages.
|
||||
|
||||
**Details:**
|
||||
|
||||
Extend `src/cli/src/commands/console/inspect-mcp.ts` with studio tools:
|
||||
|
||||
```typescript
|
||||
const studioTools: Tool[] = [
|
||||
{
|
||||
name: 'get_content_diff',
|
||||
description: 'Get original vs transformed vs edited content for a specific event',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
eventId: { type: 'string', description: 'Event ID' },
|
||||
},
|
||||
required: ['eventId'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'get_corrections',
|
||||
description: 'Get all user corrections (edits) in a session',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
sessionId: { type: 'string', description: 'Optional session filter' },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'get_active_model',
|
||||
description: 'Get current proxymodel name and stage list for a project',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
project: { type: 'string' },
|
||||
},
|
||||
required: ['project'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'switch_model',
|
||||
description: 'Hot-swap the active proxymodel on a project',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
project: { type: 'string' },
|
||||
model: { type: 'string' },
|
||||
},
|
||||
required: ['project', 'model'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'reload_stages',
|
||||
description: 'Force reload all stages from ~/.mcpctl/stages/',
|
||||
inputSchema: { type: 'object', properties: {} },
|
||||
},
|
||||
{
|
||||
name: 'get_stage_source',
|
||||
description: 'Read the source code of a stage file',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: { type: 'string' },
|
||||
},
|
||||
required: ['name'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'list_models',
|
||||
description: 'List available proxymodels',
|
||||
inputSchema: { type: 'object', properties: {} },
|
||||
},
|
||||
{
|
||||
name: 'list_stages',
|
||||
description: 'List available stages',
|
||||
inputSchema: { type: 'object', properties: {} },
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Integration test with MCP client: each tool returns expected data format, switch_model actually changes the model, reload_stages picks up file changes, get_corrections returns user edits.
|
||||
62
.taskmaster/tasks/task_110.md
Normal file
62
.taskmaster/tasks/task_110.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# Task ID: 110
|
||||
|
||||
**Title:** Implement RBAC for ProxyModels
|
||||
|
||||
**Status:** deferred
|
||||
|
||||
**Dependencies:** 87 ✗
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Add 'run' permission on proxymodels resource controlling which proxymodels users can activate on projects.
|
||||
|
||||
**Details:**
|
||||
|
||||
Update RBAC schema and enforcement:
|
||||
|
||||
1. Add to `src/db/prisma/schema.prisma`:
|
||||
```prisma
|
||||
// Extend existing RbacBinding or Permission model
|
||||
enum RbacResource {
|
||||
// ... existing
|
||||
proxymodels
|
||||
}
|
||||
|
||||
enum RbacPermission {
|
||||
// ... existing
|
||||
run // permission to use a proxymodel
|
||||
cache // permission to push to shared cache
|
||||
}
|
||||
```
|
||||
|
||||
2. Add enforcement in `src/mcplocal/src/router.ts`:
|
||||
```typescript
|
||||
async function resolveProxyModel(
|
||||
requestedModel: string,
|
||||
projectName: string,
|
||||
userId: string
|
||||
): Promise<ProxyModelDefinition> {
|
||||
const models = await loadProxyModels();
|
||||
const model = models.get(requestedModel);
|
||||
|
||||
if (!model) {
|
||||
console.warn(`Proxymodel '${requestedModel}' not found, using default`);
|
||||
return models.get('default')!;
|
||||
}
|
||||
|
||||
// Check RBAC permission
|
||||
const hasPermission = await checkPermission(userId, 'run', 'proxymodels', requestedModel);
|
||||
if (!hasPermission) {
|
||||
console.warn(`User lacks 'run' permission for proxymodel '${requestedModel}', using default`);
|
||||
return models.get('default')!;
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
```
|
||||
|
||||
3. 'default' proxymodel requires no permission (always allowed).
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Integration test: user with 'run' permission can use proxymodel, user without permission falls back to default, 'default' always works, permission check logs reason for fallback.
|
||||
76
.taskmaster/tasks/task_111.md
Normal file
76
.taskmaster/tasks/task_111.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# Task ID: 111
|
||||
|
||||
**Title:** Write Integration Tests for subindex Model
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 75 ✓, 76 ✓, 82 ✓, 83 ✗
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Create comprehensive integration tests for the subindex proxymodel processing real content through section-split and summarize-tree.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `src/mcplocal/tests/proxymodel/subindex.test.ts`:
|
||||
|
||||
```typescript
|
||||
import { describe, it, expect, beforeAll } from 'vitest';
|
||||
import { executePipeline } from '../../src/proxymodel/executor';
|
||||
import { loadProxyModels } from '../../src/proxymodel/loader';
|
||||
import { createMockProviderRegistry } from '../mocks/providers';
|
||||
|
||||
describe('subindex proxymodel', () => {
|
||||
let proxyModel;
|
||||
let mockRegistry;
|
||||
|
||||
beforeAll(async () => {
|
||||
const models = await loadProxyModels();
|
||||
proxyModel = models.get('subindex');
|
||||
mockRegistry = createMockProviderRegistry({
|
||||
complete: async (prompt) => 'Mock summary of the content',
|
||||
});
|
||||
});
|
||||
|
||||
it('splits JSON array into sections', async () => {
|
||||
const content = JSON.stringify([
|
||||
{ id: 'flow1', label: 'Thermostat', nodes: [] },
|
||||
{ id: 'flow2', label: 'Lighting', nodes: [] },
|
||||
]);
|
||||
|
||||
const result = await executePipeline({
|
||||
content,
|
||||
contentType: 'toolResult',
|
||||
sourceName: 'test/get_flows',
|
||||
projectName: 'test',
|
||||
sessionId: 'test-session',
|
||||
proxyModel,
|
||||
providerRegistry: mockRegistry,
|
||||
});
|
||||
|
||||
expect(result.sections).toHaveLength(2);
|
||||
expect(result.sections[0].id).toBe('flow1');
|
||||
expect(result.content).toContain('2 sections');
|
||||
});
|
||||
|
||||
it('provides drill-down to exact JSON content', async () => {
|
||||
// Test that drilling into a section returns exact original JSON
|
||||
});
|
||||
|
||||
it('uses structural summaries for JSON (no LLM call)', async () => {
|
||||
// Verify LLM not called for JSON content
|
||||
});
|
||||
|
||||
it('uses LLM summaries for prose content', async () => {
|
||||
// Verify LLM called for markdown content
|
||||
});
|
||||
|
||||
it('caches summaries across requests', async () => {
|
||||
// Verify cache hit on second request with same content
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Run with vitest, verify all test cases pass, check LLM call counts are as expected (structural vs prose), verify cache behavior.
|
||||
47
.taskmaster/tasks/task_112.md
Normal file
47
.taskmaster/tasks/task_112.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Task ID: 112
|
||||
|
||||
**Title:** Write Documentation for ProxyModel Authoring
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 71 ✓, 78 ✓, 93 ✗, 94 ✗
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Create comprehensive documentation for users wanting to create custom stages and proxymodels.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create documentation covering:
|
||||
|
||||
1. `docs/proxymodels/authoring-guide.md` - Complete guide from PRD's "Authoring Guide" section:
|
||||
- Concepts: stages, proxymodels, framework
|
||||
- File locations
|
||||
- Step-by-step stage creation
|
||||
- Step-by-step proxymodel creation
|
||||
- Testing with mcpctl proxymodel validate
|
||||
- Section drill-down
|
||||
- Cache usage
|
||||
- Error handling
|
||||
- Full example
|
||||
|
||||
2. `docs/proxymodels/built-in-stages.md` - Reference for all built-in stages:
|
||||
- passthrough
|
||||
- paginate
|
||||
- section-split
|
||||
- summarize-tree
|
||||
- Config options for each
|
||||
|
||||
3. `docs/proxymodels/api-reference.md` - Type reference:
|
||||
- StageHandler
|
||||
- StageContext
|
||||
- StageResult
|
||||
- Section
|
||||
- LLMProvider
|
||||
- CacheProvider
|
||||
|
||||
4. Update main README with proxymodels overview.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Review documentation for completeness, verify all code examples compile, test example stage from documentation works end-to-end.
|
||||
31
.taskmaster/tasks/task_113.md
Normal file
31
.taskmaster/tasks/task_113.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Task ID: 113
|
||||
|
||||
**Title:** Write Documentation for Model Studio
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** 105 ✓, 106 ✓, 107 ✓, 108 ✓, 109 ✓
|
||||
|
||||
**Priority:** low
|
||||
|
||||
**Description:** Create documentation for using model studio for live proxymodel development and debugging.
|
||||
|
||||
**Details:**
|
||||
|
||||
Create `docs/proxymodels/model-studio.md` covering:
|
||||
|
||||
1. Overview: Three-window setup (Claude Client, Model Studio, Claude Monitor)
|
||||
2. Starting Model Studio: `mcpctl console --model-studio <project>`
|
||||
3. Keyboard shortcuts reference
|
||||
4. Viewing original vs transformed content
|
||||
5. Pause mode: when and why to use it
|
||||
6. Editing paused responses
|
||||
7. Switching proxymodels mid-session
|
||||
8. Using Claude Monitor to observe and modify stages
|
||||
9. The correction workflow: edit → observe → adjust stage → verify
|
||||
10. MCP tools available to Claude Monitor
|
||||
11. Troubleshooting common issues
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Review documentation for completeness, verify all described features work as documented.
|
||||
74
.taskmaster/tasks/task_114.md
Normal file
74
.taskmaster/tasks/task_114.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# Task ID: 114
|
||||
|
||||
**Title:** ProxyModel v2: Code-based MCP middleware plugin system
|
||||
|
||||
**Status:** done
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Redesign the ProxyModel framework from a YAML-configured content transformation pipeline into a full code-based MCP middleware plugin system. Proxy models become TypeScript files that can intercept any MCP request/response, create synthetic tools, maintain per-session state, and compose via multiple inheritance with compile-time conflict detection. The existing gate functionality (begin_session, tools/list filtering, prompt scoring, ungating) becomes the first proxy model implementation, proving the framework works by implementing gate entirely as a plugin with zero gate-specific code in router.ts.
|
||||
|
||||
**Details:**
|
||||
|
||||
## Vision
|
||||
|
||||
A proxy model is a TypeScript code file (not YAML) that acts as full MCP middleware. It can:
|
||||
- Intercept any MCP request (initialize, tools/list, tools/call, resources/*, prompts/*)
|
||||
- Modify any response before it reaches the client
|
||||
- Create synthetic tools (e.g. begin_session doesn't exist upstream)
|
||||
- Maintain per-session state (gated/ungated, accumulated tags, etc.)
|
||||
- Access project resources (prompts, servers, config)
|
||||
- Transform content (what stages do today: paginate, section-split, etc.)
|
||||
|
||||
## Key design decisions
|
||||
|
||||
1. Code not YAML: Proxy models live as .ts files in a known directory (e.g. ~/.mcpctl/proxymodels/). File exists = model exists. No create/delete via CLI.
|
||||
2. Stages deprecated: No separate stage resource. Content transformation is just code inside the proxy model.
|
||||
3. Multiple inheritance: A model can extend [gate, subindex] to compose behaviors from multiple parents. Conflicts (two parents intercepting the same method incompatibly) detected at load/compile time, not runtime.
|
||||
4. Gate is just a proxy model: The ~300 lines of gate logic in router.ts move into a gate.ts proxy model file. Router becomes thin plumbing (~100 lines).
|
||||
5. gated:true replaced by proxyModel field: Projects get a proxyModel: gate field. If the assigned model implements gating, the project is gated. No separate boolean.
|
||||
6. Discoverable as resources: mcpctl get proxymodels lists available models (discovered from files). mcpctl describe proxymodel gate shows details. But no create/delete commands.
|
||||
7. Attached to projects: mcpctl edit project foo --proxyModel gate or via apply YAML.
|
||||
|
||||
## Framework interface (sketch)
|
||||
|
||||
export interface ProxyModelContext {
|
||||
session: SessionState;
|
||||
project: ProjectConfig;
|
||||
upstream: UpstreamClient;
|
||||
llm?: LLMProvider;
|
||||
cache?: CacheProvider;
|
||||
}
|
||||
|
||||
export interface ProxyModel {
|
||||
name: string;
|
||||
extends?: string[];
|
||||
onInitialize?(ctx, request): Promise<InitializeResult>;
|
||||
onToolsList?(ctx): Promise<Tool[]>;
|
||||
onToolCall?(ctx, name, args): Promise<ToolResult | null>;
|
||||
onResourceRead?(ctx, uri): Promise<ResourceContent | null>;
|
||||
transformContent?(ctx, content, contentType): Promise<string>;
|
||||
createSessionState?(): Record<string, unknown>;
|
||||
}
|
||||
|
||||
## Migration path
|
||||
|
||||
1. Define the ProxyModel TypeScript interface
|
||||
2. Implement the plugin loader (discover .ts files, compile, validate inheritance, detect conflicts)
|
||||
3. Implement the router integration (router delegates to loaded proxy model)
|
||||
4. Extract gate logic from router.ts into gate.ts proxy model
|
||||
5. Extract content pipeline (passthrough, paginate, section-split) into proxy model code
|
||||
6. Add proxyModel field to Project schema (replaces gated boolean)
|
||||
7. Add CLI: get proxymodels, describe proxymodel, edit project --proxyModel
|
||||
8. Add smoke tests: gate proxy model produces identical behavior to current hardcoded gate
|
||||
9. Deprecate gated field (backward compat: gated:true maps to proxyModel:gate)
|
||||
|
||||
## Supersedes
|
||||
|
||||
This task supersedes deferred tasks 83, 85-97, 98-99, 103, 104, 110, 111-112 which assumed the old YAML/stage architecture.
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
1. Gate proxy model smoke test: identical behavior to current hardcoded gate (begin_session, tools/list filtering, ungating). 2. Composition test: model extending [gate, paginate] inherits both behaviors. 3. Conflict detection test: two parents intercepting same hook differently = compile-time error. 4. Discovery test: drop a .ts file in proxymodels dir, mcpctl get proxymodels shows it. 5. Existing smoke tests (proxy-pipeline.test.ts) pass unchanged after migration.
|
||||
29
.taskmaster/tasks/task_115.md
Normal file
29
.taskmaster/tasks/task_115.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Task ID: 115
|
||||
|
||||
**Title:** RBAC tasks namespace split and alias repoint
|
||||
|
||||
**Status:** pending
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Split the RBAC 'tasks' resource into 'tasks' (work items) and 'inference-tasks', update RBAC_RESOURCES and RESOURCE_ALIASES in rbac-definition.schema.ts
|
||||
|
||||
**Details:**
|
||||
|
||||
In src/mcpd/src/validation/rbac-definition.schema.ts:
|
||||
1. Update RBAC_RESOURCES array to include: 'epics', 'epictasks', 'tasks', 'repos', 'sessions', 'inference-tasks'
|
||||
2. Update RESOURCE_ALIASES:
|
||||
- task → tasks (work items)
|
||||
- epic → epics
|
||||
- epictask → epictasks, et → epictasks
|
||||
- repo → repos, repository → repos, repositories → repos
|
||||
- session → sessions
|
||||
- inference-task → inference-tasks
|
||||
3. REMOVE the entry 'inference-tasks': 'tasks'
|
||||
4. Export normalizeResource unchanged (it uses the alias map)
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit tests in src/mcpd/tests/validation/: verify normalizeResource('task') returns 'tasks', normalizeResource('inference-task') returns 'inference-tasks', normalizeResource('et') returns 'epictasks'. Test that RBAC_RESOURCES includes all new entries.
|
||||
26
.taskmaster/tasks/task_116.md
Normal file
26
.taskmaster/tasks/task_116.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Task ID: 116
|
||||
|
||||
**Title:** One-shot RBAC binding backfill migration
|
||||
|
||||
**Status:** pending
|
||||
|
||||
**Dependencies:** 115
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Implement guarded startup migration to rewrite existing 'tasks' bindings to 'inference-tasks' so pre-existing grants continue authorizing inference endpoints
|
||||
|
||||
**Details:**
|
||||
|
||||
In src/mcpd/src/main.ts or a new bootstrap module:
|
||||
1. Read system settings from SYSTEM_SETTINGS_SECRET (see src/mcpd/src/bootstrap/system-settings.ts pattern)
|
||||
2. Check for boolean key 'rbacTasksBackfillComplete'
|
||||
3. If false/missing: iterate rbacRepo.findAll(), for each RbacDefinition row, rewrite roleBindings where resource === 'tasks' to resource: 'inference-tasks'
|
||||
4. Use rbacRepo.update() to persist changes
|
||||
5. Set 'rbacTasksBackfillComplete': true in system settings after completion
|
||||
6. Wildcard bindings (resource: '*') are untouched
|
||||
7. Model on migrateAdminRole pattern in main.ts
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Unit test: create RbacDefinition with resource:'tasks', run backfill, verify resource changed to 'inference-tasks'. Test idempotency: run twice, verify no duplicate rewrites. Test wildcard unchanged.
|
||||
25
.taskmaster/tasks/task_117.md
Normal file
25
.taskmaster/tasks/task_117.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Task ID: 117
|
||||
|
||||
**Title:** Add Epic, EpicTask, EpicTaskEdge Prisma models
|
||||
|
||||
**Status:** pending
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Add Epic, EpicTask, EpicTaskEdge models with enums EpicStatus and EpicTaskStatus to schema.prisma following PRD specifications
|
||||
|
||||
**Details:**
|
||||
|
||||
In src/db/prisma/schema.prisma add:
|
||||
1. enum EpicStatus { open, delivered, delivered_with_tradeoffs, cancelled }
|
||||
2. enum EpicTaskStatus { todo, in_progress, done, cancelled }
|
||||
3. model Epic with: id, name, description, content (@db.Text), doneCriteria (Json), acceptedTradeoffs (Json), projectId, status, semver, currentRevisionId, ownerId, version, createdAt, updatedAt. Relations: project, owner (User), epicTasks[]. @@unique([name, projectId]), @@index([projectId]), @@index([name])
|
||||
4. model EpicTask with: id, name, description, epicId, doneCriteria (Json), status, ownerId, version, createdAt, updatedAt. Relations: epic, owner, tasks[], dependsOn (EpicTaskEdge[]), blocks (EpicTaskEdge[]). @@unique([name, epicId]), @@index([epicId])
|
||||
5. model EpicTaskEdge with: id, fromId, toId, createdAt. Relations using @relation names. @@unique([fromId, toId]), @@index([fromId]), @@index([toId])
|
||||
6. Add reverse relations to User and Project models
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Schema tests in src/db/tests/: create Epic, verify unique constraint on (name, projectId), test cascade delete from Project, test EpicTask creation with Epic reference, test EpicTaskEdge uniqueness.
|
||||
25
.taskmaster/tasks/task_118.md
Normal file
25
.taskmaster/tasks/task_118.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Task ID: 118
|
||||
|
||||
**Title:** Add Task, TaskVerdict, TaskEvent Prisma models
|
||||
|
||||
**Status:** pending
|
||||
|
||||
**Dependencies:** 117
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Add Task, TaskVerdict, TaskEvent models with enums TaskState and TaskRisk to schema.prisma for work item tracking
|
||||
|
||||
**Details:**
|
||||
|
||||
In src/db/prisma/schema.prisma add:
|
||||
1. enum TaskState { todo, in_progress, building, self_testing, qa_review, security_review, sre_review, done, awaiting_review, merged, reopened, cancelled }
|
||||
2. enum TaskRisk { trivial, normal, high }
|
||||
3. model Task with: id, name, title, description (@db.Text), epicTaskId, repoId?, assigneeId?, state, risk, branch?, headCommit?, prUrl?, prNumber?, reviewNote? (@db.Text), ownerId, version, createdAt, updatedAt. Relations: epicTask, repo (CodeRepo?), assignee (Agent?), owner, verdicts[], sessions[], events[]. @@unique([name, epicTaskId]), indexes on epicTaskId, state, assigneeId
|
||||
4. model TaskVerdict with: id, taskId, stage (TaskState), agentId?, commit, passed, summary (@db.Text), findings (Json), createdAt. Relations: task, agent. @@index([taskId]), @@index([taskId, stage])
|
||||
5. model TaskEvent with: id, taskId, fromState?, toState, actorType, actorId?, note? (@db.Text), createdAt. @@index([taskId, createdAt])
|
||||
6. Add reverse relations to Agent model (assignedTasks[], verdicts[])
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Schema tests: create Task linked to EpicTask, verify cascade on EpicTask delete, test TaskVerdict immutability pattern, test TaskEvent append-only by creating multiple events for same task.
|
||||
25
.taskmaster/tasks/task_119.md
Normal file
25
.taskmaster/tasks/task_119.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Task ID: 119
|
||||
|
||||
**Title:** Add CodeRepo Prisma model
|
||||
|
||||
**Status:** pending
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Add CodeRepo model to schema.prisma for git repository management within projects
|
||||
|
||||
**Details:**
|
||||
|
||||
In src/db/prisma/schema.prisma add:
|
||||
1. model CodeRepo with: id, name, projectId, url, defaultBranch (@default("main")), path (@default("")), provider (@default("gitea")), credSecretId?, credSecretKey?, ownerId, version, createdAt, updatedAt
|
||||
2. Relations: project (Project), cred (Secret?), owner (User), tasks (Task[])
|
||||
3. @@unique([name, projectId]), @@index([projectId])
|
||||
4. Add repos CodeRepo[] relation to Project model
|
||||
5. Add codeRepos CodeRepo[] relation to Secret model
|
||||
6. Add ownedRepos CodeRepo[] relation to User model
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Schema tests: create CodeRepo linked to Project, verify unique constraint on (name, projectId), test cascade delete from Project, test SetNull behavior when Secret is deleted.
|
||||
26
.taskmaster/tasks/task_120.md
Normal file
26
.taskmaster/tasks/task_120.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Task ID: 120
|
||||
|
||||
**Title:** Add AgentProject junction model
|
||||
|
||||
**Status:** pending
|
||||
|
||||
**Dependencies:** None
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Add AgentProject many-to-many junction table linking Agents to Projects with role and optional LLM override
|
||||
|
||||
**Details:**
|
||||
|
||||
In src/db/prisma/schema.prisma add:
|
||||
1. model AgentProject with: id, agentId, projectId, role (@default("developer")), llmId?, createdAt
|
||||
2. Relations: agent (Agent), project (Project), llm (Llm?)
|
||||
3. @@unique([agentId, projectId]), @@index([agentId]), @@index([projectId])
|
||||
4. Add projectMemberships AgentProject[] to Agent model
|
||||
5. Add agentMemberships AgentProject[] to Project model
|
||||
6. Add agentProjects AgentProject[] to Llm model
|
||||
7. Keep Agent.projectId for backward compatibility (one release)
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Schema tests: create AgentProject junction, verify unique constraint prevents duplicate membership, test cascade on both Agent and Project delete, test SetNull on Llm delete.
|
||||
24
.taskmaster/tasks/task_121.md
Normal file
24
.taskmaster/tasks/task_121.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Task ID: 121
|
||||
|
||||
**Title:** Add AgentSession Prisma model
|
||||
|
||||
**Status:** pending
|
||||
|
||||
**Dependencies:** 118, 120
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Add AgentSession model with SessionState enum for ephemeral per-session pod tracking
|
||||
|
||||
**Details:**
|
||||
|
||||
In src/db/prisma/schema.prisma add:
|
||||
1. enum SessionState { pending, provisioning, running, ended, failed }
|
||||
2. model AgentSession with: id, agentId, projectId, taskId?, containerId?, state, image, expiresAt, lastError? (@db.Text), ownerId, createdAt, updatedAt, endedAt?
|
||||
3. Relations: agent (Agent), project (Project), task (Task?), owner (User)
|
||||
4. @@index([state]), @@index([taskId]), @@index([agentId])
|
||||
5. Add sessions AgentSession[] to Agent, Project, Task, User models
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Schema tests: create AgentSession with all relations, test cascade on Agent/Project delete, test SetNull on Task delete, verify state enum transitions.
|
||||
30
.taskmaster/tasks/task_122.md
Normal file
30
.taskmaster/tasks/task_122.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Task ID: 122
|
||||
|
||||
**Title:** Update clearAllTables test helper
|
||||
|
||||
**Status:** pending
|
||||
|
||||
**Dependencies:** 117, 118, 119, 120, 121
|
||||
|
||||
**Priority:** high
|
||||
|
||||
**Description:** Add deleteMany calls for all new models to clearAllTables in src/db/tests/helpers.ts
|
||||
|
||||
**Details:**
|
||||
|
||||
In src/db/tests/helpers.ts clearAllTables function:
|
||||
1. Add deleteMany for TaskEvent (child first)
|
||||
2. Add deleteMany for TaskVerdict
|
||||
3. Add deleteMany for AgentSession
|
||||
4. Add deleteMany for Task
|
||||
5. Add deleteMany for EpicTaskEdge
|
||||
6. Add deleteMany for EpicTask
|
||||
7. Add deleteMany for Epic
|
||||
8. Add deleteMany for CodeRepo
|
||||
9. Add deleteMany for AgentProject
|
||||
10. Order matters: delete children before parents to avoid FK violations
|
||||
11. Follow existing pattern in the file
|
||||
|
||||
**Test Strategy:**
|
||||
|
||||
Run existing test suite to verify clearAllTables works correctly with new models. Add explicit test that creates rows in all new tables then calls clearAllTables and verifies tables are empty.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user