@phi-code-admin/phi-code 0.82.3 → 0.84.0

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/docs/usage.md +1 -1
  3. package/extensions/phi/btw/LICENSE +21 -0
  4. package/extensions/phi/btw/btw-ui.ts +238 -0
  5. package/extensions/phi/btw/btw.ts +363 -0
  6. package/extensions/phi/btw/index.ts +17 -0
  7. package/extensions/phi/btw/prompts/btw-system.txt +9 -0
  8. package/extensions/phi/chrome/LICENSE +21 -0
  9. package/extensions/phi/chrome/browser-extension/manifest.json +26 -0
  10. package/extensions/phi/chrome/browser-extension/service_worker.js +2388 -0
  11. package/extensions/phi/chrome/browser-extension/snapshot_injected.js +677 -0
  12. package/extensions/phi/chrome/index.ts +1799 -0
  13. package/extensions/phi/goal/LICENSE +21 -0
  14. package/extensions/phi/goal/index.ts +784 -0
  15. package/extensions/phi/mcp/LICENSE +21 -0
  16. package/extensions/phi/mcp/callback-server.ts +263 -0
  17. package/extensions/phi/mcp/config.ts +195 -0
  18. package/extensions/phi/mcp/errors.ts +35 -0
  19. package/extensions/phi/mcp/index.ts +376 -0
  20. package/extensions/phi/mcp/oauth-provider.ts +367 -0
  21. package/extensions/phi/mcp/server-manager.ts +464 -0
  22. package/extensions/phi/mcp/tool-bridge.ts +494 -0
  23. package/extensions/phi/todo/LICENSE +21 -0
  24. package/extensions/phi/todo/config.ts +14 -0
  25. package/extensions/phi/todo/index.ts +113 -0
  26. package/extensions/phi/todo/locales/de.json +17 -0
  27. package/extensions/phi/todo/locales/en.json +15 -0
  28. package/extensions/phi/todo/locales/es.json +17 -0
  29. package/extensions/phi/todo/locales/fr.json +17 -0
  30. package/extensions/phi/todo/locales/pt-BR.json +17 -0
  31. package/extensions/phi/todo/locales/pt.json +17 -0
  32. package/extensions/phi/todo/locales/ru.json +17 -0
  33. package/extensions/phi/todo/locales/uk.json +17 -0
  34. package/extensions/phi/todo/rpiv-config/config.ts +223 -0
  35. package/extensions/phi/todo/rpiv-config/index.ts +12 -0
  36. package/extensions/phi/todo/state/i18n-bridge.ts +65 -0
  37. package/extensions/phi/todo/state/invariants.ts +20 -0
  38. package/extensions/phi/todo/state/replay.ts +38 -0
  39. package/extensions/phi/todo/state/selectors.ts +107 -0
  40. package/extensions/phi/todo/state/state-reducer.ts +187 -0
  41. package/extensions/phi/todo/state/state.ts +18 -0
  42. package/extensions/phi/todo/state/store.ts +54 -0
  43. package/extensions/phi/todo/state/task-graph.ts +57 -0
  44. package/extensions/phi/todo/todo-overlay.ts +194 -0
  45. package/extensions/phi/todo/todo.ts +146 -0
  46. package/extensions/phi/todo/tool/response-envelope.ts +94 -0
  47. package/extensions/phi/todo/tool/types.ts +128 -0
  48. package/extensions/phi/todo/view/format.ts +162 -0
  49. package/package.json +4 -2
@@ -0,0 +1,94 @@
1
+ import type { TaskState } from "../state/state.js";
2
+ import type { Op } from "../state/state-reducer.js";
3
+ import { deriveBlocks } from "../state/task-graph.js";
4
+ import type { Task, TaskAction, TaskDetails, TaskMutationParams } from "./types.js";
5
+
6
+ /**
7
+ * Format a single task as a `[status] #id subject [(activeForm)] [⛓ #dep,…]`
8
+ * line. Used by the `list` content branch only — the overlay and `/todos`
9
+ * formatting paths use `view/format.ts` for richer presentations.
10
+ */
11
+ function formatListLine(t: Task): string {
12
+ const block = t.blockedBy?.length ? ` ⛓ ${t.blockedBy.map((id) => `#${id}`).join(",")}` : "";
13
+ const form = t.status === "in_progress" && t.activeForm ? ` (${t.activeForm})` : "";
14
+ return `[${t.status}] #${t.id} ${t.subject}${form}${block}`;
15
+ }
16
+
17
+ /**
18
+ * Multi-line presentation for the `get` action. Order of rows is pinned by
19
+ * pre-refactor `todo.ts:354-376` — description, activeForm, blockedBy, blocks,
20
+ * owner — so envelope-level snapshot tests stay byte-equivalent.
21
+ */
22
+ function formatGetLines(task: Task, state: TaskState): string {
23
+ const blocks = deriveBlocks(state.tasks).get(task.id) ?? [];
24
+ const lines = [`#${task.id} [${task.status}] ${task.subject}`];
25
+ if (task.description) lines.push(` description: ${task.description}`);
26
+ if (task.activeForm) lines.push(` activeForm: ${task.activeForm}`);
27
+ if (task.blockedBy?.length) {
28
+ lines.push(` blockedBy: ${task.blockedBy.map((id) => `#${id}`).join(", ")}`);
29
+ }
30
+ if (blocks.length) {
31
+ lines.push(` blocks: ${blocks.map((id) => `#${id}`).join(", ")}`);
32
+ }
33
+ if (task.owner) lines.push(` owner: ${task.owner}`);
34
+ return lines.join("\n");
35
+ }
36
+
37
+ /**
38
+ * Pure formatter: `(op, state) → string`. Closed switch on `op.kind` —
39
+ * adding a new `Op` variant fails to compile here until a branch is added.
40
+ * The strings on each branch are byte-equivalent to pre-refactor `todo.ts`
41
+ * reducer output.
42
+ */
43
+ export function formatContent(op: Op, state: TaskState): string {
44
+ switch (op.kind) {
45
+ case "create": {
46
+ const t = state.tasks.find((x) => x.id === op.taskId);
47
+ // Defensive — `op.taskId` always resolves on success path.
48
+ if (!t) return `Created #${op.taskId}`;
49
+ return `Created #${t.id}: ${t.subject} (pending)`;
50
+ }
51
+ case "update": {
52
+ const transition = op.fromStatus !== op.toStatus ? ` (${op.fromStatus} → ${op.toStatus})` : "";
53
+ return `Updated #${op.id}${transition}`;
54
+ }
55
+ case "delete":
56
+ return `Deleted #${op.id}: ${op.subject}`;
57
+ case "clear":
58
+ return `Cleared ${op.count} tasks`;
59
+ case "list": {
60
+ let view = state.tasks;
61
+ if (!op.includeDeleted) view = view.filter((t) => t.status !== "deleted");
62
+ if (op.statusFilter) view = view.filter((t) => t.status === op.statusFilter);
63
+ return view.length === 0 ? "No tasks" : view.map(formatListLine).join("\n");
64
+ }
65
+ case "get":
66
+ return formatGetLines(op.task, state);
67
+ case "error":
68
+ return `Error: ${op.message}`;
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Build the LLM-facing tool envelope after the store has committed the
74
+ * reducer's new state. `details` is the persistence + replay snapshot —
75
+ * `state/replay.ts` consumes this exact shape on session lifecycle events.
76
+ *
77
+ * Mirrors `packages/rpiv-ask-user-question/tool/response-envelope.ts:13-47`.
78
+ */
79
+ export function buildToolResult(
80
+ action: TaskAction,
81
+ params: TaskMutationParams,
82
+ state: TaskState,
83
+ op: Op,
84
+ ): { content: Array<{ type: "text"; text: string }>; details: TaskDetails } {
85
+ const text = formatContent(op, state);
86
+ const details: TaskDetails = {
87
+ action,
88
+ params: params as Record<string, unknown>,
89
+ tasks: state.tasks,
90
+ nextId: state.nextId,
91
+ ...(op.kind === "error" ? { error: op.message } : {}),
92
+ };
93
+ return { content: [{ type: "text", text }], details };
94
+ }
@@ -0,0 +1,128 @@
1
+ import { StringEnum } from "phi-code-ai";
2
+ import { type Static, Type } from "typebox";
3
+
4
+ // ---------------------------------------------------------------------------
5
+ // Tool / command identity — verbatim string boundaries.
6
+ // Tool name "todo" is the persistence key for branch replay (filtering
7
+ // `toolResult.toolName === "todo"`) AND the permissions entry at
8
+ // `templates/pi-permissions.jsonc:26`. DO NOT rename.
9
+ // ---------------------------------------------------------------------------
10
+
11
+ export const TOOL_NAME = "todo";
12
+ export const TOOL_LABEL = "Todo";
13
+ export const COMMAND_NAME = "todos";
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // User-facing strings (kept stable for /todos UX parity).
17
+ // ---------------------------------------------------------------------------
18
+
19
+ export const ERR_REQUIRES_INTERACTIVE = "/todos requires interactive mode";
20
+ export const MSG_NO_TODOS = "No todos yet. Ask the agent to add some!";
21
+
22
+ // ---------------------------------------------------------------------------
23
+ // Public domain types
24
+ // ---------------------------------------------------------------------------
25
+
26
+ export type TaskStatus = "pending" | "in_progress" | "completed" | "deleted";
27
+
28
+ export type TaskAction = "create" | "update" | "list" | "get" | "delete" | "clear";
29
+
30
+ export interface Task {
31
+ id: number;
32
+ subject: string;
33
+ description?: string;
34
+ activeForm?: string;
35
+ status: TaskStatus;
36
+ blockedBy?: number[];
37
+ owner?: string;
38
+ metadata?: Record<string, unknown>;
39
+ }
40
+
41
+ /**
42
+ * Persistence + replay snapshot. Every successful `todo` tool call returns this
43
+ * shape under `details`; `state/replay.ts` reads the latest one from the branch
44
+ * to reconstruct module state. Field order and field names are pinned by
45
+ * cross-version replay compatibility.
46
+ */
47
+ export interface TaskDetails {
48
+ action: TaskAction;
49
+ params: Record<string, unknown>;
50
+ tasks: Task[];
51
+ nextId: number;
52
+ error?: string;
53
+ }
54
+
55
+ /**
56
+ * Open-shape input bag the reducer accepts. Stays an interface so the index
57
+ * signature (`[key: string]: unknown`) lets the runtime pass through TypeBox
58
+ * `Static<typeof TodoParamsSchema>` without `as` casts.
59
+ */
60
+ export interface TaskMutationParams {
61
+ [key: string]: unknown;
62
+ subject?: string;
63
+ description?: string;
64
+ activeForm?: string;
65
+ status?: TaskStatus;
66
+ blockedBy?: number[];
67
+ addBlockedBy?: number[];
68
+ removeBlockedBy?: number[];
69
+ owner?: string;
70
+ metadata?: Record<string, unknown>;
71
+ id?: number;
72
+ includeDeleted?: boolean;
73
+ }
74
+
75
+ // ---------------------------------------------------------------------------
76
+ // TypeBox parameter schema — every `description` doubles as LLM-facing prompt
77
+ // copy. Field order and wording are pinned by registration tests and the
78
+ // pre-refactor schema at `packages/rpiv-todo/todo.ts:512-573`.
79
+ // ---------------------------------------------------------------------------
80
+
81
+ export const TodoParamsSchema = Type.Object({
82
+ action: StringEnum(["create", "update", "list", "get", "delete", "clear"] as const),
83
+ subject: Type.Optional(Type.String({ description: "Task subject line (required for create)" })),
84
+ description: Type.Optional(Type.String({ description: "Long-form task description" })),
85
+ activeForm: Type.Optional(
86
+ Type.String({
87
+ description: "Present-continuous spinner label shown while status is in_progress (e.g. 'writing tests')",
88
+ }),
89
+ ),
90
+ status: Type.Optional(
91
+ StringEnum(["pending", "in_progress", "completed", "deleted"] as const, {
92
+ description: "Target status (update) or list filter (list)",
93
+ }),
94
+ ),
95
+ blockedBy: Type.Optional(
96
+ Type.Array(Type.Number(), {
97
+ description: "Initial blockedBy ids (create only)",
98
+ }),
99
+ ),
100
+ addBlockedBy: Type.Optional(
101
+ Type.Array(Type.Number(), {
102
+ description: "Task ids to add to blockedBy (update only, additive merge)",
103
+ }),
104
+ ),
105
+ removeBlockedBy: Type.Optional(
106
+ Type.Array(Type.Number(), {
107
+ description: "Task ids to remove from blockedBy (update only, additive merge)",
108
+ }),
109
+ ),
110
+ owner: Type.Optional(Type.String({ description: "Agent/owner assigned to this task" })),
111
+ metadata: Type.Optional(
112
+ Type.Record(Type.String(), Type.Unknown(), {
113
+ description: "Arbitrary metadata; pass null value for a key to delete that key on update",
114
+ }),
115
+ ),
116
+ id: Type.Optional(
117
+ Type.Number({
118
+ description: "Task id (required for update, get, delete)",
119
+ }),
120
+ ),
121
+ includeDeleted: Type.Optional(
122
+ Type.Boolean({
123
+ description: "If true, list action returns deleted (tombstoned) tasks as well. Default: false.",
124
+ }),
125
+ ),
126
+ });
127
+
128
+ export type TodoParams = Static<typeof TodoParamsSchema>;
@@ -0,0 +1,162 @@
1
+ import type { Theme } from "phi-code";
2
+ import { Text } from "phi-code-tui";
3
+ import { formatStatusLabel } from "../state/i18n-bridge.js";
4
+ import { selectTaskSubjectById } from "../state/selectors.js";
5
+ import type { TaskState } from "../state/state.js";
6
+ import type { Task, TaskAction, TaskDetails, TaskMutationParams, TaskStatus } from "../tool/types.js";
7
+
8
+ // Re-export so legacy import paths (todo.ts, tests) continue to resolve;
9
+ // the canonical definition lives in the i18n bridge.
10
+ export { formatStatusLabel };
11
+
12
+ // ---------------------------------------------------------------------------
13
+ // Status presentation tables — the single source of truth for glyph/color.
14
+ // ---------------------------------------------------------------------------
15
+
16
+ export const STATUS_GLYPH: Record<TaskStatus, string> = {
17
+ pending: "○",
18
+ in_progress: "◐",
19
+ completed: "●",
20
+ deleted: "⊘",
21
+ };
22
+
23
+ /**
24
+ * Color palette for the renderResult status echo. `deleted` uses `muted` so a
25
+ * successful delete is visually distinct from the error branch (which uses
26
+ * `error` + `✗`). Mirrors pre-refactor `todo.ts:444-450`.
27
+ */
28
+ export const STATUS_COLOR: Record<TaskStatus, "dim" | "warning" | "success" | "muted"> = {
29
+ pending: "dim",
30
+ in_progress: "warning",
31
+ completed: "success",
32
+ deleted: "muted",
33
+ };
34
+
35
+ /**
36
+ * Per-action prefix glyph for renderCall. `+` create, `→` update, `×` delete,
37
+ * `›` get, `☰` list, `∅` clear. Pre-refactor `todo.ts:457-464`.
38
+ */
39
+ export const ACTION_GLYPH: Record<TaskAction, string> = {
40
+ create: "+",
41
+ update: "→",
42
+ delete: "×",
43
+ get: "›",
44
+ list: "☰",
45
+ clear: "∅",
46
+ };
47
+
48
+ /**
49
+ * Glyph for the persistent overlay's per-task row. Differs from `STATUS_GLYPH`
50
+ * for `completed` (`✓` vs `●`) and `deleted` (`✗` vs `⊘`) because the
51
+ * overlay caller never renders a `deleted` row but uses `✗` in its
52
+ * error-toned palette. Mirrors pre-refactor `todo-overlay.ts:23-33`.
53
+ */
54
+ export function overlayStatusGlyph(status: TaskStatus, theme: Theme): string {
55
+ switch (status) {
56
+ case "pending":
57
+ return theme.fg("dim", "○");
58
+ case "in_progress":
59
+ return theme.fg("warning", "◐");
60
+ case "completed":
61
+ return theme.fg("success", "✓");
62
+ case "deleted":
63
+ return theme.fg("error", "✗");
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Format a single task for the overlay (with theme + glyph + dep suffix).
69
+ * Used by `TodoOverlay.formatTaskLine` post-refactor; behavior is unchanged.
70
+ */
71
+ export function formatOverlayTaskLine(t: Task, theme: Theme, showId: boolean): string {
72
+ const glyph = overlayStatusGlyph(t.status, theme);
73
+ const subjectColor = t.status === "completed" || t.status === "deleted" ? "dim" : "text";
74
+ let subject = theme.fg(subjectColor, t.subject);
75
+ if (t.status === "completed" || t.status === "deleted") {
76
+ subject = theme.strikethrough(subject);
77
+ }
78
+ let line = `${glyph}`;
79
+ if (showId) line += ` ${theme.fg("accent", `#${t.id}`)}`;
80
+ line += ` ${subject}`;
81
+ if (t.status === "in_progress" && t.activeForm) {
82
+ line += ` ${theme.fg("dim", `(${t.activeForm})`)}`;
83
+ }
84
+ if (t.blockedBy && t.blockedBy.length > 0) {
85
+ line += ` ${theme.fg("dim", `⛓ ${t.blockedBy.map((id) => `#${id}`).join(",")}`)}`;
86
+ }
87
+ return line;
88
+ }
89
+
90
+ /**
91
+ * Format a single task line for the `/todos` slash command (no glyph color,
92
+ * indented bullet prefix). Pre-refactor `todo.ts:670-674`.
93
+ */
94
+ export function formatCommandTaskLine(t: Task, glyph: string): string {
95
+ const form = t.status === "in_progress" && t.activeForm ? ` (${t.activeForm})` : "";
96
+ const block = t.blockedBy?.length ? ` ⛓ ${t.blockedBy.map((id) => `#${id}`).join(",")}` : "";
97
+ return ` ${glyph} #${t.id} ${t.subject}${form}${block}`;
98
+ }
99
+
100
+ // ---------------------------------------------------------------------------
101
+ // Tool render hooks — wrapped so `todo.ts` becomes a thin call-site.
102
+ // ---------------------------------------------------------------------------
103
+
104
+ /**
105
+ * `renderCall` body. Receives the parsed args, the theme, and the live
106
+ * `TaskState` (resolved by the caller via `getState()`). Returns a `Text`
107
+ * node identical to pre-refactor `todo.ts:507-525`.
108
+ */
109
+ export function renderTodoCall(
110
+ args: TaskMutationParams & { action: TaskAction },
111
+ theme: Theme,
112
+ state: TaskState,
113
+ ): Text {
114
+ const glyph = ACTION_GLYPH[args.action] ?? args.action;
115
+ let text = theme.fg("toolTitle", theme.bold("todo ")) + theme.fg("muted", glyph);
116
+
117
+ if (args.action === "create" && args.subject) {
118
+ text += ` ${theme.fg("dim", args.subject)}`;
119
+ } else if (
120
+ (args.action === "update" || args.action === "get" || args.action === "delete") &&
121
+ args.id !== undefined
122
+ ) {
123
+ const subject = selectTaskSubjectById(state, args.id);
124
+ text += ` ${theme.fg("accent", subject ?? `#${args.id}`)}`;
125
+ } else if (args.action === "list" && args.status) {
126
+ text += ` ${theme.fg("muted", formatStatusLabel(args.status))}`;
127
+ }
128
+ return new Text(text, 0, 0);
129
+ }
130
+
131
+ /**
132
+ * `renderResult` body. Inspects `details` to pick the per-action status echo
133
+ * (only `create`/`update`/`delete` advertise a status; `list`/`get`/`clear`
134
+ * fall back to plain `✓`). Identical visual output to pre-refactor
135
+ * `todo.ts:533-565`.
136
+ */
137
+ export function renderTodoResult(result: { details?: unknown }, theme: Theme): Text {
138
+ const details = result.details as TaskDetails | undefined;
139
+ let status: TaskStatus | undefined;
140
+ if (details) {
141
+ const params = details.params as TaskMutationParams;
142
+ switch (details.action) {
143
+ case "create":
144
+ status = details.tasks[details.tasks.length - 1]?.status;
145
+ break;
146
+ case "update":
147
+ status = params.status ?? details.tasks.find((t) => t.id === params.id)?.status;
148
+ break;
149
+ case "delete":
150
+ status = details.tasks.find((t) => t.id === params.id)?.status;
151
+ break;
152
+ case "list":
153
+ case "get":
154
+ case "clear":
155
+ break;
156
+ }
157
+ }
158
+ if (status) {
159
+ return new Text(theme.fg(STATUS_COLOR[status], `${STATUS_GLYPH[status]} ${formatStatusLabel(status)}`), 0, 0);
160
+ }
161
+ return new Text(theme.fg("success", "✓"), 0, 0);
162
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phi-code-admin/phi-code",
3
- "version": "0.82.3",
3
+ "version": "0.84.0",
4
4
  "description": "Coding agent CLI with persistent memory, sub-agents, intelligent routing, and orchestration",
5
5
  "type": "module",
6
6
  "piConfig": {
@@ -48,6 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@mariozechner/jiti": "^2.6.5",
51
+ "@modelcontextprotocol/sdk": "^1.29.0",
51
52
  "@phi-code-admin/browser": "^1.0.4",
52
53
  "@silvia-odwyer/photon-node": "^0.3.4",
53
54
  "chalk": "^5.5.0",
@@ -71,7 +72,8 @@
71
72
  "typebox": "^1.1.24",
72
73
  "undici": "^7.19.1",
73
74
  "uuid": "^14.0.0",
74
- "yaml": "^2.8.2"
75
+ "yaml": "^2.8.2",
76
+ "zod": "^3.25.0"
75
77
  },
76
78
  "overrides": {
77
79
  "rimraf": "6.1.2",