@anthropic-field/core 0.3.1 → 0.3.3
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/dist/src/cognitive/index.d.ts +1 -1
- package/dist/src/cognitive/index.js +3 -1
- package/dist/src/cognitive/index.js.map +1 -1
- package/dist/src/cognitive/runtime/index.d.ts +1 -0
- package/dist/src/cognitive/runtime/index.js +2 -0
- package/dist/src/cognitive/runtime/index.js.map +1 -1
- package/dist/src/cognitive/runtime/subagent.d.ts +105 -0
- package/dist/src/cognitive/runtime/subagent.js +255 -0
- package/dist/src/cognitive/runtime/subagent.js.map +1 -0
- package/dist/src/commands/init.js +4 -4
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/memory.js +2 -2
- package/dist/src/commands/memory.js.map +1 -1
- package/dist/src/config/config.d.ts +1 -1
- package/dist/src/config/config.js +8 -4
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/tools/memoryTool.d.ts +1 -1
- package/dist/src/tools/memoryTool.js +2 -2
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/read-many-files.js +1 -1
- package/dist/src/utils/memoryDiscovery.d.ts +1 -1
- package/dist/src/utils/memoryDiscovery.js +3 -3
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.d.ts +1 -1
- package/dist/src/utils/memoryImportProcessor.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
export type { ModuleTier, SchemaStrictness, EnumStrategy, RiskLevel, RiskRule, CognitiveModule, ModuleManifest, SchemaContract, OverflowPolicy, EnumPolicy, Policies, ToolsPolicy, FailureContract, RuntimeRequirements, CompatConfig, IOConfig, EnvelopeResponse, EnvelopeSuccess, EnvelopeFailure, EnvelopeMeta, EnvelopeError, Insight, Extensions, ErrorCode, RunModuleOptions, ValidationResult, ModuleSearchPaths, } from './types.js';
|
|
17
17
|
export { loadModule, findModule, discoverModules, detectFormat, detectV2Version, isValidModulePath, getModuleTier, isOverflowEnabled, shouldAutoWrap, type ModuleFormat, } from './loader/index.js';
|
|
18
18
|
export { validateInput, validateData, validateMeta, validateError, validateEnvelope, validateOverflow, validateFull, isEnvelopeResponse, isV22Envelope, isSuccessEnvelope, isFailureEnvelope, validateEnvelopeStructure, validateMetaFields, type FullValidationResult, type EnvelopeStructureResult, } from './validator/index.js';
|
|
19
|
-
export { executeModule, runModule, parseLLMResponse, setDefaultLLMCaller, getDefaultLLMCaller, extractMeta, shouldEscalate, requiresConfirmation, type ExecuteModuleParams, type LLMCaller, wrapV21ToV22, convertLegacyToEnvelope, createSuccessEnvelope, createFailureEnvelope, createParseError, createInvalidInputError, createModuleNotFoundError, createSchemaValidationError, createInternalError, aggregateRisk, aggregateRiskFromList, compareRisk, maxRisk, requiresReview, repairEnvelope, repairErrorEnvelope, tryRepair, isMetaRepairable, type RepairResult, buildPrompt, buildSystemPrompt, substituteArguments, formatConstraints, type BuildPromptOptions, } from './runtime/index.js';
|
|
19
|
+
export { executeModule, runModule, parseLLMResponse, setDefaultLLMCaller, getDefaultLLMCaller, extractMeta, shouldEscalate, requiresConfirmation, type ExecuteModuleParams, type LLMCaller, wrapV21ToV22, convertLegacyToEnvelope, createSuccessEnvelope, createFailureEnvelope, createParseError, createInvalidInputError, createModuleNotFoundError, createSchemaValidationError, createInternalError, aggregateRisk, aggregateRiskFromList, compareRisk, maxRisk, requiresReview, repairEnvelope, repairErrorEnvelope, tryRepair, isMetaRepairable, type RepairResult, buildPrompt, buildSystemPrompt, substituteArguments, formatConstraints, type BuildPromptOptions, SubagentOrchestrator, runWithSubagents, hasSubagentCalls, listSubagentCalls, parseCalls, substituteCallResults, createContext, forkContext, extendContext, type SubagentContext, type SubagentRunOptions, type SubagentResult, type CallDirective, } from './runtime/index.js';
|
|
20
20
|
export { CognitiveTool, createCognitiveTool, createCognitiveTools, CognitiveModuleRegistry, getGlobalRegistry, initGlobalRegistry, resetGlobalRegistry, getDefaultConfig, type CognitiveToolParams, type CognitiveToolResult, type CognitiveConfig, } from './tool/index.js';
|
|
21
21
|
export { discoverAndRegisterCognitiveTools, registerCognitiveModule, getCognitiveTools, isCognitiveTool, getCognitiveConfigFromSettings, createLLMCallerFromGeminiClient, type GeminiClientAdapter, } from './integration.js';
|
|
22
22
|
export { createLLMCallerFromContentGenerator, createSimpleLLMCaller, } from './gemini-adapter.js';
|
|
@@ -34,7 +34,9 @@ aggregateRisk, aggregateRiskFromList, compareRisk, maxRisk, requiresReview,
|
|
|
34
34
|
// Repair
|
|
35
35
|
repairEnvelope, repairErrorEnvelope, tryRepair, isMetaRepairable,
|
|
36
36
|
// Prompt
|
|
37
|
-
buildPrompt, buildSystemPrompt, substituteArguments, formatConstraints,
|
|
37
|
+
buildPrompt, buildSystemPrompt, substituteArguments, formatConstraints,
|
|
38
|
+
// Subagent
|
|
39
|
+
SubagentOrchestrator, runWithSubagents, hasSubagentCalls, listSubagentCalls, parseCalls, substituteCallResults, createContext, forkContext, extendContext, } from './runtime/index.js';
|
|
38
40
|
// =============================================================================
|
|
39
41
|
// Tool Integration
|
|
40
42
|
// =============================================================================
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cognitive/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA2CH,gFAAgF;AAChF,SAAS;AACT,gFAAgF;AAEhF,OAAO,EACL,UAAU,EACV,UAAU,EACV,eAAe,EACf,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,cAAc,GAEf,MAAM,mBAAmB,CAAC;AAE3B,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,OAAO,EACL,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,EACzB,kBAAkB,GAGnB,MAAM,sBAAsB,CAAC;AAE9B,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF,OAAO;AACL,WAAW;AACX,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,oBAAoB;AAIpB,mBAAmB;AACnB,YAAY,EACZ,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB;AAEnB,OAAO;AACP,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,OAAO,EACP,cAAc;AAEd,SAAS;AACT,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,gBAAgB;AAGhB,SAAS;AACT,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cognitive/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA2CH,gFAAgF;AAChF,SAAS;AACT,gFAAgF;AAEhF,OAAO,EACL,UAAU,EACV,UAAU,EACV,eAAe,EACf,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,cAAc,GAEf,MAAM,mBAAmB,CAAC;AAE3B,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,OAAO,EACL,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,EACzB,kBAAkB,GAGnB,MAAM,sBAAsB,CAAC;AAE9B,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF,OAAO;AACL,WAAW;AACX,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,mBA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AAc,EACd,eAAe;AACf,qBAAqB;AACrB,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,cAAc,GAGf,MAAM,YAAY,CAAC;AAEpB,OAAO;AACL,eAAe;AACf,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,cAAc,GAGf,MAAM,gBAAgB,CAAC;AAExB,gFAAgF;AAChF,8DAA8D;AAC9D,gFAAgF;AAEhF,OAAO;AACL,2BAA2B;AAC3B,sBAAsB,EACtB,yBAAyB,EACzB,yBAAyB,EACzB,sBAAsB,EACtB,gBAAgB;AAChB,2CAA2C;AAC3C,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GAGjB,MAAM,uBAAuB,CAAC"}
|
|
@@ -10,3 +10,4 @@ export { wrapV21ToV22, convertLegacyToEnvelope, createSuccessEnvelope, createFai
|
|
|
10
10
|
export { aggregateRisk, aggregateRiskFromList, compareRisk, maxRisk, requiresReview, requiresConfirmation as riskRequiresConfirmation, } from './risk-aggregator.js';
|
|
11
11
|
export { repairEnvelope, repairErrorEnvelope, tryRepair, isMetaRepairable, type RepairResult, } from './repair-pass.js';
|
|
12
12
|
export { buildPrompt, buildSystemPrompt, substituteArguments, formatConstraints, type BuildPromptOptions, } from './prompt-builder.js';
|
|
13
|
+
export { SubagentOrchestrator, runWithSubagents, hasSubagentCalls, listSubagentCalls, parseCalls, substituteCallResults, createContext, forkContext, extendContext, type SubagentContext, type SubagentRunOptions, type SubagentResult, type CallDirective, } from './subagent.js';
|
|
@@ -15,4 +15,6 @@ export { aggregateRisk, aggregateRiskFromList, compareRisk, maxRisk, requiresRev
|
|
|
15
15
|
export { repairEnvelope, repairErrorEnvelope, tryRepair, isMetaRepairable, } from './repair-pass.js';
|
|
16
16
|
// Prompt Builder
|
|
17
17
|
export { buildPrompt, buildSystemPrompt, substituteArguments, formatConstraints, } from './prompt-builder.js';
|
|
18
|
+
// Subagent Orchestrator
|
|
19
|
+
export { SubagentOrchestrator, runWithSubagents, hasSubagentCalls, listSubagentCalls, parseCalls, substituteCallResults, createContext, forkContext, extendContext, } from './subagent.js';
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cognitive/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,WAAW;AACX,OAAO,EACL,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,oBAAoB,GAGrB,MAAM,eAAe,CAAC;AAEvB,WAAW;AACX,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAEvB,mBAAmB;AACnB,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,OAAO,EACP,cAAc,EACd,oBAAoB,IAAI,wBAAwB,GACjD,MAAM,sBAAsB,CAAC;AAE9B,cAAc;AACd,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAE1B,iBAAiB;AACjB,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAElB,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cognitive/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,WAAW;AACX,OAAO,EACL,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,oBAAoB,GAGrB,MAAM,eAAe,CAAC;AAEvB,WAAW;AACX,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAEvB,mBAAmB;AACnB,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,OAAO,EACP,cAAc,EACd,oBAAoB,IAAI,wBAAwB,GACjD,MAAM,sBAAsB,CAAC;AAE9B,cAAc;AACd,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAE1B,iBAAiB;AACjB,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAElB,MAAM,qBAAqB,CAAC;AAE7B,wBAAwB;AACxB,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,aAAa,GAKd,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Subagent Orchestrator
|
|
7
|
+
* Orchestrate module calls with isolated execution contexts.
|
|
8
|
+
*
|
|
9
|
+
* Supports:
|
|
10
|
+
* - @call:module-name - Call another module
|
|
11
|
+
* - @call:module-name(args) - Call with arguments
|
|
12
|
+
* - context: fork - Isolated execution (no shared state)
|
|
13
|
+
* - context: main - Shared execution (default)
|
|
14
|
+
*/
|
|
15
|
+
import { type LLMCaller } from './executor.js';
|
|
16
|
+
export interface SubagentContext {
|
|
17
|
+
/** Parent module name (null for root) */
|
|
18
|
+
parentId: string | null;
|
|
19
|
+
/** Current depth in call stack */
|
|
20
|
+
depth: number;
|
|
21
|
+
/** Maximum allowed depth */
|
|
22
|
+
maxDepth: number;
|
|
23
|
+
/** Accumulated results from previous calls */
|
|
24
|
+
results: Record<string, unknown>;
|
|
25
|
+
/** Whether this context is isolated (fork) */
|
|
26
|
+
isolated: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface CallDirective {
|
|
29
|
+
/** Target module name */
|
|
30
|
+
module: string;
|
|
31
|
+
/** Arguments passed to the module */
|
|
32
|
+
args: string;
|
|
33
|
+
/** Original match string for replacement */
|
|
34
|
+
match: string;
|
|
35
|
+
}
|
|
36
|
+
export interface SubagentRunOptions {
|
|
37
|
+
/** Input data for the module */
|
|
38
|
+
input?: Record<string, unknown>;
|
|
39
|
+
/** Maximum call depth (default: 5) */
|
|
40
|
+
maxDepth?: number;
|
|
41
|
+
/** LLM caller to use */
|
|
42
|
+
llmCaller?: LLMCaller;
|
|
43
|
+
/** Working directory */
|
|
44
|
+
cwd?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface SubagentResult {
|
|
47
|
+
ok: boolean;
|
|
48
|
+
data?: unknown;
|
|
49
|
+
error?: {
|
|
50
|
+
code: string;
|
|
51
|
+
message: string;
|
|
52
|
+
};
|
|
53
|
+
meta?: {
|
|
54
|
+
confidence: number;
|
|
55
|
+
risk: string;
|
|
56
|
+
explain: string;
|
|
57
|
+
};
|
|
58
|
+
callStack: string[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a new root context.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createContext(maxDepth?: number): SubagentContext;
|
|
64
|
+
/**
|
|
65
|
+
* Fork context (isolated - no inherited results).
|
|
66
|
+
*/
|
|
67
|
+
export declare function forkContext(ctx: SubagentContext, moduleName: string): SubagentContext;
|
|
68
|
+
/**
|
|
69
|
+
* Extend context (shared - inherits results).
|
|
70
|
+
*/
|
|
71
|
+
export declare function extendContext(ctx: SubagentContext, moduleName: string): SubagentContext;
|
|
72
|
+
/**
|
|
73
|
+
* Parse @call directives from text.
|
|
74
|
+
*/
|
|
75
|
+
export declare function parseCalls(text: string): CallDirective[];
|
|
76
|
+
/**
|
|
77
|
+
* Replace @call directives with their results.
|
|
78
|
+
*/
|
|
79
|
+
export declare function substituteCallResults(text: string, callResults: Record<string, unknown>): string;
|
|
80
|
+
/**
|
|
81
|
+
* Subagent Orchestrator - manages module-to-module calls.
|
|
82
|
+
*/
|
|
83
|
+
export declare class SubagentOrchestrator {
|
|
84
|
+
private llmCaller;
|
|
85
|
+
private running;
|
|
86
|
+
private cwd;
|
|
87
|
+
constructor(llmCaller: LLMCaller, cwd?: string);
|
|
88
|
+
/**
|
|
89
|
+
* Run a module with subagent support.
|
|
90
|
+
* Recursively resolves @call directives before final execution.
|
|
91
|
+
*/
|
|
92
|
+
run(moduleName: string, options?: Omit<SubagentRunOptions, 'llmCaller' | 'cwd'>, context?: SubagentContext): Promise<SubagentResult>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Run a module with subagent support.
|
|
96
|
+
*/
|
|
97
|
+
export declare function runWithSubagents(moduleName: string, options: SubagentRunOptions): Promise<SubagentResult>;
|
|
98
|
+
/**
|
|
99
|
+
* Check if a module prompt contains @call directives.
|
|
100
|
+
*/
|
|
101
|
+
export declare function hasSubagentCalls(prompt: string): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* List all modules called by a prompt (without executing).
|
|
104
|
+
*/
|
|
105
|
+
export declare function listSubagentCalls(prompt: string): string[];
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Subagent Orchestrator
|
|
7
|
+
* Orchestrate module calls with isolated execution contexts.
|
|
8
|
+
*
|
|
9
|
+
* Supports:
|
|
10
|
+
* - @call:module-name - Call another module
|
|
11
|
+
* - @call:module-name(args) - Call with arguments
|
|
12
|
+
* - context: fork - Isolated execution (no shared state)
|
|
13
|
+
* - context: main - Shared execution (default)
|
|
14
|
+
*/
|
|
15
|
+
import { findModule } from '../loader/module-loader.js';
|
|
16
|
+
import { getModuleSearchPaths } from '../paths.js';
|
|
17
|
+
import { executeModule } from './executor.js';
|
|
18
|
+
// =============================================================================
|
|
19
|
+
// Context Management
|
|
20
|
+
// =============================================================================
|
|
21
|
+
/**
|
|
22
|
+
* Create a new root context.
|
|
23
|
+
*/
|
|
24
|
+
export function createContext(maxDepth = 5) {
|
|
25
|
+
return {
|
|
26
|
+
parentId: null,
|
|
27
|
+
depth: 0,
|
|
28
|
+
maxDepth,
|
|
29
|
+
results: {},
|
|
30
|
+
isolated: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Fork context (isolated - no inherited results).
|
|
35
|
+
*/
|
|
36
|
+
export function forkContext(ctx, moduleName) {
|
|
37
|
+
return {
|
|
38
|
+
parentId: moduleName,
|
|
39
|
+
depth: ctx.depth + 1,
|
|
40
|
+
maxDepth: ctx.maxDepth,
|
|
41
|
+
results: {},
|
|
42
|
+
isolated: true,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Extend context (shared - inherits results).
|
|
47
|
+
*/
|
|
48
|
+
export function extendContext(ctx, moduleName) {
|
|
49
|
+
return {
|
|
50
|
+
parentId: moduleName,
|
|
51
|
+
depth: ctx.depth + 1,
|
|
52
|
+
maxDepth: ctx.maxDepth,
|
|
53
|
+
results: { ...ctx.results },
|
|
54
|
+
isolated: false,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// =============================================================================
|
|
58
|
+
// Call Parsing
|
|
59
|
+
// =============================================================================
|
|
60
|
+
// Pattern to match @call:module-name or @call:module-name(args)
|
|
61
|
+
const CALL_PATTERN = /@call:([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?/g;
|
|
62
|
+
/**
|
|
63
|
+
* Parse @call directives from text.
|
|
64
|
+
*/
|
|
65
|
+
export function parseCalls(text) {
|
|
66
|
+
const calls = [];
|
|
67
|
+
let match;
|
|
68
|
+
// Reset regex state
|
|
69
|
+
CALL_PATTERN.lastIndex = 0;
|
|
70
|
+
while ((match = CALL_PATTERN.exec(text)) !== null) {
|
|
71
|
+
calls.push({
|
|
72
|
+
module: match[1],
|
|
73
|
+
args: match[2] || '',
|
|
74
|
+
match: match[0],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return calls;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Replace @call directives with their results.
|
|
81
|
+
*/
|
|
82
|
+
export function substituteCallResults(text, callResults) {
|
|
83
|
+
let result = text;
|
|
84
|
+
for (const [callStr, callResult] of Object.entries(callResults)) {
|
|
85
|
+
const resultStr = typeof callResult === 'object'
|
|
86
|
+
? JSON.stringify(callResult, null, 2)
|
|
87
|
+
: String(callResult);
|
|
88
|
+
result = result.replace(callStr, `[Result from ${callStr}]:\n${resultStr}`);
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
// =============================================================================
|
|
93
|
+
// Orchestrator
|
|
94
|
+
// =============================================================================
|
|
95
|
+
/**
|
|
96
|
+
* Subagent Orchestrator - manages module-to-module calls.
|
|
97
|
+
*/
|
|
98
|
+
export class SubagentOrchestrator {
|
|
99
|
+
llmCaller;
|
|
100
|
+
running = new Set();
|
|
101
|
+
cwd;
|
|
102
|
+
constructor(llmCaller, cwd = process.cwd()) {
|
|
103
|
+
this.llmCaller = llmCaller;
|
|
104
|
+
this.cwd = cwd;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Run a module with subagent support.
|
|
108
|
+
* Recursively resolves @call directives before final execution.
|
|
109
|
+
*/
|
|
110
|
+
async run(moduleName, options = {}, context) {
|
|
111
|
+
const { input = {}, maxDepth = 5 } = options;
|
|
112
|
+
const callStack = [];
|
|
113
|
+
// Initialize context
|
|
114
|
+
const ctx = context ?? createContext(maxDepth);
|
|
115
|
+
// Check depth limit
|
|
116
|
+
if (ctx.depth > ctx.maxDepth) {
|
|
117
|
+
return {
|
|
118
|
+
ok: false,
|
|
119
|
+
error: {
|
|
120
|
+
code: 'MAX_DEPTH_EXCEEDED',
|
|
121
|
+
message: `Max subagent depth (${ctx.maxDepth}) exceeded. Check for circular calls.`,
|
|
122
|
+
},
|
|
123
|
+
callStack,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// Prevent circular calls
|
|
127
|
+
if (this.running.has(moduleName)) {
|
|
128
|
+
return {
|
|
129
|
+
ok: false,
|
|
130
|
+
error: {
|
|
131
|
+
code: 'CIRCULAR_CALL',
|
|
132
|
+
message: `Circular call detected: ${moduleName}`,
|
|
133
|
+
},
|
|
134
|
+
callStack,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
this.running.add(moduleName);
|
|
138
|
+
callStack.push(moduleName);
|
|
139
|
+
try {
|
|
140
|
+
// Find and load module
|
|
141
|
+
const searchPaths = getModuleSearchPaths(this.cwd);
|
|
142
|
+
const module = findModule(moduleName, searchPaths);
|
|
143
|
+
if (!module) {
|
|
144
|
+
return {
|
|
145
|
+
ok: false,
|
|
146
|
+
error: {
|
|
147
|
+
code: 'MODULE_NOT_FOUND',
|
|
148
|
+
message: `Module not found: ${moduleName}`,
|
|
149
|
+
},
|
|
150
|
+
callStack,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
// Check if this module wants isolated execution
|
|
154
|
+
// Note: 'context' field is optional in manifest, defaults to 'main'
|
|
155
|
+
const manifestRaw = module.manifest;
|
|
156
|
+
const moduleContextMode = manifestRaw['context'] || 'main';
|
|
157
|
+
// Parse @call directives from prompt
|
|
158
|
+
const calls = parseCalls(module.prompt);
|
|
159
|
+
const callResults = {};
|
|
160
|
+
// Resolve each @call directive
|
|
161
|
+
for (const call of calls) {
|
|
162
|
+
const childModule = call.module;
|
|
163
|
+
const childArgs = call.args;
|
|
164
|
+
// Prepare child input
|
|
165
|
+
const childInput = childArgs
|
|
166
|
+
? { query: childArgs, code: childArgs }
|
|
167
|
+
: { ...input };
|
|
168
|
+
// Determine child context
|
|
169
|
+
const childContext = moduleContextMode === 'fork'
|
|
170
|
+
? forkContext(ctx, moduleName)
|
|
171
|
+
: extendContext(ctx, moduleName);
|
|
172
|
+
// Recursively run child module
|
|
173
|
+
const childResult = await this.run(childModule, { input: childInput }, childContext);
|
|
174
|
+
// Add child call stack
|
|
175
|
+
callStack.push(...childResult.callStack.slice(1));
|
|
176
|
+
// Store result
|
|
177
|
+
if (childResult.ok && childResult.data) {
|
|
178
|
+
callResults[call.match] = childResult.data;
|
|
179
|
+
}
|
|
180
|
+
else if (childResult.error) {
|
|
181
|
+
callResults[call.match] = { error: childResult.error };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Substitute call results into prompt
|
|
185
|
+
let modifiedModule = module;
|
|
186
|
+
if (Object.keys(callResults).length > 0) {
|
|
187
|
+
const modifiedPrompt = substituteCallResults(module.prompt, callResults) +
|
|
188
|
+
'\n\n## Subagent Results Available\nThe @call results have been injected above. Use them in your response.\n';
|
|
189
|
+
modifiedModule = {
|
|
190
|
+
...module,
|
|
191
|
+
prompt: modifiedPrompt,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
// Run the module
|
|
195
|
+
const result = await executeModule({
|
|
196
|
+
module: modifiedModule,
|
|
197
|
+
input,
|
|
198
|
+
llmCaller: this.llmCaller,
|
|
199
|
+
});
|
|
200
|
+
// Store result in context
|
|
201
|
+
if (result.ok && 'data' in result) {
|
|
202
|
+
ctx.results[moduleName] = result['data'];
|
|
203
|
+
}
|
|
204
|
+
// Convert to SubagentResult
|
|
205
|
+
return {
|
|
206
|
+
ok: result.ok,
|
|
207
|
+
data: result.ok ? result['data'] : undefined,
|
|
208
|
+
error: !result.ok
|
|
209
|
+
? result['error']
|
|
210
|
+
: undefined,
|
|
211
|
+
meta: 'meta' in result ? result['meta'] : undefined,
|
|
212
|
+
callStack,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
finally {
|
|
216
|
+
this.running.delete(moduleName);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// =============================================================================
|
|
221
|
+
// Convenience Functions
|
|
222
|
+
// =============================================================================
|
|
223
|
+
/**
|
|
224
|
+
* Run a module with subagent support.
|
|
225
|
+
*/
|
|
226
|
+
export async function runWithSubagents(moduleName, options) {
|
|
227
|
+
const { llmCaller, cwd = process.cwd(), ...runOptions } = options;
|
|
228
|
+
if (!llmCaller) {
|
|
229
|
+
return {
|
|
230
|
+
ok: false,
|
|
231
|
+
error: {
|
|
232
|
+
code: 'NO_LLM_CALLER',
|
|
233
|
+
message: 'LLM caller is required for subagent execution',
|
|
234
|
+
},
|
|
235
|
+
callStack: [],
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
const orchestrator = new SubagentOrchestrator(llmCaller, cwd);
|
|
239
|
+
return orchestrator.run(moduleName, runOptions);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Check if a module prompt contains @call directives.
|
|
243
|
+
*/
|
|
244
|
+
export function hasSubagentCalls(prompt) {
|
|
245
|
+
CALL_PATTERN.lastIndex = 0;
|
|
246
|
+
return CALL_PATTERN.test(prompt);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* List all modules called by a prompt (without executing).
|
|
250
|
+
*/
|
|
251
|
+
export function listSubagentCalls(prompt) {
|
|
252
|
+
const calls = parseCalls(prompt);
|
|
253
|
+
return [...new Set(calls.map((c) => c.module))];
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=subagent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent.js","sourceRoot":"","sources":["../../../../src/cognitive/runtime/subagent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,aAAa,EAAkB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;IAE3B,MAAM,EAAE,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IAElE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;YACL,EAAE,EAAE,KAAK;YACT,KAAK,EAAE;gBACL,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,+CAA+C;aACzD;YACD,SAAS,EAAE,EAAE;SACd,CAAC;IACJ,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,oBAAoB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAC9D,OAAO,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,YAAY,CAAC,SAAS,GAAG,CAAC,CAAC;IAC3B,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -8,13 +8,13 @@ export function performInit(doesGeminiMdExist) {
|
|
|
8
8
|
return {
|
|
9
9
|
type: 'message',
|
|
10
10
|
messageType: 'info',
|
|
11
|
-
content: 'A
|
|
11
|
+
content: 'A FIELD.md file already exists in this directory. No changes were made.',
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
return {
|
|
15
15
|
type: 'submit_prompt',
|
|
16
16
|
content: `
|
|
17
|
-
You are an AI agent that brings the power of Gemini directly into the terminal. Your task is to analyze the current directory and generate a comprehensive
|
|
17
|
+
You are an AI agent that brings the power of Gemini directly into the terminal. Your task is to analyze the current directory and generate a comprehensive FIELD.md file to be used as instructional context for future interactions.
|
|
18
18
|
|
|
19
19
|
**Analysis Process:**
|
|
20
20
|
|
|
@@ -30,7 +30,7 @@ You are an AI agent that brings the power of Gemini directly into the terminal.
|
|
|
30
30
|
* **Code Project:** Look for clues like \`package.json\`, \`requirements.txt\`, \`pom.xml\`, \`go.mod\`, \`Cargo.toml\`, \`build.gradle\`, or a \`src\` directory. If you find them, this is likely a software project.
|
|
31
31
|
* **Non-Code Project:** If you don't find code-related files, this might be a directory for documentation, research papers, notes, or something else.
|
|
32
32
|
|
|
33
|
-
**
|
|
33
|
+
**FIELD.md Content Generation:**
|
|
34
34
|
|
|
35
35
|
**For a Code Project:**
|
|
36
36
|
|
|
@@ -46,7 +46,7 @@ You are an AI agent that brings the power of Gemini directly into the terminal.
|
|
|
46
46
|
|
|
47
47
|
**Final Output:**
|
|
48
48
|
|
|
49
|
-
Write the complete content to the \`
|
|
49
|
+
Write the complete content to the \`FIELD.md\` file. The output must be well-formatted Markdown.
|
|
50
50
|
`,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,UAAU,WAAW,CAAC,iBAA0B;IACpD,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO;YACL,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,MAAM;YACnB,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,UAAU,WAAW,CAAC,iBAA0B;IACpD,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO;YACL,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,MAAM;YACnB,OAAO,EACL,yEAAyE;SAC5E,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCZ;KACE,CAAC;AACJ,CAAC"}
|
|
@@ -66,10 +66,10 @@ export function listMemoryFiles(config) {
|
|
|
66
66
|
const fileCount = filePaths.length;
|
|
67
67
|
let content;
|
|
68
68
|
if (fileCount > 0) {
|
|
69
|
-
content = `There are ${fileCount}
|
|
69
|
+
content = `There are ${fileCount} FIELD.md file(s) in use:\n\n${filePaths.join('\n')}`;
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
content = 'No
|
|
72
|
+
content = 'No FIELD.md files in use.';
|
|
73
73
|
}
|
|
74
74
|
return {
|
|
75
75
|
type: 'message',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/commands/memory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,+BAA+B,EAAE,MAAM,6BAA6B,CAAC;AAG9E,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC;IACnD,MAAM,SAAS,GAAG,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IACrD,IAAI,OAAe,CAAC;IAEpB,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO,GAAG,+BAA+B,SAAS,qBAAqB,aAAa,OAAO,CAAC;IAC9F,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,4BAA4B,CAAC;IACzC,CAAC;IAED,OAAO;QACL,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,MAAM;QACnB,OAAO;KACR,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,IAAa;IAEb,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAChC,OAAO;YACL,IAAI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 @@ export declare class Config {
|
|
|
602
602
|
getGeminiClient(): GeminiClient;
|
|
603
603
|
/**
|
|
604
604
|
* Updates the system instruction with the latest user memory.
|
|
605
|
-
* Whenever the user memory (
|
|
605
|
+
* Whenever the user memory (FIELD.md files) is updated.
|
|
606
606
|
*/
|
|
607
607
|
updateSystemInstructionIfInitialized(): void;
|
|
608
608
|
getModelRouterService(): ModelRouterService;
|
|
@@ -25,7 +25,7 @@ import { WebFetchTool } from '../tools/web-fetch.js';
|
|
|
25
25
|
import { MemoryTool, setGeminiMdFilename } from '../tools/memoryTool.js';
|
|
26
26
|
import { WebSearchTool } from '../tools/web-search.js';
|
|
27
27
|
import { discoverAndRegisterCognitiveTools } from '../cognitive/integration.js';
|
|
28
|
-
import {
|
|
28
|
+
import { createLLMCallerFromContentGenerator } from '../cognitive/gemini-adapter.js';
|
|
29
29
|
import { AskUserTool } from '../tools/ask-user.js';
|
|
30
30
|
import { GeminiClient } from '../core/client.js';
|
|
31
31
|
import { BaseLlmClient } from '../core/baseLlmClient.js';
|
|
@@ -1025,7 +1025,7 @@ export class Config {
|
|
|
1025
1025
|
}
|
|
1026
1026
|
/**
|
|
1027
1027
|
* Updates the system instruction with the latest user memory.
|
|
1028
|
-
* Whenever the user memory (
|
|
1028
|
+
* Whenever the user memory (FIELD.md files) is updated.
|
|
1029
1029
|
*/
|
|
1030
1030
|
updateSystemInstructionIfInitialized() {
|
|
1031
1031
|
const geminiClient = this.getGeminiClient();
|
|
@@ -1496,8 +1496,12 @@ export class Config {
|
|
|
1496
1496
|
*/
|
|
1497
1497
|
async registerCognitiveTools(registry) {
|
|
1498
1498
|
try {
|
|
1499
|
-
// Create LLM caller
|
|
1500
|
-
|
|
1499
|
+
// Create LLM caller using the same ContentGenerator as the main CLI
|
|
1500
|
+
// This ensures Cognitive modules use the same model/auth as the user
|
|
1501
|
+
let llmCaller = undefined;
|
|
1502
|
+
if (this.contentGenerator) {
|
|
1503
|
+
llmCaller = createLLMCallerFromContentGenerator(this.contentGenerator, this);
|
|
1504
|
+
}
|
|
1501
1505
|
// Discover and register cognitive modules
|
|
1502
1506
|
const tools = await discoverAndRegisterCognitiveTools(registry, this.messageBus, { enabled: true }, llmCaller);
|
|
1503
1507
|
if (tools.length > 0) {
|