@kosuke-ai/kosuke 1.0.131 → 1.0.133

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.133
4
+
5
+ - When stdout is a pipe, a short list's footer (`20 of 3122. More: --cursor <c>`) goes inside the JSON as `meta.hint`, notices as `meta.notices`, and `integrations call` and `integrations request` name the connection they ran on as `meta.ranOn` in a JSON object result, so `kosuke ... 2>&1 | jq` reads one JSON value. A terminal still shows these lines on stderr, and errors still go to stderr with a non-zero exit. A flag given to the wrong form of a command now names the form that takes it and the closest flag of this form.
6
+
7
+ ## 1.0.132
8
+
9
+ - Add `kosuke sensei threads search`, which finds the messages of one of your Sensei Threads that hold some words, newest first, each with a snippet. `kosuke sensei threads get --around <messageId>` reads the replies around one, such as a search hit. `kosuke user profile get` now includes your Thread routing setting (`threadRouting`: off, ask or automatic).
10
+
3
11
  ## 1.0.131
4
12
 
5
13
  - `integrations list`, `integrations tools get`, `integrations call` and integration file uploads and requests take `--workspace personal` for your own Personal space, as `integrations connections list personal` already did: with an API key or from Sensei it reads your Personal space instead of being refused. Canva is a new personal integration.
package/README.md CHANGED
@@ -23,7 +23,9 @@ for its whole answer by name: pass it in anything that pipes into `jq`.
23
23
  The lists are short by default: `projects list`, `sessions list`, `tasks list`, `crons list`,
24
24
  `activity list`, `sensei threads list`, `sensei cards list` and `files list` print at most 20
25
25
  rows, each with the fields you pick a row by and no null ones, and end with a line on stderr
26
- such as `20 of 3122. More: --cursor <c>`. `--all` reads every page, `--full` keeps every field,
26
+ such as `20 of 3122. More: --cursor <c>`. When stdout is a pipe that line goes in the JSON
27
+ instead, as `meta.hint`, with any notice in `meta.notices`, so `2>&1 | jq` still reads one value;
28
+ stderr then holds only errors. `--all` reads every page, `--full` keeps every field,
27
29
  `--fields` picks from whole rows, and `get` prints one whole. `--json` prints and sends exactly what it did before.
28
30
 
29
31
  Path params are positional, request fields are flags (`--exclude-archived`,
@@ -228,8 +230,10 @@ account, short id) and how many read-only and write tools it has. `--toolkit` an
228
230
  and how to narrow it. `--account` takes a connection's alias such as
229
231
  `notion-personal`, its short id or `scope:label`; case, curly quotes and extra
230
232
  spaces do not matter, and it is needed when several connections can run a tool.
231
- `call` prints the tool's text on stdout and the connection it ran on on stderr,
232
- and exits 1 when the tool reports an error. A tool's file argument takes a file
233
+ `call` prints the tool's text on stdout and the connection it ran on on stderr;
234
+ when stdout is a pipe, a JSON object result carries the connection as `meta.ranOn`
235
+ instead (`alias`, `scope`, `label`, `account`), and nothing else goes on stderr. It
236
+ exits 1 when the tool reports an error. A tool's file argument takes a file
233
237
  reference: `--file <argument>=<path>` uploads the local file and fills it in,
234
238
  once per file, and a file inside a list or object names its path, such as
235
239
  `attachment.0`. The file goes straight to storage, up to 5 GiB.
@@ -45,7 +45,8 @@ export function attachIntegrationsRequest(root, runtime, { guarded, fail, report
45
45
  leafAt(root, HAND_WRITTEN.integrationsRequest.command)
46
46
  .description("Send one request straight to a Composio toolkit's own API through your connection, for an " +
47
47
  'action no listed tool does, and print its answer. Composio adds the credentials on the ' +
48
- 'server, so no token is needed or shown. The connection it ran on is named on stderr. ' +
48
+ 'server, so no token is needed or shown. The connection it ran on is named on stderr at a ' +
49
+ 'terminal; piped, a JSON object answer carries it as meta.ranOn. ' +
49
50
  'A refusal or a vendor error exits 1.')
50
51
  .argument('<toolkit>', 'The toolkit, as `list` prints it, such as googlecalendar.', toolkitSlug)
51
52
  // Required, but checked in the action: commander's own refusal exits 1, not the usage exit 2.
@@ -9,6 +9,7 @@ import { jsonRequested } from '../runtime/runtime.js';
9
9
  import { connectionOf, failureOf, isRow, oneLine, readOverview, rowsOf, TOOLS_PATH, transportFailure, } from '../integrations/api.js';
10
10
  import { FILE_UPLOAD_PATH, fileSize, MAX_FILE_BYTES, md5Of, mimetypeOf, parseFileArgument, putFile, setAt, uploadName, } from '../integrations/file-upload.js';
11
11
  import { choiceLines, renderOverview } from '../integrations/render.js';
12
+ import { withRanOn } from '../integrations/ran-on.js';
12
13
  /**
13
14
  * `kosuke integrations list|call|request` and `kosuke integrations tools get`: the connected tools,
14
15
  * listed and run from a laptop or an agent's shell. Hand-written because the output is text
@@ -124,6 +125,21 @@ function failureText(text, choices, tool, given) {
124
125
  }
125
126
  return body.message;
126
127
  }
128
+ function ranOnLine(connection) {
129
+ const identity = connection.accountIdentity ?? 'account unknown';
130
+ return `Ran on ${connection.alias} (${connection.scope}, "${connection.label}", ${identity}).\n`;
131
+ }
132
+ function isJson(text) {
133
+ if (text.trim() === '')
134
+ return false;
135
+ try {
136
+ JSON.parse(text);
137
+ return true;
138
+ }
139
+ catch {
140
+ return false;
141
+ }
142
+ }
127
143
  /** The reserved upload a successful file-upload answer carries in its text. */
128
144
  function uploadOf(answer) {
129
145
  const block = rowsOf(answer.content)[0];
@@ -153,7 +169,7 @@ function uploadOf(answer) {
153
169
  export function attachIntegrationsCommands(root, runtime, deps = {}) {
154
170
  const { stdout = (text) => process.stdout.write(text), stderr = (text) => process.stderr.write(text), exit = (code) => {
155
171
  process.exitCode = code;
156
- }, readStdin = readAllStdin, stdinHasInput = realStdinHasInput, readFile: readText = (path) => readFile(path, 'utf8'), readTimeoutMs = READ_TIMEOUT_MS, callTimeoutMs = CALL_TIMEOUT_MS, uploadFetch = (input, init) => globalThis.fetch(input, init), env = process.env, } = deps;
172
+ }, readStdin = readAllStdin, stdinHasInput = realStdinHasInput, readFile: readText = (path) => readFile(path, 'utf8'), readTimeoutMs = READ_TIMEOUT_MS, callTimeoutMs = CALL_TIMEOUT_MS, uploadFetch = (input, init) => globalThis.fetch(input, init), env = process.env, stdoutIsTTY = process.stdout.isTTY === true, } = deps;
157
173
  const fail = (failure, code = EXIT_FAILED) => {
158
174
  stderr(`${typeof failure === 'string' ? failure : failure.message}\n`);
159
175
  exit(code);
@@ -197,8 +213,8 @@ export function attachIntegrationsCommands(root, runtime, deps = {}) {
197
213
  // The program's own --json takes the flag wherever it is written, so it is read from there.
198
214
  if (jsonRequested(command.optsWithGlobals().json, env)) {
199
215
  stdout(`${JSON.stringify(result.raw, null, 2)}\n`);
200
- // stdout stays parseable, so the cut is told beside it.
201
- if (result.overview.note)
216
+ // The answer's own `note` says it too; a pipe gets nothing beside the JSON.
217
+ if (result.overview.note && stdoutIsTTY)
202
218
  stderr(`${result.overview.note}\n`);
203
219
  return;
204
220
  }
@@ -250,7 +266,8 @@ export function attachIntegrationsCommands(root, runtime, deps = {}) {
250
266
  }));
251
267
  leafAt(root, HAND_WRITTEN.integrationsCall.command)
252
268
  .description('Run a tool with a JSON object of arguments and print its text result. The connection it ' +
253
- 'ran on is named on stderr. A tool that reports an error exits 1.')
269
+ 'ran on is named on stderr at a terminal; piped, a JSON object result carries it as meta.ranOn. ' +
270
+ 'A tool that reports an error exits 1.')
254
271
  .argument('<name>', 'The tool, as `list` prints it.')
255
272
  .argument('[stdin]', 'A lone - reads the JSON arguments from stdin.')
256
273
  .option('--account <account>', 'The connection to run on: an alias, id or scope:label. Needed when several can run the tool.', accountText)
@@ -414,7 +431,10 @@ export function attachIntegrationsCommands(root, runtime, deps = {}) {
414
431
  throw new UsageError('The arguments must be a JSON object.');
415
432
  return parsed;
416
433
  }
417
- /** The tool's text on stdout; which connection ran it, and any failure, on stderr. */
434
+ /**
435
+ * The tool's text on stdout; any failure on stderr. Which connection ran it goes on stderr at a
436
+ * terminal; when stdout is a pipe, a JSON object answer carries it as `meta.ranOn` instead.
437
+ */
418
438
  function report(name, account, data) {
419
439
  const answer = isRow(data) ? data : {};
420
440
  const content = rowsOf(answer.content);
@@ -426,10 +446,21 @@ export function attachIntegrationsCommands(root, runtime, deps = {}) {
426
446
  .join('\n');
427
447
  const connection = isRow(answer.connection) ? connectionOf(answer.connection) : null;
428
448
  // The alias may name a different connection tomorrow, so every call says which one it ran on.
429
- if (connection) {
430
- const identity = connection.accountIdentity ?? 'account unknown';
431
- stderr(`Ran on ${connection.alias} (${connection.scope}, "${connection.label}", ${identity}).\n`);
449
+ const ranOn = connection ? ranOnLine(connection) : null;
450
+ if (answer.isError !== true && connection && !stdoutIsTTY) {
451
+ const json = withRanOn(text, connection);
452
+ if (json !== null) {
453
+ stdout(`${json}\n`);
454
+ return;
455
+ }
456
+ // Any other JSON keeps stdout one value; plain text is no JSON, so the line stays beside it.
457
+ if (isJson(text)) {
458
+ stdout(text.endsWith('\n') || text === '' ? text : `${text}\n`);
459
+ return;
460
+ }
432
461
  }
462
+ if (ranOn)
463
+ stderr(ranOn);
433
464
  if (answer.isError === true) {
434
465
  const choices = rowsOf(answer.choices).flatMap((row) => connectionOf(row) ?? []);
435
466
  const message = failureText(text, choices, oneLine(name, 80), account);
@@ -239,116 +239,117 @@ import { operation as o237 } from './sensei/threads-list.js';
239
239
  import { operation as o238 } from './sensei/threads-move.js';
240
240
  import { operation as o239 } from './sensei/threads-notes-get.js';
241
241
  import { operation as o240 } from './sensei/threads-notes-send.js';
242
- import { operation as o241 } from './sensei/threads-split.js';
243
- import { operation as o242 } from './sensei/tickets-merge.js';
244
- import { operation as o243 } from './sensei/watch-reads-finish.js';
245
- import { operation as o244 } from './sensei/widgets-get.js';
246
- import { operation as o245 } from './sensei/writing-get.js';
247
- import { operation as o246 } from './sensei/writing-set.js';
248
- import { operation as o247 } from './sensei/writing-samples-create.js';
249
- import { operation as o248 } from './sessions/app-stack-start.js';
250
- import { operation as o249 } from './sessions/create.js';
251
- import { operation as o250 } from './sessions/delete.js';
252
- import { operation as o251 } from './sessions/desktop-control-set.js';
253
- import { operation as o252 } from './sessions/desktop-get.js';
254
- import { operation as o253 } from './sessions/desktop-start.js';
255
- import { operation as o254 } from './sessions/diff-comments-create.js';
256
- import { operation as o255 } from './sessions/diff-comments-delete.js';
257
- import { operation as o256 } from './sessions/diff-comments-list.js';
258
- import { operation as o257 } from './sessions/diff-comments-update.js';
259
- import { operation as o258 } from './sessions/diff-commits-list.js';
260
- import { operation as o259 } from './sessions/diff-files-list.js';
261
- import { operation as o260 } from './sessions/diff-patch-get.js';
262
- import { operation as o261 } from './sessions/env-sync.js';
263
- import { operation as o262 } from './sessions/files-attach.js';
264
- import { operation as o263 } from './sessions/files-get.js';
265
- import { operation as o264 } from './sessions/files-list.js';
266
- import { operation as o265 } from './sessions/get.js';
267
- import { operation as o266 } from './sessions/git-state-get.js';
268
- import { operation as o267 } from './sessions/go-ahead-delete.js';
269
- import { operation as o268 } from './sessions/go-ahead-set.js';
270
- import { operation as o269 } from './sessions/jobs-cancel.js';
271
- import { operation as o270 } from './sessions/jobs-get.js';
272
- import { operation as o271 } from './sessions/jobs-list.js';
273
- import { operation as o272 } from './sessions/labels-set.js';
274
- import { operation as o273 } from './sessions/labels-update.js';
275
- import { operation as o274 } from './sessions/list.js';
276
- import { operation as o275 } from './sessions/list--all.js';
277
- import { operation as o276 } from './sessions/mark-read.js';
278
- import { operation as o277 } from './sessions/messages-get.js';
279
- import { operation as o278 } from './sessions/messages-list.js';
280
- import { operation as o279 } from './sessions/prompt-update.js';
281
- import { operation as o280 } from './sessions/qa-runs-finish.js';
282
- import { operation as o281 } from './sessions/qa-runs-fixes-create.js';
283
- import { operation as o282 } from './sessions/qa-runs-get.js';
284
- import { operation as o283 } from './sessions/qa-runs-results-create.js';
285
- import { operation as o284 } from './sessions/qa-runs-start.js';
286
- import { operation as o285 } from './sessions/qa-runs-stop.js';
287
- import { operation as o286 } from './sessions/qa-set.js';
288
- import { operation as o287 } from './sessions/queue-delete.js';
289
- import { operation as o288 } from './sessions/queue-list.js';
290
- import { operation as o289 } from './sessions/queue-move.js';
291
- import { operation as o290 } from './sessions/queue-resume.js';
292
- import { operation as o291 } from './sessions/queue-send.js';
293
- import { operation as o292 } from './sessions/queue-steer.js';
294
- import { operation as o293 } from './sessions/queue-update.js';
295
- import { operation as o294 } from './sessions/review-set.js';
296
- import { operation as o295 } from './sessions/runtime-commands-run.js';
297
- import { operation as o296 } from './sessions/sandbox-files-get.js';
298
- import { operation as o297 } from './sessions/sandbox-files-list.js';
299
- import { operation as o298 } from './sessions/sandbox-files-set.js';
300
- import { operation as o299 } from './sessions/search.js';
301
- import { operation as o300 } from './sessions/send.js';
302
- import { operation as o301 } from './sessions/start.js';
303
- import { operation as o302 } from './sessions/steer.js';
304
- import { operation as o303 } from './sessions/update.js';
305
- import { operation as o304 } from './skills/create.js';
306
- import { operation as o305 } from './skills/create--personal.js';
307
- import { operation as o306 } from './skills/delete.js';
308
- import { operation as o307 } from './skills/delete--personal.js';
309
- import { operation as o308 } from './skills/get.js';
310
- import { operation as o309 } from './skills/get--personal.js';
311
- import { operation as o310 } from './skills/list.js';
312
- import { operation as o311 } from './skills/list--personal.js';
313
- import { operation as o312 } from './skills/update.js';
314
- import { operation as o313 } from './skills/update--personal.js';
315
- import { operation as o314 } from './tasks/create.js';
316
- import { operation as o315 } from './tasks/create--personal.js';
317
- import { operation as o316 } from './tasks/delete.js';
318
- import { operation as o317 } from './tasks/delete--personal.js';
319
- import { operation as o318 } from './tasks/get.js';
320
- import { operation as o319 } from './tasks/get--personal.js';
321
- import { operation as o320 } from './tasks/labels-list.js';
322
- import { operation as o321 } from './tasks/list.js';
323
- import { operation as o322 } from './tasks/list--all.js';
324
- import { operation as o323 } from './tasks/list--personal.js';
325
- import { operation as o324 } from './tasks/move.js';
326
- import { operation as o325 } from './tasks/move--personal.js';
327
- import { operation as o326 } from './tasks/project-set.js';
328
- import { operation as o327 } from './tasks/start.js';
329
- import { operation as o328 } from './tasks/start--personal.js';
330
- import { operation as o329 } from './tasks/update.js';
331
- import { operation as o330 } from './tasks/update--personal.js';
332
- import { operation as o331 } from './user/api-keys-delete.js';
333
- import { operation as o332 } from './user/personal-space-get.js';
334
- import { operation as o333 } from './user/profile-get.js';
335
- import { operation as o334 } from './user/push-devices-create.js';
336
- import { operation as o335 } from './user/push-devices-delete.js';
337
- import { operation as o336 } from './user/settings-get.js';
338
- import { operation as o337 } from './user/settings-update.js';
339
- import { operation as o338 } from './user/usage-get.js';
340
- import { operation as o339 } from './workspaces/credits-get.js';
341
- import { operation as o340 } from './workspaces/get.js';
342
- import { operation as o341 } from './workspaces/list.js';
343
- import { operation as o342 } from './workspaces/members-list.js';
344
- import { operation as o343 } from './workspaces/members-list--all.js';
345
- import { operation as o344 } from './workspaces/personal-runtime-get.js';
346
- import { operation as o345 } from './workspaces/sandbox-hours-get.js';
347
- import { operation as o346 } from './workspaces/sandbox-limit-get.js';
348
- import { operation as o347 } from './workspaces/sandboxes-stop.js';
349
- import { operation as o348 } from './workspaces/timezone-set.js';
350
- import { operation as o349 } from './workspaces/usage-breakdown-get.js';
351
- import { operation as o350 } from './workspaces/usage-get.js';
242
+ import { operation as o241 } from './sensei/threads-search.js';
243
+ import { operation as o242 } from './sensei/threads-split.js';
244
+ import { operation as o243 } from './sensei/tickets-merge.js';
245
+ import { operation as o244 } from './sensei/watch-reads-finish.js';
246
+ import { operation as o245 } from './sensei/widgets-get.js';
247
+ import { operation as o246 } from './sensei/writing-get.js';
248
+ import { operation as o247 } from './sensei/writing-set.js';
249
+ import { operation as o248 } from './sensei/writing-samples-create.js';
250
+ import { operation as o249 } from './sessions/app-stack-start.js';
251
+ import { operation as o250 } from './sessions/create.js';
252
+ import { operation as o251 } from './sessions/delete.js';
253
+ import { operation as o252 } from './sessions/desktop-control-set.js';
254
+ import { operation as o253 } from './sessions/desktop-get.js';
255
+ import { operation as o254 } from './sessions/desktop-start.js';
256
+ import { operation as o255 } from './sessions/diff-comments-create.js';
257
+ import { operation as o256 } from './sessions/diff-comments-delete.js';
258
+ import { operation as o257 } from './sessions/diff-comments-list.js';
259
+ import { operation as o258 } from './sessions/diff-comments-update.js';
260
+ import { operation as o259 } from './sessions/diff-commits-list.js';
261
+ import { operation as o260 } from './sessions/diff-files-list.js';
262
+ import { operation as o261 } from './sessions/diff-patch-get.js';
263
+ import { operation as o262 } from './sessions/env-sync.js';
264
+ import { operation as o263 } from './sessions/files-attach.js';
265
+ import { operation as o264 } from './sessions/files-get.js';
266
+ import { operation as o265 } from './sessions/files-list.js';
267
+ import { operation as o266 } from './sessions/get.js';
268
+ import { operation as o267 } from './sessions/git-state-get.js';
269
+ import { operation as o268 } from './sessions/go-ahead-delete.js';
270
+ import { operation as o269 } from './sessions/go-ahead-set.js';
271
+ import { operation as o270 } from './sessions/jobs-cancel.js';
272
+ import { operation as o271 } from './sessions/jobs-get.js';
273
+ import { operation as o272 } from './sessions/jobs-list.js';
274
+ import { operation as o273 } from './sessions/labels-set.js';
275
+ import { operation as o274 } from './sessions/labels-update.js';
276
+ import { operation as o275 } from './sessions/list.js';
277
+ import { operation as o276 } from './sessions/list--all.js';
278
+ import { operation as o277 } from './sessions/mark-read.js';
279
+ import { operation as o278 } from './sessions/messages-get.js';
280
+ import { operation as o279 } from './sessions/messages-list.js';
281
+ import { operation as o280 } from './sessions/prompt-update.js';
282
+ import { operation as o281 } from './sessions/qa-runs-finish.js';
283
+ import { operation as o282 } from './sessions/qa-runs-fixes-create.js';
284
+ import { operation as o283 } from './sessions/qa-runs-get.js';
285
+ import { operation as o284 } from './sessions/qa-runs-results-create.js';
286
+ import { operation as o285 } from './sessions/qa-runs-start.js';
287
+ import { operation as o286 } from './sessions/qa-runs-stop.js';
288
+ import { operation as o287 } from './sessions/qa-set.js';
289
+ import { operation as o288 } from './sessions/queue-delete.js';
290
+ import { operation as o289 } from './sessions/queue-list.js';
291
+ import { operation as o290 } from './sessions/queue-move.js';
292
+ import { operation as o291 } from './sessions/queue-resume.js';
293
+ import { operation as o292 } from './sessions/queue-send.js';
294
+ import { operation as o293 } from './sessions/queue-steer.js';
295
+ import { operation as o294 } from './sessions/queue-update.js';
296
+ import { operation as o295 } from './sessions/review-set.js';
297
+ import { operation as o296 } from './sessions/runtime-commands-run.js';
298
+ import { operation as o297 } from './sessions/sandbox-files-get.js';
299
+ import { operation as o298 } from './sessions/sandbox-files-list.js';
300
+ import { operation as o299 } from './sessions/sandbox-files-set.js';
301
+ import { operation as o300 } from './sessions/search.js';
302
+ import { operation as o301 } from './sessions/send.js';
303
+ import { operation as o302 } from './sessions/start.js';
304
+ import { operation as o303 } from './sessions/steer.js';
305
+ import { operation as o304 } from './sessions/update.js';
306
+ import { operation as o305 } from './skills/create.js';
307
+ import { operation as o306 } from './skills/create--personal.js';
308
+ import { operation as o307 } from './skills/delete.js';
309
+ import { operation as o308 } from './skills/delete--personal.js';
310
+ import { operation as o309 } from './skills/get.js';
311
+ import { operation as o310 } from './skills/get--personal.js';
312
+ import { operation as o311 } from './skills/list.js';
313
+ import { operation as o312 } from './skills/list--personal.js';
314
+ import { operation as o313 } from './skills/update.js';
315
+ import { operation as o314 } from './skills/update--personal.js';
316
+ import { operation as o315 } from './tasks/create.js';
317
+ import { operation as o316 } from './tasks/create--personal.js';
318
+ import { operation as o317 } from './tasks/delete.js';
319
+ import { operation as o318 } from './tasks/delete--personal.js';
320
+ import { operation as o319 } from './tasks/get.js';
321
+ import { operation as o320 } from './tasks/get--personal.js';
322
+ import { operation as o321 } from './tasks/labels-list.js';
323
+ import { operation as o322 } from './tasks/list.js';
324
+ import { operation as o323 } from './tasks/list--all.js';
325
+ import { operation as o324 } from './tasks/list--personal.js';
326
+ import { operation as o325 } from './tasks/move.js';
327
+ import { operation as o326 } from './tasks/move--personal.js';
328
+ import { operation as o327 } from './tasks/project-set.js';
329
+ import { operation as o328 } from './tasks/start.js';
330
+ import { operation as o329 } from './tasks/start--personal.js';
331
+ import { operation as o330 } from './tasks/update.js';
332
+ import { operation as o331 } from './tasks/update--personal.js';
333
+ import { operation as o332 } from './user/api-keys-delete.js';
334
+ import { operation as o333 } from './user/personal-space-get.js';
335
+ import { operation as o334 } from './user/profile-get.js';
336
+ import { operation as o335 } from './user/push-devices-create.js';
337
+ import { operation as o336 } from './user/push-devices-delete.js';
338
+ import { operation as o337 } from './user/settings-get.js';
339
+ import { operation as o338 } from './user/settings-update.js';
340
+ import { operation as o339 } from './user/usage-get.js';
341
+ import { operation as o340 } from './workspaces/credits-get.js';
342
+ import { operation as o341 } from './workspaces/get.js';
343
+ import { operation as o342 } from './workspaces/list.js';
344
+ import { operation as o343 } from './workspaces/members-list.js';
345
+ import { operation as o344 } from './workspaces/members-list--all.js';
346
+ import { operation as o345 } from './workspaces/personal-runtime-get.js';
347
+ import { operation as o346 } from './workspaces/sandbox-hours-get.js';
348
+ import { operation as o347 } from './workspaces/sandbox-limit-get.js';
349
+ import { operation as o348 } from './workspaces/sandboxes-stop.js';
350
+ import { operation as o349 } from './workspaces/timezone-set.js';
351
+ import { operation as o350 } from './workspaces/usage-breakdown-get.js';
352
+ import { operation as o351 } from './workspaces/usage-get.js';
352
353
  export const operations = [
353
354
  o0,
354
355
  o1,
@@ -701,4 +702,5 @@ export const operations = [
701
702
  o348,
702
703
  o349,
703
704
  o350,
705
+ o351,
704
706
  ];
@@ -6,7 +6,7 @@ export const operation = {
6
6
  "threads",
7
7
  "get"
8
8
  ],
9
- "summary": "Read one of your Sensei Threads: its name, state, sessions and root, its replies oldest first, the Turn that runs or last ran in it, and its Up next. Paged: `limit` replies at a time, `before` for the ones older than a reply already read, and `since` for the ones newer than it. `session` keeps the rows about one Chat Session.",
9
+ "summary": "Read one of your Sensei Threads: its name, state, sessions and root, its replies oldest first, the Turn that runs or last ran in it, and its Up next. Paged: `limit` replies at a time, `before` for the ones older than a reply already read, `since` for the ones newer than it, and `around` for the ones around one message, such as a search hit. `session` keeps the rows about one Chat Session.",
10
10
  "pathParams": [
11
11
  "threadId"
12
12
  ],
@@ -32,6 +32,13 @@ export const operation = {
32
32
  "required": false,
33
33
  "description": "The id of the newest reply already read: answers only the replies after it, oldest first, alone."
34
34
  },
35
+ {
36
+ "name": "around",
37
+ "flag": "around",
38
+ "kind": "string",
39
+ "required": false,
40
+ "description": "The id of a message of the thread, such as a search hit: answers the replies around it, up to half of `limit` before it, then it and the ones after it, alone."
41
+ },
35
42
  {
36
43
  "name": "session",
37
44
  "flag": "session",
@@ -0,0 +1,27 @@
1
+ export const operation = {
2
+ "method": "get",
3
+ "path": "/api/sensei/threads/{threadId}/search",
4
+ "command": [
5
+ "sensei",
6
+ "threads",
7
+ "search"
8
+ ],
9
+ "summary": "Search one of your Sensei Threads for messages, yours and Sensei's, that hold some words. Newest first, at most 50, each with its id, who wrote it, when, and a short snippet around the first match. `around` on the thread's read opens one in its place.",
10
+ "pathParams": [
11
+ "threadId"
12
+ ],
13
+ "query": [
14
+ {
15
+ "name": "q",
16
+ "flag": "q",
17
+ "kind": "string",
18
+ "required": true,
19
+ "description": "The words to find, 2 to 200 characters, as written: case is ignored and %, _ and \\ match themselves."
20
+ }
21
+ ],
22
+ "body": null,
23
+ "multipart": null,
24
+ "attachments": false,
25
+ "anonymous": false,
26
+ "agents": "all"
27
+ };
@@ -0,0 +1,92 @@
1
+ import { isRow } from './api.js';
2
+ /**
3
+ * `meta.ranOn` in a tool's JSON object answer, written into the text itself: a vendor's numbers
4
+ * are never parsed and printed again, so an id past 2^53 keeps every digit.
5
+ */
6
+ /**
7
+ * The tool's JSON object text with `meta.ranOn` naming the connection, or null when the text is
8
+ * no JSON object, its `meta` is no object, or its `meta` already has a `ranOn` of the vendor's.
9
+ */
10
+ export function withRanOn(text, connection) {
11
+ let body;
12
+ try {
13
+ body = JSON.parse(text);
14
+ }
15
+ catch {
16
+ return null;
17
+ }
18
+ if (!isRow(body))
19
+ return null;
20
+ const ranOn = JSON.stringify({
21
+ alias: connection.alias,
22
+ scope: connection.scope,
23
+ label: connection.label,
24
+ account: connection.accountIdentity,
25
+ });
26
+ if (!Object.hasOwn(body, 'meta'))
27
+ return insertBeforeClose(text, text.trimEnd().length - 1, `"meta":{"ranOn":${ranOn}}`);
28
+ if (!isRow(body.meta) || Object.hasOwn(body.meta, 'ranOn'))
29
+ return null;
30
+ const close = metaClose(text);
31
+ return close === null ? null : insertBeforeClose(text, close, `"ranOn":${ranOn}`);
32
+ }
33
+ /** `member` added as the last member of the object whose `}` is at `close`. */
34
+ function insertBeforeClose(text, close, member) {
35
+ const head = text.slice(0, close).trimEnd();
36
+ return `${head}${head.endsWith('{') ? '' : ','}${member}${text.slice(close).trimEnd()}`;
37
+ }
38
+ /**
39
+ * Where the top-level `meta` object closes, read as JSON.parse reads it (the last `meta` wins),
40
+ * or null when it is not found. The text is valid JSON: JSON.parse read it first.
41
+ */
42
+ function metaClose(text) {
43
+ let depth = 0;
44
+ let expectKey = false;
45
+ let metaNext = false;
46
+ let metaDepthOpen = false;
47
+ let found = null;
48
+ for (let at = 0; at < text.length; at++) {
49
+ const char = text[at];
50
+ if (char === '"') {
51
+ const end = stringEnd(text, at);
52
+ if (depth === 1 && expectKey) {
53
+ metaNext = JSON.parse(text.slice(at, end + 1)) === 'meta';
54
+ expectKey = false;
55
+ }
56
+ at = end;
57
+ continue;
58
+ }
59
+ if (char === '{' || char === '[') {
60
+ depth += 1;
61
+ if (depth === 1)
62
+ expectKey = true;
63
+ if (depth === 2 && metaNext && char === '{')
64
+ metaDepthOpen = true;
65
+ metaNext = false;
66
+ continue;
67
+ }
68
+ if (char === '}' || char === ']') {
69
+ if (depth === 2 && metaDepthOpen) {
70
+ found = at;
71
+ metaDepthOpen = false;
72
+ }
73
+ depth -= 1;
74
+ continue;
75
+ }
76
+ if (char === ',' && depth === 1) {
77
+ expectKey = true;
78
+ metaNext = false;
79
+ }
80
+ }
81
+ return found;
82
+ }
83
+ /** The index of the quote that closes the string opened at `start`. */
84
+ function stringEnd(text, start) {
85
+ for (let at = start + 1; at < text.length; at++) {
86
+ if (text[at] === '\\')
87
+ at += 1;
88
+ else if (text[at] === '"')
89
+ return at;
90
+ }
91
+ return text.length - 1;
92
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The short default of the list commands: at most `DEFAULT_LIST_LIMIT` rows, each cut to the
3
- * fields a reader picks a row by (a null one left out), and a footer on stderr with the total
4
- * and the next page.
3
+ * fields a reader picks a row by (a null one left out), and a footer with the total and the next
4
+ * page: on stderr at a terminal, in the answer's `meta.hint` when stdout is a pipe.
5
5
  * `--all` keeps every row the platform answers, `--full` every field; `--json` (or
6
6
  * `KOSUKE_OUTPUT=json`) prints the platform's whole answer, as before, and sends what it sent.
7
7
  *
@@ -13,6 +13,36 @@ export function createRuntime({ flags, env = process.env, fetch, stdout = (line)
13
13
  }, tty = { stdout: process.stdout.isTTY === true, stderr: process.stderr.isTTY === true }, }) {
14
14
  let resolved = null;
15
15
  const credentials = () => (resolved ??= resolveCredentials(flags, env));
16
+ // Notices held for the answer while stdout is a pipe: an agent that merges stderr into the
17
+ // stream it parses must still read one JSON value.
18
+ const held = [];
19
+ const flushHeld = () => {
20
+ for (const line of held.splice(0))
21
+ stderr(line);
22
+ };
23
+ /** The JSON to print with the footer and held notices in its `meta`, or null when it has none. */
24
+ const withHints = (json, footer) => {
25
+ if (tty.stdout)
26
+ return json;
27
+ const hints = {
28
+ ...(footer ? { hint: footer } : {}),
29
+ ...(held.length ? { notices: held.splice(0) } : {}),
30
+ };
31
+ if (!Object.keys(hints).length)
32
+ return json;
33
+ const placed = metaWith(json, hints);
34
+ // No object to hold them: a footer is left out, so stdout stays one JSON value.
35
+ if (placed === null) {
36
+ for (const line of hints.notices ?? [])
37
+ stderr(line);
38
+ return json;
39
+ }
40
+ return placed;
41
+ };
42
+ const printFooter = (footer) => {
43
+ if (footer)
44
+ stderr(footer);
45
+ };
16
46
  return {
17
47
  credentials,
18
48
  client({ anonymous = false, answerTimeoutMs } = {}) {
@@ -31,7 +61,10 @@ export function createRuntime({ flags, env = process.env, fetch, stdout = (line)
31
61
  });
32
62
  },
33
63
  notice(line) {
34
- stderr(line);
64
+ if (tty.stdout)
65
+ stderr(line);
66
+ else
67
+ held.push(line);
35
68
  },
36
69
  // `--format json` names JSON as `--json` does: the platform's whole answer.
37
70
  wholeAnswer: () => jsonRequested(flags.json, env) || flags.format === 'json',
@@ -40,17 +73,25 @@ export function createRuntime({ flags, env = process.env, fetch, stdout = (line)
40
73
  // 204 has nothing to print; anything else is passed through as JSON so
41
74
  // `| jq` works without the platform CLI knowing the shape.
42
75
  if (outcome.body === undefined)
43
- return;
76
+ return flushHeld();
44
77
  const shaping = flags.fields?.length || flags.format === 'compact';
45
78
  if (!shaping || typeof outcome.body === 'string') {
46
79
  if (shaping) {
80
+ flushHeld();
47
81
  stderr('error: this command printed text, not JSON; --fields and --format need JSON.');
48
82
  exit(1);
49
83
  return;
50
84
  }
51
- stdout(render(outcome.body, flags.pretty || tty.stdout));
52
- if (context?.footer)
53
- stderr(context.footer);
85
+ if (typeof outcome.body === 'string') {
86
+ // Text, not JSON: nothing to parse, so the lines stay beside it.
87
+ flushHeld();
88
+ stdout(outcome.body);
89
+ printFooter(context?.footer);
90
+ return;
91
+ }
92
+ stdout(render(withHints(outcome.body, context?.footer), flags.pretty || tty.stdout));
93
+ if (tty.stdout)
94
+ printFooter(context?.footer);
54
95
  return;
55
96
  }
56
97
  const shaped = shape(outcome.body, {
@@ -59,24 +100,27 @@ export function createRuntime({ flags, env = process.env, fetch, stdout = (line)
59
100
  list: context?.list === true,
60
101
  });
61
102
  if (!shaped.ok) {
103
+ flushHeld();
62
104
  stderr(shaped.message);
63
105
  exit(1);
64
106
  return;
65
107
  }
66
108
  if ('compact' in shaped) {
109
+ // A table, not JSON: what lies beside it stays on stderr.
110
+ flushHeld();
67
111
  if (shaped.compact)
68
112
  stdout(shaped.compact);
69
113
  if (shaped.meta)
70
114
  stderr(shaped.meta);
71
- if (context?.footer)
72
- stderr(context.footer);
115
+ printFooter(context?.footer);
73
116
  return;
74
117
  }
75
- stdout(render(shaped.json, flags.pretty || tty.stdout));
76
- if (context?.footer)
77
- stderr(context.footer);
118
+ stdout(render(withHints(shaped.json, context?.footer), flags.pretty || tty.stdout));
119
+ if (tty.stdout)
120
+ printFooter(context?.footer);
78
121
  return;
79
122
  }
123
+ flushHeld();
80
124
  stderr(render(outcome.body ?? { error: `HTTP ${outcome.status}` }, flags.pretty || tty.stderr));
81
125
  exit(1);
82
126
  },
@@ -102,6 +146,19 @@ function render(body, pretty) {
102
146
  : `${JSON.stringify(key)}:${JSON.stringify(value)}`);
103
147
  return `{${members.join(',')}}`;
104
148
  }
149
+ /**
150
+ * The object with `additions` merged into its `meta`, `meta` keeping its place (last when new);
151
+ * null when the value is no object or its `meta` is no object.
152
+ */
153
+ function metaWith(value, additions) {
154
+ if (!isRecord(value))
155
+ return null;
156
+ if (value.meta === undefined)
157
+ return { ...value, meta: additions };
158
+ if (!isRecord(value.meta))
159
+ return null;
160
+ return { ...value, meta: { ...value.meta, ...additions } };
161
+ }
105
162
  function isRecord(value) {
106
163
  return typeof value === 'object' && value !== null && !Array.isArray(value);
107
164
  }
@@ -1,3 +1,4 @@
1
+ import { editDistance } from './help.js';
1
2
  import { UsageError } from './invoke.js';
2
3
  /** The word that reaches a personal form. */
3
4
  export const PERSONAL = 'personal';
@@ -161,7 +162,7 @@ export function selectForm(forms, { first, flags }, reachable = () => true) {
161
162
  if (leafFlag.forms.has(form) || form.variant?.when?.flag === leafFlag.flag)
162
163
  continue;
163
164
  // A selector of another scope is not a flag of this form either.
164
- throw new UsageError(`--${leafFlag.flag} is not a flag of ${formLabel(form)} of ${command}.`);
165
+ throw new UsageError(misplacedFlag(leafFlag, form, command, shape));
165
166
  }
166
167
  for (const leafFlag of shape.flags) {
167
168
  const field = leafFlag.forms.get(form);
@@ -171,6 +172,36 @@ export function selectForm(forms, { first, flags }, reachable = () => true) {
171
172
  }
172
173
  return form;
173
174
  }
175
+ /**
176
+ * `--x is not a flag of this form`, then the forms that take it and this form's flag closest in
177
+ * spelling, so a script that names the wrong one learns the fix from the error alone.
178
+ */
179
+ function misplacedFlag(leafFlag, form, command, shape) {
180
+ const lines = [`--${leafFlag.flag} is not a flag of ${formLabel(form)} of ${command}.`];
181
+ const elsewhere = [
182
+ ...new Set([...leafFlag.forms.keys()].map((other) => {
183
+ const scope = scopeOf(other);
184
+ if (scope === 'all' && shape.scope)
185
+ return `${command} with no ${shape.scope.name}`;
186
+ return scopedUsage(command, scope, shape);
187
+ })),
188
+ ];
189
+ if (elsewhere.length)
190
+ lines.push(`It is a flag of ${elsewhere.join(' and of ')}.`);
191
+ const near = shape.flags
192
+ .filter((candidate) => candidate !== leafFlag && candidate.forms.has(form))
193
+ .map((candidate) => ({
194
+ flag: candidate.flag,
195
+ distance: editDistance(leafFlag.flag, candidate.flag),
196
+ }))
197
+ .filter(({ flag, distance }) => distance <= Math.max(2, Math.floor(flag.length / 4)))
198
+ .sort((a, b) => a.distance - b.distance)
199
+ .slice(0, 2);
200
+ if (near.length) {
201
+ lines.push(`Did you mean ${near.map(({ flag }) => `--${flag}`).join(' or ')}?`);
202
+ }
203
+ return lines.join(' ');
204
+ }
174
205
  function scopedUsage(command, scope, shape) {
175
206
  if (!shape.scope || scope === 'all')
176
207
  return command;
package/openapi.json CHANGED
@@ -26426,7 +26426,7 @@
26426
26426
  "/api/sensei/threads/{threadId}": {
26427
26427
  "get": {
26428
26428
  "operationId": "senseiThreadsGet",
26429
- "summary": "Read one of your Sensei Threads: its name, state, sessions and root, its replies oldest first, the Turn that runs or last ran in it, and its Up next. Paged: `limit` replies at a time, `before` for the ones older than a reply already read, and `since` for the ones newer than it. `session` keeps the rows about one Chat Session.",
26429
+ "summary": "Read one of your Sensei Threads: its name, state, sessions and root, its replies oldest first, the Turn that runs or last ran in it, and its Up next. Paged: `limit` replies at a time, `before` for the ones older than a reply already read, `since` for the ones newer than it, and `around` for the ones around one message, such as a search hit. `session` keeps the rows about one Chat Session.",
26430
26430
  "tags": ["sensei"],
26431
26431
  "x-kosuke-command": ["sensei", "threads", "get"],
26432
26432
  "x-kosuke-sandbox-token": true,
@@ -26479,6 +26479,18 @@
26479
26479
  "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
26480
26480
  }
26481
26481
  },
26482
+ {
26483
+ "name": "around",
26484
+ "in": "query",
26485
+ "required": false,
26486
+ "description": "The id of a message of the thread, such as a search hit: answers the replies around it, up to half of `limit` before it, then it and the ones after it, alone.",
26487
+ "schema": {
26488
+ "description": "The id of a message of the thread, such as a search hit: answers the replies around it, up to half of `limit` before it, then it and the ones after it, alone.",
26489
+ "type": "string",
26490
+ "format": "uuid",
26491
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
26492
+ }
26493
+ },
26482
26494
  {
26483
26495
  "name": "session",
26484
26496
  "in": "query",
@@ -26581,6 +26593,73 @@
26581
26593
  }
26582
26594
  }
26583
26595
  },
26596
+ "/api/sensei/threads/{threadId}/search": {
26597
+ "get": {
26598
+ "operationId": "senseiThreadsSearch",
26599
+ "summary": "Search one of your Sensei Threads for messages, yours and Sensei's, that hold some words. Newest first, at most 50, each with its id, who wrote it, when, and a short snippet around the first match. `around` on the thread's read opens one in its place.",
26600
+ "tags": ["sensei"],
26601
+ "x-kosuke-command": ["sensei", "threads", "search"],
26602
+ "x-kosuke-sandbox-token": true,
26603
+ "x-kosuke-cron-token": true,
26604
+ "x-kosuke-sensei-token": true,
26605
+ "parameters": [
26606
+ {
26607
+ "name": "threadId",
26608
+ "in": "path",
26609
+ "required": true,
26610
+ "schema": {
26611
+ "type": "string",
26612
+ "format": "uuid",
26613
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
26614
+ }
26615
+ },
26616
+ {
26617
+ "name": "q",
26618
+ "in": "query",
26619
+ "required": true,
26620
+ "description": "The words to find, 2 to 200 characters, as written: case is ignored and %, _ and \\ match themselves.",
26621
+ "schema": {
26622
+ "type": "string",
26623
+ "minLength": 2,
26624
+ "maxLength": 200,
26625
+ "description": "The words to find, 2 to 200 characters, as written: case is ignored and %, _ and \\ match themselves."
26626
+ }
26627
+ }
26628
+ ],
26629
+ "responses": {
26630
+ "2XX": {
26631
+ "description": "Success envelope",
26632
+ "content": {
26633
+ "application/json": {
26634
+ "schema": {
26635
+ "$ref": "#/components/schemas/ApiSuccess"
26636
+ }
26637
+ }
26638
+ }
26639
+ },
26640
+ "4XX": {
26641
+ "description": "Error envelope",
26642
+ "content": {
26643
+ "application/json": {
26644
+ "schema": {
26645
+ "$ref": "#/components/schemas/ApiError"
26646
+ }
26647
+ }
26648
+ }
26649
+ },
26650
+ "5XX": {
26651
+ "description": "Error envelope",
26652
+ "content": {
26653
+ "application/json": {
26654
+ "schema": {
26655
+ "$ref": "#/components/schemas/ApiError"
26656
+ }
26657
+ }
26658
+ }
26659
+ }
26660
+ }
26661
+ }
26662
+ },
26584
26663
  "/api/sensei/tickets/merge": {
26585
26664
  "post": {
26586
26665
  "operationId": "senseiTicketsMerge",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kosuke-ai/kosuke",
3
- "version": "1.0.131",
3
+ "version": "1.0.133",
4
4
  "description": "Sensei platform CLI. The client customers install to drive app.kosuke.ai from their own machine.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -43,10 +43,10 @@
43
43
  "minimatch": "^11.0.1"
44
44
  },
45
45
  "kosukeRelease": {
46
- "sourceCommit": "c4b47ba569c67982ec1766a72a89c2c122a12ae9",
47
- "sourceIdentity": "807d275f0b8c354cc68c446f357a2ccf155490c46ae6436e7e60d1610a18230b",
46
+ "sourceCommit": "f9c5e536c8ce17cc4981f141a590fea51f5f928d",
47
+ "sourceIdentity": "825dd549c0d613d40e2efd168443beeab6164d2b05d732656fc7acbb822d4816",
48
48
  "fragments": [
49
- "integrations-personal-workspace-c4nv4p.json"
49
+ "cli-piped-json-hints-125ftq.json"
50
50
  ]
51
51
  }
52
52
  }