@vincemakes/kiso-code 0.15.6 → 0.15.8

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,41 @@
1
+ /**
2
+ * REL-0152-D11 — an image reaches the model.
3
+ *
4
+ * The wire was already complete and nobody had noticed. The `user_input`
5
+ * event's content has been `string | ContentBlock[]` since the protocol
6
+ * was written; the projection passes it through untouched; the Anthropic
7
+ * adapter sends an `image` block and the OpenAI-compatible family sends
8
+ * `image_url` with a data URI. What was missing was at the two ends:
9
+ * `session.run()` narrowed its parameter to text, and the CLI never
10
+ * built a block — `grep 'type: "image"' apps/cli/src` came back empty.
11
+ *
12
+ * This module is the CLI end. A turn's text is scanned for references to
13
+ * image files and each one becomes an image block beside the words.
14
+ *
15
+ * The reference is a PATH, deliberately, because two things a user can
16
+ * already do produce one on any terminal with no clipboard involved:
17
+ * dragging a file into the window, which terminals answer by inserting
18
+ * its path, and typing or pasting a path. Clipboard image paste is a
19
+ * separate mechanism with a separate open question (see the finding);
20
+ * this one works today, everywhere, and is what that mechanism will
21
+ * hand its temp file to when it lands.
22
+ */
23
+ import type { ContentBlock } from "@vincemakes/kiso-core";
24
+ /** The four media types the protocol accepts, recognised by the file's
25
+ * own leading bytes. A name is a claim; the bytes are the fact, and a
26
+ * screenshot saved as `.jpg` is a very ordinary thing to have. */
27
+ export declare function sniff(buf: Buffer): "image/png" | "image/jpeg" | "image/gif" | "image/webp" | null;
28
+ /**
29
+ * The turn's content: the string itself when nothing was attached, or
30
+ * the blocks when something was.
31
+ *
32
+ * Returning the STRING unchanged in the common case is not an
33
+ * optimisation, it is the compatibility guarantee: a turn with no image
34
+ * produces exactly the bytes it produced before this module existed, so
35
+ * every request that is not about an image is unaffected by the feature.
36
+ *
37
+ * A path that is not there, or is not an image, or is too large, is left
38
+ * standing in the text. Silently dropping it would tell the model about
39
+ * a file it cannot see, which is worse than telling it nothing.
40
+ */
41
+ export declare function attachImages(text: string): string | ContentBlock[];
@@ -0,0 +1,122 @@
1
+ /**
2
+ * REL-0152-D11 — an image reaches the model.
3
+ *
4
+ * The wire was already complete and nobody had noticed. The `user_input`
5
+ * event's content has been `string | ContentBlock[]` since the protocol
6
+ * was written; the projection passes it through untouched; the Anthropic
7
+ * adapter sends an `image` block and the OpenAI-compatible family sends
8
+ * `image_url` with a data URI. What was missing was at the two ends:
9
+ * `session.run()` narrowed its parameter to text, and the CLI never
10
+ * built a block — `grep 'type: "image"' apps/cli/src` came back empty.
11
+ *
12
+ * This module is the CLI end. A turn's text is scanned for references to
13
+ * image files and each one becomes an image block beside the words.
14
+ *
15
+ * The reference is a PATH, deliberately, because two things a user can
16
+ * already do produce one on any terminal with no clipboard involved:
17
+ * dragging a file into the window, which terminals answer by inserting
18
+ * its path, and typing or pasting a path. Clipboard image paste is a
19
+ * separate mechanism with a separate open question (see the finding);
20
+ * this one works today, everywhere, and is what that mechanism will
21
+ * hand its temp file to when it lands.
22
+ */
23
+ import { readFileSync, statSync } from "node:fs";
24
+ /**
25
+ * The size a single image may reach before it is refused.
26
+ *
27
+ * Providers cap image payloads and base64 inflates by a third, so a file
28
+ * near this bound is already near theirs. The refusal is deliberate and
29
+ * VISIBLE: the path stays in the text, so the model is told a file was
30
+ * named rather than being handed a request that the provider will reject
31
+ * with something the user cannot act on.
32
+ */
33
+ const MAX_IMAGE_BYTES = 5 * 1024 * 1024;
34
+ /** The four media types the protocol accepts, recognised by the file's
35
+ * own leading bytes. A name is a claim; the bytes are the fact, and a
36
+ * screenshot saved as `.jpg` is a very ordinary thing to have. */
37
+ export function sniff(buf) {
38
+ if (buf.length >= 8 && buf.subarray(0, 8).equals(Buffer.from("89504e470d0a1a0a", "hex")))
39
+ return "image/png";
40
+ if (buf.length >= 3 && buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff)
41
+ return "image/jpeg";
42
+ if (buf.length >= 6 && (buf.subarray(0, 6).toString("latin1") === "GIF87a" || buf.subarray(0, 6).toString("latin1") === "GIF89a"))
43
+ return "image/gif";
44
+ if (buf.length >= 12 && buf.subarray(0, 4).toString("latin1") === "RIFF" && buf.subarray(8, 12).toString("latin1") === "WEBP")
45
+ return "image/webp";
46
+ return null;
47
+ }
48
+ /**
49
+ * Path-shaped runs in a line, longest first so a quoted path wins over
50
+ * the bare fragment inside it. Quoted forms come first because that is
51
+ * what a terminal inserts for a name containing a space.
52
+ */
53
+ const CANDIDATES = [
54
+ /'([^']*\.(?:png|jpe?g|gif|webp))'/gi,
55
+ /"([^"]*\.(?:png|jpe?g|gif|webp))"/gi,
56
+ /(\S*\.(?:png|jpe?g|gif|webp))/gi,
57
+ ];
58
+ function look(path) {
59
+ try {
60
+ const st = statSync(path);
61
+ if (!st.isFile() || st.size > MAX_IMAGE_BYTES || st.size === 0)
62
+ return null;
63
+ const buf = readFileSync(path);
64
+ const mediaType = sniff(buf);
65
+ if (mediaType === null)
66
+ return null;
67
+ return { mediaType, data: buf.toString("base64") };
68
+ }
69
+ catch {
70
+ return null; // not there, not readable, not ours to complain about
71
+ }
72
+ }
73
+ /**
74
+ * The turn's content: the string itself when nothing was attached, or
75
+ * the blocks when something was.
76
+ *
77
+ * Returning the STRING unchanged in the common case is not an
78
+ * optimisation, it is the compatibility guarantee: a turn with no image
79
+ * produces exactly the bytes it produced before this module existed, so
80
+ * every request that is not about an image is unaffected by the feature.
81
+ *
82
+ * A path that is not there, or is not an image, or is too large, is left
83
+ * standing in the text. Silently dropping it would tell the model about
84
+ * a file it cannot see, which is worse than telling it nothing.
85
+ */
86
+ export function attachImages(text) {
87
+ const found = [];
88
+ const claimed = [];
89
+ for (const re of CANDIDATES) {
90
+ re.lastIndex = 0;
91
+ for (const m of text.matchAll(re)) {
92
+ const path = m[1];
93
+ const start = m.index;
94
+ const end = start + m[0].length;
95
+ if (claimed.some((c) => start < c.end && end > c.start))
96
+ continue;
97
+ const hit = look(path);
98
+ if (hit === null)
99
+ continue;
100
+ claimed.push({ start, end });
101
+ found.push({ start, end, block: { type: "image", sourceType: "base64", mediaType: hit.mediaType, data: hit.data } });
102
+ }
103
+ }
104
+ if (found.length === 0)
105
+ return text;
106
+ found.sort((a, b) => a.start - b.start);
107
+ // the words are kept and kept IN PLACE: a turn is "what is wrong
108
+ // here?" plus the screenshot, and the question is half of it.
109
+ const blocks = [];
110
+ let at = 0;
111
+ for (const f of found) {
112
+ const before = text.slice(at, f.start).trim();
113
+ if (before !== "")
114
+ blocks.push({ type: "text", text: before });
115
+ blocks.push(f.block);
116
+ at = f.end;
117
+ }
118
+ const tail = text.slice(at).trim();
119
+ if (tail !== "")
120
+ blocks.push({ type: "text", text: tail });
121
+ return blocks;
122
+ }
package/dist/chat.js CHANGED
@@ -12,6 +12,7 @@ import { canonicalizeUsage } from "@vincemakes/kiso-runtime";
12
12
  import { canonicalizeUsageForModel } from "@vincemakes/kiso-runtime/internal";
13
13
  import { dispatch } from "./dispatch.js";
14
14
  import { agentModel, body, bodyLog, configuredWindow, dock } from "./state.js";
15
+ import { attachImages } from "./attachments.js";
15
16
  import { lookupModelMetadata } from "@vincemakes/kiso-runtime/internal";
16
17
  import { addDontAskAgainRule, askPanel, fixHintFor, pendingAsk, resolveUncertains } from "./trust-ui.js";
17
18
  import { FauxExhaustionError, failOnFauxExhaustion } from "./faux-glue.js";
@@ -822,7 +823,13 @@ export async function chat(session, faux, input, autoCompact, nav) {
822
823
  };
823
824
  const turn = (text, seedSource) => new Promise((resolve, reject) => {
824
825
  queued = Math.max(0, queued - 1); // a queued turn starts
825
- const run = seedSource !== undefined ? session.run(text, { source: seedSource }) : session.run(text);
826
+ // REL-0152-D11: a turn that names an image file carries it. The
827
+ // scan returns the STRING unchanged when it finds nothing, so a
828
+ // turn without one is byte-identical to before the feature.
829
+ // Seeded turns are the product's own words and are never
830
+ // scanned — nothing it writes to itself is an attachment.
831
+ const content = seedSource !== undefined ? text : attachImages(text);
832
+ const run = seedSource !== undefined ? session.run(content, { source: seedSource }) : session.run(content);
826
833
  currentRun = run;
827
834
  turnNo += 1;
828
835
  const myTurn = turnNo;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * REL-0152-D11 — reading an image off the clipboard.
3
+ *
4
+ * SPLIT from attachments.ts on purpose. The pty-manifest gate
5
+ * classifies a test by its resource-dependency CLOSURE, and a module
6
+ * that spawns drags every test that imports it into the serial pool.
7
+ * The path scanning and the block building are pure and belong in the
8
+ * fast pool; only this file needs a process, so only this file's tests
9
+ * pay for one. The gate found that out, which is what it is for.
10
+ */
11
+ /**
12
+ * REL-0152-D11, the clipboard half.
13
+ *
14
+ * Pasting an image into a terminal sends NOTHING useful: the terminal
15
+ * has no way to put binary into a byte stream, so a bracketed paste
16
+ * arrives empty (or with a filename, depending on the source app). An
17
+ * empty paste is therefore the signal — the user pressed paste and the
18
+ * terminal had nothing to give us — and the image, if there is one, has
19
+ * to be fetched from the clipboard directly.
20
+ *
21
+ * macOS only for now, through `osascript`, which is present on every
22
+ * Mac and needs no dependency. The coercion `the clipboard as «class
23
+ * PNGf»` is the documented way to get PNG bytes out of the pasteboard.
24
+ *
25
+ * KNOWN UNRESOLVED, and stated here rather than discovered later: that
26
+ * coercion FAILS with error -1700 when osascript runs detached from the
27
+ * user's session, which is where this was developed. `clipboard info`
28
+ * correctly reports the PNG flavour is present, so it is not a
29
+ * permission wall — it has the shape of a promised (lazily rendered)
30
+ * flavour that the source app materialises only for a process in the
31
+ * right session context. kiso runs in the user's own terminal session,
32
+ * where it may simply work. This returns null on any failure and the
33
+ * caller says so out loud; nothing here guesses.
34
+ */
35
+ export declare function clipboardImage(dir: string, run?: (cmd: string, args: readonly string[]) => {
36
+ status: number | null;
37
+ }): string | null;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * REL-0152-D11 — reading an image off the clipboard.
3
+ *
4
+ * SPLIT from attachments.ts on purpose. The pty-manifest gate
5
+ * classifies a test by its resource-dependency CLOSURE, and a module
6
+ * that spawns drags every test that imports it into the serial pool.
7
+ * The path scanning and the block building are pure and belong in the
8
+ * fast pool; only this file needs a process, so only this file's tests
9
+ * pay for one. The gate found that out, which is what it is for.
10
+ */
11
+ import { readFileSync, statSync } from "node:fs";
12
+ import { spawnSync } from "node:child_process";
13
+ import { join } from "node:path";
14
+ import { sniff } from "./attachments.js";
15
+ /**
16
+ * REL-0152-D11, the clipboard half.
17
+ *
18
+ * Pasting an image into a terminal sends NOTHING useful: the terminal
19
+ * has no way to put binary into a byte stream, so a bracketed paste
20
+ * arrives empty (or with a filename, depending on the source app). An
21
+ * empty paste is therefore the signal — the user pressed paste and the
22
+ * terminal had nothing to give us — and the image, if there is one, has
23
+ * to be fetched from the clipboard directly.
24
+ *
25
+ * macOS only for now, through `osascript`, which is present on every
26
+ * Mac and needs no dependency. The coercion `the clipboard as «class
27
+ * PNGf»` is the documented way to get PNG bytes out of the pasteboard.
28
+ *
29
+ * KNOWN UNRESOLVED, and stated here rather than discovered later: that
30
+ * coercion FAILS with error -1700 when osascript runs detached from the
31
+ * user's session, which is where this was developed. `clipboard info`
32
+ * correctly reports the PNG flavour is present, so it is not a
33
+ * permission wall — it has the shape of a promised (lazily rendered)
34
+ * flavour that the source app materialises only for a process in the
35
+ * right session context. kiso runs in the user's own terminal session,
36
+ * where it may simply work. This returns null on any failure and the
37
+ * caller says so out loud; nothing here guesses.
38
+ */
39
+ export function clipboardImage(dir, run = defaultRun) {
40
+ if (process.platform !== "darwin")
41
+ return null;
42
+ const target = join(dir, `paste-${process.pid}-${Date.now()}.png`);
43
+ const script = [
44
+ "set d to (the clipboard as «class PNGf»)",
45
+ `set f to open for access POSIX file ${JSON.stringify(target)} with write permission`,
46
+ "set eof f to 0",
47
+ "write d to f",
48
+ "close access f",
49
+ ].flatMap((line) => ["-e", line]);
50
+ try {
51
+ const r = run("osascript", script);
52
+ if (r.status !== 0)
53
+ return null;
54
+ // the file must be a real image by the SAME sniffer the path
55
+ // route uses — a zero-byte file from a half-failed coercion is
56
+ // exactly what this round already produced once
57
+ const st = statSync(target);
58
+ if (!st.isFile() || st.size === 0)
59
+ return null;
60
+ if (sniff(readFileSync(target)) === null)
61
+ return null;
62
+ return target;
63
+ }
64
+ catch {
65
+ return null;
66
+ }
67
+ }
68
+ function defaultRun(cmd, args) {
69
+ return spawnSync(cmd, [...args], { stdio: "ignore", timeout: 5000 });
70
+ }
package/dist/index.js CHANGED
@@ -43,6 +43,8 @@ import { loadProjectConfig, loadUserConfig, mergeConfigs, resolveAutoCompact, re
43
43
  import { resume } from "./resume.js";
44
44
  import { resumeTail } from "./resume-tail.js";
45
45
  import { armByteTrace } from "./byte-trace.js";
46
+ import { tmpdir } from "node:os";
47
+ import { clipboardImage } from "./clipboard.js";
46
48
  import { collectSessionCards, projectSessionCard } from "./session-cards.js";
47
49
  // The moved exports stay reachable from this entry — the test imports
48
50
  // (project-trust, coding-agent) never change (B4: zero assertion changes).
@@ -166,6 +168,9 @@ function editorInput(editor) {
166
168
  onRedirect(cb) {
167
169
  editor.onRedirect(cb);
168
170
  },
171
+ onClipboardPaste(cb) {
172
+ editor.onClipboardPaste(cb);
173
+ },
169
174
  question(query, cb) {
170
175
  editor.question(query, cb);
171
176
  },
@@ -759,6 +764,18 @@ async function main() {
759
764
  editCol: () => dock.editCol(),
760
765
  onDock: () => dock.redraw(), // v2d-B: the freeze scrolls the dock up — re-pin it
761
766
  }));
767
+ // REL-0152-D11: pasting an image sends no bytes, so an empty paste is
768
+ // the signal to go and look at the clipboard. What comes back is a
769
+ // PATH, which the turn's attachment scan then picks up exactly as it
770
+ // would a dragged-in file — one mechanism, two ways of naming a file.
771
+ input.onClipboardPaste?.(() => {
772
+ const shot = clipboardImage(tmpdir());
773
+ if (shot === null) {
774
+ bodyLog("[no image on the clipboard — ctrl+V attaches one; a file dragged into the window works too]");
775
+ return null;
776
+ }
777
+ return shot;
778
+ });
762
779
  try {
763
780
  // merge round B: the project config's mode applies AFTER the trust gate
764
781
  // (its verdict decides whether the project config exists at all) —
package/dist/state.d.ts CHANGED
@@ -75,6 +75,11 @@ export interface LineInput {
75
75
  * to stop. OPTIONAL: the pipe path has no raw keys and never wires
76
76
  * it, so readline stays exactly as it was. */
77
77
  onRedirect?(cb: (line: string) => void): void;
78
+ /** REL-0152-D11: an empty bracketed paste is the image case — a
79
+ * terminal cannot put binary in a byte stream, so pasting one sends
80
+ * nothing. The callback returns text to insert (a path) or null.
81
+ * Optional: the pipe path has no editor and no clipboard. */
82
+ onClipboardPaste?(cb: () => string | null): void;
78
83
  question(query: string, cb: (answer: string) => void): void;
79
84
  cancelQuestion(): void;
80
85
  /** W21: open the approval panel — the editor's state machine takes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vincemakes/kiso-code",
3
- "version": "0.15.6",
3
+ "version": "0.15.8",
4
4
  "description": "kiso CLI \u2014 the durable coding agent that survives kill -9: kiso chat / kiso resume / kiso sessions.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -18,19 +18,19 @@
18
18
  "test": "vitest run"
19
19
  },
20
20
  "dependencies": {
21
- "@vincemakes/kiso-ask-ext": "0.15.6",
22
- "@vincemakes/kiso-core": "0.15.6",
23
- "@vincemakes/kiso-evals": "0.15.6",
24
- "@vincemakes/kiso-mcp-ext": "0.15.6",
25
- "@vincemakes/kiso-provider-anthropic": "0.15.6",
26
- "@vincemakes/kiso-provider-openai": "0.15.6",
27
- "@vincemakes/kiso-runtime": "0.15.6",
28
- "@vincemakes/kiso-skills-ext": "0.15.6",
29
- "@vincemakes/kiso-subagent-ext": "0.15.6",
30
- "@vincemakes/kiso-task-ext": "0.15.6",
31
- "@vincemakes/kiso-tools-node": "0.15.6",
32
- "@vincemakes/kiso-tui": "0.15.6",
33
- "@vincemakes/kiso-tui-cells": "0.15.6"
21
+ "@vincemakes/kiso-ask-ext": "0.15.8",
22
+ "@vincemakes/kiso-core": "0.15.8",
23
+ "@vincemakes/kiso-evals": "0.15.8",
24
+ "@vincemakes/kiso-mcp-ext": "0.15.8",
25
+ "@vincemakes/kiso-provider-anthropic": "0.15.8",
26
+ "@vincemakes/kiso-provider-openai": "0.15.8",
27
+ "@vincemakes/kiso-runtime": "0.15.8",
28
+ "@vincemakes/kiso-skills-ext": "0.15.8",
29
+ "@vincemakes/kiso-subagent-ext": "0.15.8",
30
+ "@vincemakes/kiso-task-ext": "0.15.8",
31
+ "@vincemakes/kiso-tools-node": "0.15.8",
32
+ "@vincemakes/kiso-tui": "0.15.8",
33
+ "@vincemakes/kiso-tui-cells": "0.15.8"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^26.1.2",