@almadar/agent 3.3.0 → 3.5.2

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.
@@ -12,6 +12,7 @@
12
12
  * independent of any specific skill registry location.
13
13
  */
14
14
  import { Command } from '@langchain/langgraph';
15
+ import type { StructuredTool } from '@langchain/core/tools';
15
16
  import { type LLMProvider } from '@almadar/llm';
16
17
  import { type SubagentEventCallback, type OrbitalCompleteCallback, type DomainOrbitalCompleteCallback } from '../tools/index.js';
17
18
  import { SessionManager } from './session-manager.js';
@@ -99,6 +100,10 @@ export interface SkillAgentOptions {
99
100
  }>(tool: T) => T;
100
101
  /** Optional: Use orchestrated generation/fixing with complexity-based routing */
101
102
  useOrchestration?: boolean;
103
+ /** Optional: Additional tools to register alongside the built-in tools */
104
+ extraTools?: StructuredTool[];
105
+ /** Optional: When true, ONLY use extraTools (skip built-in execute, finishTask, etc.) */
106
+ extraToolsOnly?: boolean;
102
107
  }
103
108
  /**
104
109
  * Agent interface with stream method (simplified from DeepAgent)
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Orbital CLI Validation Utility
3
+ *
4
+ * Shells out to `orbital validate --json <file>` for real schema validation.
5
+ * The CLI always exits 0 and outputs JSON with validation results.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export interface OrbitalValidationError {
10
+ code: string;
11
+ path: string;
12
+ message: string;
13
+ suggestion?: string;
14
+ }
15
+ export interface OrbitalValidationStats {
16
+ orbitals: number;
17
+ entities: number;
18
+ traits: number;
19
+ pages: number;
20
+ }
21
+ export interface OrbitalValidationResult {
22
+ valid: boolean;
23
+ errors: OrbitalValidationError[];
24
+ stats?: OrbitalValidationStats;
25
+ }
26
+ /**
27
+ * Validate an orbital schema using the `orbital validate` CLI.
28
+ *
29
+ * @param schema - JSON schema object or JSON string
30
+ * @param workDir - Directory to write the temp .orb file
31
+ * @returns Validation result with errors and stats
32
+ */
33
+ export declare function validateWithOrbitalCLI(schema: unknown, workDir: string): OrbitalValidationResult;
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env tsx
2
+ /**
3
+ * Debug script: full Gate 0 → 0.5 → 1 → 2 → 3 → 4 → verify chain on a single prompt.
4
+ *
5
+ * Usage:
6
+ * export $(grep -E '^(DEEPSEEK|OPEN_ROUTER)' ../../.env | xargs)
7
+ * npx tsx src/gates/_debug.ts # pure mode
8
+ * npx tsx src/gates/_debug.ts --guided # guided mode (LLM picks golden behavior)
9
+ * npx tsx src/gates/_debug.ts --no-verify # skip orbital-verify
10
+ * npx tsx src/gates/_debug.ts --prompt "Todo app" # custom prompt
11
+ */
12
+ import 'dotenv/config';
@@ -0,0 +1 @@
1
+ import 'dotenv/config';
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env tsx
2
+ /**
3
+ * Agentic Gates Runner
4
+ *
5
+ * Claude main agent with gate tools. Decomposes, matches behaviors,
6
+ * builds orbitals via gate pipeline, verifies, iterates on failures.
7
+ *
8
+ * Usage:
9
+ * export $(grep -E '^(DEEPSEEK|OPEN_ROUTER|ANTHROPIC)' ../../.env | xargs)
10
+ * npx tsx src/gates/agentic/run.ts
11
+ * npx tsx src/gates/agentic/run.ts --prompt "Todo app with categories"
12
+ */
13
+ import 'dotenv/config';
@@ -0,0 +1,301 @@
1
+ /**
2
+ * Agentic Gate Tools
3
+ *
4
+ * LangGraph-compatible tools that wrap the gate pipeline for use
5
+ * by a Claude main agent. Each tool is a scoped operation:
6
+ *
7
+ * - decompose_app: break prompt into orbital plan (Gate 0 subagent)
8
+ * - match_behavior: find golden behavior (Gate 0.5 subagent)
9
+ * - build_orbital: run gate pipeline on one orbital (Gates 1-4, DeepSeek)
10
+ * - verify_app: run orbital-verify (deterministic)
11
+ *
12
+ * The main agent (Claude) decides what to call, reads results, iterates.
13
+ * The gate subagents (DeepSeek) do the scoped generation.
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ import { z } from 'zod';
18
+ import type { OrbitalSchema } from '@almadar/core/types';
19
+ export declare function createDecomposeAppTool(): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
20
+ prompt: z.ZodString;
21
+ }, "strip", z.ZodTypeAny, {
22
+ prompt: string;
23
+ }, {
24
+ prompt: string;
25
+ }>, {
26
+ prompt: string;
27
+ }, {
28
+ prompt: string;
29
+ }, {
30
+ appName: string;
31
+ orbitals: {
32
+ name: string;
33
+ entityName: string;
34
+ traitNames: string[];
35
+ pageCount: number;
36
+ }[];
37
+ shellOrb: OrbitalSchema;
38
+ }, unknown, "decompose_app">;
39
+ export declare function createMatchBehaviorTool(): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
40
+ description: z.ZodString;
41
+ orbitalName: z.ZodString;
42
+ entityName: z.ZodString;
43
+ }, "strip", z.ZodTypeAny, {
44
+ description: string;
45
+ orbitalName: string;
46
+ entityName: string;
47
+ }, {
48
+ description: string;
49
+ orbitalName: string;
50
+ entityName: string;
51
+ }>, {
52
+ description: string;
53
+ orbitalName: string;
54
+ entityName: string;
55
+ }, {
56
+ description: string;
57
+ orbitalName: string;
58
+ entityName: string;
59
+ }, {
60
+ matched: boolean;
61
+ behaviorName: string | null;
62
+ hasGoldenOrb: boolean;
63
+ }, unknown, "match_behavior">;
64
+ export declare function createBuildOrbitalTool(workDir: string): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
65
+ orbitalName: z.ZodString;
66
+ shellOrb: z.ZodString;
67
+ goldenBehavior: z.ZodOptional<z.ZodString>;
68
+ feedback: z.ZodOptional<z.ZodString>;
69
+ }, "strip", z.ZodTypeAny, {
70
+ orbitalName: string;
71
+ shellOrb: string;
72
+ goldenBehavior?: string | undefined;
73
+ feedback?: string | undefined;
74
+ }, {
75
+ orbitalName: string;
76
+ shellOrb: string;
77
+ goldenBehavior?: string | undefined;
78
+ feedback?: string | undefined;
79
+ }>, {
80
+ orbitalName: string;
81
+ shellOrb: string;
82
+ goldenBehavior?: string | undefined;
83
+ feedback?: string | undefined;
84
+ }, {
85
+ orbitalName: string;
86
+ shellOrb: string;
87
+ goldenBehavior?: string | undefined;
88
+ feedback?: string | undefined;
89
+ }, {
90
+ success: boolean;
91
+ error: string;
92
+ orbitalName?: undefined;
93
+ orbitalsWritten?: undefined;
94
+ validation?: undefined;
95
+ } | {
96
+ success: boolean;
97
+ orbitalName: string;
98
+ orbitalsWritten: number;
99
+ validation: {
100
+ valid: boolean;
101
+ errorCount: number;
102
+ errors: string[];
103
+ };
104
+ error?: undefined;
105
+ } | {
106
+ success: boolean;
107
+ orbitalName: string;
108
+ error: string;
109
+ orbitalsWritten?: undefined;
110
+ validation?: undefined;
111
+ }, unknown, "build_orbital">;
112
+ export declare function createVerifyAppTool(workDir: string): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
113
+ orbPath: z.ZodOptional<z.ZodString>;
114
+ }, "strip", z.ZodTypeAny, {
115
+ orbPath?: string | undefined;
116
+ }, {
117
+ orbPath?: string | undefined;
118
+ }>, {
119
+ orbPath?: string | undefined;
120
+ }, {
121
+ orbPath?: string | undefined;
122
+ }, {
123
+ success: boolean;
124
+ error: string;
125
+ passed?: undefined;
126
+ failed?: undefined;
127
+ total?: undefined;
128
+ coverage?: undefined;
129
+ failures?: undefined;
130
+ } | {
131
+ success: boolean;
132
+ passed: number;
133
+ failed: number;
134
+ total: number;
135
+ coverage: number | null;
136
+ failures: string[];
137
+ error?: undefined;
138
+ } | {
139
+ success: boolean;
140
+ error: string;
141
+ passed: number;
142
+ failed: number;
143
+ total: number;
144
+ coverage: null;
145
+ failures: string[];
146
+ }, unknown, "verify_app">;
147
+ export declare function createUseBehaviorTool(workDir: string): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
148
+ behaviorName: z.ZodString;
149
+ entityName: z.ZodString;
150
+ fieldsJson: z.ZodString;
151
+ persistence: z.ZodOptional<z.ZodString>;
152
+ title: z.ZodOptional<z.ZodString>;
153
+ createButtonLabel: z.ZodOptional<z.ZodString>;
154
+ pageName: z.ZodOptional<z.ZodString>;
155
+ pagePath: z.ZodOptional<z.ZodString>;
156
+ isInitialPage: z.ZodOptional<z.ZodBoolean>;
157
+ }, "strip", z.ZodTypeAny, {
158
+ entityName: string;
159
+ behaviorName: string;
160
+ fieldsJson: string;
161
+ persistence?: string | undefined;
162
+ title?: string | undefined;
163
+ createButtonLabel?: string | undefined;
164
+ pageName?: string | undefined;
165
+ pagePath?: string | undefined;
166
+ isInitialPage?: boolean | undefined;
167
+ }, {
168
+ entityName: string;
169
+ behaviorName: string;
170
+ fieldsJson: string;
171
+ persistence?: string | undefined;
172
+ title?: string | undefined;
173
+ createButtonLabel?: string | undefined;
174
+ pageName?: string | undefined;
175
+ pagePath?: string | undefined;
176
+ isInitialPage?: boolean | undefined;
177
+ }>, {
178
+ entityName: string;
179
+ behaviorName: string;
180
+ fieldsJson: string;
181
+ persistence?: string | undefined;
182
+ title?: string | undefined;
183
+ createButtonLabel?: string | undefined;
184
+ pageName?: string | undefined;
185
+ pagePath?: string | undefined;
186
+ isInitialPage?: boolean | undefined;
187
+ }, {
188
+ entityName: string;
189
+ behaviorName: string;
190
+ fieldsJson: string;
191
+ persistence?: string | undefined;
192
+ title?: string | undefined;
193
+ createButtonLabel?: string | undefined;
194
+ pageName?: string | undefined;
195
+ pagePath?: string | undefined;
196
+ isInitialPage?: boolean | undefined;
197
+ }, {
198
+ success: boolean;
199
+ error: string;
200
+ behaviorName?: undefined;
201
+ entityName?: undefined;
202
+ orbitalPath?: undefined;
203
+ usedFunction?: undefined;
204
+ validation?: undefined;
205
+ } | {
206
+ success: boolean;
207
+ behaviorName: string;
208
+ entityName: string;
209
+ orbitalPath: string;
210
+ usedFunction: boolean;
211
+ validation: {
212
+ valid: boolean;
213
+ errorCount: number;
214
+ errors: string[];
215
+ };
216
+ error?: undefined;
217
+ }, unknown, "use_behavior">;
218
+ export declare function createConnectTool(workDir: string): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
219
+ emitterFile: z.ZodString;
220
+ listenerFile: z.ZodString;
221
+ eventName: z.ZodString;
222
+ triggersEvent: z.ZodOptional<z.ZodString>;
223
+ payloadJson: z.ZodOptional<z.ZodString>;
224
+ }, "strip", z.ZodTypeAny, {
225
+ emitterFile: string;
226
+ listenerFile: string;
227
+ eventName: string;
228
+ triggersEvent?: string | undefined;
229
+ payloadJson?: string | undefined;
230
+ }, {
231
+ emitterFile: string;
232
+ listenerFile: string;
233
+ eventName: string;
234
+ triggersEvent?: string | undefined;
235
+ payloadJson?: string | undefined;
236
+ }>, {
237
+ emitterFile: string;
238
+ listenerFile: string;
239
+ eventName: string;
240
+ triggersEvent?: string | undefined;
241
+ payloadJson?: string | undefined;
242
+ }, {
243
+ emitterFile: string;
244
+ listenerFile: string;
245
+ eventName: string;
246
+ triggersEvent?: string | undefined;
247
+ payloadJson?: string | undefined;
248
+ }, {
249
+ success: boolean;
250
+ error: string;
251
+ event?: undefined;
252
+ emitter?: undefined;
253
+ listener?: undefined;
254
+ } | {
255
+ success: boolean;
256
+ event: string;
257
+ emitter: string;
258
+ listener: string;
259
+ error?: undefined;
260
+ }, unknown, "connect_behaviors">;
261
+ export declare function createComposeTool(workDir: string): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
262
+ appName: z.ZodOptional<z.ZodString>;
263
+ orbitalFiles: z.ZodOptional<z.ZodString>;
264
+ pagesJson: z.ZodOptional<z.ZodString>;
265
+ }, "strip", z.ZodTypeAny, {
266
+ appName?: string | undefined;
267
+ orbitalFiles?: string | undefined;
268
+ pagesJson?: string | undefined;
269
+ }, {
270
+ appName?: string | undefined;
271
+ orbitalFiles?: string | undefined;
272
+ pagesJson?: string | undefined;
273
+ }>, {
274
+ appName?: string | undefined;
275
+ orbitalFiles?: string | undefined;
276
+ pagesJson?: string | undefined;
277
+ }, {
278
+ appName?: string | undefined;
279
+ orbitalFiles?: string | undefined;
280
+ pagesJson?: string | undefined;
281
+ }, {
282
+ success: boolean;
283
+ error: string;
284
+ appName?: undefined;
285
+ orbitalCount?: undefined;
286
+ pageCount?: undefined;
287
+ schemaPath?: undefined;
288
+ validation?: undefined;
289
+ } | {
290
+ success: boolean;
291
+ appName: string;
292
+ orbitalCount: number;
293
+ pageCount: number;
294
+ schemaPath: string;
295
+ validation: {
296
+ valid: boolean;
297
+ errorCount: number;
298
+ errors: string[];
299
+ };
300
+ error?: undefined;
301
+ }, unknown, "compose_app">;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Behavior Extract
3
+ *
4
+ * Extract per-gate slices from BehaviorSchema for guided mode.
5
+ * Each function extracts the data a specific gate needs from the golden behavior.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { BehaviorSchema } from '@almadar/std/behaviors/types';
10
+ import type { BehaviorGateData } from './types.js';
11
+ /**
12
+ * Extract all gate-level slices from a BehaviorSchema.
13
+ * Returns structured data that each gate can consume in guided mode.
14
+ */
15
+ export declare function extractBehaviorGateData(behavior: BehaviorSchema): BehaviorGateData;
16
+ /**
17
+ * Get gate-specific slice for a particular trait from extracted data.
18
+ */
19
+ export declare function getTraitGateData(data: BehaviorGateData, traitName: string): BehaviorGateData['traitLevels'][0] | undefined;
20
+ /**
21
+ * Get gate-specific slice for a particular transition from extracted data.
22
+ */
23
+ export declare function getTransitionGateData(data: BehaviorGateData, from: string, event: string): {
24
+ transition: BehaviorGateData['transitionLevels'][0] | undefined;
25
+ renderUi: BehaviorGateData['renderUiLevels'][0] | undefined;
26
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Gate 0: Application Decomposition
3
+ *
4
+ * NL prompt -> shell OrbitalSchema (orbital names, entity name + id field,
5
+ * trait names with empty state machines, pages).
6
+ * Single LLM call with fresh context.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import type { LLMClient } from '@almadar/llm';
11
+ import type { OrbitalSchema } from '@almadar/core/types';
12
+ import type { GateOpts, BehaviorGateData } from './types.js';
13
+ export declare function runGate0(client: LLMClient, prompt: string, opts?: GateOpts, behaviorData?: BehaviorGateData): Promise<OrbitalSchema>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Gate 0.5: Behavior Matching
3
+ *
4
+ * Given the shell .orb from Gate 0, asks the LLM to select the best-matching
5
+ * golden behavior from @almadar/std. Loads the matched behavior's exported
6
+ * .orb file (full OrbitalSchema with entities, state machines, render-ui)
7
+ * as the goldenOrb for Gates 1-4.
8
+ *
9
+ * Only runs in guided mode. Skipped entirely in pure mode.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import type { LLMClient } from '@almadar/llm';
14
+ import type { OrbitalSchema } from '@almadar/core/types';
15
+ import type { GateOpts } from './types.js';
16
+ export { loadGoldenOrb as loadGoldenOrbByName };
17
+ declare function loadGoldenOrb(behaviorName: string): OrbitalSchema | null;
18
+ export interface BehaviorMatchResult {
19
+ matchedName: string | null;
20
+ goldenOrb: OrbitalSchema | null;
21
+ }
22
+ /**
23
+ * Match the prompt against golden behaviors via LLM.
24
+ * Loads the matched behavior's exported .orb file as goldenOrb.
25
+ */
26
+ export declare function runGate05(client: LLMClient, prompt: string, orb: OrbitalSchema, opts?: GateOpts): Promise<BehaviorMatchResult>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Gate 1: Orbital Structure
3
+ *
4
+ * Enriches each orbital shell with full entity fields, persistence,
5
+ * collection, trait emits/listens, and pages.
6
+ * One LLM call per orbital.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import type { LLMClient } from '@almadar/llm';
11
+ import type { OrbitalSchema } from '@almadar/core/types';
12
+ import type { GateOpts, BehaviorGateData } from './types.js';
13
+ /**
14
+ * Enrich all orbital shells with full entity fields and trait details.
15
+ * Iterates orbitals with one LLM call each, merges back via replaceOrbital.
16
+ */
17
+ export declare function runGate1(client: LLMClient, orb: OrbitalSchema, opts?: GateOpts, behaviorData?: BehaviorGateData): Promise<OrbitalSchema>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Gate 2: Trait State Machine
3
+ *
4
+ * Fills in stateMachine (states, events, transitions with empty effects)
5
+ * for each trait across all orbitals.
6
+ * One LLM call per trait.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import type { LLMClient } from '@almadar/llm';
11
+ import type { OrbitalSchema } from '@almadar/core/types';
12
+ import type { GateOpts, BehaviorGateData } from './types.js';
13
+ /**
14
+ * Fill in state machines for all traits across all orbitals.
15
+ * Iterates traits with one LLM call each, merges back via replaceTrait.
16
+ */
17
+ export declare function runGate2(client: LLMClient, orb: OrbitalSchema, opts?: GateOpts, behaviorData?: BehaviorGateData): Promise<OrbitalSchema>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Gate 3: Transition Effects
3
+ *
4
+ * Fills in guard + non-render effects for each transition across all traits.
5
+ * One LLM call per transition.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { LLMClient } from '@almadar/llm';
10
+ import type { OrbitalSchema } from '@almadar/core/types';
11
+ import type { GateOpts, BehaviorGateData } from './types.js';
12
+ /**
13
+ * Fill in guards and non-render effects for all transitions.
14
+ * Iterates all transitions across all traits with one LLM call each.
15
+ */
16
+ export declare function runGate3(client: LLMClient, orb: OrbitalSchema, opts?: GateOpts, _behaviorData?: BehaviorGateData): Promise<OrbitalSchema>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Gate 4: Render UI
3
+ *
4
+ * Appends render-ui effects to each transition.
5
+ * One LLM call per transition.
6
+ * Passes slot context (which states are modal vs main) to every call.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import type { LLMClient } from '@almadar/llm';
11
+ import type { OrbitalSchema } from '@almadar/core/types';
12
+ import type { GateOpts, BehaviorGateData } from './types.js';
13
+ /**
14
+ * Append render-ui effects to all transitions.
15
+ * Builds slot context from state machine and passes it to every LLM call.
16
+ */
17
+ export declare function runGate4(client: LLMClient, orb: OrbitalSchema, opts?: GateOpts, _behaviorData?: BehaviorGateData): Promise<OrbitalSchema>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Gated Construction Pipeline
3
+ *
4
+ * Decomposes .orb program construction into five scoped gates,
5
+ * each handled by a standalone LLM call with fresh context.
6
+ * Every gate accepts an OrbitalSchema and returns an enriched OrbitalSchema.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ export { runGatePipeline } from './orchestrator.js';
11
+ export { runGate0 } from './gate0-application.js';
12
+ export { runGate05 } from './gate05-behavior-match.js';
13
+ export type { BehaviorMatchResult } from './gate05-behavior-match.js';
14
+ export { runGate1 } from './gate1-orbital.js';
15
+ export { runGate2 } from './gate2-trait.js';
16
+ export { runGate3 } from './gate3-transition.js';
17
+ export { runGate4 } from './gate4-render-ui.js';
18
+ export { deepCloneOrb, replaceOrbital, replaceTrait, replaceTransition } from './merge.js';
19
+ export { extractBehaviorGateData, getTraitGateData, getTransitionGateData } from './behavior-extract.js';
20
+ export { scoreGate0, scoreGate1, scoreGate2, scoreGate3, scoreGate4, scoreOverall, } from './scoring.js';
21
+ export type { GateProvider, GateMode, GateOpts, GatePipelineConfig, GateTimings, GatePipelineResult, GateScore, PipelineScore, BehaviorGateData, } from './types.js';
22
+ export type { OrbitalSchema, OrbitalDefinition, Orbital, Entity, Trait, StateMachine, State, Event, Transition, Effect, Page, Expression, } from '@almadar/core/types';
23
+ export { createDecomposeAppTool, createMatchBehaviorTool, createBuildOrbitalTool, createVerifyAppTool, createUseBehaviorTool, createConnectTool, createComposeTool, } from './agentic/tools.js';