@planu/cli 7.1.4 → 7.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [7.1.6] - 2026-09-19
2
+
3
+ - resolve the SDD workspace from MCP client `roots/list` so Cursor, Claude, and Codex bind to the open project, not the `npx` process cwd
4
+ - ignore `$HOME/.sdd` and stop treating mkdir ENOENT as `ERR_FEATURE_ALREADY_EXISTS`
5
+
6
+ ## [7.1.5] - 2026-09-18
7
+
8
+ - list v6 `planu/specs` in `sdd_list_features` as `data.legacy` without bulk rewrite
9
+ - website lead/analytics buttons: consent status, honeypot rename, local `/api` mock
10
+
1
11
  ## [7.1.4] - 2026-09-18
2
12
 
3
13
  - public install is `npx -y @planu/cli@latest` (same as Claude/Codex): `cli`, `planu`, and `sdd-engine` bins always start MCP stdio
package/README.md CHANGED
@@ -54,7 +54,7 @@ Local development in this repo:
54
54
  }
55
55
  ```
56
56
 
57
- Set `cwd` to the project that owns `.sdd/`, or set `PLANU_WORKSPACE` to that absolute path. The server also walks up from cwd until it finds `.sdd/`. A home-directory cwd with no ancestor `.sdd` will not see repo features. `pnpm start` runs the MCP server.
57
+ The published server asks the host for MCP roots and binds to the open project that owns `.sdd/`. Do not set a global `PLANU_WORKSPACE`: that pins every client to one repo. `PLANU_WORKSPACE` remains an optional per-process override. `pnpm start` runs the MCP server.
58
58
 
59
59
  **Requirements:** Node.js >= 22.13.
60
60
 
@@ -72,6 +72,8 @@ sdd_init_workspace → sdd_create_feature → architect trinity → sdd_lock_spe
72
72
  4. **Execute:** `sdd_get_active_task` → `sdd_apply_file_patch` → `sdd_complete_task`.
73
73
  5. **Janitor:** prune local branches and orphaned worktrees.
74
74
 
75
+ Legacy `planu/specs/SPEC-*` files stay on disk. `sdd_list_features` returns them under `legacy` (id, path, archive/active/unknown, `migratedTo`) so the trace is never empty. They are not executable until migrated via `.sdd/skills/legacy-migrator.md` into `.sdd/features/FEAT-*`. There is no bulk rewrite of `done` specs.
76
+
75
77
  ### Canonical tools
76
78
 
77
79
  `sdd_init_workspace`, `sdd_list_features`, `sdd_create_feature`, `sdd_lock_spec`, `sdd_read_spec_artifact`, `sdd_read_file_slice`, `sdd_get_active_task`, `sdd_apply_file_patch`, `sdd_complete_task`
@@ -0,0 +1,14 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { ResolvedSddWorkspace, SddWorkspaceHandle } from '../types/sdd-engine.js';
3
+ export declare class McpClientWorkspace implements SddWorkspaceHandle {
4
+ private readonly server;
5
+ private readonly pinnedRoot;
6
+ private readonly env;
7
+ private rootUris;
8
+ private listening;
9
+ constructor(server: McpServer, pinnedRoot: string | undefined, env?: NodeJS.ProcessEnv);
10
+ resolve(): Promise<ResolvedSddWorkspace>;
11
+ private ensureRootsListener;
12
+ private loadRootUris;
13
+ }
14
+ //# sourceMappingURL=client-workspace.d.ts.map
@@ -0,0 +1,57 @@
1
+ import { RootsListChangedNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
2
+ import { resolveSddWorkspace } from './workspace-root.js';
3
+ const LIST_ROOTS_TIMEOUT_MS = 2000;
4
+ export class McpClientWorkspace {
5
+ server;
6
+ pinnedRoot;
7
+ env;
8
+ rootUris;
9
+ listening = false;
10
+ constructor(server, pinnedRoot, env = process.env) {
11
+ this.server = server;
12
+ this.pinnedRoot = pinnedRoot;
13
+ this.env = env;
14
+ }
15
+ async resolve() {
16
+ if (this.pinnedRoot) {
17
+ return resolveSddWorkspace({ pinnedRoot: this.pinnedRoot, env: this.env });
18
+ }
19
+ this.ensureRootsListener();
20
+ const mcpRootUris = await this.loadRootUris();
21
+ return resolveSddWorkspace({
22
+ startDir: process.cwd(),
23
+ env: this.env,
24
+ mcpRootUris,
25
+ });
26
+ }
27
+ ensureRootsListener() {
28
+ if (this.listening) {
29
+ return;
30
+ }
31
+ this.listening = true;
32
+ try {
33
+ this.server.server.setNotificationHandler(RootsListChangedNotificationSchema, () => {
34
+ this.rootUris = undefined;
35
+ });
36
+ }
37
+ catch {
38
+ this.listening = false;
39
+ }
40
+ }
41
+ async loadRootUris() {
42
+ if (this.rootUris) {
43
+ return this.rootUris;
44
+ }
45
+ try {
46
+ const listed = await this.server.server.listRoots(undefined, {
47
+ timeout: LIST_ROOTS_TIMEOUT_MS,
48
+ });
49
+ this.rootUris = listed.roots.map((root) => root.uri);
50
+ }
51
+ catch {
52
+ this.rootUris = [];
53
+ }
54
+ return this.rootUris;
55
+ }
56
+ }
57
+ //# sourceMappingURL=client-workspace.js.map
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- export type { ArtifactType, FilePermission, ErrorCode, SddErrorDetails, SddSuccess, SddFailure, SddResult, InitWorkspaceInput, ListFeaturesInput, CreateFeatureInput, LockSpecInput, ReadSpecArtifactInput, ReadFileSliceInput, GetActiveTaskInput, ApplyFilePatchInput, CompleteTaskInput, ParsedManifest, ActiveTaskDetails, ActiveTaskResult, CompleteTaskResult, FeatureSummary, } from '../types/sdd-engine.js';
2
+ export type { ArtifactType, FilePermission, ErrorCode, SddErrorDetails, SddSuccess, SddFailure, SddResult, InitWorkspaceInput, ListFeaturesInput, CreateFeatureInput, LockSpecInput, ReadSpecArtifactInput, ReadFileSliceInput, GetActiveTaskInput, ApplyFilePatchInput, CompleteTaskInput, ParsedManifest, ActiveTaskDetails, ActiveTaskResult, CompleteTaskResult, FeatureSummary, LegacySpecSummary, LegacyCatalogSummary, } from '../types/sdd-engine.js';
3
3
  export declare const FeatureIdSchema: z.ZodString;
4
4
  export declare const ArtifactTypeSchema: z.ZodEnum<{
5
5
  plan: "plan";
@@ -0,0 +1,11 @@
1
+ import type { LegacyCatalogSummary, LegacySpecSummary } from '../types/sdd-engine.js';
2
+ export declare function classifyLegacyStatus(status: string | null): LegacySpecSummary['lifecycle'];
3
+ export declare function parseLegacyFrontmatter(content: string): {
4
+ id: string | null;
5
+ title: string | null;
6
+ status: string | null;
7
+ migratedTo: string | null;
8
+ };
9
+ export declare function inferredFeatId(legacyId: string): string;
10
+ export declare function collectLegacyCatalog(workspaceRoot: string, sddDir: string): Promise<LegacyCatalogSummary>;
11
+ //# sourceMappingURL=legacy-catalog.d.ts.map
@@ -0,0 +1,112 @@
1
+ import * as fs from 'node:fs/promises';
2
+ import * as path from 'node:path';
3
+ const LEGACY_SPEC_ROOTS = ['planu/specs', 'legacy-specs'];
4
+ const ARCHIVE_STATUSES = new Set(['done', 'completed', 'complete', 'discarded']);
5
+ const ACTIVE_STATUSES = new Set([
6
+ 'implementing',
7
+ 'approved',
8
+ 'review',
9
+ 'validating',
10
+ 'draft',
11
+ 'planning',
12
+ ]);
13
+ export function classifyLegacyStatus(status) {
14
+ if (!status) {
15
+ return 'unknown';
16
+ }
17
+ const normalized = status.trim().toLowerCase();
18
+ if (ARCHIVE_STATUSES.has(normalized)) {
19
+ return 'archive';
20
+ }
21
+ if (ACTIVE_STATUSES.has(normalized)) {
22
+ return 'active';
23
+ }
24
+ return 'unknown';
25
+ }
26
+ export function parseLegacyFrontmatter(content) {
27
+ const head = content.slice(0, 4000);
28
+ const fence = /^---\r?\n([\s\S]*?)\r?\n---/.exec(head);
29
+ const block = head.startsWith('---') ? (fence?.[1] ?? head) : head;
30
+ return {
31
+ id: matchField(block, 'id'),
32
+ title: matchField(block, 'title'),
33
+ status: matchField(block, 'status'),
34
+ migratedTo: matchField(block, 'sdd_migrated_to'),
35
+ };
36
+ }
37
+ export function inferredFeatId(legacyId) {
38
+ return `FEAT-${legacyId}`;
39
+ }
40
+ export async function collectLegacyCatalog(workspaceRoot, sddDir) {
41
+ const specs = [];
42
+ const seen = new Set();
43
+ for (const relativeRoot of LEGACY_SPEC_ROOTS) {
44
+ const absRoot = path.join(workspaceRoot, relativeRoot);
45
+ const folders = await listSpecFolders(absRoot);
46
+ for (const folder of folders) {
47
+ const specPath = path.join(folder, 'spec.md');
48
+ let content;
49
+ try {
50
+ content = await fs.readFile(specPath, 'utf-8');
51
+ }
52
+ catch {
53
+ continue;
54
+ }
55
+ const meta = parseLegacyFrontmatter(content);
56
+ const folderName = path.basename(folder);
57
+ const idMatch = /^SPEC[-_]\d+/i.exec(folderName);
58
+ const id = meta.id ?? idMatch?.[0]?.toUpperCase() ?? folderName;
59
+ if (seen.has(id)) {
60
+ continue;
61
+ }
62
+ seen.add(id);
63
+ const featAlias = inferredFeatId(id);
64
+ const featExists = await pathExists(path.join(sddDir, 'features', featAlias));
65
+ specs.push({
66
+ id,
67
+ title: meta.title ?? folderName,
68
+ lifecycle: classifyLegacyStatus(meta.status),
69
+ legacyStatus: meta.status,
70
+ path: path.relative(workspaceRoot, specPath).split(path.sep).join('/'),
71
+ migratedTo: meta.migratedTo ?? (featExists ? featAlias : null),
72
+ });
73
+ }
74
+ }
75
+ specs.sort((a, b) => a.id.localeCompare(b.id));
76
+ return {
77
+ total: specs.length,
78
+ active: specs.filter((spec) => spec.lifecycle === 'active').length,
79
+ archive: specs.filter((spec) => spec.lifecycle === 'archive').length,
80
+ unknown: specs.filter((spec) => spec.lifecycle === 'unknown').length,
81
+ specs,
82
+ };
83
+ }
84
+ function matchField(block, key) {
85
+ const match = new RegExp(`^${key}:\\s*(.+)$`, 'im').exec(block);
86
+ if (!match?.[1]) {
87
+ return null;
88
+ }
89
+ return match[1].trim().replace(/^['"]|['"]$/g, '') || null;
90
+ }
91
+ async function listSpecFolders(absRoot) {
92
+ const found = [];
93
+ try {
94
+ const entries = await fs.readdir(absRoot, { withFileTypes: true });
95
+ for (const entry of entries) {
96
+ if (entry.isDirectory()) {
97
+ found.push(path.join(absRoot, entry.name));
98
+ }
99
+ }
100
+ }
101
+ catch {
102
+ return [];
103
+ }
104
+ return found;
105
+ }
106
+ async function pathExists(target) {
107
+ return fs
108
+ .access(target)
109
+ .then(() => true)
110
+ .catch(() => false);
111
+ }
112
+ //# sourceMappingURL=legacy-catalog.js.map
@@ -1,11 +1,10 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
3
  import { registerUltralightSddTools } from './tools.js';
4
- import { resolveSddWorkspaceRoot } from './workspace-root.js';
5
4
  export function createUltralightSddServer(workspaceRoot) {
6
5
  const server = new McpServer({
7
6
  name: 'sdd-engine',
8
- version: '7.1.4',
7
+ version: '7.1.6',
9
8
  }, {
10
9
  capabilities: {
11
10
  tools: {},
@@ -16,7 +15,7 @@ export function createUltralightSddServer(workspaceRoot) {
16
15
  return server;
17
16
  }
18
17
  export async function runServer() {
19
- const server = createUltralightSddServer(resolveSddWorkspaceRoot());
18
+ const server = createUltralightSddServer();
20
19
  const transport = new StdioServerTransport();
21
20
  await server.connect(transport);
22
21
  }
@@ -1,5 +1,4 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import type { PatchSandbox } from '../patch-sandbox.js';
3
- import type { TaskWindowManager } from '../task-window.js';
4
- export declare function registerExecutionTools(server: McpServer, sddDir: string, workspaceRoot: string, patchSandbox: PatchSandbox, taskWindow: TaskWindowManager): void;
2
+ import type { SddWorkspaceHandle } from '../../types/sdd-engine.js';
3
+ export declare function registerExecutionTools(server: McpServer, workspace: SddWorkspaceHandle): void;
5
4
  //# sourceMappingURL=execution-tools.d.ts.map
@@ -1,22 +1,26 @@
1
1
  import * as fs from 'node:fs/promises';
2
2
  import * as path from 'node:path';
3
3
  import { ReadSpecArtifactInputSchema, ReadFileSliceInputSchema, GetActiveTaskInputSchema, ApplyFilePatchInputSchema, CompleteTaskInputSchema, } from '../contracts.js';
4
+ import { PatchSandbox } from '../patch-sandbox.js';
5
+ import { TaskWindowManager } from '../task-window.js';
4
6
  import { formatResult } from './format-result.js';
5
7
  import { verifyLockedTrinity } from '../lock-integrity.js';
6
- export function registerExecutionTools(server, sddDir, workspaceRoot, patchSandbox, taskWindow) {
7
- registerReadArtifactTool(server, sddDir);
8
- registerReadFileSliceTool(server, workspaceRoot);
9
- registerGetActiveTaskTool(server, sddDir, taskWindow);
10
- registerApplyPatchTool(server, sddDir, patchSandbox);
11
- registerCompleteTaskTool(server, sddDir, taskWindow);
8
+ export function registerExecutionTools(server, workspace) {
9
+ const taskWindow = new TaskWindowManager();
10
+ registerReadArtifactTool(server, workspace);
11
+ registerReadFileSliceTool(server, workspace);
12
+ registerGetActiveTaskTool(server, workspace, taskWindow);
13
+ registerApplyPatchTool(server, workspace);
14
+ registerCompleteTaskTool(server, workspace, taskWindow);
12
15
  }
13
- function registerReadArtifactTool(server, sddDir) {
16
+ function registerReadArtifactTool(server, workspace) {
14
17
  server.registerTool('sdd_read_spec_artifact', {
15
18
  description: 'Reads one of the three Holy Trinity artifacts (spec, plan, or tasks).',
16
19
  inputSchema: ReadSpecArtifactInputSchema.shape,
17
20
  }, async (rawArgs) => {
18
21
  const args = ReadSpecArtifactInputSchema.parse(rawArgs);
19
- const targetPath = path.join(sddDir, 'features', args.feature_id, `${args.artifact}.md`);
22
+ const resolved = await workspace.resolve();
23
+ const targetPath = path.join(resolved.sddDir, 'features', args.feature_id, `${args.artifact}.md`);
20
24
  try {
21
25
  const text = await fs.readFile(targetPath, 'utf-8');
22
26
  return { content: [{ type: 'text', text }] };
@@ -33,42 +37,47 @@ function registerReadArtifactTool(server, sddDir) {
33
37
  }
34
38
  });
35
39
  }
36
- function registerReadFileSliceTool(server, workspaceRoot) {
40
+ function registerReadFileSliceTool(server, workspace) {
37
41
  server.registerTool('sdd_read_file_slice', {
38
42
  description: 'Reads an exact line slice from a target file to optimize token usage.',
39
43
  inputSchema: ReadFileSliceInputSchema.shape,
40
44
  }, async (rawArgs) => {
41
45
  const args = ReadFileSliceInputSchema.parse(rawArgs);
42
- return executeReadFileSlice(workspaceRoot, args.path, args.start_line, args.end_line);
46
+ const resolved = await workspace.resolve();
47
+ return executeReadFileSlice(resolved.workspaceRoot, args.path, args.start_line, args.end_line);
43
48
  });
44
49
  }
45
- function registerGetActiveTaskTool(server, sddDir, taskWindow) {
50
+ function registerGetActiveTaskTool(server, workspace, taskWindow) {
46
51
  server.registerTool('sdd_get_active_task', {
47
52
  description: 'Delivers exclusively the active task (Single Task Window). Zero future backlog.',
48
53
  inputSchema: GetActiveTaskInputSchema.shape,
49
54
  }, async (rawArgs) => {
50
55
  const args = GetActiveTaskInputSchema.parse(rawArgs);
51
- const tasksPath = path.join(sddDir, 'features', args.feature_id, 'tasks.md');
56
+ const resolved = await workspace.resolve();
57
+ const tasksPath = path.join(resolved.sddDir, 'features', args.feature_id, 'tasks.md');
52
58
  const result = await taskWindow.getActiveTask(tasksPath);
53
59
  return formatResult(result);
54
60
  });
55
61
  }
56
- function registerApplyPatchTool(server, sddDir, patchSandbox) {
62
+ function registerApplyPatchTool(server, workspace) {
57
63
  server.registerTool('sdd_apply_file_patch', {
58
64
  description: 'Applies diff patches to files strictly authorized in plan.md File Manifest.',
59
65
  inputSchema: ApplyFilePatchInputSchema.shape,
60
66
  }, async (rawArgs) => {
61
67
  const args = ApplyFilePatchInputSchema.parse(rawArgs);
62
- return executeApplyPatch(sddDir, patchSandbox, args);
68
+ const resolved = await workspace.resolve();
69
+ const patchSandbox = new PatchSandbox(resolved.workspaceRoot);
70
+ return executeApplyPatch(resolved.sddDir, patchSandbox, args);
63
71
  });
64
72
  }
65
- function registerCompleteTaskTool(server, sddDir, taskWindow) {
73
+ function registerCompleteTaskTool(server, workspace, taskWindow) {
66
74
  server.registerTool('sdd_complete_task', {
67
75
  description: 'Marks active task as completed with recorded verification output.',
68
76
  inputSchema: CompleteTaskInputSchema.shape,
69
77
  }, async (rawArgs) => {
70
78
  const args = CompleteTaskInputSchema.parse(rawArgs);
71
- const featDir = path.join(sddDir, 'features', args.feature_id);
79
+ const resolved = await workspace.resolve();
80
+ const featDir = path.join(resolved.sddDir, 'features', args.feature_id);
72
81
  const lockError = await requireLockedTrinity(featDir, 'sdd_complete_task');
73
82
  if (lockError) {
74
83
  return lockError;
@@ -1,3 +1,4 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- export declare function registerWorkspaceTools(server: McpServer, sddDir: string, workspaceRoot: string): void;
2
+ import type { SddWorkspaceHandle } from '../../types/sdd-engine.js';
3
+ export declare function registerWorkspaceTools(server: McpServer, workspace: SddWorkspaceHandle): void;
3
4
  //# sourceMappingURL=workspace-tools.d.ts.map
@@ -6,65 +6,92 @@ const moduleDir = path.dirname(fileURLToPath(import.meta.url));
6
6
  import { InitWorkspaceInputSchema, ListFeaturesInputSchema, CreateFeatureInputSchema, LockSpecInputSchema, } from '../contracts.js';
7
7
  import { TaskWindowManager } from '../task-window.js';
8
8
  import { formatResult } from './format-result.js';
9
- export function registerWorkspaceTools(server, sddDir, workspaceRoot) {
9
+ import { collectLegacyCatalog } from '../legacy-catalog.js';
10
+ const MISSING_SDD_HINT = 'No .sdd directory in the client project. Call sdd_init_workspace with scope=project. MCP hosts should advertise roots; do not pin PLANU_WORKSPACE globally.';
11
+ export function registerWorkspaceTools(server, workspace) {
10
12
  const taskWindow = new TaskWindowManager();
11
- registerInitTool(server, sddDir, workspaceRoot);
12
- registerListTool(server, sddDir, taskWindow);
13
- registerCreateTool(server, sddDir);
14
- registerLockTool(server, sddDir);
13
+ registerInitTool(server, workspace);
14
+ registerListTool(server, workspace, taskWindow);
15
+ registerCreateTool(server, workspace);
16
+ registerLockTool(server, workspace);
15
17
  }
16
- function registerInitTool(server, sddDir, workspaceRoot) {
18
+ function registerInitTool(server, workspace) {
17
19
  server.registerTool('sdd_init_workspace', {
18
20
  description: 'Initializes the SDD workspace creating .sdd/ directory and decoupled skills.',
19
21
  inputSchema: InitWorkspaceInputSchema.shape,
20
22
  }, async (rawArgs) => {
21
23
  const args = InitWorkspaceInputSchema.parse(rawArgs);
22
- const targetBase = args.scope === 'global' ? path.join(process.env.HOME ?? '~', '.config', 'sdd') : sddDir;
24
+ const resolved = await workspace.resolve();
25
+ const targetBase = args.scope === 'global'
26
+ ? path.join(process.env.HOME ?? '~', '.config', 'sdd')
27
+ : resolved.sddDir;
23
28
  const featuresDir = path.join(targetBase, 'features');
24
29
  const skillsDir = path.join(targetBase, 'skills');
25
30
  await fs.mkdir(featuresDir, { recursive: true });
26
31
  await fs.mkdir(skillsDir, { recursive: true });
27
32
  await copySkillTemplates(skillsDir);
28
- await copyGlobalRules(workspaceRoot);
33
+ await copyGlobalRules(resolved.workspaceRoot);
29
34
  return formatResult({
30
35
  success: true,
31
- data: { initializedPath: targetBase, scope: args.scope, featuresDir, skillsDir },
36
+ data: {
37
+ initializedPath: targetBase,
38
+ scope: args.scope,
39
+ featuresDir,
40
+ skillsDir,
41
+ workspaceRoot: resolved.workspaceRoot,
42
+ source: resolved.source,
43
+ },
32
44
  });
33
45
  });
34
46
  }
35
- function registerListTool(server, sddDir, taskWindow) {
47
+ function registerListTool(server, workspace, taskWindow) {
36
48
  server.registerTool('sdd_list_features', {
37
- description: 'Lists all features in .sdd/ directory along with their locking and progress status.',
49
+ description: 'Lists v7 FEAT-* features and a read-only catalog of legacy planu/specs SPEC-* (trace only; not executable until migrated).',
38
50
  inputSchema: ListFeaturesInputSchema.shape,
39
51
  }, async (rawArgs) => {
40
52
  const args = ListFeaturesInputSchema.parse(rawArgs);
41
- const featuresDir = path.join(sddDir, 'features');
53
+ const resolved = await workspace.resolve();
54
+ const featuresDir = path.join(resolved.sddDir, 'features');
42
55
  const featuresList = await collectFeatures(featuresDir, taskWindow, args.status_filter);
56
+ const legacy = await collectLegacyCatalog(resolved.workspaceRoot, resolved.sddDir);
43
57
  return formatResult({
44
58
  success: true,
45
- data: { total: featuresList.length, features: featuresList },
59
+ data: {
60
+ total: featuresList.length,
61
+ features: featuresList,
62
+ legacy,
63
+ workspaceRoot: resolved.workspaceRoot,
64
+ sddPresent: resolved.sddPresent,
65
+ source: resolved.source,
66
+ hint: resolved.sddPresent ? undefined : MISSING_SDD_HINT,
67
+ },
46
68
  });
47
69
  });
48
70
  }
49
- function registerCreateTool(server, sddDir) {
71
+ function registerCreateTool(server, workspace) {
50
72
  server.registerTool('sdd_create_feature', {
51
73
  description: 'Creates a new feature conforming to The Holy Trinity (.sdd/features/{id}/[spec.md, plan.md, tasks.md]).',
52
74
  inputSchema: CreateFeatureInputSchema.shape,
53
75
  }, async (rawArgs) => {
54
76
  const args = CreateFeatureInputSchema.parse(rawArgs);
55
- const featDir = path.join(sddDir, 'features', args.id);
77
+ const resolved = await workspace.resolve();
78
+ const featDir = path.join(resolved.sddDir, 'features', args.id);
79
+ await fs.mkdir(path.dirname(featDir), { recursive: true });
56
80
  try {
57
81
  await fs.mkdir(featDir);
58
82
  }
59
- catch {
60
- return formatResult({
61
- success: false,
62
- error: {
63
- code: 'ERR_FEATURE_ALREADY_EXISTS',
64
- message: `Feature '${args.id}' already exists in the workspace.`,
65
- trigger: 'sdd_create_feature',
66
- },
67
- });
83
+ catch (err) {
84
+ if (isNodeErrorCode(err, 'EEXIST')) {
85
+ return formatResult({
86
+ success: false,
87
+ error: {
88
+ code: 'ERR_FEATURE_ALREADY_EXISTS',
89
+ message: `Feature '${args.id}' already exists in the workspace.`,
90
+ trigger: 'sdd_create_feature',
91
+ },
92
+ });
93
+ }
94
+ throw err;
68
95
  }
69
96
  await writeFeatureArtifacts(featDir, args.id, args.title);
70
97
  return formatResult({
@@ -73,20 +100,25 @@ function registerCreateTool(server, sddDir) {
73
100
  featureId: args.id,
74
101
  artifactsCreated: ['spec.md', 'plan.md', 'tasks.md'],
75
102
  directory: featDir,
103
+ workspaceRoot: resolved.workspaceRoot,
76
104
  },
77
105
  });
78
106
  });
79
107
  }
80
- function registerLockTool(server, sddDir) {
108
+ function registerLockTool(server, workspace) {
81
109
  server.registerTool('sdd_lock_spec', {
82
110
  description: 'Locks spec.md and plan.md with cryptographic digests to enable execution phase.',
83
111
  inputSchema: LockSpecInputSchema.shape,
84
112
  }, async (rawArgs) => {
85
113
  const args = LockSpecInputSchema.parse(rawArgs);
86
- const featDir = path.join(sddDir, 'features', args.feature_id);
114
+ const resolved = await workspace.resolve();
115
+ const featDir = path.join(resolved.sddDir, 'features', args.feature_id);
87
116
  return executeLockSpec(featDir, args.feature_id);
88
117
  });
89
118
  }
119
+ function isNodeErrorCode(err, code) {
120
+ return typeof err === 'object' && err !== null && 'code' in err && err.code === code;
121
+ }
90
122
  async function copySkillTemplates(skillsDir) {
91
123
  const sourceSkillsDir = path.resolve(moduleDir, '..', '..', '..', 'templates', 'skills');
92
124
  try {
@@ -1,3 +1,3 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- export declare function registerUltralightSddTools(server: McpServer, workspaceRoot?: string): void;
2
+ export declare function registerUltralightSddTools(server: McpServer, pinnedRoot?: string): void;
3
3
  //# sourceMappingURL=tools.d.ts.map
@@ -1,13 +1,9 @@
1
- import * as path from 'node:path';
2
- import { PatchSandbox } from './patch-sandbox.js';
3
- import { TaskWindowManager } from './task-window.js';
1
+ import { McpClientWorkspace } from './client-workspace.js';
4
2
  import { registerWorkspaceTools } from './tools/workspace-tools.js';
5
3
  import { registerExecutionTools } from './tools/execution-tools.js';
6
- export function registerUltralightSddTools(server, workspaceRoot = process.cwd()) {
7
- const sddDir = path.join(workspaceRoot, '.sdd');
8
- const patchSandbox = new PatchSandbox(workspaceRoot);
9
- const taskWindow = new TaskWindowManager();
10
- registerWorkspaceTools(server, sddDir, workspaceRoot);
11
- registerExecutionTools(server, sddDir, workspaceRoot, patchSandbox, taskWindow);
4
+ export function registerUltralightSddTools(server, pinnedRoot) {
5
+ const workspace = new McpClientWorkspace(server, pinnedRoot);
6
+ registerWorkspaceTools(server, workspace);
7
+ registerExecutionTools(server, workspace);
12
8
  }
13
9
  //# sourceMappingURL=tools.js.map
@@ -1,2 +1,5 @@
1
- export declare function resolveSddWorkspaceRoot(startDir?: string, env?: NodeJS.ProcessEnv): string;
1
+ import type { ResolvedSddWorkspace, ResolveSddWorkspaceInput } from '../types/sdd-engine.js';
2
+ export declare function parseMcpRootUri(uri: string): string | null;
3
+ export declare function resolveSddWorkspaceRoot(startDir?: string, env?: NodeJS.ProcessEnv, mcpRootUris?: readonly string[]): string;
4
+ export declare function resolveSddWorkspace(input?: ResolveSddWorkspaceInput): ResolvedSddWorkspace;
2
5
  //# sourceMappingURL=workspace-root.d.ts.map
@@ -1,20 +1,94 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { dirname, join, resolve } from 'node:path';
3
- export function resolveSddWorkspaceRoot(startDir = process.cwd(), env = process.env) {
3
+ import { fileURLToPath } from 'node:url';
4
+ export function parseMcpRootUri(uri) {
5
+ const trimmed = uri.trim();
6
+ if (!trimmed) {
7
+ return null;
8
+ }
9
+ try {
10
+ if (trimmed.startsWith('file:')) {
11
+ return resolve(fileURLToPath(trimmed));
12
+ }
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ if (trimmed.startsWith('/')) {
18
+ return resolve(trimmed);
19
+ }
20
+ return null;
21
+ }
22
+ export function resolveSddWorkspaceRoot(startDir = process.cwd(), env = process.env, mcpRootUris = []) {
23
+ return resolveSddWorkspace({ startDir, env, mcpRootUris }).workspaceRoot;
24
+ }
25
+ export function resolveSddWorkspace(input = {}) {
26
+ const env = input.env ?? process.env;
27
+ const startDir = resolve(input.startDir ?? process.cwd());
28
+ if (input.pinnedRoot?.trim()) {
29
+ return finish(resolve(input.pinnedRoot.trim()), 'pin');
30
+ }
4
31
  const fromEnv = env.PLANU_WORKSPACE?.trim();
5
32
  if (fromEnv) {
6
- return resolve(fromEnv);
33
+ return finish(resolve(fromEnv), 'env');
34
+ }
35
+ const mcpDirs = unique((input.mcpRootUris ?? [])
36
+ .map((uri) => parseMcpRootUri(uri))
37
+ .filter((dir) => dir !== null));
38
+ for (const dir of mcpDirs) {
39
+ const found = nearestProjectSdd(dir, env);
40
+ if (found) {
41
+ return finish(found, 'mcp_root');
42
+ }
7
43
  }
44
+ const fromCwd = nearestProjectSdd(startDir, env);
45
+ if (fromCwd) {
46
+ return finish(fromCwd, 'cwd_walk');
47
+ }
48
+ if (mcpDirs[0]) {
49
+ return finish(mcpDirs[0], 'fallback');
50
+ }
51
+ return finish(startDir, 'fallback');
52
+ }
53
+ function finish(workspaceRoot, source) {
54
+ const sddDir = join(workspaceRoot, '.sdd');
55
+ return {
56
+ workspaceRoot,
57
+ sddDir,
58
+ sddPresent: existsSync(sddDir),
59
+ source,
60
+ };
61
+ }
62
+ function nearestProjectSdd(startDir, env) {
8
63
  let dir = resolve(startDir);
9
64
  for (;;) {
10
- if (existsSync(join(dir, '.sdd'))) {
65
+ if (existsSync(join(dir, '.sdd')) && !isHomeDirectory(dir, env)) {
11
66
  return dir;
12
67
  }
13
68
  const parent = dirname(dir);
14
69
  if (parent === dir) {
15
- return resolve(startDir);
70
+ return null;
16
71
  }
17
72
  dir = parent;
18
73
  }
19
74
  }
75
+ function isHomeDirectory(dir, env) {
76
+ const home = env.HOME?.trim() ?? env.USERPROFILE?.trim();
77
+ if (!home) {
78
+ return false;
79
+ }
80
+ return resolve(dir) === resolve(home);
81
+ }
82
+ function unique(values) {
83
+ const seen = new Set();
84
+ const out = [];
85
+ for (const value of values) {
86
+ if (seen.has(value)) {
87
+ continue;
88
+ }
89
+ seen.add(value);
90
+ out.push(value);
91
+ }
92
+ return out;
93
+ }
20
94
  //# sourceMappingURL=workspace-root.js.map
@@ -88,6 +88,21 @@ export interface FeatureSummary {
88
88
  status: 'planning' | 'executing' | 'done';
89
89
  locked: boolean;
90
90
  }
91
+ export interface LegacySpecSummary {
92
+ id: string;
93
+ title: string;
94
+ lifecycle: 'active' | 'archive' | 'unknown';
95
+ legacyStatus: string | null;
96
+ path: string;
97
+ migratedTo: string | null;
98
+ }
99
+ export interface LegacyCatalogSummary {
100
+ total: number;
101
+ active: number;
102
+ archive: number;
103
+ unknown: number;
104
+ specs: LegacySpecSummary[];
105
+ }
91
106
  export interface SddLockFile {
92
107
  specHash?: string;
93
108
  planHash?: string;
@@ -106,4 +121,20 @@ export interface ToolResult {
106
121
  structuredContent?: Record<string, unknown>;
107
122
  isError?: boolean;
108
123
  }
124
+ export type WorkspaceResolutionSource = 'env' | 'pin' | 'mcp_root' | 'cwd_walk' | 'fallback';
125
+ export interface ResolvedSddWorkspace {
126
+ workspaceRoot: string;
127
+ sddDir: string;
128
+ sddPresent: boolean;
129
+ source: WorkspaceResolutionSource;
130
+ }
131
+ export interface ResolveSddWorkspaceInput {
132
+ startDir?: string;
133
+ env?: NodeJS.ProcessEnv;
134
+ mcpRootUris?: readonly string[];
135
+ pinnedRoot?: string;
136
+ }
137
+ export interface SddWorkspaceHandle {
138
+ resolve(): Promise<ResolvedSddWorkspace>;
139
+ }
109
140
  //# sourceMappingURL=sdd-engine.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planu/cli",
3
- "version": "7.1.4",
3
+ "version": "7.1.6",
4
4
  "description": "Planu — MCP Server for Spec Driven Development. Cross-platform (Linux/macOS/Windows, x64/arm64).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -6,24 +6,69 @@ role: Spec Fragmentation Specialist
6
6
  # SDD LEGACY MIGRATOR DIRECTIVE
7
7
 
8
8
  You act as a Specification Fragmentation Specialist.
9
- Your objective is to read old, monolithic specifications and refactor them into the modern SDD Engine format (The Holy Trinity: `spec.md`, `plan.md`, `tasks.md`).
9
+ Old Planu v6 specs (`planu/specs/SPEC-*`, `legacy-specs/SPEC-*`) stay on disk. `sdd_list_features` returns them in `data.legacy` (id, path, lifecycle, `migratedTo`). They are **not** executable. `sdd_lock_spec` / `sdd_apply_file_patch` still require a `FEAT-*` trinity.
10
10
 
11
- ## RULES FOR MIGRATION
11
+ Read a legacy spec with `sdd_read_file_slice` using `legacy.specs[].path`. Then follow this skill to create `FEAT-SPEC-{n}` and stamp `sdd_migrated_to`.
12
12
 
13
- 1. **Information Preservation:**
14
- - Ensure all critical constraints, edge cases, and business logic from the monolithic spec are captured.
15
- - Do not hallucinate new requirements; only restructure the existing ones.
13
+ There is no MCP tool `migrate_spec`. Migration is cognitive: read the old artifact, emit a Holy Trinity, lock it.
16
14
 
17
- 2. **Target Format:**
18
- - **`spec.md`:** Focus on pure requirements, out-of-scope boundaries, strict typed contracts, and the error matrix.
19
- - **`plan.md`:** Focus on architectural decisions, frozen dependencies, and the exhaustive file manifest (CREATE, MODIFY, READ_ONLY).
20
- - **`tasks.md`:** Translate implicit steps into explicit, atomic, verifiable tasks with checkboxes (`- [ ] TASK-N: ...`).
15
+ ## Do not bulk-convert the archive
21
16
 
22
- 3. **Language:**
23
- - ALL generated artifacts MUST be written entirely in Technical English.
17
+ A host app may have hundreds of `SPEC-*` files. Most are finished history. Copying every `done` spec into `.sdd/features/` creates empty locked features and noise.
24
18
 
25
- 4. **Workflow:**
26
- - Read the legacy spec thoroughly.
27
- - Run `sdd_create_feature` with a `FEAT-*` id to initialize the target structure.
28
- - Populate `spec.md`, `plan.md`, and `tasks.md` following the SDD Engine standards.
29
- - Verify the migration (five architect laws) and then lock with `sdd_lock_spec`. Do not lock an empty skeleton.
19
+ Triage first, migrate only what still governs work.
20
+
21
+ ### Inventory (run in the target repo)
22
+
23
+ Count `status:` in each `planu/specs/**/spec.md` (or `legacy-specs/**/spec.md`). Bucket:
24
+
25
+ | Bucket | Typical v6 `status` | Action |
26
+ |---|---|---|
27
+ | Archive | `done`, `completed`, `complete`, `discarded` | Keep the folder. Do not create a `FEAT-*` unless the work is being reopened. |
28
+ | Active | `implementing`, `approved`, `review`, `validating`, `draft` | Migrate one spec at a time before more product code. |
29
+ | Unknown | missing `status` | Open the file. If the code already shipped, archive. If work remains, treat as Active. |
30
+
31
+ Never invent requirements. If the old spec is too thin to lock, mark it archive or rewrite as a **new** `FEAT-*` with the user, not as a fake migration.
32
+
33
+ ## ID mapping
34
+
35
+ - Legacy id `SPEC-1047` stays on disk as history.
36
+ - v7 id MUST be `FEAT-*` (example: `FEAT-SPEC-1047` or `FEAT-PAYMENTS-1047`).
37
+ - Put `Legacy-Spec: SPEC-1047` plus the old path in the new `spec.md` frontmatter or header so the two remain traceable.
38
+ - After a successful lock, add to the **old** spec (do not rewrite its body):
39
+
40
+ ```yaml
41
+ sdd_migrated_to: FEAT-SPEC-1047
42
+ sdd_migrated_at: <ISO date>
43
+ ```
44
+
45
+ ## One-spec workflow (mandatory order)
46
+
47
+ 1. Adopt this skill. Adopt `spec-architect.md` for quality of the new trinity.
48
+ 2. `sdd_init_workspace` if `.sdd/` is missing (`scope: project`).
49
+ 3. Read the entire legacy `spec.md` (and `technical.md` / `progress.md` if they still exist).
50
+ 4. `sdd_create_feature` with the `FEAT-*` id and the legacy title.
51
+ 5. Rewrite into:
52
+ - `spec.md` — BDD, Out-of-Scope, typed contracts, error matrix, `Legacy-Spec` pointer.
53
+ - `plan.md` — decisions, frozen dependencies, exhaustive File Manifest (`CREATE` / `MODIFY` / `READ_ONLY`).
54
+ - `tasks.md` — atomic `- [ ] TASK-N:` lines with `Verification:` commands. Check off only work that is already true in the tree.
55
+ 6. If the legacy spec is already implemented, tasks may all be `[x]` **only** when each verification command still passes. Otherwise leave remaining work `[ ]`.
56
+ 7. Five architect laws in `spec-architect.md` must hold. Do not lock an empty skeleton.
57
+ 8. `sdd_lock_spec`.
58
+ 9. Stamp `sdd_migrated_to` on the old spec.
59
+ 10. Continue execution with `spec-executor.md` if tasks remain. Do not use native Write during execution.
60
+
61
+ Language: Technical English in all new SDD artifacts.
62
+
63
+ ## Preservation rules
64
+
65
+ - Copy constraints, edge cases, and error behavior. Do not add product scope.
66
+ - Out-of-Scope is mandatory even if the old spec never had it.
67
+ - File Manifest must match the real tree (paths that no longer exist are not `MODIFY`).
68
+ - Leave `planu/specs/` in place. v7 does not delete or import that directory.
69
+
70
+ ## Host notes (CONKER-scale)
71
+
72
+ Typical shape: majority `done` = archive; tens of `implementing`/`approved`/`draft` = the real queue; a large `status`-less set = triage, not a dump into `.sdd`.
73
+
74
+ New work in that repo starts with `sdd_create_feature`, never with a new `planu/specs/SPEC-*`.