@kosuke-ai/kosuke 1.0.167 → 1.0.168
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 +4 -0
- package/dist/runtime/attach.js +5 -23
- package/dist/runtime/session-project.js +23 -0
- package/dist/runtime/workspace-slug.js +51 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.168
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
|
|
3
7
|
## 1.0.167
|
|
4
8
|
|
|
5
9
|
- 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
|
package/dist/runtime/attach.js
CHANGED
|
@@ -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
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosuke-ai/kosuke",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.168",
|
|
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": "0fa55482dc518c6bd3ddcbaae22962b84e6ce455",
|
|
47
|
+
"sourceIdentity": "3909e257786e2bd044575f8de584203f4f89ede99004114724427036f72b68c9",
|
|
48
48
|
"fragments": [
|
|
49
|
-
"
|
|
49
|
+
"cli-workspace-slug-r7k2mq.json"
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
}
|