@myagentroam/agent 0.9.62 → 0.9.65
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/dist/cli/codex-auth-file.js +268 -3
- package/dist/cli/main.js +431 -2
- package/dist/error.js +66 -2
- package/dist/host/contracts.js +20 -2
- package/dist/host/local-agent-host.js +146 -2
- package/dist/host/local-process-executor.js +39 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -2
- package/dist/model/anthropic-messages.js +474 -2
- package/dist/model/anthropic-thinking.js +33 -2
- package/dist/model/catalog-file.js +88 -2
- package/dist/model/configuration.js +137 -2
- package/dist/model/contracts.d.ts +2 -0
- package/dist/model/contracts.js +1 -2
- package/dist/model/http.js +529 -2
- package/dist/model/openai-responses.d.ts +2 -0
- package/dist/model/openai-responses.js +1602 -2
- package/dist/model/runtime-credential.js +35 -2
- package/dist/model/sse.js +199 -2
- package/dist/prompts/compact.js +25 -2
- package/dist/prompts/core.js +37 -2
- package/dist/prompts/execution-budget.js +10 -2
- package/dist/prompts/index.d.ts +3 -2
- package/dist/prompts/index.js +47 -2
- package/dist/prompts/modes.js +25 -2
- package/dist/prompts/output.js +1 -2
- package/dist/prompts/resources.d.ts +1 -1
- package/dist/prompts/resources.js +31 -2
- package/dist/prompts/subagent.d.ts +6 -0
- package/dist/prompts/subagent.js +29 -2
- package/dist/prompts/title.js +9 -2
- package/dist/prompts/workflow.js +32 -2
- package/dist/runtime/async-queue.js +62 -2
- package/dist/runtime/builtin-skills.js +19 -2
- package/dist/runtime/byted-ark-imagegen-skill.js +18 -2
- package/dist/runtime/codex-imagegen-skill.js +35 -2
- package/dist/runtime/compact.js +225 -2
- package/dist/runtime/context-gc-runtime.d.ts +35 -0
- package/dist/runtime/context-gc-runtime.js +163 -0
- package/dist/runtime/context-gc-tokens.d.ts +24 -0
- package/dist/runtime/context-gc-tokens.js +83 -0
- package/dist/runtime/context-gc.d.ts +66 -0
- package/dist/runtime/context-gc.js +909 -0
- package/dist/runtime/context-projection.d.ts +23 -0
- package/dist/runtime/context-projection.js +203 -0
- package/dist/runtime/environment-context.js +41 -2
- package/dist/runtime/execution-policy.js +13 -2
- package/dist/runtime/instructions.js +298 -2
- package/dist/runtime/normalize.js +40 -2
- package/dist/runtime/plan-output.js +95 -2
- package/dist/runtime/rollout-budget.d.ts +2 -0
- package/dist/runtime/rollout-budget.js +92 -2
- package/dist/runtime/token-budget.d.ts +2 -0
- package/dist/runtime/token-budget.js +44 -2
- package/dist/sdk/agent.js +1804 -2
- package/dist/sdk/types.d.ts +15 -5
- package/dist/sdk/types.js +1 -2
- package/dist/session/catalog.d.ts +5 -4
- package/dist/session/catalog.js +133 -2
- package/dist/session/context-gc-checkpoint.d.ts +148 -0
- package/dist/session/context-gc-checkpoint.js +665 -0
- package/dist/session/context-gc-replacements.d.ts +52 -0
- package/dist/session/context-gc-replacements.js +226 -0
- package/dist/session/context-gc-subagent.d.ts +43 -0
- package/dist/session/context-gc-subagent.js +267 -0
- package/dist/session/jsonl-store.d.ts +42 -4
- package/dist/session/jsonl-store.js +1657 -2
- package/dist/subagent/scheduler.d.ts +35 -2
- package/dist/subagent/scheduler.js +249 -2
- package/dist/subagent/session-controller.d.ts +94 -0
- package/dist/subagent/session-controller.js +675 -0
- package/dist/tools/agent-cancel.js +28 -2
- package/dist/tools/{task.d.ts → agent-message.d.ts} +2 -2
- package/dist/tools/agent-message.js +51 -0
- package/dist/tools/agent-start.js +84 -2
- package/dist/tools/agent-wait.js +53 -2
- package/dist/tools/apply-patch.js +478 -2
- package/dist/tools/code-mode.js +370 -2
- package/dist/tools/codex-image-gen.js +312 -2
- package/dist/tools/exec.js +455 -2
- package/dist/tools/execution-limits.d.ts +1 -0
- package/dist/tools/execution-limits.js +44 -2
- package/dist/tools/local-registry.js +233 -2
- package/dist/tools/local-workspace-tools.js +28 -2
- package/dist/tools/question.js +124 -2
- package/dist/tools/read-context.d.ts +16 -0
- package/dist/tools/read-context.js +85 -0
- package/dist/tools/read.d.ts +13 -0
- package/dist/tools/read.js +294 -2
- package/dist/tools/registry.js +76 -2
- package/dist/tools/runtime-context.d.ts +9 -2
- package/dist/tools/runtime-context.js +1 -2
- package/dist/tools/runtime.js +21 -2
- package/dist/tools/scheduler.js +41 -2
- package/dist/tools/shared/path-resolver.js +133 -2
- package/dist/tools/skill.js +37 -2
- package/dist/tools/todo-read.js +10 -2
- package/dist/tools/todo-write.js +65 -2
- package/dist/tools/todo.js +67 -2
- package/dist/tools/view-image.js +81 -2
- package/dist/tools/web-fetch.js +11 -2
- package/dist/tools/web-search.js +14 -2
- package/package.json +9 -7
- package/README.md +0 -3
- package/dist/runtime/prompt.d.ts +0 -9
- package/dist/runtime/prompt.js +0 -2
- package/dist/tools/shared/secret-redaction.d.ts +0 -4
- package/dist/tools/shared/secret-redaction.js +0 -2
- package/dist/tools/task-cancel.d.ts +0 -7
- package/dist/tools/task-cancel.js +0 -2
- package/dist/tools/task-output.d.ts +0 -7
- package/dist/tools/task-output.js +0 -2
- package/dist/tools/task-tools.d.ts +0 -36
- package/dist/tools/task-tools.js +0 -2
- package/dist/tools/task.js +0 -2
- package/dist/tools/todo-tools.d.ts +0 -25
- package/dist/tools/todo-tools.js +0 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ModelMessage } from '../model/contracts.js';
|
|
2
|
+
import { type ContextGcCheckpointCache, type ContextGcCheckpointPayload, type ContextGcReplacement } from '../session/context-gc-checkpoint.js';
|
|
3
|
+
import type { SessionRecord } from '../session/jsonl-store.js';
|
|
4
|
+
export interface ContextProjectionEntry {
|
|
5
|
+
readonly record: SessionRecord;
|
|
6
|
+
readonly message: ModelMessage;
|
|
7
|
+
}
|
|
8
|
+
export interface ContextProjection {
|
|
9
|
+
readonly entries: readonly ContextProjectionEntry[];
|
|
10
|
+
readonly checkpoint?: ContextGcCheckpointPayload;
|
|
11
|
+
}
|
|
12
|
+
export declare function buildContextProjection(records: readonly SessionRecord[], workspace?: string, checkpointCache?: ContextGcCheckpointCache): ContextProjection;
|
|
13
|
+
export declare function applyContextGcReplacementsToMessages(messages: readonly ModelMessage[], messageSources: readonly SessionRecord[], replacements: readonly ContextGcReplacement[]): {
|
|
14
|
+
readonly messages: ModelMessage[];
|
|
15
|
+
readonly messageSources: SessionRecord[];
|
|
16
|
+
};
|
|
17
|
+
export declare function filterPairedContext(messages: readonly ModelMessage[], messageSources: readonly SessionRecord[]): {
|
|
18
|
+
readonly messages: ModelMessage[];
|
|
19
|
+
readonly messageSources: SessionRecord[];
|
|
20
|
+
};
|
|
21
|
+
export declare function restoreModelContext(payload: Record<string, unknown>, providerModelId?: string): ModelMessage | undefined;
|
|
22
|
+
export declare function providerToolCallId(message: ModelMessage): string | undefined;
|
|
23
|
+
export declare function providerToolName(message: ModelMessage): string | undefined;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { anthropicThinkingBlock } from '../model/anthropic-thinking.js';
|
|
2
|
+
import { latestValidContextGcCheckpoint, contextGcRecordSourceHash, contextGcTargetKey } from '../session/context-gc-checkpoint.js';
|
|
3
|
+
import { TOOL_EXECUTION_LIMITS } from '../tools/execution-limits.js';
|
|
4
|
+
import { replaceReadContextItems } from '../tools/read-context.js';
|
|
5
|
+
const MAX_MODEL_CONTEXT_BYTES = 1024 * 1024;
|
|
6
|
+
export function buildContextProjection(records, workspace, checkpointCache) {
|
|
7
|
+
let activeModelId;
|
|
8
|
+
const rawEntries = [];
|
|
9
|
+
for (const record of records) {
|
|
10
|
+
if (record.type === 'execution.header') {
|
|
11
|
+
activeModelId = modelIdFromPayload(record.payload);
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (record.type === 'compact.completed') {
|
|
15
|
+
activeModelId = modelIdFromPayload(record.payload);
|
|
16
|
+
rawEntries.splice(0);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (record.type !== 'model.context' || !isRecord(record.payload))
|
|
20
|
+
continue;
|
|
21
|
+
const message = restoreModelContext(record.payload, activeModelId);
|
|
22
|
+
if (message)
|
|
23
|
+
rawEntries.push({ record, message });
|
|
24
|
+
}
|
|
25
|
+
const valid = checkpointCache
|
|
26
|
+
? checkpointCache.read(records, undefined, workspace)
|
|
27
|
+
: latestValidContextGcCheckpoint(records, undefined, workspace);
|
|
28
|
+
const messages = rawEntries.flatMap((entry) => (entry.message ? [entry.message] : []));
|
|
29
|
+
const sources = rawEntries.flatMap((entry) => (entry.message ? [entry.record] : []));
|
|
30
|
+
const applied = applyContextGcReplacementsToMessages(messages, sources, valid?.payload.replacements ?? []);
|
|
31
|
+
const paired = filterPairedContext(applied.messages, applied.messageSources);
|
|
32
|
+
const entries = paired.messages.map((message, index) => ({
|
|
33
|
+
message,
|
|
34
|
+
record: paired.messageSources[index]
|
|
35
|
+
}));
|
|
36
|
+
return { entries, ...(valid ? { checkpoint: valid.payload } : {}) };
|
|
37
|
+
}
|
|
38
|
+
export function applyContextGcReplacementsToMessages(messages, messageSources, replacements) {
|
|
39
|
+
if (messages.length !== messageSources.length)
|
|
40
|
+
throw new Error('Context projection message sources are not aligned.');
|
|
41
|
+
const direct = new Map(replacements.map((replacement) => [contextGcTargetKey(replacement.target), replacement]));
|
|
42
|
+
const aliases = new Set(replacements.flatMap((replacement) => replacement.kind === 'TOOL_CALL_INPUT'
|
|
43
|
+
? replacement.providerAliasTargets.map(contextGcTargetKey)
|
|
44
|
+
: []));
|
|
45
|
+
const projected = [];
|
|
46
|
+
for (const [index, source] of messageSources.entries()) {
|
|
47
|
+
const message = messages[index];
|
|
48
|
+
const target = targetFromMessage(source, message);
|
|
49
|
+
if (target && aliases.has(contextGcTargetKey(target)))
|
|
50
|
+
continue;
|
|
51
|
+
const replacement = target ? direct.get(contextGcTargetKey(target)) : undefined;
|
|
52
|
+
let next = cloneMessage(message);
|
|
53
|
+
if (replacement && target && targetMatchesReplacement(target, replacement.target)) {
|
|
54
|
+
if (replacement.kind === 'READ_OUTPUT_ITEMS' &&
|
|
55
|
+
next.role === 'tool' &&
|
|
56
|
+
typeof next.content === 'string')
|
|
57
|
+
next = {
|
|
58
|
+
...next,
|
|
59
|
+
content: replaceReadContextItems(next.content, replacement.items)
|
|
60
|
+
};
|
|
61
|
+
else if (replacement.kind === 'TOOL_CALL_INPUT' && next.role === 'tool_call')
|
|
62
|
+
next = { ...next, arguments: structuredClone(replacement.replacementArguments) };
|
|
63
|
+
else if ((replacement.kind === 'EXEC_OUTPUT' || replacement.kind === 'SUBAGENT_OUTPUT') &&
|
|
64
|
+
next.role === 'tool')
|
|
65
|
+
next = { ...next, content: replacement.replacementContent };
|
|
66
|
+
}
|
|
67
|
+
projected.push({ message: next, source });
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
messages: projected.map(({ message }) => message),
|
|
71
|
+
messageSources: projected.map(({ source }) => source)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export function filterPairedContext(messages, messageSources) {
|
|
75
|
+
if (messages.length !== messageSources.length)
|
|
76
|
+
throw new Error('Context projection message sources are not aligned.');
|
|
77
|
+
const entries = messages.map((message, index) => ({
|
|
78
|
+
message,
|
|
79
|
+
source: messageSources[index]
|
|
80
|
+
}));
|
|
81
|
+
const completedToolCalls = new Set(entries
|
|
82
|
+
.filter(({ message }) => message.role === 'tool')
|
|
83
|
+
.map(({ message }) => message.callId)
|
|
84
|
+
.filter((callId) => callId !== undefined));
|
|
85
|
+
const paired = entries.filter(({ message }) => {
|
|
86
|
+
if (message.role === 'tool_call')
|
|
87
|
+
return completedToolCalls.has(message.callId ?? '');
|
|
88
|
+
if (message.role !== 'provider' || message.provider !== 'OPENAI_RESPONSES')
|
|
89
|
+
return true;
|
|
90
|
+
const callId = providerToolCallId(message);
|
|
91
|
+
return callId === undefined || completedToolCalls.has(callId);
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
messages: paired.map(({ message }) => message),
|
|
95
|
+
messageSources: paired.map(({ source }) => source)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function restoreModelContext(payload, providerModelId) {
|
|
99
|
+
const nativeItem = payload.role === 'provider' && payload.provider === 'OPENAI_RESPONSES' && isRecord(payload.item)
|
|
100
|
+
? payload.item
|
|
101
|
+
: undefined;
|
|
102
|
+
const toolName = payload.role === 'tool_call'
|
|
103
|
+
? payload.name
|
|
104
|
+
: nativeItem?.type === 'custom_tool_call'
|
|
105
|
+
? nativeItem.name
|
|
106
|
+
: undefined;
|
|
107
|
+
const inputLimit = toolName === 'code_mode'
|
|
108
|
+
? TOOL_EXECUTION_LIMITS.codeMaxInputBytes
|
|
109
|
+
: toolName === 'apply_patch'
|
|
110
|
+
? TOOL_EXECUTION_LIMITS.patchMaxBytes
|
|
111
|
+
: undefined;
|
|
112
|
+
const byteLimit = inputLimit === undefined ? MAX_MODEL_CONTEXT_BYTES : inputLimit * 6 + 4096;
|
|
113
|
+
if (Buffer.byteLength(JSON.stringify(payload)) > byteLimit)
|
|
114
|
+
return undefined;
|
|
115
|
+
if (payload.role === 'tool' &&
|
|
116
|
+
typeof payload.content === 'string' &&
|
|
117
|
+
typeof payload.callId === 'string')
|
|
118
|
+
return { role: 'tool', content: payload.content, callId: payload.callId };
|
|
119
|
+
if (payload.role === 'tool_call' &&
|
|
120
|
+
typeof payload.callId === 'string' &&
|
|
121
|
+
typeof payload.name === 'string')
|
|
122
|
+
return {
|
|
123
|
+
role: 'tool_call',
|
|
124
|
+
content: '',
|
|
125
|
+
callId: payload.callId,
|
|
126
|
+
name: payload.name,
|
|
127
|
+
arguments: payload.arguments,
|
|
128
|
+
...(payload.inputMode === 'json' || payload.inputMode === 'freeform'
|
|
129
|
+
? { inputMode: payload.inputMode }
|
|
130
|
+
: {})
|
|
131
|
+
};
|
|
132
|
+
if (payload.role === 'provider' && payload.provider === 'ANTHROPIC_MESSAGES') {
|
|
133
|
+
const item = anthropicThinkingBlock(payload.item);
|
|
134
|
+
const modelId = modelIdFromPayload(payload, 'providerModelId');
|
|
135
|
+
return item && modelId
|
|
136
|
+
? {
|
|
137
|
+
role: 'provider',
|
|
138
|
+
provider: 'ANTHROPIC_MESSAGES',
|
|
139
|
+
providerModelId: modelId,
|
|
140
|
+
content: '',
|
|
141
|
+
item
|
|
142
|
+
}
|
|
143
|
+
: undefined;
|
|
144
|
+
}
|
|
145
|
+
if (payload.role === 'provider' &&
|
|
146
|
+
payload.provider === 'OPENAI_RESPONSES' &&
|
|
147
|
+
isRecord(payload.item)) {
|
|
148
|
+
const restoredProviderModelId = modelIdFromPayload(payload, 'providerModelId') ?? providerModelId;
|
|
149
|
+
return {
|
|
150
|
+
role: 'provider',
|
|
151
|
+
content: '',
|
|
152
|
+
provider: 'OPENAI_RESPONSES',
|
|
153
|
+
...(restoredProviderModelId === undefined
|
|
154
|
+
? {}
|
|
155
|
+
: { providerModelId: restoredProviderModelId }),
|
|
156
|
+
item: payload.item
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
export function providerToolCallId(message) {
|
|
162
|
+
if (message.role !== 'provider' || message.provider !== 'OPENAI_RESPONSES' || !message.item)
|
|
163
|
+
return undefined;
|
|
164
|
+
if (message.item.type !== 'function_call' && message.item.type !== 'custom_tool_call')
|
|
165
|
+
return undefined;
|
|
166
|
+
return typeof message.item.call_id === 'string' ? message.item.call_id : undefined;
|
|
167
|
+
}
|
|
168
|
+
export function providerToolName(message) {
|
|
169
|
+
if (message.role !== 'provider' || !message.item)
|
|
170
|
+
return undefined;
|
|
171
|
+
return typeof message.item.name === 'string' ? message.item.name : undefined;
|
|
172
|
+
}
|
|
173
|
+
function targetFromMessage(record, message) {
|
|
174
|
+
if (record.type !== 'model.context')
|
|
175
|
+
return undefined;
|
|
176
|
+
const callId = message.role === 'provider' ? providerToolCallId(message) : message.callId;
|
|
177
|
+
const toolName = message.role === 'provider' ? providerToolName(message) : message.name;
|
|
178
|
+
if (message.role !== 'tool_call' && message.role !== 'tool' && message.role !== 'provider')
|
|
179
|
+
return undefined;
|
|
180
|
+
return {
|
|
181
|
+
sequence: record.sequence,
|
|
182
|
+
recordId: record.recordId,
|
|
183
|
+
role: message.role,
|
|
184
|
+
...(callId === undefined ? {} : { callId }),
|
|
185
|
+
...(toolName === undefined ? {} : { toolName }),
|
|
186
|
+
sourceHash: contextGcRecordSourceHash(record)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function targetMatchesReplacement(left, right) {
|
|
190
|
+
return (contextGcTargetKey(left) === contextGcTargetKey(right) && left.sourceHash === right.sourceHash);
|
|
191
|
+
}
|
|
192
|
+
function cloneMessage(message) {
|
|
193
|
+
return structuredClone(message);
|
|
194
|
+
}
|
|
195
|
+
function modelIdFromPayload(payload, key = 'modelId') {
|
|
196
|
+
if (!isRecord(payload))
|
|
197
|
+
return undefined;
|
|
198
|
+
const value = payload[key];
|
|
199
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
200
|
+
}
|
|
201
|
+
function isRecord(value) {
|
|
202
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
203
|
+
}
|
|
@@ -1,2 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { buildEnvironmentContext } from '../prompts/core.js';
|
|
3
|
+
const environmentStateSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
platform: z.string().min(1).max(64),
|
|
6
|
+
architecture: z.string().min(1).max(64).optional(),
|
|
7
|
+
workspace: z.string().max(32768),
|
|
8
|
+
shell: z
|
|
9
|
+
.object({
|
|
10
|
+
name: z.string().min(1).max(128),
|
|
11
|
+
path: z.string().min(1).max(32768)
|
|
12
|
+
})
|
|
13
|
+
.strict()
|
|
14
|
+
.optional(),
|
|
15
|
+
guaranteedCommands: z.record(z.string().min(1).max(128), z.string().max(256)).optional()
|
|
16
|
+
})
|
|
17
|
+
.strict();
|
|
18
|
+
const environmentRecordSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
version: z.literal(1),
|
|
21
|
+
state: environmentStateSchema
|
|
22
|
+
})
|
|
23
|
+
.strict();
|
|
24
|
+
export function restoreEnvironmentState(payload) {
|
|
25
|
+
if (Buffer.byteLength(JSON.stringify(payload) ?? '') > 128 * 1024)
|
|
26
|
+
return undefined;
|
|
27
|
+
const parsed = environmentRecordSchema.safeParse(payload);
|
|
28
|
+
if (!parsed.success)
|
|
29
|
+
return undefined;
|
|
30
|
+
const { architecture, shell, guaranteedCommands, ...required } = parsed.data.state;
|
|
31
|
+
return {
|
|
32
|
+
...required,
|
|
33
|
+
...(architecture === undefined ? {} : { architecture }),
|
|
34
|
+
...(shell === undefined ? {} : { shell }),
|
|
35
|
+
...(guaranteedCommands === undefined ? {} : { guaranteedCommands })
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function environmentContextUpdate(current, previous) {
|
|
39
|
+
const content = buildEnvironmentContext(current, previous);
|
|
40
|
+
return content ? { role: 'user', contextKind: 'environment', content } : undefined;
|
|
41
|
+
}
|
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export const AGENT_EXECUTION_POLICY = Object.freeze({
|
|
2
|
+
subagentModelRounds: 32,
|
|
3
|
+
rolloutBudgetTokens: 1_250_000,
|
|
4
|
+
rolloutBudgetConserveRemainingTokens: 350_000,
|
|
5
|
+
rolloutBudgetFinalizeRemainingTokens: 200_000,
|
|
6
|
+
rolloutBudgetSamplingTokenWeight: 1,
|
|
7
|
+
rolloutBudgetPrefillTokenWeight: 1,
|
|
8
|
+
toolEventSummaryCharacters: 2_000,
|
|
9
|
+
modelToolOutputTokens: 10_000,
|
|
10
|
+
automaticCompactionPercent: 90,
|
|
11
|
+
subagentVerificationCharacters: 500,
|
|
12
|
+
estimatedTokensPerImage: 1_000
|
|
13
|
+
});
|
|
@@ -1,2 +1,298 @@
|
|
|
1
|
-
|
|
2
|
-
const _0x557ad7=_0xb17d;(function(_0xd742fa,_0x1117b9){const _0x24cfad=_0xb17d,_0x184c95=_0xd742fa();while(!![]){try{const _0x4c5cdf=parseInt(_0x24cfad(0xb0))/(-0xe3+-0x7*0x151+0xa1b)+-parseInt(_0x24cfad(0x83))/(0xfa9+-0x264d*0x1+-0xdf*-0x1a)*(-parseInt(_0x24cfad(0xd8))/(-0xd90+-0x1*0x1a0f+-0x39*-0xb2))+parseInt(_0x24cfad(0x89))/(-0xc84+0x2e*0x64+-0x570)*(-parseInt(_0x24cfad(0x90))/(0x75d+0x1ccf+-0x2427))+parseInt(_0x24cfad(0x86))/(0x693*-0x5+0x1*0x235f+0x2*-0x13d)*(-parseInt(_0x24cfad(0x8f))/(0x459+-0x3e*0x5a+-0x2*-0x8bd))+-parseInt(_0x24cfad(0xdd))/(-0x481*0x4+-0x517+0x1723*0x1)*(parseInt(_0x24cfad(0x99))/(0x7b6+-0x203d+0x1890))+parseInt(_0x24cfad(0x80))/(-0xb8*0x25+-0x1cbc*-0x1+-0x21a)*(parseInt(_0x24cfad(0x79))/(0x1030+0x2f*-0x2e+-0x7b3))+parseInt(_0x24cfad(0xc9))/(-0x182f+-0x93+0x18ce);if(_0x4c5cdf===_0x1117b9)break;else _0x184c95['push'](_0x184c95['shift']());}catch(_0x5791e9){_0x184c95['push'](_0x184c95['shift']());}}}(_0x21be,-0x27*0x61+-0x1fe69*0x1+0x3f282));import{open,readdir,realpath,stat}from'node:fs/promises';import{dirname,isAbsolute,join,parse,posix,relative,resolve}from'node:path';import{availableBuiltinSkills}from'./builtin-skills.js';const MAX_FILE_BYTES=(0x161a*-0x1+-0x214b+0x37a5)*(-0x47*-0x5b+-0x1d97+0x85a),MAX_PROJECT_BYTES=(-0x39*-0x1b+0x266c+-0x2c4f)*(0xc93+-0x150c+0xc79),INSTRUCTION_FILENAMES=[_0x557ad7(0xda),_0x557ad7(0xd1)],REPLACEMENT_NOTICE=_0x557ad7(0x82),REMOVAL_NOTICE=_0x557ad7(0x7f);export function agentSkillSource(_0x19fa4f){const _0x2c90c3=_0x557ad7;return _0x19fa4f[_0x2c90c3(0xcc)]===_0x2c90c3(0xb7)?_0x2c90c3(0xce):dirname(_0x19fa4f[_0x2c90c3(0xad)]);}export async function loadAgentInstructions(_0xf1cdc8){const _0x16a26f=_0x557ad7,_0xdfe089=[];let _0x29da1a=MAX_PROJECT_BYTES;const _0x331304=async _0x47d4bc=>{const _0x3224c8=_0xb17d,_0x115d89=_0x47d4bc[_0x3224c8(0xd7)]===_0x3224c8(0x88)?MAX_FILE_BYTES:_0x29da1a;if(_0x115d89===0x97c*0x3+0xc9e+-0xe*0x2ef)return;const _0x4bfc92=await loadPreferredInstruction({'directory':_0x47d4bc[_0x3224c8(0x7c)],'boundary':_0x47d4bc[_0x3224c8(0xcd)],'maxBytes':_0x115d89});if(!_0x4bfc92||!_0x4bfc92[_0x3224c8(0xb4)][_0x3224c8(0xde)]())return;_0xdfe089[_0x3224c8(0xd3)]({'kind':_0x47d4bc[_0x3224c8(0xd7)],'label':_0x4bfc92[_0x3224c8(0x85)]?_0x47d4bc[_0x3224c8(0xa8)]+_0x3224c8(0x9e):_0x47d4bc[_0x3224c8(0xa8)],'sourcePath':_0x4bfc92[_0x3224c8(0xc7)],'displayPath':displayJoin(_0x47d4bc[_0x3224c8(0xc1)],_0x4bfc92[_0x3224c8(0xc5)]),'scopePath':resolve(_0x47d4bc[_0x3224c8(0x7a)]),'displayScope':_0x47d4bc[_0x3224c8(0x95)],'content':_0x4bfc92[_0x3224c8(0xb4)],'truncated':_0x4bfc92[_0x3224c8(0x7e)]});if(_0x47d4bc[_0x3224c8(0xd7)]!==_0x3224c8(0x88))_0x29da1a-=_0x4bfc92[_0x3224c8(0x84)];};await _0x331304({'kind':_0x16a26f(0x88),'label':_0x16a26f(0xa4),'directory':join(_0xf1cdc8[_0x16a26f(0xbd)],_0x16a26f(0xd4)),'boundary':_0xf1cdc8[_0x16a26f(0xbd)],'displayDirectory':_0x16a26f(0x8a),'displayScope':_0x16a26f(0x81),'scopePath':_0xf1cdc8[_0x16a26f(0xbd)]});const _0x2f5394=await nearestProjectRoot(_0xf1cdc8[_0x16a26f(0xa1)]);await _0x331304({'kind':_0x16a26f(0xc8),'label':_0x16a26f(0xbc),'directory':_0x2f5394,'boundary':_0x2f5394,'displayDirectory':_0x16a26f(0x87),'displayScope':_0x16a26f(0x87),'scopePath':_0x2f5394});for(const _0x51d0fb of instructionDirectories(_0x2f5394,_0xf1cdc8[_0x16a26f(0xa1)])[_0x16a26f(0xba)](-0x3*0x8f3+0xfe7+0x1*0xaf3)){const _0x47612d=relative(_0x2f5394,_0x51d0fb),_0x25205d=projectDisplayPath(_0x2f5394,_0x51d0fb);await _0x331304({'kind':_0x16a26f(0x8d),'label':_0x16a26f(0x96)+_0x47612d,'directory':_0x51d0fb,'boundary':_0x2f5394,'displayDirectory':_0x25205d,'displayScope':_0x25205d,'scopePath':_0x51d0fb});}const _0x5ee428=new Map(availableBuiltinSkills(_0xf1cdc8[_0x16a26f(0x98)])[_0x16a26f(0x91)](_0x362fd5=>[_0x362fd5[_0x16a26f(0xd0)],_0x362fd5]));await discoverSkills(join(_0xf1cdc8[_0x16a26f(0xbd)],_0x16a26f(0xd4),_0x16a26f(0xe0)),_0xf1cdc8[_0x16a26f(0xbd)],_0x5ee428);const _0x513914=join(_0x2f5394,_0x16a26f(0xd4),_0x16a26f(0xe0));await discoverSkills(_0x513914,_0x2f5394,_0x5ee428,displayPath(_0x513914,_0xf1cdc8[_0x16a26f(0xa1)],_0xf1cdc8[_0x16a26f(0x9c)]));const _0x15ab85=_0x5ee428[_0x16a26f(0xa9)]===0x3b*0x10+-0x125*0x1+-0x28b?'':_0x16a26f(0xab)+[..._0x5ee428][_0x16a26f(0x91)](([_0x385204,_0x3ddd0f])=>'-\x20'+_0x385204+':\x20'+_0x3ddd0f[_0x16a26f(0x8e)]+_0x16a26f(0xd2)+agentSkillSource(_0x3ddd0f)+')')[_0x16a26f(0xbb)]('\x0a');return{'entries':_0xdfe089,'skillCatalog':_0x15ab85,'skills':_0x5ee428};}export function renderAgentInstructions(_0x5ab82e,_0x53fa7b){const _0x404982=_0x557ad7;if(_0x5ab82e[_0x404982(0xdf)]===0x1267+0x14f7+0x1*-0x275e&&!_0x53fa7b)return undefined;const _0x460be5=_0x5ab82e[_0x404982(0xdf)]===-0x2*-0x59f+-0x1d*0xcd+-0xbfb*-0x1?REMOVAL_NOTICE:_0x53fa7b?REPLACEMENT_NOTICE:'',_0x3da051=_0x5ab82e[_0x404982(0x91)](_0x381c6d=>[_0x404982(0xb5)+_0x381c6d[_0x404982(0xa8)],_0x404982(0xd9)+_0x381c6d[_0x404982(0xad)],_0x404982(0x78)+_0x381c6d[_0x404982(0x95)],..._0x381c6d[_0x404982(0x7e)]?[_0x404982(0x94)]:[],'',_0x381c6d[_0x404982(0xb4)]][_0x404982(0xbb)]('\x0a'));return[_0x404982(0xc4),'',_0x404982(0xc6),...[_0x460be5,..._0x3da051][_0x404982(0xaa)](Boolean),_0x404982(0xa5)][_0x404982(0xbb)]('\x0a');}export async function loadAgentSkill(_0x447f2a){const _0x15ef1c=_0x557ad7;if(_0x447f2a[_0x15ef1c(0xcc)]===_0x15ef1c(0xb7)){const _0x1e99b8=await _0x447f2a[_0x15ef1c(0xa2)]();if(!_0x1e99b8[_0x15ef1c(0xde)]()||Buffer[_0x15ef1c(0xaf)](_0x1e99b8)>MAX_FILE_BYTES)return'';return[_0x15ef1c(0x9d)+_0x447f2a[_0x15ef1c(0xd0)]+'\x22>',_0x15ef1c(0xb3)+_0x447f2a[_0x15ef1c(0xd0)],_0x15ef1c(0xa0),'',_0x1e99b8[_0x15ef1c(0xde)](),_0x15ef1c(0xb2)][_0x15ef1c(0xbb)]('\x0a');}const _0x34f8cc=await safeRead(_0x447f2a[_0x15ef1c(0x8c)],_0x447f2a[_0x15ef1c(0xcd)]);if(!_0x34f8cc)return'';const _0x1210be=dirname(_0x447f2a[_0x15ef1c(0x8c)]),_0x5be71a=dirname(_0x447f2a[_0x15ef1c(0xad)]),_0x1e2eb1=await sampleSkillFiles(_0x1210be);return[_0x15ef1c(0x9d)+_0x447f2a[_0x15ef1c(0xd0)]+'\x22>',_0x15ef1c(0xb3)+_0x447f2a[_0x15ef1c(0xd0)],'',_0x34f8cc[_0x15ef1c(0xde)](),'',_0x15ef1c(0xae)+_0x5be71a,_0x15ef1c(0xc2),_0x15ef1c(0xdc),'',_0x15ef1c(0xdb),..._0x1e2eb1[_0x15ef1c(0x91)](_0xf8bcce=>_0x15ef1c(0x9a)+displayDescendant(_0x1210be,_0x5be71a,_0xf8bcce)+_0x15ef1c(0xd5)),_0x15ef1c(0xd6),_0x15ef1c(0xb2)][_0x15ef1c(0xbb)]('\x0a');}function _0x21be(){const _0x4f837d=['pgzPBgu+','C2HPzNq','D29YA3nWywnLrgLZCgXHEvbHDgG','phnRAwXSx2nVBNrLBNqGBMfTzt0I','icHVDMvYCMLKzsK','zxHLyW','u291CMnLoIbtreSGyNvPBhqTAw4UifrOAxmGC2TPBgWGAgfZig5VigzPBgvZExn0zw0GyMfZzsbKAxjLy3rVCNKGB3iGyNvUzgXLzcbZy3jPChrZlG','D29YA3nWywnL','Bg9Hza','qwDLBNqGC2TPBgW','vxnLCIbPBNn0CNvJDgLVBNm','pc9jtLnuuLvdveLptLm+','AxneAxjLy3rVCNK','Bwf4qNL0zxm','BgfIzwW','C2L6zq','zMLSDgvY','iYmGqxzHAwXHyMXLihnRAwXSCWOk','CM9VDa','zgLZCgXHEvbHDgG','qMfZzsbKAxjLy3rVCNKGzM9YihrOAxmGC2TPBgW6ia','yNL0zuXLBMD0Aa','odi3otHOsu55uwe','DxrMoa','pc9ZA2LSBf9JB250zw50pG','iYbtA2LSBdOG','y29UDgvUDa','iYmG','AxntEw1IB2XPy0XPBMS','yNvPBhrPBG','C3vIyxjYyxK','y2f0y2G','C2XPy2u','AM9PBG','uhjVAMvJDcbPBNn0CNvJDgLVBNm','Ag9Tzq','u0TjteWUBwq','C3bSAxq','C3rHCNrZv2L0Aa','zgLZCgXHEurPCMvJDg9YEq','uMvSyxrPDMuGCgf0AhmGAw4GDgHPCYbZA2LSBcbHCMuGCMvSyxrPDMuGDg8GDgHPCYbIyxnLigrPCMvJDg9YEs4','ywXS','iYbbr0vovfmUBwqGAw5ZDhj1y3rPB25Z','zMLSzu5HBwu','peLou1rsvunusu9ouZ4','C291CMnLugf0Aa','ChjVAMvJDa','mtiXotiZnNjeBuDPEq','lMDPDa','AxngAwXL','C291CMnL','yM91BMrHCNK','u0rligj1AwX0lwLU','BwLU','BMfTzq','quDftLrtlM1K','icHZB3vYy2u6ia','ChvZAa','lMfNzw50CW','pc9MAwXLpG','pc9ZA2LSBf9MAwXLCZ4','A2LUza','mta0ntaYveLmEwPW','u291CMnLoIa','quDftLrtlM92zxjYAwrLlM1K','phnRAwXSx2zPBgvZpG','vgHLigzPBguGBgLZDcbIzwXVDYbPCYbHihnHBxbSztSGCMvHzcbVBMX5ihrOzsbYzxnVDxjJzxmGBMvLzgvKigzVCIb0AguGDgfZAY4','nteYoeLOteLQCW','DhjPBq','BgvUz3rO','C2TPBgXZ','C29YDa','u2nVCgu6ia','mtfcvfnIEMW','C2nVCgvqyxrO','CMvHza','zgLYzwn0B3j5','Bg9JywXLq29TCgfYzq','Dhj1BMnHDgvK','vgHLihbYzxzPB3vZBhKGChjVDMLKzwqGquDftLrtlM1KigLUC3rYDwn0Aw9UCYbUBYbSB25NzxiGyxbWBhKU','mJa4odG5mhfoqvvbvG','pgfJy291BNq+','vgHLC2uGquDftLrtlM1KigLUC3rYDwn0Aw9UCYbYzxbSywnLigfSBcbWCMv2Aw91C2X5ihbYB3zPzgvKiefhru5uuY5TzcbPBNn0CNvJDgLVBNmU','mtbWyu5ou20','Bg9HzgvKqNL0zxm','B3zLCNjPzgu','mtKYyKzMDwfz','phbYB2PLy3q+','DxnLCG','nJi1otq4rxDhCMXR','FI8UywDLBNrZ','ywXSB2nvBNnHzMu','Cgf0Aa','C2nVCgvK','zgvZy3jPChrPB24','ndC3mtLMExPoBue','nxr6DKrpra','BwfW','y2XVC2u','Dg9tDhjPBMC','u3rHDhvZoIb0CNvUy2f0zwqGDg8GDgHLignVBMzPz3vYzwqGAw5ZDhj1y3rPB24GyNvKz2v0','zgLZCgXHEvnJB3bL','u2nVCgvKigLUC3rYDwn0Aw9UCZOG','C2v0','yxzHAwXHyMXLvg9VBhm','otyZAu5frwre'];_0x21be=function(){return _0x4f837d;};return _0x21be();}async function nearestProjectRoot(_0x1f02d1){const _0x54a384=_0x557ad7;let _0x1d3412=resolve(_0x1f02d1);const _0xba302b=parse(_0x1d3412)[_0x54a384(0xac)];while(!![]){try{return await stat(join(_0x1d3412,_0x54a384(0xca))),_0x1d3412;}catch{if(_0x1d3412===_0xba302b)return resolve(_0x1f02d1);_0x1d3412=dirname(_0x1d3412);}}}function instructionDirectories(_0x4931c7,_0x599e32){const _0x5ef5c7=_0x557ad7,_0x5431ba=relative(_0x4931c7,resolve(_0x599e32));if(_0x5431ba[_0x5ef5c7(0xc0)]('..')||isAbsolute(_0x5431ba))return[resolve(_0x599e32)];const _0x5dba60=[_0x4931c7];let _0x24a4c8=_0x4931c7;for(const _0x21fda5 of _0x5431ba[_0x5ef5c7(0xbf)](/[\\/]/u)[_0x5ef5c7(0xaa)](Boolean)){_0x24a4c8=join(_0x24a4c8,_0x21fda5),_0x5dba60[_0x5ef5c7(0xd3)](_0x24a4c8);}return _0x5dba60;}async function discoverSkills(_0x5e75d4,_0x3d3553,_0x15878c,_0x234660=_0x5e75d4){const _0x3e1651=_0x557ad7;let _0x968b88;try{_0x968b88=await readdir(_0x5e75d4,{'withFileTypes':!![]});}catch{return;}for(const _0x1ea0b4 of _0x968b88){if(!_0x1ea0b4[_0x3e1651(0xa6)]()&&!_0x1ea0b4[_0x3e1651(0xb6)]())continue;const _0x9eb517=join(_0x5e75d4,_0x1ea0b4[_0x3e1651(0xd0)],_0x3e1651(0xbe)),_0x492b76=await safeRead(_0x9eb517,_0x3d3553);if(!_0x492b76)continue;const _0x3fa104=/^description:\s*(.+)$/imu[_0x3e1651(0x9f)](_0x492b76)?.[-0x1ee7+-0x5*-0x2a7+0x11a5*0x1]?.[_0x3e1651(0xde)]()??_0x3e1651(0xa3);_0x15878c[_0x3e1651(0x97)](_0x1ea0b4[_0x3e1651(0xd0)],{'name':_0x1ea0b4[_0x3e1651(0xd0)],'description':_0x3fa104,'path':_0x9eb517,'displayPath':displayJoin(_0x234660,_0x1ea0b4[_0x3e1651(0xd0)],_0x3e1651(0xbe)),'boundary':_0x3d3553});}}async function safeRead(_0x300102,_0x5ae5b3){const _0x5777c0=_0x557ad7;try{const [_0x557472,_0x3b0d3c]=await Promise[_0x5777c0(0xc3)]([realpath(_0x300102),realpath(_0x5ae5b3)]),_0x21bdb9=relative(_0x3b0d3c,_0x557472);if(_0x21bdb9[_0x5777c0(0xc0)]('..')||isAbsolute(_0x21bdb9))return undefined;const _0x12980d=await readInstructionFile(_0x557472,MAX_FILE_BYTES);return _0x12980d&&!_0x12980d[_0x5777c0(0x7e)]?_0x12980d[_0x5777c0(0xb4)]:undefined;}catch{return undefined;}}async function loadPreferredInstruction(_0x5a2e6c){const _0x1995df=_0x557ad7;for(const _0x54dbb4 of INSTRUCTION_FILENAMES){const _0x220e14=resolve(_0x5a2e6c[_0x1995df(0x7c)],_0x54dbb4),_0x1565a3=await readInstructionFile(_0x220e14,_0x5a2e6c[_0x1995df(0xa7)]);if(!_0x1565a3)continue;return{'sourcePath':_0x220e14,'fileName':_0x54dbb4,'override':_0x54dbb4===_0x1995df(0xda),..._0x1565a3};}return undefined;}async function readInstructionFile(_0x2d94a5,_0x48b60f){const _0x191e30=_0x557ad7;let _0x23d919;try{if(!(await stat(_0x2d94a5))[_0x191e30(0xcb)]())return undefined;_0x23d919=await open(_0x2d94a5,'r');const _0x322de4=Buffer[_0x191e30(0x8b)](_0x48b60f+(0x5*0x395+0x1*0xdbd+-0x1fa5));let _0x5aee8e=-0x607*-0x3+0x48f+-0x33c*0x7;while(_0x5aee8e<_0x322de4[_0x191e30(0xdf)]){const {bytesRead:_0x1f4e86}=await _0x23d919[_0x191e30(0x7b)](_0x322de4,_0x5aee8e,_0x322de4[_0x191e30(0xdf)]-_0x5aee8e,_0x5aee8e);if(_0x1f4e86===0xd03*0x1+-0xd25*-0x1+-0x1a28)break;_0x5aee8e+=_0x1f4e86;}const _0x52c714=Math[_0x191e30(0xcf)](_0x5aee8e,_0x48b60f);return{'content':_0x322de4[_0x191e30(0xb8)](-0x14c4+0x15*-0x5b+0x1c3b,_0x52c714)[_0x191e30(0x93)](_0x191e30(0xb1)),'loadedBytes':_0x52c714,'truncated':_0x5aee8e>_0x52c714};}catch{return undefined;}finally{await _0x23d919?.[_0x191e30(0x92)]()[_0x191e30(0xb9)](()=>undefined);}}function projectDisplayPath(_0x135162,_0x32ef22){const _0x53570b=_0x557ad7,_0xbd32=relative(resolve(_0x135162),resolve(_0x32ef22));return displayJoin(_0x53570b(0x87),..._0xbd32[_0x53570b(0xbf)](/[\\/]/u)[_0x53570b(0xaa)](Boolean));}async function sampleSkillFiles(_0x358c86){const _0x46e8a7=_0x557ad7,_0x253be7=[],_0x2ef45e=[_0x358c86];let _0x386e9c=-0x1642+-0x11e*0x16+0x2ed6;while(_0x2ef45e[_0x46e8a7(0xdf)]>-0x2*0x2c5+-0x6*-0x3dc+-0x119e&&_0x253be7[_0x46e8a7(0xdf)]<-0x22bc+0x1*-0x16cf+0x3995&&_0x386e9c<-0x19ee+-0x3a7+0x33*0x97){const _0x1b32a1=_0x2ef45e[_0x46e8a7(0x9b)]();_0x386e9c++;let _0x17861e;try{_0x17861e=(await readdir(_0x1b32a1,{'withFileTypes':!![]}))[_0x46e8a7(0x77)]((_0x361aeb,_0x246438)=>_0x361aeb[_0x46e8a7(0xd0)][_0x46e8a7(0x7d)](_0x246438[_0x46e8a7(0xd0)]));}catch{continue;}for(const _0x15b0bf of _0x17861e){if(_0x15b0bf[_0x46e8a7(0xb6)]())continue;const _0x37e40f=join(_0x1b32a1,_0x15b0bf[_0x46e8a7(0xd0)]);if(_0x15b0bf[_0x46e8a7(0xa6)]())_0x2ef45e[_0x46e8a7(0xd3)](_0x37e40f);else{if(_0x15b0bf[_0x46e8a7(0xcb)]()&&_0x37e40f!==join(_0x358c86,_0x46e8a7(0xbe)))_0x253be7[_0x46e8a7(0xd3)](_0x37e40f);}if(_0x253be7[_0x46e8a7(0xdf)]>=0x1*0x2104+0x836+-0x2930)break;}}return _0x253be7;}function displayPath(_0xa7d242,_0x1b0d64,_0x49e2ca){const _0x3ee1d7=_0x557ad7;if(_0x49e2ca===undefined)return _0xa7d242;const _0x11c019=relative(resolve(_0x1b0d64),resolve(_0xa7d242));if(_0x11c019[_0x3ee1d7(0xc0)]('..')||isAbsolute(_0x11c019))return _0xa7d242;return displayJoin(_0x49e2ca,..._0x11c019[_0x3ee1d7(0xbf)](/[\\/]/u)[_0x3ee1d7(0xaa)](Boolean));}function displayDescendant(_0x105e73,_0x4af475,_0x35e9c7){const _0x155d9f=_0x557ad7;return displayJoin(_0x4af475,...relative(_0x105e73,_0x35e9c7)[_0x155d9f(0xbf)](/[\\/]/u)[_0x155d9f(0xaa)](Boolean));}function _0xb17d(_0x4ed968,_0x56f4a1){_0x4ed968=_0x4ed968-(-0xcec+-0x2027+0x192*0x1d);const _0x10b25e=_0x21be();let _0x16585e=_0x10b25e[_0x4ed968];if(_0xb17d['widifA']===undefined){var _0x2693e9=function(_0x4029dc){const _0x95fccb='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x1485dc='',_0x11b098='';for(let _0x19f534=-0x3c*0x35+-0x30b+0xf77,_0x5bc57f,_0xf07d44,_0x106b11=0x77f+0x25ba+-0xf13*0x3;_0xf07d44=_0x4029dc['charAt'](_0x106b11++);~_0xf07d44&&(_0x5bc57f=_0x19f534%(0xfb8+-0x111f+0x16b*0x1)?_0x5bc57f*(0xbb0+-0x154a+-0x61*-0x1a)+_0xf07d44:_0xf07d44,_0x19f534++%(-0x14f1+0x1f*-0xe6+0x2df*0x11))?_0x1485dc+=String['fromCharCode'](-0xf93+0x197f+0x1*-0x8ed&_0x5bc57f>>(-(0xa*-0xe3+-0x1*0x26e6+0x4c7*0xa)*_0x19f534&0x615+0xda3*-0x2+0x1537)):0x13*-0x1f1+0x119c+-0x23*-0x8d){_0xf07d44=_0x95fccb['indexOf'](_0xf07d44);}for(let _0x28edb3=-0x42b*-0x7+-0xe56+-0x1d*0x83,_0x4bf37d=_0x1485dc['length'];_0x28edb3<_0x4bf37d;_0x28edb3++){_0x11b098+='%'+('00'+_0x1485dc['charCodeAt'](_0x28edb3)['toString'](0x1e66*0x1+0x2*-0x38f+0x2*-0xb9c))['slice'](-(0xb4+0x1*0x649+-0x6fb*0x1));}return decodeURIComponent(_0x11b098);};_0xb17d['BirMSb']=_0x2693e9,_0xb17d['DCKFwc']={},_0xb17d['widifA']=!![];}const _0x6d42f7=_0x10b25e[-0xf62+0x9*0x301+0xba7*-0x1];_0xb17d['IYZySZ']!==_0x6d42f7&&(_0xb17d['DCKFwc']={},_0xb17d['IYZySZ']=_0x6d42f7);const _0x4cf30e=_0xb17d['DCKFwc'][_0x4ed968];return _0x4cf30e===undefined?(_0x16585e=_0xb17d['BirMSb'](_0x16585e),_0xb17d['DCKFwc'][_0x4ed968]=_0x16585e):_0x16585e=_0x4cf30e,_0x16585e;}function displayJoin(_0x1e6bda,..._0x17e4d8){const _0x32b721=_0x557ad7;return _0x1e6bda[_0x32b721(0xc0)]('/')?posix[_0x32b721(0xbb)](_0x1e6bda,..._0x17e4d8):join(_0x1e6bda,..._0x17e4d8);}
|
|
1
|
+
import { open, readdir, realpath, stat } from 'node:fs/promises';
|
|
2
|
+
import { dirname, isAbsolute, join, parse, posix, relative, resolve } from 'node:path';
|
|
3
|
+
import { availableBuiltinSkills } from './builtin-skills.js';
|
|
4
|
+
const MAX_FILE_BYTES = 64 * 1024;
|
|
5
|
+
const MAX_PROJECT_BYTES = 32 * 1024;
|
|
6
|
+
const INSTRUCTION_FILENAMES = ['AGENTS.override.md', 'AGENTS.md'];
|
|
7
|
+
const REPLACEMENT_NOTICE = 'These AGENTS.md instructions replace all previously provided AGENTS.md instructions.';
|
|
8
|
+
const REMOVAL_NOTICE = 'The previously provided AGENTS.md instructions no longer apply.';
|
|
9
|
+
export function agentSkillSource(skill) {
|
|
10
|
+
return skill.source === 'builtin' ? 'SDK built-in' : dirname(skill.displayPath);
|
|
11
|
+
}
|
|
12
|
+
export async function loadAgentInstructions(input) {
|
|
13
|
+
const entries = [];
|
|
14
|
+
let remaining = MAX_PROJECT_BYTES;
|
|
15
|
+
const addPreferred = async (entry) => {
|
|
16
|
+
const maxBytes = entry.kind === 'user' ? MAX_FILE_BYTES : remaining;
|
|
17
|
+
if (maxBytes === 0)
|
|
18
|
+
return;
|
|
19
|
+
const selected = await loadPreferredInstruction({
|
|
20
|
+
directory: entry.directory,
|
|
21
|
+
boundary: entry.boundary,
|
|
22
|
+
maxBytes
|
|
23
|
+
});
|
|
24
|
+
if (!selected || !selected.content.trim())
|
|
25
|
+
return;
|
|
26
|
+
entries.push({
|
|
27
|
+
kind: entry.kind,
|
|
28
|
+
label: selected.override ? `${entry.label} (override)` : entry.label,
|
|
29
|
+
sourcePath: selected.sourcePath,
|
|
30
|
+
displayPath: displayJoin(entry.displayDirectory, selected.fileName),
|
|
31
|
+
scopePath: resolve(entry.scopePath),
|
|
32
|
+
displayScope: entry.displayScope,
|
|
33
|
+
content: selected.content,
|
|
34
|
+
truncated: selected.truncated
|
|
35
|
+
});
|
|
36
|
+
if (entry.kind !== 'user')
|
|
37
|
+
remaining -= selected.loadedBytes;
|
|
38
|
+
};
|
|
39
|
+
await addPreferred({
|
|
40
|
+
kind: 'user',
|
|
41
|
+
label: 'User instructions',
|
|
42
|
+
directory: join(input.home, '.agents'),
|
|
43
|
+
boundary: input.home,
|
|
44
|
+
displayDirectory: '~/.agents',
|
|
45
|
+
displayScope: '<account>',
|
|
46
|
+
scopePath: input.home
|
|
47
|
+
});
|
|
48
|
+
const projectRoot = await nearestProjectRoot(input.workspace);
|
|
49
|
+
await addPreferred({
|
|
50
|
+
kind: 'project',
|
|
51
|
+
label: 'Project instructions',
|
|
52
|
+
directory: projectRoot,
|
|
53
|
+
boundary: projectRoot,
|
|
54
|
+
displayDirectory: '<project>',
|
|
55
|
+
displayScope: '<project>',
|
|
56
|
+
scopePath: projectRoot
|
|
57
|
+
});
|
|
58
|
+
for (const directory of instructionDirectories(projectRoot, input.workspace).slice(1)) {
|
|
59
|
+
const relativeDirectory = relative(projectRoot, directory);
|
|
60
|
+
const displayDirectory = projectDisplayPath(projectRoot, directory);
|
|
61
|
+
await addPreferred({
|
|
62
|
+
kind: 'scoped',
|
|
63
|
+
label: `Scoped instructions: ${relativeDirectory}`,
|
|
64
|
+
directory,
|
|
65
|
+
boundary: projectRoot,
|
|
66
|
+
displayDirectory,
|
|
67
|
+
displayScope: displayDirectory,
|
|
68
|
+
scopePath: directory
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const skills = new Map(availableBuiltinSkills(input.availableTools).map((skill) => [skill.name, skill]));
|
|
72
|
+
await discoverSkills(join(input.home, '.agents', 'skills'), input.home, skills);
|
|
73
|
+
const projectSkillRoot = join(projectRoot, '.agents', 'skills');
|
|
74
|
+
await discoverSkills(projectSkillRoot, projectRoot, skills, displayPath(projectSkillRoot, input.workspace, input.workspaceDisplayPath));
|
|
75
|
+
const skillCatalog = skills.size === 0
|
|
76
|
+
? ''
|
|
77
|
+
: `## Available skills\n\n${[...skills]
|
|
78
|
+
.map(([name, skill]) => `- ${name}: ${skill.description} (source: ${agentSkillSource(skill)})`)
|
|
79
|
+
.join('\n')}`;
|
|
80
|
+
return { entries, skillCatalog, skills };
|
|
81
|
+
}
|
|
82
|
+
export function renderAgentInstructions(entries, previousMayContainInstructions) {
|
|
83
|
+
if (entries.length === 0 && !previousMayContainInstructions)
|
|
84
|
+
return undefined;
|
|
85
|
+
const notice = entries.length === 0
|
|
86
|
+
? REMOVAL_NOTICE
|
|
87
|
+
: previousMayContainInstructions
|
|
88
|
+
? REPLACEMENT_NOTICE
|
|
89
|
+
: '';
|
|
90
|
+
const sections = entries.map((entry) => [
|
|
91
|
+
`## ${entry.label}`,
|
|
92
|
+
`Source: ${entry.displayPath}`,
|
|
93
|
+
`Scope: ${entry.displayScope}`,
|
|
94
|
+
...(entry.truncated ? ['Status: truncated to the configured instruction budget'] : []),
|
|
95
|
+
'',
|
|
96
|
+
entry.content
|
|
97
|
+
].join('\n'));
|
|
98
|
+
return [
|
|
99
|
+
'# AGENTS.md instructions',
|
|
100
|
+
'',
|
|
101
|
+
'<INSTRUCTIONS>',
|
|
102
|
+
...[notice, ...sections].filter(Boolean),
|
|
103
|
+
'</INSTRUCTIONS>'
|
|
104
|
+
].join('\n');
|
|
105
|
+
}
|
|
106
|
+
export async function loadAgentSkill(skill) {
|
|
107
|
+
if (skill.source === 'builtin') {
|
|
108
|
+
const body = await skill.load();
|
|
109
|
+
if (!body.trim() || Buffer.byteLength(body) > MAX_FILE_BYTES)
|
|
110
|
+
return '';
|
|
111
|
+
return [
|
|
112
|
+
`<skill_content name="${skill.name}">`,
|
|
113
|
+
`# Skill: ${skill.name}`,
|
|
114
|
+
'Source: SDK built-in. This skill has no filesystem base directory or bundled scripts.',
|
|
115
|
+
'',
|
|
116
|
+
body.trim(),
|
|
117
|
+
'</skill_content>'
|
|
118
|
+
].join('\n');
|
|
119
|
+
}
|
|
120
|
+
const body = await safeRead(skill.path, skill.boundary);
|
|
121
|
+
if (!body)
|
|
122
|
+
return '';
|
|
123
|
+
const base = dirname(skill.path);
|
|
124
|
+
const displayBase = dirname(skill.displayPath);
|
|
125
|
+
const files = await sampleSkillFiles(base);
|
|
126
|
+
return [
|
|
127
|
+
`<skill_content name="${skill.name}">`,
|
|
128
|
+
`# Skill: ${skill.name}`,
|
|
129
|
+
'',
|
|
130
|
+
body.trim(),
|
|
131
|
+
'',
|
|
132
|
+
`Base directory for this skill: ${displayBase}`,
|
|
133
|
+
'Relative paths in this skill are relative to this base directory.',
|
|
134
|
+
'The file list below is a sample; read only the resources needed for the task.',
|
|
135
|
+
'',
|
|
136
|
+
'<skill_files>',
|
|
137
|
+
...files.map((path) => `<file>${displayDescendant(base, displayBase, path)}</file>`),
|
|
138
|
+
'</skill_files>',
|
|
139
|
+
'</skill_content>'
|
|
140
|
+
].join('\n');
|
|
141
|
+
}
|
|
142
|
+
async function nearestProjectRoot(workspace) {
|
|
143
|
+
let current = resolve(workspace);
|
|
144
|
+
const root = parse(current).root;
|
|
145
|
+
while (true) {
|
|
146
|
+
try {
|
|
147
|
+
await stat(join(current, '.git'));
|
|
148
|
+
return current;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
if (current === root)
|
|
152
|
+
return resolve(workspace);
|
|
153
|
+
current = dirname(current);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function instructionDirectories(root, target) {
|
|
158
|
+
const relativeTarget = relative(root, resolve(target));
|
|
159
|
+
if (relativeTarget.startsWith('..') || isAbsolute(relativeTarget))
|
|
160
|
+
return [resolve(target)];
|
|
161
|
+
const result = [root];
|
|
162
|
+
let current = root;
|
|
163
|
+
for (const part of relativeTarget.split(/[\\/]/u).filter(Boolean)) {
|
|
164
|
+
current = join(current, part);
|
|
165
|
+
result.push(current);
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
async function discoverSkills(root, boundary, target, displayRoot = root) {
|
|
170
|
+
let entries;
|
|
171
|
+
try {
|
|
172
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
for (const entry of entries) {
|
|
178
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink())
|
|
179
|
+
continue;
|
|
180
|
+
const path = join(root, entry.name, 'SKILL.md');
|
|
181
|
+
const content = await safeRead(path, boundary);
|
|
182
|
+
if (!content)
|
|
183
|
+
continue;
|
|
184
|
+
const description = /^description:\s*(.+)$/imu.exec(content)?.[1]?.trim() ?? 'Agent skill';
|
|
185
|
+
target.set(entry.name, {
|
|
186
|
+
name: entry.name,
|
|
187
|
+
description,
|
|
188
|
+
path,
|
|
189
|
+
displayPath: displayJoin(displayRoot, entry.name, 'SKILL.md'),
|
|
190
|
+
boundary
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async function safeRead(path, boundary) {
|
|
195
|
+
try {
|
|
196
|
+
const [resolvedPath, resolvedBoundary] = await Promise.all([
|
|
197
|
+
realpath(path),
|
|
198
|
+
realpath(boundary)
|
|
199
|
+
]);
|
|
200
|
+
const rel = relative(resolvedBoundary, resolvedPath);
|
|
201
|
+
if (rel.startsWith('..') || isAbsolute(rel))
|
|
202
|
+
return undefined;
|
|
203
|
+
const loaded = await readInstructionFile(resolvedPath, MAX_FILE_BYTES);
|
|
204
|
+
return loaded && !loaded.truncated ? loaded.content : undefined;
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function loadPreferredInstruction(input) {
|
|
211
|
+
for (const fileName of INSTRUCTION_FILENAMES) {
|
|
212
|
+
const sourcePath = resolve(input.directory, fileName);
|
|
213
|
+
const loaded = await readInstructionFile(sourcePath, input.maxBytes);
|
|
214
|
+
if (!loaded)
|
|
215
|
+
continue;
|
|
216
|
+
return {
|
|
217
|
+
sourcePath,
|
|
218
|
+
fileName,
|
|
219
|
+
override: fileName === 'AGENTS.override.md',
|
|
220
|
+
...loaded
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
async function readInstructionFile(path, maxBytes) {
|
|
226
|
+
let handle;
|
|
227
|
+
try {
|
|
228
|
+
if (!(await stat(path)).isFile())
|
|
229
|
+
return undefined;
|
|
230
|
+
handle = await open(path, 'r');
|
|
231
|
+
const buffer = Buffer.allocUnsafe(maxBytes + 1);
|
|
232
|
+
let readBytes = 0;
|
|
233
|
+
while (readBytes < buffer.length) {
|
|
234
|
+
const { bytesRead } = await handle.read(buffer, readBytes, buffer.length - readBytes, readBytes);
|
|
235
|
+
if (bytesRead === 0)
|
|
236
|
+
break;
|
|
237
|
+
readBytes += bytesRead;
|
|
238
|
+
}
|
|
239
|
+
const loadedBytes = Math.min(readBytes, maxBytes);
|
|
240
|
+
return {
|
|
241
|
+
content: buffer.subarray(0, loadedBytes).toString('utf8'),
|
|
242
|
+
loadedBytes,
|
|
243
|
+
truncated: readBytes > loadedBytes
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
await handle?.close().catch(() => undefined);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function projectDisplayPath(projectRoot, directory) {
|
|
254
|
+
const suffix = relative(resolve(projectRoot), resolve(directory));
|
|
255
|
+
return displayJoin('<project>', ...suffix.split(/[\\/]/u).filter(Boolean));
|
|
256
|
+
}
|
|
257
|
+
async function sampleSkillFiles(root) {
|
|
258
|
+
const files = [];
|
|
259
|
+
const directories = [root];
|
|
260
|
+
let scannedDirectories = 0;
|
|
261
|
+
while (directories.length > 0 && files.length < 10 && scannedDirectories < 128) {
|
|
262
|
+
const directory = directories.shift();
|
|
263
|
+
scannedDirectories++;
|
|
264
|
+
let entries;
|
|
265
|
+
try {
|
|
266
|
+
entries = (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name));
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
for (const entry of entries) {
|
|
272
|
+
if (entry.isSymbolicLink())
|
|
273
|
+
continue;
|
|
274
|
+
const path = join(directory, entry.name);
|
|
275
|
+
if (entry.isDirectory())
|
|
276
|
+
directories.push(path);
|
|
277
|
+
else if (entry.isFile() && path !== join(root, 'SKILL.md'))
|
|
278
|
+
files.push(path);
|
|
279
|
+
if (files.length >= 10)
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return files;
|
|
284
|
+
}
|
|
285
|
+
function displayPath(path, physicalWorkspace, logicalWorkspace) {
|
|
286
|
+
if (logicalWorkspace === undefined)
|
|
287
|
+
return path;
|
|
288
|
+
const suffix = relative(resolve(physicalWorkspace), resolve(path));
|
|
289
|
+
if (suffix.startsWith('..') || isAbsolute(suffix))
|
|
290
|
+
return path;
|
|
291
|
+
return displayJoin(logicalWorkspace, ...suffix.split(/[\\/]/u).filter(Boolean));
|
|
292
|
+
}
|
|
293
|
+
function displayDescendant(physicalRoot, displayRoot, path) {
|
|
294
|
+
return displayJoin(displayRoot, ...relative(physicalRoot, path).split(/[\\/]/u).filter(Boolean));
|
|
295
|
+
}
|
|
296
|
+
function displayJoin(root, ...parts) {
|
|
297
|
+
return root.startsWith('/') ? posix.join(root, ...parts) : join(root, ...parts);
|
|
298
|
+
}
|