@aidenhq/sdk 0.4.2 → 0.4.4
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.
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export declare const SETTINGS_PATHS: RegExp;
|
|
2
|
+
/**
|
|
3
|
+
* A local module's own file, `modules/<name>/<path>`: each segment starts with a letter, digit or _ (no hidden files but a
|
|
4
|
+
* last `.dockerignore`), and none is `node_modules` or `dist` (installed and built output is never landed).
|
|
5
|
+
*/
|
|
6
|
+
export declare const MODULE_FILE: RegExp;
|
|
7
|
+
/** What an apply may land: the settings paths, and a local module's files. */
|
|
1
8
|
export declare const APPLY_PATHS: RegExp;
|
|
2
9
|
/** Files a change touches outside what apply may land. */
|
|
3
10
|
export declare const strayFiles: (files: string[]) => string[];
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
// The instance repo files
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// Pure: the kernel's apply and both code hosts (codehost-local imports it, codehost-github holds a copy,
|
|
5
|
-
// scripts/sync-shared.ts) read
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
// The instance repo files a settings write may touch (SETTINGS_PATHS: instance.yaml, apps.yaml, the owner's profile, a module
|
|
2
|
+
// agent's added rules agents/<key>.md and handbook fork agents/<key>/AGENTS.md, and a local module's module.yaml, agents'
|
|
3
|
+
// handbooks and skills) and the files an apply may land (APPLY_PATHS: those, and every file of a local module under the file
|
|
4
|
+
// policy MODULE_FILE). Pure: the kernel's apply and both code hosts (codehost-local imports it, codehost-github holds a copy,
|
|
5
|
+
// scripts/sync-shared.ts) read these lists. A file's mode, size and text are the code hosts' to check (fileAt: 100644, text, 1 MB).
|
|
6
|
+
export const SETTINGS_PATHS = /^(instance\.yaml|apps\.yaml|owner\/profile\.md|agents\/[\w.-]+\.md|agents\/[a-z0-9][a-z0-9-]*\/AGENTS\.md|modules\/[a-z0-9][a-z0-9-]*\/(module\.yaml|agents\/[a-z0-9][a-z0-9-]*\/AGENTS\.md|skills\/[a-z0-9][a-z0-9-]*\/SKILL\.md))$/;
|
|
7
|
+
/**
|
|
8
|
+
* A local module's own file, `modules/<name>/<path>`: each segment starts with a letter, digit or _ (no hidden files but a
|
|
9
|
+
* last `.dockerignore`), and none is `node_modules` or `dist` (installed and built output is never landed).
|
|
10
|
+
*/
|
|
11
|
+
export const MODULE_FILE = /^modules\/[a-z0-9][a-z0-9-]{0,62}\/(?:(?!(?:node_modules|dist)\/)[A-Za-z0-9_][A-Za-z0-9._@+-]*\/)*(?:(?!(?:node_modules|dist)$)[A-Za-z0-9_][A-Za-z0-9._@+-]*|\.dockerignore)$/;
|
|
12
|
+
/** What an apply may land: the settings paths, and a local module's files. */
|
|
13
|
+
export const APPLY_PATHS = new RegExp(`${SETTINGS_PATHS.source}|${MODULE_FILE.source}`);
|
|
8
14
|
/** Files a change touches outside what apply may land. */
|
|
9
15
|
export const strayFiles = (files) => files.filter((f) => !APPLY_PATHS.test(f));
|
package/dist/src/paperclip.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const RESTART_WAIT_MS = 20_000;
|
|
1
2
|
export class PaperclipError extends Error {
|
|
2
3
|
status;
|
|
3
4
|
body;
|
|
@@ -22,12 +23,47 @@ function errorMessage(text) {
|
|
|
22
23
|
export function paperclipClient({ url, token, lane, headers, timeoutMs = 20_000, fetcher = fetch }) {
|
|
23
24
|
const prefix = (method) => (lane === "owner" ? (method === "GET" ? "/v1/cp/read" : "/v1/cp/owner") : lane === "agent" ? "/v1/cp/agent" : "");
|
|
24
25
|
/** The raw response, for a body that isn't JSON (an upload's form, a file's bytes). */
|
|
25
|
-
const
|
|
26
|
+
const once = (method, path, init) => fetcher(new URL(`${prefix(method)}${path}`, url), {
|
|
26
27
|
method,
|
|
27
28
|
headers: { authorization: `Bearer ${token}`, accept: "application/json", ...(init.type ? { "content-type": init.type } : {}), ...headers?.(method) },
|
|
28
29
|
body: init.body,
|
|
29
30
|
signal: AbortSignal.timeout(init.timeoutMs ?? timeoutMs),
|
|
30
31
|
});
|
|
32
|
+
// A read rides out a Paperclip restart (an apply): a 503 or a refused connection is retried for up to RESTART_WAIT_MS,
|
|
33
|
+
// honouring retry-after. A write is sent once. The caller's own timeout is the first attempt's; each retry's attempt is bounded
|
|
34
|
+
// by what is left of the deadline, so a stalled request can't outlast it.
|
|
35
|
+
const send = async (method, path, init = {}) => {
|
|
36
|
+
const until = Date.now() + RESTART_WAIT_MS;
|
|
37
|
+
for (let attempt = init.timeoutMs;;) {
|
|
38
|
+
let res, down;
|
|
39
|
+
try {
|
|
40
|
+
res = await once(method, path, attempt === undefined ? init : { ...init, timeoutMs: attempt });
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (method !== "GET" || !(e instanceof TypeError))
|
|
44
|
+
throw e;
|
|
45
|
+
down = e;
|
|
46
|
+
}
|
|
47
|
+
if (res && (res.status !== 503 || method !== "GET"))
|
|
48
|
+
return res;
|
|
49
|
+
const ra = Number(res?.headers.get("retry-after") ?? "");
|
|
50
|
+
const wait = Math.max(200, (res?.headers.get("retry-after") && ra >= 0 ? ra : 1) * 1000);
|
|
51
|
+
if (Date.now() + wait >= until) {
|
|
52
|
+
if (res)
|
|
53
|
+
return res;
|
|
54
|
+
throw down;
|
|
55
|
+
}
|
|
56
|
+
await res?.body?.cancel();
|
|
57
|
+
await new Promise((r) => setTimeout(r, wait));
|
|
58
|
+
const left = until - Date.now();
|
|
59
|
+
if (left <= 0) {
|
|
60
|
+
if (res)
|
|
61
|
+
return res;
|
|
62
|
+
throw down;
|
|
63
|
+
}
|
|
64
|
+
attempt = Math.min(init.timeoutMs ?? timeoutMs, left);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
31
67
|
const fail = async (res, method, path) => {
|
|
32
68
|
const text = await res.text();
|
|
33
69
|
let body;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidenhq/sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "The shared code of AidenHQ modules: contract types, engine IO, the caller check and fence, write executors, the reviewer side, the judges' models and call, the source writer and the vendor MCP pass-through.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|