@plurnk/plurnk-contracts 9.0.0 → 10.0.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.
- package/.env.defaults +1 -19
- package/README.md +5 -6
- package/SPEC.md +93 -44
- package/dist/schema/DaemonNotificationEnvelope.json +77 -30
- package/dist/schema/FunctionalityCandidate.json +4 -0
- package/dist/schema/FunctionalityDiscoverQuery.json +12 -0
- package/dist/schema/FunctionalityDiscoverResult.json +10 -0
- package/dist/schema/FunctionalityListQuery.json +33 -0
- package/dist/schema/FunctionalityListResult.json +16 -1
- package/dist/schema/ModelCatalogPage.json +9 -0
- package/dist/schema/PlurnkStatement.json +18 -2
- package/dist/schema/ProviderAccounting.json +3 -3
- package/dist/schema/ProviderCost.json +1 -1
- package/dist/schema/ProviderRequestAccounting.json +3 -3
- package/dist/schema/ProviderUsage.json +1 -1
- package/dist/src/ActorIdentity.d.ts +26 -0
- package/dist/src/ActorIdentity.d.ts.map +1 -0
- package/dist/src/ActorIdentity.js +179 -0
- package/dist/src/ActorIdentity.js.map +1 -0
- package/dist/src/Application.d.ts +38 -126
- package/dist/src/Application.d.ts.map +1 -1
- package/dist/src/Application.js +47 -220
- package/dist/src/Application.js.map +1 -1
- package/dist/src/ApplicationNotifications.d.ts +19 -6
- package/dist/src/ApplicationNotifications.d.ts.map +1 -1
- package/dist/src/ApplicationNotifications.js +6 -3
- package/dist/src/ApplicationNotifications.js.map +1 -1
- package/dist/src/ApplicationPort.d.ts +27 -6
- package/dist/src/ApplicationPort.d.ts.map +1 -1
- package/dist/src/ApplicationPort.js +1 -1
- package/dist/src/ApplicationPort.js.map +1 -1
- package/dist/src/ApplicationStream.d.ts +2 -2
- package/dist/src/ApplicationStream.d.ts.map +1 -1
- package/dist/src/ApplicationStream.js.map +1 -1
- package/dist/src/CollectionCommand.d.ts +33 -0
- package/dist/src/CollectionCommand.d.ts.map +1 -0
- package/dist/src/CollectionCommand.js +277 -0
- package/dist/src/CollectionCommand.js.map +1 -0
- package/dist/src/Functionality.d.ts +7 -2
- package/dist/src/Functionality.d.ts.map +1 -1
- package/dist/src/Functionality.js.map +1 -1
- package/dist/src/HttpOrigin.d.ts +79 -10
- package/dist/src/HttpOrigin.d.ts.map +1 -1
- package/dist/src/HttpOrigin.js +286 -44
- package/dist/src/HttpOrigin.js.map +1 -1
- package/dist/src/HttpPort.d.ts +35 -0
- package/dist/src/HttpPort.d.ts.map +1 -0
- package/dist/src/HttpPort.js +106 -0
- package/dist/src/HttpPort.js.map +1 -0
- package/dist/src/InteractiveCommands.d.ts +96 -0
- package/dist/src/InteractiveCommands.d.ts.map +1 -0
- package/dist/src/InteractiveCommands.js +409 -0
- package/dist/src/InteractiveCommands.js.map +1 -0
- package/dist/src/McpWireTool.d.ts +27 -0
- package/dist/src/McpWireTool.d.ts.map +1 -0
- package/dist/src/McpWireTool.js +30 -0
- package/dist/src/McpWireTool.js.map +1 -0
- package/dist/src/OAuthClient.d.ts +64 -0
- package/dist/src/OAuthClient.d.ts.map +1 -0
- package/dist/src/OAuthClient.js +226 -0
- package/dist/src/OAuthClient.js.map +1 -0
- package/dist/src/ScheduleCommand.d.ts +60 -0
- package/dist/src/ScheduleCommand.d.ts.map +1 -0
- package/dist/src/ScheduleCommand.js +677 -0
- package/dist/src/ScheduleCommand.js.map +1 -0
- package/dist/src/SessionProjection.d.ts +91 -0
- package/dist/src/SessionProjection.d.ts.map +1 -0
- package/dist/src/SessionProjection.js +223 -0
- package/dist/src/SessionProjection.js.map +1 -0
- package/dist/src/Validator.d.ts +2 -1
- package/dist/src/Validator.d.ts.map +1 -1
- package/dist/src/Validator.js +19 -1
- package/dist/src/Validator.js.map +1 -1
- package/dist/src/index.d.ts +10 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/types.generated.d.ts +85 -21
- package/dist/src/types.generated.d.ts.map +1 -1
- package/dist/src/types.generated.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export interface InteractiveCommandSpec {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly usage: string;
|
|
4
|
+
readonly summary: string;
|
|
5
|
+
readonly settingsSection?: string;
|
|
6
|
+
readonly clientOnly?: "term" | "web";
|
|
7
|
+
}
|
|
8
|
+
export interface FamilySubcommandSpec {
|
|
9
|
+
readonly value: string;
|
|
10
|
+
readonly description: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const INTERACTIVE_COMMANDS: readonly InteractiveCommandSpec[];
|
|
13
|
+
export declare const FAMILY_SUBCOMMANDS_BY_FAMILY: Readonly<Record<string, readonly FamilySubcommandSpec[]>>;
|
|
14
|
+
export interface InteractiveCompletionItem {
|
|
15
|
+
readonly value: string;
|
|
16
|
+
readonly description: string;
|
|
17
|
+
readonly trailingSpace: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface InteractiveCompletionResult {
|
|
20
|
+
readonly suggestions: readonly InteractiveCompletionItem[];
|
|
21
|
+
readonly prefix: string;
|
|
22
|
+
}
|
|
23
|
+
export interface InteractiveCompletionSnapshot {
|
|
24
|
+
readonly surface?: "term" | "web";
|
|
25
|
+
readonly projectRoot?: string | null;
|
|
26
|
+
readonly models?: readonly string[];
|
|
27
|
+
readonly efforts?: readonly string[];
|
|
28
|
+
readonly effortsForModel?: (selector: string) => readonly string[] | null | undefined;
|
|
29
|
+
readonly personas?: readonly string[];
|
|
30
|
+
readonly familyAliases?: Readonly<Record<string, readonly string[]>>;
|
|
31
|
+
readonly sessionNames?: readonly string[];
|
|
32
|
+
readonly workspaceNames?: readonly string[];
|
|
33
|
+
readonly pendingGateIds?: readonly string[];
|
|
34
|
+
readonly loopSequences?: readonly string[];
|
|
35
|
+
readonly skills?: readonly {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly description?: string;
|
|
38
|
+
}[];
|
|
39
|
+
readonly advertisedCommands?: readonly {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly description?: string;
|
|
42
|
+
}[];
|
|
43
|
+
readonly promptSuggestions?: readonly string[];
|
|
44
|
+
}
|
|
45
|
+
export declare const completeInteractiveCommand: (line: string, snapshot?: InteractiveCompletionSnapshot) => InteractiveCompletionResult;
|
|
46
|
+
/**
|
|
47
|
+
* {§client-interactive-commands} Computes the longest shared prefix across completion candidates
|
|
48
|
+
* on Unicode code-point boundaries without splitting surrogate pairs.
|
|
49
|
+
*/
|
|
50
|
+
export declare const longestCommonPrefix: (values: readonly string[]) => string;
|
|
51
|
+
export type ComposerInputClassification = {
|
|
52
|
+
readonly kind: "empty";
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: "help";
|
|
55
|
+
} | {
|
|
56
|
+
readonly kind: "review";
|
|
57
|
+
readonly text: string;
|
|
58
|
+
} | {
|
|
59
|
+
readonly kind: "continue";
|
|
60
|
+
readonly text: string;
|
|
61
|
+
} | {
|
|
62
|
+
readonly kind: "statement";
|
|
63
|
+
readonly text: string;
|
|
64
|
+
} | {
|
|
65
|
+
readonly kind: "statement-empty";
|
|
66
|
+
} | {
|
|
67
|
+
readonly kind: "shell";
|
|
68
|
+
readonly command: string;
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: "shell-empty";
|
|
71
|
+
} | {
|
|
72
|
+
readonly kind: "slash";
|
|
73
|
+
readonly name: string;
|
|
74
|
+
readonly argsText: string;
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: "prompt";
|
|
77
|
+
readonly text: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* {§client-composer-sigils} Classifies raw interactive composer input into canonical sigil and command forms
|
|
81
|
+
* (`?`, `? <text>`, `... [text]`, `: <stmt>`, `! <cmd>`, `[await ]plurnk.<op>(`, `/<cmd>`, or `prompt`).
|
|
82
|
+
*/
|
|
83
|
+
export declare const classifyComposerInput: (raw: string) => ComposerInputClassification;
|
|
84
|
+
export type PromptContentBlock = {
|
|
85
|
+
readonly type: "text";
|
|
86
|
+
readonly text: string;
|
|
87
|
+
} | {
|
|
88
|
+
readonly type: "skill";
|
|
89
|
+
readonly name: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* {§client-composer-sigils} Splits composer text on enabled inline `$<skill>` tokens into interleaved
|
|
93
|
+
* ACPv2 `{ type: "text", text }` and `{ type: "skill", name }` prompt blocks, leaving unknown `$tokens` as text.
|
|
94
|
+
*/
|
|
95
|
+
export declare const buildPromptBlocks: (text: string, availableSkills?: ReadonlySet<string>) => readonly PromptContentBlock[];
|
|
96
|
+
//# sourceMappingURL=InteractiveCommands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InteractiveCommands.d.ts","sourceRoot":"","sources":["../../src/InteractiveCommands.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
// {§contract-representations} {§client-interactive-commands} {§client-composer-sigils}
|
|
2
|
+
// Browser/Node-neutral interactive client command inventory, composer sigil classifier,
|
|
3
|
+
// inline skill prompt-block builder, and multi-token completion state machine.
|
|
4
|
+
import { PLURNK_OPS, PROPOSAL_POLICIES } from "./types.js";
|
|
5
|
+
import { FAMILY_DISCOVER_FLAGS_BY_FAMILY, FAMILY_LIST_FLAGS, LIST_ORIGINS, LIST_STATES, MODELS_LIST_FLAGS, } from "./CollectionCommand.js";
|
|
6
|
+
import { SCHEDULE_ADD_FLAGS } from "./ScheduleCommand.js";
|
|
7
|
+
export const INTERACTIVE_COMMANDS = Object.freeze([
|
|
8
|
+
{ name: "help", usage: "/help [verb]", summary: "Show the command index or one command's usage.", settingsSection: "help" },
|
|
9
|
+
{ name: "update", usage: "/update", summary: "Update the model catalog and show how to update Plurnk packages." },
|
|
10
|
+
{ name: "models", usage: "/models [search] [--provider <id>] [--all] [--offset <n>] [--limit <n>]", summary: "Search the bounded model catalog.", settingsSection: "models" },
|
|
11
|
+
{ name: "workspaces", usage: "/workspaces", summary: "List daemon workspaces." },
|
|
12
|
+
{ name: "sessions", usage: "/sessions", summary: "List this workspace's sessions as a tree, each with its state." },
|
|
13
|
+
{ name: "loops", usage: "/loops", summary: "List this session's loops: each one's number and opening line." },
|
|
14
|
+
{ name: "loop", usage: "/loop [n]", summary: "Print loop n whole, or the current loop." },
|
|
15
|
+
{ name: "model", usage: "/model [selector] [effort]", summary: "Inspect or select this session's durable model, and its effort with it.", settingsSection: "session" },
|
|
16
|
+
{ name: "child", usage: "/child [selector|inherit]", summary: "Inspect or select the inherited child model.", settingsSection: "session" },
|
|
17
|
+
{ name: "effort", usage: "/effort [policy]", summary: "Inspect or select reasoning effort.", settingsSection: "session" },
|
|
18
|
+
{ name: "persona", usage: "/persona [name|none]", summary: "Inspect, select, or clear this session's persona role.", settingsSection: "session" },
|
|
19
|
+
{ name: "mode", usage: "/mode [review|accept|reject]", summary: "Inspect or select this session's proposal review mode.", settingsSection: "session" },
|
|
20
|
+
{ name: "yolo", usage: "/yolo", summary: "Toggle proposal auto-accept (Shift-Tab)." },
|
|
21
|
+
{ name: "workspace", usage: "/workspace [name]", summary: "Open or create a workspace.", settingsSection: "workspace" },
|
|
22
|
+
{ name: "rename", usage: "/rename <name>", summary: "Rename this workspace's mutable handle.", settingsSection: "workspace" },
|
|
23
|
+
{ name: "share", usage: "/share <folder>", summary: "Write this workspace's share into <folder> for a bug report." },
|
|
24
|
+
{ name: "rollback", usage: "/rollback <loop>/<turn>/<item>", summary: "Reverse the bound session's file mutations after a log coordinate, latest first, as your own operations." },
|
|
25
|
+
{ name: "session", usage: "/session [name]", summary: "Show this session, or go to the named one; a new name makes a new session.", settingsSection: "session" },
|
|
26
|
+
{ name: "fork", usage: "/fork [name]", summary: "Fork this session into a child that keeps its history, and go there." },
|
|
27
|
+
{ name: "parent", usage: "/parent", summary: "Hop to the bound session's parent (Alt-h)." },
|
|
28
|
+
{ name: "enter", usage: "/enter", summary: "Hop into the bound session's newest child (Alt-l)." },
|
|
29
|
+
{ name: "older", usage: "/older", summary: "Hop to the next older sibling session, wrapping (Alt-j)." },
|
|
30
|
+
{ name: "newer", usage: "/newer", summary: "Hop to the next newer sibling session, wrapping (Alt-k)." },
|
|
31
|
+
{ name: "mcp", usage: "/mcp [subcommand]", summary: "List or manage this workspace's MCP servers.", settingsSection: "mcp" },
|
|
32
|
+
{ name: "skills", usage: "/skills [subcommand]", summary: "List or manage this workspace's Agent Skills.", settingsSection: "skills" },
|
|
33
|
+
{ name: "members", usage: "/members [subcommand]", summary: "List or manage this workspace's file members.", settingsSection: "members" },
|
|
34
|
+
{ name: "env", usage: "/env [--scope session|workspace] [subcommand]", summary: "Manage session overrides or shared workspace environment defaults.", settingsSection: "env" },
|
|
35
|
+
{ name: "schedule", usage: "/schedule [subcommand]", summary: "List or manage this workspace's schedules and macros.", settingsSection: "schedule" },
|
|
36
|
+
{ name: "personas", usage: "/personas [subcommand]", summary: "List or manage this workspace's persona roles.", settingsSection: "personas" },
|
|
37
|
+
{ name: "import", usage: "/import <path>", summary: "Insert a local file into the composer.", clientOnly: "term" },
|
|
38
|
+
{ name: "script", usage: "/script <path>", summary: "Submit MCP expressions through op.exec.", clientOnly: "term" },
|
|
39
|
+
{ name: "editor", usage: "/editor", summary: "Compose the current value in $EDITOR.", clientOnly: "term" },
|
|
40
|
+
{ name: "review", usage: "/review", summary: "Inspect pending proposals or questions." },
|
|
41
|
+
{ name: "approve", usage: "/approve @<id> [optionId]", summary: "Approve the identified proposal or gate." },
|
|
42
|
+
{ name: "accept", usage: "/accept @<id> [optionId]", summary: "Accept the identified proposal or gate." },
|
|
43
|
+
{ name: "reject", usage: "/reject @<id> [optionId]", summary: "Reject the identified proposal or gate." },
|
|
44
|
+
{ name: "cancel", usage: "/cancel @<id>", summary: "Cancel the identified proposal or question." },
|
|
45
|
+
{ name: "edit", usage: "/edit @<id> <body...>", summary: "Edit and accept the identified proposal." },
|
|
46
|
+
{ name: "answer", usage: "/answer @<id> <json>", summary: "Answer the identified elicitation or question." },
|
|
47
|
+
{ name: "login", usage: "/login", summary: "Sign in to the daemon through the browser and keep the grant.", clientOnly: "term" },
|
|
48
|
+
{ name: "logout", usage: "/logout", summary: "Forget the stored token for this daemon." },
|
|
49
|
+
{ name: "learn", usage: "/learn [--scope project|plurnk] [instructions]", summary: "Distill reusable workflow from this session into a SKILL.md." },
|
|
50
|
+
{ name: "stop", usage: "/stop", summary: "Cancel the running loop." },
|
|
51
|
+
{ name: "quit", usage: "/quit", summary: "Exit the interactive client.", clientOnly: "term" },
|
|
52
|
+
]);
|
|
53
|
+
export const FAMILY_SUBCOMMANDS_BY_FAMILY = Object.freeze({
|
|
54
|
+
mcp: Object.freeze([
|
|
55
|
+
{ value: "list", description: "List definitions" },
|
|
56
|
+
{ value: "discover", description: "Discover candidates" },
|
|
57
|
+
{ value: "add", description: "Add definition" },
|
|
58
|
+
{ value: "replace", description: "Replace definition" },
|
|
59
|
+
{ value: "enable", description: "Enable definition" },
|
|
60
|
+
{ value: "disable", description: "Disable definition" },
|
|
61
|
+
{ value: "remove", description: "Remove definition" },
|
|
62
|
+
{ value: "skills", description: "Inspect MCP server skills" },
|
|
63
|
+
{ value: "complete", description: "Complete MCP prompt or resource" },
|
|
64
|
+
{ value: "oauth", description: "Authorize MCP server" },
|
|
65
|
+
]),
|
|
66
|
+
skills: Object.freeze([
|
|
67
|
+
{ value: "list", description: "List definitions" },
|
|
68
|
+
{ value: "discover", description: "Discover candidates" },
|
|
69
|
+
{ value: "add", description: "Add definition" },
|
|
70
|
+
{ value: "replace", description: "Replace definition" },
|
|
71
|
+
{ value: "enable", description: "Enable definition" },
|
|
72
|
+
{ value: "disable", description: "Disable definition" },
|
|
73
|
+
{ value: "remove", description: "Remove definition" },
|
|
74
|
+
]),
|
|
75
|
+
personas: Object.freeze([
|
|
76
|
+
{ value: "list", description: "List definitions" },
|
|
77
|
+
{ value: "discover", description: "Discover candidates" },
|
|
78
|
+
{ value: "add", description: "Add definition" },
|
|
79
|
+
{ value: "replace", description: "Replace definition" },
|
|
80
|
+
{ value: "enable", description: "Enable definition" },
|
|
81
|
+
{ value: "disable", description: "Disable definition" },
|
|
82
|
+
{ value: "remove", description: "Remove definition" },
|
|
83
|
+
]),
|
|
84
|
+
members: Object.freeze([
|
|
85
|
+
{ value: "list", description: "List definitions" },
|
|
86
|
+
{ value: "discover", description: "Discover candidates" },
|
|
87
|
+
{ value: "add", description: "Add definition" },
|
|
88
|
+
{ value: "enable", description: "Enable definition" },
|
|
89
|
+
{ value: "disable", description: "Disable definition" },
|
|
90
|
+
{ value: "remove", description: "Remove definition" },
|
|
91
|
+
]),
|
|
92
|
+
env: Object.freeze([
|
|
93
|
+
{ value: "list", description: "List variables" },
|
|
94
|
+
{ value: "discover", description: "Discover variables" },
|
|
95
|
+
{ value: "add", description: "Add variable" },
|
|
96
|
+
{ value: "replace", description: "Replace variable" },
|
|
97
|
+
{ value: "set", description: "Set NAME=value" },
|
|
98
|
+
{ value: "unset", description: "Remove variable" },
|
|
99
|
+
{ value: "enable", description: "Enable variable" },
|
|
100
|
+
{ value: "disable", description: "Disable variable" },
|
|
101
|
+
{ value: "remove", description: "Remove variable" },
|
|
102
|
+
{ value: "import", description: "Import dotenv file" },
|
|
103
|
+
{ value: "--scope", description: "Select session or workspace scope" },
|
|
104
|
+
]),
|
|
105
|
+
schedule: Object.freeze([
|
|
106
|
+
{ value: "list", description: "List schedules and macros" },
|
|
107
|
+
{ value: "show", description: "Inspect one schedule or macro" },
|
|
108
|
+
{ value: "inspect", description: "Inspect one schedule or macro" },
|
|
109
|
+
{ value: "discover", description: "Show clock or preview rule occurrences" },
|
|
110
|
+
{ value: "add", description: "Add a prompt schedule or macro" },
|
|
111
|
+
{ value: "replace", description: "Replace an existing schedule or macro" },
|
|
112
|
+
{ value: "run", description: "Trigger a schedule or macro now" },
|
|
113
|
+
{ value: "done", description: "Mark an obligation done" },
|
|
114
|
+
{ value: "reopen", description: "Reopen a completed obligation" },
|
|
115
|
+
{ value: "enable", description: "Enable a schedule" },
|
|
116
|
+
{ value: "disable", description: "Disable a schedule" },
|
|
117
|
+
{ value: "remove", description: "Remove a schedule" },
|
|
118
|
+
]),
|
|
119
|
+
});
|
|
120
|
+
const filterPrefix = (candidates, frag, describe, trailingSpace = () => false) => {
|
|
121
|
+
const lower = frag.toLowerCase();
|
|
122
|
+
const hits = candidates.filter((c) => c.toLowerCase().startsWith(lower));
|
|
123
|
+
return {
|
|
124
|
+
suggestions: hits.map((value) => ({
|
|
125
|
+
value,
|
|
126
|
+
description: describe(value),
|
|
127
|
+
trailingSpace: trailingSpace(value),
|
|
128
|
+
})),
|
|
129
|
+
prefix: frag,
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
export const completeInteractiveCommand = (line, snapshot = {}) => {
|
|
133
|
+
if (line.length === 0) {
|
|
134
|
+
const prompts = snapshot.promptSuggestions ?? [];
|
|
135
|
+
if (prompts.length === 0)
|
|
136
|
+
return { suggestions: [], prefix: "" };
|
|
137
|
+
return {
|
|
138
|
+
suggestions: prompts.map((value) => ({
|
|
139
|
+
value,
|
|
140
|
+
description: "suggested prompt",
|
|
141
|
+
trailingSpace: false,
|
|
142
|
+
})),
|
|
143
|
+
prefix: "",
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const surface = snapshot.surface ?? "term";
|
|
147
|
+
const visibleCommands = INTERACTIVE_COMMANDS.filter((c) => surface === "web" ? c.clientOnly !== "term" : c.clientOnly !== "web");
|
|
148
|
+
const rootMatch = /^\/([-\w:]*)$/u.exec(line);
|
|
149
|
+
if (rootMatch !== null) {
|
|
150
|
+
const typed = rootMatch[1].toLowerCase();
|
|
151
|
+
const seen = new Set();
|
|
152
|
+
const merged = [];
|
|
153
|
+
for (const c of visibleCommands) {
|
|
154
|
+
if (!c.name.startsWith(typed))
|
|
155
|
+
continue;
|
|
156
|
+
seen.add(c.name);
|
|
157
|
+
merged.push({
|
|
158
|
+
value: `/${c.name}`,
|
|
159
|
+
description: c.summary,
|
|
160
|
+
trailingSpace: c.usage.includes(" "),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
for (const adv of snapshot.advertisedCommands ?? []) {
|
|
164
|
+
if (seen.has(adv.name) || !adv.name.toLowerCase().startsWith(typed))
|
|
165
|
+
continue;
|
|
166
|
+
seen.add(adv.name);
|
|
167
|
+
merged.push({
|
|
168
|
+
value: `/${adv.name}`,
|
|
169
|
+
description: adv.description ?? "command",
|
|
170
|
+
trailingSpace: true,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
merged.sort((a, b) => (a.value === `/${typed}` ? 0 : 1) - (b.value === `/${typed}` ? 0 : 1));
|
|
174
|
+
return { suggestions: merged, prefix: line };
|
|
175
|
+
}
|
|
176
|
+
const helpMatch = /^\/help\s+(\w*)$/u.exec(line);
|
|
177
|
+
if (helpMatch !== null) {
|
|
178
|
+
const summaryByName = new Map(visibleCommands.map((c) => [c.name, c.summary]));
|
|
179
|
+
return filterPrefix([...summaryByName.keys()], helpMatch[1], (v) => summaryByName.get(v) ?? "command");
|
|
180
|
+
}
|
|
181
|
+
const learnScopeMatch = /^\/learn\s+--scope(?:\s+|=)(\w*)$/u.exec(line);
|
|
182
|
+
if (learnScopeMatch !== null) {
|
|
183
|
+
const scopes = snapshot.projectRoot === null ? ["plurnk"] : ["project", "plurnk"];
|
|
184
|
+
return filterPrefix(scopes, learnScopeMatch[1], (v) => (v === "plurnk" ? "user-wide Plurnk skills" : "project .agents/skills"), () => true);
|
|
185
|
+
}
|
|
186
|
+
const learnFlagMatch = /^\/learn\s+(--\w*)$/u.exec(line);
|
|
187
|
+
if (learnFlagMatch !== null) {
|
|
188
|
+
return filterPrefix(["--scope"], learnFlagMatch[1], () => "skill target scope", () => true);
|
|
189
|
+
}
|
|
190
|
+
const envScopeMatch = /^\/env\s+--scope(?:\s+|=)(\w*)$/u.exec(line);
|
|
191
|
+
if (envScopeMatch !== null) {
|
|
192
|
+
return filterPrefix(["session", "workspace"], envScopeMatch[1], (v) => (v === "workspace" ? "workspace environment defaults" : "session environment overrides"), () => true);
|
|
193
|
+
}
|
|
194
|
+
const familyMatch = /^\/(mcp|skills|personas|members|env|schedule)\s+(?:--scope(?:=|\s+)(?:session|workspace)\s+)?([-\w]*)$/u.exec(line);
|
|
195
|
+
if (familyMatch !== null) {
|
|
196
|
+
const family = familyMatch[1];
|
|
197
|
+
const subs = (FAMILY_SUBCOMMANDS_BY_FAMILY[family] ?? []).filter((s) => !(surface === "web" && family === "env" && s.value === "import"));
|
|
198
|
+
const descBySub = new Map(subs.map((s) => [s.value, s.description]));
|
|
199
|
+
return filterPrefix(subs.map((s) => s.value), familyMatch[2], (v) => descBySub.get(v) ?? "subcommand", (v) => v !== "list");
|
|
200
|
+
}
|
|
201
|
+
const familyAliasMatch = /^\/(mcp|skills|personas|members|env|schedule)\s+(?:--scope(?:=|\s+)(?:session|workspace)\s+)?(show|inspect|replace|enable|disable|remove|unset|oauth|skills|run|done|reopen)\s+(\S*)$/u.exec(line);
|
|
202
|
+
if (familyAliasMatch !== null) {
|
|
203
|
+
const family = familyAliasMatch[1];
|
|
204
|
+
const sub = familyAliasMatch[2];
|
|
205
|
+
const validForFamily = ((sub !== "show" && sub !== "inspect") || family === "schedule")
|
|
206
|
+
&& (sub !== "replace" || family !== "members");
|
|
207
|
+
if (validForFamily) {
|
|
208
|
+
const aliases = snapshot.familyAliases?.[family] ?? [];
|
|
209
|
+
return filterPrefix(aliases, familyAliasMatch[3], () => `${family} definition`, () => sub === "replace");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const familyListStateMatch = /^\/(mcp|skills|personas|members|env|schedule)\s+(?:--scope(?:=|\s+)(?:session|workspace)\s+)?(?:list\s+)?(?:.*\s+)?--state(?:\s+|=)([-\w]*)$/u.exec(line);
|
|
213
|
+
if (familyListStateMatch !== null) {
|
|
214
|
+
return filterPrefix(LIST_STATES, familyListStateMatch[2], () => "definition state", () => true);
|
|
215
|
+
}
|
|
216
|
+
const familyListOriginMatch = /^\/(mcp|skills|personas|members|env|schedule)\s+(?:--scope(?:=|\s+)(?:session|workspace)\s+)?(?:list\s+)?(?:.*\s+)?--origin(?:\s+|=)([-\w]*)$/u.exec(line);
|
|
217
|
+
if (familyListOriginMatch !== null) {
|
|
218
|
+
return filterPrefix(LIST_ORIGINS, familyListOriginMatch[2], () => "definition origin", () => true);
|
|
219
|
+
}
|
|
220
|
+
const familyListFlagMatch = /^\/(mcp|skills|personas|members|env|schedule)\s+(?:--scope(?:=|\s+)(?:session|workspace)\s+)?list(?:\s+.*)?\s+(--[-\w]*)$/u.exec(line);
|
|
221
|
+
if (familyListFlagMatch !== null) {
|
|
222
|
+
const descByFlag = new Map(FAMILY_LIST_FLAGS.map((f) => [f.value, f.description]));
|
|
223
|
+
return filterPrefix(FAMILY_LIST_FLAGS.map((f) => f.value), familyListFlagMatch[2], (v) => descByFlag.get(v) ?? "list option", () => true);
|
|
224
|
+
}
|
|
225
|
+
const familyDiscoverFlagMatch = /^\/(mcp|skills|personas|members|env|schedule)\s+(?:--scope(?:=|\s+)(?:session|workspace)\s+)?discover(?:\s+.*)?\s+(--[-\w]*)$/u.exec(line);
|
|
226
|
+
if (familyDiscoverFlagMatch !== null) {
|
|
227
|
+
const flags = FAMILY_DISCOVER_FLAGS_BY_FAMILY[familyDiscoverFlagMatch[1]] ?? [];
|
|
228
|
+
const descByFlag = new Map(flags.map((f) => [f.value, f.description]));
|
|
229
|
+
return filterPrefix(flags.map((f) => f.value), familyDiscoverFlagMatch[2], (v) => descByFlag.get(v) ?? "discover option", () => true);
|
|
230
|
+
}
|
|
231
|
+
const scheduleFlagMatch = /^\/schedule\s+(?:add|replace)\s+\S+(?:\s+.*)?\s+(--[-\w]*)$/u.exec(line);
|
|
232
|
+
if (scheduleFlagMatch !== null) {
|
|
233
|
+
const descByFlag = new Map(SCHEDULE_ADD_FLAGS.map((f) => [f.value, f.description]));
|
|
234
|
+
return filterPrefix(SCHEDULE_ADD_FLAGS.map((f) => f.value), scheduleFlagMatch[1], (v) => descByFlag.get(v) ?? "schedule option", (v) => v !== "--manual" && v !== "--once" && v !== "--catchup" && v !== "--no-catchup");
|
|
235
|
+
}
|
|
236
|
+
const gateMatch = /^\/(approve|accept|reject|cancel|edit|answer)\s+@?([0-9a-f]*)$/iu.exec(line);
|
|
237
|
+
if (gateMatch !== null) {
|
|
238
|
+
const verb = gateMatch[1].toLowerCase();
|
|
239
|
+
const typed = gateMatch[2].toLowerCase();
|
|
240
|
+
const tokenPrefix = line.slice(line.lastIndexOf(" ") + 1);
|
|
241
|
+
const ids = (snapshot.pendingGateIds ?? [])
|
|
242
|
+
.filter((id) => id.toLowerCase().startsWith(typed))
|
|
243
|
+
.map((id) => `@${id}`);
|
|
244
|
+
return {
|
|
245
|
+
suggestions: ids.map((value) => ({
|
|
246
|
+
value,
|
|
247
|
+
description: "pending gate",
|
|
248
|
+
trailingSpace: verb === "edit" || verb === "answer",
|
|
249
|
+
})),
|
|
250
|
+
prefix: tokenPrefix,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const loopMatch = /^\/loop\s+(\d*)$/u.exec(line);
|
|
254
|
+
if (loopMatch !== null) {
|
|
255
|
+
return filterPrefix(snapshot.loopSequences ?? [], loopMatch[1], () => "loop");
|
|
256
|
+
}
|
|
257
|
+
const sessionMatch = /^\/session\s+(\S*)$/u.exec(line);
|
|
258
|
+
if (sessionMatch !== null) {
|
|
259
|
+
return filterPrefix(snapshot.sessionNames ?? [], sessionMatch[1], () => "session");
|
|
260
|
+
}
|
|
261
|
+
const workspaceMatch = /^\/workspace\s+(\S*)$/u.exec(line);
|
|
262
|
+
if (workspaceMatch !== null) {
|
|
263
|
+
return filterPrefix(snapshot.workspaceNames ?? [], workspaceMatch[1], () => "workspace");
|
|
264
|
+
}
|
|
265
|
+
const modelsFlagMatch = /^\/models(?:\s+.*)?\s+(--[-\w]*)$/u.exec(line);
|
|
266
|
+
if (modelsFlagMatch !== null) {
|
|
267
|
+
const descByFlag = new Map(MODELS_LIST_FLAGS.map((f) => [f.value, f.description]));
|
|
268
|
+
return filterPrefix(MODELS_LIST_FLAGS.map((f) => f.value), modelsFlagMatch[1], (v) => descByFlag.get(v) ?? "models option", (v) => v !== "--all");
|
|
269
|
+
}
|
|
270
|
+
const modelMatch = /^\/(model|models|child)\s+(\S*)$/u.exec(line);
|
|
271
|
+
if (modelMatch !== null) {
|
|
272
|
+
const verb = modelMatch[1];
|
|
273
|
+
const models = snapshot.models ?? [];
|
|
274
|
+
const candidates = verb === "child" ? ["inherit", ...models.filter((m) => m !== "inherit")] : models;
|
|
275
|
+
return filterPrefix(candidates, modelMatch[2], (v) => (v === "inherit" ? "inherit parent route" : "model"), () => verb === "model");
|
|
276
|
+
}
|
|
277
|
+
const modelEffortMatch = /^\/model\s+(\S+)\s+(\S*)$/u.exec(line);
|
|
278
|
+
if (modelEffortMatch !== null) {
|
|
279
|
+
const selector = modelEffortMatch[1];
|
|
280
|
+
const efforts = snapshot.effortsForModel?.(selector) ?? snapshot.efforts ?? [];
|
|
281
|
+
return filterPrefix(efforts, modelEffortMatch[2], () => "reasoning effort");
|
|
282
|
+
}
|
|
283
|
+
const effortMatch = /^\/effort\s+(\S*)$/u.exec(line);
|
|
284
|
+
if (effortMatch !== null) {
|
|
285
|
+
return filterPrefix(snapshot.efforts ?? [], effortMatch[1], () => "reasoning effort");
|
|
286
|
+
}
|
|
287
|
+
const personaMatch = /^\/persona\s+(\S*)$/u.exec(line);
|
|
288
|
+
if (personaMatch !== null) {
|
|
289
|
+
const personas = snapshot.personas ?? ["none"];
|
|
290
|
+
return filterPrefix(personas, personaMatch[1], (v) => (v === "none" ? "clear persona role" : "persona"));
|
|
291
|
+
}
|
|
292
|
+
const modeMatch = /^\/mode\s+(\S*)$/u.exec(line);
|
|
293
|
+
if (modeMatch !== null) {
|
|
294
|
+
return filterPrefix(PROPOSAL_POLICIES, modeMatch[1], () => "proposal review mode");
|
|
295
|
+
}
|
|
296
|
+
const dslMatch = /^((?:await\s+)?plurnk\.)([A-Za-z]*)$/u.exec(line);
|
|
297
|
+
if (dslMatch !== null) {
|
|
298
|
+
const opPrefix = dslMatch[1];
|
|
299
|
+
const typed = dslMatch[2];
|
|
300
|
+
return filterPrefix(PLURNK_OPS.map((op) => `${opPrefix}${op.toLowerCase()}`), `${opPrefix}${typed}`, () => "MCP expression");
|
|
301
|
+
}
|
|
302
|
+
const skillMatch = /(?:^|[\s([{,])\$(\S*)$/u.exec(line);
|
|
303
|
+
if (skillMatch !== null) {
|
|
304
|
+
const skills = snapshot.skills ?? [];
|
|
305
|
+
const descByName = new Map(skills.map((s) => [s.name, s.description ?? "skill"]));
|
|
306
|
+
const tokenPrefix = `$${skillMatch[1]}`;
|
|
307
|
+
const hits = skills
|
|
308
|
+
.filter((s) => s.name.toLowerCase().startsWith(skillMatch[1].toLowerCase()))
|
|
309
|
+
.map((s) => ({
|
|
310
|
+
value: `$${s.name}`,
|
|
311
|
+
description: descByName.get(s.name) ?? "skill",
|
|
312
|
+
trailingSpace: true,
|
|
313
|
+
}));
|
|
314
|
+
return { suggestions: hits, prefix: tokenPrefix };
|
|
315
|
+
}
|
|
316
|
+
return { suggestions: [], prefix: line };
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* {§client-interactive-commands} Computes the longest shared prefix across completion candidates
|
|
320
|
+
* on Unicode code-point boundaries without splitting surrogate pairs.
|
|
321
|
+
*/
|
|
322
|
+
export const longestCommonPrefix = (values) => {
|
|
323
|
+
if (values.length === 0)
|
|
324
|
+
return "";
|
|
325
|
+
let shared = Array.from(values[0] ?? "");
|
|
326
|
+
for (let i = 1; i < values.length && shared.length > 0; i += 1) {
|
|
327
|
+
const chars = Array.from(values[i] ?? "");
|
|
328
|
+
const maxLen = Math.min(shared.length, chars.length);
|
|
329
|
+
let matchLen = 0;
|
|
330
|
+
while (matchLen < maxLen && shared[matchLen] === chars[matchLen]) {
|
|
331
|
+
matchLen += 1;
|
|
332
|
+
}
|
|
333
|
+
shared = shared.slice(0, matchLen);
|
|
334
|
+
}
|
|
335
|
+
return shared.join("");
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* {§client-composer-sigils} Classifies raw interactive composer input into canonical sigil and command forms
|
|
339
|
+
* (`?`, `? <text>`, `... [text]`, `: <stmt>`, `! <cmd>`, `[await ]plurnk.<op>(`, `/<cmd>`, or `prompt`).
|
|
340
|
+
*/
|
|
341
|
+
export const classifyComposerInput = (raw) => {
|
|
342
|
+
const trimmed = raw.trim();
|
|
343
|
+
if (trimmed.length === 0)
|
|
344
|
+
return { kind: "empty" };
|
|
345
|
+
if (trimmed === "?")
|
|
346
|
+
return { kind: "help" };
|
|
347
|
+
if (/^\?\s+/u.test(trimmed)) {
|
|
348
|
+
return { kind: "review", text: trimmed.slice(1).trim() };
|
|
349
|
+
}
|
|
350
|
+
if (trimmed === "..." || /^\.\.\.\s+/u.test(trimmed)) {
|
|
351
|
+
return { kind: "continue", text: trimmed.slice(3).trim() };
|
|
352
|
+
}
|
|
353
|
+
if (trimmed.startsWith(":")) {
|
|
354
|
+
const body = trimmed.slice(1).trim();
|
|
355
|
+
return body.length === 0 ? { kind: "statement-empty" } : { kind: "statement", text: body };
|
|
356
|
+
}
|
|
357
|
+
if (trimmed.startsWith("!")) {
|
|
358
|
+
const command = trimmed.slice(1).trim();
|
|
359
|
+
return command.length === 0 ? { kind: "shell-empty" } : { kind: "shell", command };
|
|
360
|
+
}
|
|
361
|
+
if (/^(?:await\s+)?plurnk\.[a-z][a-z0-9_]*\s*\(/iu.test(trimmed)) {
|
|
362
|
+
return { kind: "statement", text: trimmed };
|
|
363
|
+
}
|
|
364
|
+
const slashMatch = /^\/([a-zA-Z0-9_:-]+)(?:\s+([\s\S]*))?$/u.exec(trimmed);
|
|
365
|
+
if (slashMatch !== null) {
|
|
366
|
+
return {
|
|
367
|
+
kind: "slash",
|
|
368
|
+
name: slashMatch[1] ?? "",
|
|
369
|
+
argsText: (slashMatch[2] ?? "").trim(),
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
return { kind: "prompt", text: raw };
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* {§client-composer-sigils} Splits composer text on enabled inline `$<skill>` tokens into interleaved
|
|
376
|
+
* ACPv2 `{ type: "text", text }` and `{ type: "skill", name }` prompt blocks, leaving unknown `$tokens` as text.
|
|
377
|
+
*/
|
|
378
|
+
export const buildPromptBlocks = (text, availableSkills) => {
|
|
379
|
+
if (text.length === 0)
|
|
380
|
+
return [];
|
|
381
|
+
if (availableSkills === undefined || availableSkills.size === 0) {
|
|
382
|
+
return [{ type: "text", text }];
|
|
383
|
+
}
|
|
384
|
+
const pattern = /(^|[\s([{,])\$([A-Za-z0-9][A-Za-z0-9_-]{0,62})(?=$|[\s)\]}.,;:!?])/gu;
|
|
385
|
+
const blocks = [];
|
|
386
|
+
let buffer = "";
|
|
387
|
+
let cursor = 0;
|
|
388
|
+
for (const match of text.matchAll(pattern)) {
|
|
389
|
+
const matchIndex = match.index ?? 0;
|
|
390
|
+
const prefix = match[1] ?? "";
|
|
391
|
+
const skillName = match[2] ?? "";
|
|
392
|
+
if (!availableSkills.has(skillName)) {
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
buffer += text.slice(cursor, matchIndex) + prefix;
|
|
396
|
+
if (buffer.length > 0) {
|
|
397
|
+
blocks.push({ type: "text", text: buffer });
|
|
398
|
+
buffer = "";
|
|
399
|
+
}
|
|
400
|
+
blocks.push({ type: "skill", name: skillName });
|
|
401
|
+
cursor = matchIndex + match[0].length;
|
|
402
|
+
}
|
|
403
|
+
buffer += text.slice(cursor);
|
|
404
|
+
if (buffer.length > 0) {
|
|
405
|
+
blocks.push({ type: "text", text: buffer });
|
|
406
|
+
}
|
|
407
|
+
return blocks;
|
|
408
|
+
};
|
|
409
|
+
//# sourceMappingURL=InteractiveCommands.js.map
|