@aidenhq/sdk 0.5.4 → 0.5.6
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/README.md +2 -2
- package/dist/assets/page-kit.css +142 -0
- package/dist/assets/page-kit.js +311 -0
- package/dist/src/card-words.d.ts +8 -0
- package/dist/src/card-words.js +29 -0
- package/dist/src/event-send.d.ts +4 -2
- package/dist/src/event-send.js +28 -10
- package/dist/src/face-kit.d.ts +20 -0
- package/dist/src/face-kit.js +32 -0
- package/dist/src/module-mcp.d.ts +39 -0
- package/dist/src/module-mcp.js +80 -0
- package/dist/src/number-setting.d.ts +11 -0
- package/dist/src/number-setting.js +27 -0
- package/dist/src/reason-codes.d.ts +14 -0
- package/dist/src/reason-codes.js +45 -0
- package/dist/src/requested-parent.d.ts +33 -0
- package/dist/src/requested-parent.js +56 -0
- package/dist/src/schedule.d.ts +52 -0
- package/dist/src/schedule.js +653 -0
- package/dist/src/teammate-name.d.ts +4 -0
- package/dist/src/teammate-name.js +25 -0
- package/dist/src/url-setting.d.ts +5 -0
- package/dist/src/url-setting.js +49 -0
- package/package.json +10 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const HAIRS: readonly ["short", "spiky", "long", "curly", "bun"];
|
|
2
|
+
export declare const ACCESSORIES: readonly ["none", "headset", "glasses", "round-glasses", "cap", "hard-hat", "earrings", "pencil", "headband"];
|
|
3
|
+
export declare const BODIES: readonly ["none", "tie", "notepad", "badge", "shield"];
|
|
4
|
+
/** How many of each colour the kit has (web/src/ui/tokens.css --face-skin-*, --face-hair-*, --face-bg-*). */
|
|
5
|
+
export declare const SKINS = 10;
|
|
6
|
+
export declare const HAIR_COLORS = 9;
|
|
7
|
+
export declare const PALETTES = 10;
|
|
8
|
+
export interface FaceKit {
|
|
9
|
+
hair: (typeof HAIRS)[number];
|
|
10
|
+
accessory: (typeof ACCESSORIES)[number];
|
|
11
|
+
body: (typeof BODIES)[number];
|
|
12
|
+
/** 0–9 */
|
|
13
|
+
skin: number;
|
|
14
|
+
/** 0–8; the brow follows. */
|
|
15
|
+
hair_color: number;
|
|
16
|
+
/** 0–9: the background and shirt pair. */
|
|
17
|
+
palette: number;
|
|
18
|
+
}
|
|
19
|
+
/** Why `v` isn't a face spec, or undefined when it is: exactly these six keys, all required. */
|
|
20
|
+
export declare function faceKitProblem(v: unknown): string | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// A teammate's face as a character-kit spec (an agent's `teammate.face:` in AGENTS.md or module.yaml): which hair,
|
|
2
|
+
// accessory and body mark, and which skin, hair colour and palette by index. One rule for the compiler (the gate) and the
|
|
3
|
+
// board (it draws the face: web/src/ui/Face.tsx). Plain TypeScript Node runs as is; the board holds a synced copy
|
|
4
|
+
// (scripts/sync-shared.ts).
|
|
5
|
+
export const HAIRS = ["short", "spiky", "long", "curly", "bun"];
|
|
6
|
+
export const ACCESSORIES = ["none", "headset", "glasses", "round-glasses", "cap", "hard-hat", "earrings", "pencil", "headband"];
|
|
7
|
+
export const BODIES = ["none", "tie", "notepad", "badge", "shield"];
|
|
8
|
+
/** How many of each colour the kit has (web/src/ui/tokens.css --face-skin-*, --face-hair-*, --face-bg-*). */
|
|
9
|
+
export const SKINS = 10;
|
|
10
|
+
export const HAIR_COLORS = 9;
|
|
11
|
+
export const PALETTES = 10;
|
|
12
|
+
const ENUMS = { hair: HAIRS, accessory: ACCESSORIES, body: BODIES };
|
|
13
|
+
const RANGES = { skin: SKINS, hair_color: HAIR_COLORS, palette: PALETTES };
|
|
14
|
+
/** Why `v` isn't a face spec, or undefined when it is: exactly these six keys, all required. */
|
|
15
|
+
export function faceKitProblem(v) {
|
|
16
|
+
if (!v || typeof v !== "object" || Array.isArray(v))
|
|
17
|
+
return "a face spec is a map of hair, accessory, body, skin, hair_color and palette";
|
|
18
|
+
const o = v;
|
|
19
|
+
for (const k of Object.keys(o))
|
|
20
|
+
if (!(k in ENUMS) && !(k in RANGES))
|
|
21
|
+
return `a face spec has no ${k}`;
|
|
22
|
+
for (const [k, values] of Object.entries(ENUMS)) {
|
|
23
|
+
if (!values.includes(o[k]))
|
|
24
|
+
return `face ${k} is one of ${values.join(", ")}`;
|
|
25
|
+
}
|
|
26
|
+
for (const [k, n] of Object.entries(RANGES)) {
|
|
27
|
+
const x = o[k];
|
|
28
|
+
if (typeof x !== "number" || !Number.isInteger(x) || x < 0 || x >= n)
|
|
29
|
+
return `face ${k} is a whole number from 0 to ${n - 1}`;
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { Caller } from "./caller.js";
|
|
3
|
+
type Dict = Record<string, unknown>;
|
|
4
|
+
export interface Tool {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: object;
|
|
8
|
+
roles?: string[];
|
|
9
|
+
run: (args: Dict, caller: {
|
|
10
|
+
agent: string;
|
|
11
|
+
roles: string[];
|
|
12
|
+
assertion?: string;
|
|
13
|
+
task?: string;
|
|
14
|
+
kind?: string;
|
|
15
|
+
}) => Promise<unknown>;
|
|
16
|
+
}
|
|
17
|
+
type Msg = {
|
|
18
|
+
id?: unknown;
|
|
19
|
+
method?: string;
|
|
20
|
+
params?: {
|
|
21
|
+
name?: string;
|
|
22
|
+
arguments?: Record<string, unknown>;
|
|
23
|
+
uri?: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/** The Fleet page: an MCP Apps view (text/html;profile=mcp-app) the module serves as a resource. */
|
|
27
|
+
export interface View {
|
|
28
|
+
uri: string;
|
|
29
|
+
html: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function pageHtml(dir: URL): string;
|
|
32
|
+
export declare function createMcp(name: string, tools: Tool[], views?: View[]): (msg: Msg, caller: () => Promise<Caller & {
|
|
33
|
+
assertion?: string;
|
|
34
|
+
}>) => Promise<object | undefined>;
|
|
35
|
+
/** POST /mcp with the connection's service key; false for any other path. */
|
|
36
|
+
export declare function serveMcp(handle: ReturnType<typeof createMcp>, key: () => string, caller: (req: IncomingMessage) => Promise<Caller & {
|
|
37
|
+
assertion?: string;
|
|
38
|
+
}>, maxBytes?: number): (req: IncomingMessage, res: ServerResponse) => Promise<boolean>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// The module's MCP connection (a stateless JSON-RPC subset: initialize, tools/list, tools/call) for the kernel's
|
|
2
|
+
// proxy: the module's tools and its Fleet page view. Every call carries the kernel's caller assertion, whose signed roles gate
|
|
3
|
+
// each tool; the connection returns untrusted (a PR's title is a stranger's text).
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { timingSafeEqual } from "node:crypto";
|
|
6
|
+
const text = (v, isError = false, structured = false) => ({ content: [{ type: "text", text: typeof v === "string" ? v : JSON.stringify(v) }], ...(structured && v && typeof v === "object" ? { structuredContent: v } : {}), ...(isError ? { isError: true } : {}) });
|
|
7
|
+
// A page.html (in `dir`) with the shared kit (assets/page-kit.css and .js, shipped in this package) inlined at its kit:css and kit:js markers.
|
|
8
|
+
export function pageHtml(dir) {
|
|
9
|
+
const read = (f) => readFileSync(f, "utf8");
|
|
10
|
+
const kit = (f) => read(new URL(`../assets/${f}`, import.meta.url));
|
|
11
|
+
return read(new URL("./page.html", dir)).replace("/*kit:css*/", () => kit("page-kit.css")).replace("/*kit:js*/", () => kit("page-kit.js"));
|
|
12
|
+
}
|
|
13
|
+
export function createMcp(name, tools, views = []) {
|
|
14
|
+
const byName = new Map(tools.map((t) => [t.name, t]));
|
|
15
|
+
return async function handle(msg, caller) {
|
|
16
|
+
const reply = (result) => ({ jsonrpc: "2.0", id: msg.id ?? null, result });
|
|
17
|
+
if (msg.method === "initialize")
|
|
18
|
+
return reply({ protocolVersion: "2025-03-26", capabilities: { tools: {}, ...(views.length ? { resources: {} } : {}) }, serverInfo: { name, version: "0.1.0" } });
|
|
19
|
+
if (msg.method === "tools/list")
|
|
20
|
+
return reply({ tools: tools.map(({ name, description, inputSchema }) => ({ name, description, inputSchema })) });
|
|
21
|
+
if (msg.method === "resources/read") {
|
|
22
|
+
const v = views.find((x) => x.uri === msg.params?.uri);
|
|
23
|
+
return v ? reply({ contents: [{ uri: v.uri, mimeType: "text/html;profile=mcp-app", text: v.html }] }) : { jsonrpc: "2.0", id: msg.id ?? null, error: { code: -32002, message: "no such resource" } };
|
|
24
|
+
}
|
|
25
|
+
if (msg.method === "tools/call") {
|
|
26
|
+
const tool = byName.get(String(msg.params?.name));
|
|
27
|
+
if (!tool)
|
|
28
|
+
return reply(text(`no tool ${String(msg.params?.name)}`, true));
|
|
29
|
+
let who;
|
|
30
|
+
try {
|
|
31
|
+
who = await caller();
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return reply(text(`Refused: ${e.message}.`, true));
|
|
35
|
+
}
|
|
36
|
+
if (who.kind !== "owner" && tool.roles && !tool.roles.some((r) => who.roles.includes(r)))
|
|
37
|
+
return reply(text(`Refused: ${tool.name} is for an agent with the ${tool.roles.join(" or ")} role.`, true));
|
|
38
|
+
try {
|
|
39
|
+
return reply(text(await tool.run(msg.params?.arguments ?? {}, who), false, who.kind === "owner"));
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
return reply(text(String(e.message ?? e), true));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return msg.id === undefined ? undefined : { jsonrpc: "2.0", id: msg.id, error: { code: -32601, message: "method not found" } };
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** POST /mcp with the connection's service key; false for any other path. */
|
|
49
|
+
export function serveMcp(handle, key, caller, maxBytes = 400_000) {
|
|
50
|
+
return async (req, res) => {
|
|
51
|
+
if (req.method !== "POST" || !URL.canParse(req.url ?? "/", "http://localhost") || new URL(req.url ?? "/", "http://localhost").pathname !== "/mcp")
|
|
52
|
+
return false;
|
|
53
|
+
const want = Buffer.from(key()), got = Buffer.from(String(req.headers.authorization ?? "").replace(/^Bearer\s+/i, ""));
|
|
54
|
+
if (!want.length || got.length !== want.length || !timingSafeEqual(got, want))
|
|
55
|
+
return void res.writeHead(401).end(), true;
|
|
56
|
+
let n = 0;
|
|
57
|
+
const chunks = [];
|
|
58
|
+
for await (const c of req) {
|
|
59
|
+
n += c.length;
|
|
60
|
+
if (n > maxBytes)
|
|
61
|
+
return void res.writeHead(413).end(), true;
|
|
62
|
+
chunks.push(c);
|
|
63
|
+
}
|
|
64
|
+
let msg;
|
|
65
|
+
try {
|
|
66
|
+
msg = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return void res.writeHead(400).end(), true;
|
|
70
|
+
}
|
|
71
|
+
if (!(Array.isArray(msg) ? msg : [msg]).every((m) => m && typeof m === "object" && !Array.isArray(m)))
|
|
72
|
+
return void res.writeHead(400).end(), true;
|
|
73
|
+
const who = () => caller(req);
|
|
74
|
+
const out = Array.isArray(msg) ? (await Promise.all(msg.map((m) => handle(m, who)))).filter(Boolean) : await handle(msg, who);
|
|
75
|
+
if (out === undefined)
|
|
76
|
+
return void res.writeHead(202).end(), true;
|
|
77
|
+
res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify(out));
|
|
78
|
+
return true;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** What a number setting declares: its inclusive `min` and `max`, `whole` (no fraction), `exclusiveMin` (strictly above `min`). */
|
|
2
|
+
export interface NumberBounds {
|
|
3
|
+
min?: number;
|
|
4
|
+
max?: number;
|
|
5
|
+
whole?: boolean;
|
|
6
|
+
exclusiveMin?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Whether a declaration says anything about the number (otherwise it is any number, as before). */
|
|
9
|
+
export declare const hasBounds: (b: NumberBounds | undefined) => b is NumberBounds;
|
|
10
|
+
/** Why `value` can't be this setting's number, or null when it can: a range and whole-number rule in words the owner can act on. */
|
|
11
|
+
export declare function numberProblem(value: unknown, b: NumberBounds): string | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// A number setting's declared range (module.yaml or kernel/settings.json `min`, `max`, `whole`, `exclusiveMin`): one check
|
|
2
|
+
// for the compiler (the gate: an agent writes the commit), the board (the owner's feedback as he types, before filing) and the
|
|
3
|
+
// kernel's settings change. Plain TypeScript Node runs as is (scripts/modules.ts and kernel/src/settings-change.ts import this
|
|
4
|
+
// file directly); the board holds a synced copy (scripts/sync-shared.ts). docs/design/settings-changes.md.
|
|
5
|
+
/** Whether a declaration says anything about the number (otherwise it is any number, as before). */
|
|
6
|
+
export const hasBounds = (b) => Boolean(b && (b.min !== undefined || b.max !== undefined || b.whole || b.exclusiveMin));
|
|
7
|
+
/** A bound in words: 100000 reads "100,000" (the owner's own figures, not a machine's). */
|
|
8
|
+
const bound = (n) => n.toLocaleString("en-US");
|
|
9
|
+
/** Why `value` can't be this setting's number, or null when it can: a range and whole-number rule in words the owner can act on. */
|
|
10
|
+
export function numberProblem(value, b) {
|
|
11
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
12
|
+
return "a number";
|
|
13
|
+
if (b.whole && !Number.isInteger(value))
|
|
14
|
+
return "a whole number";
|
|
15
|
+
const { min, max } = b, lo = min === undefined ? undefined : bound(min), hi = max === undefined ? undefined : bound(max);
|
|
16
|
+
if (min !== undefined && (b.exclusiveMin ? value <= min : value < min)) {
|
|
17
|
+
if (hi === undefined)
|
|
18
|
+
return b.exclusiveMin ? `a number above ${lo}` : `a number ${lo} or more`;
|
|
19
|
+
return b.exclusiveMin ? `a number above ${lo} and at most ${hi}` : `a number from ${lo} to ${hi}`;
|
|
20
|
+
}
|
|
21
|
+
if (max !== undefined && value > max) {
|
|
22
|
+
if (lo === undefined)
|
|
23
|
+
return `a number at most ${hi}`;
|
|
24
|
+
return b.exclusiveMin ? `a number above ${lo} and at most ${hi}` : `a number from ${lo} to ${hi}`;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The AI reviewer's code on a card: what it judged (model-chosen, malice only) or what code decided in its place. */
|
|
2
|
+
export declare const REVIEW_CODES: readonly ["clean", "malicious", "secret_exfiltration", "prompt_injection", "reviewer_failed", "fail_open", "files_not_shown", "instance_details", "tool_call_unreadable", "code_review_owns", "owner_veto", "shadow", "refused_by_code", "stale_head"];
|
|
3
|
+
export type ReviewCode = (typeof REVIEW_CODES)[number];
|
|
4
|
+
/** A grant refusal (kernel/src/identity.ts): the tool isn't granted, the agent lacks a role, or it has no grants at all. */
|
|
5
|
+
export declare const GRANT_CODES: readonly ["denied_not_granted", "denied_role", "denied_no_grants", "denied_unknown_caller"];
|
|
6
|
+
/** A model gateway refusal (kernel/src/gateway). */
|
|
7
|
+
export declare const GATEWAY_CODES: readonly ["cap_reached", "model_not_granted", "advisor_limit"];
|
|
8
|
+
/** A request already satisfied on its target: no card is filed (the duplicate-card guard). */
|
|
9
|
+
export declare const ALREADY_APPLIED_CODE = "already_applied";
|
|
10
|
+
export declare const REASON_CODES: readonly ["clean", "malicious", "secret_exfiltration", "prompt_injection", "reviewer_failed", "fail_open", "files_not_shown", "instance_details", "tool_call_unreadable", "code_review_owns", "owner_veto", "shadow", "refused_by_code", "stale_head", "denied_not_granted", "denied_role", "denied_no_grants", "denied_unknown_caller", "cap_reached", "model_not_granted", "advisor_limit", "already_applied"];
|
|
11
|
+
export type ReasonCode = (typeof REASON_CODES)[number];
|
|
12
|
+
/** The shape of a tier rule (tiers.mjs `rule`; also the board's deploy_app, app_run and raise_cap rules). */
|
|
13
|
+
export declare const TIER_RULE: RegExp;
|
|
14
|
+
export declare const isReviewCode: (c: unknown) => c is ReviewCode;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Reason codes: one stable word for why a write, a tool call or a model call was decided the way it was, recorded next to
|
|
2
|
+
// the prose reason so the board can show and count them. Plain `as const` lists (no TS enum): Node strips the types.
|
|
3
|
+
//
|
|
4
|
+
// Shared by the board and the kernel (the board imports @aidenhq/sdk/reason-codes);
|
|
5
|
+
// the reviewer module keeps its own list in modules/ai-reviewer/service/src/review.ts, which
|
|
6
|
+
// modules/ai-reviewer/test/review.test.ts pins to REVIEW_CODES here.
|
|
7
|
+
//
|
|
8
|
+
// A card's tier rule (kernel/src/tier.ts `rule`, or the board's own for its actions) is a reason code too: those
|
|
9
|
+
// are kebab-case words owned by the classifier, checked by shape (TIER_RULE), not listed here, so a new rule needs no edit.
|
|
10
|
+
/** The AI reviewer's code on a card: what it judged (model-chosen, malice only) or what code decided in its place. */
|
|
11
|
+
export const REVIEW_CODES = [
|
|
12
|
+
// the model's verdict: approve, or reject naming the malice
|
|
13
|
+
"clean",
|
|
14
|
+
"malicious",
|
|
15
|
+
"secret_exfiltration",
|
|
16
|
+
"prompt_injection",
|
|
17
|
+
// the review didn't finish (a call failed, timed out, refused or hit a limit): tried once more, then approved
|
|
18
|
+
"reviewer_failed",
|
|
19
|
+
"fail_open",
|
|
20
|
+
// code's own refusals before any review: the diff differs from the code host's own count of the change, a GitHub
|
|
21
|
+
// write carries the instance's hosts, addresses or paths, or a conn.tool call's arguments can't be read or shown whole
|
|
22
|
+
"files_not_shown",
|
|
23
|
+
"instance_details",
|
|
24
|
+
"tool_call_unreadable",
|
|
25
|
+
// ai_review_code skips the AI review of this push or PR (code review owns it): code approved it
|
|
26
|
+
"code_review_owns",
|
|
27
|
+
// the owner's own veto on this task: he decides
|
|
28
|
+
"owner_veto",
|
|
29
|
+
// the owner's autonomy below full: the reviewer's verdict is a note for him
|
|
30
|
+
"shadow",
|
|
31
|
+
// code refused the request at review time (the same content was already rejected as malicious): back to the agent
|
|
32
|
+
"refused_by_code",
|
|
33
|
+
// code closed the card because its head moved before review: not a verdict, and not a rejection
|
|
34
|
+
"stale_head",
|
|
35
|
+
];
|
|
36
|
+
/** A grant refusal (kernel/src/identity.ts): the tool isn't granted, the agent lacks a role, or it has no grants at all. */
|
|
37
|
+
export const GRANT_CODES = ["denied_not_granted", "denied_role", "denied_no_grants", "denied_unknown_caller"];
|
|
38
|
+
/** A model gateway refusal (kernel/src/gateway). */
|
|
39
|
+
export const GATEWAY_CODES = ["cap_reached", "model_not_granted", "advisor_limit"];
|
|
40
|
+
/** A request already satisfied on its target: no card is filed (the duplicate-card guard). */
|
|
41
|
+
export const ALREADY_APPLIED_CODE = "already_applied";
|
|
42
|
+
export const REASON_CODES = [...REVIEW_CODES, ...GRANT_CODES, ...GATEWAY_CODES, ALREADY_APPLIED_CODE];
|
|
43
|
+
/** The shape of a tier rule (tiers.mjs `rule`; also the board's deploy_app, app_run and raise_cap rules). */
|
|
44
|
+
export const TIER_RULE = /^[a-z0-9-]{1,60}$/;
|
|
45
|
+
export const isReviewCode = (c) => typeof c === "string" && REVIEW_CODES.includes(c);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** The marker that records `id` as the task a delegation was asked to be filed under. */
|
|
2
|
+
export declare const requestedParentMarker: (id: string) => string;
|
|
3
|
+
/** The requester a task's description records, without the `parentId` fallback: undefined on a task that carries none. */
|
|
4
|
+
export declare function recordedRequesterOf(t: {
|
|
5
|
+
description?: unknown;
|
|
6
|
+
} | undefined): string | undefined;
|
|
7
|
+
/** `text` with the requester marker `original` carried, first: an edit replaces the text the marker sits in, and the routing
|
|
8
|
+
* it records must outlive that. Text that itself carries a marker is stripped of it, so only `original`'s counts. */
|
|
9
|
+
export declare function withRequester(original: unknown, text: string): string;
|
|
10
|
+
/** The task a delegation was asked to be filed under: the recorded requester, else the task's `parentId`; never the task itself. */
|
|
11
|
+
export declare function requestedParentOf(t: {
|
|
12
|
+
id?: unknown;
|
|
13
|
+
parentId?: string | null;
|
|
14
|
+
description?: unknown;
|
|
15
|
+
} | undefined): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The requester of a task read from a list, where Paperclip cuts every description to 1200 characters: a row whose
|
|
18
|
+
* `descriptionTruncated` is true and carries no visible marker is read whole, so a marker the cut hid still resolves.
|
|
19
|
+
* `full` reads one task (a single-task read is never cut).
|
|
20
|
+
*
|
|
21
|
+
* A row that is cut without a marker is only a preview, so it is never decided on: if `full` cannot read the task this
|
|
22
|
+
* throws. Falling back to its `parentId` would route the task to the placed parent the cut exposed instead of the requester
|
|
23
|
+
* the marker records — a wrong delegator, a dropped notice, or (in grading) a live child left out of its batch. A caller
|
|
24
|
+
* that cannot tell retries; a caller that must answer says the read failed.
|
|
25
|
+
*/
|
|
26
|
+
export declare function requesterOfListed(t: {
|
|
27
|
+
id?: unknown;
|
|
28
|
+
parentId?: string | null;
|
|
29
|
+
description?: unknown;
|
|
30
|
+
descriptionTruncated?: unknown;
|
|
31
|
+
} | undefined, full: (id: string) => Promise<{
|
|
32
|
+
description?: unknown;
|
|
33
|
+
} | undefined>): Promise<string | undefined>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// The task a delegation asked to be filed under, when the control plane placed it somewhere else. Paperclip limits
|
|
2
|
+
// agent-created trees to parent → child: a grandchild request is not refused, the task is placed beside its requester (or,
|
|
3
|
+
// when the caller didn't authorize that placement, at the top level) and the create response says so (`parentAdjusted`),
|
|
4
|
+
// and later reads carry only the placed `parentId`. AidenHQ routes a task's delegator, its parent notices and its sibling
|
|
5
|
+
// grouping by the task that asked for it, so the paperclip-events plugin records that task in the new task's description
|
|
6
|
+
// when the two differ. Reads fall back to `parentId`, which is the requested parent whenever no placement happened: a tree
|
|
7
|
+
// that was never adjusted resolves exactly as it did before.
|
|
8
|
+
//
|
|
9
|
+
// The marker goes FIRST in the description: Paperclip cuts every description in a task list to 1200 characters
|
|
10
|
+
// (`ISSUE_LIST_DESCRIPTION_MAX_CHARS`, `descriptionTruncated`), so a marker at the end of a long brief would be invisible to
|
|
11
|
+
// the readers that scan lists. A row that is still truncated without a marker is read whole (`requesterOfListed`).
|
|
12
|
+
//
|
|
13
|
+
// The marker is in the `aidenhq:` namespace, which the plugin's text sanitiser and the task tools both quote out of any
|
|
14
|
+
// text an agent writes, so only the plugin's own write can produce one.
|
|
15
|
+
//
|
|
16
|
+
// Shared (@aidenhq/sdk/requested-parent) by the task
|
|
17
|
+
// tools, dispatch and the grading service.
|
|
18
|
+
const MARK = /<!--\s*aidenhq:requested-parent:([A-Za-z0-9_-]{1,100})\s*-->/;
|
|
19
|
+
const MARK_G = new RegExp(MARK.source, "g");
|
|
20
|
+
/** The marker that records `id` as the task a delegation was asked to be filed under. */
|
|
21
|
+
export const requestedParentMarker = (id) => `<!-- aidenhq:requested-parent:${id} -->`;
|
|
22
|
+
/** The requester a task's description records, without the `parentId` fallback: undefined on a task that carries none. */
|
|
23
|
+
export function recordedRequesterOf(t) {
|
|
24
|
+
return MARK.exec(String(t?.description ?? ""))?.[1] || undefined;
|
|
25
|
+
}
|
|
26
|
+
/** `text` with the requester marker `original` carried, first: an edit replaces the text the marker sits in, and the routing
|
|
27
|
+
* it records must outlive that. Text that itself carries a marker is stripped of it, so only `original`'s counts. */
|
|
28
|
+
export function withRequester(original, text) {
|
|
29
|
+
const had = recordedRequesterOf({ description: original });
|
|
30
|
+
const body = String(text).replace(MARK_G, "").trim();
|
|
31
|
+
return had ? `${requestedParentMarker(had)}\n\n${body}` : body;
|
|
32
|
+
}
|
|
33
|
+
/** The task a delegation was asked to be filed under: the recorded requester, else the task's `parentId`; never the task itself. */
|
|
34
|
+
export function requestedParentOf(t) {
|
|
35
|
+
const asked = recordedRequesterOf(t);
|
|
36
|
+
const parent = asked || (typeof t?.parentId === "string" && t.parentId ? t.parentId : undefined);
|
|
37
|
+
return parent && parent !== t?.id ? parent : undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The requester of a task read from a list, where Paperclip cuts every description to 1200 characters: a row whose
|
|
41
|
+
* `descriptionTruncated` is true and carries no visible marker is read whole, so a marker the cut hid still resolves.
|
|
42
|
+
* `full` reads one task (a single-task read is never cut).
|
|
43
|
+
*
|
|
44
|
+
* A row that is cut without a marker is only a preview, so it is never decided on: if `full` cannot read the task this
|
|
45
|
+
* throws. Falling back to its `parentId` would route the task to the placed parent the cut exposed instead of the requester
|
|
46
|
+
* the marker records — a wrong delegator, a dropped notice, or (in grading) a live child left out of its batch. A caller
|
|
47
|
+
* that cannot tell retries; a caller that must answer says the read failed.
|
|
48
|
+
*/
|
|
49
|
+
export async function requesterOfListed(t, full) {
|
|
50
|
+
if (t?.descriptionTruncated === true && typeof t.id === "string" && !recordedRequesterOf(t)) {
|
|
51
|
+
const whole = await full(t.id);
|
|
52
|
+
if (whole)
|
|
53
|
+
return requestedParentOf({ ...t, description: whole.description });
|
|
54
|
+
}
|
|
55
|
+
return requestedParentOf(t);
|
|
56
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare const MIN_GAP_MINUTES = 15;
|
|
2
|
+
/** The time of day a day-only schedule ("every Monday") runs at when the owner names none, in minutes: 07:00. */
|
|
3
|
+
export declare const DEFAULT_TIME: number;
|
|
4
|
+
export type Parsed = {
|
|
5
|
+
crons: string[];
|
|
6
|
+
words: string;
|
|
7
|
+
perDay: number;
|
|
8
|
+
minGapMinutes: number;
|
|
9
|
+
};
|
|
10
|
+
export type Refusal = {
|
|
11
|
+
error: string;
|
|
12
|
+
examples: [string, string];
|
|
13
|
+
};
|
|
14
|
+
export type ClockFormat = "12h" | "24h";
|
|
15
|
+
export declare const isRefusal: (r: Parsed | Refusal) => r is Refusal;
|
|
16
|
+
/** A refusal as one message that carries its examples (a tool error or a 400 is a string): "<why>. Try "<a>" or "<b>"." */
|
|
17
|
+
export declare const refusalText: (r: Refusal) => string;
|
|
18
|
+
/** "8:45 AM" (12h) or "08:45" (24h): the board's clock words (services/board/src/clock.ts), so the one formatter's output matches. */
|
|
19
|
+
export declare function clockWords(hour: number, minute: number, fmt?: ClockFormat): string;
|
|
20
|
+
/** A cron line in plain words ("weekdays 8:45 AM", "every 4h", "every 30 min, 8:00 AM to 8:59 PM"); the cron itself when it's unusual. */
|
|
21
|
+
export declare function describeCron(cron: string, fmt?: ClockFormat): string;
|
|
22
|
+
/** The smallest gap, in minutes, between the times of day a set of cron lines fires at: 0 when two lines fire at the same moment (null when one isn't a valid cron line). */
|
|
23
|
+
export declare function minGapOf(crons: string[]): number | null;
|
|
24
|
+
/**
|
|
25
|
+
* The longest gap, in minutes, between two consecutive fires of a set of cron lines (a day of the month and a weekday must both
|
|
26
|
+
* match), read over 800 days of a leap-year calendar so a monthly or yearly line shows its real gap. Infinity when a line fires
|
|
27
|
+
* fewer than twice in that time; null when one isn't a valid cron line. Without a zone, clock times only: a daylight-saving hour
|
|
28
|
+
* is not counted. With a zone, each fire is a real instant there over the 800 days from today, so the gap is elapsed time (a time
|
|
29
|
+
* a spring-forward change skips isn't fired, and a change already behind isn't counted).
|
|
30
|
+
*/
|
|
31
|
+
export declare function maxGapMinutes(crons: string[], tz?: string): number | null;
|
|
32
|
+
/**
|
|
33
|
+
* Turn English (or a five-field cron) into cron lines. `fmt` is the owner's clock format for the words. A phrase the grammar can't say
|
|
34
|
+
* exactly is refused with the reason and two examples that work.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseSchedule(text: string, fmt?: ClockFormat, opts?: {
|
|
37
|
+
defaultTime?: number;
|
|
38
|
+
}): Parsed | Refusal;
|
|
39
|
+
/**
|
|
40
|
+
* The next `count` instants after `from` a set of cron lines fires in a time zone (for a preview: the board's live runs come from Paperclip).
|
|
41
|
+
* A day of the month and a weekday must both match, as Paperclip's scheduler has it; a time a daylight-saving change skips is left out.
|
|
42
|
+
*/
|
|
43
|
+
export declare function nextRuns(crons: string[], tz: string, from: Date, count?: number): Date[];
|
|
44
|
+
/**
|
|
45
|
+
* The schedule phrase in a chat message ("please summarise my GitHub every weekday at 8" → "every weekday at 8"), or null when there
|
|
46
|
+
* is none, it follows a negation in its clause ("don't do this every day at 8"), or it sits in quotes or a `>` quote line. The
|
|
47
|
+
* longest run of words the parser accepts, starting at the first word that can begin a schedule.
|
|
48
|
+
*/
|
|
49
|
+
export declare function findSchedule(message: string, fmt?: ClockFormat): {
|
|
50
|
+
text: string;
|
|
51
|
+
parsed: Parsed;
|
|
52
|
+
} | null;
|