mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-09 17:29:12 +00:00
chore: use raw query imports for prompt sources (#682)
This commit is contained in:
parent
2f7218cba4
commit
dff9fd4e32
47 changed files with 67 additions and 99 deletions
|
|
@ -2,12 +2,9 @@ import { resolve } from 'node:path';
|
||||||
|
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
import { rawTextPlugin } from '../../build/raw-text-plugin.mjs';
|
|
||||||
|
|
||||||
const appRoot = import.meta.dirname;
|
const appRoot = import.meta.dirname;
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [rawTextPlugin()],
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(appRoot, 'src'),
|
'@': resolve(appRoot, 'src'),
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,17 @@ import { readFile } from 'node:fs/promises';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node ESM `load` hook: import `.md` / `.yaml` files as raw-string modules.
|
* Node ESM `load` hook: import `?raw` files as raw-string modules.
|
||||||
*
|
*
|
||||||
* This is the runtime counterpart of `build/raw-text-plugin.mjs` (the bundler
|
* This is the runtime counterpart of `build/raw-text-plugin.mjs` (the bundler
|
||||||
* plugin). The plugin covers build (tsdown) and test (vitest); this loader
|
* plugin). The plugin covers build (tsdown); this loader covers source
|
||||||
* covers source execution — e.g. `tsx`-run dev flows that import `kimi-core`
|
* execution — e.g. `tsx`-run dev flows that import `kimi-core` straight from
|
||||||
* straight from `src`, where no bundler is involved.
|
* `src`, where no bundler is involved.
|
||||||
*/
|
*/
|
||||||
export async function load(url, context, nextLoad) {
|
export async function load(url, context, nextLoad) {
|
||||||
const filePath = url.split('?', 1)[0] ?? url;
|
const [fileUrl, query = ''] = url.split('?', 2);
|
||||||
if (filePath.endsWith('.md') || filePath.endsWith('.yaml')) {
|
if (query.split('&').includes('raw')) {
|
||||||
const text = await readFile(fileURLToPath(filePath), 'utf-8');
|
const text = await readFile(fileURLToPath(fileUrl), 'utf-8');
|
||||||
return {
|
return {
|
||||||
format: 'module',
|
format: 'module',
|
||||||
shortCircuit: true,
|
shortCircuit: true,
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bundler plugin that lets `.md` / `.yaml` files be imported as raw strings:
|
* Bundler plugin that lets files be imported as raw strings:
|
||||||
*
|
*
|
||||||
* import description from './grep.md';
|
* import description from './grep.md?raw';
|
||||||
*
|
*
|
||||||
* The file content is inlined into the bundle at build time, so prompt
|
* The file content is inlined into the bundle at build time, so prompt
|
||||||
* source files never ship separately in `dist`. Shared by tsdown (build)
|
* source files never ship separately in `dist`. Vitest handles the same
|
||||||
* and vitest (test) so both resolve these imports identically.
|
* `?raw` imports through Vite's built-in asset loader.
|
||||||
*/
|
*/
|
||||||
export function rawTextPlugin() {
|
export function rawTextPlugin() {
|
||||||
return {
|
return {
|
||||||
name: 'raw-text',
|
name: 'raw-text',
|
||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
load(id) {
|
load(id) {
|
||||||
const path = id.split('?', 1)[0] ?? id;
|
const [path, query = ''] = id.split('?', 2);
|
||||||
if (!path.endsWith('.md') && !path.endsWith('.yaml')) return null;
|
if (!query.split('&').includes('raw')) return null;
|
||||||
const text = readFileSync(path, 'utf-8');
|
const text = readFileSync(path, 'utf-8');
|
||||||
return { code: `export default ${JSON.stringify(text)};`, map: null };
|
return { code: `export default ${JSON.stringify(text)};`, map: null };
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { register } from 'node:module';
|
import { register } from 'node:module';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the `.md` / `.yaml` raw-text loader. Pass to Node via `--import`
|
* Registers the `?raw` text loader. Pass to Node via `--import` (alongside
|
||||||
* (alongside tsx) so source-executed code can import these prompt files.
|
* tsx) so source-executed code can import text files.
|
||||||
*/
|
*/
|
||||||
register('./raw-text-loader.mjs', import.meta.url);
|
register('./raw-text-loader.mjs', import.meta.url);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
import { rawTextPlugin } from '../../build/raw-text-plugin.mjs';
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [rawTextPlugin()],
|
|
||||||
test: {
|
test: {
|
||||||
name: 'acp-adapter',
|
name: 'acp-adapter',
|
||||||
include: ['test/**/*.test.ts'],
|
include: ['test/**/*.test.ts'],
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import {
|
||||||
applyCompletionBudget,
|
applyCompletionBudget,
|
||||||
resolveCompletionBudget,
|
resolveCompletionBudget,
|
||||||
} from '../../utils/completion-budget';
|
} from '../../utils/completion-budget';
|
||||||
import compactionInstructionTemplate from './compaction-instruction.md';
|
import compactionInstructionTemplate from './compaction-instruction.md?raw';
|
||||||
import { renderMessagesToText } from './render-messages';
|
import { renderMessagesToText } from './render-messages';
|
||||||
import { renderTodoList, type TodoItem } from '../../tools/builtin/state/todo-list';
|
import { renderTodoList, type TodoItem } from '../../tools/builtin/state/todo-list';
|
||||||
import type { CompactionBeginData, CompactionResult } from './types';
|
import type { CompactionBeginData, CompactionResult } from './types';
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import type { Agent } from '..';
|
import type { Agent } from '..';
|
||||||
|
|
||||||
import SWARM_MODE_ENTER_REMINDER from './enter-reminder.md';
|
import SWARM_MODE_ENTER_REMINDER from './enter-reminder.md?raw';
|
||||||
import SWARM_MODE_EXIT_REMINDER from './exit-reminder.md';
|
import SWARM_MODE_EXIT_REMINDER from './exit-reminder.md?raw';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* manual = persistent toggle (/swarm on);
|
* manual = persistent toggle (/swarm on);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import agentYaml from './default/agent.yaml';
|
import agentYaml from './default/agent.yaml?raw';
|
||||||
import coderYaml from './default/coder.yaml';
|
import coderYaml from './default/coder.yaml?raw';
|
||||||
import exploreYaml from './default/explore.yaml';
|
import exploreYaml from './default/explore.yaml?raw';
|
||||||
import initMd from './default/init.md';
|
import initMd from './default/init.md?raw';
|
||||||
import planYaml from './default/plan.yaml';
|
import planYaml from './default/plan.yaml?raw';
|
||||||
import systemMd from './default/system.md';
|
import systemMd from './default/system.md?raw';
|
||||||
import { loadAgentProfilesFromSources } from './load';
|
import { loadAgentProfilesFromSources } from './load';
|
||||||
|
|
||||||
// Keyed by the source path the profile loader expects: profile YAML files
|
// Keyed by the source path the profile loader expects: profile YAML files
|
||||||
|
|
|
||||||
11
packages/agent-core/src/prompt-modules.d.ts
vendored
11
packages/agent-core/src/prompt-modules.d.ts
vendored
|
|
@ -1,12 +1,7 @@
|
||||||
// Raw-string imports for prompt sources. The `raw-text-plugin` (used by both
|
// Raw-string imports for prompt sources. Vite/Vitest handles `?raw` natively;
|
||||||
// tsdown and vitest) loads `.md` / `.yaml` files as their string content.
|
// tsdown uses the shared `raw-text-plugin` for the same import shape.
|
||||||
|
|
||||||
declare module '*.md' {
|
declare module '*?raw' {
|
||||||
const content: string;
|
|
||||||
export default content;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*.yaml' {
|
|
||||||
const content: string;
|
const content: string;
|
||||||
export default content;
|
export default content;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import {
|
||||||
type SubagentSuspendedEvent,
|
type SubagentSuspendedEvent,
|
||||||
type QueuedSubagentTask,
|
type QueuedSubagentTask,
|
||||||
} from './subagent-batch';
|
} from './subagent-batch';
|
||||||
import SUMMARY_CONTINUATION_PROMPT from './summary-continuation.md';
|
import SUMMARY_CONTINUATION_PROMPT from './summary-continuation.md?raw';
|
||||||
|
|
||||||
export const DEFAULT_SUBAGENT_TIMEOUT_MS = 30 * 60 * 1000;
|
export const DEFAULT_SUBAGENT_TIMEOUT_MS = 30 * 60 * 1000;
|
||||||
export const DEFAULT_SUBAGENT_TIMEOUT_DESCRIPTION = '30 minutes';
|
export const DEFAULT_SUBAGENT_TIMEOUT_DESCRIPTION = '30 minutes';
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { parseSkillText } from '../parser';
|
import { parseSkillText } from '../parser';
|
||||||
import type { SkillDefinition } from '../types';
|
import type { SkillDefinition } from '../types';
|
||||||
import CUSTOM_THEME_BODY from './custom-theme.md';
|
import CUSTOM_THEME_BODY from './custom-theme.md?raw';
|
||||||
|
|
||||||
const PSEUDO_PATH = 'builtin://custom-theme';
|
const PSEUDO_PATH = 'builtin://custom-theme';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { parseSkillText } from '../parser';
|
import { parseSkillText } from '../parser';
|
||||||
import type { SkillDefinition } from '../types';
|
import type { SkillDefinition } from '../types';
|
||||||
import IMPORT_FROM_CC_CODEX_BODY from './import-from-cc-codex.md';
|
import IMPORT_FROM_CC_CODEX_BODY from './import-from-cc-codex.md?raw';
|
||||||
|
|
||||||
const PSEUDO_PATH = 'builtin://import-from-cc-codex';
|
const PSEUDO_PATH = 'builtin://import-from-cc-codex';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { parseSkillText } from '../parser';
|
import { parseSkillText } from '../parser';
|
||||||
import type { SkillDefinition } from '../types';
|
import type { SkillDefinition } from '../types';
|
||||||
import MCP_CONFIG_BODY from './mcp-config.md';
|
import MCP_CONFIG_BODY from './mcp-config.md?raw';
|
||||||
|
|
||||||
const PSEUDO_PATH = 'builtin://mcp-config';
|
const PSEUDO_PATH = 'builtin://mcp-config';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { parseSkillText } from '../parser';
|
import { parseSkillText } from '../parser';
|
||||||
import type { SkillDefinition } from '../types';
|
import type { SkillDefinition } from '../types';
|
||||||
import CONSOLIDATE_BODY from './sub-skill/consolidate/SKILL.md';
|
import CONSOLIDATE_BODY from './sub-skill/consolidate/SKILL.md?raw';
|
||||||
import REVIEW_BODY from './sub-skill/review/SKILL.md';
|
import REVIEW_BODY from './sub-skill/review/SKILL.md?raw';
|
||||||
import PARENT_BODY from './sub-skill/SKILL.md';
|
import PARENT_BODY from './sub-skill/SKILL.md?raw';
|
||||||
|
|
||||||
function makeBuiltin(
|
function makeBuiltin(
|
||||||
body: string,
|
body: string,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { parseSkillText } from '../parser';
|
import { parseSkillText } from '../parser';
|
||||||
import type { SkillDefinition } from '../types';
|
import type { SkillDefinition } from '../types';
|
||||||
import UPDATE_CONFIG_BODY from './update-config.md';
|
import UPDATE_CONFIG_BODY from './update-config.md?raw';
|
||||||
|
|
||||||
const PSEUDO_PATH = 'builtin://update-config';
|
const PSEUDO_PATH = 'builtin://update-config';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import type { ToolExecution } from '../../loop/types';
|
||||||
import { toInputJsonSchema } from '../support/input-schema';
|
import { toInputJsonSchema } from '../support/input-schema';
|
||||||
import { matchesGlobRuleSubject } from '../support/rule-match';
|
import { matchesGlobRuleSubject } from '../support/rule-match';
|
||||||
import { formatPlainObject } from './format';
|
import { formatPlainObject } from './format';
|
||||||
import TASK_LIST_DESCRIPTION from './task-list.md';
|
import TASK_LIST_DESCRIPTION from './task-list.md?raw';
|
||||||
|
|
||||||
// ── Input schema ─────────────────────────────────────────────────────
|
// ── Input schema ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import type { ExecutableToolResult, ToolExecution } from '../../loop/types';
|
||||||
import { toInputJsonSchema } from '../support/input-schema';
|
import { toInputJsonSchema } from '../support/input-schema';
|
||||||
import { matchesGlobRuleSubject } from '../support/rule-match';
|
import { matchesGlobRuleSubject } from '../support/rule-match';
|
||||||
import { formatPlainObject } from './format';
|
import { formatPlainObject } from './format';
|
||||||
import TASK_OUTPUT_DESCRIPTION from './task-output.md';
|
import TASK_OUTPUT_DESCRIPTION from './task-output.md?raw';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum bytes of output included inline as a preview. Output larger
|
* Maximum bytes of output included inline as a preview. Output larger
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import {
|
||||||
import type { ToolExecution } from '../../loop/types';
|
import type { ToolExecution } from '../../loop/types';
|
||||||
import { toInputJsonSchema } from '../support/input-schema';
|
import { toInputJsonSchema } from '../support/input-schema';
|
||||||
import { matchesGlobRuleSubject } from '../support/rule-match';
|
import { matchesGlobRuleSubject } from '../support/rule-match';
|
||||||
import TASK_STOP_DESCRIPTION from './task-stop.md';
|
import TASK_STOP_DESCRIPTION from './task-stop.md?raw';
|
||||||
|
|
||||||
// ── Input schema ─────────────────────────────────────────────────────
|
// ── Input schema ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
import { ToolAccesses } from '../../../loop/tool-access';
|
import { ToolAccesses } from '../../../loop/tool-access';
|
||||||
import type { ExecutableToolContext, ExecutableToolResult, ToolExecution } from '../../../loop/types';
|
import type { ExecutableToolContext, ExecutableToolResult, ToolExecution } from '../../../loop/types';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import AGENT_SWARM_DESCRIPTION from './agent-swarm.md';
|
import AGENT_SWARM_DESCRIPTION from './agent-swarm.md?raw';
|
||||||
|
|
||||||
const DEFAULT_SUBAGENT_TYPE = 'coder';
|
const DEFAULT_SUBAGENT_TYPE = 'coder';
|
||||||
const PROMPT_TEMPLATE_PLACEHOLDER = '{{item}}';
|
const PROMPT_TEMPLATE_PLACEHOLDER = '{{item}}';
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,9 @@ import {
|
||||||
import { AgentBackgroundTask, type BackgroundManager } from '../../../agent/background';
|
import { AgentBackgroundTask, type BackgroundManager } from '../../../agent/background';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import { matchesGlobRuleSubject } from '../../support/rule-match';
|
import { matchesGlobRuleSubject } from '../../support/rule-match';
|
||||||
import AGENT_BACKGROUND_DISABLED_DESCRIPTION from './agent-background-disabled.md';
|
import AGENT_BACKGROUND_DISABLED_DESCRIPTION from './agent-background-disabled.md?raw';
|
||||||
import AGENT_BACKGROUND_DESCRIPTION from './agent-background-enabled.md';
|
import AGENT_BACKGROUND_DESCRIPTION from './agent-background-enabled.md?raw';
|
||||||
import AGENT_DESCRIPTION_BASE from './agent.md';
|
import AGENT_DESCRIPTION_BASE from './agent.md?raw';
|
||||||
|
|
||||||
// ── AgentTool input ──────────────────────────────────────────────────
|
// ── AgentTool input ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import type {
|
||||||
} from '../../../rpc';
|
} from '../../../rpc';
|
||||||
import type { TelemetryPropertyValue } from '../../../telemetry';
|
import type { TelemetryPropertyValue } from '../../../telemetry';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import DESCRIPTION from './ask-user.md';
|
import DESCRIPTION from './ask-user.md?raw';
|
||||||
|
|
||||||
// ── Input schema ─────────────────────────────────────────────────────
|
// ── Input schema ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import { isInlineSkillType, type SkillDefinition } from '../../../skill';
|
||||||
import { renderPrompt } from '../../../utils/render-prompt';
|
import { renderPrompt } from '../../../utils/render-prompt';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import { matchesGlobRuleSubject } from '../../support/rule-match';
|
import { matchesGlobRuleSubject } from '../../support/rule-match';
|
||||||
import skillDescriptionTemplate from './skill-tool.md';
|
import skillDescriptionTemplate from './skill-tool.md?raw';
|
||||||
|
|
||||||
export const MAX_SKILL_QUERY_DEPTH = 3;
|
export const MAX_SKILL_QUERY_DEPTH = 3;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import { literalRulePattern, matchesPathRuleSubject } from '../../support/rule-match';
|
import { literalRulePattern, matchesPathRuleSubject } from '../../support/rule-match';
|
||||||
import type { WorkspaceConfig } from '../../support/workspace';
|
import type { WorkspaceConfig } from '../../support/workspace';
|
||||||
import { materializeModelText, toModelTextView } from './line-endings';
|
import { materializeModelText, toModelTextView } from './line-endings';
|
||||||
import EDIT_DESCRIPTION from './edit.md';
|
import EDIT_DESCRIPTION from './edit.md?raw';
|
||||||
|
|
||||||
// `old_string` must be non-empty: the non-replace_all branch walks
|
// `old_string` must be non-empty: the non-replace_all branch walks
|
||||||
// occurrences with `content.indexOf("", pos)`, which would loop forever
|
// occurrences with `content.indexOf("", pos)`, which would loop forever
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ import type { PathClass } from '../../policies/path-access';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import { literalRulePattern, matchesGlobRuleSubject } from '../../support/rule-match';
|
import { literalRulePattern, matchesGlobRuleSubject } from '../../support/rule-match';
|
||||||
import type { WorkspaceConfig } from '../../support/workspace';
|
import type { WorkspaceConfig } from '../../support/workspace';
|
||||||
import GLOB_DESCRIPTION from './glob.md';
|
import GLOB_DESCRIPTION from './glob.md?raw';
|
||||||
|
|
||||||
export const GlobInputSchema = z.object({
|
export const GlobInputSchema = z.object({
|
||||||
pattern: z.string().describe('Glob pattern to match files/directories.'),
|
pattern: z.string().describe('Glob pattern to match files/directories.'),
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ import { ensureRgPath, rgUnavailableMessage } from '../../support/rg-locator';
|
||||||
import { literalRulePattern, matchesGlobRuleSubject } from '../../support/rule-match';
|
import { literalRulePattern, matchesGlobRuleSubject } from '../../support/rule-match';
|
||||||
import { ToolResultBuilder } from '../../support/result-builder';
|
import { ToolResultBuilder } from '../../support/result-builder';
|
||||||
import type { WorkspaceConfig } from '../../support/workspace';
|
import type { WorkspaceConfig } from '../../support/workspace';
|
||||||
import GREP_DESCRIPTION from './grep.md';
|
import GREP_DESCRIPTION from './grep.md?raw';
|
||||||
|
|
||||||
export const GrepInputSchema = z.object({
|
export const GrepInputSchema = z.object({
|
||||||
pattern: z.string().describe('Regular expression to search for.'),
|
pattern: z.string().describe('Regular expression to search for.'),
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import { MEDIA_SNIFF_BYTES, detectFileType, sniffImageDimensions } from '../../s
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import { literalRulePattern, matchesPathRuleSubject } from '../../support/rule-match';
|
import { literalRulePattern, matchesPathRuleSubject } from '../../support/rule-match';
|
||||||
import type { WorkspaceConfig } from '../../support/workspace';
|
import type { WorkspaceConfig } from '../../support/workspace';
|
||||||
import readMediaDescriptionHead from './read-media.md';
|
import readMediaDescriptionHead from './read-media.md?raw';
|
||||||
|
|
||||||
// ── Constants ────────────────────────────────────────────────────────
|
// ── Constants ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import { literalRulePattern, matchesPathRuleSubject } from '../../support/rule-match';
|
import { literalRulePattern, matchesPathRuleSubject } from '../../support/rule-match';
|
||||||
import type { WorkspaceConfig } from '../../support/workspace';
|
import type { WorkspaceConfig } from '../../support/workspace';
|
||||||
import { makeCarriageReturnsVisible, type LineEndingStyle } from './line-endings';
|
import { makeCarriageReturnsVisible, type LineEndingStyle } from './line-endings';
|
||||||
import readDescriptionTemplate from './read.md';
|
import readDescriptionTemplate from './read.md?raw';
|
||||||
|
|
||||||
export const MAX_LINES: number = 1000;
|
export const MAX_LINES: number = 1000;
|
||||||
export const MAX_LINE_LENGTH: number = 2000;
|
export const MAX_LINE_LENGTH: number = 2000;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import { resolvePathAccessPath } from '../../policies/path-access';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import { literalRulePattern, matchesPathRuleSubject } from '../../support/rule-match';
|
import { literalRulePattern, matchesPathRuleSubject } from '../../support/rule-match';
|
||||||
import type { WorkspaceConfig } from '../../support/workspace';
|
import type { WorkspaceConfig } from '../../support/workspace';
|
||||||
import WRITE_DESCRIPTION from './write.md';
|
import WRITE_DESCRIPTION from './write.md?raw';
|
||||||
|
|
||||||
/** Mask isolating the file-type bits of a stat mode. */
|
/** Mask isolating the file-type bits of a stat mode. */
|
||||||
const S_IFMT = 0o170000;
|
const S_IFMT = 0o170000;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { z } from 'zod';
|
||||||
import type { BuiltinTool } from '../../../agent/tool';
|
import type { BuiltinTool } from '../../../agent/tool';
|
||||||
import type { ToolExecution } from '../../../loop/types';
|
import type { ToolExecution } from '../../../loop/types';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import DESCRIPTION from './create-goal.md';
|
import DESCRIPTION from './create-goal.md?raw';
|
||||||
|
|
||||||
export const CreateGoalToolInputSchema = z
|
export const CreateGoalToolInputSchema = z
|
||||||
.object({
|
.object({
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { z } from 'zod';
|
||||||
import type { BuiltinTool } from '../../../agent/tool';
|
import type { BuiltinTool } from '../../../agent/tool';
|
||||||
import type { ToolExecution } from '../../../loop/types';
|
import type { ToolExecution } from '../../../loop/types';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import DESCRIPTION from './get-goal.md';
|
import DESCRIPTION from './get-goal.md?raw';
|
||||||
|
|
||||||
export const GetGoalToolInputSchema = z.object({}).strict();
|
export const GetGoalToolInputSchema = z.object({}).strict();
|
||||||
export type GetGoalToolInput = z.infer<typeof GetGoalToolInputSchema>;
|
export type GetGoalToolInput = z.infer<typeof GetGoalToolInputSchema>;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import type { BuiltinTool } from '../../../agent/tool';
|
||||||
import type { GoalBudgetLimits } from '../../../agent/goal';
|
import type { GoalBudgetLimits } from '../../../agent/goal';
|
||||||
import type { ToolExecution } from '../../../loop/types';
|
import type { ToolExecution } from '../../../loop/types';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import DESCRIPTION from './set-goal-budget.md';
|
import DESCRIPTION from './set-goal-budget.md?raw';
|
||||||
|
|
||||||
const MIN_REASONABLE_TIME_BUDGET_MS = 1_000;
|
const MIN_REASONABLE_TIME_BUDGET_MS = 1_000;
|
||||||
const MAX_REASONABLE_TIME_BUDGET_MS = 24 * 60 * 60 * 1000;
|
const MAX_REASONABLE_TIME_BUDGET_MS = 24 * 60 * 60 * 1000;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import {
|
||||||
import type { BuiltinTool } from '../../../agent/tool';
|
import type { BuiltinTool } from '../../../agent/tool';
|
||||||
import type { ToolExecution } from '../../../loop/types';
|
import type { ToolExecution } from '../../../loop/types';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import DESCRIPTION from './update-goal.md';
|
import DESCRIPTION from './update-goal.md?raw';
|
||||||
|
|
||||||
export const UpdateGoalToolInputSchema = z
|
export const UpdateGoalToolInputSchema = z
|
||||||
.object({
|
.object({
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { z } from 'zod';
|
||||||
import type { BuiltinTool } from '../../../agent/tool';
|
import type { BuiltinTool } from '../../../agent/tool';
|
||||||
import type { ToolExecution } from '../../../loop/types';
|
import type { ToolExecution } from '../../../loop/types';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import DESCRIPTION from './enter-plan-mode.md';
|
import DESCRIPTION from './enter-plan-mode.md?raw';
|
||||||
|
|
||||||
// ── Input schema ─────────────────────────────────────────────────────
|
// ── Input schema ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import type { BuiltinTool } from '../../../agent/tool';
|
||||||
import type { ExecutableToolResult, ToolExecution } from '../../../loop/types';
|
import type { ExecutableToolResult, ToolExecution } from '../../../loop/types';
|
||||||
import type { ToolInputDisplay } from '../../display';
|
import type { ToolInputDisplay } from '../../display';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import DESCRIPTION from './exit-plan-mode.md';
|
import DESCRIPTION from './exit-plan-mode.md?raw';
|
||||||
|
|
||||||
// ── Input schema ─────────────────────────────────────────────────────
|
// ── Input schema ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ import { renderPrompt } from '../../../utils/render-prompt';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import { literalRulePattern, matchesGlobRuleSubject } from '../../support/rule-match';
|
import { literalRulePattern, matchesGlobRuleSubject } from '../../support/rule-match';
|
||||||
import { ToolResultBuilder } from '../../support/result-builder';
|
import { ToolResultBuilder } from '../../support/result-builder';
|
||||||
import bashDescriptionTemplate from './bash.md';
|
import bashDescriptionTemplate from './bash.md?raw';
|
||||||
|
|
||||||
const MS_PER_SECOND = 1000;
|
const MS_PER_SECOND = 1000;
|
||||||
const DEFAULT_TIMEOUT_S = 60;
|
const DEFAULT_TIMEOUT_S = 60;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import type { BuiltinTool } from '../../../agent/tool';
|
||||||
import type { ToolExecution } from '../../../loop/types';
|
import type { ToolExecution } from '../../../loop/types';
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import type { ToolStore } from '../../store';
|
import type { ToolStore } from '../../store';
|
||||||
import DESCRIPTION from './todo-list.md';
|
import DESCRIPTION from './todo-list.md?raw';
|
||||||
|
|
||||||
// ── TODO state shape ─────────────────────────────────────────────────
|
// ── TODO state shape ─────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import type { ExecutableToolContext, ExecutableToolResult, ToolExecution } from
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import { literalRulePattern, matchesGlobRuleSubject } from '../../support/rule-match';
|
import { literalRulePattern, matchesGlobRuleSubject } from '../../support/rule-match';
|
||||||
import { ToolResultBuilder } from '../../support/result-builder';
|
import { ToolResultBuilder } from '../../support/result-builder';
|
||||||
import DESCRIPTION from './fetch-url.md';
|
import DESCRIPTION from './fetch-url.md?raw';
|
||||||
|
|
||||||
// ── Provider interface (host-injected) ───────────────────────────────
|
// ── Provider interface (host-injected) ───────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import type { ExecutableToolContext, ExecutableToolResult, ToolExecution } from
|
||||||
import { toInputJsonSchema } from '../../support/input-schema';
|
import { toInputJsonSchema } from '../../support/input-schema';
|
||||||
import { literalRulePattern, matchesGlobRuleSubject } from '../../support/rule-match';
|
import { literalRulePattern, matchesGlobRuleSubject } from '../../support/rule-match';
|
||||||
import { ToolResultBuilder } from '../../support/result-builder';
|
import { ToolResultBuilder } from '../../support/result-builder';
|
||||||
import DESCRIPTION from './web-search.md';
|
import DESCRIPTION from './web-search.md?raw';
|
||||||
|
|
||||||
// ── Provider interface (host-injected) ───────────────────────────────
|
// ── Provider interface (host-injected) ───────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ import {
|
||||||
oneShotJitteredNextCronRunMs,
|
oneShotJitteredNextCronRunMs,
|
||||||
} from './jitter';
|
} from './jitter';
|
||||||
import { formatLocalIsoWithOffset } from './time-format';
|
import { formatLocalIsoWithOffset } from './time-format';
|
||||||
import CRON_CREATE_DESCRIPTION from './cron-create.md';
|
import CRON_CREATE_DESCRIPTION from './cron-create.md?raw';
|
||||||
|
|
||||||
// ── Constants ────────────────────────────────────────────────────────
|
// ── Constants ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ import type { BuiltinTool } from '../../agent/tool';
|
||||||
import type { CronManager } from '../../agent/cron';
|
import type { CronManager } from '../../agent/cron';
|
||||||
import type { ToolExecution } from '../../loop/types';
|
import type { ToolExecution } from '../../loop/types';
|
||||||
import { toInputJsonSchema } from '../support/input-schema';
|
import { toInputJsonSchema } from '../support/input-schema';
|
||||||
import CRON_DELETE_DESCRIPTION from './cron-delete.md';
|
import CRON_DELETE_DESCRIPTION from './cron-delete.md?raw';
|
||||||
|
|
||||||
// ── Constants ────────────────────────────────────────────────────────
|
// ── Constants ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ import {
|
||||||
} from './cron-expr';
|
} from './cron-expr';
|
||||||
import { formatLocalIsoWithOffset } from './time-format';
|
import { formatLocalIsoWithOffset } from './time-format';
|
||||||
import type { CronTask } from './types';
|
import type { CronTask } from './types';
|
||||||
import CRON_LIST_DESCRIPTION from './cron-list.md';
|
import CRON_LIST_DESCRIPTION from './cron-list.md?raw';
|
||||||
|
|
||||||
// ── Input schema ─────────────────────────────────────────────────────
|
// ── Input schema ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import {
|
||||||
ExitPlanModeTool,
|
ExitPlanModeTool,
|
||||||
type ExitPlanModeInput,
|
type ExitPlanModeInput,
|
||||||
} from '../../src/tools/builtin/planning/exit-plan-mode';
|
} from '../../src/tools/builtin/planning/exit-plan-mode';
|
||||||
import DESCRIPTION from '../../src/tools/builtin/planning/exit-plan-mode.md';
|
import DESCRIPTION from '../../src/tools/builtin/planning/exit-plan-mode.md?raw';
|
||||||
import { executeTool } from './fixtures/execute-tool';
|
import { executeTool } from './fixtures/execute-tool';
|
||||||
import { toolContentString } from './fixtures/fake-kaos';
|
import { toolContentString } from './fixtures/fake-kaos';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
import { rawTextPlugin } from '../../build/raw-text-plugin.mjs';
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [rawTextPlugin()],
|
|
||||||
test: {
|
test: {
|
||||||
name: 'kimi-core',
|
name: 'kimi-core',
|
||||||
include: ['test/**/*.{test,e2e}.ts'],
|
include: ['test/**/*.{test,e2e}.ts'],
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,8 @@
|
||||||
// `resume.integration.test.ts` imports real kimi-core, which transitively
|
// `resume.integration.test.ts` imports real kimi-core, which transitively
|
||||||
// imports `.md` / `.yaml` prompt sources as raw strings (resolved by the
|
// imports prompt sources with `?raw`. This ambient declaration lets `tsc`
|
||||||
// shared `raw-text-plugin`). This ambient declaration lets `tsc` type-check
|
// type-check the migration package without pulling in kimi-core's own `.d.ts`.
|
||||||
// the migration package without pulling in kimi-core's own `.d.ts`.
|
|
||||||
|
|
||||||
declare module '*.md' {
|
declare module '*?raw' {
|
||||||
const content: string;
|
|
||||||
export default content;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*.yaml' {
|
|
||||||
const content: string;
|
const content: string;
|
||||||
export default content;
|
export default content;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
import { rawTextPlugin } from '../../build/raw-text-plugin.mjs';
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
// `resume.integration.test.ts` imports real kimi-core (`Session`), which
|
|
||||||
// transitively imports `.md` / `.yaml` prompt sources as raw strings.
|
|
||||||
// Reuse the same plugin kimi-core uses so those imports resolve identically.
|
|
||||||
plugins: [rawTextPlugin()],
|
|
||||||
test: {
|
test: {
|
||||||
name: 'migration-legacy',
|
name: 'migration-legacy',
|
||||||
include: ['test/**/*.test.ts'],
|
include: ['test/**/*.test.ts'],
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,7 @@ import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
import { rawTextPlugin } from '../../build/raw-text-plugin.mjs';
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [rawTextPlugin()],
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@moonshot-ai/agent-core': fileURLToPath(new URL('../agent-core/src/index.ts', import.meta.url)),
|
'@moonshot-ai/agent-core': fileURLToPath(new URL('../agent-core/src/index.ts', import.meta.url)),
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
import { rawTextPlugin } from '../../build/raw-text-plugin.mjs';
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [rawTextPlugin()],
|
|
||||||
test: {
|
test: {
|
||||||
name: 'protocol',
|
name: 'protocol',
|
||||||
include: ['src/__tests__/**/*.test.ts'],
|
include: ['src/__tests__/**/*.test.ts'],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue