@kosuke-ai/kosuke 1.0.113 → 1.0.114
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 +4 -0
- package/README.md +8 -4
- package/dist/generated/commands/projects/list.js +13 -1
- package/dist/program.js +1 -0
- package/dist/runtime/arguments.js +9 -5
- package/dist/runtime/attach.js +16 -6
- package/dist/runtime/list-defaults.js +399 -0
- package/dist/runtime/runtime.js +9 -1
- package/openapi.json +13 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.114
|
|
4
|
+
|
|
5
|
+
- The lists (`projects`, `sessions`, `tasks`, `crons`, `activity`, `sensei threads`, `sensei cards`, `files`) print at most 20 short rows by default, with a footer on stderr naming the total and the next page. `--all` keeps every row, `--full` every field, and `--json` prints the platform's whole answer as before.
|
|
6
|
+
|
|
3
7
|
## 1.0.113
|
|
4
8
|
|
|
5
9
|
- Admin user reads now return `foundUs`, how the person says they found Kosuke, and the user detail adds `foundUsAt`, when they said it. Member settings list the new `find-us` system cron, which a member can turn off like the others.
|
package/README.md
CHANGED
|
@@ -18,10 +18,14 @@ kosuke workspaces timezone set <workspaceId> --timezone Europe/Zurich
|
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Every API command prints the platform's JSON response. `--json`, or `KOSUKE_OUTPUT=json`, asks
|
|
21
|
-
for
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
for its whole answer by name: pass it in anything that pipes into `jq`.
|
|
22
|
+
|
|
23
|
+
The lists are short by default: `projects list`, `sessions list`, `tasks list`, `crons list`,
|
|
24
|
+
`activity list`, `sensei threads list`, `sensei cards list` and `files list` print at most 20
|
|
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,
|
|
27
|
+
`--fields` picks from whole rows, and `get` prints one whole. `--json` prints and sends exactly what it did before.
|
|
28
|
+
|
|
25
29
|
Path params are positional, request fields are flags (`--exclude-archived`,
|
|
26
30
|
`--start-line-number 12`, and `--project a --project b` where a field takes
|
|
27
31
|
several values), and any body can be passed whole with `--body '{…}'`,
|
|
@@ -7,7 +7,19 @@ export const operation = {
|
|
|
7
7
|
],
|
|
8
8
|
"summary": "List the projects you can reach, across every workspace you belong to. An agent token sees only its own workspace.",
|
|
9
9
|
"pathParams": [],
|
|
10
|
-
"query": [
|
|
10
|
+
"query": [
|
|
11
|
+
{
|
|
12
|
+
"name": "sessions",
|
|
13
|
+
"flag": "sessions",
|
|
14
|
+
"kind": "string",
|
|
15
|
+
"required": false,
|
|
16
|
+
"description": "false leaves out each project's sessions, which grow with every session; the CLI's short list sends it.",
|
|
17
|
+
"choices": [
|
|
18
|
+
"true",
|
|
19
|
+
"false"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
],
|
|
11
23
|
"body": null,
|
|
12
24
|
"multipart": null,
|
|
13
25
|
"attachments": false,
|
package/dist/program.js
CHANGED
|
@@ -73,6 +73,7 @@ export function createProgram(options = {}) {
|
|
|
73
73
|
client: (o) => runtimeFor().client(o),
|
|
74
74
|
output: (outcome, context) => runtimeFor().output(outcome, context),
|
|
75
75
|
notice: (line) => runtimeFor().notice?.(line),
|
|
76
|
+
wholeAnswer: () => runtimeFor().wholeAnswer?.() ?? true,
|
|
76
77
|
};
|
|
77
78
|
attachAuthCommands(program, lazy, options.auth);
|
|
78
79
|
// An agent's credential reaches what its member's API key does, less the
|
|
@@ -28,11 +28,15 @@ export const CLI_OUTPUT_FLAGS = new Set(['--json', '--pretty']);
|
|
|
28
28
|
/** CLI-only flags of generated commands, by command words, each a boolean. */
|
|
29
29
|
export const CLI_ONLY_FLAGS = {
|
|
30
30
|
'sensei threads get': ['--tools'],
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
31
|
+
// The lists' short default (`./list-defaults.ts`): every row, and every field.
|
|
32
|
+
'projects list': ['--all', '--full'],
|
|
33
|
+
'sessions list': ['--all', '--full'],
|
|
34
|
+
'tasks list': ['--all', '--full'],
|
|
35
|
+
'crons list': ['--all', '--full'],
|
|
36
|
+
'activity list': ['--all', '--full'],
|
|
37
|
+
'sensei threads list': ['--all', '--full'],
|
|
38
|
+
'sensei cards list': ['--all', '--full'],
|
|
39
|
+
'files list': ['--all', '--full'],
|
|
36
40
|
// Read by `./prototype-create.ts` before it sends; a flag with `<value>` takes one.
|
|
37
41
|
'prototypes create': ['--project-dir <path>', '--preview-url <url>', '--skip-visual-check'],
|
|
38
42
|
};
|
package/dist/runtime/attach.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Argument, Command, InvalidArgumentError, Option } from 'commander';
|
|
|
3
3
|
import { addsSessionIdFlag, CLI_ONLY_FLAGS, omitsProject, SESSION_ID_FLAG, sessionIdField, } from './arguments.js';
|
|
4
4
|
import { setAfterHelp, setOptionShape, shortSummary, usageError } from './help.js';
|
|
5
5
|
import { buildRequest, execute, readWholeBody, UsageError } from './invoke.js';
|
|
6
|
+
import { LIST_FLAG_HELP, listAnswer, shortList, shortRequestFields } from './list-defaults.js';
|
|
6
7
|
import { collect, jsonParser } from './option-parsers.js';
|
|
7
8
|
import { withMemberTimeZone } from './member-time-zone.js';
|
|
8
9
|
import { isOwnerRepo, ownerRepoParser } from './owner-repo.js';
|
|
@@ -114,14 +115,10 @@ const VIEWS = {
|
|
|
114
115
|
view: (body, options) => threadView(body, { tools: options.tools === true }),
|
|
115
116
|
},
|
|
116
117
|
};
|
|
117
|
-
/** A list's `--all`. It changes nothing yet: a script passes it to keep every row when lists get a default limit. */
|
|
118
|
-
const ALL_FLAG_HELP = 'Every row, as a list prints now. Scripts pass it to stay whole.';
|
|
119
118
|
function addCliOnlyOptions(leaf, operation) {
|
|
120
119
|
const command = operation.command.join(' ');
|
|
121
120
|
for (const flag of CLI_ONLY_FLAGS[command] ?? []) {
|
|
122
|
-
leaf.addOption(new Option(flag, VIEWS[command]?.flags[flag] ??
|
|
123
|
-
PROTOTYPE_CREATE_HELP[flag] ??
|
|
124
|
-
(flag === '--all' ? ALL_FLAG_HELP : '')));
|
|
121
|
+
leaf.addOption(new Option(flag, VIEWS[command]?.flags[flag] ?? PROTOTYPE_CREATE_HELP[flag] ?? LIST_FLAG_HELP[flag] ?? ''));
|
|
125
122
|
}
|
|
126
123
|
}
|
|
127
124
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -312,13 +309,20 @@ function attachForms(root, forms, runtime, reachable) {
|
|
|
312
309
|
fields,
|
|
313
310
|
wholeBody,
|
|
314
311
|
attachments: options.attach ?? [],
|
|
315
|
-
});
|
|
312
|
+
}, options);
|
|
316
313
|
});
|
|
317
314
|
return leaf;
|
|
318
315
|
}
|
|
319
316
|
/** Build, send and print; a usage error is commander's, so it prints as one. */
|
|
320
317
|
async function run(leaf, runtime, operation, input, options = {}) {
|
|
321
318
|
input = await prepareOperationInput(runtime, operation, input, options);
|
|
319
|
+
// A list's short default, unless the call asked for the platform's whole answer.
|
|
320
|
+
const list = runtime.wholeAnswer?.() === false
|
|
321
|
+
? shortList(operation, input, { ...leaf.optsWithGlobals(), ...options })
|
|
322
|
+
: null;
|
|
323
|
+
if (list) {
|
|
324
|
+
input = { ...input, fields: { ...input.fields, ...shortRequestFields(list.rules, list.call) } };
|
|
325
|
+
}
|
|
322
326
|
let request;
|
|
323
327
|
try {
|
|
324
328
|
request = buildRequest(operation, input);
|
|
@@ -348,6 +352,12 @@ async function run(leaf, runtime, operation, input, options = {}) {
|
|
|
348
352
|
// `--fields` and `--format` pick from the platform's own JSON, so a text view steps aside.
|
|
349
353
|
const { fields, format } = leaf.optsWithGlobals();
|
|
350
354
|
const view = fields || format ? undefined : VIEWS[operation.command.join(' ')]?.view;
|
|
355
|
+
if (list && outcome.ok) {
|
|
356
|
+
const sent = request;
|
|
357
|
+
const short = await listAnswer(list.rules, list.call, outcome, (more) => execute(client, { ...sent, query: { ...sent.query, ...more } }, controller.signal));
|
|
358
|
+
runtime.output(short.answer, { list: true, footer: short.footer });
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
351
361
|
runtime.output(view && outcome.ok ? { ...outcome, body: view(outcome.body, options) } : outcome, { list: operation.command[operation.command.length - 1] === 'list' });
|
|
352
362
|
}
|
|
353
363
|
finally {
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
5
|
+
* `--all` keeps every row the platform answers, `--full` every field; `--json` (or
|
|
6
|
+
* `KOSUKE_OUTPUT=json`) prints the platform's whole answer, as before, and sends what it sent.
|
|
7
|
+
*
|
|
8
|
+
* Data and pure functions only, importing nothing, so the generator reads `LIST_DEFAULTS`
|
|
9
|
+
* and `LISTS_WITHOUT_DEFAULT` to refuse a new list that is in neither.
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_LIST_LIMIT = 20;
|
|
12
|
+
/** The help of a list's `--all` and `--full`. */
|
|
13
|
+
export const LIST_FLAG_HELP = {
|
|
14
|
+
'--all': `Every row, every page read, not the first ${DEFAULT_LIST_LIMIT}.`,
|
|
15
|
+
'--full': 'Every field of each row, not the short row.',
|
|
16
|
+
};
|
|
17
|
+
const PROMPT = { includePrompt: ['prompt', 'promptTruncated'] };
|
|
18
|
+
/** By command words. Every form of a command shares its entry. */
|
|
19
|
+
const LIST_DEFAULTS = {
|
|
20
|
+
'projects list': {
|
|
21
|
+
paging: { kind: 'client' },
|
|
22
|
+
fields: ['id', 'orgId', 'name', 'githubOwner', 'githubRepoName', 'defaultBranch'],
|
|
23
|
+
// The platform leaves out each project's sessions, which grow with every session.
|
|
24
|
+
shortQuery: { sessions: 'false' },
|
|
25
|
+
},
|
|
26
|
+
'sessions list': {
|
|
27
|
+
paging: { kind: 'cursor', limit: 'limit', cursor: 'cursor' },
|
|
28
|
+
fields: [
|
|
29
|
+
'id',
|
|
30
|
+
'projectId',
|
|
31
|
+
'title',
|
|
32
|
+
'status',
|
|
33
|
+
'stage',
|
|
34
|
+
'branchName',
|
|
35
|
+
'pullRequestNumber',
|
|
36
|
+
'prStatus',
|
|
37
|
+
'latestChatJobStatus',
|
|
38
|
+
'lastActivityAt',
|
|
39
|
+
],
|
|
40
|
+
askedFor: PROMPT,
|
|
41
|
+
samePath: { projectId: 'projectId' },
|
|
42
|
+
},
|
|
43
|
+
'tasks list': {
|
|
44
|
+
paging: { kind: 'cursor', limit: 'limit', cursor: 'cursor' },
|
|
45
|
+
fields: ['id', 'organizationId', 'projectId', 'title', 'status', 'priority', 'chatSession'],
|
|
46
|
+
nested: { chatSession: ['id', 'status', 'pullRequestNumber'] },
|
|
47
|
+
askedFor: PROMPT,
|
|
48
|
+
samePath: { organizationId: 'workspaceId' },
|
|
49
|
+
},
|
|
50
|
+
'crons list': {
|
|
51
|
+
// The sizes `readPageQuery` (src/lib/api/pagination.ts) applies.
|
|
52
|
+
paging: { kind: 'page', limit: 'pageSize', page: 'page', sizes: { default: 25, max: 100 } },
|
|
53
|
+
rowsAt: 'crons',
|
|
54
|
+
fields: ['id', 'name', 'enabled', 'cronExpression', 'timezone', 'nextRunAt', 'lastRunStatus'],
|
|
55
|
+
},
|
|
56
|
+
'activity list': {
|
|
57
|
+
paging: { kind: 'cursor', limit: 'limit', cursor: 'cursor' },
|
|
58
|
+
fields: [
|
|
59
|
+
'id',
|
|
60
|
+
'projectId',
|
|
61
|
+
'chatSessionId',
|
|
62
|
+
'kind',
|
|
63
|
+
'text',
|
|
64
|
+
'subject',
|
|
65
|
+
'sessionUrl',
|
|
66
|
+
'createdAt',
|
|
67
|
+
'isNew',
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
'sensei threads list': {
|
|
71
|
+
paging: { kind: 'cursor', limit: 'limit', cursor: 'cursor' },
|
|
72
|
+
rowsAt: 'threads',
|
|
73
|
+
fields: [
|
|
74
|
+
'id',
|
|
75
|
+
'kind',
|
|
76
|
+
'type',
|
|
77
|
+
'title',
|
|
78
|
+
'state',
|
|
79
|
+
'turn',
|
|
80
|
+
'pinned',
|
|
81
|
+
'openCards',
|
|
82
|
+
'lastActivityAt',
|
|
83
|
+
'sessions',
|
|
84
|
+
],
|
|
85
|
+
nested: { sessions: ['id', 'number', 'status'] },
|
|
86
|
+
},
|
|
87
|
+
'sensei cards list': {
|
|
88
|
+
paging: { kind: 'client' },
|
|
89
|
+
rowsAt: 'cards',
|
|
90
|
+
fields: [
|
|
91
|
+
'id',
|
|
92
|
+
'key',
|
|
93
|
+
'revision',
|
|
94
|
+
'threadId',
|
|
95
|
+
'sessionId',
|
|
96
|
+
'headline',
|
|
97
|
+
'urgency',
|
|
98
|
+
'stateKey',
|
|
99
|
+
'decision',
|
|
100
|
+
'answeredAt',
|
|
101
|
+
'closedAt',
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
'files list': {
|
|
105
|
+
paging: { kind: 'client' },
|
|
106
|
+
rowsAt: 'items',
|
|
107
|
+
fields: ['id', 'kind', 'name', 'path', 'byteSize', 'version', 'updatedAt'],
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* The `list` commands that print the platform's whole answer by default: each reads one
|
|
112
|
+
* thing's children or a short, fixed set. A new list goes here or in `LIST_DEFAULTS`.
|
|
113
|
+
*/
|
|
114
|
+
const LISTS_WITHOUT_DEFAULT = new Set([
|
|
115
|
+
'crons files list',
|
|
116
|
+
'crons runs files list',
|
|
117
|
+
'crons runs list',
|
|
118
|
+
'crons runs messages list',
|
|
119
|
+
'deploys list',
|
|
120
|
+
'deploys messages list',
|
|
121
|
+
'deploys queue list',
|
|
122
|
+
'devices list',
|
|
123
|
+
'github repositories list',
|
|
124
|
+
'integrations browser-connections list',
|
|
125
|
+
'integrations connections list',
|
|
126
|
+
'integrations tools list',
|
|
127
|
+
'mac apps list',
|
|
128
|
+
'mac browser connections list',
|
|
129
|
+
'mac browser profiles list',
|
|
130
|
+
'mac files list',
|
|
131
|
+
'mac windows list',
|
|
132
|
+
'models list',
|
|
133
|
+
'plugins list',
|
|
134
|
+
'projects branches list',
|
|
135
|
+
'projects labels list',
|
|
136
|
+
'projects labels sessions list',
|
|
137
|
+
'projects live logs list',
|
|
138
|
+
'projects merge-agent runs list',
|
|
139
|
+
'projects releases list',
|
|
140
|
+
'projects services list',
|
|
141
|
+
'projects settings changes list',
|
|
142
|
+
'projects skills list',
|
|
143
|
+
'projects versions list',
|
|
144
|
+
'sensei delegates list',
|
|
145
|
+
'sensei device-requests list',
|
|
146
|
+
'sensei reels activity list',
|
|
147
|
+
'sensei reels later-holds list',
|
|
148
|
+
'sessions diff comments list',
|
|
149
|
+
'sessions diff commits list',
|
|
150
|
+
'sessions diff files list',
|
|
151
|
+
'sessions files list',
|
|
152
|
+
'sessions jobs list',
|
|
153
|
+
'sessions messages list',
|
|
154
|
+
'sessions queue list',
|
|
155
|
+
'sessions sandbox-files list',
|
|
156
|
+
'skills list',
|
|
157
|
+
'tasks labels list',
|
|
158
|
+
'workspaces list',
|
|
159
|
+
'workspaces members list',
|
|
160
|
+
]);
|
|
161
|
+
/**
|
|
162
|
+
* A command whose last word is `list` in neither set, named for the generator's refusal.
|
|
163
|
+
* @internal Read by `scripts/generate.ts`.
|
|
164
|
+
*/
|
|
165
|
+
export function listsWithoutDecision(commands) {
|
|
166
|
+
const missing = new Set();
|
|
167
|
+
for (const command of commands) {
|
|
168
|
+
const words = command.join(' ');
|
|
169
|
+
if (command[command.length - 1] !== 'list')
|
|
170
|
+
continue;
|
|
171
|
+
if (LIST_DEFAULTS[words] || LISTS_WITHOUT_DEFAULT.has(words))
|
|
172
|
+
continue;
|
|
173
|
+
missing.add(words);
|
|
174
|
+
}
|
|
175
|
+
return [...missing].sort();
|
|
176
|
+
}
|
|
177
|
+
/** The short default of a GET list command, read from its call; null for any other command. */
|
|
178
|
+
export function shortList(operation, input, options) {
|
|
179
|
+
const rules = LIST_DEFAULTS[operation.command.join(' ')];
|
|
180
|
+
if (!rules || operation.method !== 'get')
|
|
181
|
+
return null;
|
|
182
|
+
const call = {
|
|
183
|
+
all: options.all === true,
|
|
184
|
+
// `--fields` picks its own fields from whole rows, so it reads as `--full`.
|
|
185
|
+
full: options.full === true || options.fields !== undefined,
|
|
186
|
+
fields: input.fields,
|
|
187
|
+
pathParams: input.pathParams,
|
|
188
|
+
};
|
|
189
|
+
return { rules, call };
|
|
190
|
+
}
|
|
191
|
+
/** The request fields the short default adds: the limit, and `shortQuery` without `--full`. */
|
|
192
|
+
export function shortRequestFields(list, call) {
|
|
193
|
+
const added = {};
|
|
194
|
+
const { paging } = list;
|
|
195
|
+
if (!call.all && paging.kind !== 'client' && call.fields[paging.limit] === undefined) {
|
|
196
|
+
added[paging.limit] = DEFAULT_LIST_LIMIT;
|
|
197
|
+
}
|
|
198
|
+
if (!call.full) {
|
|
199
|
+
for (const [name, value] of Object.entries(list.shortQuery ?? {})) {
|
|
200
|
+
if (call.fields[name] === undefined)
|
|
201
|
+
added[name] = value;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return added;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* With `--all`, a paged list reads every page after `first` through `fetchPage`, which sends the
|
|
208
|
+
* call again with the next page's fields; the rows are joined into the last answer's shape. A
|
|
209
|
+
* refused page is the answer. Without `--all`, or for a list the platform does not page, `first`.
|
|
210
|
+
* It ends on the last page, an empty page, or a cursor already read. A batch (`hasMore` with no
|
|
211
|
+
* cursor, as `activity list --mark-seen` answers: each call takes the next one) is asked again.
|
|
212
|
+
*/
|
|
213
|
+
async function everyPage(list, call, first, fetchPage) {
|
|
214
|
+
const { paging } = list;
|
|
215
|
+
let rows = rowsOf(list, first.body);
|
|
216
|
+
if (!call.all || paging.kind === 'client' || !first.ok || !rows)
|
|
217
|
+
return first;
|
|
218
|
+
const joined = [...rows];
|
|
219
|
+
const read = new Set();
|
|
220
|
+
let answer = first;
|
|
221
|
+
const batches = isBatch(first.body);
|
|
222
|
+
for (;;) {
|
|
223
|
+
let fields;
|
|
224
|
+
if (paging.kind === 'cursor') {
|
|
225
|
+
// A cursor answered twice would read the same page again: the list ends there.
|
|
226
|
+
const next = nextCursor(answer.body);
|
|
227
|
+
if (next && !read.has(next)) {
|
|
228
|
+
read.add(next);
|
|
229
|
+
fields = { [paging.cursor]: next };
|
|
230
|
+
}
|
|
231
|
+
else if (batches && isBatch(answer.body) && rows.length)
|
|
232
|
+
fields = {};
|
|
233
|
+
else
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
const total = totalOf(answer.body);
|
|
238
|
+
const size = pageSize(paging, call);
|
|
239
|
+
const start = positive(call.fields[paging.page]) ?? 1;
|
|
240
|
+
if (total === null || !rows.length || (start - 1) * size + joined.length >= total)
|
|
241
|
+
break;
|
|
242
|
+
fields = { [paging.page]: start + Math.ceil(joined.length / size) };
|
|
243
|
+
}
|
|
244
|
+
const page = await fetchPage(fields);
|
|
245
|
+
rows = rowsOf(list, page.body);
|
|
246
|
+
if (!page.ok)
|
|
247
|
+
return page;
|
|
248
|
+
if (!rows?.length)
|
|
249
|
+
break;
|
|
250
|
+
joined.push(...rows);
|
|
251
|
+
answer = page;
|
|
252
|
+
}
|
|
253
|
+
const body = withRows(list, answer.body, joined);
|
|
254
|
+
// A batch's total counts what was left before it: the first one's counts the whole read.
|
|
255
|
+
return { ...answer, body: batches ? withTotal(body, paginationOf(first.body).total) : body };
|
|
256
|
+
}
|
|
257
|
+
function paginationOf(body) {
|
|
258
|
+
const meta = isRecord(body) && isRecord(body.meta) ? body.meta : {};
|
|
259
|
+
return isRecord(meta.pagination) ? meta.pagination : {};
|
|
260
|
+
}
|
|
261
|
+
/** More rows wait, with no cursor to them: the same call answers the next batch. */
|
|
262
|
+
function isBatch(body) {
|
|
263
|
+
const pagination = paginationOf(body);
|
|
264
|
+
return pagination.hasMore === true && !stringOrNull(pagination.nextCursor);
|
|
265
|
+
}
|
|
266
|
+
function withTotal(body, total) {
|
|
267
|
+
if (!isRecord(body) || typeof total !== 'number')
|
|
268
|
+
return body;
|
|
269
|
+
const meta = isRecord(body.meta) ? body.meta : {};
|
|
270
|
+
return { ...body, meta: { ...meta, pagination: { ...paginationOf(body), total } } };
|
|
271
|
+
}
|
|
272
|
+
function rowsOf(list, body) {
|
|
273
|
+
const holder = isRecord(body) ? (list.rowsAt ? body.data : body) : null;
|
|
274
|
+
const rows = isRecord(holder) ? holder[list.rowsAt ?? 'data'] : null;
|
|
275
|
+
return Array.isArray(rows) ? rows : null;
|
|
276
|
+
}
|
|
277
|
+
function withRows(list, body, rows) {
|
|
278
|
+
if (!isRecord(body))
|
|
279
|
+
return body;
|
|
280
|
+
if (!list.rowsAt)
|
|
281
|
+
return { ...body, data: rows };
|
|
282
|
+
return isRecord(body.data) ? { ...body, data: { ...body.data, [list.rowsAt]: rows } } : body;
|
|
283
|
+
}
|
|
284
|
+
function nextCursor(body) {
|
|
285
|
+
if (!isRecord(body))
|
|
286
|
+
return null;
|
|
287
|
+
const meta = isRecord(body.meta) ? body.meta : {};
|
|
288
|
+
const pagination = isRecord(meta.pagination) ? meta.pagination : {};
|
|
289
|
+
const data = isRecord(body.data) ? body.data : {};
|
|
290
|
+
return stringOrNull(pagination.nextCursor) ?? stringOrNull(data.nextCursor);
|
|
291
|
+
}
|
|
292
|
+
function totalOf(body) {
|
|
293
|
+
const data = isRecord(body) && isRecord(body.data) ? body.data : {};
|
|
294
|
+
return typeof data.total === 'number' ? data.total : null;
|
|
295
|
+
}
|
|
296
|
+
/** The page size the platform applies: the one asked for, else its default, at most its max. */
|
|
297
|
+
function pageSize(paging, call) {
|
|
298
|
+
const asked = positive(call.fields[paging.limit]) ?? (call.all ? null : DEFAULT_LIST_LIMIT);
|
|
299
|
+
return Math.min(asked ?? paging.sizes.default, paging.sizes.max);
|
|
300
|
+
}
|
|
301
|
+
/** A list's answer as the short default prints it, every page read first with `--all`. */
|
|
302
|
+
export async function listAnswer(list, call, first, fetchPage) {
|
|
303
|
+
const answer = await everyPage(list, call, first, fetchPage);
|
|
304
|
+
if (!answer.ok)
|
|
305
|
+
return { answer, footer: null };
|
|
306
|
+
const short = shortAnswer(list, call, answer.body);
|
|
307
|
+
return { answer: { ...answer, body: short.body }, footer: short.footer };
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The answer cut to its short default: the rows (client paging, without `--all`), each row's
|
|
311
|
+
* fields (without `--full`), and the footer. An answer of another shape passes through whole.
|
|
312
|
+
*/
|
|
313
|
+
function shortAnswer(list, call, body) {
|
|
314
|
+
if (!isRecord(body))
|
|
315
|
+
return { body, footer: null };
|
|
316
|
+
const holder = list.rowsAt ? body.data : body;
|
|
317
|
+
const key = list.rowsAt ?? 'data';
|
|
318
|
+
if (!isRecord(holder) || !Array.isArray(holder[key]))
|
|
319
|
+
return { body, footer: null };
|
|
320
|
+
const rows = holder[key];
|
|
321
|
+
const cut = list.paging.kind === 'client' && !call.all && rows.length > DEFAULT_LIST_LIMIT;
|
|
322
|
+
const kept = cut ? rows.slice(0, DEFAULT_LIST_LIMIT) : rows;
|
|
323
|
+
const shown = call.full ? kept : kept.map((row) => shortRow(list, call, row));
|
|
324
|
+
const shortHolder = { ...holder, [key]: shown };
|
|
325
|
+
const answer = list.rowsAt ? { ...body, data: shortHolder } : shortHolder;
|
|
326
|
+
return { body: answer, footer: footer(list, call, body, rows.length, shown.length) };
|
|
327
|
+
}
|
|
328
|
+
function shortRow(list, call, row) {
|
|
329
|
+
if (!isRecord(row))
|
|
330
|
+
return row;
|
|
331
|
+
const keep = new Set(list.fields);
|
|
332
|
+
for (const [field, adds] of Object.entries(list.askedFor ?? {})) {
|
|
333
|
+
if (call.fields[field] === true || call.fields[field] === 'true') {
|
|
334
|
+
for (const name of adds)
|
|
335
|
+
keep.add(name);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
for (const [field, param] of Object.entries(list.samePath ?? {})) {
|
|
339
|
+
const sent = call.pathParams?.[param];
|
|
340
|
+
if (sent !== undefined && row[field] === sent)
|
|
341
|
+
keep.delete(field);
|
|
342
|
+
}
|
|
343
|
+
const short = {};
|
|
344
|
+
for (const [name, value] of Object.entries(row)) {
|
|
345
|
+
// A null says nothing a reader needs: a short row leaves it out.
|
|
346
|
+
if (!keep.has(name) || value === null)
|
|
347
|
+
continue;
|
|
348
|
+
const inner = list.nested?.[name];
|
|
349
|
+
short[name] = inner ? pick(value, inner) : value;
|
|
350
|
+
}
|
|
351
|
+
return short;
|
|
352
|
+
}
|
|
353
|
+
function pick(value, keys) {
|
|
354
|
+
if (Array.isArray(value))
|
|
355
|
+
return value.map((item) => pick(item, keys));
|
|
356
|
+
if (!isRecord(value))
|
|
357
|
+
return value;
|
|
358
|
+
return Object.fromEntries(keys
|
|
359
|
+
.filter((key) => value[key] !== undefined && value[key] !== null)
|
|
360
|
+
.map((key) => [key, value[key]]));
|
|
361
|
+
}
|
|
362
|
+
/** `20 of 3122. More: --cursor <c>`; `20 of 20+.` where the platform counts no total. */
|
|
363
|
+
function footer(list, call, body, answered, shown) {
|
|
364
|
+
const { paging } = list;
|
|
365
|
+
if (paging.kind === 'client') {
|
|
366
|
+
return shown < answered ? `${shown} of ${answered}. More: --all` : `${shown} of ${answered}.`;
|
|
367
|
+
}
|
|
368
|
+
if (paging.kind === 'page') {
|
|
369
|
+
const total = totalOf(body);
|
|
370
|
+
if (total === null)
|
|
371
|
+
return `${shown} shown.`;
|
|
372
|
+
// The rows answered, from the page asked for on: a single page, or every one with --all.
|
|
373
|
+
const size = pageSize(paging, call);
|
|
374
|
+
const start = positive(call.fields[paging.page]) ?? 1;
|
|
375
|
+
const more = answered > 0 && (start - 1) * size + answered < total;
|
|
376
|
+
const next = start + Math.ceil(answered / size);
|
|
377
|
+
return `${shown} of ${total}.${more ? ` More: --${kebab(paging.page)} ${next}` : ''}`;
|
|
378
|
+
}
|
|
379
|
+
const meta = isRecord(body.meta) ? body.meta : {};
|
|
380
|
+
const pagination = isRecord(meta.pagination) ? meta.pagination : {};
|
|
381
|
+
const next = nextCursor(body);
|
|
382
|
+
const total = typeof pagination.total === 'number' ? pagination.total : null;
|
|
383
|
+
const of = total ?? (next || isBatch(body) ? `${shown}+` : shown);
|
|
384
|
+
const more = next ? ` More: --cursor ${next}` : isBatch(body) ? ' More: run it again' : '';
|
|
385
|
+
return `${shown} of ${of}.${more}`;
|
|
386
|
+
}
|
|
387
|
+
function positive(value) {
|
|
388
|
+
const number = typeof value === 'string' ? Number(value) : value;
|
|
389
|
+
return typeof number === 'number' && Number.isInteger(number) && number > 0 ? number : null;
|
|
390
|
+
}
|
|
391
|
+
function stringOrNull(value) {
|
|
392
|
+
return typeof value === 'string' && value !== '' ? value : null;
|
|
393
|
+
}
|
|
394
|
+
function kebab(name) {
|
|
395
|
+
return name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
396
|
+
}
|
|
397
|
+
function isRecord(value) {
|
|
398
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
399
|
+
}
|
package/dist/runtime/runtime.js
CHANGED
|
@@ -3,7 +3,7 @@ import { resolveCredentials, } from './credentials.js';
|
|
|
3
3
|
import { shape } from './fields.js';
|
|
4
4
|
/**
|
|
5
5
|
* Whether the call asked for JSON: `--json` or `KOSUKE_OUTPUT=json`, one switch. Every generated
|
|
6
|
-
* command
|
|
6
|
+
* command prints JSON; with it, a list prints the platform's whole answer, not its short default.
|
|
7
7
|
*/
|
|
8
8
|
export function jsonRequested(flag, env) {
|
|
9
9
|
return flag === true || env.KOSUKE_OUTPUT === 'json';
|
|
@@ -33,6 +33,8 @@ export function createRuntime({ flags, env = process.env, fetch, stdout = (line)
|
|
|
33
33
|
notice(line) {
|
|
34
34
|
stderr(line);
|
|
35
35
|
},
|
|
36
|
+
// `--format json` names JSON as `--json` does: the platform's whole answer.
|
|
37
|
+
wholeAnswer: () => jsonRequested(flags.json, env) || flags.format === 'json',
|
|
36
38
|
output(outcome, context) {
|
|
37
39
|
if (outcome.ok) {
|
|
38
40
|
// 204 has nothing to print; anything else is passed through as JSON so
|
|
@@ -47,6 +49,8 @@ export function createRuntime({ flags, env = process.env, fetch, stdout = (line)
|
|
|
47
49
|
return;
|
|
48
50
|
}
|
|
49
51
|
stdout(render(outcome.body, flags.pretty || tty.stdout));
|
|
52
|
+
if (context?.footer)
|
|
53
|
+
stderr(context.footer);
|
|
50
54
|
return;
|
|
51
55
|
}
|
|
52
56
|
const shaped = shape(outcome.body, {
|
|
@@ -64,9 +68,13 @@ export function createRuntime({ flags, env = process.env, fetch, stdout = (line)
|
|
|
64
68
|
stdout(shaped.compact);
|
|
65
69
|
if (shaped.meta)
|
|
66
70
|
stderr(shaped.meta);
|
|
71
|
+
if (context?.footer)
|
|
72
|
+
stderr(context.footer);
|
|
67
73
|
return;
|
|
68
74
|
}
|
|
69
75
|
stdout(render(shaped.json, flags.pretty || tty.stdout));
|
|
76
|
+
if (context?.footer)
|
|
77
|
+
stderr(context.footer);
|
|
70
78
|
return;
|
|
71
79
|
}
|
|
72
80
|
stderr(render(outcome.body ?? { error: `HTTP ${outcome.status}` }, flags.pretty || tty.stderr));
|
package/openapi.json
CHANGED
|
@@ -10765,6 +10765,19 @@
|
|
|
10765
10765
|
"x-kosuke-sandbox-token": true,
|
|
10766
10766
|
"x-kosuke-cron-token": true,
|
|
10767
10767
|
"x-kosuke-sensei-token": true,
|
|
10768
|
+
"parameters": [
|
|
10769
|
+
{
|
|
10770
|
+
"name": "sessions",
|
|
10771
|
+
"in": "query",
|
|
10772
|
+
"required": false,
|
|
10773
|
+
"description": "false leaves out each project's sessions, which grow with every session; the CLI's short list sends it.",
|
|
10774
|
+
"schema": {
|
|
10775
|
+
"description": "false leaves out each project's sessions, which grow with every session; the CLI's short list sends it.",
|
|
10776
|
+
"type": "string",
|
|
10777
|
+
"enum": ["true", "false"]
|
|
10778
|
+
}
|
|
10779
|
+
}
|
|
10780
|
+
],
|
|
10768
10781
|
"responses": {
|
|
10769
10782
|
"2XX": {
|
|
10770
10783
|
"description": "Success envelope",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosuke-ai/kosuke",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.114",
|
|
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": "
|
|
47
|
-
"sourceIdentity": "
|
|
46
|
+
"sourceCommit": "a48484955733ab073729e1c3409f2668543958e7",
|
|
47
|
+
"sourceIdentity": "c60ac18c46f6b2aef9a32073095845a2e01fe3bd4d1ad988911915220058452e",
|
|
48
48
|
"fragments": [
|
|
49
|
-
"
|
|
49
|
+
"short-list-defaults-hs1ff2.json"
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
}
|