@anhlp/alp-core 0.0.0-beta.1

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 (144) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +7 -0
  4. package/dist/adapter.d.ts +20 -0
  5. package/dist/adapter.js +30 -0
  6. package/dist/atomic.d.ts +2 -0
  7. package/dist/atomic.js +28 -0
  8. package/dist/backup.d.ts +27 -0
  9. package/dist/backup.js +582 -0
  10. package/dist/beads.d.ts +65 -0
  11. package/dist/beads.js +213 -0
  12. package/dist/delegation.d.ts +2 -0
  13. package/dist/delegation.js +32 -0
  14. package/dist/errors.d.ts +4 -0
  15. package/dist/errors.js +11 -0
  16. package/dist/formulas.d.ts +25 -0
  17. package/dist/formulas.js +201 -0
  18. package/dist/hook-run.d.ts +44 -0
  19. package/dist/hook-run.js +60 -0
  20. package/dist/hooks.d.ts +35 -0
  21. package/dist/hooks.js +30 -0
  22. package/dist/index.d.ts +30 -0
  23. package/dist/index.js +63 -0
  24. package/dist/init.d.ts +30 -0
  25. package/dist/init.js +88 -0
  26. package/dist/library-edit.d.ts +90 -0
  27. package/dist/library-edit.js +315 -0
  28. package/dist/library.d.ts +28 -0
  29. package/dist/library.js +108 -0
  30. package/dist/log.d.ts +37 -0
  31. package/dist/log.js +156 -0
  32. package/dist/migrations.d.ts +9 -0
  33. package/dist/migrations.js +95 -0
  34. package/dist/models.d.ts +11 -0
  35. package/dist/models.js +44 -0
  36. package/dist/permissions.d.ts +14 -0
  37. package/dist/permissions.js +229 -0
  38. package/dist/profiles.d.ts +27 -0
  39. package/dist/profiles.js +122 -0
  40. package/dist/promptsafe.d.ts +1 -0
  41. package/dist/promptsafe.js +13 -0
  42. package/dist/providers.d.ts +90 -0
  43. package/dist/providers.js +101 -0
  44. package/dist/resolver.d.ts +41 -0
  45. package/dist/resolver.js +240 -0
  46. package/dist/safe-path.d.ts +2 -0
  47. package/dist/safe-path.js +24 -0
  48. package/dist/shell.d.ts +16 -0
  49. package/dist/shell.js +22 -0
  50. package/dist/state-schema.d.ts +9 -0
  51. package/dist/state-schema.js +54 -0
  52. package/dist/task-rows.d.ts +47 -0
  53. package/dist/task-rows.js +45 -0
  54. package/dist/tasks.d.ts +128 -0
  55. package/dist/tasks.js +835 -0
  56. package/dist/teams.d.ts +69 -0
  57. package/dist/teams.js +159 -0
  58. package/dist/template-path.d.ts +2 -0
  59. package/dist/template-path.js +10 -0
  60. package/dist/trust.d.ts +8 -0
  61. package/dist/trust.js +47 -0
  62. package/dist/types.d.ts +51 -0
  63. package/dist/upgrade.d.ts +10 -0
  64. package/dist/upgrade.js +200 -0
  65. package/dist/user-settings.d.ts +6 -0
  66. package/dist/user-settings.js +72 -0
  67. package/dist/validation.d.ts +17 -0
  68. package/dist/validation.js +295 -0
  69. package/dist/verify.d.ts +15 -0
  70. package/dist/verify.js +123 -0
  71. package/dist/workflow.d.ts +14 -0
  72. package/dist/workflow.js +24 -0
  73. package/package.json +309 -0
  74. package/src/adapter.d.ts +20 -0
  75. package/src/adapter.js +29 -0
  76. package/src/atomic.d.ts +2 -0
  77. package/src/atomic.js +28 -0
  78. package/src/backup.d.ts +27 -0
  79. package/src/backup.js +570 -0
  80. package/src/beads.js +236 -0
  81. package/src/delegation.js +28 -0
  82. package/src/errors.js +7 -0
  83. package/src/formulas.d.ts +25 -0
  84. package/src/formulas.js +202 -0
  85. package/src/hook-run.js +57 -0
  86. package/src/hooks.js +36 -0
  87. package/src/index.js +31 -0
  88. package/src/init.js +92 -0
  89. package/src/library-edit.js +346 -0
  90. package/src/library.js +117 -0
  91. package/src/log.d.ts +37 -0
  92. package/src/log.js +177 -0
  93. package/src/migrations.d.ts +9 -0
  94. package/src/migrations.js +111 -0
  95. package/src/models.js +45 -0
  96. package/src/permissions.d.ts +14 -0
  97. package/src/permissions.js +242 -0
  98. package/src/profiles.js +139 -0
  99. package/src/promptsafe.d.ts +1 -0
  100. package/src/promptsafe.js +19 -0
  101. package/src/providers.js +122 -0
  102. package/src/resolver.js +238 -0
  103. package/src/safe-path.js +20 -0
  104. package/src/shell.js +28 -0
  105. package/src/state-schema.d.ts +9 -0
  106. package/src/state-schema.js +60 -0
  107. package/src/task-rows.js +44 -0
  108. package/src/tasks.d.ts +128 -0
  109. package/src/tasks.js +881 -0
  110. package/src/teams.js +170 -0
  111. package/src/template-path.js +8 -0
  112. package/src/trust.js +59 -0
  113. package/src/types.d.ts +51 -0
  114. package/src/upgrade.js +195 -0
  115. package/src/user-settings.d.ts +6 -0
  116. package/src/user-settings.js +76 -0
  117. package/src/validation.d.ts +17 -0
  118. package/src/validation.js +302 -0
  119. package/src/verify.d.ts +15 -0
  120. package/src/verify.js +127 -0
  121. package/src/workflow.js +28 -0
  122. package/templates/ALP.md +52 -0
  123. package/templates/agents/lead/AGENT.md +90 -0
  124. package/templates/agents/main/AGENT.md +150 -0
  125. package/templates/agents/oracle/AGENT.md +44 -0
  126. package/templates/agents/peer/AGENT.md +55 -0
  127. package/templates/agents/reviewer/AGENT.md +80 -0
  128. package/templates/agents/supervisor/AGENT.md +72 -0
  129. package/templates/providers/antigravity.json +6 -0
  130. package/templates/providers/opencode.json +7 -0
  131. package/templates/role-skills.json +8 -0
  132. package/templates/skills/bug-loop/SKILL.md +44 -0
  133. package/templates/skills/bug-loop/references/test-proof.md +25 -0
  134. package/templates/skills/goal-griller/SKILL.md +49 -0
  135. package/templates/skills/prompt-leverage/SKILL.md +37 -0
  136. package/templates/skills/prompt-leverage/references/brief-template.md +27 -0
  137. package/templates/skills/sequence-execution-plan/SKILL.md +42 -0
  138. package/templates/skills/sequence-execution-plan/references/plan-template.md +22 -0
  139. package/templates/skills/smart-commits/SKILL.md +40 -0
  140. package/templates/skills/xia/SKILL.md +42 -0
  141. package/templates/teams/cafe/HOUSE_RULES.md +1 -0
  142. package/templates/teams/cafe/team.json +15 -0
  143. package/templates/teams/pho/HOUSE_RULES.md +1 -0
  144. package/templates/teams/pho/team.json +14 -0
package/package.json ADDED
@@ -0,0 +1,309 @@
1
+ {
2
+ "name": "@anhlp/alp-core",
3
+ "version": "0.0.0-beta.1",
4
+ "type": "module",
5
+ "description": "ALP core module",
6
+ "files": [
7
+ "src",
8
+ "dist",
9
+ "templates",
10
+ "NOTICE"
11
+ ],
12
+ "exports": {
13
+ "./adapter": {
14
+ "alp-source": {
15
+ "types": "./src/adapter.js",
16
+ "default": "./src/adapter.js"
17
+ },
18
+ "types": "./dist/adapter.d.ts",
19
+ "default": "./src/adapter.js"
20
+ },
21
+ "./atomic": {
22
+ "alp-source": {
23
+ "types": "./src/atomic.js",
24
+ "default": "./src/atomic.js"
25
+ },
26
+ "types": "./dist/atomic.d.ts",
27
+ "default": "./src/atomic.js"
28
+ },
29
+ "./backup": {
30
+ "alp-source": {
31
+ "types": "./src/backup.js",
32
+ "default": "./src/backup.js"
33
+ },
34
+ "types": "./dist/backup.d.ts",
35
+ "default": "./src/backup.js"
36
+ },
37
+ "./beads": {
38
+ "alp-source": {
39
+ "types": "./src/beads.js",
40
+ "default": "./src/beads.js"
41
+ },
42
+ "types": "./dist/beads.d.ts",
43
+ "default": "./src/beads.js"
44
+ },
45
+ "./delegation": {
46
+ "alp-source": {
47
+ "types": "./src/delegation.js",
48
+ "default": "./src/delegation.js"
49
+ },
50
+ "types": "./dist/delegation.d.ts",
51
+ "default": "./src/delegation.js"
52
+ },
53
+ "./errors": {
54
+ "alp-source": {
55
+ "types": "./src/errors.js",
56
+ "default": "./src/errors.js"
57
+ },
58
+ "types": "./dist/errors.d.ts",
59
+ "default": "./src/errors.js"
60
+ },
61
+ "./formulas": {
62
+ "alp-source": {
63
+ "types": "./src/formulas.js",
64
+ "default": "./src/formulas.js"
65
+ },
66
+ "types": "./dist/formulas.d.ts",
67
+ "default": "./src/formulas.js"
68
+ },
69
+ "./hook-run": {
70
+ "alp-source": {
71
+ "types": "./src/hook-run.js",
72
+ "default": "./src/hook-run.js"
73
+ },
74
+ "types": "./dist/hook-run.d.ts",
75
+ "default": "./src/hook-run.js"
76
+ },
77
+ "./hooks": {
78
+ "alp-source": {
79
+ "types": "./src/hooks.js",
80
+ "default": "./src/hooks.js"
81
+ },
82
+ "types": "./dist/hooks.d.ts",
83
+ "default": "./src/hooks.js"
84
+ },
85
+ "./index": {
86
+ "alp-source": {
87
+ "types": "./src/index.js",
88
+ "default": "./src/index.js"
89
+ },
90
+ "types": "./dist/index.d.ts",
91
+ "default": "./src/index.js"
92
+ },
93
+ ".": {
94
+ "alp-source": {
95
+ "types": "./src/index.js",
96
+ "default": "./src/index.js"
97
+ },
98
+ "types": "./dist/index.d.ts",
99
+ "default": "./src/index.js"
100
+ },
101
+ "./init": {
102
+ "alp-source": {
103
+ "types": "./src/init.js",
104
+ "default": "./src/init.js"
105
+ },
106
+ "types": "./dist/init.d.ts",
107
+ "default": "./src/init.js"
108
+ },
109
+ "./library-edit": {
110
+ "alp-source": {
111
+ "types": "./src/library-edit.js",
112
+ "default": "./src/library-edit.js"
113
+ },
114
+ "types": "./dist/library-edit.d.ts",
115
+ "default": "./src/library-edit.js"
116
+ },
117
+ "./library": {
118
+ "alp-source": {
119
+ "types": "./src/library.js",
120
+ "default": "./src/library.js"
121
+ },
122
+ "types": "./dist/library.d.ts",
123
+ "default": "./src/library.js"
124
+ },
125
+ "./log": {
126
+ "alp-source": {
127
+ "types": "./src/log.js",
128
+ "default": "./src/log.js"
129
+ },
130
+ "types": "./dist/log.d.ts",
131
+ "default": "./src/log.js"
132
+ },
133
+ "./migrations": {
134
+ "alp-source": {
135
+ "types": "./src/migrations.js",
136
+ "default": "./src/migrations.js"
137
+ },
138
+ "types": "./dist/migrations.d.ts",
139
+ "default": "./src/migrations.js"
140
+ },
141
+ "./models": {
142
+ "alp-source": {
143
+ "types": "./src/models.js",
144
+ "default": "./src/models.js"
145
+ },
146
+ "types": "./dist/models.d.ts",
147
+ "default": "./src/models.js"
148
+ },
149
+ "./permissions": {
150
+ "alp-source": {
151
+ "types": "./src/permissions.js",
152
+ "default": "./src/permissions.js"
153
+ },
154
+ "types": "./dist/permissions.d.ts",
155
+ "default": "./src/permissions.js"
156
+ },
157
+ "./profiles": {
158
+ "alp-source": {
159
+ "types": "./src/profiles.js",
160
+ "default": "./src/profiles.js"
161
+ },
162
+ "types": "./dist/profiles.d.ts",
163
+ "default": "./src/profiles.js"
164
+ },
165
+ "./promptsafe": {
166
+ "alp-source": {
167
+ "types": "./src/promptsafe.js",
168
+ "default": "./src/promptsafe.js"
169
+ },
170
+ "types": "./dist/promptsafe.d.ts",
171
+ "default": "./src/promptsafe.js"
172
+ },
173
+ "./providers": {
174
+ "alp-source": {
175
+ "types": "./src/providers.js",
176
+ "default": "./src/providers.js"
177
+ },
178
+ "types": "./dist/providers.d.ts",
179
+ "default": "./src/providers.js"
180
+ },
181
+ "./resolver": {
182
+ "alp-source": {
183
+ "types": "./src/resolver.js",
184
+ "default": "./src/resolver.js"
185
+ },
186
+ "types": "./dist/resolver.d.ts",
187
+ "default": "./src/resolver.js"
188
+ },
189
+ "./state-schema": {
190
+ "alp-source": {
191
+ "types": "./src/state-schema.js",
192
+ "default": "./src/state-schema.js"
193
+ },
194
+ "types": "./dist/state-schema.d.ts",
195
+ "default": "./src/state-schema.js"
196
+ },
197
+ "./task-rows": {
198
+ "alp-source": {
199
+ "types": "./src/task-rows.js",
200
+ "default": "./src/task-rows.js"
201
+ },
202
+ "types": "./dist/task-rows.d.ts",
203
+ "default": "./src/task-rows.js"
204
+ },
205
+ "./tasks": {
206
+ "alp-source": {
207
+ "types": "./src/tasks.js",
208
+ "default": "./src/tasks.js"
209
+ },
210
+ "types": "./dist/tasks.d.ts",
211
+ "default": "./src/tasks.js"
212
+ },
213
+ "./teams": {
214
+ "alp-source": {
215
+ "types": "./src/teams.js",
216
+ "default": "./src/teams.js"
217
+ },
218
+ "types": "./dist/teams.d.ts",
219
+ "default": "./src/teams.js"
220
+ },
221
+ "./trust": {
222
+ "alp-source": {
223
+ "types": "./src/trust.js",
224
+ "default": "./src/trust.js"
225
+ },
226
+ "types": "./dist/trust.d.ts",
227
+ "default": "./src/trust.js"
228
+ },
229
+ "./upgrade": {
230
+ "alp-source": {
231
+ "types": "./src/upgrade.js",
232
+ "default": "./src/upgrade.js"
233
+ },
234
+ "types": "./dist/upgrade.d.ts",
235
+ "default": "./src/upgrade.js"
236
+ },
237
+ "./user-settings": {
238
+ "alp-source": {
239
+ "types": "./src/user-settings.js",
240
+ "default": "./src/user-settings.js"
241
+ },
242
+ "types": "./dist/user-settings.d.ts",
243
+ "default": "./src/user-settings.js"
244
+ },
245
+ "./validation": {
246
+ "alp-source": {
247
+ "types": "./src/validation.js",
248
+ "default": "./src/validation.js"
249
+ },
250
+ "types": "./dist/validation.d.ts",
251
+ "default": "./src/validation.js"
252
+ },
253
+ "./verify": {
254
+ "alp-source": {
255
+ "types": "./src/verify.js",
256
+ "default": "./src/verify.js"
257
+ },
258
+ "types": "./dist/verify.d.ts",
259
+ "default": "./src/verify.js"
260
+ },
261
+ "./workflow": {
262
+ "alp-source": {
263
+ "types": "./src/workflow.js",
264
+ "default": "./src/workflow.js"
265
+ },
266
+ "types": "./dist/workflow.d.ts",
267
+ "default": "./src/workflow.js"
268
+ },
269
+ "./types": {
270
+ "alp-source": {
271
+ "types": "./src/types.d.ts"
272
+ },
273
+ "types": "./dist/types.d.ts"
274
+ },
275
+ "./template-path": {
276
+ "alp-source": {
277
+ "types": "./src/template-path.js"
278
+ },
279
+ "types": "./dist/template-path.d.ts",
280
+ "default": "./src/template-path.js"
281
+ }
282
+ },
283
+ "engines": {
284
+ "node": ">=22.12"
285
+ },
286
+ "dependencies": {
287
+ "@anhlp/alp-protocol": "0.0.0-beta.1"
288
+ },
289
+ "scripts": {
290
+ "build": "node ../../scripts/build-workspace.mjs core",
291
+ "test": "node ../../scripts/test-package.mjs core",
292
+ "prepack": "npm run build"
293
+ },
294
+ "publishConfig": {
295
+ "access": "public",
296
+ "registry": "https://registry.npmjs.org/",
297
+ "tag": "beta"
298
+ },
299
+ "license": "Apache-2.0",
300
+ "repository": {
301
+ "type": "git",
302
+ "url": "git+https://github.com/phucanh08/alp.git",
303
+ "directory": "packages/core"
304
+ },
305
+ "homepage": "https://github.com/phucanh08/alp/tree/main/packages/core#readme",
306
+ "bugs": {
307
+ "url": "https://github.com/phucanh08/alp/issues"
308
+ }
309
+ }
@@ -0,0 +1,20 @@
1
+ import type { ResolvedAgent } from './types.js';
2
+ export type CapabilitySupport = 'native' | 'emulated' | 'unsupported';
3
+ export interface AdapterCapabilities {
4
+ instructions: CapabilitySupport;
5
+ skills: CapabilitySupport;
6
+ hooks: CapabilitySupport;
7
+ mcp: CapabilitySupport;
8
+ }
9
+ export interface CompiledAgent<T = unknown> {
10
+ adapterId: string;
11
+ agentName: string;
12
+ projectRoot: string;
13
+ material: T;
14
+ }
15
+ export interface AlpRuntimeAdapter<T = unknown> {
16
+ id: string;
17
+ capabilities(): AdapterCapabilities;
18
+ compile(agent: ResolvedAgent): Promise<CompiledAgent<T>>;
19
+ }
20
+ export function compileAgent<T>(adapter: AlpRuntimeAdapter<T>, agent: ResolvedAgent): Promise<CompiledAgent<T>>;
package/src/adapter.js ADDED
@@ -0,0 +1,29 @@
1
+ import { AlpError } from './errors.js';
2
+ import { validateResolvedAgent } from './validation.js';
3
+
4
+ /** Validate a plugin boundary before handing off the provider-neutral IR. */
5
+ export async function compileAgent(adapter, agent) {
6
+ if (!adapter || typeof adapter.id !== 'string' || !adapter.id.trim() || typeof adapter.capabilities !== 'function' || typeof adapter.compile !== 'function') {
7
+ throw new AlpError('INVALID_ADAPTER', 'Adapter requires id, capabilities(), and compile()');
8
+ }
9
+ validateResolvedAgent(agent);
10
+ const capabilities = adapter.capabilities();
11
+ for (const key of ['instructions', 'skills', 'hooks', 'mcp']) {
12
+ if (!['native', 'emulated', 'unsupported'].includes(capabilities?.[key])) throw new AlpError('INVALID_CAPABILITIES', `${adapter.id}: invalid ${key} capability`);
13
+ }
14
+ const required = {
15
+ instructions: Boolean(agent.instructions.project || agent.instructions.agent),
16
+ skills: agent.skills.length > 0,
17
+ hooks: agent.hooks.length > 0,
18
+ mcp: Object.keys(agent.mcp.mcpServers).length > 0,
19
+ };
20
+ for (const [key, present] of Object.entries(required)) {
21
+ if (present && capabilities[key] === 'unsupported') throw new AlpError('UNSUPPORTED_CAPABILITY', `${adapter.id} does not support ${key} required by '${agent.name}'`);
22
+ }
23
+ // Adapters receive their own snapshot; compilation must not mutate the resolved source.
24
+ const compiled = await adapter.compile(structuredClone(agent));
25
+ if (!compiled || compiled.adapterId !== adapter.id || compiled.agentName !== agent.name || compiled.projectRoot !== agent.projectRoot || !Object.hasOwn(compiled, 'material')) {
26
+ throw new AlpError('INVALID_COMPILED_AGENT', `${adapter.id}: invalid compiled agent envelope`);
27
+ }
28
+ return compiled;
29
+ }
@@ -0,0 +1,2 @@
1
+ export function moveFile(from: string, to: string): Promise<void>;
2
+ export function writeAtomic(file: string, body: string | Uint8Array, mode?: number): Promise<void>;
package/src/atomic.js ADDED
@@ -0,0 +1,28 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { rename, rm, writeFile } from 'node:fs/promises';
3
+
4
+ /**
5
+ * Moves `from` to `to`. On Windows the move fails with EPERM, EACCES or EBUSY while another
6
+ * process has the target open, such as a client reading it; it is tried again then.
7
+ */
8
+ export async function moveFile(from, to) {
9
+ for (let attempt = 0; ; attempt++) {
10
+ try { return await rename(from, to); }
11
+ catch (error) {
12
+ if (process.platform !== 'win32' || attempt >= 20 || !['EPERM', 'EACCES', 'EBUSY'].includes(error?.code)) throw error;
13
+ await new Promise(resolve => setTimeout(resolve, 10 + attempt * 10));
14
+ }
15
+ }
16
+ }
17
+
18
+ /** Writes `file` through a temporary file beside it, so a reader sees the old or the new content. */
19
+ export async function writeAtomic(file, body, mode = 0o600) {
20
+ const temporary = `${file}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`;
21
+ try {
22
+ await writeFile(temporary, body, { mode });
23
+ await moveFile(temporary, file);
24
+ } catch (error) {
25
+ await rm(temporary, { force: true }).catch(() => {});
26
+ throw error;
27
+ }
28
+ }
@@ -0,0 +1,27 @@
1
+ export const BACKUP_FORMAT: number;
2
+ export const BACKUP_EXTENSION: string;
3
+ export const STATE_UNITS: string[];
4
+ export const CLEARED_UNITS: string[];
5
+ export const HOME_UNITS: string[];
6
+ export const PROJECT_UNITS: string[];
7
+ export function backupsDir(home: string): string;
8
+ export function knownProjects(home: string): Promise<string[]>;
9
+ export type BackupSummary = { file: string; files: number; bytes: number; projects: string[]; stateSchema: number | null; sessions: number; tasks: number };
10
+ export function createBackup(options: { home: string; out: string; units?: string[]; projects?: string[]; by?: string; kind?: string }): Promise<BackupSummary>;
11
+ export function automaticBackup(home: string, kind: string, options?: { units?: string[]; projects?: string[]; by?: string }): Promise<string>;
12
+ export type BackupContents = { file: string; kind: string; by?: string; createdAt: string; home: string; stateSchema: number | null; units: string[]; projects: string[]; sessions: number; tasks: number; files: number; bytes: number; external: number };
13
+ export function verifyBackup(file: string): Promise<BackupContents>;
14
+ export function recoverInterruptedRestore(home: string): Promise<{ outcome: 'rolled back' | 'completed'; file?: string; safety?: string } | undefined>;
15
+ export type RestoreResult = {
16
+ file: string;
17
+ safety?: string;
18
+ stateSchema: number | null;
19
+ interrupted?: { outcome: 'rolled back' | 'completed'; file?: string; safety?: string };
20
+ units: Array<{ area: string; unit: string; present: boolean }>;
21
+ projects: string[];
22
+ skipped: Array<{ root: string; reason: string }>;
23
+ warnings: string[];
24
+ };
25
+ export function restoreBackup(options: { home: string; file: string; projects?: boolean; safety?: boolean; clearLive?: boolean; replaceNewer?: boolean; by?: string; beforeSwap?: (index: number, total: number) => Promise<void> | void }): Promise<RestoreResult>;
26
+ export function readRestoredMarker(home: string): Promise<{ at?: string; from?: string; by?: string } | undefined>;
27
+ export function clearRestoredMarker(home: string): Promise<void>;