@triflux/core 10.50.2 → 10.51.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/hooks/agy-session-hook.mjs +11 -56
- package/hooks/codex-session-hook.mjs +11 -101
- package/hub/bridge.mjs +1 -79
- package/hub/cli-adapter-base.mjs +12 -90
- package/hub/codex-adapter.mjs +0 -1
- package/hub/codex-preflight.mjs +5 -28
- package/hub/index.mjs +1 -1
- package/hub/lib/known-errors.json +2 -2
- package/hub/lib/process-utils.mjs +0 -123
- package/hub/lib/spawn-trace.mjs +3 -2
- package/hub/lib/timeout-defaults.mjs +0 -1
- package/hub/role-contract.mjs +0 -2
- package/hud/cli-policy.mjs +0 -22
- package/hud/constants.mjs +11 -26
- package/hud/hud-qos-status.mjs +23 -51
- package/hud/providers/gemini.mjs +105 -20
- package/hud/renderers.mjs +50 -104
- package/hud/utils.mjs +2 -2
- package/package.json +1 -3
- package/scripts/lib/agent-route-policy.mjs +162 -14
- package/scripts/lib/claudemd-scanner.mjs +2 -199
- package/scripts/lib/cli-claude.mjs +0 -2
- package/scripts/lib/context.mjs +3 -19
- package/scripts/lib/env-probe.mjs +5 -64
- package/scripts/lib/gemini-profiles.mjs +2 -69
- package/scripts/lib/machine-profile.mjs +3 -17
- package/scripts/lib/mcp-filter.mjs +109 -53
- package/scripts/lib/mcp-health.mjs +2 -2
- package/scripts/lib/mcp-server-catalog.mjs +2 -2
- package/scripts/lib/psmux-info.mjs +11 -59
- package/scripts/lib/session-presence.mjs +1 -1
- package/scripts/lib/skill-template.mjs +0 -245
- package/hub/dynamic-routing-engine.mjs +0 -511
- package/hub/lib/risk-tier.mjs +0 -53
- package/hub/lib/ssh-command.mjs +0 -231
- package/hub/lib/staged-file-detect.mjs +0 -43
- package/hub/lib/tfx-route-args.mjs +0 -353
- package/hub/routing-snapshot.mjs +0 -261
- package/mesh/index.mjs +0 -69
- package/mesh/mesh-budget.mjs +0 -137
- package/mesh/mesh-heartbeat.mjs +0 -100
- package/mesh/mesh-protocol.mjs +0 -96
- package/mesh/mesh-queue.mjs +0 -163
- package/mesh/mesh-registry.mjs +0 -78
- package/mesh/mesh-router.mjs +0 -77
- package/scripts/lib/dynamic-route-cli.mjs +0 -107
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
3
|
-
basename,
|
|
4
|
-
extname,
|
|
5
|
-
isAbsolute,
|
|
6
|
-
join,
|
|
7
|
-
relative,
|
|
8
|
-
resolve,
|
|
9
|
-
} from "node:path";
|
|
10
|
-
|
|
11
|
-
const IF_TAG_RE = /{{\s*(#if\s+([A-Za-z0-9_.-]+)|\/if)\s*}}/g;
|
|
12
|
-
const PARTIAL_RE = /{{>\s*([A-Za-z0-9_./-]+)\s*}}/g;
|
|
13
|
-
const FILE_INCLUDE_RE = /{{#include\s+([A-Za-z0-9_./-]+)\s*}}/g;
|
|
14
|
-
const VARIABLE_RE = /{{\s*([A-Za-z0-9_.-]+)\s*}}/g;
|
|
15
1
|
const FRONTMATTER_RE = /^---\r?\n(?:([\s\S]*?)\r?\n)?---\r?\n?/;
|
|
16
2
|
|
|
17
|
-
function isTruthy(value) {
|
|
18
|
-
if (typeof value === "string") return value.trim().length > 0;
|
|
19
|
-
return Boolean(value);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function normalizeVariable(context, key) {
|
|
23
|
-
if (Object.hasOwn(context, key)) return context[key];
|
|
24
|
-
const upper = key.toUpperCase();
|
|
25
|
-
if (Object.hasOwn(context, upper)) return context[upper];
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
3
|
function parseBoolean(raw) {
|
|
30
4
|
if (typeof raw !== "string") return undefined;
|
|
31
5
|
if (raw === "true") return true;
|
|
@@ -120,175 +94,6 @@ function parseFrontmatterBlock(block) {
|
|
|
120
94
|
return data;
|
|
121
95
|
}
|
|
122
96
|
|
|
123
|
-
function evaluateConditionals(source, context) {
|
|
124
|
-
const matcher = new RegExp(IF_TAG_RE.source, "g");
|
|
125
|
-
|
|
126
|
-
function walk(startIndex, nested) {
|
|
127
|
-
let output = "";
|
|
128
|
-
let cursor = startIndex;
|
|
129
|
-
|
|
130
|
-
while (true) {
|
|
131
|
-
const found = matcher.exec(source);
|
|
132
|
-
if (!found) {
|
|
133
|
-
if (nested) throw new Error("Unclosed {{#if ...}} block in template");
|
|
134
|
-
output += source.slice(cursor);
|
|
135
|
-
return { output, index: source.length };
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
output += source.slice(cursor, found.index);
|
|
139
|
-
cursor = matcher.lastIndex;
|
|
140
|
-
|
|
141
|
-
const directive = found[1];
|
|
142
|
-
const flag = found[2];
|
|
143
|
-
if (directive.startsWith("#if")) {
|
|
144
|
-
const nestedResult = walk(cursor, true);
|
|
145
|
-
cursor = nestedResult.index;
|
|
146
|
-
matcher.lastIndex = cursor;
|
|
147
|
-
if (isTruthy(normalizeVariable(context, flag))) {
|
|
148
|
-
output += nestedResult.output;
|
|
149
|
-
}
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (!nested) {
|
|
154
|
-
throw new Error("Unexpected {{/if}} without matching {{#if ...}}");
|
|
155
|
-
}
|
|
156
|
-
return { output, index: cursor };
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return walk(0, false).output;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function renderPartials(source, context, partials, options, includeStack) {
|
|
164
|
-
return source.replace(PARTIAL_RE, (_full, partialName) => {
|
|
165
|
-
const partial = partials[partialName];
|
|
166
|
-
if (partial == null) {
|
|
167
|
-
throw new Error(`Missing partial: ${partialName}`);
|
|
168
|
-
}
|
|
169
|
-
if (includeStack.includes(partialName)) {
|
|
170
|
-
const chain = [...includeStack, partialName].join(" -> ");
|
|
171
|
-
throw new Error(`Circular partial include: ${chain}`);
|
|
172
|
-
}
|
|
173
|
-
return renderWithContext(partial, context, partials, options, [
|
|
174
|
-
...includeStack,
|
|
175
|
-
partialName,
|
|
176
|
-
]);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function normalizeIncludeName(includeName) {
|
|
181
|
-
return includeName.replace(/\\/g, "/");
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function resolveIncludeContent(includeName, options) {
|
|
185
|
-
const normalizedName = normalizeIncludeName(includeName);
|
|
186
|
-
if (Object.hasOwn(options.includes, normalizedName)) {
|
|
187
|
-
return options.includes[normalizedName];
|
|
188
|
-
}
|
|
189
|
-
if (!options.includeBaseDir) {
|
|
190
|
-
throw new Error(`Missing include: ${normalizedName}`);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const baseDir = resolve(options.includeBaseDir);
|
|
194
|
-
const fullPath = resolve(baseDir, normalizedName);
|
|
195
|
-
const relativePath = relative(baseDir, fullPath);
|
|
196
|
-
const isInsideBaseDir =
|
|
197
|
-
relativePath === "" ||
|
|
198
|
-
(!relativePath.startsWith("..") && !isAbsolute(relativePath));
|
|
199
|
-
|
|
200
|
-
if (!isInsideBaseDir || !existsSync(fullPath)) {
|
|
201
|
-
throw new Error(`Missing include: ${normalizedName}`);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const content = readFileSync(fullPath, "utf8");
|
|
205
|
-
options.includes[normalizedName] = content;
|
|
206
|
-
return content;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function renderFileIncludes(source, context, partials, options, includeStack) {
|
|
210
|
-
return source.replace(FILE_INCLUDE_RE, (_full, includeName) => {
|
|
211
|
-
const normalizedName = normalizeIncludeName(includeName);
|
|
212
|
-
const content = resolveIncludeContent(normalizedName, options);
|
|
213
|
-
if (includeStack.includes(normalizedName)) {
|
|
214
|
-
const chain = [...includeStack, normalizedName].join(" -> ");
|
|
215
|
-
throw new Error(`Circular template include: ${chain}`);
|
|
216
|
-
}
|
|
217
|
-
return renderWithContext(content, context, partials, options, [
|
|
218
|
-
...includeStack,
|
|
219
|
-
normalizedName,
|
|
220
|
-
]);
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function renderVariables(source, context) {
|
|
225
|
-
return source.replace(VARIABLE_RE, (full, key) => {
|
|
226
|
-
const value = normalizeVariable(context, key);
|
|
227
|
-
if (value == null) {
|
|
228
|
-
throw new Error(`Missing template variable: ${key}`);
|
|
229
|
-
}
|
|
230
|
-
return String(value);
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function renderWithContext(
|
|
235
|
-
source,
|
|
236
|
-
context,
|
|
237
|
-
partials,
|
|
238
|
-
options,
|
|
239
|
-
includeStack = [],
|
|
240
|
-
) {
|
|
241
|
-
const afterIf = evaluateConditionals(source, context);
|
|
242
|
-
const afterPartials = renderPartials(
|
|
243
|
-
afterIf,
|
|
244
|
-
context,
|
|
245
|
-
partials,
|
|
246
|
-
options,
|
|
247
|
-
includeStack,
|
|
248
|
-
);
|
|
249
|
-
const afterFileIncludes = renderFileIncludes(
|
|
250
|
-
afterPartials,
|
|
251
|
-
context,
|
|
252
|
-
partials,
|
|
253
|
-
options,
|
|
254
|
-
includeStack,
|
|
255
|
-
);
|
|
256
|
-
return renderVariables(afterFileIncludes, context);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function readAllTemplateFiles(rootDir, currentDir = rootDir) {
|
|
260
|
-
if (!rootDir || !existsSync(rootDir)) return [];
|
|
261
|
-
|
|
262
|
-
const entries = readdirSync(currentDir, { withFileTypes: true }).sort(
|
|
263
|
-
(left, right) => left.name.localeCompare(right.name),
|
|
264
|
-
);
|
|
265
|
-
const files = [];
|
|
266
|
-
|
|
267
|
-
for (const entry of entries) {
|
|
268
|
-
const fullPath = join(currentDir, entry.name);
|
|
269
|
-
if (entry.isDirectory()) {
|
|
270
|
-
files.push(...readAllTemplateFiles(rootDir, fullPath));
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (!entry.isFile()) continue;
|
|
275
|
-
if (!entry.name.endsWith(".md") && !entry.name.endsWith(".tmpl")) continue;
|
|
276
|
-
|
|
277
|
-
const relativePath = relative(rootDir, fullPath).replace(/\\/g, "/");
|
|
278
|
-
const content = readFileSync(fullPath, "utf8");
|
|
279
|
-
files.push({ fullPath, relativePath, content });
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return files;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function setPartial(partials, key, value) {
|
|
286
|
-
if (!key) return;
|
|
287
|
-
if (!Object.hasOwn(partials, key)) {
|
|
288
|
-
partials[key] = value;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
97
|
export function parseFrontmatter(source) {
|
|
293
98
|
const match = source.match(FRONTMATTER_RE);
|
|
294
99
|
if (!match) return { data: {}, body: source };
|
|
@@ -297,53 +102,3 @@ export function parseFrontmatter(source) {
|
|
|
297
102
|
const body = source.slice(match[0].length);
|
|
298
103
|
return { data, body };
|
|
299
104
|
}
|
|
300
|
-
|
|
301
|
-
export function buildSkillTemplateContext({
|
|
302
|
-
frontmatter = {},
|
|
303
|
-
skillDirName = "",
|
|
304
|
-
} = {}) {
|
|
305
|
-
const context = { ...frontmatter };
|
|
306
|
-
const skillName = String(frontmatter.name || skillDirName || "").trim();
|
|
307
|
-
const skillDescription = String(frontmatter.description || "").trim();
|
|
308
|
-
|
|
309
|
-
let deep = frontmatter.DEEP ?? frontmatter.deep;
|
|
310
|
-
if (typeof deep === "string") {
|
|
311
|
-
const parsed = parseBoolean(deep.trim().toLowerCase());
|
|
312
|
-
deep = parsed ?? deep;
|
|
313
|
-
}
|
|
314
|
-
if (typeof deep !== "boolean") {
|
|
315
|
-
deep = /(^|[-_])deep($|[-_])/i.test(skillName);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
context.SKILL_NAME = skillName;
|
|
319
|
-
context.SKILL_DESCRIPTION = skillDescription;
|
|
320
|
-
context.DEEP = deep;
|
|
321
|
-
return context;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
export function loadTemplatePartials(partialsDir) {
|
|
325
|
-
const files = readAllTemplateFiles(partialsDir);
|
|
326
|
-
const partials = {};
|
|
327
|
-
|
|
328
|
-
for (const file of files) {
|
|
329
|
-
const extension = extname(file.relativePath);
|
|
330
|
-
const withoutExt = extension
|
|
331
|
-
? file.relativePath.slice(0, -extension.length)
|
|
332
|
-
: file.relativePath;
|
|
333
|
-
const normalized = withoutExt.replace(/\\/g, "/");
|
|
334
|
-
const base = basename(normalized);
|
|
335
|
-
|
|
336
|
-
setPartial(partials, normalized, file.content);
|
|
337
|
-
setPartial(partials, base, file.content);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
return partials;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
export function renderSkillTemplate(template, context = {}, options = {}) {
|
|
344
|
-
const { partials = {}, includes = {}, includeBaseDir = "" } = options;
|
|
345
|
-
return renderWithContext(template, context, partials, {
|
|
346
|
-
includeBaseDir,
|
|
347
|
-
includes: { ...includes },
|
|
348
|
-
});
|
|
349
|
-
}
|