ainecto 0.16.2 → 0.16.3

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/README.md CHANGED
@@ -221,7 +221,8 @@ ainecto term restore # after a reboot: start again
221
221
 
222
222
  - Keys for `key`: `enter`, `tab`, `shift-tab`, `escape`, `backspace`, `delete`, `space`, `up`, `down`,
223
223
  `left`, `right`, `home`, `end`, `pageup`, `pagedown`, `ctrl-a` … `ctrl-z` (`ctrl+c`, `esc` and `return`
224
- are accepted too).
224
+ are accepted too). `wheel-up` and `wheel-down` scroll one step: a mouse wheel report when the app turned on
225
+ mouse tracking, otherwise the up/down key in a full-screen app (nothing in a plain shell).
225
226
  - `send --paste` sends the text as a bracketed paste when the app asked for one. To send text that starts
226
227
  with `-`, put it after `--`.
227
228
  - In `attach`, press `Ctrl-\` twice to send one `Ctrl-\` to the app.
@@ -271,7 +272,7 @@ This is the entry `setup --local` and `init --mcp --local` write — you normall
271
272
  "mcpServers": {
272
273
  "ainecto": {
273
274
  "command": "npx",
274
- "args": ["-y", "@ainecto/mcp@0.16.2"]
275
+ "args": ["-y", "@ainecto/mcp@0.16.3"]
275
276
  }
276
277
  }
277
278
  }
@@ -5699,8 +5699,8 @@ function legacyRoleInput(flag, envVars = process.env) {
5699
5699
 
5700
5700
  // src/core/version.ts
5701
5701
  var UNBUNDLED_VERSION = "dev";
5702
- var CLI_VERSION = true ? "0.16.2" : UNBUNDLED_VERSION;
5703
- var CLI_BUILD = true ? "3033982" : void 0;
5702
+ var CLI_VERSION = true ? "0.16.3" : UNBUNDLED_VERSION;
5703
+ var CLI_BUILD = true ? "8924808" : void 0;
5704
5704
  function cliVersionLabel(version, build, release2) {
5705
5705
  return release2 || build === void 0 ? version : `${version}-dev+${build}`;
5706
5706
  }
@@ -11369,7 +11369,14 @@ function parseClientMessage(line) {
11369
11369
  case "key":
11370
11370
  return { id, op, name: stringField(record4, "name"), key: stringField(record4, "key"), ...optionalInstance(record4) };
11371
11371
  case "read":
11372
- return { id, op, name: stringField(record4, "name"), scrollback: record4.scrollback === true, lines: optionalSize(record4, "lines") };
11372
+ return {
11373
+ id,
11374
+ op,
11375
+ name: stringField(record4, "name"),
11376
+ scrollback: record4.scrollback === true,
11377
+ lines: optionalSize(record4, "lines"),
11378
+ ...record4.styles === true ? { styles: true } : {}
11379
+ };
11373
11380
  case "kill":
11374
11381
  return { id, op, name: stringField(record4, "name"), ...optionalInstance(record4) };
11375
11382
  case "watch":
@@ -11441,7 +11448,17 @@ function readModes(data) {
11441
11448
  const altScreen = "altScreen" in modes ? modes.altScreen : void 0;
11442
11449
  const appCursor = "appCursor" in modes ? modes.appCursor : void 0;
11443
11450
  const bracketedPaste = "bracketedPaste" in modes ? modes.bracketedPaste : void 0;
11444
- return typeof altScreen === "boolean" && typeof appCursor === "boolean" && typeof bracketedPaste === "boolean" ? { altScreen, appCursor, bracketedPaste } : void 0;
11451
+ const mouse = "mouse" in modes ? modes.mouse : void 0;
11452
+ return typeof altScreen === "boolean" && typeof appCursor === "boolean" && typeof bracketedPaste === "boolean" ? { altScreen, appCursor, bracketedPaste, ...typeof mouse === "boolean" ? { mouse } : {} } : void 0;
11453
+ }
11454
+ function readStyles(data, lineCount) {
11455
+ if (!data || typeof data !== "object" || !("styles" in data) || !("runs" in data)) return void 0;
11456
+ const { styles, runs } = data;
11457
+ if (!Array.isArray(styles) || !styles.every((style) => style && typeof style === "object" && !Array.isArray(style))) return void 0;
11458
+ if (!Array.isArray(runs) || runs.length !== lineCount || !runs.every((row) => Array.isArray(row) && row.length % 3 === 0 && row.every((value) => Number.isInteger(value) && value >= 0))) return void 0;
11459
+ const cursor = "cursor" in data ? data.cursor : void 0;
11460
+ const at = cursor && typeof cursor === "object" && "row" in cursor && "col" in cursor && Number.isInteger(cursor.row) && Number.isInteger(cursor.col) ? { row: cursor.row, col: cursor.col } : void 0;
11461
+ return { styles, runs, ...at ? { cursor: at } : {} };
11445
11462
  }
11446
11463
  function sessionInstance(data) {
11447
11464
  return data && typeof data === "object" && "instance" in data && typeof data.instance === "string" && data.instance !== "" ? data.instance : void 0;
@@ -11852,8 +11869,24 @@ var KEY_NAMES = [
11852
11869
  "ctrl-space",
11853
11870
  "ctrl-slash",
11854
11871
  "alt-<key>",
11855
- "ctrl-/shift-/alt- + up/down/left/right/home/end/pageup/pagedown/delete"
11872
+ "ctrl-/shift-/alt- + up/down/left/right/home/end/pageup/pagedown/delete",
11873
+ "wheel-up",
11874
+ "wheel-down"
11856
11875
  ];
11876
+ function wheelBytes(up, context) {
11877
+ const wheel = context.wheel;
11878
+ if (!wheel) return void 0;
11879
+ if (wheel.mouseTracking !== "none") {
11880
+ const button = up ? 64 : 65;
11881
+ const x = Math.max(1, Math.ceil(wheel.cols / 2));
11882
+ const y = Math.max(1, Math.ceil(wheel.rows / 2));
11883
+ return wheel.sgrMouse ? `\x1B[<${button};${x};${y}M` : `\x1B[M${String.fromCharCode(32 + button, 32 + Math.min(x, 223), 32 + Math.min(y, 223))}`;
11884
+ }
11885
+ if (wheel.altScreen) {
11886
+ return `${context.applicationCursorKeys ? "\x1BO" : "\x1B["}${up ? "A" : "B"}`;
11887
+ }
11888
+ return "";
11889
+ }
11857
11890
  function normalizeKeyName(raw) {
11858
11891
  const lower = raw.trim().toLowerCase().replace(/\+/g, "-");
11859
11892
  return ALIASES[lower] ?? lower;
@@ -11868,6 +11901,9 @@ function keyBytes(raw, context) {
11868
11901
  if (cursor !== void 0) {
11869
11902
  return `${context.applicationCursorKeys ? "\x1BO" : "\x1B["}${cursor}`;
11870
11903
  }
11904
+ if (name === "wheel-up" || name === "wheel-down") {
11905
+ return wheelBytes(name === "wheel-up", context);
11906
+ }
11871
11907
  return comboBytes(name);
11872
11908
  }
11873
11909
  function comboBytes(name) {
@@ -12255,16 +12291,108 @@ function oscWithoutQueries(payload) {
12255
12291
 
12256
12292
  // src/core/term/screen.ts
12257
12293
  function screenLines(buffer, rows, range) {
12294
+ return styledScreen(buffer, rows, range, false).lines;
12295
+ }
12296
+ function styledScreen(buffer, rows, range, cursorVisible) {
12258
12297
  const end = buffer.baseY + rows;
12259
12298
  const start = range.scrollback ? 0 : buffer.baseY;
12260
12299
  const lines = [];
12300
+ const runs = [];
12301
+ const styles = [];
12302
+ const styleIndex = /* @__PURE__ */ new Map();
12303
+ const cell = buffer.getNullCell();
12261
12304
  for (let index = start; index < end; index += 1) {
12262
- lines.push(buffer.getLine(index)?.translateToString(true) ?? "");
12263
- }
12264
- while (lines.length > 0 && lines[lines.length - 1] === "") {
12265
- lines.pop();
12305
+ const line = buffer.getLine(index);
12306
+ const text2 = line?.translateToString(true) ?? "";
12307
+ lines.push(text2);
12308
+ const row = [];
12309
+ let offset = 0;
12310
+ for (let column = 0; line && column < line.length && offset < text2.length; column += 1) {
12311
+ line.getCell(column, cell);
12312
+ if (cell.getWidth() === 0) continue;
12313
+ const length = (cell.getChars() || " ").length;
12314
+ const style = cellStyle(cell);
12315
+ if (style) {
12316
+ const key = JSON.stringify(style);
12317
+ let at = styleIndex.get(key);
12318
+ if (at === void 0) {
12319
+ at = styles.length;
12320
+ styles.push(style);
12321
+ styleIndex.set(key, at);
12322
+ }
12323
+ const stop = Math.min(offset + length, text2.length);
12324
+ if (row.length > 0 && row[row.length - 1] === at && row[row.length - 2] === offset) {
12325
+ row[row.length - 2] = stop;
12326
+ } else {
12327
+ row.push(offset, stop, at);
12328
+ }
12329
+ }
12330
+ offset += length;
12331
+ }
12332
+ runs.push(row);
12266
12333
  }
12267
- return range.lines === void 0 ? lines : lines.slice(Math.max(0, lines.length - range.lines));
12334
+ let kept = lines.length;
12335
+ while (kept > 0 && lines[kept - 1] === "") kept -= 1;
12336
+ const from = range.lines === void 0 ? 0 : Math.max(0, kept - range.lines);
12337
+ const cursorRow = buffer.baseY + buffer.cursorY - start - from;
12338
+ return {
12339
+ lines: lines.slice(from, kept),
12340
+ styles,
12341
+ runs: runs.slice(from, kept),
12342
+ ...cursorVisible && cursorRow >= 0 ? { cursor: { row: cursorRow, col: cursorColumn(buffer, cell) } } : {}
12343
+ };
12344
+ }
12345
+ function cursorColumn(buffer, cell) {
12346
+ const line = buffer.getLine(buffer.baseY + buffer.cursorY);
12347
+ let offset = 0;
12348
+ for (let column = 0; line && column < buffer.cursorX && column < line.length; column += 1) {
12349
+ line.getCell(column, cell);
12350
+ if (cell.getWidth() !== 0) offset += (cell.getChars() || " ").length;
12351
+ }
12352
+ return offset + Math.max(0, buffer.cursorX - (line?.length ?? 0));
12353
+ }
12354
+ function cellStyle(cell) {
12355
+ if (cell.isAttributeDefault()) return void 0;
12356
+ const style = {};
12357
+ const fg = cellColor(cell.isFgDefault(), cell.isFgRGB(), cell.getFgColor());
12358
+ const bg = cellColor(cell.isBgDefault(), cell.isBgRGB(), cell.getBgColor());
12359
+ if (fg !== void 0) style.fg = fg;
12360
+ if (bg !== void 0) style.bg = bg;
12361
+ if (cell.isBold()) style.bold = true;
12362
+ if (cell.isDim()) style.dim = true;
12363
+ if (cell.isItalic()) style.italic = true;
12364
+ if (cell.isUnderline()) style.underline = true;
12365
+ if (cell.isInverse()) style.inverse = true;
12366
+ if (cell.isInvisible()) style.invisible = true;
12367
+ if (cell.isStrikethrough()) style.strike = true;
12368
+ return Object.keys(style).length > 0 ? style : void 0;
12369
+ }
12370
+ function cellColor(isDefault, isRgb, value) {
12371
+ if (isDefault) return void 0;
12372
+ return isRgb ? `#${value.toString(16).padStart(6, "0")}` : value;
12373
+ }
12374
+ function trackScreenFlags(terminal) {
12375
+ const flags = { cursorVisible: true, sgrMouse: false };
12376
+ const privateMode = (on) => (params) => {
12377
+ for (const param of params) {
12378
+ if (param === 25) flags.cursorVisible = on;
12379
+ if (param === 1006) flags.sgrMouse = on;
12380
+ }
12381
+ return false;
12382
+ };
12383
+ terminal.parser.registerCsiHandler({ prefix: "?", final: "h" }, privateMode(true));
12384
+ terminal.parser.registerCsiHandler({ prefix: "?", final: "l" }, privateMode(false));
12385
+ const reset = () => {
12386
+ flags.cursorVisible = true;
12387
+ flags.sgrMouse = false;
12388
+ return false;
12389
+ };
12390
+ terminal.parser.registerEscHandler({ final: "c" }, reset);
12391
+ terminal.parser.registerCsiHandler({ intermediates: "!", final: "p" }, () => {
12392
+ flags.cursorVisible = true;
12393
+ return false;
12394
+ });
12395
+ return flags;
12268
12396
  }
12269
12397
  function terminalResetSequence(modes, alternateScreen) {
12270
12398
  let reset = "\x1B[0m";
@@ -12296,16 +12424,18 @@ var FULL_TERMINAL_RESET = terminalResetSequence(
12296
12424
  // src/core/term/session.ts
12297
12425
  var SESSION_ENV = "AINECTO_TERM_SESSION";
12298
12426
  var TermSession = class _TermSession {
12299
- constructor(spec, pty, screen, serializer) {
12427
+ constructor(spec, pty, screen, serializer, flags) {
12300
12428
  this.spec = spec;
12301
12429
  this.pty = pty;
12302
12430
  this.screen = screen;
12303
12431
  this.serializer = serializer;
12432
+ this.flags = flags;
12304
12433
  }
12305
12434
  spec;
12306
12435
  pty;
12307
12436
  screen;
12308
12437
  serializer;
12438
+ flags;
12309
12439
  attached = /* @__PURE__ */ new Map();
12310
12440
  /** watch 중인 쪽 → 다음 «바뀜» 알림을 보낼 차례인가. */
12311
12441
  watchers = /* @__PURE__ */ new Map();
@@ -12339,7 +12469,8 @@ var TermSession = class _TermSession {
12339
12469
  const screen = new import_headless.default.Terminal({ cols: pty.cols, rows: pty.rows, allowProposedApi: true });
12340
12470
  const serializer = new import_addon_serialize.default.SerializeAddon();
12341
12471
  screen.loadAddon(serializer);
12342
- const session = new _TermSession(spec, pty, screen, serializer);
12472
+ const flags = trackScreenFlags(screen);
12473
+ const session = new _TermSession(spec, pty, screen, serializer, flags);
12343
12474
  session.label = spec.label;
12344
12475
  screen.onData((answer) => session.answerQuery(answer));
12345
12476
  pty.onData((data) => session.handleOutput(data));
@@ -12374,7 +12505,8 @@ var TermSession = class _TermSession {
12374
12505
  return {
12375
12506
  altScreen: this.screen.buffer.active.type === "alternate",
12376
12507
  appCursor: this.screen.modes.applicationCursorKeysMode,
12377
- bracketedPaste: this.screen.modes.bracketedPasteMode
12508
+ bracketedPaste: this.screen.modes.bracketedPasteMode,
12509
+ mouse: this.screen.modes.mouseTrackingMode !== "none"
12378
12510
  };
12379
12511
  }
12380
12512
  async send(text2, paste) {
@@ -12383,7 +12515,16 @@ var TermSession = class _TermSession {
12383
12515
  }
12384
12516
  async key(name) {
12385
12517
  await this.settled();
12386
- const bytes = keyBytes(name, { applicationCursorKeys: this.screen.modes.applicationCursorKeysMode });
12518
+ const bytes = keyBytes(name, {
12519
+ applicationCursorKeys: this.screen.modes.applicationCursorKeysMode,
12520
+ wheel: {
12521
+ mouseTracking: this.screen.modes.mouseTrackingMode,
12522
+ sgrMouse: this.flags.sgrMouse,
12523
+ altScreen: this.screen.buffer.active.type === "alternate",
12524
+ cols: this.screen.cols,
12525
+ rows: this.screen.rows
12526
+ }
12527
+ });
12387
12528
  if (bytes === void 0) {
12388
12529
  throw new TermError("TERM_UNKNOWN_KEY", `Unknown key "${name}".`);
12389
12530
  }
@@ -12397,6 +12538,14 @@ var TermSession = class _TermSession {
12397
12538
  await this.settled();
12398
12539
  return screenLines(this.screen.buffer.active, this.screen.rows, range);
12399
12540
  }
12541
+ /** {@link read} 와 같은 줄에 글자 속성·커서까지(원격 웹 화면 — 색·흐림을 칠한다). */
12542
+ async readStyled(range, reader) {
12543
+ if (reader && this.watchers.has(reader)) {
12544
+ this.watchers.set(reader, true);
12545
+ }
12546
+ await this.settled();
12547
+ return styledScreen(this.screen.buffer.active, this.screen.rows, range, this.flags.cursorVisible);
12548
+ }
12400
12549
  /**
12401
12550
  * 붙는다 — ★첫 화면(직렬화)과 그 «뒤» 출력의 경계를 맞춘다: 붙는 순간부터 오는 출력은 모아 두고,
12402
12551
  * 그 앞까지 그린 화면을 직렬화해 보낸 다음 모은 출력을 흘린다(설계 2-3 «화면 세대 번호»와 같은 일).
@@ -12783,7 +12932,12 @@ var TermDaemon = class {
12783
12932
  }
12784
12933
  case "read": {
12785
12934
  const session = this.session(request.name);
12786
- const lines = await session.read({ scrollback: request.scrollback, lines: request.lines }, connection);
12935
+ const range = { scrollback: request.scrollback, lines: request.lines };
12936
+ if (request.styles) {
12937
+ const screen = await session.readStyled(range, connection);
12938
+ return { data: { name: request.name, instance: session.instance, ...screen, modes: await session.modes() } };
12939
+ }
12940
+ const lines = await session.read(range, connection);
12787
12941
  return { data: { name: request.name, instance: session.instance, lines, modes: await session.modes() } };
12788
12942
  }
12789
12943
  case "kill": {
@@ -15680,21 +15834,34 @@ function sessionsKey(sessions) {
15680
15834
 
15681
15835
  // src/core/term/remoteFrame.ts
15682
15836
  import { createHash as createHash7 } from "crypto";
15683
- function screenFrame(lines, maxD) {
15837
+ function screenFrame(lines, maxD, attributes) {
15684
15838
  const sizes = lines.map((line) => Buffer.byteLength(line, "utf8"));
15839
+ const runs = attributes?.runs.length === lines.length ? attributes.runs : void 0;
15840
+ const runSizes = runs ? runs.map((row) => JSON.stringify(row).length + 1) : [];
15685
15841
  let start = 0;
15686
15842
  let bytes = sizes.reduce((sum, size) => sum + size, 0) + Math.max(0, lines.length - 1) * 2;
15687
- while (start < lines.length && base64Length(bytes) > maxD) {
15843
+ const fixed = runs ? 10 + CURSOR_BYTES : 0;
15844
+ let runBytes = runSizes.reduce((sum, size) => sum + size, 0);
15845
+ while (start < lines.length && base64Length(bytes) + fixed + runBytes > maxD) {
15688
15846
  bytes -= (sizes[start] ?? 0) + (start < lines.length - 1 ? 2 : 0);
15847
+ runBytes -= runSizes[start] ?? 0;
15689
15848
  start += 1;
15690
15849
  }
15691
15850
  const text2 = lines.slice(start).join("\r\n");
15851
+ const kept = runs?.slice(start);
15852
+ const cursorRow = attributes?.cursor ? attributes.cursor.row - start : -1;
15853
+ const cursor = attributes?.cursor && cursorRow >= 0 ? { row: cursorRow, col: attributes.cursor.col } : void 0;
15854
+ const hash = createHash7("sha256").update(text2, "utf8");
15855
+ if (kept) hash.update(JSON.stringify([attributes?.styles, kept, cursor ?? null]), "utf8");
15692
15856
  return {
15693
15857
  d: Buffer.from(text2, "utf8").toString("base64"),
15694
- hash: createHash7("sha256").update(text2, "utf8").digest("hex"),
15858
+ ...kept ? { runs: kept } : {},
15859
+ ...cursor ? { cursor } : {},
15860
+ hash: hash.digest("hex"),
15695
15861
  dropped: start
15696
15862
  };
15697
15863
  }
15864
+ var CURSOR_BYTES = Buffer.byteLength(JSON.stringify({ cursor: { row: 2 ** 32 - 1, col: 2 ** 32 - 1 } }), "utf8");
15698
15865
  var GCM_TAG_BYTES = 16;
15699
15866
  var MAX_COUNTER = 2 ** 32 - 1;
15700
15867
  function frameBudget(frameMaxBytes, outer, sealed) {
@@ -15807,7 +15974,7 @@ var RemoteViewer = class {
15807
15974
  }
15808
15975
  let data;
15809
15976
  try {
15810
- data = await client.request({ op: "read", name, scrollback: true, lines: FRAME_SCROLLBACK_LINES + rows });
15977
+ data = await client.request({ op: "read", name, scrollback: true, lines: FRAME_SCROLLBACK_LINES + rows, styles: true });
15811
15978
  } catch (error) {
15812
15979
  this.daemonFailed("read", error);
15813
15980
  return;
@@ -15821,9 +15988,11 @@ var RemoteViewer = class {
15821
15988
  return;
15822
15989
  }
15823
15990
  const modes = readModes(data);
15991
+ const lines = readLines(data);
15992
+ const attributes = readStyles(data, lines.length);
15824
15993
  const outer = { linkId: target.linkId, channelId: this.deps.channelId, session: name, cols, rows };
15825
- const sealed = { ...modes ? { modes } : {}, instance };
15826
- const frame = screenFrame(readLines(data), frameBudget(target.frameMaxBytes, outer, sealed));
15994
+ const sealed = { ...modes ? { modes } : {}, ...attributes ? { styles: attributes.styles } : {}, instance };
15995
+ const frame = screenFrame(lines, frameBudget(target.frameMaxBytes, outer, sealed), attributes);
15827
15996
  if (frame.dropped !== dropped) {
15828
15997
  dropped = frame.dropped;
15829
15998
  this.deps.log.write({ event: "remote_frame_trimmed", channelId: this.deps.channelId, session: name, dropped });
@@ -15832,7 +16001,13 @@ var RemoteViewer = class {
15832
16001
  if (key === sentKey) continue;
15833
16002
  let box;
15834
16003
  try {
15835
- box = await this.deps.seal({ d: frame.d, ...sealed, executedThrough });
16004
+ box = await this.deps.seal({
16005
+ d: frame.d,
16006
+ ...sealed,
16007
+ ...frame.runs ? { runs: frame.runs } : {},
16008
+ ...frame.cursor ? { cursor: frame.cursor } : {},
16009
+ executedThrough
16010
+ });
15836
16011
  } catch (error) {
15837
16012
  this.stop();
15838
16013
  this.deps.onChannelEnded(error instanceof ChannelSealError ? error.reason : "CHANNEL_GONE");