@theokit/sdk 3.1.1 → 3.2.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/CHANGELOG.md +10 -0
- package/dist/a2a/index.cjs +152 -35
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +152 -35
- package/dist/a2a/index.js.map +1 -1
- package/dist/{cron-C2jWAvlQ.d.cts → cron-4u1UdmgC.d.cts} +1 -1
- package/dist/{cron-BLRe166v.d.ts → cron-DuhVPer6.d.ts} +1 -1
- package/dist/cron.cjs +152 -35
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +152 -35
- package/dist/cron.js.map +1 -1
- package/dist/{errors-D_Bfo30u.d.ts → errors-_fPS0X80.d.ts} +1 -1
- package/dist/{errors-DZpCGlYv.d.cts → errors-jxK4yfp5.d.cts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +152 -35
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +152 -35
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +152 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +152 -35
- package/dist/index.js.map +1 -1
- package/dist/internal/runtime/context/context-discovery.d.ts +1 -1
- package/dist/internal/runtime/context/context-glob.d.ts +1 -0
- package/dist/internal/runtime/context/context-manager.d.ts +18 -1
- package/dist/internal/runtime/context/context-mdc-parser.d.ts +7 -6
- package/dist/internal/runtime/context/context-rules-frontmatter.d.ts +30 -0
- package/dist/internal/runtime/context/context-yaml-lite.d.ts +26 -0
- package/dist/project.cjs.map +1 -1
- package/dist/project.js.map +1 -1
- package/dist/{run-CLXKMRgq.d.cts → run-CrHz9BAP.d.cts} +9 -0
- package/dist/{run-CLXKMRgq.d.ts → run-CrHz9BAP.d.ts} +9 -0
- package/dist/types/run.d.ts +9 -0
- package/package.json +3 -3
package/dist/cron.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { V as Cron } from './cron-
|
|
2
|
-
import './run-
|
|
1
|
+
export { V as Cron } from './cron-4u1UdmgC.cjs';
|
|
2
|
+
import './run-CrHz9BAP.cjs';
|
|
3
3
|
import 'zod';
|
package/dist/cron.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { V as Cron } from './cron-
|
|
2
|
-
import './run-
|
|
1
|
+
export { V as Cron } from './cron-DuhVPer6.js';
|
|
2
|
+
import './run-CrHz9BAP.js';
|
|
3
3
|
import 'zod';
|
package/dist/cron.js
CHANGED
|
@@ -963,10 +963,10 @@ function buildToolPrompt(prompt) {
|
|
|
963
963
|
Respond by calling the \`output\` tool with the structured answer that matches the schema.`;
|
|
964
964
|
}
|
|
965
965
|
function setupStructuredOutput(schema, maxRetries) {
|
|
966
|
-
const
|
|
966
|
+
const z8 = requireZod();
|
|
967
967
|
const jsonSchema = toJsonSchema(schema, { unrepresentable: "any" });
|
|
968
968
|
return {
|
|
969
|
-
z:
|
|
969
|
+
z: z8,
|
|
970
970
|
jsonSchema,
|
|
971
971
|
maxRetries: maxRetries ?? 1,
|
|
972
972
|
initialUsage: { inputTokens: 0, outputTokens: 0 }
|
|
@@ -6042,7 +6042,7 @@ async function buildSystemPromptContext(inputs, userText, memoryFacts, manager =
|
|
|
6042
6042
|
memory: memoryFacts.map((fact) => ({ text: fact.text }))
|
|
6043
6043
|
};
|
|
6044
6044
|
}
|
|
6045
|
-
async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary) {
|
|
6045
|
+
async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary, contextPaths) {
|
|
6046
6046
|
const resolved = await resolveSendSkills(inputs, userText, memoryFacts);
|
|
6047
6047
|
const baseCtx = await buildSystemPromptContext(inputs, userText, memoryFacts, resolved.manager);
|
|
6048
6048
|
const assemblyCtx = {
|
|
@@ -6055,19 +6055,21 @@ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFa
|
|
|
6055
6055
|
assemblyCtx.activeMemorySummary = activeMemorySummary;
|
|
6056
6056
|
}
|
|
6057
6057
|
if (inputs.context !== void 0) {
|
|
6058
|
+
await inputs.context.applyScope(contextPaths);
|
|
6058
6059
|
const internal = inputs.context.internalAssemblySnapshot();
|
|
6059
6060
|
assemblyCtx.contextSnapshot = { sources: internal.sources };
|
|
6060
6061
|
if (internal.maxTokens !== void 0) assemblyCtx.contextMaxTokens = internal.maxTokens;
|
|
6061
6062
|
}
|
|
6062
6063
|
return assemblyCtx;
|
|
6063
6064
|
}
|
|
6064
|
-
async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary) {
|
|
6065
|
+
async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary, contextPaths) {
|
|
6065
6066
|
const ctx = await buildAssemblyContext(
|
|
6066
6067
|
inputs,
|
|
6067
6068
|
userText,
|
|
6068
6069
|
baseSystemPrompt,
|
|
6069
6070
|
memoryFacts,
|
|
6070
|
-
activeMemorySummary
|
|
6071
|
+
activeMemorySummary,
|
|
6072
|
+
contextPaths
|
|
6071
6073
|
);
|
|
6072
6074
|
return inputs.systemPromptPipeline.assemble(ctx);
|
|
6073
6075
|
}
|
|
@@ -6774,6 +6776,14 @@ var init_context_discovery = __esm({
|
|
|
6774
6776
|
followImports: false,
|
|
6775
6777
|
priority: 40
|
|
6776
6778
|
},
|
|
6779
|
+
{
|
|
6780
|
+
id: "theokit-rules",
|
|
6781
|
+
pattern: ".theokit/rules/*.md",
|
|
6782
|
+
scope: "globbed",
|
|
6783
|
+
parser: "rules-frontmatter",
|
|
6784
|
+
followImports: false,
|
|
6785
|
+
priority: 45
|
|
6786
|
+
},
|
|
6777
6787
|
{
|
|
6778
6788
|
id: "theokit-context",
|
|
6779
6789
|
pattern: ".theokit/context/*.md",
|
|
@@ -6857,32 +6867,27 @@ var init_context_import_resolver = __esm({
|
|
|
6857
6867
|
MAX_HOPS = 5;
|
|
6858
6868
|
}
|
|
6859
6869
|
});
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
}
|
|
6865
|
-
const yamlBody = m[1] ?? "";
|
|
6866
|
-
const body = m[2] ?? "";
|
|
6867
|
-
try {
|
|
6868
|
-
const parsed = parseSimpleYaml2(yamlBody);
|
|
6869
|
-
const validated = McdFrontmatterSchema.safeParse(parsed);
|
|
6870
|
-
if (!validated.success) return void 0;
|
|
6871
|
-
return { frontmatter: validated.data, body };
|
|
6872
|
-
} catch {
|
|
6873
|
-
return void 0;
|
|
6874
|
-
}
|
|
6870
|
+
|
|
6871
|
+
// src/internal/runtime/context/context-glob.ts
|
|
6872
|
+
function globToRegex(glob) {
|
|
6873
|
+
const compiled = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "::GLOBSTAR_SLASH::").replace(/\*\*/g, "::GLOBSTAR::").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/::GLOBSTAR_SLASH::/g, "(?:.*/)?").replace(/::GLOBSTAR::/g, ".*");
|
|
6874
|
+
return new RegExp(`^${compiled}$`);
|
|
6875
6875
|
}
|
|
6876
|
-
function
|
|
6877
|
-
if (
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
const globRes = fm.globs.map(globToRegex);
|
|
6881
|
-
return touchedFiles.some((file) => globRes.some((re) => re.test(file)));
|
|
6876
|
+
function anyGlobMatches(patterns, paths) {
|
|
6877
|
+
if (patterns.length === 0 || paths.length === 0) return false;
|
|
6878
|
+
const res = patterns.map(globToRegex);
|
|
6879
|
+
return paths.some((p) => res.some((re) => re.test(p)));
|
|
6882
6880
|
}
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6881
|
+
var init_context_glob = __esm({
|
|
6882
|
+
"src/internal/runtime/context/context-glob.ts"() {
|
|
6883
|
+
}
|
|
6884
|
+
});
|
|
6885
|
+
|
|
6886
|
+
// src/internal/runtime/context/context-yaml-lite.ts
|
|
6887
|
+
function splitFrontmatter3(content) {
|
|
6888
|
+
const m = FRONTMATTER_RE.exec(content);
|
|
6889
|
+
if (m === null) return { yaml: void 0, body: content };
|
|
6890
|
+
return { yaml: m[1] ?? "", body: m[2] ?? "" };
|
|
6886
6891
|
}
|
|
6887
6892
|
function parseSimpleYaml2(yaml) {
|
|
6888
6893
|
const out = {};
|
|
@@ -6929,15 +6934,76 @@ function parseScalar(s) {
|
|
|
6929
6934
|
if (/^-?\d+$/.test(s)) return parseInt(s, 10);
|
|
6930
6935
|
return s.replace(/^["']|["']$/g, "");
|
|
6931
6936
|
}
|
|
6932
|
-
var
|
|
6937
|
+
var FRONTMATTER_RE;
|
|
6938
|
+
var init_context_yaml_lite = __esm({
|
|
6939
|
+
"src/internal/runtime/context/context-yaml-lite.ts"() {
|
|
6940
|
+
FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
|
|
6941
|
+
}
|
|
6942
|
+
});
|
|
6943
|
+
function parseMdc(content) {
|
|
6944
|
+
const { yaml, body } = splitFrontmatter3(content);
|
|
6945
|
+
if (yaml === void 0) {
|
|
6946
|
+
return { frontmatter: { alwaysApply: true }, body: content };
|
|
6947
|
+
}
|
|
6948
|
+
try {
|
|
6949
|
+
const parsed = parseSimpleYaml2(yaml);
|
|
6950
|
+
const validated = McdFrontmatterSchema.safeParse(parsed);
|
|
6951
|
+
if (!validated.success) return void 0;
|
|
6952
|
+
return { frontmatter: validated.data, body };
|
|
6953
|
+
} catch {
|
|
6954
|
+
return void 0;
|
|
6955
|
+
}
|
|
6956
|
+
}
|
|
6957
|
+
function shouldActivate(fm, touchedFiles) {
|
|
6958
|
+
if (fm.alwaysApply === true) return true;
|
|
6959
|
+
if (fm.globs === void 0 || fm.globs.length === 0) return false;
|
|
6960
|
+
return anyGlobMatches(fm.globs, touchedFiles);
|
|
6961
|
+
}
|
|
6962
|
+
var McdFrontmatterSchema;
|
|
6933
6963
|
var init_context_mdc_parser = __esm({
|
|
6934
6964
|
"src/internal/runtime/context/context-mdc-parser.ts"() {
|
|
6965
|
+
init_context_glob();
|
|
6966
|
+
init_context_yaml_lite();
|
|
6935
6967
|
McdFrontmatterSchema = z.object({
|
|
6936
6968
|
description: z.string().optional(),
|
|
6937
6969
|
globs: z.array(z.string()).optional(),
|
|
6938
6970
|
alwaysApply: z.boolean().optional()
|
|
6939
6971
|
});
|
|
6940
|
-
|
|
6972
|
+
}
|
|
6973
|
+
});
|
|
6974
|
+
function parseRules(content) {
|
|
6975
|
+
const { yaml, body } = splitFrontmatter3(content);
|
|
6976
|
+
if (yaml === void 0) {
|
|
6977
|
+
return { frontmatter: { alwaysApply: true }, body: content };
|
|
6978
|
+
}
|
|
6979
|
+
try {
|
|
6980
|
+
const parsed = parseSimpleYaml2(yaml);
|
|
6981
|
+
const validated = RulesFrontmatterSchema.safeParse(parsed);
|
|
6982
|
+
if (!validated.success) return void 0;
|
|
6983
|
+
return { frontmatter: validated.data, body };
|
|
6984
|
+
} catch {
|
|
6985
|
+
return void 0;
|
|
6986
|
+
}
|
|
6987
|
+
}
|
|
6988
|
+
function shouldActivateRule(fm, inScopePaths) {
|
|
6989
|
+
if (fm.enabled === false) return false;
|
|
6990
|
+
if (fm.alwaysApply === true) return true;
|
|
6991
|
+
const patterns = [...fm.paths ?? [], ...fm.globs ?? []];
|
|
6992
|
+
if (patterns.length === 0) return false;
|
|
6993
|
+
return anyGlobMatches(patterns, inScopePaths);
|
|
6994
|
+
}
|
|
6995
|
+
var RulesFrontmatterSchema;
|
|
6996
|
+
var init_context_rules_frontmatter = __esm({
|
|
6997
|
+
"src/internal/runtime/context/context-rules-frontmatter.ts"() {
|
|
6998
|
+
init_context_glob();
|
|
6999
|
+
init_context_yaml_lite();
|
|
7000
|
+
RulesFrontmatterSchema = z.object({
|
|
7001
|
+
description: z.string().optional(),
|
|
7002
|
+
paths: z.array(z.string()).optional(),
|
|
7003
|
+
globs: z.array(z.string()).optional(),
|
|
7004
|
+
alwaysApply: z.boolean().optional(),
|
|
7005
|
+
enabled: z.boolean().optional()
|
|
7006
|
+
});
|
|
6941
7007
|
}
|
|
6942
7008
|
});
|
|
6943
7009
|
async function runDiscovery(opts) {
|
|
@@ -6973,6 +7039,9 @@ async function loadOneSource(spec, path, opts, gitRoot) {
|
|
|
6973
7039
|
if (spec.parser === "mdc") {
|
|
6974
7040
|
return loadMdcSource(spec, path, id, opts);
|
|
6975
7041
|
}
|
|
7042
|
+
if (spec.parser === "rules-frontmatter") {
|
|
7043
|
+
return loadRulesSource(spec, path, id, opts);
|
|
7044
|
+
}
|
|
6976
7045
|
if (spec.parser === "frontmatter-zod") {
|
|
6977
7046
|
return void 0;
|
|
6978
7047
|
}
|
|
@@ -6996,6 +7065,24 @@ async function loadMdcSource(spec, path, id, opts) {
|
|
|
6996
7065
|
truncated: false
|
|
6997
7066
|
};
|
|
6998
7067
|
}
|
|
7068
|
+
async function loadRulesSource(spec, path, id, opts) {
|
|
7069
|
+
let raw;
|
|
7070
|
+
try {
|
|
7071
|
+
raw = await readFile(path, "utf8");
|
|
7072
|
+
} catch {
|
|
7073
|
+
return void 0;
|
|
7074
|
+
}
|
|
7075
|
+
const parsed = parseRules(raw);
|
|
7076
|
+
if (parsed === void 0) return void 0;
|
|
7077
|
+
if (!shouldActivateRule(parsed.frontmatter, opts.touchedFiles ?? [])) return void 0;
|
|
7078
|
+
return {
|
|
7079
|
+
id,
|
|
7080
|
+
source: path,
|
|
7081
|
+
content: parsed.body,
|
|
7082
|
+
priority: spec.priority,
|
|
7083
|
+
truncated: false
|
|
7084
|
+
};
|
|
7085
|
+
}
|
|
6999
7086
|
async function loadPlainMarkdownSource(spec, path, id, opts) {
|
|
7000
7087
|
const loaded = await loadPlainMarkdown(path, { maxBytesPerFile: opts.maxBytesPerFile });
|
|
7001
7088
|
if (loaded === void 0) return void 0;
|
|
@@ -7021,6 +7108,7 @@ var init_context_discovery_runner = __esm({
|
|
|
7021
7108
|
init_context_import_resolver();
|
|
7022
7109
|
init_context_loaders();
|
|
7023
7110
|
init_context_mdc_parser();
|
|
7111
|
+
init_context_rules_frontmatter();
|
|
7024
7112
|
}
|
|
7025
7113
|
});
|
|
7026
7114
|
var ContextSourceFrontmatterSchema;
|
|
@@ -7156,6 +7244,10 @@ function matchesGlob(pattern, path) {
|
|
|
7156
7244
|
function tokenizeContent(content) {
|
|
7157
7245
|
return content.split(/\s+/).filter((token) => token.length > 0);
|
|
7158
7246
|
}
|
|
7247
|
+
function sameScope(a, b) {
|
|
7248
|
+
if (a.length !== b.length) return false;
|
|
7249
|
+
return a.every((v, i) => v === b[i]);
|
|
7250
|
+
}
|
|
7159
7251
|
var FileContextManager;
|
|
7160
7252
|
var init_context_manager = __esm({
|
|
7161
7253
|
"src/internal/runtime/context/context-manager.ts"() {
|
|
@@ -7176,6 +7268,13 @@ var init_context_manager = __esm({
|
|
|
7176
7268
|
settings;
|
|
7177
7269
|
settingSourcesIncludeProject;
|
|
7178
7270
|
state;
|
|
7271
|
+
/**
|
|
7272
|
+
* The in-scope file set used by the most recent `refresh`. Tracked so
|
|
7273
|
+
* `applyScope` only touches state when the scope actually changes — a
|
|
7274
|
+
* caller that never scopes (the common case) keeps the create-time
|
|
7275
|
+
* snapshot untouched, at zero per-send cost.
|
|
7276
|
+
*/
|
|
7277
|
+
lastScope = [];
|
|
7179
7278
|
async initialize() {
|
|
7180
7279
|
if (!this.settingSourcesIncludeProject && this.settings.manager !== "file") {
|
|
7181
7280
|
this.state = { config: { sources: [] }, loadedSources: [] };
|
|
@@ -7183,14 +7282,31 @@ var init_context_manager = __esm({
|
|
|
7183
7282
|
}
|
|
7184
7283
|
await this.refresh();
|
|
7185
7284
|
}
|
|
7186
|
-
|
|
7285
|
+
/**
|
|
7286
|
+
* Re-run discovery for a specific per-send in-scope file set (T3). Path-scoped
|
|
7287
|
+
* rules (`.theokit/rules/*.md`, `.cursor/rules/*.mdc` globs) activate iff a
|
|
7288
|
+
* pattern matches one of `contextPaths`. Idempotent: unchanged scope is a
|
|
7289
|
+
* no-op, and `undefined` scope while never previously scoped never touches
|
|
7290
|
+
* state (preserves the create-time snapshot for non-users).
|
|
7291
|
+
*/
|
|
7292
|
+
async applyScope(contextPaths) {
|
|
7293
|
+
const scope = contextPaths ?? [];
|
|
7294
|
+
if (scope.length === 0 && this.lastScope.length === 0) return;
|
|
7295
|
+
if (sameScope(scope, this.lastScope)) return;
|
|
7296
|
+
await this.refresh({ touchedFiles: scope });
|
|
7297
|
+
}
|
|
7298
|
+
async refresh(opts) {
|
|
7299
|
+
const touchedFiles = opts?.touchedFiles ?? [];
|
|
7300
|
+
this.lastScope = [...touchedFiles];
|
|
7187
7301
|
const config = await loadContextConfig(this.cwd);
|
|
7188
7302
|
const legacy = await loadSources(config, this.cwd);
|
|
7189
7303
|
const maxBytesPerFile = this.settings.maxBytesPerFile ?? DEFAULT_MAX_BYTES_PER_FILE;
|
|
7190
7304
|
const maxBytesTotal = this.settings.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL;
|
|
7191
7305
|
const discovered = await runDiscovery({
|
|
7192
7306
|
cwd: this.cwd,
|
|
7193
|
-
maxBytesPerFile
|
|
7307
|
+
maxBytesPerFile,
|
|
7308
|
+
touchedFiles
|
|
7309
|
+
});
|
|
7194
7310
|
const legacyAsAggregator = legacy.map((src) => ({
|
|
7195
7311
|
id: src.name,
|
|
7196
7312
|
source: src.path,
|
|
@@ -17120,7 +17236,8 @@ async function executeSendLocked(inputs, message, options) {
|
|
|
17120
17236
|
userText,
|
|
17121
17237
|
baseSystemPrompt,
|
|
17122
17238
|
memoryFacts,
|
|
17123
|
-
activeMemorySummary
|
|
17239
|
+
activeMemorySummary,
|
|
17240
|
+
options.contextPaths
|
|
17124
17241
|
);
|
|
17125
17242
|
const projectedSystemPrompt = await projectCurrentObjective(
|
|
17126
17243
|
inputs.storageHandle,
|
|
@@ -18008,7 +18125,7 @@ var init_local_agent = __esm({
|
|
|
18008
18125
|
runPreHook: (ut) => this.runPreHook(ut),
|
|
18009
18126
|
// biome-ignore format: G8 budget — callbacks wire to private methods.
|
|
18010
18127
|
resolveSystemPromptForSend: (ut, o, mf) => this.resolveSystemPrompt(ut, o, mf),
|
|
18011
|
-
assembleSystemPromptForSend: (ut, bp, mf, ams) => assembleSystemPromptForSend(this.assemblyInputs(), ut, bp, mf, ams),
|
|
18128
|
+
assembleSystemPromptForSend: (ut, bp, mf, ams, cp) => assembleSystemPromptForSend(this.assemblyInputs(), ut, bp, mf, ams, cp),
|
|
18012
18129
|
dispatchRun: (msg, o, sp, mf, pm, mt, mp) => this.dispatchRun(msg, o, sp, mf, pm, mt, mp)
|
|
18013
18130
|
},
|
|
18014
18131
|
message,
|