@kosuke-ai/kosuke 1.3.3682 → 1.3.3705
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.3.3705
|
|
4
|
+
|
|
5
|
+
- In a Kosuke sandbox, a failed call now says when KOSUKE_API_KEY is the preview's own key from /run/kosuke/shared.env, not the session's.
|
|
6
|
+
|
|
7
|
+
## 1.3.3689
|
|
8
|
+
|
|
9
|
+
- `sessions search` and `workspaces artifacts search` match each word of the query in any order, and take `--closest true` for the titles holding one of its words when none holds them all.
|
|
10
|
+
|
|
3
11
|
## 1.3.3682
|
|
4
12
|
|
|
5
13
|
- Sensei cards can bind a new WhatsApp message that quotes no earlier message, still sent only after the member approves it.
|
|
@@ -24,6 +24,16 @@ export const operation = {
|
|
|
24
24
|
"choices": [
|
|
25
25
|
"status"
|
|
26
26
|
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "closest",
|
|
30
|
+
"flag": "closest",
|
|
31
|
+
"kind": "string",
|
|
32
|
+
"required": false,
|
|
33
|
+
"description": "true: when no title holds every word of a q of two words or more, answer with the titles that hold one of its words of three letters or more, and set closest.",
|
|
34
|
+
"choices": [
|
|
35
|
+
"true"
|
|
36
|
+
]
|
|
27
37
|
}
|
|
28
38
|
],
|
|
29
39
|
"body": null,
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, openSync, readSync } from 'node:fs';
|
|
2
|
+
/**
|
|
3
|
+
* The environment file a Kosuke sandbox's preview services start with. It holds the project's
|
|
4
|
+
* own saved variables, which may include a `KOSUKE_API_KEY` for the preview's own processes.
|
|
5
|
+
* A shell that sources it (`set -a; . /run/kosuke/shared.env`) replaces the session's own key.
|
|
6
|
+
*/
|
|
7
|
+
const PREVIEW_SHARED_ENV_PATH = '/run/kosuke/shared.env';
|
|
8
|
+
/** Far above any environment file ksb writes: a larger one is not read. */
|
|
9
|
+
const MAX_SHARED_ENV_BYTES = 1024 * 1024;
|
|
10
|
+
/**
|
|
11
|
+
* The preview's environment file as text, or null when it is missing, unreadable, too large or
|
|
12
|
+
* no regular file. Opened without blocking, so a FIFO or device at the path never holds up the
|
|
13
|
+
* error it is read for.
|
|
14
|
+
*/
|
|
15
|
+
export function readPreviewSharedEnv(path = PREVIEW_SHARED_ENV_PATH) {
|
|
16
|
+
let fd = null;
|
|
17
|
+
try {
|
|
18
|
+
fd = openSync(path, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
19
|
+
const stat = fstatSync(fd);
|
|
20
|
+
if (!stat.isFile() || stat.size > MAX_SHARED_ENV_BYTES)
|
|
21
|
+
return null;
|
|
22
|
+
const buffer = Buffer.alloc(stat.size);
|
|
23
|
+
let read = 0;
|
|
24
|
+
while (read < buffer.length) {
|
|
25
|
+
const got = readSync(fd, buffer, read, buffer.length - read, read);
|
|
26
|
+
if (got === 0)
|
|
27
|
+
break;
|
|
28
|
+
read += got;
|
|
29
|
+
}
|
|
30
|
+
return buffer.subarray(0, read).toString('utf8');
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
if (fd !== null)
|
|
37
|
+
closeSync(fd);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One variable's value in an environment file ksb writes (`NAME="value"`, `\\` and `\"`
|
|
42
|
+
* escaped), or a plain `NAME=value` line; null when the file does not set it.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export function envFileValue(text, name) {
|
|
46
|
+
let found = null;
|
|
47
|
+
for (const line of text.split(/\r?\n/)) {
|
|
48
|
+
const trimmed = line.replace(/^\s*export\s+/, '').trim();
|
|
49
|
+
if (!trimmed.startsWith(`${name}=`))
|
|
50
|
+
continue;
|
|
51
|
+
const raw = trimmed.slice(name.length + 1);
|
|
52
|
+
const quoted = /^"(.*)"$/.exec(raw);
|
|
53
|
+
// The last assignment wins, as it does when a shell sources the file.
|
|
54
|
+
found = quoted ? quoted[1].replace(/\\(["\\])/g, '$1') : raw;
|
|
55
|
+
}
|
|
56
|
+
return found;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The line a failed call prints when its key came from the environment and is the preview's own
|
|
60
|
+
* `KOSUKE_API_KEY`: the shell sourced the preview's file, so the call did not run as this session.
|
|
61
|
+
* Null otherwise. It never prints the key.
|
|
62
|
+
*/
|
|
63
|
+
export function previewKeyHint(credentials, readSharedEnv = readPreviewSharedEnv) {
|
|
64
|
+
if (credentials.apiKeySource !== 'env' || !credentials.apiKey)
|
|
65
|
+
return null;
|
|
66
|
+
const text = readSharedEnv();
|
|
67
|
+
if (!text)
|
|
68
|
+
return null;
|
|
69
|
+
if (envFileValue(text, 'KOSUKE_API_KEY') !== credentials.apiKey)
|
|
70
|
+
return null;
|
|
71
|
+
return (`This key belongs to the preview, not this session: KOSUKE_API_KEY came from ${PREVIEW_SHARED_ENV_PATH}. ` +
|
|
72
|
+
'Run kosuke from a shell that never sourced that file.');
|
|
73
|
+
}
|
package/dist/runtime/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createApiClient } from './client.js';
|
|
2
2
|
import { resolveCredentials, } from './credentials.js';
|
|
3
3
|
import { shape } from './fields.js';
|
|
4
|
+
import { previewKeyHint, readPreviewSharedEnv } from './preview-credentials.js';
|
|
4
5
|
/**
|
|
5
6
|
* Whether the call asked for JSON: `--json` or `KOSUKE_OUTPUT=json`, one switch. Every generated
|
|
6
7
|
* command prints JSON; with it, a list prints the platform's whole answer, not its short default.
|
|
@@ -10,9 +11,12 @@ export function jsonRequested(flag, env) {
|
|
|
10
11
|
}
|
|
11
12
|
export function createRuntime({ flags, env = process.env, fetch, stdout = (line) => process.stdout.write(line + '\n'), stderr = (line) => process.stderr.write(line + '\n'), exit = (code) => {
|
|
12
13
|
process.exitCode = code;
|
|
13
|
-
}, tty = { stdout: process.stdout.isTTY === true, stderr: process.stderr.isTTY === true }, }) {
|
|
14
|
+
}, tty = { stdout: process.stdout.isTTY === true, stderr: process.stderr.isTTY === true }, readPreviewSharedEnv: readSharedEnv = () => env.KOSUKE_SANDBOX_KEY ? readPreviewSharedEnv() : null, }) {
|
|
14
15
|
let resolved = null;
|
|
15
16
|
const credentials = () => (resolved ??= resolveCredentials(flags, env));
|
|
17
|
+
// Whether a call sent the key: an anonymous one cannot have failed for it.
|
|
18
|
+
let sentKey = false;
|
|
19
|
+
const keyHint = () => (sentKey ? previewKeyHint(credentials(), readSharedEnv) : null);
|
|
16
20
|
// Notices held for the answer while stdout is a pipe: an agent that merges stderr into the
|
|
17
21
|
// stream it parses must still read one JSON value.
|
|
18
22
|
const held = [];
|
|
@@ -53,10 +57,12 @@ export function createRuntime({ flags, env = process.env, fetch, stdout = (line)
|
|
|
53
57
|
exit(1);
|
|
54
58
|
throw new ExitSignal();
|
|
55
59
|
}
|
|
60
|
+
if (!anonymous)
|
|
61
|
+
sentKey = true;
|
|
56
62
|
return createApiClient({
|
|
57
63
|
apiUrl,
|
|
58
64
|
apiKey: anonymous ? null : apiKey,
|
|
59
|
-
fetch,
|
|
65
|
+
fetch: anonymous ? fetch : namingPreviewKey(fetch ?? globalThis.fetch, keyHint),
|
|
60
66
|
answerTimeoutMs,
|
|
61
67
|
});
|
|
62
68
|
},
|
|
@@ -121,12 +127,48 @@ export function createRuntime({ flags, env = process.env, fetch, stdout = (line)
|
|
|
121
127
|
printFooter(context?.footer);
|
|
122
128
|
return;
|
|
123
129
|
}
|
|
124
|
-
|
|
125
|
-
|
|
130
|
+
const body = outcome.body ?? { error: `HTTP ${outcome.status}` };
|
|
131
|
+
// First, so a caller that keeps only the start of stderr still reads it. Piped, it is the
|
|
132
|
+
// error's first field, with the held notices in its meta, so stderr stays one JSON value.
|
|
133
|
+
const hint = keyHint();
|
|
134
|
+
if (hint && !tty.stderr && isRecord(body)) {
|
|
135
|
+
const hinted = { credentialHint: hint, ...body };
|
|
136
|
+
const notices = held.splice(0);
|
|
137
|
+
const placed = notices.length ? metaWith(hinted, { notices }) : hinted;
|
|
138
|
+
stderr(render(placed ?? hinted, flags.pretty === true));
|
|
139
|
+
if (placed === null)
|
|
140
|
+
for (const line of notices)
|
|
141
|
+
stderr(line);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
if (hint)
|
|
145
|
+
stderr(hint);
|
|
146
|
+
flushHeld();
|
|
147
|
+
stderr(render(body, flags.pretty || tty.stderr));
|
|
148
|
+
}
|
|
126
149
|
exit(1);
|
|
127
150
|
},
|
|
128
151
|
};
|
|
129
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* A call that never reaches the platform skips `output`: its error names the preview's key itself,
|
|
155
|
+
* first, so the line the CLI prints for it says why. A caller's own abort or timeout is left as is.
|
|
156
|
+
*/
|
|
157
|
+
function namingPreviewKey(fetchImpl, hint) {
|
|
158
|
+
return async (...args) => {
|
|
159
|
+
try {
|
|
160
|
+
return await fetchImpl(...args);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (error instanceof Error && error.name !== 'AbortError' && error.name !== 'TimeoutError') {
|
|
164
|
+
const line = hint();
|
|
165
|
+
if (line && !error.message.startsWith(line))
|
|
166
|
+
error.message = `${line} ${error.message}`;
|
|
167
|
+
}
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
130
172
|
/**
|
|
131
173
|
* Indented for a person at a terminal or with `--pretty`; one line for a pipe, which an agent
|
|
132
174
|
* reads token by token, with each row of a top-level `data` list on its own line.
|
package/openapi.json
CHANGED
|
@@ -1093,6 +1093,17 @@
|
|
|
1093
1093
|
"type": "string",
|
|
1094
1094
|
"enum": ["status"]
|
|
1095
1095
|
}
|
|
1096
|
+
},
|
|
1097
|
+
{
|
|
1098
|
+
"name": "closest",
|
|
1099
|
+
"in": "query",
|
|
1100
|
+
"required": false,
|
|
1101
|
+
"description": "true: when no title holds every word of a q of two words or more, answer with the titles that hold one of its words of three letters or more, and set closest.",
|
|
1102
|
+
"schema": {
|
|
1103
|
+
"description": "true: when no title holds every word of a q of two words or more, answer with the titles that hold one of its words of three letters or more, and set closest.",
|
|
1104
|
+
"type": "string",
|
|
1105
|
+
"enum": ["true"]
|
|
1106
|
+
}
|
|
1096
1107
|
}
|
|
1097
1108
|
],
|
|
1098
1109
|
"responses": {
|
|
@@ -6754,6 +6765,17 @@
|
|
|
6754
6765
|
"description": "Search text, trimmed. Empty or absent returns the most recent artifacts.",
|
|
6755
6766
|
"type": "string"
|
|
6756
6767
|
}
|
|
6768
|
+
},
|
|
6769
|
+
{
|
|
6770
|
+
"name": "closest",
|
|
6771
|
+
"in": "query",
|
|
6772
|
+
"required": false,
|
|
6773
|
+
"description": "true: when no title holds every word of a q of two words or more, answer with the titles that hold one of its words of three letters or more, and set closest.",
|
|
6774
|
+
"schema": {
|
|
6775
|
+
"description": "true: when no title holds every word of a q of two words or more, answer with the titles that hold one of its words of three letters or more, and set closest.",
|
|
6776
|
+
"type": "string",
|
|
6777
|
+
"enum": ["true"]
|
|
6778
|
+
}
|
|
6757
6779
|
}
|
|
6758
6780
|
],
|
|
6759
6781
|
"responses": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosuke-ai/kosuke",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3705",
|
|
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": "f5061fd62eb6afe6158567b641335a039f5fa112",
|
|
47
|
+
"sourceIdentity": "dca3fde9ebf709019f059bef5ceb6f6bc608de81d3e2125b4dfec90142bf0c91",
|
|
48
48
|
"fragments": [
|
|
49
|
-
"
|
|
49
|
+
"preview-key-hint-ald26n.json"
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
}
|