bernard-agent 0.8.1 → 0.9.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/README.md +80 -44
- package/dist/agent.d.ts +14 -3
- package/dist/agent.js +228 -38
- package/dist/agent.js.map +1 -1
- package/dist/builtin-specialists/correction-agent.json +32 -0
- package/dist/builtin-specialists/file-wrapper.json +43 -0
- package/dist/builtin-specialists/shell-wrapper.json +50 -0
- package/dist/builtin-specialists/specialist-creator.json +32 -0
- package/dist/builtin-specialists/web-wrapper.json +38 -0
- package/dist/candidate-bootstrap.d.ts +18 -0
- package/dist/candidate-bootstrap.js +61 -0
- package/dist/candidate-bootstrap.js.map +1 -0
- package/dist/config.d.ts +126 -10
- package/dist/config.js +222 -45
- package/dist/config.js.map +1 -1
- package/dist/context.js +23 -6
- package/dist/context.js.map +1 -1
- package/dist/correction-candidates.d.ts +54 -0
- package/dist/correction-candidates.js +138 -0
- package/dist/correction-candidates.js.map +1 -0
- package/dist/correction.d.ts +67 -0
- package/dist/correction.js +138 -0
- package/dist/correction.js.map +1 -0
- package/dist/critic.js +2 -1
- package/dist/critic.js.map +1 -1
- package/dist/cron/notes-store.d.ts +41 -0
- package/dist/cron/notes-store.js +134 -0
- package/dist/cron/notes-store.js.map +1 -0
- package/dist/cron/runner.js +25 -3
- package/dist/cron/runner.js.map +1 -1
- package/dist/cron/scoped-notes-tools.d.ts +24 -0
- package/dist/cron/scoped-notes-tools.js +50 -0
- package/dist/cron/scoped-notes-tools.js.map +1 -0
- package/dist/custom-providers.d.ts +80 -0
- package/dist/custom-providers.js +238 -0
- package/dist/custom-providers.js.map +1 -0
- package/dist/fs-utils.d.ts +2 -0
- package/dist/fs-utils.js +44 -0
- package/dist/fs-utils.js.map +1 -0
- package/dist/history.js +3 -1
- package/dist/history.js.map +1 -1
- package/dist/image.d.ts +59 -0
- package/dist/image.js +228 -0
- package/dist/image.js.map +1 -0
- package/dist/index.js +72 -4
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +1 -1
- package/dist/mcp.js.map +1 -1
- package/dist/memory.d.ts +13 -0
- package/dist/memory.js +45 -4
- package/dist/memory.js.map +1 -1
- package/dist/menu.d.ts +97 -0
- package/dist/menu.js +338 -0
- package/dist/menu.js.map +1 -0
- package/dist/os-info.d.ts +22 -0
- package/dist/os-info.js +111 -0
- package/dist/os-info.js.map +1 -0
- package/dist/output.d.ts +35 -1
- package/dist/output.js +256 -45
- package/dist/output.js.map +1 -1
- package/dist/pac.d.ts +14 -2
- package/dist/pac.js +5 -5
- package/dist/pac.js.map +1 -1
- package/dist/paths.d.ts +5 -0
- package/dist/paths.js +6 -1
- package/dist/paths.js.map +1 -1
- package/dist/plan-store.d.ts +47 -0
- package/dist/plan-store.js +94 -0
- package/dist/plan-store.js.map +1 -0
- package/dist/prompt-rewriter.d.ts +29 -0
- package/dist/prompt-rewriter.js +155 -0
- package/dist/prompt-rewriter.js.map +1 -0
- package/dist/providers/index.d.ts +56 -4
- package/dist/providers/index.js +86 -5
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/profiles.d.ts +37 -0
- package/dist/providers/profiles.js +110 -0
- package/dist/providers/profiles.js.map +1 -0
- package/dist/providers/types.d.ts +11 -2
- package/dist/providers/types.js +3 -0
- package/dist/providers/types.js.map +1 -1
- package/dist/rag-query.js +15 -1
- package/dist/rag-query.js.map +1 -1
- package/dist/react.d.ts +38 -0
- package/dist/react.js +116 -0
- package/dist/react.js.map +1 -0
- package/dist/reasoning-log.d.ts +30 -0
- package/dist/reasoning-log.js +102 -0
- package/dist/reasoning-log.js.map +1 -0
- package/dist/reference-resolver.d.ts +47 -0
- package/dist/reference-resolver.js +316 -0
- package/dist/reference-resolver.js.map +1 -0
- package/dist/reference-tool-lookup.d.ts +37 -0
- package/dist/reference-tool-lookup.js +318 -0
- package/dist/reference-tool-lookup.js.map +1 -0
- package/dist/repl.js +1038 -371
- package/dist/repl.js.map +1 -1
- package/dist/setup.js +2 -1
- package/dist/setup.js.map +1 -1
- package/dist/specialist-detector.js +2 -1
- package/dist/specialist-detector.js.map +1 -1
- package/dist/specialists.d.ts +74 -3
- package/dist/specialists.js +152 -20
- package/dist/specialists.js.map +1 -1
- package/dist/structured-output.d.ts +58 -0
- package/dist/structured-output.js +138 -0
- package/dist/structured-output.js.map +1 -0
- package/dist/theme.d.ts +2 -0
- package/dist/theme.js +18 -12
- package/dist/theme.js.map +1 -1
- package/dist/tool-call-repair.d.ts +29 -0
- package/dist/tool-call-repair.js +99 -0
- package/dist/tool-call-repair.js.map +1 -0
- package/dist/tool-profiles.d.ts +70 -0
- package/dist/tool-profiles.js +385 -0
- package/dist/tool-profiles.js.map +1 -0
- package/dist/tools/activity-summary.d.ts +15 -0
- package/dist/tools/activity-summary.js +44 -0
- package/dist/tools/activity-summary.js.map +1 -0
- package/dist/tools/ask-user.d.ts +49 -0
- package/dist/tools/ask-user.js +52 -0
- package/dist/tools/ask-user.js.map +1 -0
- package/dist/tools/augment.d.ts +17 -0
- package/dist/tools/augment.js +102 -0
- package/dist/tools/augment.js.map +1 -0
- package/dist/tools/cron-logs.js +7 -0
- package/dist/tools/cron-logs.js.map +1 -1
- package/dist/tools/cron-notes.d.ts +52 -0
- package/dist/tools/cron-notes.js +105 -0
- package/dist/tools/cron-notes.js.map +1 -0
- package/dist/tools/datetime.d.ts +7 -0
- package/dist/tools/datetime.js +29 -3
- package/dist/tools/datetime.js.map +1 -1
- package/dist/tools/evaluate.d.ts +20 -0
- package/dist/tools/evaluate.js +29 -0
- package/dist/tools/evaluate.js.map +1 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/mcp.d.ts +3 -3
- package/dist/tools/plan.d.ts +81 -0
- package/dist/tools/plan.js +108 -0
- package/dist/tools/plan.js.map +1 -0
- package/dist/tools/result-cap.d.ts +24 -0
- package/dist/tools/result-cap.js +44 -0
- package/dist/tools/result-cap.js.map +1 -0
- package/dist/tools/routine.d.ts +3 -3
- package/dist/tools/shell.d.ts +14 -1
- package/dist/tools/shell.js +86 -4
- package/dist/tools/shell.js.map +1 -1
- package/dist/tools/specialist-run.d.ts +5 -3
- package/dist/tools/specialist-run.js +115 -24
- package/dist/tools/specialist-run.js.map +1 -1
- package/dist/tools/specialist.d.ts +83 -3
- package/dist/tools/specialist.js +83 -3
- package/dist/tools/specialist.js.map +1 -1
- package/dist/tools/subagent.js +32 -14
- package/dist/tools/subagent.js.map +1 -1
- package/dist/tools/task.d.ts +5 -5
- package/dist/tools/task.js +9 -42
- package/dist/tools/task.js.map +1 -1
- package/dist/tools/think.d.ts +18 -0
- package/dist/tools/think.js +25 -0
- package/dist/tools/think.js.map +1 -0
- package/dist/tools/tool-wrapper-run.d.ts +121 -0
- package/dist/tools/tool-wrapper-run.js +382 -0
- package/dist/tools/tool-wrapper-run.js.map +1 -0
- package/dist/tools/types.d.ts +28 -2
- package/dist/tools/web-search.d.ts +31 -0
- package/dist/tools/web-search.js +172 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/wrap-with-specialist.d.ts +55 -0
- package/dist/tools/wrap-with-specialist.js +137 -0
- package/dist/tools/wrap-with-specialist.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Model-specific prompt optimization profiles.
|
|
4
|
+
*
|
|
5
|
+
* Each provider + model family has a {@link ModelProfile} that adjusts how a user
|
|
6
|
+
* message is wrapped and what short advisory block is appended to the system
|
|
7
|
+
* prompt. Profiles are resolved once per turn and applied deterministically —
|
|
8
|
+
* no extra LLM call. Cache-safe: the system-prompt suffix depends only on the
|
|
9
|
+
* selected model, not on the user's input, so the KV-cache prefix stays stable
|
|
10
|
+
* across a session with a fixed model.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.getModelProfile = getModelProfile;
|
|
14
|
+
const ANTHROPIC_SUFFIX = `## Model Notes
|
|
15
|
+
This model responds best to XML-structured input. User-authored text is wrapped in a \`<user_request>\` tag to make the primary instruction explicit. Treat the tag contents as the authoritative request; also attend to other content supplied with the same user turn (attached images, system-inserted context notices) as relevant context. Text outside the tag is not a new standalone instruction from the user.`;
|
|
16
|
+
const OPENAI_REASONING_SUFFIX = `Formatting re-enabled
|
|
17
|
+
|
|
18
|
+
## Model Notes
|
|
19
|
+
This model reasons internally. Do not narrate chain-of-thought ("think step by step", "explain your reasoning before acting") — state conclusions and take actions directly. Prefer zero-shot; keep instructions terse.`;
|
|
20
|
+
const OPENAI_STANDARD_SUFFIX = `## Model Notes
|
|
21
|
+
- Persistence: keep working until the user's request is fully resolved before yielding.
|
|
22
|
+
- Tool-calling: if you are unsure about file content or codebase structure, call a tool to read it — do not guess.
|
|
23
|
+
- Planning: plan before each function call and reflect on the outcome of the previous call before the next.`;
|
|
24
|
+
const XAI_REASONING_SUFFIX = `## Model Notes
|
|
25
|
+
This model reasons internally. Do not narrate chain-of-thought ("think step by step", "explain your reasoning before acting") — state conclusions and take actions directly. Keep instructions terse.`;
|
|
26
|
+
const ANTHROPIC_REWRITER_HINT = 'Use natural prose framed with XML-style tags (<task>, <context>, <constraints>) when the request has distinct parts. Keep the original voice; do not over-structure short conversational requests.';
|
|
27
|
+
const OPENAI_REASONING_REWRITER_HINT = 'Keep the rewrite terse. Drop filler ("please", "could you"). One or two short paragraphs or a tight bullet list is ideal. No chain-of-thought prompts.';
|
|
28
|
+
const OPENAI_STANDARD_REWRITER_HINT = 'Prefer explicit "Task:", "Constraints:", and "Output:" sections when the request has multiple parts. Keep very short requests in natural prose.';
|
|
29
|
+
const XAI_REASONING_REWRITER_HINT = 'Terse and direct. Strip conversational padding. State the goal in one or two sentences; add a short numbered list only when multiple distinct steps are implied.';
|
|
30
|
+
const XAI_STANDARD_REWRITER_HINT = 'Direct, explicit, minimal verbosity. A short "Task: … / Requirements: …" shape works well for compound requests.';
|
|
31
|
+
const DEFAULT_REWRITER_HINT = 'Keep the rewrite close to the original phrasing. Only add structure when the original has multiple distinct parts.';
|
|
32
|
+
const DEFAULT_PROFILE = {
|
|
33
|
+
family: 'default',
|
|
34
|
+
wrapUserMessage: (msg) => msg,
|
|
35
|
+
systemSuffix: '',
|
|
36
|
+
rewriterHint: DEFAULT_REWRITER_HINT,
|
|
37
|
+
};
|
|
38
|
+
const ANTHROPIC_PROFILE = {
|
|
39
|
+
family: 'anthropic-claude',
|
|
40
|
+
wrapUserMessage: (msg) => `<user_request>\n${msg}\n</user_request>`,
|
|
41
|
+
systemSuffix: ANTHROPIC_SUFFIX,
|
|
42
|
+
rewriterHint: ANTHROPIC_REWRITER_HINT,
|
|
43
|
+
};
|
|
44
|
+
const OPENAI_REASONING_PROFILE = {
|
|
45
|
+
family: 'openai-reasoning',
|
|
46
|
+
wrapUserMessage: (msg) => msg,
|
|
47
|
+
systemSuffix: OPENAI_REASONING_SUFFIX,
|
|
48
|
+
rewriterHint: OPENAI_REASONING_REWRITER_HINT,
|
|
49
|
+
};
|
|
50
|
+
const OPENAI_STANDARD_PROFILE = {
|
|
51
|
+
family: 'openai-standard',
|
|
52
|
+
wrapUserMessage: (msg) => `# Request\n${msg}`,
|
|
53
|
+
systemSuffix: OPENAI_STANDARD_SUFFIX,
|
|
54
|
+
rewriterHint: OPENAI_STANDARD_REWRITER_HINT,
|
|
55
|
+
};
|
|
56
|
+
const XAI_REASONING_PROFILE = {
|
|
57
|
+
family: 'xai-grok-reasoning',
|
|
58
|
+
wrapUserMessage: (msg) => msg,
|
|
59
|
+
systemSuffix: XAI_REASONING_SUFFIX,
|
|
60
|
+
rewriterHint: XAI_REASONING_REWRITER_HINT,
|
|
61
|
+
};
|
|
62
|
+
const XAI_STANDARD_PROFILE = {
|
|
63
|
+
family: 'xai-grok-standard',
|
|
64
|
+
wrapUserMessage: (msg) => `# Request\n${msg}`,
|
|
65
|
+
systemSuffix: '',
|
|
66
|
+
rewriterHint: XAI_STANDARD_REWRITER_HINT,
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Resolves the {@link ModelProfile} for a provider + model pair.
|
|
70
|
+
*
|
|
71
|
+
* Matching is first-match-wins and pattern-based so new models in an existing
|
|
72
|
+
* family pick up the right profile automatically. Unknown combinations fall
|
|
73
|
+
* back to a conservative passthrough profile.
|
|
74
|
+
*
|
|
75
|
+
* For custom providers (user-defined endpoints that wrap an installed AI-SDK)
|
|
76
|
+
* pass the wrapped SDK family via `sdk` so the model picks up family-specific
|
|
77
|
+
* prompt tuning regardless of the registered provider name.
|
|
78
|
+
*/
|
|
79
|
+
function getModelProfile(provider, model, sdk) {
|
|
80
|
+
const m = model.toLowerCase();
|
|
81
|
+
const family = sdk ?? provider;
|
|
82
|
+
if (family === 'anthropic') {
|
|
83
|
+
return ANTHROPIC_PROFILE;
|
|
84
|
+
}
|
|
85
|
+
if (family === 'openai') {
|
|
86
|
+
// o-series reasoning models: o1, o3, o3-mini, o4-mini, …
|
|
87
|
+
if (/^o\d/.test(m))
|
|
88
|
+
return OPENAI_REASONING_PROFILE;
|
|
89
|
+
return OPENAI_STANDARD_PROFILE;
|
|
90
|
+
}
|
|
91
|
+
if (family === 'xai') {
|
|
92
|
+
// Explicit non-reasoning variants take precedence over the generic grok-4 rule.
|
|
93
|
+
if (m.includes('non-reasoning'))
|
|
94
|
+
return XAI_STANDARD_PROFILE;
|
|
95
|
+
if (m.includes('reasoning'))
|
|
96
|
+
return XAI_REASONING_PROFILE;
|
|
97
|
+
// Grok 4.x is a reasoning family by default unless tagged otherwise.
|
|
98
|
+
if (/^grok-4(\b|[-.])/.test(m))
|
|
99
|
+
return XAI_REASONING_PROFILE;
|
|
100
|
+
return XAI_STANDARD_PROFILE;
|
|
101
|
+
}
|
|
102
|
+
return DEFAULT_PROFILE;
|
|
103
|
+
}
|
|
104
|
+
// References for maintainers updating the suffix constants:
|
|
105
|
+
// https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices
|
|
106
|
+
// https://developers.openai.com/cookbook/examples/gpt4-1_prompting_guide
|
|
107
|
+
// https://developers.openai.com/cookbook/examples/gpt-5/gpt-5_prompting_guide
|
|
108
|
+
// https://developers.openai.com/api/docs/guides/reasoning-best-practices
|
|
109
|
+
// https://docs.x.ai/docs/guides/chat
|
|
110
|
+
//# sourceMappingURL=profiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/providers/profiles.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAyGH,0CA4BC;AAnHD,MAAM,gBAAgB,GAAG;yZACgY,CAAC;AAE1Z,MAAM,uBAAuB,GAAG;;;wNAGwL,CAAC;AAEzN,MAAM,sBAAsB,GAAG;;;4GAG6E,CAAC;AAE7G,MAAM,oBAAoB,GAAG;sMACyK,CAAC;AAEvM,MAAM,uBAAuB,GAC3B,oMAAoM,CAAC;AAEvM,MAAM,8BAA8B,GAClC,wJAAwJ,CAAC;AAE3J,MAAM,6BAA6B,GACjC,iJAAiJ,CAAC;AAEpJ,MAAM,2BAA2B,GAC/B,kKAAkK,CAAC;AAErK,MAAM,0BAA0B,GAC9B,kHAAkH,CAAC;AAErH,MAAM,qBAAqB,GACzB,oHAAoH,CAAC;AAEvH,MAAM,eAAe,GAAiB;IACpC,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG;IAC7B,YAAY,EAAE,EAAE;IAChB,YAAY,EAAE,qBAAqB;CACpC,CAAC;AAEF,MAAM,iBAAiB,GAAiB;IACtC,MAAM,EAAE,kBAAkB;IAC1B,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,GAAG,mBAAmB;IACnE,YAAY,EAAE,gBAAgB;IAC9B,YAAY,EAAE,uBAAuB;CACtC,CAAC;AAEF,MAAM,wBAAwB,GAAiB;IAC7C,MAAM,EAAE,kBAAkB;IAC1B,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC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AC,WAAW,CAAC;YAAE,OAAO,qBAAqB,CAAC;QAC1D,qEAAqE;QACrE,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;YAAE,OAAO,qBAAqB,CAAC;QAC7D,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,4DAA4D;AAC5D,6GAA6G;AAC7G,2EAA2E;AAC3E,gFAAgF;AAChF,2EAA2E;AAC3E,uCAAuC"}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export type
|
|
1
|
+
/** The three AI-SDK packages we ship; custom providers must wrap one of these. */
|
|
2
|
+
export type SupportedSdk = 'anthropic' | 'openai' | 'xai';
|
|
3
|
+
/** Built-in provider identifiers — fall back to the official endpoints. */
|
|
4
|
+
export declare const BUILTIN_PROVIDERS: readonly ["anthropic", "openai", "xai"];
|
|
5
|
+
export type BuiltinProvider = (typeof BUILTIN_PROVIDERS)[number];
|
|
6
|
+
/**
|
|
7
|
+
* Provider identifier — `'anthropic' | 'openai' | 'xai'` for built-ins, or any
|
|
8
|
+
* user-chosen name registered as a custom provider. The literal union documents
|
|
9
|
+
* intent; runtime values are plain strings.
|
|
10
|
+
*/
|
|
11
|
+
export type ProviderName = BuiltinProvider | (string & {});
|
|
3
12
|
/** Provider and model pair used to instantiate an AI SDK `LanguageModel`. */
|
|
4
13
|
export interface ProviderConfig {
|
|
5
14
|
/** Which LLM provider to use. */
|
package/dist/providers/types.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BUILTIN_PROVIDERS = void 0;
|
|
4
|
+
/** Built-in provider identifiers — fall back to the official endpoints. */
|
|
5
|
+
exports.BUILTIN_PROVIDERS = ['anthropic', 'openai', 'xai'];
|
|
3
6
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":";;;AAGA,2EAA2E;AAC9D,QAAA,iBAAiB,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAU,CAAC"}
|
package/dist/rag-query.js
CHANGED
|
@@ -19,6 +19,20 @@ const BOUNDARY_PREFIXES = [
|
|
|
19
19
|
'[Previous session ended',
|
|
20
20
|
'[Earlier conversation was truncated',
|
|
21
21
|
];
|
|
22
|
+
/**
|
|
23
|
+
* Strip model-profile wrappers applied by `wrapUserMessage` (XML tag for Claude,
|
|
24
|
+
* `# Request` heading for standard OpenAI/xAI). Passthrough profiles are no-ops.
|
|
25
|
+
* Kept in sync with `src/providers/profiles.ts` by shape, not import, to avoid
|
|
26
|
+
* cycling the providers module into RAG.
|
|
27
|
+
*/
|
|
28
|
+
function stripProfileWrapper(text) {
|
|
29
|
+
const xmlMatch = text.match(/^<user_request>\n([\s\S]*)\n<\/user_request>$/);
|
|
30
|
+
if (xmlMatch)
|
|
31
|
+
return xmlMatch[1];
|
|
32
|
+
if (text.startsWith('# Request\n'))
|
|
33
|
+
return text.slice('# Request\n'.length);
|
|
34
|
+
return text;
|
|
35
|
+
}
|
|
22
36
|
/**
|
|
23
37
|
* Walk history backward and collect up to `maxMessages` user-role text strings.
|
|
24
38
|
* Skips system-injected boundary messages (context summaries, session markers).
|
|
@@ -36,7 +50,7 @@ function extractRecentUserTexts(history, maxMessages = exports.DEFAULT_WINDOW_SI
|
|
|
36
50
|
// Skip system-injected boundary messages
|
|
37
51
|
if (BOUNDARY_PREFIXES.some((prefix) => text.startsWith(prefix)))
|
|
38
52
|
continue;
|
|
39
|
-
texts.push((0, datetime_js_1.stripTimestamp)(text));
|
|
53
|
+
texts.push((0, datetime_js_1.stripTimestamp)(stripProfileWrapper(text)));
|
|
40
54
|
}
|
|
41
55
|
// Reverse to chronological order (oldest first)
|
|
42
56
|
texts.reverse();
|
package/dist/rag-query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rag-query.js","sourceRoot":"","sources":["../src/rag-query.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"rag-query.js","sourceRoot":"","sources":["../src/rag-query.ts"],"names":[],"mappings":";;;AAqCA,wDAsBC;AA0BD,4DAiCC;AAeD,sCAmCC;AAiBD,0CAgCC;AAxND,6CAA2C;AAE3C,qCAAyE;AACzE,qDAAqD;AAErD,6FAA6F;AAChF,QAAA,mBAAmB,GAAG,CAAC,CAAC;AACrC,kEAAkE;AACrD,QAAA,uBAAuB,GAAG,IAAI,CAAC;AAC5C,4FAA4F;AAC/E,QAAA,wBAAwB,GAAG,IAAI,CAAC;AAE7C,MAAM,iBAAiB,GAAG;IACxB,kBAAkB;IAClB,yBAAyB;IACzB,qCAAqC;CACtC,CAAC;AAEF;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,IAAY;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;IAC7E,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;IACjC,IAAI,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5E,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CACpC,OAAsB,EACtB,cAAsB,2BAAmB;IAEzC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3E,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,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AK,IAAI,aAAa;YAAE,SAAS;QACrC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QAC3C,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtB,IAAI,QAAQ,CAAC,MAAM,IAAI,UAAU;YAAE,MAAM;IAC3C,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ReAct (coordinator) mode primitives shared by the main agent and specialist
|
|
3
|
+
* dispatch tools (`specialist_run`). Extracted from `agent.ts` so tools — which
|
|
4
|
+
* are imported BY agent.ts — can use them without forming a circular import.
|
|
5
|
+
*/
|
|
6
|
+
export declare const REACT_COORDINATOR_PROMPT = "## Coordinator Mode (Active)\n\nYou are operating as a coordinator, not a sole executor. Your primary role is to decompose, delegate, and synthesize \u2014 not to do all work yourself.\n\n### Reason before acting\nBefore each tool call or batch of parallel calls, state in 1-3 sentences:\n- What you know so far\n- What gap this action fills\n- What success looks like\n\n### Delegate scoped work\nPrefer delegation for any work that can be expressed as a self-contained scope:\n- Information gathering (shell commands, file reads, web research) \u2192 agent or task\n- Structured data extraction or transformation \u2192 task\n- Domain-specific work matching a specialist \u2192 specialist_run or tool_wrapper_run\n\nDo the work yourself only when:\n- It requires conversation history a sub-agent cannot have\n- It is trivially small (1-2 tool calls) and delegation overhead is not worth it\n- You need intermediate results before deciding the next step\n\n### Treat subagent outputs as observations\nWhen a sub-agent returns, interpret the result \u2014 do not echo it. Extract the signal, discard the noise, and state what it means for the task. If a sub-agent returns 500 lines, your synthesis should be 2-5 sentences.\n\n### Context discipline\nDo not accumulate long chains of raw tool output in your reasoning. Once you have gathered sufficient information, synthesize it and move forward. Do not re-list everything you know \u2014 refer to prior findings and build on them.\n\n### The think \u2192 act \u2192 evaluate \u2192 decide loop\nEvery step follows the same rhythm. Do not skip stages.\n\n1. **Think** \u2014 call `think` with a 1-3 sentence statement of what you know, what gap the next action fills, and what success looks like.\n2. **Act** \u2014 make the tool call (or batch of parallel calls).\n3. **Stop and evaluate** \u2014 call `evaluate` immediately after the action completes. State in 1-3 sentences whether the result matched expectations, whether any surprise / error / risk was revealed, and whether to continue or course-correct. Be willing to catch yourself \u2014 \"Actually, that's not right because...\" or \"Wait \u2014 this might make things worse, let me take a different approach\" is exactly what evaluate is for.\n4. **Decide** \u2014 based on the evaluation, either continue to the next think/act or go back and try a different approach. If you course-correct, say so before acting.\n\nSkip this full cycle only for trivially small work (1-2 tool calls). For any non-trivial step, all four stages happen.\n\n### Use the `plan` tool\n\n**At the start of each new user request**, assess whether the task requires planning. Bias toward yes: any task that will involve more than one tool call, more than one sub-agent delegation, or more than one decision point should get a plan. Only skip planning for trivially small work (1-2 tool calls).\n\n**The plan store is reset on every user turn.** Any `plan` tool calls visible in earlier turns of the conversation are stale \u2014 their step IDs no longer exist. Start fresh by calling `plan` with action `create` and an ordered list of step objects. Do not try to `update` IDs from a previous turn; they will not resolve.\n\n**Each step has two parts at creation time:**\n- `description`: what the step accomplishes.\n- `verification`: a concrete, observable check that will prove the step succeeded \u2014 a command to run, a file/URL to read, a specific output substring, an exit code, a status code. Must be something a third party could re-run; never subjective (\"looks right\", \"should work\").\n\n**Step lifecycle:**\n- Before starting a step: `update` it to `in_progress`.\n- After completing it: actually run the verification, then `update` to `done` with a `signoff` that cites the concrete evidence you observed (command output excerpt, file contents, status code, URL, etc.). The sign-off is your attestation that the verification was performed \u2014 not a restatement of the description. If the verification has not been run, the step is not done.\n- If a step becomes unnecessary (user pivoted, work no longer needed): mark it `cancelled` with a `note`.\n- If a step is genuinely unachievable, or verification failed and you cannot fix it (permission denied, resource missing, tool broken): mark it `error` with a `note` explaining what went wrong. Do not sign off on a step whose verification did not pass \u2014 mark it `error` and adapt the plan instead.\n- If a step needs user input to proceed (intent, choice, missing argument), call the `ask_user` tool from inside the step. The answer comes back as the tool result; use it to continue. Never end the turn with a question written in prose \u2014 enforcement will trigger and the turn will be auto-cancelled before the user can answer.\n\n**Before composing your final response**, verify every step is in a terminal state (`done`, `cancelled`, or `error`) and that every `done` step carries a sign-off. If you are giving up on the task \u2014 partially or fully \u2014 mark the remaining non-terminal steps `cancelled` or `error` with notes **before** writing the user-facing text. Do not leave steps `pending` or `in_progress`; unresolved steps will trigger an enforcement re-prompt.\n\n### Keep reflective notes in `scratch`\nThe `plan` note is a one-line summary \u2014 `scratch` is where the evidence lives. For any non-trivial step:\n- After a substantive tool call, sub-agent return, or batch of parallel calls, write a scratch entry with key `step-{id}` (or `findings-{topic}` for cross-cutting observations) containing: what you did, the concrete result (command output excerpts, file paths, numeric values, URLs \u2014 facts, not vibes), and any follow-ups this uncovered.\n- Update the same key as you learn more within a single step; do not spawn a new key per tool call.\n- Treat scratch as your working record. When you need to recall what happened several steps ago, read from scratch rather than scrolling back through tool results.\n\n### Synthesize the final response from scratch\nWhen all plan steps are in terminal states and you are ready to respond to the user:\n1. Call `scratch` with action `list` to see what you captured.\n2. Call `scratch` with action `read` for the relevant keys.\n3. Compose the response from those notes \u2014 not from the conversation tail. Conversation history is noisy and can include stale intermediate state; your scratch notes are the curated record of what actually happened.\n4. Skip this synthesis step only for trivial work where no plan was created.";
|
|
7
|
+
/**
|
|
8
|
+
* Pure predicate: should the ReAct plan-enforcement loop run after the main
|
|
9
|
+
* generateText call?
|
|
10
|
+
*/
|
|
11
|
+
export declare function shouldEnforcePlan(args: {
|
|
12
|
+
reactMode: boolean;
|
|
13
|
+
aborted: boolean;
|
|
14
|
+
stepLimitHit: boolean;
|
|
15
|
+
hasSteps: boolean;
|
|
16
|
+
}): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Upper ceiling on the per-turn step budget when reactMode triples maxSteps.
|
|
19
|
+
* Prevents pathological cost amplification when a user has set a high
|
|
20
|
+
* BERNARD_MAX_STEPS for the non-react path.
|
|
21
|
+
*/
|
|
22
|
+
export declare const REACT_MAX_STEPS_CEILING = 150;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the per-turn step budget for an agent loop. In reactMode the base
|
|
25
|
+
* budget is tripled (deliberation + delegation + synthesis), then clamped to
|
|
26
|
+
* {@link REACT_MAX_STEPS_CEILING} so a high base cannot blow up.
|
|
27
|
+
*/
|
|
28
|
+
export declare function computeEffectiveMaxSteps(maxSteps: number, reactMode: boolean): number;
|
|
29
|
+
/** Max plan-enforcement re-prompts after the main generateText call. */
|
|
30
|
+
export declare const REACT_ENFORCEMENT_MAX_RETRIES = 2;
|
|
31
|
+
/** Note attached to plan steps auto-cancelled after enforcement retries are exhausted. */
|
|
32
|
+
export declare const REACT_AUTO_CANCEL_NOTE = "auto-cancelled: enforcement retries exhausted";
|
|
33
|
+
/**
|
|
34
|
+
* Builds the user-facing enforcement re-prompt used when a plan still has
|
|
35
|
+
* unresolved steps after the main generateText call. Shared by the agent and
|
|
36
|
+
* specialist enforcement loops so the wording cannot drift between the two.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildEnforcementFeedback(planRender: string): string;
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ReAct (coordinator) mode primitives shared by the main agent and specialist
|
|
4
|
+
* dispatch tools (`specialist_run`). Extracted from `agent.ts` so tools — which
|
|
5
|
+
* are imported BY agent.ts — can use them without forming a circular import.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.REACT_AUTO_CANCEL_NOTE = exports.REACT_ENFORCEMENT_MAX_RETRIES = exports.REACT_MAX_STEPS_CEILING = exports.REACT_COORDINATOR_PROMPT = void 0;
|
|
9
|
+
exports.shouldEnforcePlan = shouldEnforcePlan;
|
|
10
|
+
exports.computeEffectiveMaxSteps = computeEffectiveMaxSteps;
|
|
11
|
+
exports.buildEnforcementFeedback = buildEnforcementFeedback;
|
|
12
|
+
exports.REACT_COORDINATOR_PROMPT = `## Coordinator Mode (Active)
|
|
13
|
+
|
|
14
|
+
You are operating as a coordinator, not a sole executor. Your primary role is to decompose, delegate, and synthesize — not to do all work yourself.
|
|
15
|
+
|
|
16
|
+
### Reason before acting
|
|
17
|
+
Before each tool call or batch of parallel calls, state in 1-3 sentences:
|
|
18
|
+
- What you know so far
|
|
19
|
+
- What gap this action fills
|
|
20
|
+
- What success looks like
|
|
21
|
+
|
|
22
|
+
### Delegate scoped work
|
|
23
|
+
Prefer delegation for any work that can be expressed as a self-contained scope:
|
|
24
|
+
- Information gathering (shell commands, file reads, web research) → agent or task
|
|
25
|
+
- Structured data extraction or transformation → task
|
|
26
|
+
- Domain-specific work matching a specialist → specialist_run or tool_wrapper_run
|
|
27
|
+
|
|
28
|
+
Do the work yourself only when:
|
|
29
|
+
- It requires conversation history a sub-agent cannot have
|
|
30
|
+
- It is trivially small (1-2 tool calls) and delegation overhead is not worth it
|
|
31
|
+
- You need intermediate results before deciding the next step
|
|
32
|
+
|
|
33
|
+
### Treat subagent outputs as observations
|
|
34
|
+
When a sub-agent returns, interpret the result — do not echo it. Extract the signal, discard the noise, and state what it means for the task. If a sub-agent returns 500 lines, your synthesis should be 2-5 sentences.
|
|
35
|
+
|
|
36
|
+
### Context discipline
|
|
37
|
+
Do not accumulate long chains of raw tool output in your reasoning. Once you have gathered sufficient information, synthesize it and move forward. Do not re-list everything you know — refer to prior findings and build on them.
|
|
38
|
+
|
|
39
|
+
### The think → act → evaluate → decide loop
|
|
40
|
+
Every step follows the same rhythm. Do not skip stages.
|
|
41
|
+
|
|
42
|
+
1. **Think** — call \`think\` with a 1-3 sentence statement of what you know, what gap the next action fills, and what success looks like.
|
|
43
|
+
2. **Act** — make the tool call (or batch of parallel calls).
|
|
44
|
+
3. **Stop and evaluate** — call \`evaluate\` immediately after the action completes. State in 1-3 sentences whether the result matched expectations, whether any surprise / error / risk was revealed, and whether to continue or course-correct. Be willing to catch yourself — "Actually, that's not right because..." or "Wait — this might make things worse, let me take a different approach" is exactly what evaluate is for.
|
|
45
|
+
4. **Decide** — based on the evaluation, either continue to the next think/act or go back and try a different approach. If you course-correct, say so before acting.
|
|
46
|
+
|
|
47
|
+
Skip this full cycle only for trivially small work (1-2 tool calls). For any non-trivial step, all four stages happen.
|
|
48
|
+
|
|
49
|
+
### Use the \`plan\` tool
|
|
50
|
+
|
|
51
|
+
**At the start of each new user request**, assess whether the task requires planning. Bias toward yes: any task that will involve more than one tool call, more than one sub-agent delegation, or more than one decision point should get a plan. Only skip planning for trivially small work (1-2 tool calls).
|
|
52
|
+
|
|
53
|
+
**The plan store is reset on every user turn.** Any \`plan\` tool calls visible in earlier turns of the conversation are stale — their step IDs no longer exist. Start fresh by calling \`plan\` with action \`create\` and an ordered list of step objects. Do not try to \`update\` IDs from a previous turn; they will not resolve.
|
|
54
|
+
|
|
55
|
+
**Each step has two parts at creation time:**
|
|
56
|
+
- \`description\`: what the step accomplishes.
|
|
57
|
+
- \`verification\`: a concrete, observable check that will prove the step succeeded — a command to run, a file/URL to read, a specific output substring, an exit code, a status code. Must be something a third party could re-run; never subjective ("looks right", "should work").
|
|
58
|
+
|
|
59
|
+
**Step lifecycle:**
|
|
60
|
+
- Before starting a step: \`update\` it to \`in_progress\`.
|
|
61
|
+
- After completing it: actually run the verification, then \`update\` to \`done\` with a \`signoff\` that cites the concrete evidence you observed (command output excerpt, file contents, status code, URL, etc.). The sign-off is your attestation that the verification was performed — not a restatement of the description. If the verification has not been run, the step is not done.
|
|
62
|
+
- If a step becomes unnecessary (user pivoted, work no longer needed): mark it \`cancelled\` with a \`note\`.
|
|
63
|
+
- If a step is genuinely unachievable, or verification failed and you cannot fix it (permission denied, resource missing, tool broken): mark it \`error\` with a \`note\` explaining what went wrong. Do not sign off on a step whose verification did not pass — mark it \`error\` and adapt the plan instead.
|
|
64
|
+
- If a step needs user input to proceed (intent, choice, missing argument), call the \`ask_user\` tool from inside the step. The answer comes back as the tool result; use it to continue. Never end the turn with a question written in prose — enforcement will trigger and the turn will be auto-cancelled before the user can answer.
|
|
65
|
+
|
|
66
|
+
**Before composing your final response**, verify every step is in a terminal state (\`done\`, \`cancelled\`, or \`error\`) and that every \`done\` step carries a sign-off. If you are giving up on the task — partially or fully — mark the remaining non-terminal steps \`cancelled\` or \`error\` with notes **before** writing the user-facing text. Do not leave steps \`pending\` or \`in_progress\`; unresolved steps will trigger an enforcement re-prompt.
|
|
67
|
+
|
|
68
|
+
### Keep reflective notes in \`scratch\`
|
|
69
|
+
The \`plan\` note is a one-line summary — \`scratch\` is where the evidence lives. For any non-trivial step:
|
|
70
|
+
- After a substantive tool call, sub-agent return, or batch of parallel calls, write a scratch entry with key \`step-{id}\` (or \`findings-{topic}\` for cross-cutting observations) containing: what you did, the concrete result (command output excerpts, file paths, numeric values, URLs — facts, not vibes), and any follow-ups this uncovered.
|
|
71
|
+
- Update the same key as you learn more within a single step; do not spawn a new key per tool call.
|
|
72
|
+
- Treat scratch as your working record. When you need to recall what happened several steps ago, read from scratch rather than scrolling back through tool results.
|
|
73
|
+
|
|
74
|
+
### Synthesize the final response from scratch
|
|
75
|
+
When all plan steps are in terminal states and you are ready to respond to the user:
|
|
76
|
+
1. Call \`scratch\` with action \`list\` to see what you captured.
|
|
77
|
+
2. Call \`scratch\` with action \`read\` for the relevant keys.
|
|
78
|
+
3. Compose the response from those notes — not from the conversation tail. Conversation history is noisy and can include stale intermediate state; your scratch notes are the curated record of what actually happened.
|
|
79
|
+
4. Skip this synthesis step only for trivial work where no plan was created.`;
|
|
80
|
+
/**
|
|
81
|
+
* Pure predicate: should the ReAct plan-enforcement loop run after the main
|
|
82
|
+
* generateText call?
|
|
83
|
+
*/
|
|
84
|
+
function shouldEnforcePlan(args) {
|
|
85
|
+
return args.reactMode && !args.aborted && !args.stepLimitHit && args.hasSteps;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Upper ceiling on the per-turn step budget when reactMode triples maxSteps.
|
|
89
|
+
* Prevents pathological cost amplification when a user has set a high
|
|
90
|
+
* BERNARD_MAX_STEPS for the non-react path.
|
|
91
|
+
*/
|
|
92
|
+
exports.REACT_MAX_STEPS_CEILING = 150;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the per-turn step budget for an agent loop. In reactMode the base
|
|
95
|
+
* budget is tripled (deliberation + delegation + synthesis), then clamped to
|
|
96
|
+
* {@link REACT_MAX_STEPS_CEILING} so a high base cannot blow up.
|
|
97
|
+
*/
|
|
98
|
+
function computeEffectiveMaxSteps(maxSteps, reactMode) {
|
|
99
|
+
if (!reactMode)
|
|
100
|
+
return maxSteps;
|
|
101
|
+
return Math.min(maxSteps * 3, exports.REACT_MAX_STEPS_CEILING);
|
|
102
|
+
}
|
|
103
|
+
/** Max plan-enforcement re-prompts after the main generateText call. */
|
|
104
|
+
exports.REACT_ENFORCEMENT_MAX_RETRIES = 2;
|
|
105
|
+
/** Note attached to plan steps auto-cancelled after enforcement retries are exhausted. */
|
|
106
|
+
exports.REACT_AUTO_CANCEL_NOTE = 'auto-cancelled: enforcement retries exhausted';
|
|
107
|
+
/**
|
|
108
|
+
* Builds the user-facing enforcement re-prompt used when a plan still has
|
|
109
|
+
* unresolved steps after the main generateText call. Shared by the agent and
|
|
110
|
+
* specialist enforcement loops so the wording cannot drift between the two.
|
|
111
|
+
*/
|
|
112
|
+
function buildEnforcementFeedback(planRender) {
|
|
113
|
+
return (`Your plan still has unresolved steps:\n\n${planRender}\n\n` +
|
|
114
|
+
`Resolve each remaining step: complete it (plan update -> done), mark it cancelled with a note if the user's intent changed or the step is no longer needed, or mark it error with a note if it is genuinely unachievable. Do not leave steps pending or in_progress.`);
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA2EH,8CAOC;AAcD,4DAGC;AAaD,4DAKC;AAnHY,QAAA,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6EAmEqC,CAAC;AAE9E;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,IAKjC;IACC,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,QAAQ,CAAC;AAChF,CAAC;AAED;;;;GAIG;AACU,QAAA,uBAAuB,GAAG,GAAG,CAAC;AAE3C;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,QAAgB,EAAE,SAAkB;IAC3E,IAAI,CAAC,SAAS;QAAE,OAAO,QAAQ,CAAC;IAChC,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,CAAC,EAAE,+BAAuB,CAAC,CAAC;AACzD,CAAC;AAED,wEAAwE;AAC3D,QAAA,6BAA6B,GAAG,CAAC,CAAC;AAE/C,0FAA0F;AAC7E,QAAA,sBAAsB,GAAG,+CAA+C,CAAC;AAEtF;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,UAAkB;IACzD,OAAO,CACL,4CAA4C,UAAU,MAAM;QAC5D,sQAAsQ,CACvQ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One entry per `tool_wrapper_run` invocation. Appended as a JSONL line to
|
|
3
|
+
* {@link TOOL_WRAPPER_LOG}. The log is append-only and user-readable; it
|
|
4
|
+
* exists primarily so failed runs can be inspected, replayed, or converted
|
|
5
|
+
* into correction candidates.
|
|
6
|
+
*/
|
|
7
|
+
export interface ReasoningLogEntry {
|
|
8
|
+
ts: string;
|
|
9
|
+
specialistId: string;
|
|
10
|
+
input: string;
|
|
11
|
+
toolCalls: Array<{
|
|
12
|
+
tool: string;
|
|
13
|
+
args: unknown;
|
|
14
|
+
resultPreview: string;
|
|
15
|
+
}>;
|
|
16
|
+
finalOutput: unknown;
|
|
17
|
+
status: 'ok' | 'error' | 'parse_failed';
|
|
18
|
+
error?: string;
|
|
19
|
+
reasoning?: string[];
|
|
20
|
+
/** Session id if available (short identifier to correlate related runs). */
|
|
21
|
+
sessionId?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function appendReasoningLog(entry: ReasoningLogEntry): void;
|
|
24
|
+
/**
|
|
25
|
+
* Reads and parses the reasoning log, returning the most recent `limit` entries.
|
|
26
|
+
* Skips malformed lines.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readReasoningLog(limit?: number): ReasoningLogEntry[];
|
|
29
|
+
/** Trims the reasoning log to the last `keep` entries. Used for maintenance. */
|
|
30
|
+
export declare function rotateReasoningLog(keep?: number): void;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.appendReasoningLog = appendReasoningLog;
|
|
37
|
+
exports.readReasoningLog = readReasoningLog;
|
|
38
|
+
exports.rotateReasoningLog = rotateReasoningLog;
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
|
+
const paths_js_1 = require("./paths.js");
|
|
41
|
+
/**
|
|
42
|
+
* Appends one entry to the reasoning log. Never throws — logging must not
|
|
43
|
+
* break the hot path.
|
|
44
|
+
*/
|
|
45
|
+
let logsDirReady = false;
|
|
46
|
+
function appendReasoningLog(entry) {
|
|
47
|
+
try {
|
|
48
|
+
if (!logsDirReady) {
|
|
49
|
+
fs.mkdirSync(paths_js_1.LOGS_DIR, { recursive: true });
|
|
50
|
+
logsDirReady = true;
|
|
51
|
+
}
|
|
52
|
+
fs.appendFileSync(paths_js_1.TOOL_WRAPPER_LOG, JSON.stringify(entry) + '\n', 'utf-8');
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// best-effort; swallow
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Reads and parses the reasoning log, returning the most recent `limit` entries.
|
|
60
|
+
* Skips malformed lines.
|
|
61
|
+
*/
|
|
62
|
+
function readReasoningLog(limit = 100) {
|
|
63
|
+
try {
|
|
64
|
+
if (!fs.existsSync(paths_js_1.TOOL_WRAPPER_LOG))
|
|
65
|
+
return [];
|
|
66
|
+
const contents = fs.readFileSync(paths_js_1.TOOL_WRAPPER_LOG, 'utf-8');
|
|
67
|
+
const lines = contents.split('\n').filter((l) => l.trim().length > 0);
|
|
68
|
+
const tail = lines.slice(-limit);
|
|
69
|
+
const entries = [];
|
|
70
|
+
for (const line of tail) {
|
|
71
|
+
try {
|
|
72
|
+
entries.push(JSON.parse(line));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
/* skip */
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return entries;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Trims the reasoning log to the last `keep` entries. Used for maintenance. */
|
|
85
|
+
function rotateReasoningLog(keep = 1000) {
|
|
86
|
+
try {
|
|
87
|
+
if (!fs.existsSync(paths_js_1.TOOL_WRAPPER_LOG))
|
|
88
|
+
return;
|
|
89
|
+
const contents = fs.readFileSync(paths_js_1.TOOL_WRAPPER_LOG, 'utf-8');
|
|
90
|
+
const lines = contents.split('\n').filter((l) => l.trim().length > 0);
|
|
91
|
+
if (lines.length <= keep)
|
|
92
|
+
return;
|
|
93
|
+
const tail = lines.slice(-keep);
|
|
94
|
+
const tmp = paths_js_1.TOOL_WRAPPER_LOG + '.tmp';
|
|
95
|
+
fs.writeFileSync(tmp, tail.join('\n') + '\n', 'utf-8');
|
|
96
|
+
fs.renameSync(tmp, paths_js_1.TOOL_WRAPPER_LOG);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
/* best-effort */
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=reasoning-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reasoning-log.js","sourceRoot":"","sources":["../src/reasoning-log.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,gDAUC;AAMD,4CAkBC;AAGD,gDAaC;AA9ED,4CAA8B;AAC9B,yC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AM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,SAAgB,kBAAkB,CAAC,IAAI,GAAG,IAAI;IAC5C,IAAI,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,2BAAgB,CAAC;YAAE,OAAO;QAC7C,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,2BAAgB,EAAE,OAAO,CAAC,CAAC;QAC5D,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACtE,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI;YAAE,OAAO;QACjC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,GAAG,GAAG,2BAAgB,GAAG,MAAM,CAAC;QACtC,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC;QACvD,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,2BAAgB,CAAC,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,iBAAiB;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type CoreMessage } from 'ai';
|
|
2
|
+
import { type MemoryStore } from './memory.js';
|
|
3
|
+
import type { RAGStore } from './rag.js';
|
|
4
|
+
import type { BernardConfig } from './config.js';
|
|
5
|
+
/** Sentinel sourceKey used for resolutions drawn from the RAG knowledge base. */
|
|
6
|
+
export declare const RAG_SOURCE_KEY = "rag";
|
|
7
|
+
/**
|
|
8
|
+
* Derive a memory key from a natural-language reference phrase.
|
|
9
|
+
* Strips a leading possessive/demonstrative and replaces internal spaces with dashes.
|
|
10
|
+
*
|
|
11
|
+
* Examples: "my brother" → "brother", "the car" → "car", "my brother Tom" → "brother-tom".
|
|
12
|
+
*/
|
|
13
|
+
export declare function deriveKeyFromReference(reference: string): string;
|
|
14
|
+
export interface ResolvedEntry {
|
|
15
|
+
phrase: string;
|
|
16
|
+
resolvedTo: string;
|
|
17
|
+
sourceKey: string;
|
|
18
|
+
}
|
|
19
|
+
export interface Candidate {
|
|
20
|
+
label: string;
|
|
21
|
+
sourceKey: string;
|
|
22
|
+
preview: string;
|
|
23
|
+
}
|
|
24
|
+
export type ResolveResult = {
|
|
25
|
+
status: 'noop';
|
|
26
|
+
} | {
|
|
27
|
+
status: 'resolved';
|
|
28
|
+
entries: ResolvedEntry[];
|
|
29
|
+
} | {
|
|
30
|
+
status: 'ambiguous';
|
|
31
|
+
reference: string;
|
|
32
|
+
candidates: Candidate[];
|
|
33
|
+
} | {
|
|
34
|
+
status: 'unknown';
|
|
35
|
+
reference: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Remove tokens that the main agent can resolve with tools (URLs, PR/issue refs,
|
|
39
|
+
* file paths, commit hashes) before the reference resolver sees the input.
|
|
40
|
+
* Mirrors {@link ./image.ts:stripImagePaths} in shape and intent.
|
|
41
|
+
*/
|
|
42
|
+
export declare function stripToolResolvableTokens(text: string): string;
|
|
43
|
+
export declare function shouldSkipResolver(userInput: string): boolean;
|
|
44
|
+
export declare function buildRecentTurnsBlock(history: CoreMessage[]): string;
|
|
45
|
+
export declare function validateAgainstMemory(result: ResolveResult, memoryKeys: Set<string>, ragAvailable?: boolean): ResolveResult;
|
|
46
|
+
export declare function resolveReferences(userInput: string, memoryStore: MemoryStore, config: BernardConfig, hints?: Map<string, string>, abortSignal?: AbortSignal, ragStore?: RAGStore, recentHistory?: CoreMessage[]): Promise<ResolveResult>;
|
|
47
|
+
export declare function renderResolvedBlock(entries: ResolvedEntry[]): string;
|