@agent-city/engine 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/dist/audit.d.ts +54 -0
- package/dist/audit.js +291 -0
- package/dist/audit.js.map +1 -0
- package/dist/budget.d.ts +24 -0
- package/dist/budget.js +65 -0
- package/dist/budget.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/card.d.ts +19 -0
- package/dist/integrations/card.js +99 -0
- package/dist/integrations/card.js.map +1 -0
- package/dist/integrations/config.d.ts +13 -0
- package/dist/integrations/config.js +74 -0
- package/dist/integrations/config.js.map +1 -0
- package/dist/integrations/index.d.ts +29 -0
- package/dist/integrations/index.js +181 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/lan.d.ts +24 -0
- package/dist/lan.js +103 -0
- package/dist/lan.js.map +1 -0
- package/dist/learning.d.ts +73 -0
- package/dist/learning.js +261 -0
- package/dist/learning.js.map +1 -0
- package/dist/lessons.d.ts +17 -0
- package/dist/lessons.js +87 -0
- package/dist/lessons.js.map +1 -0
- package/dist/loops.d.ts +16 -0
- package/dist/loops.js +75 -0
- package/dist/loops.js.map +1 -0
- package/dist/mobile-page.d.ts +6 -0
- package/dist/mobile-page.js +146 -0
- package/dist/mobile-page.js.map +1 -0
- package/dist/mobile.d.ts +40 -0
- package/dist/mobile.js +67 -0
- package/dist/mobile.js.map +1 -0
- package/dist/packs.d.ts +47 -0
- package/dist/packs.js +103 -0
- package/dist/packs.js.map +1 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +7 -0
- package/dist/paths.js.map +1 -0
- package/dist/policies.d.ts +21 -0
- package/dist/policies.js +126 -0
- package/dist/policies.js.map +1 -0
- package/dist/search.d.ts +8 -0
- package/dist/search.js +46 -0
- package/dist/search.js.map +1 -0
- package/dist/server.d.ts +47 -0
- package/dist/server.js +921 -0
- package/dist/server.js.map +1 -0
- package/dist/slack.d.ts +62 -0
- package/dist/slack.js +214 -0
- package/dist/slack.js.map +1 -0
- package/dist/snapshots.d.ts +39 -0
- package/dist/snapshots.js +265 -0
- package/dist/snapshots.js.map +1 -0
- package/dist/sqlite.d.ts +17 -0
- package/dist/sqlite.js +57 -0
- package/dist/sqlite.js.map +1 -0
- package/dist/store.d.ts +22 -0
- package/dist/store.js +114 -0
- package/dist/store.js.map +1 -0
- package/dist/sync.d.ts +38 -0
- package/dist/sync.js +173 -0
- package/dist/sync.js.map +1 -0
- package/dist/team.d.ts +62 -0
- package/dist/team.js +245 -0
- package/dist/team.js.map +1 -0
- package/dist/timetravel.d.ts +37 -0
- package/dist/timetravel.js +178 -0
- package/dist/timetravel.js.map +1 -0
- package/dist/usage.d.ts +28 -0
- package/dist/usage.js +114 -0
- package/dist/usage.js.map +1 -0
- package/dist/verify.d.ts +41 -0
- package/dist/verify.js +73 -0
- package/dist/verify.js.map +1 -0
- package/package.json +43 -3
- package/README.md +0 -3
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained phone page for remote approvals (no external resources; CSP nonce placeholder __NONCE__).
|
|
3
|
+
* The token arrives in the #t= fragment, is kept in sessionStorage and removed from the address bar.
|
|
4
|
+
* Data from the engine is rendered with textContent only.
|
|
5
|
+
*/
|
|
6
|
+
export const MOBILE_PAGE = `<!DOCTYPE html>
|
|
7
|
+
<html lang="es">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="utf-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
11
|
+
<meta name="referrer" content="no-referrer">
|
|
12
|
+
<title>AgentCity · Aprobaciones</title>
|
|
13
|
+
<style nonce="__NONCE__">
|
|
14
|
+
:root{color-scheme:dark;--bg:#0b1020;--card:#141b31;--ink:#e8ecf7;--mute:#97a0bd;--line:#243052;--ok:#1f9d55;--no:#d64545;--warn:#f2b84b}
|
|
15
|
+
*{box-sizing:border-box}
|
|
16
|
+
body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.5 system-ui,-apple-system,Segoe UI,Roboto,sans-serif;padding:16px;padding-bottom:40px}
|
|
17
|
+
header{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:16px}
|
|
18
|
+
h1{font-size:20px;margin:0}
|
|
19
|
+
#status{font-size:13px;color:var(--mute)}
|
|
20
|
+
#status.bad{color:var(--warn)}
|
|
21
|
+
.empty{color:var(--mute);text-align:center;padding:48px 8px;border:1px dashed var(--line);border-radius:14px}
|
|
22
|
+
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:14px;margin-bottom:14px}
|
|
23
|
+
.meta{font-size:13px;color:var(--mute);display:flex;flex-wrap:wrap;gap:4px 12px}
|
|
24
|
+
.action{font-size:18px;font-weight:600;margin:6px 0 4px}
|
|
25
|
+
.target{font:14px/1.4 ui-monospace,Consolas,monospace;background:#0b1226;border-radius:8px;padding:8px;overflow-wrap:anywhere;white-space:pre-wrap;max-height:160px;overflow:auto}
|
|
26
|
+
.reason{font-size:14px;color:var(--warn);margin-top:6px}
|
|
27
|
+
.row{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:12px}
|
|
28
|
+
button{min-height:52px;border:0;border-radius:12px;font-size:17px;font-weight:600;color:#fff;cursor:pointer}
|
|
29
|
+
button:focus-visible{outline:3px solid #fff;outline-offset:2px}
|
|
30
|
+
button:disabled{opacity:.5}
|
|
31
|
+
.allow{background:var(--ok)}.deny{background:var(--no)}
|
|
32
|
+
.note{font-size:12px;color:var(--mute);margin-top:24px}
|
|
33
|
+
</style>
|
|
34
|
+
</head>
|
|
35
|
+
<body>
|
|
36
|
+
<header><h1 id="title">Aprobaciones</h1><span id="status" role="status"></span></header>
|
|
37
|
+
<main id="list" aria-live="polite"></main>
|
|
38
|
+
<p class="note" id="note"></p>
|
|
39
|
+
<script nonce="__NONCE__">
|
|
40
|
+
{
|
|
41
|
+
const es = !/^en/i.test(navigator.language || '');
|
|
42
|
+
const T = es ? {
|
|
43
|
+
title: 'Aprobaciones', empty: 'Nada pendiente. Esta página se actualiza sola.', allow: 'Permitir', deny: 'Denegar',
|
|
44
|
+
live: 'Conectado', offline: 'Sin conexión con AgentCity', unauthorized: 'Enlace no válido o caducado: vuelve a escanear el QR.',
|
|
45
|
+
locked: 'Demasiados intentos. Espera un minuto.', gone: 'Ya se decidió o caducó.',
|
|
46
|
+
note: 'Solo ves acciones que esperan tu decisión. Nada de esto sale de tu red local.',
|
|
47
|
+
reasons: { 'the agent explicitly requested human approval': 'El agente pidió aprobación humana explícitamente.' }
|
|
48
|
+
} : {
|
|
49
|
+
title: 'Approvals', empty: 'Nothing pending. This page refreshes by itself.', allow: 'Allow', deny: 'Deny',
|
|
50
|
+
live: 'Connected', offline: 'Cannot reach AgentCity', unauthorized: 'Invalid or expired link: scan the QR code again.',
|
|
51
|
+
locked: 'Too many attempts. Wait a minute.', gone: 'Already decided or expired.',
|
|
52
|
+
note: 'You only see actions waiting for your decision. Nothing here leaves your local network.',
|
|
53
|
+
reasons: {}
|
|
54
|
+
};
|
|
55
|
+
document.documentElement.lang = es ? 'es' : 'en';
|
|
56
|
+
document.title = 'AgentCity · ' + T.title;
|
|
57
|
+
document.getElementById('title').textContent = T.title;
|
|
58
|
+
document.getElementById('note').textContent = T.note;
|
|
59
|
+
|
|
60
|
+
const m = location.hash.match(/[#&]t=([A-Za-z0-9_-]+)/);
|
|
61
|
+
let token = '';
|
|
62
|
+
try {
|
|
63
|
+
if (m) sessionStorage.setItem('agentcity-token', m[1]);
|
|
64
|
+
token = (m && m[1]) || sessionStorage.getItem('agentcity-token') || '';
|
|
65
|
+
} catch { token = (m && m[1]) || ''; }
|
|
66
|
+
if (m) history.replaceState(null, '', location.pathname);
|
|
67
|
+
|
|
68
|
+
const list = document.getElementById('list');
|
|
69
|
+
const status = document.getElementById('status');
|
|
70
|
+
const busy = new Set();
|
|
71
|
+
let stopped = false;
|
|
72
|
+
let offline = false;
|
|
73
|
+
let last = [];
|
|
74
|
+
|
|
75
|
+
const setStatus = (text, bad) => { status.textContent = text; status.className = bad ? 'bad' : ''; };
|
|
76
|
+
const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; };
|
|
77
|
+
const api = (path, init) => fetch(path, Object.assign({}, init, {
|
|
78
|
+
headers: Object.assign({ authorization: 'Bearer ' + token, 'content-type': 'application/json' }, (init && init.headers) || {}),
|
|
79
|
+
cache: 'no-store'
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
const render = (items) => {
|
|
83
|
+
list.replaceChildren();
|
|
84
|
+
if (!items.length) { list.append(el('div', 'empty', T.empty)); return; }
|
|
85
|
+
for (const a of items) {
|
|
86
|
+
const card = el('article', 'card');
|
|
87
|
+
const meta = el('div', 'meta');
|
|
88
|
+
meta.append(el('span', '', a.tool), el('span', '', a.project || ''), el('span', '', new Date(a.createdAt).toLocaleTimeString()));
|
|
89
|
+
card.append(meta, el('div', 'action', a.action || a.category || '?'));
|
|
90
|
+
if (a.target) card.append(el('div', 'target', a.target));
|
|
91
|
+
if (a.reason) card.append(el('div', 'reason', T.reasons[a.reason] || a.reason));
|
|
92
|
+
const row = el('div', 'row');
|
|
93
|
+
for (const d of ['allow', 'deny']) {
|
|
94
|
+
const b = el('button', d, T[d]);
|
|
95
|
+
b.type = 'button';
|
|
96
|
+
b.disabled = busy.has(a.requestId) || offline;
|
|
97
|
+
b.addEventListener('click', () => decide(a.requestId, d));
|
|
98
|
+
row.append(b);
|
|
99
|
+
}
|
|
100
|
+
card.append(row);
|
|
101
|
+
list.append(card);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const handle = (r) => {
|
|
106
|
+
if (r.status === 401) { stopped = true; setStatus(T.unauthorized, true); list.replaceChildren(); return false; }
|
|
107
|
+
if (r.status === 429) { setStatus(T.locked, true); return false; }
|
|
108
|
+
return true;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const refresh = async () => {
|
|
112
|
+
if (stopped) return;
|
|
113
|
+
try {
|
|
114
|
+
const r = await api('/api/approvals');
|
|
115
|
+
if (!handle(r)) return;
|
|
116
|
+
last = await r.json();
|
|
117
|
+
offline = false;
|
|
118
|
+
render(last);
|
|
119
|
+
setStatus(T.live, false);
|
|
120
|
+
} catch {
|
|
121
|
+
// keep the last list visible but never let a stale card be decided
|
|
122
|
+
offline = true;
|
|
123
|
+
render(last);
|
|
124
|
+
setStatus(T.offline, true);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const decide = async (id, decision) => {
|
|
129
|
+
busy.add(id);
|
|
130
|
+
try {
|
|
131
|
+
const r = await api('/api/approvals/' + encodeURIComponent(id), { method: 'POST', body: JSON.stringify({ decision }) });
|
|
132
|
+
if (handle(r) && r.status === 404) setStatus(T.gone, true);
|
|
133
|
+
} catch { setStatus(T.offline, true); }
|
|
134
|
+
busy.delete(id);
|
|
135
|
+
refresh();
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
if (!token) { stopped = true; setStatus(T.unauthorized, true); }
|
|
139
|
+
refresh();
|
|
140
|
+
setInterval(refresh, 2000);
|
|
141
|
+
}
|
|
142
|
+
</script>
|
|
143
|
+
</body>
|
|
144
|
+
</html>
|
|
145
|
+
`;
|
|
146
|
+
//# sourceMappingURL=mobile-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobile-page.js","sourceRoot":"","sources":["../src/mobile-page.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2I1B,CAAC"}
|
package/dist/mobile.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ApprovalDecision, type PendingApproval } from '@agent-city/spec';
|
|
2
|
+
import { lanAddresses } from './lan.js';
|
|
3
|
+
export { lanAddresses };
|
|
4
|
+
/**
|
|
5
|
+
* Opt-in approval page for a phone on the same network.
|
|
6
|
+
*
|
|
7
|
+
* A separate listener from the engine (which stays on 127.0.0.1). It exposes ONLY the list of pending
|
|
8
|
+
* approvals (reduced and redacted) and the allow/deny decision: no events, memory, policies or hooks.
|
|
9
|
+
* Every API call needs the per-start token, which travels in the QR link's #fragment (never in a URL
|
|
10
|
+
* the server logs or a Referer). Repeated bad tokens lock out the offending client for a while.
|
|
11
|
+
*/
|
|
12
|
+
export type MobileOptions = {
|
|
13
|
+
/** Port for the phone page. Default 0 (any free port). */
|
|
14
|
+
port?: number;
|
|
15
|
+
/** Interface to bind. Default 0.0.0.0 (all; the token protects every API call). */
|
|
16
|
+
host?: string;
|
|
17
|
+
/** Fixed token (tests). Default: 32 random bytes, new on every start. */
|
|
18
|
+
token?: string;
|
|
19
|
+
};
|
|
20
|
+
export type MobileApproval = {
|
|
21
|
+
requestId: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
tool: string;
|
|
24
|
+
action?: string;
|
|
25
|
+
target?: string;
|
|
26
|
+
category?: string;
|
|
27
|
+
project?: string;
|
|
28
|
+
reason?: string;
|
|
29
|
+
};
|
|
30
|
+
export type MobileHandle = {
|
|
31
|
+
port: number;
|
|
32
|
+
token: string;
|
|
33
|
+
urls: string[];
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
export declare function toMobileApproval(a: PendingApproval): MobileApproval;
|
|
37
|
+
export declare function startMobileApprovals(deps: {
|
|
38
|
+
list: () => PendingApproval[];
|
|
39
|
+
decide: (requestId: string, d: ApprovalDecision) => boolean;
|
|
40
|
+
}, opts?: MobileOptions): Promise<MobileHandle>;
|
package/dist/mobile.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { redactSecrets } from '@agent-city/spec';
|
|
4
|
+
import { MOBILE_PAGE } from './mobile-page.js';
|
|
5
|
+
import { closeServer, createLanGuard, hardenServer, lanAddresses, listenOn, newLanToken, readSmallJson, sendJson, setSafeHeaders, } from './lan.js';
|
|
6
|
+
export { lanAddresses };
|
|
7
|
+
export function toMobileApproval(a) {
|
|
8
|
+
const ev = a.event;
|
|
9
|
+
const clip = (s, n) => (s ? redactSecrets(s).slice(0, n) : undefined);
|
|
10
|
+
return {
|
|
11
|
+
requestId: a.requestId,
|
|
12
|
+
createdAt: a.createdAt,
|
|
13
|
+
tool: clip(ev.source.tool, 40) ?? '?',
|
|
14
|
+
...(ev.step?.action ? { action: clip(ev.step.action, 80) } : {}),
|
|
15
|
+
...(ev.step?.target ? { target: clip(ev.step.target, 500) } : {}),
|
|
16
|
+
...(ev.step?.category ? { category: ev.step.category } : {}),
|
|
17
|
+
...(ev.session.project ? { project: clip(ev.session.project, 80) } : {}),
|
|
18
|
+
...(a.reason ? { reason: clip(a.reason, 200) } : {}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export async function startMobileApprovals(deps, opts = {}) {
|
|
22
|
+
const token = opts.token ?? newLanToken();
|
|
23
|
+
const guard = createLanGuard(token);
|
|
24
|
+
const server = http.createServer((req, res) => {
|
|
25
|
+
void (async () => {
|
|
26
|
+
setSafeHeaders(res);
|
|
27
|
+
const p = new URL(req.url ?? '/', 'http://x').pathname;
|
|
28
|
+
const m = req.method ?? 'GET';
|
|
29
|
+
if (m === 'GET' && p === '/') {
|
|
30
|
+
const nonce = randomBytes(16).toString('base64');
|
|
31
|
+
res.writeHead(200, {
|
|
32
|
+
'content-type': 'text/html; charset=utf-8',
|
|
33
|
+
'cache-control': 'no-store',
|
|
34
|
+
'content-security-policy': `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'nonce-${nonce}'; connect-src 'self'; img-src data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`,
|
|
35
|
+
});
|
|
36
|
+
return res.end(MOBILE_PAGE.replaceAll('__NONCE__', nonce));
|
|
37
|
+
}
|
|
38
|
+
if (!p.startsWith('/api/'))
|
|
39
|
+
return sendJson(res, 404, { error: 'not found' });
|
|
40
|
+
const denied = guard.check(req);
|
|
41
|
+
if (denied)
|
|
42
|
+
return sendJson(res, denied, { error: denied === 429 ? 'too many attempts' : 'unauthorized' });
|
|
43
|
+
if (m === 'GET' && p === '/api/approvals')
|
|
44
|
+
return sendJson(res, 200, deps.list().map(toMobileApproval));
|
|
45
|
+
const mm = p.match(/^\/api\/approvals\/([A-Za-z0-9_.:-]{1,128})$/);
|
|
46
|
+
if (m === 'POST' && mm) {
|
|
47
|
+
const body = (await readSmallJson(req));
|
|
48
|
+
const decision = body?.decision;
|
|
49
|
+
if (decision !== 'allow' && decision !== 'deny')
|
|
50
|
+
return sendJson(res, 400, { error: 'invalid decision' });
|
|
51
|
+
if (!deps.decide(mm[1], { decision, by: 'mobile' }))
|
|
52
|
+
return sendJson(res, 404, { error: 'approval not found' });
|
|
53
|
+
return sendJson(res, 200, { ok: true });
|
|
54
|
+
}
|
|
55
|
+
return sendJson(res, 404, { error: 'not found' });
|
|
56
|
+
})().catch(() => { if (!res.headersSent)
|
|
57
|
+
sendJson(res, 500, { error: 'internal error' });
|
|
58
|
+
else
|
|
59
|
+
res.end(); });
|
|
60
|
+
});
|
|
61
|
+
hardenServer(server);
|
|
62
|
+
const host = opts.host ?? '0.0.0.0';
|
|
63
|
+
const port = await listenOn(server, opts.port ?? 0, host);
|
|
64
|
+
const hosts = host === '0.0.0.0' ? lanAddresses() : [host];
|
|
65
|
+
return { port, token, urls: hosts.map((h) => `http://${h}:${port}/#t=${token}`), close: () => closeServer(server) };
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=mobile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobile.js","sourceRoot":"","sources":["../src/m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ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Policy } from '@agent-city/spec';
|
|
2
|
+
/**
|
|
3
|
+
* Marketplace packs (opt-in, local files in ~/.agentcity/packs/<id>.json).
|
|
4
|
+
*
|
|
5
|
+
* - `policies` packs can only TIGHTEN control: every policy must be `deny` or `ask`, and pack policies are
|
|
6
|
+
* evaluated AFTER the user's own policies. A third-party pack can never allow what the user blocks.
|
|
7
|
+
* - `theme` packs carry a city theme (open theme format, shared with ui-core). The engine only checks size and
|
|
8
|
+
* shape; the web UI validates the theme fully before using it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const PACK_FORMAT = 1;
|
|
11
|
+
export declare const MAX_PACK_BYTES: number;
|
|
12
|
+
/** Same id rule as ui-core custom themes, minus built-in ids. */
|
|
13
|
+
export declare const THEME_ID_RE: RegExp;
|
|
14
|
+
export declare const BUILTIN_THEME_IDS: readonly ["pueblo", "neon", "isla", "invierno"];
|
|
15
|
+
export type PackKind = 'policies' | 'theme';
|
|
16
|
+
export type Pack = {
|
|
17
|
+
agentcityPack: typeof PACK_FORMAT;
|
|
18
|
+
kind: PackKind;
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
version: string;
|
|
22
|
+
description: string;
|
|
23
|
+
author?: string;
|
|
24
|
+
license?: string;
|
|
25
|
+
policies?: Policy[];
|
|
26
|
+
theme?: Record<string, unknown> & {
|
|
27
|
+
id: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export type PackSummary = Pick<Pack, 'kind' | 'id' | 'name' | 'version' | 'description' | 'author' | 'license'> & {
|
|
31
|
+
items: number;
|
|
32
|
+
};
|
|
33
|
+
/** Returns an error message, or null when `v` is a well-formed pack. */
|
|
34
|
+
export declare function validatePack(v: unknown): string | null;
|
|
35
|
+
export declare const summarizePack: (p: Pack) => PackSummary;
|
|
36
|
+
export declare const packsDir: (home: string) => string;
|
|
37
|
+
export type LoadedPacks = {
|
|
38
|
+
packs: PackSummary[];
|
|
39
|
+
/** Pack policies, ids prefixed `pack:<packId>:`; evaluated after the user's policies. */
|
|
40
|
+
policies: Policy[];
|
|
41
|
+
themes: Pack['theme'][];
|
|
42
|
+
invalid: {
|
|
43
|
+
file: string;
|
|
44
|
+
error: string;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
47
|
+
export declare function loadPacks(home: string): LoadedPacks;
|
package/dist/packs.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isPolicyArray } from './policies.js';
|
|
4
|
+
/**
|
|
5
|
+
* Marketplace packs (opt-in, local files in ~/.agentcity/packs/<id>.json).
|
|
6
|
+
*
|
|
7
|
+
* - `policies` packs can only TIGHTEN control: every policy must be `deny` or `ask`, and pack policies are
|
|
8
|
+
* evaluated AFTER the user's own policies. A third-party pack can never allow what the user blocks.
|
|
9
|
+
* - `theme` packs carry a city theme (open theme format, shared with ui-core). The engine only checks size and
|
|
10
|
+
* shape; the web UI validates the theme fully before using it.
|
|
11
|
+
*/
|
|
12
|
+
export const PACK_FORMAT = 1;
|
|
13
|
+
export const MAX_PACK_BYTES = 256 * 1024;
|
|
14
|
+
const MAX_PACK_POLICIES = 100;
|
|
15
|
+
const ID_RE = /^[a-z0-9][a-z0-9-]{1,47}$/;
|
|
16
|
+
/** Same id rule as ui-core custom themes, minus built-in ids. */
|
|
17
|
+
export const THEME_ID_RE = /^[a-z0-9][a-z0-9-]{1,40}$/;
|
|
18
|
+
export const BUILTIN_THEME_IDS = ['pueblo', 'neon', 'isla', 'invierno'];
|
|
19
|
+
const VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
20
|
+
const str = (v, max) => typeof v === 'string' && v.trim().length > 0 && v.length <= max;
|
|
21
|
+
/** Returns an error message, or null when `v` is a well-formed pack. */
|
|
22
|
+
export function validatePack(v) {
|
|
23
|
+
if (!v || typeof v !== 'object' || Array.isArray(v))
|
|
24
|
+
return 'a pack must be a JSON object';
|
|
25
|
+
const p = v;
|
|
26
|
+
if (p.agentcityPack !== PACK_FORMAT)
|
|
27
|
+
return `agentcityPack must be ${PACK_FORMAT}`;
|
|
28
|
+
if (!str(p.id, 48) || !ID_RE.test(p.id))
|
|
29
|
+
return 'id must be lowercase letters, digits and dashes (2-48)';
|
|
30
|
+
if (!str(p.name, 80))
|
|
31
|
+
return 'name is required (max 80)';
|
|
32
|
+
if (!str(p.version, 20) || !VERSION_RE.test(p.version))
|
|
33
|
+
return 'version must look like 1.0.0';
|
|
34
|
+
if (!str(p.description, 300))
|
|
35
|
+
return 'description is required (max 300)';
|
|
36
|
+
for (const k of ['author', 'license'])
|
|
37
|
+
if (p[k] !== undefined && !str(p[k], 80))
|
|
38
|
+
return `${k} must be a short string`;
|
|
39
|
+
if (p.kind === 'policies') {
|
|
40
|
+
if (!isPolicyArray(p.policies) || p.policies.length === 0 || p.policies.length > MAX_PACK_POLICIES) {
|
|
41
|
+
return `policies must be 1-${MAX_PACK_POLICIES} valid policies`;
|
|
42
|
+
}
|
|
43
|
+
const loose = p.policies.find((x) => x.decision === 'allow');
|
|
44
|
+
if (loose)
|
|
45
|
+
return `policy ${loose.id}: packs may only deny or ask (they can never loosen your control)`;
|
|
46
|
+
if (p.theme !== undefined)
|
|
47
|
+
return 'a policies pack cannot carry a theme';
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (p.kind === 'theme') {
|
|
51
|
+
const t = p.theme;
|
|
52
|
+
if (!t || typeof t !== 'object' || Array.isArray(t) || !str(t.id, 41) || !THEME_ID_RE.test(t.id))
|
|
53
|
+
return 'theme must be an object with a valid id (2-41 chars)';
|
|
54
|
+
if (BUILTIN_THEME_IDS.includes(t.id))
|
|
55
|
+
return 'a pack cannot replace a built-in theme';
|
|
56
|
+
if (p.policies !== undefined)
|
|
57
|
+
return 'a theme pack cannot carry policies';
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return "kind must be 'policies' or 'theme'";
|
|
61
|
+
}
|
|
62
|
+
export const summarizePack = (p) => ({
|
|
63
|
+
kind: p.kind, id: p.id, name: p.name, version: p.version, description: p.description,
|
|
64
|
+
...(p.author ? { author: p.author } : {}), ...(p.license ? { license: p.license } : {}),
|
|
65
|
+
items: p.kind === 'policies' ? p.policies.length : 1,
|
|
66
|
+
});
|
|
67
|
+
export const packsDir = (home) => path.join(home, 'packs');
|
|
68
|
+
export function loadPacks(home) {
|
|
69
|
+
const out = { packs: [], policies: [], themes: [], invalid: [] };
|
|
70
|
+
let files = [];
|
|
71
|
+
try {
|
|
72
|
+
files = fs.readdirSync(packsDir(home)).filter((f) => f.endsWith('.json')).sort();
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
for (const file of files) {
|
|
78
|
+
const full = path.join(packsDir(home), file);
|
|
79
|
+
try {
|
|
80
|
+
if (!fs.lstatSync(full).isFile())
|
|
81
|
+
throw new Error('not a regular file');
|
|
82
|
+
const bytes = fs.readFileSync(full);
|
|
83
|
+
if (bytes.length > MAX_PACK_BYTES)
|
|
84
|
+
throw new Error(`larger than ${MAX_PACK_BYTES} bytes`);
|
|
85
|
+
const p = JSON.parse(bytes.toString('utf8'));
|
|
86
|
+
const err = validatePack(p);
|
|
87
|
+
if (err)
|
|
88
|
+
throw new Error(err);
|
|
89
|
+
if (`${p.id}.json` !== file)
|
|
90
|
+
throw new Error(`file name must be ${p.id}.json`);
|
|
91
|
+
out.packs.push(summarizePack(p));
|
|
92
|
+
if (p.kind === 'policies')
|
|
93
|
+
out.policies.push(...p.policies.map((x) => ({ ...x, id: `pack:${p.id}:${x.id}` })));
|
|
94
|
+
else
|
|
95
|
+
out.themes.push(p.theme);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
out.invalid.push({ file, error: e.message });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL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C9B,IAAI,GAAG,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAC/E,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU;gBAAE,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;;gBAC3G,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAG,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/paths.d.ts
ADDED
package/dist/paths.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/** Root of local data: AGENTCITY_HOME or ~/.agentcity. */
|
|
4
|
+
export function agentcityHome(override) {
|
|
5
|
+
return override ?? process.env.AGENTCITY_HOME ?? path.join(os.homedir(), '.agentcity');
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,0DAA0D;AAC1D,MAAM,UAAU,aAAa,CAAC,QAAiB;IAC7C,OAAO,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AgentEvent, Policy, PolicyAction } from '@agent-city/spec';
|
|
2
|
+
/** Built-in policies: ask before writing/executing on secrets or running destructive commands; allow the rest. */
|
|
3
|
+
export declare function defaultPolicies(): Policy[];
|
|
4
|
+
export type PolicyResult = {
|
|
5
|
+
decision: PolicyAction;
|
|
6
|
+
policyId?: string;
|
|
7
|
+
};
|
|
8
|
+
export type PolicyEngine = {
|
|
9
|
+
evaluate(event: AgentEvent): PolicyResult;
|
|
10
|
+
list(): Policy[];
|
|
11
|
+
set(policies: Policy[]): void;
|
|
12
|
+
};
|
|
13
|
+
/** Max length of a user-supplied regex; longer patterns make the policy invalid (ReDoS guard). */
|
|
14
|
+
export declare const MAX_PATTERN_LENGTH = 500;
|
|
15
|
+
/** Values are truncated to this length before matching (ReDoS guard). */
|
|
16
|
+
export declare const MAX_MATCH_INPUT = 4096;
|
|
17
|
+
/** First enabled policy whose action/category/target regexes all match wins; no match = allow. */
|
|
18
|
+
export declare function createPolicyEngine(initial?: Policy[]): PolicyEngine;
|
|
19
|
+
export declare function isPolicyArray(v: unknown): v is Policy[];
|
|
20
|
+
export declare function loadPolicies(home: string): Policy[];
|
|
21
|
+
export declare function savePolicies(home: string, policies: Policy[]): void;
|
package/dist/policies.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
const SECRET_PATH_RE = String.raw `(^|[\s\\/"'=])(\.env(\.(?!example\b|sample\b|template\b)[\w.-]+)?|[\w.-]+\.(pem|key|p12|pfx)|id_(rsa|ed25519|ecdsa|dsa)|credentials(\.json)?)($|[\s"';|&>)])`;
|
|
4
|
+
const DANGEROUS_CMD_RE = [
|
|
5
|
+
String.raw `\brm\s+(-[a-z]*r[a-z]*f|-[a-z]*f[a-z]*r|-r\s+-f|-f\s+-r|--recursive\s+--force|--force\s+--recursive)\b`,
|
|
6
|
+
String.raw `\bgit\s+push\b.*(--force\b|--force-with-lease\b|\s-f\b)`,
|
|
7
|
+
String.raw `\bgit\s+reset\s+--hard\b`,
|
|
8
|
+
String.raw `\bgit\s+clean\s+-[a-z]*f`,
|
|
9
|
+
String.raw `\bdrop\s+(table|database|schema)\b`,
|
|
10
|
+
String.raw `\btruncate\s+table\b`,
|
|
11
|
+
String.raw `\bmkfs(\.\w+)?\b`,
|
|
12
|
+
String.raw `\bdd\s+if=`,
|
|
13
|
+
String.raw `:\(\)\s*\{\s*:\|:&\s*\};:`,
|
|
14
|
+
String.raw `\bchmod\s+-R\s+777\b`,
|
|
15
|
+
String.raw `\bremove-item\b.*-recurse\b.*-force\b|\bremove-item\b.*-force\b.*-recurse\b`,
|
|
16
|
+
String.raw `\b(rd|rmdir)\s+/s\b`,
|
|
17
|
+
String.raw `\bformat\s+[a-z]:`,
|
|
18
|
+
].join('|');
|
|
19
|
+
/** Built-in policies: ask before writing/executing on secrets or running destructive commands; allow the rest. */
|
|
20
|
+
export function defaultPolicies() {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
id: 'ask-secret-paths',
|
|
24
|
+
description: 'Ask before writing or executing on secret files (.env, keys, credentials)',
|
|
25
|
+
category: '^(write|execute|test)$',
|
|
26
|
+
target: SECRET_PATH_RE,
|
|
27
|
+
decision: 'ask',
|
|
28
|
+
enabled: true,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'ask-dangerous-commands',
|
|
32
|
+
description: 'Ask before destructive commands (rm -rf, git push --force, drop table...)',
|
|
33
|
+
category: '^(write|execute|test)$',
|
|
34
|
+
target: DANGEROUS_CMD_RE,
|
|
35
|
+
decision: 'ask',
|
|
36
|
+
enabled: true,
|
|
37
|
+
},
|
|
38
|
+
{ id: 'default-allow', description: 'Allow everything else', decision: 'allow', enabled: true },
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
/** Max length of a user-supplied regex; longer patterns make the policy invalid (ReDoS guard). */
|
|
42
|
+
export const MAX_PATTERN_LENGTH = 500;
|
|
43
|
+
/** Values are truncated to this length before matching (ReDoS guard). */
|
|
44
|
+
export const MAX_MATCH_INPUT = 4096;
|
|
45
|
+
function compile(src) {
|
|
46
|
+
if (src === undefined || src === '')
|
|
47
|
+
return undefined;
|
|
48
|
+
if (src.length > MAX_PATTERN_LENGTH)
|
|
49
|
+
return null; // too long: never matches
|
|
50
|
+
try {
|
|
51
|
+
return new RegExp(src, 'i');
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null; // invalid regex never matches
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function matches(re, value) {
|
|
58
|
+
if (re === undefined)
|
|
59
|
+
return true;
|
|
60
|
+
if (re === null || value === undefined)
|
|
61
|
+
return false;
|
|
62
|
+
return re.test(value.length > MAX_MATCH_INPUT ? value.slice(0, MAX_MATCH_INPUT) : value);
|
|
63
|
+
}
|
|
64
|
+
/** First enabled policy whose action/category/target regexes all match wins; no match = allow. */
|
|
65
|
+
export function createPolicyEngine(initial = defaultPolicies()) {
|
|
66
|
+
let compiled = [];
|
|
67
|
+
let policies = [];
|
|
68
|
+
const set = (ps) => {
|
|
69
|
+
policies = ps.map((p) => ({ ...p }));
|
|
70
|
+
compiled = policies.map((p) => ({ p, action: compile(p.action), category: compile(p.category), target: compile(p.target) }));
|
|
71
|
+
};
|
|
72
|
+
set(initial);
|
|
73
|
+
return {
|
|
74
|
+
evaluate(event) {
|
|
75
|
+
const step = event.step;
|
|
76
|
+
for (const c of compiled) {
|
|
77
|
+
if (c.p.enabled === false)
|
|
78
|
+
continue;
|
|
79
|
+
if (!matches(c.action, step?.action))
|
|
80
|
+
continue;
|
|
81
|
+
if (!matches(c.category, step?.category))
|
|
82
|
+
continue;
|
|
83
|
+
if (!matches(c.target, step?.target ?? step?.summary))
|
|
84
|
+
continue;
|
|
85
|
+
return { decision: c.p.decision, policyId: c.p.id };
|
|
86
|
+
}
|
|
87
|
+
return { decision: 'allow' };
|
|
88
|
+
},
|
|
89
|
+
list: () => policies.map((p) => ({ ...p })),
|
|
90
|
+
set,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const VALID = ['allow', 'deny', 'ask'];
|
|
94
|
+
export function isPolicyArray(v) {
|
|
95
|
+
return (Array.isArray(v) &&
|
|
96
|
+
v.every((p) => {
|
|
97
|
+
if (!p || typeof p !== 'object')
|
|
98
|
+
return false;
|
|
99
|
+
const o = p;
|
|
100
|
+
return typeof o.id === 'string' && VALID.includes(o.decision) &&
|
|
101
|
+
['action', 'category', 'target', 'description'].every((k) => o[k] === undefined || typeof o[k] === 'string') &&
|
|
102
|
+
['action', 'category', 'target'].every((k) => o[k] === undefined || o[k].length <= MAX_PATTERN_LENGTH) &&
|
|
103
|
+
(o.enabled === undefined || typeof o.enabled === 'boolean');
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
function readConfig(file) {
|
|
107
|
+
try {
|
|
108
|
+
const v = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
109
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? v : {};
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function loadPolicies(home) {
|
|
116
|
+
const cfg = readConfig(path.join(home, 'config.json'));
|
|
117
|
+
return isPolicyArray(cfg.policies) ? cfg.policies : defaultPolicies();
|
|
118
|
+
}
|
|
119
|
+
export function savePolicies(home, policies) {
|
|
120
|
+
const file = path.join(home, 'config.json');
|
|
121
|
+
const cfg = readConfig(file);
|
|
122
|
+
cfg.policies = policies;
|
|
123
|
+
fs.mkdirSync(home, { recursive: true });
|
|
124
|
+
fs.writeFileSync(file, JSON.stringify(cfg, null, 2));
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=policies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policies.js","sourceRoot":"","sources":["../src/policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,cAAc,GAClB,MAAM,CAAC,GAAG,CAAA,8JAA8J,CAAC;AAE3K,MAAM,gBAAgB,GAAG;IACvB,MAAM,CAAC,GAAG,CAAA,wGAAwG;IAClH,MAAM,CAAC,GAAG,CAAA,yDAAyD;IACnE,MAAM,CAAC,GAAG,CAAA,0BAA0B;IACpC,MAAM,CAAC,GAAG,CAAA,0BAA0B;IACpC,MAAM,CAAC,GAAG,CAAA,oCAAoC;IAC9C,MAAM,CAAC,GAAG,CAAA,sBAAsB;IAChC,MAAM,CAAC,GAAG,CAAA,kBAAkB;IAC5B,MAAM,CAAC,GAAG,CAAA,YAAY;IACtB,MAAM,CAAC,GAAG,CAAA,2BAA2B;IACrC,MAAM,CAAC,GAAG,CAAA,sBAAsB;IAChC,MAAM,CAAC,GAAG,CAAA,6EAA6E;IACvF,MAAM,CAAC,GAAG,CAAA,qBAAqB;IAC/B,MAAM,CAAC,GAAG,CAAA,mBAAmB;CAC9B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,kHAAkH;AAClH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL;YACE,EAAE,EAAE,kBAAkB;YACtB,WAAW,EAAE,2EAA2E;YACxF,QAAQ,EAAE,wBAAwB;YAClC,MAAM,EAAE,cAAc;YACtB,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,IAAI;SACd;QACD;YACE,EAAE,EAAE,wBAAwB;YAC5B,WAAW,EAAE,2EAA2E;YACxF,QAAQ,EAAE,wBAAwB;YAClC,MAAM,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,CAAC,CAAC,CAAC;QAC7D,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAA6B,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC;IACvD,OAAO,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,QAAkB;IAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC7B,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACxB,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC"}
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Lesson } from '@agent-city/spec';
|
|
2
|
+
/** Lowercase, no accents, words of 3+ letters without stop words, cut to a 5-letter root (cheap stemming es/en). */
|
|
3
|
+
export declare function terms(text: string): string[];
|
|
4
|
+
/**
|
|
5
|
+
* Orders lessons by relevance to `q`: share of query terms found (tags weigh double), then score and uses.
|
|
6
|
+
* Without a query: by score and uses. Lessons matching no term are left out.
|
|
7
|
+
*/
|
|
8
|
+
export declare function rankLessons(lessons: readonly Lesson[], q?: string): Lesson[];
|