@agent-city/ui-core 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/appearance.d.ts +24 -0
- package/dist/appearance.js +56 -0
- package/dist/appearance.js.map +1 -0
- package/dist/card.d.ts +41 -0
- package/dist/card.js +133 -0
- package/dist/card.js.map +1 -0
- package/dist/city.d.ts +44 -0
- package/dist/city.js +89 -0
- package/dist/city.js.map +1 -0
- package/dist/connection.d.ts +93 -0
- package/dist/connection.js +174 -0
- package/dist/connection.js.map +1 -0
- package/dist/demo.d.ts +35 -0
- package/dist/demo.js +393 -0
- package/dist/demo.js.map +1 -0
- package/dist/derive.d.ts +72 -0
- package/dist/derive.js +140 -0
- package/dist/derive.js.map +1 -0
- package/dist/diff.d.ts +33 -0
- package/dist/diff.js +160 -0
- package/dist/diff.js.map +1 -0
- package/dist/i18n.d.ts +368 -0
- package/dist/i18n.js +730 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +77 -0
- package/dist/memory.js +160 -0
- package/dist/memory.js.map +1 -0
- package/dist/narrative.d.ts +32 -0
- package/dist/narrative.js +64 -0
- package/dist/narrative.js.map +1 -0
- package/dist/observatory.d.ts +39 -0
- package/dist/observatory.js +121 -0
- package/dist/observatory.js.map +1 -0
- package/dist/playback.d.ts +27 -0
- package/dist/playback.js +81 -0
- package/dist/playback.js.map +1 -0
- package/dist/react.d.ts +6 -0
- package/dist/react.js +7 -0
- package/dist/react.js.map +1 -0
- package/dist/reducer.d.ts +6 -0
- package/dist/reducer.js +106 -0
- package/dist/reducer.js.map +1 -0
- package/dist/selectors.d.ts +41 -0
- package/dist/selectors.js +53 -0
- package/dist/selectors.js.map +1 -0
- package/dist/state.d.ts +69 -0
- package/dist/state.js +8 -0
- package/dist/state.js.map +1 -0
- package/dist/store.d.ts +44 -0
- package/dist/store.js +82 -0
- package/dist/store.js.map +1 -0
- package/dist/theme.d.ts +28 -0
- package/dist/theme.js +64 -0
- package/dist/theme.js.map +1 -0
- package/dist/usage.d.ts +36 -0
- package/dist/usage.js +58 -0
- package/dist/usage.js.map +1 -0
- package/package.json +56 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AgentCity contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AgentCityState, CityQuality, TimeOfDay } from './state.js';
|
|
2
|
+
/** Appearance settings of the city (theme, 3D quality, time of day). */
|
|
3
|
+
export type Appearance = Pick<AgentCityState, 'cityTheme' | 'cityQuality' | 'timeOfDay'>;
|
|
4
|
+
export declare const APPEARANCE_STORAGE_KEY = "agentcity.appearance";
|
|
5
|
+
export declare const BUILTIN_CITY_THEMES: readonly ["pueblo", "neon", "isla", "invierno"];
|
|
6
|
+
export declare const CITY_QUALITIES: readonly CityQuality[];
|
|
7
|
+
export declare const TIMES_OF_DAY: readonly TimeOfDay[];
|
|
8
|
+
/** Keeps only valid fields (theme ids are slugs; unknown ids are fine: the city falls back to `pueblo`). */
|
|
9
|
+
export declare function sanitizeAppearance(input: unknown): Partial<Appearance>;
|
|
10
|
+
type KV = Pick<Storage, 'getItem' | 'setItem'>;
|
|
11
|
+
/** Reads saved appearance; never throws (private mode, corrupt JSON...). */
|
|
12
|
+
export declare function loadAppearance(storage?: KV | undefined): Partial<Appearance>;
|
|
13
|
+
export declare function saveAppearance(a: Appearance, storage?: KV | undefined): void;
|
|
14
|
+
/**
|
|
15
|
+
* Loads saved appearance into the store and saves every later change. Returns the unsubscribe function.
|
|
16
|
+
* `override` (e.g. from ?cityTheme= in the URL) wins over the saved values for this visit without being saved.
|
|
17
|
+
*/
|
|
18
|
+
export declare function persistAppearance(store: {
|
|
19
|
+
getState(): Appearance & {
|
|
20
|
+
setAppearance(a: Partial<Appearance>): void;
|
|
21
|
+
};
|
|
22
|
+
subscribe(f: (s: Appearance, p: Appearance) => void): () => void;
|
|
23
|
+
}, override?: Partial<Appearance> | Record<string, unknown>, storage?: KV | undefined): () => void;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const APPEARANCE_STORAGE_KEY = 'agentcity.appearance';
|
|
2
|
+
export const BUILTIN_CITY_THEMES = ['pueblo', 'neon', 'isla', 'invierno'];
|
|
3
|
+
export const CITY_QUALITIES = ['auto', 'high', 'saver'];
|
|
4
|
+
export const TIMES_OF_DAY = ['auto', 'day', 'night'];
|
|
5
|
+
const THEME_ID = /^[a-z0-9][a-z0-9-]{0,40}$/;
|
|
6
|
+
/** Keeps only valid fields (theme ids are slugs; unknown ids are fine: the city falls back to `pueblo`). */
|
|
7
|
+
export function sanitizeAppearance(input) {
|
|
8
|
+
if (!input || typeof input !== 'object')
|
|
9
|
+
return {};
|
|
10
|
+
const a = input;
|
|
11
|
+
const out = {};
|
|
12
|
+
if (typeof a.cityTheme === 'string' && THEME_ID.test(a.cityTheme))
|
|
13
|
+
out.cityTheme = a.cityTheme;
|
|
14
|
+
if (CITY_QUALITIES.includes(a.cityQuality))
|
|
15
|
+
out.cityQuality = a.cityQuality;
|
|
16
|
+
if (TIMES_OF_DAY.includes(a.timeOfDay))
|
|
17
|
+
out.timeOfDay = a.timeOfDay;
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
const defaultStorage = () => {
|
|
21
|
+
try {
|
|
22
|
+
return typeof localStorage === 'undefined' ? undefined : localStorage;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/** Reads saved appearance; never throws (private mode, corrupt JSON...). */
|
|
29
|
+
export function loadAppearance(storage = defaultStorage()) {
|
|
30
|
+
try {
|
|
31
|
+
const raw = storage?.getItem(APPEARANCE_STORAGE_KEY);
|
|
32
|
+
return raw ? sanitizeAppearance(JSON.parse(raw)) : {};
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function saveAppearance(a, storage = defaultStorage()) {
|
|
39
|
+
try {
|
|
40
|
+
storage?.setItem(APPEARANCE_STORAGE_KEY, JSON.stringify(sanitizeAppearance(a)));
|
|
41
|
+
}
|
|
42
|
+
catch { /* storage full or blocked */ }
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Loads saved appearance into the store and saves every later change. Returns the unsubscribe function.
|
|
46
|
+
* `override` (e.g. from ?cityTheme= in the URL) wins over the saved values for this visit without being saved.
|
|
47
|
+
*/
|
|
48
|
+
export function persistAppearance(store, override = {}, storage = defaultStorage()) {
|
|
49
|
+
store.getState().setAppearance({ ...loadAppearance(storage), ...sanitizeAppearance(override) });
|
|
50
|
+
return store.subscribe((s, p) => {
|
|
51
|
+
if (s.cityTheme !== p.cityTheme || s.cityQuality !== p.cityQuality || s.timeOfDay !== p.timeOfDay) {
|
|
52
|
+
saveAppearance({ cityTheme: s.cityTheme, cityQuality: s.cityQuality, timeOfDay: s.timeOfDay }, storage);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=appearance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appearance.js","sourceRoot":"","sources":["../src/appearance.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAC7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAU,CAAC;AACnF,MAAM,CAAC,MAAM,cAAc,GAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAChF,MAAM,CAAC,MAAM,YAAY,GAAyB,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AAE3E,MAAM,QAAQ,GAAG,2BAA2B,CAAC;AAE7C,4GAA4G;AAC5G,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACnD,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,MAAM,GAAG,GAAwB,EAAE,CAAC;IACpC,IAAI,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QAAE,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;IAC/F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AQ,EAAE,CAAC,aAAa,CAAC,EAAE,GAAG,cAAc,CAAC,OAAO,CAAC,EAAE,GAAG,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAChG,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC9B,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;YAClG,cAAc,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,CAAC;QAC1G,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/card.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AgentEvent, SessionSummary, StepCategory } from '@agent-city/spec';
|
|
2
|
+
import type { Lang } from './state.js';
|
|
3
|
+
export type CardLesson = {
|
|
4
|
+
id: string;
|
|
5
|
+
text: string;
|
|
6
|
+
};
|
|
7
|
+
export type SessionCard = {
|
|
8
|
+
sessionId: string;
|
|
9
|
+
project?: string;
|
|
10
|
+
tool: string;
|
|
11
|
+
agents: string[];
|
|
12
|
+
startedAt?: string;
|
|
13
|
+
endedAt?: string;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
totalSteps: number;
|
|
16
|
+
steps: Record<StepCategory, number>;
|
|
17
|
+
errors: number;
|
|
18
|
+
/** Undefined when no event reported costUsd. */
|
|
19
|
+
costUsd?: number;
|
|
20
|
+
approvals: {
|
|
21
|
+
allow: number;
|
|
22
|
+
deny: number;
|
|
23
|
+
};
|
|
24
|
+
lessonsWritten: CardLesson[];
|
|
25
|
+
lessonsRecalled: CardLesson[];
|
|
26
|
+
/** Files read or written; secret paths (.env, keys...) are removed and strings redacted. */
|
|
27
|
+
files: string[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Makes a path safe to share: relative to cwd when inside it, otherwise with the home prefix
|
|
31
|
+
* replaced by `~`. Separator-agnostic and free of node:path (runs in the browser).
|
|
32
|
+
*/
|
|
33
|
+
export declare function shareablePath(p: string, cwd?: string): string;
|
|
34
|
+
/** Builds the shareable summary from a session's events. Pure; tolerant of unknown kinds/categories. */
|
|
35
|
+
export declare function summarizeSession(events: AgentEvent[], summary?: SessionSummary): SessionCard;
|
|
36
|
+
export declare function formatDuration(ms: number): string;
|
|
37
|
+
export declare const formatUsd: (n: number) => string;
|
|
38
|
+
/** One-line footer for PRs: "Built with AgentCity: N lessons applied, M human approvals". */
|
|
39
|
+
export declare function builtWithLine(card: SessionCard, lang?: Lang): string;
|
|
40
|
+
/** Markdown suitable for a PR description. */
|
|
41
|
+
export declare function sessionCardMarkdown(card: SessionCard, lang?: Lang): string;
|
package/dist/card.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { STEP_CATEGORIES, isSecretPath, redactSecrets } from '@agent-city/spec';
|
|
2
|
+
import { deriveTimeline } from './derive.js';
|
|
3
|
+
import { t } from './i18n.js';
|
|
4
|
+
/** Deciders the engine uses for automatic (non-human) approval results. */
|
|
5
|
+
const AUTOMATIC_DECIDERS = new Set(['agentcity', 'policy']);
|
|
6
|
+
const FILE_CATS = new Set(['read', 'write']);
|
|
7
|
+
/** Looks like a path, not a shell command or a URL. */
|
|
8
|
+
const looksLikePath = (s) => !/\s/.test(s) && !/^[a-z]+:\/\//i.test(s) && /[./\\]/.test(s);
|
|
9
|
+
const HOME_RE = /^(?:[a-z]:\/users\/[^/]+|\/home\/[^/]+|\/users\/[^/]+|\/root)(?=\/|$)/i;
|
|
10
|
+
/**
|
|
11
|
+
* Makes a path safe to share: relative to cwd when inside it, otherwise with the home prefix
|
|
12
|
+
* replaced by `~`. Separator-agnostic and free of node:path (runs in the browser).
|
|
13
|
+
*/
|
|
14
|
+
export function shareablePath(p, cwd) {
|
|
15
|
+
const norm = (x) => x.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
16
|
+
const f = p.replace(/\\/g, '/');
|
|
17
|
+
if (cwd) {
|
|
18
|
+
const c = norm(cwd);
|
|
19
|
+
const win = /^[a-z]:\//i.test(c);
|
|
20
|
+
const fc = win ? f.toLowerCase() : f;
|
|
21
|
+
const cc = win ? c.toLowerCase() : c;
|
|
22
|
+
if (cc && fc.startsWith(cc + '/'))
|
|
23
|
+
return f.slice(c.length + 1) || '.';
|
|
24
|
+
if (cc && fc === cc)
|
|
25
|
+
return '.';
|
|
26
|
+
}
|
|
27
|
+
const m = HOME_RE.exec(f);
|
|
28
|
+
if (m)
|
|
29
|
+
return '~' + f.slice(m[0].length);
|
|
30
|
+
return f;
|
|
31
|
+
}
|
|
32
|
+
/** Builds the shareable summary from a session's events. Pure; tolerant of unknown kinds/categories. */
|
|
33
|
+
export function summarizeSession(events, summary) {
|
|
34
|
+
const first = events[0];
|
|
35
|
+
const steps = Object.fromEntries(STEP_CATEGORIES.map((c) => [c, 0]));
|
|
36
|
+
const tl = deriveTimeline(events);
|
|
37
|
+
let totalSteps = 0;
|
|
38
|
+
let errors = 0;
|
|
39
|
+
const files = new Set();
|
|
40
|
+
const cwd = events.find((e) => e.session.cwd)?.session.cwd;
|
|
41
|
+
for (const e of tl) {
|
|
42
|
+
if (e.kind !== 'step.start' && e.kind !== 'step.end')
|
|
43
|
+
continue;
|
|
44
|
+
totalSteps++;
|
|
45
|
+
steps[e.category ?? 'other']++;
|
|
46
|
+
if (e.status === 'error')
|
|
47
|
+
errors++;
|
|
48
|
+
if (e.target && e.category && FILE_CATS.has(e.category) && looksLikePath(e.target) && !isSecretPath(e.target)) {
|
|
49
|
+
files.add(redactSecrets(shareablePath(e.target, cwd)));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
let cost = 0;
|
|
53
|
+
let hasCost = false;
|
|
54
|
+
const approvals = { allow: 0, deny: 0 };
|
|
55
|
+
const written = new Map();
|
|
56
|
+
const recalled = new Map();
|
|
57
|
+
for (const ev of events) {
|
|
58
|
+
const c = ev.step?.costUsd;
|
|
59
|
+
if (typeof c === 'number' && Number.isFinite(c)) {
|
|
60
|
+
cost += c;
|
|
61
|
+
hasCost = true;
|
|
62
|
+
}
|
|
63
|
+
// Only human decisions count: the engine marks automatic ones (timeouts, policies, prunes) with by 'agentcity' | 'policy'.
|
|
64
|
+
if (ev.kind === 'approval.result' && ev.approval?.decision && !AUTOMATIC_DECIDERS.has(ev.approval.by ?? '')) {
|
|
65
|
+
approvals[ev.approval.decision]++;
|
|
66
|
+
}
|
|
67
|
+
if (ev.lesson && (ev.kind === 'lesson.write' || ev.kind === 'lesson.recall')) {
|
|
68
|
+
const l = { id: ev.lesson.id, text: redactSecrets(ev.lesson.text) };
|
|
69
|
+
(ev.kind === 'lesson.write' ? written : recalled).set(l.id, l);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const startedAt = summary?.startedAt ?? first?.ts;
|
|
73
|
+
const endedAt = summary?.endedAt ?? [...events].reverse().find((e) => e.kind === 'session.end')?.ts;
|
|
74
|
+
const lastTs = endedAt ?? summary?.lastEventAt ?? events.at(-1)?.ts;
|
|
75
|
+
const d = startedAt && lastTs ? Date.parse(lastTs) - Date.parse(startedAt) : 0;
|
|
76
|
+
const agents = (summary?.agents ?? [...new Set(events.map((e) => e.agent?.id).filter((x) => !!x))]).map(redactSecrets);
|
|
77
|
+
const project = summary?.project ?? first?.session.project;
|
|
78
|
+
return {
|
|
79
|
+
sessionId: redactSecrets(summary?.id ?? first?.session.id ?? 'unknown'),
|
|
80
|
+
project: project === undefined ? undefined : redactSecrets(shareablePath(project)),
|
|
81
|
+
tool: summary?.tool ?? first?.source.tool ?? 'unknown',
|
|
82
|
+
agents, startedAt, endedAt,
|
|
83
|
+
durationMs: Number.isFinite(d) && d > 0 ? d : 0,
|
|
84
|
+
totalSteps, steps, errors,
|
|
85
|
+
costUsd: hasCost ? Math.round(cost * 10000) / 10000 : undefined,
|
|
86
|
+
approvals,
|
|
87
|
+
lessonsWritten: [...written.values()],
|
|
88
|
+
lessonsRecalled: [...recalled.values()],
|
|
89
|
+
files: [...files].sort(),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function formatDuration(ms) {
|
|
93
|
+
const s = Math.round(ms / 1000);
|
|
94
|
+
if (s < 60)
|
|
95
|
+
return `${s} s`;
|
|
96
|
+
const m = Math.floor(s / 60);
|
|
97
|
+
if (m < 60)
|
|
98
|
+
return `${m} min ${s % 60} s`;
|
|
99
|
+
return `${Math.floor(m / 60)} h ${m % 60} min`;
|
|
100
|
+
}
|
|
101
|
+
export const formatUsd = (n) => `$${n < 1 ? n.toFixed(4) : n.toFixed(2)}`;
|
|
102
|
+
/** One-line footer for PRs: "Built with AgentCity: N lessons applied, M human approvals". */
|
|
103
|
+
export function builtWithLine(card, lang = 'es') {
|
|
104
|
+
return t('card.builtWith', lang, { n: card.lessonsRecalled.length, m: card.approvals.allow + card.approvals.deny });
|
|
105
|
+
}
|
|
106
|
+
/** Markdown suitable for a PR description. */
|
|
107
|
+
export function sessionCardMarkdown(card, lang = 'es') {
|
|
108
|
+
const tr = (k, v) => t(k, lang, v);
|
|
109
|
+
const cats = STEP_CATEGORIES.filter((c) => card.steps[c] > 0).map((c) => `${tr(`cat.${c}`)} ${card.steps[c]}`).join(' · ');
|
|
110
|
+
const lines = [
|
|
111
|
+
`### ${tr('card.title')}: ${card.project ?? card.sessionId}`,
|
|
112
|
+
'',
|
|
113
|
+
`| ${tr('card.field')} | ${tr('card.value')} |`,
|
|
114
|
+
'|---|---|',
|
|
115
|
+
`| ${tr('card.tool')} | ${card.tool} |`,
|
|
116
|
+
`| ${tr('card.duration')} | ${formatDuration(card.durationMs)} |`,
|
|
117
|
+
`| ${tr('card.steps')} | ${card.totalSteps}${cats ? ` (${cats})` : ''} |`,
|
|
118
|
+
`| ${tr('card.errors')} | ${card.errors} |`,
|
|
119
|
+
`| ${tr('card.cost')} | ${card.costUsd === undefined ? tr('card.noCost') : formatUsd(card.costUsd)} |`,
|
|
120
|
+
`| ${tr('card.approvals')} | ${tr('card.approvalsValue', { a: card.approvals.allow, d: card.approvals.deny })} |`,
|
|
121
|
+
`| ${tr('card.lessons')} | ${tr('card.lessonsValue', { w: card.lessonsWritten.length, r: card.lessonsRecalled.length })} |`,
|
|
122
|
+
];
|
|
123
|
+
const esc = (s) => s.replace(/\|/g, '\\|').replace(/\n/g, ' ');
|
|
124
|
+
if (card.lessonsWritten.length)
|
|
125
|
+
lines.push('', `**${tr('card.learned')}**`, ...card.lessonsWritten.map((l) => `- ${esc(l.text)}`));
|
|
126
|
+
if (card.lessonsRecalled.length)
|
|
127
|
+
lines.push('', `**${tr('card.applied')}**`, ...card.lessonsRecalled.map((l) => `- ${esc(l.text)}`));
|
|
128
|
+
if (card.files.length)
|
|
129
|
+
lines.push('', `**${tr('card.files')}**`, ...card.files.map((f) => `- \`${f.replace(/`/g, '')}\``));
|
|
130
|
+
lines.push('', `_${builtWithLine(card, lang)}_`);
|
|
131
|
+
return lines.join('\n');
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=card.js.map
|
package/dist/card.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.js","sourceRoot":"","sources":["../src/card.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,WAAW,CAAC;AAG9B,2EAA2E;AAC3E,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AAwB5D,MAAM,SAAS,GAAG,IAAI,GAAG,CAAe,CAAC,MAAM,EAAE,OAAO,C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,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACnI,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACrI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3H,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACjD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/city.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { PendingApproval, SessionSummary, StepCategory } from '@agent-city/spec';
|
|
2
|
+
import type { AgentCityState } from './state.js';
|
|
3
|
+
import { type AgentView } from './derive.js';
|
|
4
|
+
export type CityAgentStatusLike = 'idle' | 'working' | 'waiting' | 'blocked' | 'error';
|
|
5
|
+
/** Shape of the town agent (`WorldAgent` in world-retro) plus the fields the city may use (action, lastStatus, startedAt). Built here so
|
|
6
|
+
* renderers never talk to adapters, only to ui-core state. */
|
|
7
|
+
export type CityAgentInput = {
|
|
8
|
+
id: string;
|
|
9
|
+
role?: string;
|
|
10
|
+
parentId?: string;
|
|
11
|
+
tool: string;
|
|
12
|
+
sessionId: string;
|
|
13
|
+
status: CityAgentStatusLike;
|
|
14
|
+
category?: StepCategory;
|
|
15
|
+
target?: string;
|
|
16
|
+
action?: string;
|
|
17
|
+
lastStatus?: 'ok' | 'error' | 'blocked';
|
|
18
|
+
/** When the current step started (ISO), for "for 3 s" labels and progress. */
|
|
19
|
+
startedAt?: string;
|
|
20
|
+
/** Teammate handle (team city): the avatar's name is shown as "ana · coder". */
|
|
21
|
+
peer?: string;
|
|
22
|
+
/** Model reported by the agent (e.g. claude-opus-4-1), shown next to its name. */
|
|
23
|
+
model?: string;
|
|
24
|
+
/** Last tool calls, oldest first, for the town's console. */
|
|
25
|
+
recent?: {
|
|
26
|
+
action: string;
|
|
27
|
+
target?: string;
|
|
28
|
+
status: 'running' | 'ok' | 'error' | 'blocked' | 'cancelled';
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
export declare function toCityAgent(a: AgentView, sessionId: string, tool: string, peer?: string): CityAgentInput;
|
|
32
|
+
/** Memoized per agents array so the 3D scene only re-renders when state changes. */
|
|
33
|
+
export declare function toCityAgents(agents: AgentView[], session?: Pick<SessionSummary, 'id' | 'tool' | 'peer'>): CityAgentInput[];
|
|
34
|
+
/** Main agent of a session: the root (no parent) with the most steps; falls back to the first agent. */
|
|
35
|
+
export declare function mainAgentId(agents: AgentView[]): string | undefined;
|
|
36
|
+
export type CitySession = {
|
|
37
|
+
session: SessionSummary;
|
|
38
|
+
agents: AgentView[];
|
|
39
|
+
approvals: PendingApproval[];
|
|
40
|
+
};
|
|
41
|
+
/** Every session with its live agents (city mode). Memoized on sessions/events/approvals references. */
|
|
42
|
+
export declare function selectCityOverview(s: AgentCityState): CitySession[];
|
|
43
|
+
/** Every agent of every session as city agents (city mode in 3D). */
|
|
44
|
+
export declare function selectAllCityAgents(s: AgentCityState): CityAgentInput[];
|
package/dist/city.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { deriveAgents } from './derive.js';
|
|
2
|
+
import { selectSessions } from './selectors.js';
|
|
3
|
+
export function toCityAgent(a, sessionId, tool, peer) {
|
|
4
|
+
const act = a.activity;
|
|
5
|
+
const status = act.kind === 'step' ? 'working' : act.kind === 'waiting' ? 'waiting' : act.kind === 'blocked' ? 'blocked'
|
|
6
|
+
: a.lastStatus === 'error' ? 'error' : 'idle';
|
|
7
|
+
const out = { id: a.id, tool, sessionId, status, ...(peer ? { peer } : {}) };
|
|
8
|
+
if (a.role)
|
|
9
|
+
out.role = a.role;
|
|
10
|
+
if (a.parentId)
|
|
11
|
+
out.parentId = a.parentId;
|
|
12
|
+
if (a.model)
|
|
13
|
+
out.model = a.model;
|
|
14
|
+
if (a.recent?.length)
|
|
15
|
+
out.recent = a.recent.map((r) => ({ ...r }));
|
|
16
|
+
if (act.kind === 'step') {
|
|
17
|
+
out.category = act.category;
|
|
18
|
+
out.action = act.action;
|
|
19
|
+
out.startedAt = act.since;
|
|
20
|
+
}
|
|
21
|
+
if ((act.kind === 'step' || act.kind === 'waiting') && act.target)
|
|
22
|
+
out.target = act.target;
|
|
23
|
+
if (act.kind === 'waiting' && act.action)
|
|
24
|
+
out.action = act.action;
|
|
25
|
+
if (!out.action && a.lastAction)
|
|
26
|
+
out.action = a.lastAction;
|
|
27
|
+
if (a.lastStatus && a.lastStatus !== 'cancelled')
|
|
28
|
+
out.lastStatus = a.lastStatus;
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
const cache = new WeakMap();
|
|
32
|
+
/** Memoized per agents array so the 3D scene only re-renders when state changes. */
|
|
33
|
+
export function toCityAgents(agents, session) {
|
|
34
|
+
const key = `${session?.id ?? ''}\u0000${session?.tool ?? 'unknown'}\u0000${session?.peer ?? ''}`;
|
|
35
|
+
let m = cache.get(agents);
|
|
36
|
+
if (!m) {
|
|
37
|
+
m = new Map();
|
|
38
|
+
cache.set(agents, m);
|
|
39
|
+
}
|
|
40
|
+
let out = m.get(key);
|
|
41
|
+
if (!out) {
|
|
42
|
+
out = agents.map((a) => toCityAgent(a, session?.id ?? '', session?.tool ?? 'unknown', session?.peer));
|
|
43
|
+
m.set(key, out);
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/** Main agent of a session: the root (no parent) with the most steps; falls back to the first agent. */
|
|
48
|
+
export function mainAgentId(agents) {
|
|
49
|
+
const roots = agents.filter((a) => !a.parentId || !agents.some((b) => b.id === a.parentId));
|
|
50
|
+
const pool = roots.length ? roots : agents;
|
|
51
|
+
return [...pool].sort((a, b) => b.stepCount - a.stepCount)[0]?.id;
|
|
52
|
+
}
|
|
53
|
+
let lastIn;
|
|
54
|
+
let lastOut = [];
|
|
55
|
+
/** Every session with its live agents (city mode). Memoized on sessions/events/approvals references. */
|
|
56
|
+
export function selectCityOverview(s) {
|
|
57
|
+
if (lastIn && lastIn[0] === s.sessions && lastIn[1] === s.events && lastIn[2] === s.approvals)
|
|
58
|
+
return lastOut;
|
|
59
|
+
const approvals = Object.values(s.approvals);
|
|
60
|
+
lastOut = selectSessions(s.sessions).map((session) => {
|
|
61
|
+
const ap = approvals.filter((a) => a.event?.session?.id === session.id);
|
|
62
|
+
return { session, agents: deriveAgents(s.events[session.id] ?? [], ap), approvals: ap };
|
|
63
|
+
});
|
|
64
|
+
lastIn = [s.sessions, s.events, s.approvals];
|
|
65
|
+
return lastOut;
|
|
66
|
+
}
|
|
67
|
+
const allCache = new WeakMap();
|
|
68
|
+
/** Every agent of every session as city agents (city mode in 3D). */
|
|
69
|
+
export function selectAllCityAgents(s) {
|
|
70
|
+
const ov = selectCityOverview(s);
|
|
71
|
+
let out = allCache.get(ov);
|
|
72
|
+
if (!out) {
|
|
73
|
+
const seen = new Set();
|
|
74
|
+
out = ov.flatMap((c) => {
|
|
75
|
+
const list = toCityAgents(c.agents, c.session);
|
|
76
|
+
const clash = list.some((a) => seen.has(a.id));
|
|
77
|
+
const suffix = `·${c.session.id.slice(0, 8)}`;
|
|
78
|
+
const fixed = clash
|
|
79
|
+
? list.map((a) => ({ ...a, id: a.id + suffix, ...(a.parentId ? { parentId: a.parentId + suffix } : {}) }))
|
|
80
|
+
: list;
|
|
81
|
+
for (const a of fixed)
|
|
82
|
+
seen.add(a.id);
|
|
83
|
+
return fixed;
|
|
84
|
+
});
|
|
85
|
+
allCache.set(ov, out);
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=city.js.map
|
package/dist/city.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"city.js","sourceRoot":"","sources":["../src/city.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAkB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AA2BhD,MAAM,UAAU,WAAW,CAAC,CAAY,EAAE,SAAiB,EAAE,IAAY,EAAE,IAAa;IACtF,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC;IACvB,MAAM,MAAM,GACV,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS;QACvG,CAAC,CAAC,CAAC,CAAC,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IAClD,MAAM,GAAG,GAAmB,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAC7F,IAAI,CAAC,CAAC,IAAI;QAAE,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;IAC9B,IAAI,CAAC,CAAC,QAAQ;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0,0 +1,93 @@
|
|
|
1
|
+
import type { ApprovalDecision, Checkpoint, ControlCommand, FileChange, ForkRequest, ForkResult, IntegrationConfig, IntegrationId, IntegrationStatus, Lesson, LessonInput, RewindRequest, RewindResult, SessionSummary } from '@agent-city/spec';
|
|
2
|
+
import { type AgentCityStore } from './store.js';
|
|
3
|
+
/** Minimal WebSocket surface we rely on (browser, Node 22 global, or a fake in tests). */
|
|
4
|
+
export interface WebSocketLike {
|
|
5
|
+
readyState: number;
|
|
6
|
+
send(data: string): void;
|
|
7
|
+
close(): void;
|
|
8
|
+
onopen: ((ev: unknown) => void) | null;
|
|
9
|
+
onclose: ((ev: unknown) => void) | null;
|
|
10
|
+
onerror: ((ev: unknown) => void) | null;
|
|
11
|
+
onmessage: ((ev: {
|
|
12
|
+
data: unknown;
|
|
13
|
+
}) => void) | null;
|
|
14
|
+
}
|
|
15
|
+
export type WebSocketFactory = (url: string) => WebSocketLike;
|
|
16
|
+
export interface EngineClient {
|
|
17
|
+
readonly url: string;
|
|
18
|
+
decideApproval(requestId: string, decision: ApprovalDecision): Promise<void>;
|
|
19
|
+
sendControl(sessionId: string, command: ControlCommand): Promise<void>;
|
|
20
|
+
/** Loads a full session replay into the store. */
|
|
21
|
+
loadSession(sessionId: string): Promise<void>;
|
|
22
|
+
/** GET /sessions (optional so older/fake clients keep working). */
|
|
23
|
+
listSessions?(): Promise<SessionSummary[]>;
|
|
24
|
+
/** GET /lessons?q=&project= */
|
|
25
|
+
listLessons?(q?: string, project?: string): Promise<Lesson[]>;
|
|
26
|
+
/** POST /lessons (the engine rejects unverified lessons). Throws with the engine error message. */
|
|
27
|
+
addLesson?(input: LessonInput): Promise<Lesson>;
|
|
28
|
+
/** POST /lessons/:id/feedback */
|
|
29
|
+
lessonFeedback?(id: string, helped: boolean): Promise<Lesson>;
|
|
30
|
+
/** PATCH /lessons/:id {text?, tags?, project?} (protocol 0.3). Evidence and verified never change. */
|
|
31
|
+
updateLesson?(id: string, patch: import('@agent-city/spec').LessonPatch): Promise<Lesson>;
|
|
32
|
+
/** DELETE /lessons/:id (protocol 0.3). Hard delete. */
|
|
33
|
+
deleteLesson?(id: string): Promise<void>;
|
|
34
|
+
/** GET /lessons/proposals: lessons the engine proposes from observed fail -> fix -> pass. */
|
|
35
|
+
listProposals?(): Promise<import('./memory.js').LessonProposal[]>;
|
|
36
|
+
/** POST /lessons/proposals/:id/accept {text?}: saves it as a lesson (the person may rewrite the text). */
|
|
37
|
+
acceptProposal?(id: string, text?: string): Promise<Lesson>;
|
|
38
|
+
/** DELETE /lessons/proposals/:id */
|
|
39
|
+
discardProposal?(id: string): Promise<void>;
|
|
40
|
+
/** GET /memory/impact: sessions with memory vs without (tokens, failed tests, steps). */
|
|
41
|
+
memoryImpact?(): Promise<import('./memory.js').MemoryImpact>;
|
|
42
|
+
/** GET /sessions/:id/files (protocol 0.2). */
|
|
43
|
+
listFiles?(sessionId: string): Promise<FileChange[]>;
|
|
44
|
+
/** GET /sessions/:id/checkpoints (protocol 0.2). */
|
|
45
|
+
listCheckpoints?(sessionId: string): Promise<Checkpoint[]>;
|
|
46
|
+
/** POST /sessions/:id/rewind. The session must be paused (409 otherwise). */
|
|
47
|
+
rewind?(sessionId: string, req: RewindRequest): Promise<RewindResult>;
|
|
48
|
+
/** POST /sessions/:id/fork. Git repos only (409 otherwise). */
|
|
49
|
+
fork?(sessionId: string, req: ForkRequest): Promise<ForkResult>;
|
|
50
|
+
/** GET /integrations */
|
|
51
|
+
listIntegrations?(): Promise<IntegrationStatus[]>;
|
|
52
|
+
/** PUT /integrations/:id */
|
|
53
|
+
putIntegration?(id: IntegrationId, config: IntegrationConfig): Promise<IntegrationStatus>;
|
|
54
|
+
/** POST /sessions/:id/export/otel */
|
|
55
|
+
exportOtel?(sessionId: string, endpoint?: string): Promise<{
|
|
56
|
+
spans: number;
|
|
57
|
+
}>;
|
|
58
|
+
/** POST /sessions/:id/share/github {pr} (protocol 0.2; 404 = not available). */
|
|
59
|
+
shareGithub?(sessionId: string, req: ShareGithubRequest): Promise<ShareGithubResult>;
|
|
60
|
+
close(): void;
|
|
61
|
+
}
|
|
62
|
+
export type ShareGithubRequest = {
|
|
63
|
+
pr: number;
|
|
64
|
+
};
|
|
65
|
+
export type ShareGithubResult = {
|
|
66
|
+
ok: true;
|
|
67
|
+
url?: string;
|
|
68
|
+
};
|
|
69
|
+
/** HTTP error from the engine, keeping the status (409 = not paused / not a git repo, 404 = not available). */
|
|
70
|
+
export declare class EngineError extends Error {
|
|
71
|
+
readonly status: number;
|
|
72
|
+
constructor(message: string, status: number);
|
|
73
|
+
}
|
|
74
|
+
export type ConnectOptions = {
|
|
75
|
+
store?: AgentCityStore;
|
|
76
|
+
WebSocket?: WebSocketFactory;
|
|
77
|
+
fetch?: typeof fetch;
|
|
78
|
+
/** Backoff: min(maxDelayMs, baseDelayMs * 2^attempt). */
|
|
79
|
+
baseDelayMs?: number;
|
|
80
|
+
maxDelayMs?: number;
|
|
81
|
+
setTimeout?: (fn: () => void, ms: number) => unknown;
|
|
82
|
+
clearTimeout?: (h: unknown) => void;
|
|
83
|
+
};
|
|
84
|
+
/** Resolves the engine base URL: explicit > same origin (served by engine) > default local port. */
|
|
85
|
+
export declare function resolveEngineUrl(url?: string): string;
|
|
86
|
+
export declare function wsUrl(base: string): string;
|
|
87
|
+
export declare function backoffDelay(attempt: number, base?: number, max?: number): number;
|
|
88
|
+
export declare function connectEngine(url?: string, opts?: ConnectOptions): EngineClient;
|
|
89
|
+
export declare function setCurrentClient(c: EngineClient | undefined): void;
|
|
90
|
+
export declare function getCurrentClient(): EngineClient | undefined;
|
|
91
|
+
/** Uses the most recent client (connectEngine or demo). No-op if none. */
|
|
92
|
+
export declare function decideApproval(requestId: string, decision: ApprovalDecision | 'allow' | 'deny'): Promise<void>;
|
|
93
|
+
export declare function sendControl(sessionId: string, command: ControlCommand | 'pause' | 'resume'): Promise<void>;
|