@anhlp/alp-runtime 0.0.0-stage → 0.0.1-beta.10

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.
Files changed (127) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +6 -2
  4. package/dist/acp-transport.d.ts +130 -0
  5. package/dist/acp-transport.js +482 -0
  6. package/dist/antigravity-transport.d.ts +107 -0
  7. package/dist/antigravity-transport.js +665 -0
  8. package/dist/assignment-results.d.ts +55 -0
  9. package/dist/assignment-results.js +181 -0
  10. package/dist/attachments.d.ts +84 -0
  11. package/dist/attachments.js +213 -0
  12. package/dist/board-domain.d.ts +56 -0
  13. package/dist/board-domain.js +157 -0
  14. package/dist/board.d.ts +27 -0
  15. package/dist/board.js +76 -0
  16. package/dist/catalog.d.ts +44 -0
  17. package/dist/catalog.js +47 -0
  18. package/dist/claude-transport.d.ts +251 -0
  19. package/dist/claude-transport.js +931 -0
  20. package/dist/compact.d.ts +29 -0
  21. package/dist/compact.js +49 -0
  22. package/dist/configure.d.ts +44 -0
  23. package/dist/configure.js +64 -0
  24. package/dist/contracts.d.ts +378 -0
  25. package/dist/contracts.js +16 -0
  26. package/dist/conversation.d.ts +45 -0
  27. package/dist/conversation.js +62 -0
  28. package/dist/events.d.ts +1 -0
  29. package/dist/events.js +0 -0
  30. package/dist/github.d.ts +10 -0
  31. package/dist/github.js +39 -0
  32. package/dist/handoff.d.ts +36 -0
  33. package/dist/handoff.js +73 -0
  34. package/dist/index.d.ts +39 -0
  35. package/dist/index.js +122 -0
  36. package/dist/input-limits.d.ts +25 -0
  37. package/dist/input-limits.js +48 -0
  38. package/dist/language.d.ts +51 -0
  39. package/dist/language.js +94 -0
  40. package/dist/live.d.ts +48 -0
  41. package/dist/live.js +50 -0
  42. package/dist/mailbox.d.ts +26 -0
  43. package/dist/mailbox.js +38 -0
  44. package/dist/mcp-tools.d.ts +123 -0
  45. package/dist/mcp-tools.js +97 -0
  46. package/dist/model-catalog.d.ts +162 -0
  47. package/dist/model-catalog.js +338 -0
  48. package/dist/model-probes.d.ts +7 -0
  49. package/dist/model-probes.js +69 -0
  50. package/dist/permission-path.d.ts +2 -0
  51. package/dist/permission-path.js +44 -0
  52. package/dist/process-info.d.ts +14 -0
  53. package/dist/process-info.js +32 -0
  54. package/dist/providers.d.ts +28 -0
  55. package/dist/providers.js +73 -0
  56. package/dist/recall.d.ts +42 -0
  57. package/dist/recall.js +61 -0
  58. package/dist/resolve.d.ts +123 -0
  59. package/dist/resolve.js +242 -0
  60. package/dist/runtime-context.d.ts +43 -0
  61. package/dist/runtime-context.js +61 -0
  62. package/dist/runtime.d.ts +13 -0
  63. package/dist/runtime.js +4818 -0
  64. package/dist/session-config.d.ts +2345 -0
  65. package/dist/session-config.js +209 -0
  66. package/dist/session-state.d.ts +190 -0
  67. package/dist/session-state.js +0 -0
  68. package/dist/skill-resources.d.ts +30 -0
  69. package/dist/skill-resources.js +55 -0
  70. package/dist/tool-detail.d.ts +81 -0
  71. package/dist/tool-detail.js +332 -0
  72. package/dist/tool-results.d.ts +12 -0
  73. package/dist/tool-results.js +25 -0
  74. package/dist/tools.d.ts +827 -0
  75. package/dist/tools.js +463 -0
  76. package/dist/transport.d.ts +47 -0
  77. package/dist/transport.js +171 -0
  78. package/dist/usage.d.ts +25 -0
  79. package/dist/usage.js +60 -0
  80. package/dist/workspace.d.ts +127 -0
  81. package/dist/workspace.js +340 -0
  82. package/dist/worktree-domain.d.ts +89 -0
  83. package/dist/worktree-domain.js +199 -0
  84. package/dist/write-error.d.ts +2 -0
  85. package/dist/write-error.js +10 -0
  86. package/package.json +262 -4
  87. package/src/acp-transport.ts +481 -0
  88. package/src/antigravity-transport.ts +740 -0
  89. package/src/assignment-results.ts +154 -0
  90. package/src/attachments.ts +254 -0
  91. package/src/board-domain.ts +185 -0
  92. package/src/board.ts +87 -0
  93. package/src/catalog.ts +43 -0
  94. package/src/claude-transport.ts +1097 -0
  95. package/src/compact.ts +62 -0
  96. package/src/configure.ts +93 -0
  97. package/src/contracts.ts +363 -0
  98. package/src/conversation.ts +81 -0
  99. package/src/events.ts +1 -0
  100. package/src/github.ts +37 -0
  101. package/src/handoff.ts +86 -0
  102. package/src/index.ts +41 -0
  103. package/src/input-limits.ts +65 -0
  104. package/src/language.ts +130 -0
  105. package/src/live.ts +90 -0
  106. package/src/mailbox.ts +49 -0
  107. package/src/mcp-tools.ts +106 -0
  108. package/src/model-catalog.ts +316 -0
  109. package/src/model-probes.ts +58 -0
  110. package/src/permission-path.ts +37 -0
  111. package/src/process-info.ts +40 -0
  112. package/src/providers.ts +87 -0
  113. package/src/recall.ts +86 -0
  114. package/src/resolve.ts +238 -0
  115. package/src/runtime-context.ts +49 -0
  116. package/src/runtime.ts +5608 -0
  117. package/src/session-config.ts +312 -0
  118. package/src/session-state.ts +180 -0
  119. package/src/skill-resources.ts +73 -0
  120. package/src/tool-detail.ts +397 -0
  121. package/src/tool-results.ts +26 -0
  122. package/src/tools.ts +466 -0
  123. package/src/transport.ts +118 -0
  124. package/src/usage.ts +79 -0
  125. package/src/workspace.ts +424 -0
  126. package/src/worktree-domain.ts +220 -0
  127. package/src/write-error.ts +4 -0
package/src/board.ts ADDED
@@ -0,0 +1,87 @@
1
+ import path from 'node:path';
2
+ import { realpathSync } from 'node:fs';
3
+ import type { InputLimits } from './input-limits.js';
4
+
5
+ /**
6
+ * The project board (plans/reference/ALPD.md §18): one group channel per project that every
7
+ * agent working on it shares, across trees. Agents pin claims (paths they are changing),
8
+ * decisions (the approach everyone follows) and findings (what others need to know), so
9
+ * agents working independently neither edit each other's files nor pursue different ideas.
10
+ * These helpers stay pure; storage and delivery live in the runtime.
11
+ */
12
+
13
+ export const PIN_KINDS = ['claim', 'decision', 'finding'] as const;
14
+ import type { PinKind, Pin } from '@anhlp/alp-protocol/dto';
15
+ export type { PinKind, Pin } from '@anhlp/alp-protocol/dto';
16
+
17
+
18
+ export const PIN_BODY_CHARS = 2000;
19
+ export const PIN_PATHS = 50;
20
+ /** One claimed path; macOS's PATH_MAX. Each segment of a path is one more realpath call. */
21
+ export const PIN_PATH_CHARS = 1024;
22
+ /** alp_pin's paths and alp_board's kinds, checked before any schema walks them. */
23
+ export const PIN_PATHS_INPUT: InputLimits = { bytes: PIN_PATHS * (3 * PIN_PATH_CHARS + 3), items: PIN_PATHS, depth: 1, string: PIN_PATH_CHARS };
24
+ export const BOARD_KINDS_INPUT: InputLimits = { bytes: 64, items: PIN_KINDS.length, depth: 1, string: 16 };
25
+ /** Decisions and findings kept per project; live claims are always kept. */
26
+ export const BOARD_KEEP = 200;
27
+ const DIGEST_CHARS = 3000;
28
+
29
+ /** Resolve symlinked parents even for a file an assignment has not created yet. */
30
+ function canonicalPath(file: string): string {
31
+ try { return realpathSync(file); } catch {
32
+ const parent = path.dirname(file);
33
+ return parent === file ? file : path.join(canonicalPath(parent), path.basename(file));
34
+ }
35
+ }
36
+ const containsPath = (outer: string, inner: string) => {
37
+ const relative = path.relative(outer, inner);
38
+ return !relative || (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
39
+ };
40
+
41
+ /** Normalized project-relative paths, or absolute paths in a declared external write root. */
42
+ export function normalizePaths(paths: unknown, project: string, roots: string[] = [project]): string[] | string {
43
+ if (!Array.isArray(paths) || !paths.length || paths.length > PIN_PATHS) return `paths must list 1 to ${PIN_PATHS} files or directories`;
44
+ const normalized: string[] = [];
45
+ for (const entry of paths) {
46
+ if (typeof entry !== 'string' || !entry.trim()) return 'paths must be nonempty strings';
47
+ if (entry.length > PIN_PATH_CHARS) return `paths must be at most ${PIN_PATH_CHARS} characters each`;
48
+ const absolute = canonicalPath(path.resolve(project, entry.trim()));
49
+ if (!roots.some(root => containsPath(canonicalPath(root), absolute))) return `${entry} is outside the project or declared write root`;
50
+ const relative = path.relative(canonicalPath(project), absolute).split(path.sep).join('/');
51
+ normalized.push(relative === '' ? '.' : relative === '..' || relative.startsWith('../') || path.isAbsolute(relative) ? absolute.split(path.sep).join('/') : relative);
52
+ }
53
+ return [...new Set(normalized)];
54
+ }
55
+
56
+ /** Two paths overlap when one is the other or contains it; '.' is the whole project. */
57
+ const contains = (outer: string, inner: string) => path.isAbsolute(outer) === path.isAbsolute(inner) && (outer === '.' || inner === outer || inner.startsWith(outer.endsWith('/') ? outer : `${outer}/`));
58
+
59
+ export function overlapping(a: string[], b: string[]) {
60
+ return a.filter(left => b.some(right => contains(left, right) || contains(right, left)));
61
+ }
62
+
63
+ export const live = (pin: Pin) => !pin.released;
64
+
65
+ export function renderPin(pin: Pin) {
66
+ const where = pin.paths?.length ? ` [${pin.paths.join(', ')}]` : '';
67
+ return `${pin.kind} ${pin.id} by ${pin.agent}${pin.task ? ` for task ${pin.task}` : ''}${where}: ${pin.body}`;
68
+ }
69
+
70
+ /** What an agent should know before it starts: live claims, then recent decisions and findings. */
71
+ export function renderBoard(pins: Pin[], limit = DIGEST_CHARS) {
72
+ const claims = pins.filter(pin => pin.kind === 'claim' && live(pin));
73
+ const notes = pins.filter(pin => pin.kind !== 'claim' && live(pin)).reverse();
74
+ if (!claims.length && !notes.length) return '';
75
+ const lines = ['Project board (shared by every agent on this project; read more with alp_board):'];
76
+ let size = lines[0].length;
77
+ for (const pin of [...claims, ...notes]) {
78
+ const line = `- ${renderPin(pin)}`;
79
+ if (size + line.length > limit) {
80
+ lines.push('- … more on alp_board');
81
+ break;
82
+ }
83
+ lines.push(line);
84
+ size += line.length;
85
+ }
86
+ return lines.join('\n');
87
+ }
package/src/catalog.ts ADDED
@@ -0,0 +1,43 @@
1
+ /** Models, modes and thinking options the runtime accepts; viewers render them as-is. */
2
+ import { MODELS, useLiveModels } from '@anhlp/alp-core/models';
3
+
4
+ export const DEFAULT_MODEL = 'gpt-5.6-sol';
5
+ export const DEFAULT_CLAUDE_MODEL = 'sonnet';
6
+ export const DEFAULT_ANTIGRAVITY_MODEL = 'gemini-3.8-flash-high';
7
+ // Main's and the supervisor's models and effort come from the session's team: templates/teams/<id>/team.json (ALPD §42).
8
+ /** Oracle runs on one of these; main may consult both for two opinions. */
9
+ export const ORACLE_MODELS = ['claude:claude-fable-5-1', 'codex:gpt-6-astra'];
10
+ export const ORACLE_THINKING = 'high';
11
+ export const modes = [{ id: 'read-only', label: 'Read only' }, { id: 'workspace-write', label: 'Workspace write' }, { id: 'full-access', label: 'Full access' }];
12
+ const modeRank: Record<string, number> = { 'read-only': 0, 'workspace-write': 1, 'full-access': 2 };
13
+ /** Whether a session in `mode` may run with `requested`; a child never exceeds its requester. */
14
+ export const withinMode = (requested: string, mode: string) => (modeRank[requested] ?? 3) <= (modeRank[mode] ?? -1);
15
+ export const writes = (mode: string) => mode !== 'read-only';
16
+ const option = (id: string) => ({ id, label: id });
17
+ const options = (ids: string[]) => ids.map(option);
18
+ export const thinkingOptions = options(['none', 'off', 'low', 'medium', 'high', 'xhigh', 'max', 'ultra', 'ultracode']);
19
+
20
+ const model = (runtime: 'codex' | 'claude' | 'antigravity', id: string, label: string, description: string, modelThinkingOptions: Array<{ id: string; label: string }>, defaultThinkingOptionId?: string) => ({
21
+ id: `${runtime}:${id}`,
22
+ label: `${runtime === 'codex' ? 'Codex' : runtime === 'claude' ? 'Claude Code' : 'Antigravity'} · ${label}`,
23
+ description,
24
+ thinkingOptions: modelThinkingOptions,
25
+ ...(defaultThinkingOptionId ? { defaultThinkingOptionId } : {}),
26
+ });
27
+
28
+ export type CatalogEntry = { runtime: 'codex' | 'claude' | 'antigravity'; id: string; label: string; description: string; efforts: string[]; effort?: string; source?: 'live' | 'fallback' | 'static' };
29
+ const toModel = (entry: CatalogEntry) => model(entry.runtime, entry.id, entry.label, entry.description, options(entry.efforts), entry.effort);
30
+ /** The rows every consumer reads: core MODELS at start, replaced in place by the live catalog (model-catalog.ts). */
31
+ export const entries: CatalogEntry[] = MODELS.map(entry => ({ ...entry, source: 'static' as const })) as CatalogEntry[];
32
+ export const models = entries.map(toModel);
33
+ /** Replaces the catalog in place so every module holding `models`/`entries` sees the new rows. */
34
+ export function applyCatalog(next: CatalogEntry[]) {
35
+ entries.splice(0, entries.length, ...next);
36
+ models.splice(0, models.length, ...next.map(toModel));
37
+ // Core's effort checks and fitting (validation.js, profiles.js) consult the same rows (t-086c).
38
+ useLiveModels(next);
39
+ }
40
+
41
+ export function thinkingOptionsFor(runtime: 'codex' | 'claude' | 'antigravity', nativeModel: string) {
42
+ return models.find(candidate => candidate.id === `${runtime}:${nativeModel}`)?.thinkingOptions ?? thinkingOptions;
43
+ }