@x-otto/prompt 0.1.0-alpha.43 → 0.3.0-beta.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/dist/build-revision.json +4 -0
- package/dist/index.d.ts +121 -181
- package/dist/index.js +842 -10
- package/package.json +10 -15
- package/prompts/lead-guidance.md +58 -115
- package/prompts/subagent-note.md +3 -0
- package/README.md +0 -72
- package/prompts/lesson/runtime-lessons.md +0 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,209 +1,149 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Clock, ContextCatalog, ContextComputeInput, ContextContribution, PromptAssemblyResult, RuntimeDiagnosticInput, RuntimeEnv, SystemBlock } from "@x-otto/kernel";
|
|
2
|
+
import * as _$_x_otto_universal0 from "@x-otto/universal";
|
|
3
|
+
import { Accessor } from "@x-otto/universal";
|
|
4
|
+
import { HookContributor } from "@x-otto/hooks";
|
|
2
5
|
|
|
3
6
|
//#region src/types.d.ts
|
|
4
7
|
interface PromptEntry {
|
|
5
8
|
key: string;
|
|
6
9
|
content: string;
|
|
7
10
|
}
|
|
8
|
-
interface
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
interface LocalProviderOptions {
|
|
13
|
-
type: 'local';
|
|
14
|
-
baseDir: string;
|
|
15
|
-
extension?: string;
|
|
11
|
+
interface PromptLoadFailure {
|
|
12
|
+
readonly key: string;
|
|
13
|
+
readonly message: string;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
tags: string[];
|
|
30
|
-
trigger: string;
|
|
31
|
-
insight: string;
|
|
15
|
+
type PromptLoadResult = {
|
|
16
|
+
readonly status: 'loaded';
|
|
17
|
+
readonly entry: PromptEntry;
|
|
18
|
+
} | {
|
|
19
|
+
readonly status: 'not-loaded';
|
|
20
|
+
readonly key: string;
|
|
21
|
+
} | {
|
|
22
|
+
readonly status: 'failed';
|
|
23
|
+
readonly failure: PromptLoadFailure;
|
|
24
|
+
};
|
|
25
|
+
interface PromptProvider {
|
|
26
|
+
load(key: string): Promise<PromptLoadResult>;
|
|
32
27
|
}
|
|
33
28
|
//#endregion
|
|
34
29
|
//#region src/local-provider.d.ts
|
|
35
|
-
/**
|
|
36
|
-
* Local file system prompt provider
|
|
37
|
-
* Reads markdown files from the specified directory as prompt content
|
|
38
|
-
*
|
|
39
|
-
* Directory structure maps to key:
|
|
40
|
-
* baseDir/lead-guidance.md → "lead-guidance"
|
|
41
|
-
* baseDir/lesson/runtime-lessons.md → "lesson/runtime-lessons"
|
|
42
|
-
*/
|
|
43
30
|
declare class LocalPromptProvider implements PromptProvider {
|
|
44
31
|
private readonly baseDir;
|
|
45
32
|
private readonly extension;
|
|
46
|
-
constructor(options:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
33
|
+
constructor(options: {
|
|
34
|
+
baseDir: string;
|
|
35
|
+
extension?: string;
|
|
36
|
+
});
|
|
37
|
+
load(key: string): Promise<PromptLoadResult>;
|
|
50
38
|
}
|
|
51
39
|
//#endregion
|
|
52
|
-
//#region src/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
private readonly
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
40
|
+
//#region src/prompt-manager.d.ts
|
|
41
|
+
interface PromptAssembleResult {
|
|
42
|
+
readonly text: string;
|
|
43
|
+
readonly failures: readonly PromptLoadFailure[];
|
|
44
|
+
}
|
|
45
|
+
declare class PromptManager {
|
|
46
|
+
private readonly provider;
|
|
47
|
+
private readonly cache;
|
|
48
|
+
constructor(options: {
|
|
49
|
+
provider: PromptProvider;
|
|
50
|
+
});
|
|
51
|
+
load(key: string): Promise<PromptLoadResult>;
|
|
52
|
+
private loadCached;
|
|
53
|
+
assemble(depth?: number): Promise<PromptAssembleResult>;
|
|
63
54
|
}
|
|
64
55
|
//#endregion
|
|
65
|
-
//#region src/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
//#region src/component.d.ts
|
|
57
|
+
interface PromptOptions {
|
|
58
|
+
promptsDir: string;
|
|
59
|
+
clock?: Clock;
|
|
60
|
+
runtimeEnv?: RuntimeEnv;
|
|
61
|
+
}
|
|
62
|
+
declare const Prompt: _$_x_otto_universal0.ComponentDefinition<PromptOptions>;
|
|
71
63
|
//#endregion
|
|
72
|
-
//#region src/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
64
|
+
//#region src/prefix-freezer.d.ts
|
|
65
|
+
interface AcceptedRevision {
|
|
66
|
+
readonly digest: string;
|
|
67
|
+
readonly text: string | undefined;
|
|
68
|
+
}
|
|
69
|
+
interface PrefixEpoch {
|
|
70
|
+
readonly turn: number;
|
|
71
|
+
readonly surfaceLength: number;
|
|
72
|
+
readonly surfaceHead: string;
|
|
73
|
+
}
|
|
74
|
+
interface FrozenPrefix {
|
|
75
|
+
readonly text: string;
|
|
76
|
+
readonly parts: Map<string, string>;
|
|
77
|
+
readonly chains: Map<string, AcceptedRevision[]>;
|
|
78
|
+
readonly epoch: PrefixEpoch;
|
|
79
|
+
}
|
|
80
|
+
interface PrefixFreezer {
|
|
81
|
+
divergedSessions: Set<string>;
|
|
82
|
+
frozenOf(prefixKey: string): FrozenPrefix | undefined;
|
|
83
|
+
remember(prefixKey: string, frozen: FrozenPrefix): void;
|
|
78
84
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Assemble the system prompt for a sub-agent based on agent profile and task context.
|
|
81
|
-
* Replaces `{task_*}` placeholders.
|
|
82
|
-
*
|
|
83
|
-
* 未知占位符 fail-loud(不静默):替换完成后若模板仍有 `{word}` 残留(用户自定义 profile
|
|
84
|
-
* 写了 `{task_*}` 之外的占位符),console.warn 提示——防模型看到未替换的占位符原文。
|
|
85
|
-
* 只 warn 不抛错:内置三占位符有 'not provided' 缺省(buildContextReplacements),
|
|
86
|
-
* 残留只可能来自自定义模板的笔误/扩展占位符,warn 足够暴露问题。
|
|
87
|
-
*/
|
|
88
|
-
declare function assembleSubAgentPrompt(profile: AgentProfile$1, context?: SubAgentPromptContext): string;
|
|
89
|
-
declare function assembleGenericSubAgentPrompt(agentName: string, context?: SubAgentPromptContext): string;
|
|
90
|
-
/**
|
|
91
|
-
* Find the matching profile from agent-profiles data.
|
|
92
|
-
* Prefers exact match by name, then fuzzy match by capabilities.
|
|
93
|
-
*/
|
|
94
|
-
declare function resolveAgentProfile(profiles: AgentProfile$1[], agentName: string): AgentProfile$1 | undefined;
|
|
95
85
|
//#endregion
|
|
96
|
-
//#region src/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
excludedSections?: ReadonlySet<string>;
|
|
108
|
-
};
|
|
109
|
-
interface PromptManagerOptions {
|
|
110
|
-
provider: PromptProvider;
|
|
111
|
-
/**
|
|
112
|
-
* 已知能力键全集(终局审查 2026-07-18 S2 接线):传入后 `assemble()` 对 `lead-guidance.md`
|
|
113
|
-
* 中的 `requires-capability` 标记做拼写/漂移检测——标记的能力键不在此集合中时经
|
|
114
|
-
* `onUnknownCapability` 告警(console.warn),防止"能力键改名/写错 → 段落静默消失"。
|
|
115
|
-
* 真源是宿主层 `CAPABILITY_TOOL_MAP`(@x-otto/coding capability-tool-map.ts)的键集合,
|
|
116
|
-
* 经组装根注入(本层不依赖 coding,保持 RFC-057 D9 能力层边界)。缺省不检测(向后兼容)。
|
|
117
|
-
*/
|
|
118
|
-
knownCapabilities?: ReadonlySet<string>;
|
|
86
|
+
//#region src/state.d.ts
|
|
87
|
+
interface PromptSectionState {
|
|
88
|
+
readonly warnedSectionsByRequest: Map<string, Set<string>>;
|
|
89
|
+
readonly prefixFreezer: PrefixFreezer;
|
|
90
|
+
}
|
|
91
|
+
declare function createPromptSectionState(): PromptSectionState;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/section-catalog.d.ts
|
|
94
|
+
declare const BASE_INJECT_PRIORITY = 5;
|
|
95
|
+
declare class DuplicateSectionPriorityError extends Error {
|
|
96
|
+
constructor(priority: number, owner: string, incoming: string);
|
|
119
97
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* 分离,让下游不再字符串拼接而是按 lane 取用。
|
|
123
|
-
*
|
|
124
|
-
* - `stable`:会话内稳定的 system 前缀(lead-guidance.md 经能力门控后的内容)。
|
|
125
|
-
* - `volatile`:逐轮可变的尾段。PromptManager 当前不产生 volatile 内容(动态段由
|
|
126
|
-
* @x-otto/runtime 的 hook 体系注入),此字段为结构预留——未来 PromptManager 可注册
|
|
127
|
-
* section 时自然填充。
|
|
128
|
-
* - `render()`:拼接 stable + volatile 的便捷方法(向后兼容 assemblePreset 的 string 返回)。
|
|
129
|
-
*/
|
|
130
|
-
interface PromptAssembly {
|
|
131
|
-
readonly stable: string;
|
|
132
|
-
readonly volatile: string;
|
|
133
|
-
render(): string;
|
|
98
|
+
declare class ReservedSectionPriorityError extends Error {
|
|
99
|
+
constructor(priority: number, name: string);
|
|
134
100
|
}
|
|
135
|
-
declare
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* 组装 lead-guidance.md 为结构化 PromptAssembly。
|
|
143
|
-
*
|
|
144
|
-
* `enabledCapabilities`:本会话已解析的能力键集合(RFC-101,见 `tool-gated-sections.ts`)。传入时
|
|
145
|
-
* 对 `lead-guidance.md` 中 `<!-- requires-capability: X -->` 标记的段落做门控——`X` 不在集合中则
|
|
146
|
-
* 剔除该段落,消除悬空引用。缺省(`undefined`)保持向后兼容:不剔除任何段落内容,仅清理标记语法本身。
|
|
147
|
-
* 能力键本身不是工具名(RFC-057 D9/M94-01:能力层不得硬编码宿主工具名)——具体映射由宿主层
|
|
148
|
-
* (`@x-otto/coding`)的 `CAPABILITY_TOOL_MAP` 负责,本层只消费已转换好的能力键集合。
|
|
149
|
-
*/
|
|
150
|
-
assemble(enabledCapabilities?: ReadonlySet<string>, excludedSections?: ReadonlySet<string>): Promise<PromptAssembly>;
|
|
151
|
-
assemblePreset(options?: PromptPresetOptions, enabledCapabilities?: ReadonlySet<string>): Promise<string>;
|
|
152
|
-
/**
|
|
153
|
-
* append 模式子代理的**角色块** —— 渲染后的 profile 模板,由宿主注入为
|
|
154
|
-
* **volatile system 尾段**(落在 prompt cache 断点之后)。append 的 system prompt 主体由
|
|
155
|
-
* `assemblePreset` 返回基底(共享、进缓存),角色差异走此尾段——既得专门化又不击穿跨子代理缓存。
|
|
156
|
-
* 仅 append 模式返回值;replace/缺省(模板已是 system prompt 主体)/无 profile 返回 undefined。
|
|
157
|
-
*/
|
|
158
|
-
assembleSubAgentTail(options: PromptPresetOptions): string | undefined;
|
|
159
|
-
loadRuntimeLessonsTemplate(): Promise<string | null>;
|
|
101
|
+
declare function orderSections(contributions: ReadonlyMap<string, ContextContribution>, disabled?: ReadonlySet<string>): ContextContribution[];
|
|
102
|
+
declare function composeSections(state: PromptSectionState, sections: readonly ContextContribution[], input: ContextComputeInput, base: readonly SystemBlock[]): Promise<PromptAssemblyResult>;
|
|
103
|
+
declare function createContextCatalog(contributions: Accessor<ReadonlyMap<string, ContextContribution>>): ContextCatalog;
|
|
104
|
+
interface SectionComposerDeps {
|
|
105
|
+
contribute: HookContributor;
|
|
106
|
+
diagnose: (input: RuntimeDiagnosticInput) => void;
|
|
160
107
|
}
|
|
108
|
+
declare function registerSectionComposer(deps: SectionComposerDeps, state: PromptSectionState, contributions: Accessor<ReadonlyMap<string, ContextContribution>>, priority: number, options?: {
|
|
109
|
+
disabled?: () => ReadonlySet<string>;
|
|
110
|
+
}): void;
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/section-policy.d.ts
|
|
113
|
+
declare const SECTIONS_DISABLED_FIELD_SPEC: Readonly<{
|
|
114
|
+
key: "prompt.sections.disabled";
|
|
115
|
+
env: "OTTO_PROMPT_SECTIONS_DISABLED";
|
|
116
|
+
default: never[];
|
|
117
|
+
parse: (raw: unknown) => string[] | undefined;
|
|
118
|
+
ownership: "trusted-project";
|
|
119
|
+
}>;
|
|
120
|
+
type PromptSectionsPreset = 'full' | 'lean';
|
|
121
|
+
declare const SECTIONS_PRESET_FIELD_SPEC: Readonly<{
|
|
122
|
+
key: "prompt.sections.preset";
|
|
123
|
+
env: "OTTO_PROMPT_SECTIONS_PRESET";
|
|
124
|
+
default: "full";
|
|
125
|
+
parse: (raw: unknown) => PromptSectionsPreset | undefined;
|
|
126
|
+
ownership: "trusted-project";
|
|
127
|
+
}>;
|
|
128
|
+
declare const LEAN_DISABLED_SECTIONS: readonly string[];
|
|
129
|
+
declare function resolveDisabledSections(disabled: readonly string[] | undefined, preset: PromptSectionsPreset | undefined): ReadonlySet<string>;
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/context-fragment.d.ts
|
|
132
|
+
declare function contextFragmentBytes(content: string): number;
|
|
133
|
+
declare function boundFragment(content: string, budgetBytes: number): string;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/prompt-budget.d.ts
|
|
136
|
+
declare const PROMPT_LEAD_HARD_MAX_BYTES = 7168;
|
|
137
|
+
declare const PROMPT_LEAD_REGRESSION_MAX_BYTES = 6862;
|
|
138
|
+
declare const PROMPT_GUIDANCE_REGRESSION_MAX_BYTES = 2871;
|
|
161
139
|
//#endregion
|
|
162
|
-
//#region src/
|
|
140
|
+
//#region src/builtin-prompts-dir.d.ts
|
|
163
141
|
declare const BUILTIN_PROMPTS_DIR: string;
|
|
164
142
|
//#endregion
|
|
165
|
-
//#region src/
|
|
166
|
-
declare
|
|
143
|
+
//#region src/dangling-terms.d.ts
|
|
144
|
+
declare const DANGLING_TERMS: readonly string[];
|
|
167
145
|
//#endregion
|
|
168
|
-
//#region src/
|
|
169
|
-
|
|
170
|
-
* tool-gated-sections.ts
|
|
171
|
-
*
|
|
172
|
-
* RFC-101:lead-guidance.md 按已解析能力键集合分段门控。
|
|
173
|
-
*
|
|
174
|
-
* markdown 内联标记 `<!-- requires-capability: X -->...<!-- /requires-capability -->` 标注段落对
|
|
175
|
-
* 特定**能力**(非具体工具名)的依赖。`gateByToolAvailability` 在组装期扫描并剔除能力不可用的
|
|
176
|
-
* 段落(含标记本身),消除悬空引用(如 minimal/standard 工具集会话看到引用了不存在能力的操作指引)。
|
|
177
|
-
*
|
|
178
|
-
* RFC-057 §3 D9 / M94-01:`packages/prompt` 是能力层,不得硬编码宿主工具名字面量——本模块与
|
|
179
|
-
* `lead-guidance.md` 只认识语义能力键(如 `delegation`/`task-observability`),能力键到具体工具名
|
|
180
|
-
* 的映射表下沉到宿主层(`@x-otto/coding`)。
|
|
181
|
-
*
|
|
182
|
-
* 纯函数,不访问全局状态、不做 I/O(RFC-101 重要事项规则 1)。
|
|
183
|
-
*/
|
|
184
|
-
/**
|
|
185
|
-
* 扫描 `content` 中的 `requires-capability` 标记区块:
|
|
186
|
-
* - `enabledCapabilities` 为 `undefined` → 不做任何剔除,但仍清理标记语法(标记本身不应泄漏到最终 prompt)。
|
|
187
|
-
* - 标记的能力键在 `enabledCapabilities` 中 → 保留区块内容,剔除标记。
|
|
188
|
-
* - 标记的能力键不在 `enabledCapabilities` 中 → 整段剔除(含内容与标记)。
|
|
189
|
-
* - 未闭合标记(无匹配 `/requires-capability`)→ 保守处理:不剔除任何内容,原样保留(含标记本身),
|
|
190
|
-
* 并触发 `onUnclosedTag`(RFC-101 重要事项规则 6:system prompt 组装失败是致命故障,必须优雅降级)。
|
|
191
|
-
*/
|
|
192
|
-
declare function gateByToolAvailability(content: string, enabledCapabilities: ReadonlySet<string> | undefined, options?: {
|
|
193
|
-
/** 已知能力键全集(用于检测标记拼写错误/能力已重命名)。缺省时不做未知能力键检测。 */knownCapabilities?: ReadonlySet<string>; /** 按 `###`/`####` 标题文本剔除整段(宿主按场景裁剪框架提示词,如无人值守的生成类任务)。 */
|
|
194
|
-
excludedSections?: ReadonlySet<string>;
|
|
195
|
-
onUnknownCapability?: (capability: string) => void;
|
|
196
|
-
onUnclosedTag?: (capability: string) => void;
|
|
197
|
-
/**
|
|
198
|
-
* `excludedSections` 中未命中任何标题的段名逐条上报(拼写错误/段名改名 → 静默 no-op 漂移,
|
|
199
|
-
* 需要与 `onUnknownCapability` 同等的可观测性)。
|
|
200
|
-
*/
|
|
201
|
-
onUnknownSection?: (section: string) => void;
|
|
202
|
-
/**
|
|
203
|
-
* 剔除后正文为空的回调。此时本函数返回 `''` 而非回退原文——回退会让宿主误配
|
|
204
|
-
* 「裁光全部段」变成静默的全文注入(fail-open),调用方须自行决定由此产生的空提示词。
|
|
205
|
-
*/
|
|
206
|
-
onAllSectionsRemoved?: () => void;
|
|
207
|
-
}): string;
|
|
146
|
+
//#region src/contexts/environment.d.ts
|
|
147
|
+
declare function createEnvironmentContext(runtimeEnv: RuntimeEnv | undefined, clock: Clock): ContextContribution;
|
|
208
148
|
//#endregion
|
|
209
|
-
export {
|
|
149
|
+
export { BASE_INJECT_PRIORITY, BUILTIN_PROMPTS_DIR, DANGLING_TERMS, DuplicateSectionPriorityError, LEAN_DISABLED_SECTIONS, LocalPromptProvider, PROMPT_GUIDANCE_REGRESSION_MAX_BYTES, PROMPT_LEAD_HARD_MAX_BYTES, PROMPT_LEAD_REGRESSION_MAX_BYTES, Prompt, type PromptAssembleResult, type PromptEntry, type PromptLoadFailure, type PromptLoadResult, PromptManager, type PromptOptions, type PromptProvider, type PromptSectionState, type PromptSectionsPreset, ReservedSectionPriorityError, SECTIONS_DISABLED_FIELD_SPEC, SECTIONS_PRESET_FIELD_SPEC, boundFragment, composeSections, contextFragmentBytes, createContextCatalog, createEnvironmentContext, createPromptSectionState, orderSections, registerSectionComposer, resolveDisabledSections };
|