@kosuke-ai/kosuke 1.0.167 → 1.0.169

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.169
4
+
5
+ - `kosuke sensei threads split` and `threads create` say they run only when the member asks for a separate thread.
6
+
7
+ ## 1.0.168
8
+
9
+ - Accept a workspace's slug from an app URL wherever a workspace id goes: a refused slug is looked up among your workspaces and sent again as its id.
10
+
3
11
  ## 1.0.167
4
12
 
5
13
  - The cards schema text now says a card with a clarification question takes a headline of its own that names its subject, never a question's words.
package/README.md CHANGED
@@ -55,6 +55,10 @@ kosuke sensei sessions facts get <sessionId>
55
55
  kosuke sensei threads get <threadId> --since <messageId>
56
56
  ```
57
57
 
58
+ A workspace's slug, as an app URL carries it (`/w/kosuke-core-765bebf6/…`), works where a
59
+ workspace id goes: when the platform refuses it as an id, the CLI looks it up among your
60
+ workspaces and sends the request again with its id.
61
+
58
62
  `kosuke find` prints one row per match: its workspace, project, session, thread, task, pull
59
63
  request number and head SHA. A command whose path starts with the project and session ids
60
64
  takes the session id alone, or `--session-id`, and reads its project with the same lookup; a
@@ -6,7 +6,7 @@ export const operation = {
6
6
  "threads",
7
7
  "create"
8
8
  ],
9
- "summary": "Open a new thread for the member, at any point of this Turn, on a prompt you write. Only Sensei calls it, for a separate topic that should not go on in this thread. Never for the asks of the member’s message that started this thread: `sensei threads split` does that. The new thread gets its own Turn, which may read Queued, and links back here; nothing of this thread goes with it, so the prompt says all it needs. A Turn opens at most 3 threads, and so do the threads opened from one thread in all. Answers the new thread id and turn id: do not do that work here.",
9
+ "summary": "Open a new thread for the member, at any point of this Turn, on a prompt you write. Only Sensei calls it, and only when the member asks for a new thread: another topic goes on here, or in the thread that holds it (`sensei threads search`). Never for the asks of the member’s message that started this thread: `sensei threads split` does that. The new thread gets its own Turn, which may read Queued, and links back here; nothing of this thread goes with it, so the prompt says all it needs. A Turn opens at most 3 threads, and so do the threads opened from one thread in all. Answers the new thread id and turn id: do not do that work here.",
10
10
  "pathParams": [],
11
11
  "query": [],
12
12
  "body": {
@@ -6,7 +6,7 @@ export const operation = {
6
6
  "threads",
7
7
  "split"
8
8
  ],
9
- "summary": "Split the member’s message that started this Turn’s thread into one thread per ask. Only Sensei calls it, once per message. The member’s message stays the root of this thread, which does the first ask; each other ask becomes a thread of its own with its own Turn. The reply lists the asks handed off: do not do those here. Each ask stands alone: \"Ship A, B and C\" is three asks, the steps of one piece of work are one.",
9
+ "summary": "Split the member’s message that started this Turn’s thread into one thread per ask, only when the member asked for separate threads: one thread runs several asks at once, so \"Ship A, B and C\" stays here. Only Sensei calls it, once per message. The member’s message stays the root of this thread, which does the first ask; each other ask becomes a thread of its own with its own Turn. The reply lists the asks handed off: do not do those here.",
10
10
  "pathParams": [],
11
11
  "query": [],
12
12
  "body": {
@@ -76,7 +76,7 @@ export const operation = {
76
76
  "flag": "branch",
77
77
  "kind": "string",
78
78
  "required": false,
79
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
79
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
80
80
  },
81
81
  {
82
82
  "name": "reason",
@@ -208,7 +208,7 @@ export const operation = {
208
208
  "flag": "branch",
209
209
  "kind": "string",
210
210
  "required": false,
211
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
211
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
212
212
  },
213
213
  {
214
214
  "name": "reason",
@@ -65,7 +65,7 @@ export const operation = {
65
65
  "flag": "branch",
66
66
  "kind": "string",
67
67
  "required": false,
68
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
68
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
69
69
  },
70
70
  {
71
71
  "name": "reason",
@@ -228,7 +228,7 @@ export const operation = {
228
228
  "flag": "branch",
229
229
  "kind": "string",
230
230
  "required": false,
231
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
231
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
232
232
  },
233
233
  {
234
234
  "name": "reason",
@@ -63,7 +63,7 @@ export const operation = {
63
63
  "flag": "branch",
64
64
  "kind": "string",
65
65
  "required": false,
66
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
66
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
67
67
  },
68
68
  {
69
69
  "name": "reason",
@@ -226,7 +226,7 @@ export const operation = {
226
226
  "flag": "branch",
227
227
  "kind": "string",
228
228
  "required": false,
229
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
229
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch."
230
230
  },
231
231
  {
232
232
  "name": "reason",
@@ -10,6 +10,8 @@ import { isOwnerRepo, ownerRepoParser } from './owner-repo.js';
10
10
  import { PERSONAL_SPACE_PARAM } from './personal-space.js';
11
11
  import { refusedBeforeSending } from './prototype-check.js';
12
12
  import { personalSpaceId } from './personal-space-id.js';
13
+ import { projectOf } from './session-project.js';
14
+ import { sendWithWorkspaceSlug } from './workspace-slug.js';
13
15
  import { PROTOTYPE_CREATE_HELP, prepareOperationInput } from './prototype-create.js';
14
16
  import { threadView, TOOLS_FLAG_HELP } from './thread-text.js';
15
17
  import { fieldsOf, formLabel, formUsage, leafShape, pathParamsFor, PERSONAL, scopeOf, selectForm, } from './variants.js';
@@ -170,28 +172,6 @@ function sessionArgs(operation, operands, options) {
170
172
  },
171
173
  };
172
174
  }
173
- /** The session's project, by the lookup `kosuke find` runs; null once the failure is printed. */
174
- async function projectOf(runtime, sessionId) {
175
- const outcome = await execute(runtime.client(), {
176
- method: 'get',
177
- path: '/api/find/{query}',
178
- pathParams: { query: sessionId },
179
- query: {},
180
- body: null,
181
- });
182
- if (!outcome.ok) {
183
- runtime.output(outcome);
184
- return null;
185
- }
186
- const rows = outcome.body?.data;
187
- const row = (Array.isArray(rows) ? rows : []).find((candidate) => candidate.match === 'session' &&
188
- typeof candidate.sessionId === 'string' &&
189
- candidate.sessionId.toLowerCase() === sessionId.toLowerCase());
190
- if (typeof row?.projectId === 'string')
191
- return row.projectId;
192
- runtime.output({ ok: false, status: 404, body: `error: no session ${sessionId} in your reach.` });
193
- return null;
194
- }
195
175
  /** A leaf over several forms: the union of their flags, the form picked per call. */
196
176
  function attachForms(root, forms, runtime, reachable) {
197
177
  const path = forms[0].command;
@@ -349,7 +329,9 @@ async function run(leaf, runtime, operation, input, options = {}) {
349
329
  process.once('SIGTERM', cancel);
350
330
  }
351
331
  try {
352
- const outcome = await execute(client, request, controller.signal);
332
+ const sent = await sendWithWorkspaceSlug(runtime, operation, input, request, (built) => execute(client, built, controller.signal));
333
+ const outcome = sent.outcome;
334
+ request = sent.request;
353
335
  // `--fields` and `--format` pick from the platform's own JSON, so a text view steps aside.
354
336
  const { fields, format } = leaf.optsWithGlobals();
355
337
  const view = fields || format ? undefined : VIEWS[operation.command.join(' ')]?.view;
@@ -0,0 +1,23 @@
1
+ import { execute } from './invoke.js';
2
+ /** The session's project, by the lookup `kosuke find` runs; null once the failure is printed. */
3
+ export async function projectOf(runtime, sessionId) {
4
+ const outcome = await execute(runtime.client(), {
5
+ method: 'get',
6
+ path: '/api/find/{query}',
7
+ pathParams: { query: sessionId },
8
+ query: {},
9
+ body: null,
10
+ });
11
+ if (!outcome.ok) {
12
+ runtime.output(outcome);
13
+ return null;
14
+ }
15
+ const rows = outcome.body?.data;
16
+ const row = (Array.isArray(rows) ? rows : []).find((candidate) => candidate.match === 'session' &&
17
+ typeof candidate.sessionId === 'string' &&
18
+ candidate.sessionId.toLowerCase() === sessionId.toLowerCase());
19
+ if (typeof row?.projectId === 'string')
20
+ return row.projectId;
21
+ runtime.output({ ok: false, status: 404, body: `error: no session ${sessionId} in your reach.` });
22
+ return null;
23
+ }
@@ -0,0 +1,51 @@
1
+ import { buildRequest, execute, } from './invoke.js';
2
+ import { withMemberTimeZone } from './member-time-zone.js';
3
+ /**
4
+ * A workspace's slug, as the app's URLs carry it (`/w/kosuke-core-765bebf6/tasks`), where a
5
+ * workspace id goes. Read only after the platform refused the value as an id: a value shaped
6
+ * like a slug (lowercase words and dashes, not a UUID) is swapped for the id of the member's
7
+ * workspace that has it. A slug none of their workspaces has comes back unchanged, so the
8
+ * refusal stands.
9
+ */
10
+ /** `kosuke workspaces list`: the member's workspaces, `{ data: [{ id, slug }] }`. */
11
+ const WORKSPACES_PATH = '/api/organizations';
12
+ const WORKSPACE_PARAMS = ['workspaceId', 'organizationId'];
13
+ const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)+$/;
14
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
15
+ /**
16
+ * Sends `request`; refused with a 403 or 404 for a workspace slug copied from an app URL, sends
17
+ * it again with the workspace's id. Returns the request last sent with its outcome.
18
+ */
19
+ export async function sendWithWorkspaceSlug(runtime, operation, input, request, send) {
20
+ const outcome = await send(request);
21
+ if (outcome.ok || (outcome.status !== 403 && outcome.status !== 404)) {
22
+ return { outcome, request };
23
+ }
24
+ const pathParams = await resolveWorkspaceSlug(runtime, input.pathParams);
25
+ if (pathParams === input.pathParams)
26
+ return { outcome, request };
27
+ const resolved = { ...input, pathParams };
28
+ const retry = await withMemberTimeZone(runtime, operation, resolved, buildRequest(operation, resolved));
29
+ return { outcome: await send(retry), request: retry };
30
+ }
31
+ async function resolveWorkspaceSlug(runtime, pathParams) {
32
+ const param = WORKSPACE_PARAMS.find((name) => {
33
+ const value = pathParams[name] ?? '';
34
+ return SLUG.test(value) && !UUID.test(value);
35
+ });
36
+ if (!param)
37
+ return pathParams;
38
+ const outcome = await execute(runtime.client(), {
39
+ method: 'get',
40
+ path: WORKSPACES_PATH,
41
+ pathParams: {},
42
+ query: {},
43
+ body: null,
44
+ });
45
+ const rows = isRecord(outcome.body) && Array.isArray(outcome.body.data) ? outcome.body.data : [];
46
+ const match = rows.find((row) => isRecord(row) && row.slug === pathParams[param] && typeof row.id === 'string');
47
+ return match ? { ...pathParams, [param]: match.id } : pathParams;
48
+ }
49
+ function isRecord(value) {
50
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
51
+ }
package/openapi.json CHANGED
@@ -11061,7 +11061,7 @@
11061
11061
  "maxLength": 255
11062
11062
  },
11063
11063
  "branch": {
11064
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch.",
11064
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch.",
11065
11065
  "type": "string",
11066
11066
  "minLength": 1,
11067
11067
  "maxLength": 255
@@ -11187,7 +11187,7 @@
11187
11187
  "maxLength": 255
11188
11188
  },
11189
11189
  "branch": {
11190
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch.",
11190
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch.",
11191
11191
  "type": "string",
11192
11192
  "minLength": 1,
11193
11193
  "maxLength": 255
@@ -11292,7 +11292,7 @@
11292
11292
  "maxLength": 255
11293
11293
  },
11294
11294
  "branch": {
11295
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch.",
11295
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch.",
11296
11296
  "type": "string",
11297
11297
  "minLength": 1,
11298
11298
  "maxLength": 255
@@ -14188,7 +14188,7 @@
14188
14188
  "maxLength": 255
14189
14189
  },
14190
14190
  "branch": {
14191
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch.",
14191
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch.",
14192
14192
  "type": "string",
14193
14193
  "minLength": 1,
14194
14194
  "maxLength": 255
@@ -14265,7 +14265,7 @@
14265
14265
  "maxLength": 255
14266
14266
  },
14267
14267
  "branch": {
14268
- "description": "An existing branch the session works on: it checks it out, pushes to it and opens its pull request from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch.",
14268
+ "description": "An existing branch the session works on: it checks it out, pushes to it, and takes the pull request already open on it or opens one from it. Not the default branch, the Target Branch, or a branch another open session works on. Absent: a new branch. Repository projects only; not with startBranch.",
14269
14269
  "type": "string",
14270
14270
  "minLength": 1,
14271
14271
  "maxLength": 255
@@ -27670,7 +27670,7 @@
27670
27670
  "/api/sensei/thread-create": {
27671
27671
  "post": {
27672
27672
  "operationId": "senseiThreadsCreate",
27673
- "summary": "Open a new thread for the member, at any point of this Turn, on a prompt you write. Only Sensei calls it, for a separate topic that should not go on in this thread. Never for the asks of the member’s message that started this thread: `sensei threads split` does that. The new thread gets its own Turn, which may read Queued, and links back here; nothing of this thread goes with it, so the prompt says all it needs. A Turn opens at most 3 threads, and so do the threads opened from one thread in all. Answers the new thread id and turn id: do not do that work here.",
27673
+ "summary": "Open a new thread for the member, at any point of this Turn, on a prompt you write. Only Sensei calls it, and only when the member asks for a new thread: another topic goes on here, or in the thread that holds it (`sensei threads search`). Never for the asks of the member’s message that started this thread: `sensei threads split` does that. The new thread gets its own Turn, which may read Queued, and links back here; nothing of this thread goes with it, so the prompt says all it needs. A Turn opens at most 3 threads, and so do the threads opened from one thread in all. Answers the new thread id and turn id: do not do that work here.",
27674
27674
  "tags": ["sensei"],
27675
27675
  "x-kosuke-command": ["sensei", "threads", "create"],
27676
27676
  "x-kosuke-sandbox-token": true,
@@ -27921,7 +27921,7 @@
27921
27921
  "/api/sensei/thread-split": {
27922
27922
  "post": {
27923
27923
  "operationId": "senseiThreadsSplit",
27924
- "summary": "Split the member’s message that started this Turn’s thread into one thread per ask. Only Sensei calls it, once per message. The member’s message stays the root of this thread, which does the first ask; each other ask becomes a thread of its own with its own Turn. The reply lists the asks handed off: do not do those here. Each ask stands alone: \"Ship A, B and C\" is three asks, the steps of one piece of work are one.",
27924
+ "summary": "Split the member’s message that started this Turn’s thread into one thread per ask, only when the member asked for separate threads: one thread runs several asks at once, so \"Ship A, B and C\" stays here. Only Sensei calls it, once per message. The member’s message stays the root of this thread, which does the first ask; each other ask becomes a thread of its own with its own Turn. The reply lists the asks handed off: do not do those here.",
27925
27925
  "tags": ["sensei"],
27926
27926
  "x-kosuke-command": ["sensei", "threads", "split"],
27927
27927
  "x-kosuke-sandbox-token": true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kosuke-ai/kosuke",
3
- "version": "1.0.167",
3
+ "version": "1.0.169",
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": "50ba22d7db0d754c39b353af4d55ac94e79b82fe",
47
- "sourceIdentity": "e279517d3f5e05181d0a6238e13b1f60e43af53d12d7e45521141ac1b5b4e38a",
46
+ "sourceCommit": "57a8cd52af9f8a9b2cc73e2fdb4879350ff9585a",
47
+ "sourceIdentity": "1822471fb9ca087cd347060a2188775c02c945c67a47d2c9c6b5a117bf237ccf",
48
48
  "fragments": [
49
- "sensei-question-card-headline.json"
49
+ "fewer-threads-ux-q7m2kd.json"
50
50
  ]
51
51
  }
52
52
  }