@2kw/ai 6.3.0-dev.36 → 6.3.0-dev.39

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.
@@ -98,6 +98,22 @@ export function makeConversationsCommand() {
98
98
  formatSuccess(`Conversation ${conversationId} deleted.`, command);
99
99
  });
100
100
  });
101
+ cmd
102
+ .command("cancel")
103
+ .description("Ask a running turn of a conversation to stop")
104
+ .argument("<conversationId>", "Conversation ID")
105
+ .requiredOption("--turn <turnId>", "The turn id the client sent as the Backbone-Turn-Id header")
106
+ .action(async (conversationId, opts, command) => {
107
+ await runAction(command, async () => {
108
+ const client = getClient(command);
109
+ await client.POST("/v1/conversations/{conversationId}/cancel", {
110
+ params: { path: { conversationId } },
111
+ body: { turn_id: opts.turn },
112
+ });
113
+ // Accepted, not performed: the turn's own response says whether it stopped.
114
+ formatSuccess(`Stop requested for turn ${opts.turn} of conversation ${conversationId}.`, command);
115
+ });
116
+ });
101
117
  const items = new Command("items").description("List a conversation's items");
102
118
  items
103
119
  .command("list")
@@ -1,5 +1,8 @@
1
+ import type { components } from "../generated/openapi.js";
1
2
  type AnyRecord = Record<string, any>;
2
3
  export type RunStatus = "completed" | "requires_approval" | "requires_tool_output" | "incomplete";
4
+ /** A built-in SkillsApply approval's preview (#781, spec §6); the generated type, fields all optional. */
5
+ export type SkillsApplyPreview = components["schemas"]["SkillsApplyPreview"];
3
6
  export interface PendingApproval {
4
7
  approvalId: string;
5
8
  callId: string;
@@ -8,6 +11,8 @@ export interface PendingApproval {
8
11
  policyClass: string;
9
12
  /** Why the automatic approver escalated this request to a human (#634); null when it did not. */
10
13
  reason: string | null;
14
+ /** What a built-in SkillsApply change does (#781); null for every other approval. Keyed on presence, not on the tool name (#948). */
15
+ preview: SkillsApplyPreview | null;
11
16
  }
12
17
  export interface ToolCallSummary {
13
18
  tool: string;
@@ -80,6 +80,7 @@ export function buildRunEnvelope(result, agentRef) {
80
80
  arguments: parseArguments(i.arguments),
81
81
  policyClass: String(i.policy_class),
82
82
  reason: typeof i.reason === "string" && i.reason ? i.reason : null,
83
+ preview: i.preview && typeof i.preview === "object" && !Array.isArray(i.preview) ? i.preview : null,
83
84
  }));
84
85
  const withheldCallIds = new Set(pendingApprovals.map((a) => a.callId));
85
86
  const toolCalls = [];
@@ -1,6 +1,7 @@
1
1
  import { createInterface } from "node:readline/promises";
2
2
  import chalk from "chalk";
3
3
  import { stripControl } from "./agent-run.js";
4
+ import { REMEMBER_NOTE, previewIsIncomplete, previewLines } from "./skills-apply-preview.js";
4
5
  /** Raised when the prompt's input closes (EOF, Ctrl+C, Ctrl+D) before an answer arrives. */
5
6
  export class PromptAbortedError extends Error {
6
7
  constructor() {
@@ -54,7 +55,23 @@ export async function promptApprovals(pending, ask, write = (line) => console.er
54
55
  const destructive = a.policyClass.toLowerCase() === "destructive";
55
56
  write(chalk.yellow(`\nApproval ${index + 1}/${pending.length}: ${s(a.tool)} [${s(a.policyClass)}]`));
56
57
  // JSON.stringify escapes C0 controls but leaves DEL and C1 raw.
57
- write(chalk.dim(s(JSON.stringify(a.arguments, null, 2))));
58
+ const request = () => write(chalk.dim(s(JSON.stringify(a.arguments, null, 2))));
59
+ if (a.preview) {
60
+ // A SkillsApply change reads as its diff (#782, spec §10). When the preview leaves changes
61
+ // out, the full arguments follow it: this prompt never runs with --json, so it is the only
62
+ // place the member can read what would persist (spec D7).
63
+ for (const line of previewLines(a.preview))
64
+ write(colourPreviewLine(s(line)));
65
+ if (previewIsIncomplete(a.preview)) {
66
+ write(chalk.dim("Full request (the preview leaves changes out):"));
67
+ request();
68
+ }
69
+ if (!destructive)
70
+ write(chalk.dim(REMEMBER_NOTE));
71
+ }
72
+ else {
73
+ request();
74
+ }
58
75
  if (a.reason)
59
76
  write(chalk.dim(`reason: ${s(a.reason)}`));
60
77
  const question = destructive ? "[a]pprove / [r]eject? " : "[a]pprove / [r]eject / approve and [R]emember? ";
@@ -81,4 +98,17 @@ export async function promptApprovals(pending, ask, write = (line) => console.er
81
98
  }
82
99
  return answers;
83
100
  }
101
+ /** Diff lines sit indented six spaces under their file; only those are coloured. */
102
+ function colourPreviewLine(line) {
103
+ if (!line.startsWith(" "))
104
+ return line;
105
+ const body = line.slice(6);
106
+ if (body.startsWith("+"))
107
+ return chalk.green(line);
108
+ if (body.startsWith("-"))
109
+ return chalk.red(line);
110
+ if (body.startsWith("@@"))
111
+ return chalk.cyan(line);
112
+ return chalk.dim(line);
113
+ }
84
114
  //# sourceMappingURL=approval-prompt.js.map
@@ -0,0 +1,19 @@
1
+ import type { SkillsApplyPreview } from "./agent-run.js";
2
+ /** The grant's consequence for a SkillsApply change (spec §6, D13), shown next to "approve and Remember". */
3
+ export declare const REMEMBER_NOTE = "approve and Remember: later skill changes you make in this chat apply without asking";
4
+ /**
5
+ * A SkillsApply preview as plain text, one entry per line (#782, spec §10): per skill where it
6
+ * starts and the labels it moves, each file with its unified diff indented under it, then the
7
+ * followers snapshot and the binding. Lines are unstyled and unstripped; the prompt does both.
8
+ * The generated type marks every field optional and the wire sends nulls, so every read is guarded.
9
+ */
10
+ export declare function previewLines(preview: SkillsApplyPreview): string[];
11
+ /**
12
+ * Whether the preview leaves part of the change unseen (#782, spec D7): a skill with files left
13
+ * out, a diff that was cut, or an add or edit with no diff at all (abandoned as too large, or a
14
+ * base the server could not read). The prompt then prints the full arguments as well, because a
15
+ * change that persists must be readable at the prompt. A `put` or `delete` carries no diff by
16
+ * design and does not count. Guarded like {@link previewLines}: every field optional, nulls on the wire.
17
+ */
18
+ export declare function previewIsIncomplete(preview: SkillsApplyPreview): boolean;
19
+ //# sourceMappingURL=skills-apply-preview.d.ts.map
@@ -0,0 +1,94 @@
1
+ /** The grant's consequence for a SkillsApply change (spec §6, D13), shown next to "approve and Remember". */
2
+ export const REMEMBER_NOTE = "approve and Remember: later skill changes you make in this chat apply without asking";
3
+ const OP_WORDS = { add: "new file", edit: "edited", delete: "deleted", put: "uploaded file" };
4
+ /**
5
+ * A SkillsApply preview as plain text, one entry per line (#782, spec §10): per skill where it
6
+ * starts and the labels it moves, each file with its unified diff indented under it, then the
7
+ * followers snapshot and the binding. Lines are unstyled and unstripped; the prompt does both.
8
+ * The generated type marks every field optional and the wire sends nulls, so every read is guarded.
9
+ */
10
+ export function previewLines(preview) {
11
+ const lines = ["Skill changes:"];
12
+ for (const skill of list(preview.skills)) {
13
+ const name = String(skill.name ?? "");
14
+ const from = typeof skill.from === "number" ? skill.from : null;
15
+ const moves = list(skill.moves).map(String);
16
+ const start = from === null ? `${name}: new skill` : `${name} v${from} -> new version`;
17
+ lines.push(` ${start}${moves.length > 0 ? `, moves ${moves.join(", ")}` : ""}`);
18
+ if (typeof skill.fork_of_plugin === "string" && skill.fork_of_plugin) {
19
+ lines.push(` forks the plugin skill from ${skill.fork_of_plugin}: later plugin syncs no longer move latest`);
20
+ }
21
+ for (const file of list(skill.files))
22
+ lines.push(...fileLines(file));
23
+ const omitted = typeof skill.files_omitted === "number" ? skill.files_omitted : 0;
24
+ if (omitted > 0)
25
+ lines.push(` ${omitted} more ${omitted === 1 ? "file" : "files"} not shown`);
26
+ }
27
+ const followers = preview.followers;
28
+ if (followers) {
29
+ const agents = list(followers.agents).map(String);
30
+ const more = typeof followers.more === "number" ? followers.more : 0;
31
+ const when = typeof followers.as_of === "string" ? ` (as of ${followers.as_of})` : "";
32
+ if (agents.length === 0 && more === 0)
33
+ lines.push(`No agent follows these labels${when}`);
34
+ else
35
+ lines.push(`Agents following these labels${when}: ${agents.length > 0 ? agents.join(", ") : `${more} agents`}${agents.length > 0 && more > 0 ? ` and ${more} more` : ""}`);
36
+ }
37
+ const agent = preview.agent;
38
+ const bind = agent ? list(agent.bind).map(String) : [];
39
+ if (agent && bind.length > 0) {
40
+ const base = typeof agent.from === "number" ? ` (new agent version from v${agent.from})` : "";
41
+ lines.push(`Binds ${bind.join(", ")} to this agent${base}`);
42
+ }
43
+ return lines;
44
+ }
45
+ /**
46
+ * Whether the preview leaves part of the change unseen (#782, spec D7): a skill with files left
47
+ * out, a diff that was cut, or an add or edit with no diff at all (abandoned as too large, or a
48
+ * base the server could not read). The prompt then prints the full arguments as well, because a
49
+ * change that persists must be readable at the prompt. A `put` or `delete` carries no diff by
50
+ * design and does not count. Guarded like {@link previewLines}: every field optional, nulls on the wire.
51
+ */
52
+ export function previewIsIncomplete(preview) {
53
+ for (const skill of list(preview.skills)) {
54
+ if (typeof skill.files_omitted === "number" && skill.files_omitted > 0)
55
+ return true;
56
+ for (const file of list(skill.files)) {
57
+ if (file.truncated === true)
58
+ return true;
59
+ if ((file.op === "add" || file.op === "edit") && typeof file.diff !== "string")
60
+ return true;
61
+ }
62
+ }
63
+ return false;
64
+ }
65
+ function fileLines(file) {
66
+ const facts = [OP_WORDS[String(file.op)] ?? String(file.op)];
67
+ if (typeof file.added === "number" && typeof file.removed === "number")
68
+ facts.push(`+${file.added} -${file.removed}`);
69
+ if (typeof file.bytes === "number")
70
+ facts.push(size(file.bytes));
71
+ const lines = [` ${String(file.path ?? "")}: ${facts.join(", ")}`];
72
+ const diff = typeof file.diff === "string" ? file.diff : null;
73
+ if (diff !== null) {
74
+ for (const line of diff.split("\n"))
75
+ lines.push(` ${line}`);
76
+ if (file.truncated === true)
77
+ lines.push(" (diff cut; the counts cover every changed line)");
78
+ }
79
+ else if (file.truncated === true) {
80
+ lines.push(` too many changes to show: at most +${Number(file.added ?? 0)} -${Number(file.removed ?? 0)} lines`);
81
+ }
82
+ return lines;
83
+ }
84
+ function list(value) {
85
+ return Array.isArray(value) ? value.filter((entry) => entry !== null && entry !== undefined) : [];
86
+ }
87
+ function size(bytes) {
88
+ if (bytes < 1024)
89
+ return `${bytes} B`;
90
+ if (bytes < 1024 * 1024)
91
+ return `${Math.round(bytes / 1024)} KB`;
92
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
93
+ }
94
+ //# sourceMappingURL=skills-apply-preview.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2kw/ai",
3
- "version": "6.3.0-dev.36",
3
+ "version": "6.3.0-dev.39",
4
4
  "description": "CLI for 2kw.ai — schema-driven document extraction, an OpenAI-compatible EU LLM gateway, transcription, prompts, datasets, and experiments from your terminal or agentic workflows. Ships as 2kw, backbone, and bb.",
5
5
  "keywords": [
6
6
  "cli",