@wwjd/pi-graphify 0.3.0 → 0.4.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.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Shared test helpers for command tests.
3
+ */
4
+
5
+ import { createMockBackend } from "../backends/mock.js";
6
+ import { GraphifyCoordinator } from "../coordinator.js";
7
+
8
+ export function createTestCoordinator(backend = createMockBackend()): GraphifyCoordinator {
9
+ return new GraphifyCoordinator({ cwd: process.cwd(), backend });
10
+ }
11
+
12
+ export function getCoordinator(
13
+ coordinator: GraphifyCoordinator | null,
14
+ ): () => GraphifyCoordinator | null {
15
+ return () => coordinator;
16
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Shared types for Graphify slash commands.
3
+ *
4
+ * Command executors receive a narrow subset of ExtensionCommandContext so they
5
+ * are easy to test with mock contexts.
6
+ */
7
+
8
+ import type { ExtensionCommandContext, ExtensionUIContext } from "@earendil-works/pi-coding-agent";
9
+ import type { GraphifyCapabilities } from "../backends/types.js";
10
+ import type { CoordinatorProvider } from "../coordinator.js";
11
+
12
+ export type ExtensionMode = "tui" | "rpc" | "json" | "print";
13
+
14
+ /** UI surface needed by command executors and the unified menu. */
15
+ export interface CommandUIContext
16
+ extends Pick<ExtensionUIContext, "notify" | "input" | "select" | "custom"> {}
17
+
18
+ /** Context passed to every command executor. */
19
+ export interface CommandContext {
20
+ cwd: string;
21
+ ui: CommandUIContext;
22
+ hasUI: boolean;
23
+ mode: ExtensionMode;
24
+ isProjectTrusted(): boolean;
25
+ }
26
+
27
+ /** Function signature for a command executor. */
28
+ export type CommandExecutor = (
29
+ ctx: CommandContext,
30
+ getCoordinator: CoordinatorProvider,
31
+ args: string,
32
+ ) => Promise<void>;
33
+
34
+ /** How a command collects arguments from the unified menu. */
35
+ export type CommandArgMode = "none" | "input" | "flags";
36
+
37
+ /** Static metadata and runtime executor for one slash command. */
38
+ export interface CommandDefinition {
39
+ /** Slash command name, e.g. "graphify-build". */
40
+ name: string;
41
+
42
+ /** Menu label, e.g. "Build graph". */
43
+ label: string;
44
+
45
+ /** Description shown in the menu and in Pi's command list. */
46
+ description: string;
47
+
48
+ /** Required Graphify capability. */
49
+ feature: keyof GraphifyCapabilities;
50
+
51
+ /** Usage string shown when arguments are invalid. */
52
+ usage: string;
53
+
54
+ /** How the menu collects arguments. */
55
+ argMode: CommandArgMode;
56
+
57
+ /** Title for ctx.ui.input when argMode is "input" or "flags". */
58
+ prompt?: string;
59
+
60
+ /** Placeholder for ctx.ui.input. */
61
+ placeholder?: string;
62
+
63
+ /** Execute the command with the given raw argument string. */
64
+ execute: CommandExecutor;
65
+ }
66
+
67
+ /** Narrow an ExtensionCommandContext to the CommandContext shape. */
68
+ export function toCommandContext(ctx: ExtensionCommandContext): CommandContext {
69
+ return {
70
+ cwd: ctx.cwd,
71
+ ui: ctx.ui,
72
+ hasUI: ctx.hasUI,
73
+ mode: ctx.mode as ExtensionMode,
74
+ isProjectTrusted: ctx.isProjectTrusted,
75
+ };
76
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * /graphify-version — show the installed Graphify CLI version.
3
+ */
4
+
5
+ import type { GraphifyCapabilities } from "../backends/types.js";
6
+ import { formatErrorForCommand, formatResultForCommand } from "./format.js";
7
+ import { requireCoordinatorWithCapability } from "./helpers.js";
8
+ import type { CommandDefinition, CommandExecutor } from "./types.js";
9
+
10
+ const FEATURE: keyof GraphifyCapabilities = "version";
11
+
12
+ const executeVersion: CommandExecutor = async (ctx, getCoordinator) => {
13
+ if (!ctx.hasUI) return;
14
+
15
+ const coordinator = requireCoordinatorWithCapability(
16
+ ctx,
17
+ getCoordinator,
18
+ FEATURE,
19
+ "The installed Graphify version does not support version reporting.",
20
+ );
21
+ if (!coordinator) return;
22
+
23
+ try {
24
+ const result = await coordinator.getVersion();
25
+ ctx.ui.notify(formatResultForCommand(result), "info");
26
+ } catch (error) {
27
+ const { message, severity } = formatErrorForCommand(error);
28
+ ctx.ui.notify(message, severity);
29
+ }
30
+ };
31
+
32
+ export const versionCommand: CommandDefinition = {
33
+ name: "graphify-version",
34
+ label: "Graphify version",
35
+ description: "Show the installed Graphify CLI version",
36
+ feature: FEATURE,
37
+ usage: "",
38
+ argMode: "none",
39
+ execute: executeVersion,
40
+ };
@@ -181,6 +181,8 @@ export class GraphifyCoordinator {
181
181
  }
182
182
  }
183
183
 
184
+ export type CoordinatorProvider = () => GraphifyCoordinator | null;
185
+
184
186
  /** Convenience factory. */
185
187
  export async function createGraphifyCoordinator(
186
188
  cwd: string,
@@ -1,6 +1,6 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import type { GraphifyCapabilities } from "../backends/types.js";
3
- import type { GraphifyCoordinator } from "../coordinator.js";
3
+ import type { CoordinatorProvider, GraphifyCoordinator } from "../coordinator.js";
4
4
  import { registerAffectedTool } from "./affected.js";
5
5
  import { registerBuildTool } from "./build.js";
6
6
  import { registerExplainTool } from "./explain.js";
@@ -9,7 +9,7 @@ import { registerQueryTool } from "./query.js";
9
9
  import { registerStatusTool } from "./status.js";
10
10
  import { registerVersionTool } from "./version.js";
11
11
 
12
- export type CoordinatorProvider = () => GraphifyCoordinator | null;
12
+ export type { CoordinatorProvider } from "../coordinator.js";
13
13
 
14
14
  export interface RegisterToolsOptions {
15
15
  /** Tracks tool names that have already been registered to prevent duplicates. */