@fusengine/harness 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/claude/index.d.mts +1 -35
- package/dist/adapters/claude/index.mjs +1 -65
- package/dist/adapters/cline/index.mjs +1 -24
- package/dist/adapters/codex/index.d.mts +2 -0
- package/dist/adapters/codex/index.mjs +2 -0
- package/dist/adapters/cursor/index.mjs +1 -36
- package/dist/adapters/gemini/index.mjs +1 -24
- package/dist/cache/index.d.mts +1 -29
- package/dist/cache/index.mjs +1 -109
- package/dist/cache-DbPSJ9bC.mjs +110 -0
- package/dist/claude-DbzjbxmO.mjs +66 -0
- package/dist/cli/bin.mjs +84 -10
- package/dist/cline-BxslHtBG.mjs +25 -0
- package/dist/config/index.d.mts +1 -36
- package/dist/config/index.mjs +1 -18
- package/dist/config-BG55s6HZ.mjs +20 -0
- package/dist/cursor-Bh7eh9y_.mjs +37 -0
- package/dist/detect/index.d.mts +1 -30
- package/dist/detect/index.mjs +2 -81
- package/dist/detect-la_KkjCS.mjs +1 -0
- package/dist/freshness/index.d.mts +1 -12
- package/dist/freshness/index.mjs +1 -63
- package/dist/freshness-DzGoBKKj.mjs +64 -0
- package/dist/gemini-SrK_fFAr.mjs +25 -0
- package/dist/harness-C8Nxxyn_.mjs +83 -0
- package/dist/harness-DwJskkz_.d.mts +31 -0
- package/dist/index-B-z0CCiU.d.mts +37 -0
- package/dist/index-B3Ve_bBu.d.mts +30 -0
- package/dist/index-BEM-mQMC.d.mts +30 -0
- package/dist/index-BKZ67WMa.d.mts +1 -0
- package/dist/index-BOBXQ91y.d.mts +12 -0
- package/dist/index-BVVgDSdq.d.mts +1 -0
- package/dist/index-BWK8slRi.d.mts +84 -0
- package/dist/index-C1vLIMwN.d.mts +20 -0
- package/dist/index-CPoF_hLP.d.mts +59 -0
- package/dist/index-D7MkQNdc.d.mts +80 -0
- package/dist/index-DqNKW8Ki.d.mts +44 -0
- package/dist/index-FrWgmkbP.d.mts +36 -0
- package/dist/index.d.mts +10 -10
- package/dist/index.mjs +9 -11
- package/dist/init/index.d.mts +34 -0
- package/dist/init/index.mjs +2 -0
- package/dist/memory/index.d.mts +1 -29
- package/dist/memory/index.mjs +1 -93
- package/dist/memory-BVNt4Ary.mjs +94 -0
- package/dist/policy/index.d.mts +1 -79
- package/dist/policy/index.mjs +1 -32
- package/dist/policy-C_pXmeNB.mjs +33 -0
- package/dist/prompt/index.mjs +1 -0
- package/dist/prompt-la_KkjCS.mjs +1 -0
- package/dist/refs/index.d.mts +1 -43
- package/dist/refs/index.mjs +1 -69
- package/dist/refs-Dj3AfgBE.mjs +70 -0
- package/dist/run-Cc98348q.mjs +94 -0
- package/dist/state/index.d.mts +1 -58
- package/dist/state/index.mjs +1 -103
- package/dist/state-Bc4wdnCG.mjs +104 -0
- package/dist/statusline/index.d.mts +1 -83
- package/dist/statusline/index.mjs +1 -147
- package/dist/statusline-D87eUNXl.mjs +148 -0
- package/dist/util/index.d.mts +1 -19
- package/dist/util/index.mjs +1 -0
- package/dist/util-la_KkjCS.mjs +1 -0
- package/package.json +5 -3
package/dist/policy/index.d.mts
CHANGED
|
@@ -1,80 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
//#region src/policy/detect-project.d.ts
|
|
4
|
-
/** Project types detected from filesystem indicators. */
|
|
5
|
-
type ProjectType = "nextjs" | "nuxt" | "angular" | "svelte" | "vue" | "react" | "tailwind" | "laravel" | "rails" | "django" | "python" | "go" | "rust" | "swift" | "java" | "scala" | "elixir" | "ruby" | "generic";
|
|
6
|
-
/** Keywords that signal a development task (APEX trigger). */
|
|
7
|
-
declare const DEV_KEYWORDS: RegExp;
|
|
8
|
-
/** True when the prompt invokes the /apex command. */
|
|
9
|
-
declare function isApexCommand(prompt: string): boolean;
|
|
10
|
-
/** Detect the project type by scanning config files in `dir`. */
|
|
11
|
-
declare function detectProjectType(dir: string): ProjectType;
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/policy/detect-framework.d.ts
|
|
14
|
-
/**
|
|
15
|
-
* Detect the framework from a file path extension + content patterns.
|
|
16
|
-
* Aligned with the fusengine require-solid-read detection (distinct from
|
|
17
|
-
* {@link detectProjectType}, which scans config files on disk).
|
|
18
|
-
*/
|
|
19
|
-
declare function detectFramework(filePath: string, content: string): string;
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/policy/file-size.d.ts
|
|
22
|
-
/** Verdict from {@link evaluateFileSize}. */
|
|
23
|
-
interface FileSizeVerdict {
|
|
24
|
-
ok: boolean;
|
|
25
|
-
lines: number;
|
|
26
|
-
max: number;
|
|
27
|
-
message: string | null;
|
|
28
|
-
}
|
|
29
|
-
/** Count lines in file content (empty string = 0). */
|
|
30
|
-
declare function countLines(content: string): number;
|
|
31
|
-
/**
|
|
32
|
-
* Evaluate a file's line count against the SOLID limit.
|
|
33
|
-
* @param lines - the file's line count
|
|
34
|
-
* @param max - the limit (defaults to `resolveMaxLines()`)
|
|
35
|
-
*/
|
|
36
|
-
declare function evaluateFileSize(lines: number, max?: number): FileSizeVerdict;
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/policy/patterns.d.ts
|
|
39
|
-
/**
|
|
40
|
-
* Guard pattern data, ported verbatim from the fusengine git/install guards.
|
|
41
|
-
* Note (faithful): `git push.*--force` also matches `--force-with-lease` —
|
|
42
|
-
* preserved from the source guard.
|
|
43
|
-
*/
|
|
44
|
-
/** Destructive git operations to block outright. */
|
|
45
|
-
declare const GIT_BLOCKED: ReadonlyArray<RegExp>;
|
|
46
|
-
/** Git operations that warrant a confirmation prompt. */
|
|
47
|
-
declare const GIT_ASK: ReadonlyArray<RegExp>;
|
|
48
|
-
/** System-level package installs (need confirmation). */
|
|
49
|
-
declare const SYSTEM_INSTALL: ReadonlyArray<RegExp>;
|
|
50
|
-
/** Project-level package installs. */
|
|
51
|
-
declare const PROJECT_INSTALL: ReadonlyArray<RegExp>;
|
|
52
|
-
/** True when `cmd` matches any pattern in `patterns`. */
|
|
53
|
-
declare function matchPatterns(cmd: string, patterns: ReadonlyArray<RegExp>): boolean;
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/policy/evaluate.d.ts
|
|
56
|
-
/** Harness-agnostic input to {@link evaluate}. */
|
|
57
|
-
interface PolicyContext {
|
|
58
|
-
/** Tool name (e.g. "Write", "Edit", "Bash"). */
|
|
59
|
-
tool: string;
|
|
60
|
-
filePath?: string;
|
|
61
|
-
content?: string;
|
|
62
|
-
command?: string;
|
|
63
|
-
/** Optional override for the SOLID max-lines limit. */
|
|
64
|
-
maxLines?: number;
|
|
65
|
-
}
|
|
66
|
-
/** Harness-agnostic policy decision (+ a portable prompt for adapters to render). */
|
|
67
|
-
interface PolicyResult {
|
|
68
|
-
decision: "allow" | "deny" | "warn";
|
|
69
|
-
message: string | null;
|
|
70
|
-
prompt?: Prompt;
|
|
71
|
-
meta?: Record<string, unknown>;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Evaluate a single tool-use against the bundled policies, returning a pure
|
|
75
|
-
* decision plus a portable {@link Prompt}. Adapters translate the prompt into
|
|
76
|
-
* their harness's native response (Claude `permissionDecision`, etc.).
|
|
77
|
-
*/
|
|
78
|
-
declare function evaluate(ctx: PolicyContext): PolicyResult;
|
|
79
|
-
//#endregion
|
|
1
|
+
import { a as GIT_BLOCKED, c as matchPatterns, d as evaluateFileSize, f as detectFramework, g as isApexCommand, h as detectProjectType, i as GIT_ASK, l as FileSizeVerdict, m as ProjectType, n as PolicyResult, o as PROJECT_INSTALL, p as DEV_KEYWORDS, r as evaluate, s as SYSTEM_INSTALL, t as PolicyContext, u as countLines } from "../index-D7MkQNdc.mjs";
|
|
80
2
|
export { DEV_KEYWORDS, FileSizeVerdict, GIT_ASK, GIT_BLOCKED, PROJECT_INSTALL, PolicyContext, PolicyResult, ProjectType, SYSTEM_INSTALL, countLines, detectFramework, detectProjectType, evaluate, evaluateFileSize, isApexCommand, matchPatterns };
|
package/dist/policy/index.mjs
CHANGED
|
@@ -1,34 +1,3 @@
|
|
|
1
|
+
import { n as detectProjectType, r as isApexCommand, t as DEV_KEYWORDS } from "../policy-C_pXmeNB.mjs";
|
|
1
2
|
import { a as SYSTEM_INSTALL, c as evaluateFileSize, i as PROJECT_INSTALL, l as detectFramework, n as GIT_ASK, o as matchPatterns, r as GIT_BLOCKED, s as countLines, t as evaluate } from "../evaluate-CsYyUucy.mjs";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
//#region src/policy/detect-project.ts
|
|
5
|
-
/** Keywords that signal a development task (APEX trigger). */
|
|
6
|
-
const DEV_KEYWORDS = /\b(implement|create|build|fix|add|refactor|develop|feature|bug|update|modify|change|write|code)\b/i;
|
|
7
|
-
/** True when the prompt invokes the /apex command. */
|
|
8
|
-
function isApexCommand(prompt) {
|
|
9
|
-
return /(?:^|\s)\/apex|\/fuse-ai-pilot:apex/i.test(prompt);
|
|
10
|
-
}
|
|
11
|
-
/** Detect the project type by scanning config files in `dir`. */
|
|
12
|
-
function detectProjectType(dir) {
|
|
13
|
-
const has = (f) => existsSync(join(dir, f));
|
|
14
|
-
if (has("next.config.js") || has("next.config.ts") || has("next.config.mjs")) return "nextjs";
|
|
15
|
-
if (has("nuxt.config.ts") || has("nuxt.config.js")) return "nuxt";
|
|
16
|
-
if (has("angular.json")) return "angular";
|
|
17
|
-
if (has("svelte.config.js") || has("svelte.config.ts")) return "svelte";
|
|
18
|
-
if (has("vite.config.ts") && has("src/App.vue")) return "vue";
|
|
19
|
-
if (has("vite.config.ts") || has("vite.config.js")) return "react";
|
|
20
|
-
if (has("tailwind.config.js") || has("tailwind.config.ts")) return "tailwind";
|
|
21
|
-
if (has("composer.json") && has("artisan")) return "laravel";
|
|
22
|
-
if (has("Gemfile") && has("config/routes.rb")) return "rails";
|
|
23
|
-
if (has("requirements.txt") || has("pyproject.toml") || has("setup.py")) return has("manage.py") ? "django" : "python";
|
|
24
|
-
if (has("go.mod")) return "go";
|
|
25
|
-
if (has("Cargo.toml")) return "rust";
|
|
26
|
-
if (has("Package.swift")) return "swift";
|
|
27
|
-
if (has("pom.xml") || has("build.gradle") || has("build.gradle.kts")) return "java";
|
|
28
|
-
if (has("build.sbt")) return "scala";
|
|
29
|
-
if (has("mix.exs")) return "elixir";
|
|
30
|
-
if (has("Gemfile")) return "ruby";
|
|
31
|
-
return "generic";
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
3
|
export { DEV_KEYWORDS, GIT_ASK, GIT_BLOCKED, PROJECT_INSTALL, SYSTEM_INSTALL, countLines, detectFramework, detectProjectType, evaluate, evaluateFileSize, isApexCommand, matchPatterns };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
//#region src/policy/detect-project.ts
|
|
4
|
+
/** Keywords that signal a development task (APEX trigger). */
|
|
5
|
+
const DEV_KEYWORDS = /\b(implement|create|build|fix|add|refactor|develop|feature|bug|update|modify|change|write|code)\b/i;
|
|
6
|
+
/** True when the prompt invokes the /apex command. */
|
|
7
|
+
function isApexCommand(prompt) {
|
|
8
|
+
return /(?:^|\s)\/apex|\/fuse-ai-pilot:apex/i.test(prompt);
|
|
9
|
+
}
|
|
10
|
+
/** Detect the project type by scanning config files in `dir`. */
|
|
11
|
+
function detectProjectType(dir) {
|
|
12
|
+
const has = (f) => existsSync(join(dir, f));
|
|
13
|
+
if (has("next.config.js") || has("next.config.ts") || has("next.config.mjs")) return "nextjs";
|
|
14
|
+
if (has("nuxt.config.ts") || has("nuxt.config.js")) return "nuxt";
|
|
15
|
+
if (has("angular.json")) return "angular";
|
|
16
|
+
if (has("svelte.config.js") || has("svelte.config.ts")) return "svelte";
|
|
17
|
+
if (has("vite.config.ts") && has("src/App.vue")) return "vue";
|
|
18
|
+
if (has("vite.config.ts") || has("vite.config.js")) return "react";
|
|
19
|
+
if (has("tailwind.config.js") || has("tailwind.config.ts")) return "tailwind";
|
|
20
|
+
if (has("composer.json") && has("artisan")) return "laravel";
|
|
21
|
+
if (has("Gemfile") && has("config/routes.rb")) return "rails";
|
|
22
|
+
if (has("requirements.txt") || has("pyproject.toml") || has("setup.py")) return has("manage.py") ? "django" : "python";
|
|
23
|
+
if (has("go.mod")) return "go";
|
|
24
|
+
if (has("Cargo.toml")) return "rust";
|
|
25
|
+
if (has("Package.swift")) return "swift";
|
|
26
|
+
if (has("pom.xml") || has("build.gradle") || has("build.gradle.kts")) return "java";
|
|
27
|
+
if (has("build.sbt")) return "scala";
|
|
28
|
+
if (has("mix.exs")) return "elixir";
|
|
29
|
+
if (has("Gemfile")) return "ruby";
|
|
30
|
+
return "generic";
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { detectProjectType as n, isApexCommand as r, DEV_KEYWORDS as t };
|
package/dist/prompt/index.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/refs/index.d.mts
CHANGED
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/** Parsed frontmatter metadata from a reference .md file. */
|
|
3
|
-
interface RefMeta {
|
|
4
|
-
name: string;
|
|
5
|
-
description: string;
|
|
6
|
-
keywords: string;
|
|
7
|
-
priority: string;
|
|
8
|
-
related: string;
|
|
9
|
-
appliesTo: string;
|
|
10
|
-
triggerOnEdit: string;
|
|
11
|
-
level: string;
|
|
12
|
-
filePath: string;
|
|
13
|
-
}
|
|
14
|
-
/** A reference with its computed routing score. */
|
|
15
|
-
interface ScoredRef {
|
|
16
|
-
meta: RefMeta;
|
|
17
|
-
score: number;
|
|
18
|
-
}
|
|
19
|
-
/** Routing result with categorized references. */
|
|
20
|
-
interface RouteResult {
|
|
21
|
-
required: ScoredRef[];
|
|
22
|
-
optional: ScoredRef[];
|
|
23
|
-
skillPath: string;
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/refs/frontmatter.d.ts
|
|
27
|
-
/** Extract frontmatter key/value pairs from markdown content (quotes stripped). */
|
|
28
|
-
declare function parseFrontmatter(content: string): Record<string, string>;
|
|
29
|
-
/** Convert a simple glob (`**`, `*`) to an anchored RegExp. */
|
|
30
|
-
declare function globToRe(g: string): RegExp;
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/refs/router.d.ts
|
|
33
|
-
/**
|
|
34
|
-
* Score references against a file edit (pure):
|
|
35
|
-
* +10 per `applies-to` glob match, +5 per `trigger-on-edit` fragment, +1 per keyword.
|
|
36
|
-
*/
|
|
37
|
-
declare function scoreReferences(refs: RefMeta[], filePath: string, content: string): ScoredRef[];
|
|
38
|
-
/**
|
|
39
|
-
* Route references for a file edit: top-2 required + next-2 optional, ensuring a
|
|
40
|
-
* `principle` and a `template` appear in the top 4. Returns null when nothing scores.
|
|
41
|
-
*/
|
|
42
|
-
declare function routeReferences(refs: RefMeta[], filePath: string, content: string, skillPath?: string): RouteResult | null;
|
|
43
|
-
//#endregion
|
|
1
|
+
import { a as RefMeta, i as parseFrontmatter, n as scoreReferences, o as RouteResult, r as globToRe, s as ScoredRef, t as routeReferences } from "../index-DqNKW8Ki.mjs";
|
|
44
2
|
export { RefMeta, RouteResult, ScoredRef, globToRe, parseFrontmatter, routeReferences, scoreReferences };
|
package/dist/refs/index.mjs
CHANGED
|
@@ -1,70 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/** Extract frontmatter key/value pairs from markdown content (quotes stripped). */
|
|
3
|
-
function parseFrontmatter(content) {
|
|
4
|
-
const m = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
5
|
-
if (!m?.[1]) return {};
|
|
6
|
-
const result = {};
|
|
7
|
-
for (const line of m[1].split("\n")) {
|
|
8
|
-
const idx = line.indexOf(":");
|
|
9
|
-
if (idx > 0) result[line.slice(0, idx).trim()] = line.slice(idx + 1).trim().replace(/^["']|["']$/g, "");
|
|
10
|
-
}
|
|
11
|
-
return result;
|
|
12
|
-
}
|
|
13
|
-
/** Convert a simple glob (`**`, `*`) to an anchored RegExp. */
|
|
14
|
-
function globToRe(g) {
|
|
15
|
-
const escaped = g.trim().replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\0").replace(/\*/g, "[^/]*").replace(/\0/g, ".*");
|
|
16
|
-
return new RegExp(`^${escaped}$`);
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/refs/router.ts
|
|
20
|
-
/**
|
|
21
|
-
* Score references against a file edit (pure):
|
|
22
|
-
* +10 per `applies-to` glob match, +5 per `trigger-on-edit` fragment, +1 per keyword.
|
|
23
|
-
*/
|
|
24
|
-
function scoreReferences(refs, filePath, content) {
|
|
25
|
-
const scored = [];
|
|
26
|
-
for (const meta of refs) {
|
|
27
|
-
let score = 0;
|
|
28
|
-
if (meta.appliesTo) {
|
|
29
|
-
for (const g of meta.appliesTo.split(", ")) if (globToRe(g).test(filePath)) score += 10;
|
|
30
|
-
}
|
|
31
|
-
if (meta.triggerOnEdit) {
|
|
32
|
-
for (const frag of meta.triggerOnEdit.split(", ")) if (filePath.includes(frag.trim())) score += 5;
|
|
33
|
-
}
|
|
34
|
-
if (meta.keywords) for (const kw of meta.keywords.split(", ")) {
|
|
35
|
-
const k = kw.trim();
|
|
36
|
-
if (k && (filePath.includes(k) || content.includes(k))) score += 1;
|
|
37
|
-
}
|
|
38
|
-
if (score > 0) scored.push({
|
|
39
|
-
meta,
|
|
40
|
-
score
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return scored;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Route references for a file edit: top-2 required + next-2 optional, ensuring a
|
|
47
|
-
* `principle` and a `template` appear in the top 4. Returns null when nothing scores.
|
|
48
|
-
*/
|
|
49
|
-
function routeReferences(refs, filePath, content, skillPath = "") {
|
|
50
|
-
const scored = scoreReferences(refs, filePath, content);
|
|
51
|
-
if (!scored.length) return null;
|
|
52
|
-
scored.sort((a, b) => b.score - a.score);
|
|
53
|
-
const hoist = (level) => {
|
|
54
|
-
if (scored.slice(0, 4).some((r) => r.meta.level === level)) return;
|
|
55
|
-
const found = scored.find((r) => r.meta.level === level);
|
|
56
|
-
if (found) {
|
|
57
|
-
scored.splice(scored.indexOf(found), 1);
|
|
58
|
-
scored.splice(3, 0, found);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
hoist("principle");
|
|
62
|
-
hoist("template");
|
|
63
|
-
return {
|
|
64
|
-
required: scored.slice(0, 2),
|
|
65
|
-
optional: scored.slice(2, 4),
|
|
66
|
-
skillPath
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
//#endregion
|
|
1
|
+
import { i as parseFrontmatter, n as scoreReferences, r as globToRe, t as routeReferences } from "../refs-Dj3AfgBE.mjs";
|
|
70
2
|
export { globToRe, parseFrontmatter, routeReferences, scoreReferences };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region src/refs/frontmatter.ts
|
|
2
|
+
/** Extract frontmatter key/value pairs from markdown content (quotes stripped). */
|
|
3
|
+
function parseFrontmatter(content) {
|
|
4
|
+
const m = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
5
|
+
if (!m?.[1]) return {};
|
|
6
|
+
const result = {};
|
|
7
|
+
for (const line of m[1].split("\n")) {
|
|
8
|
+
const idx = line.indexOf(":");
|
|
9
|
+
if (idx > 0) result[line.slice(0, idx).trim()] = line.slice(idx + 1).trim().replace(/^["']|["']$/g, "");
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
/** Convert a simple glob (`**`, `*`) to an anchored RegExp. */
|
|
14
|
+
function globToRe(g) {
|
|
15
|
+
const escaped = g.trim().replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\0").replace(/\*/g, "[^/]*").replace(/\0/g, ".*");
|
|
16
|
+
return new RegExp(`^${escaped}$`);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/refs/router.ts
|
|
20
|
+
/**
|
|
21
|
+
* Score references against a file edit (pure):
|
|
22
|
+
* +10 per `applies-to` glob match, +5 per `trigger-on-edit` fragment, +1 per keyword.
|
|
23
|
+
*/
|
|
24
|
+
function scoreReferences(refs, filePath, content) {
|
|
25
|
+
const scored = [];
|
|
26
|
+
for (const meta of refs) {
|
|
27
|
+
let score = 0;
|
|
28
|
+
if (meta.appliesTo) {
|
|
29
|
+
for (const g of meta.appliesTo.split(", ")) if (globToRe(g).test(filePath)) score += 10;
|
|
30
|
+
}
|
|
31
|
+
if (meta.triggerOnEdit) {
|
|
32
|
+
for (const frag of meta.triggerOnEdit.split(", ")) if (filePath.includes(frag.trim())) score += 5;
|
|
33
|
+
}
|
|
34
|
+
if (meta.keywords) for (const kw of meta.keywords.split(", ")) {
|
|
35
|
+
const k = kw.trim();
|
|
36
|
+
if (k && (filePath.includes(k) || content.includes(k))) score += 1;
|
|
37
|
+
}
|
|
38
|
+
if (score > 0) scored.push({
|
|
39
|
+
meta,
|
|
40
|
+
score
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return scored;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Route references for a file edit: top-2 required + next-2 optional, ensuring a
|
|
47
|
+
* `principle` and a `template` appear in the top 4. Returns null when nothing scores.
|
|
48
|
+
*/
|
|
49
|
+
function routeReferences(refs, filePath, content, skillPath = "") {
|
|
50
|
+
const scored = scoreReferences(refs, filePath, content);
|
|
51
|
+
if (!scored.length) return null;
|
|
52
|
+
scored.sort((a, b) => b.score - a.score);
|
|
53
|
+
const hoist = (level) => {
|
|
54
|
+
if (scored.slice(0, 4).some((r) => r.meta.level === level)) return;
|
|
55
|
+
const found = scored.find((r) => r.meta.level === level);
|
|
56
|
+
if (found) {
|
|
57
|
+
scored.splice(scored.indexOf(found), 1);
|
|
58
|
+
scored.splice(3, 0, found);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
hoist("principle");
|
|
62
|
+
hoist("template");
|
|
63
|
+
return {
|
|
64
|
+
required: scored.slice(0, 2),
|
|
65
|
+
optional: scored.slice(2, 4),
|
|
66
|
+
skillPath
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { parseFrontmatter as i, scoreReferences as n, globToRe as r, routeReferences as t };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { chmodSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
//#region src/init/templates.ts
|
|
4
|
+
function json(obj) {
|
|
5
|
+
return `${JSON.stringify(obj, null, 2)}\n`;
|
|
6
|
+
}
|
|
7
|
+
/** Claude Code: PreToolUse(Write|Edit) -> command. Target: `.claude/settings.json`. */
|
|
8
|
+
function claudeInit(command) {
|
|
9
|
+
return {
|
|
10
|
+
path: ".claude/settings.json",
|
|
11
|
+
content: json({ hooks: { PreToolUse: [{
|
|
12
|
+
matcher: "Write|Edit",
|
|
13
|
+
hooks: [{
|
|
14
|
+
type: "command",
|
|
15
|
+
command
|
|
16
|
+
}]
|
|
17
|
+
}] } })
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Codex CLI: `.codex/hooks.json` — PreToolUse (Claude-compatible shape). */
|
|
21
|
+
function codexInit(command) {
|
|
22
|
+
return {
|
|
23
|
+
path: ".codex/hooks.json",
|
|
24
|
+
content: json({ hooks: { PreToolUse: [{
|
|
25
|
+
matcher: "Bash|apply_patch",
|
|
26
|
+
hooks: [{
|
|
27
|
+
type: "command",
|
|
28
|
+
command
|
|
29
|
+
}]
|
|
30
|
+
}] } })
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Cursor: `.cursor/hooks.json` (version 1) — shell + file-edit hooks. */
|
|
34
|
+
function cursorInit(command) {
|
|
35
|
+
return {
|
|
36
|
+
path: ".cursor/hooks.json",
|
|
37
|
+
content: json({
|
|
38
|
+
version: 1,
|
|
39
|
+
hooks: {
|
|
40
|
+
beforeShellExecution: [{ command }],
|
|
41
|
+
afterFileEdit: [{ command }]
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Gemini CLI: `.gemini/settings.json` — BeforeTool, timeout in ms. */
|
|
47
|
+
function geminiInit(command) {
|
|
48
|
+
return {
|
|
49
|
+
path: ".gemini/settings.json",
|
|
50
|
+
content: json({ hooks: { BeforeTool: [{
|
|
51
|
+
matcher: "write_file|edit_file|replace",
|
|
52
|
+
hooks: [{
|
|
53
|
+
type: "command",
|
|
54
|
+
command,
|
|
55
|
+
timeout: 3e4
|
|
56
|
+
}]
|
|
57
|
+
}] } })
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Cline: an executable `.clinerules/hooks/PreToolUse` that pipes stdin to the command. */
|
|
61
|
+
function clineInit(command) {
|
|
62
|
+
return {
|
|
63
|
+
path: ".clinerules/hooks/PreToolUse",
|
|
64
|
+
content: `#!/usr/bin/env bash\n# fuse-harness Cline hook — evaluate each tool use\ncat | ${command}\n`,
|
|
65
|
+
executable: true
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/init/run.ts
|
|
70
|
+
const RUNNERS = {
|
|
71
|
+
"claude-code": claudeInit,
|
|
72
|
+
codex: codexInit,
|
|
73
|
+
cursor: cursorInit,
|
|
74
|
+
"gemini-cli": geminiInit,
|
|
75
|
+
cline: clineInit
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Build the wiring file for a harness, or null when it has no hook integration
|
|
79
|
+
* (cli-mode harnesses use `harness check` in a pre-commit step instead).
|
|
80
|
+
*/
|
|
81
|
+
function initFor(id, command = `npx harness hook ${id}`) {
|
|
82
|
+
const make = RUNNERS[id];
|
|
83
|
+
return make ? make(command) : null;
|
|
84
|
+
}
|
|
85
|
+
/** Write an {@link InitFile} under `root` (creates dirs; `chmod +x` when executable). */
|
|
86
|
+
function writeInitFile(root, file) {
|
|
87
|
+
const full = join(root, file.path);
|
|
88
|
+
mkdirSync(dirname(full), { recursive: true });
|
|
89
|
+
writeFileSync(full, file.content);
|
|
90
|
+
if (file.executable) chmodSync(full, 493);
|
|
91
|
+
return full;
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { codexInit as a, clineInit as i, writeInitFile as n, cursorInit as o, claudeInit as r, geminiInit as s, initFor as t };
|
package/dist/state/index.d.mts
CHANGED
|
@@ -1,59 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
//#region src/state/lock.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Acquire a directory-based lock (atomic `mkdir`, EEXIST = already held) with a timeout.
|
|
6
|
-
* @returns a release function, or null if the lock could not be acquired in time.
|
|
7
|
-
*/
|
|
8
|
-
declare function acquireLock(lockDir: string, timeoutMs?: number): Promise<(() => Promise<void>) | null>;
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/state/apex-state.d.ts
|
|
11
|
-
declare const DEFAULT_STATE: {
|
|
12
|
-
$schema: string;
|
|
13
|
-
description: string;
|
|
14
|
-
target: Record<string, string>;
|
|
15
|
-
authorizations: Record<string, AuthEntry & {
|
|
16
|
-
doc_consulted?: string;
|
|
17
|
-
}>;
|
|
18
|
-
};
|
|
19
|
-
/** APEX state shape. */
|
|
20
|
-
type ApexState = typeof DEFAULT_STATE;
|
|
21
|
-
/** APEX state directory under a home dir. */
|
|
22
|
-
declare function apexStateDir(home?: string): string;
|
|
23
|
-
/** Daily state file path: `<home>/.claude/logs/00-apex/<YYYY-MM-DD>-state.json`. */
|
|
24
|
-
declare function stateFilePath(home?: string, today?: string): string;
|
|
25
|
-
/** Ensure the state directory exists and return its path. */
|
|
26
|
-
declare function ensureStateDir(home?: string): Promise<string>;
|
|
27
|
-
/** Load APEX state, or a fresh default. */
|
|
28
|
-
declare function loadState(path: string): Promise<ApexState>;
|
|
29
|
-
/** Save APEX state. */
|
|
30
|
-
declare function saveState(path: string, state: ApexState): Promise<void>;
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/state/task-helpers.d.ts
|
|
33
|
-
/** A task entry in task.json. */
|
|
34
|
-
interface ApexTask {
|
|
35
|
-
subject: string;
|
|
36
|
-
description: string;
|
|
37
|
-
status: string;
|
|
38
|
-
phase: string;
|
|
39
|
-
started_at?: string;
|
|
40
|
-
completed_at?: string;
|
|
41
|
-
created_at?: string;
|
|
42
|
-
doc_consulted: Record<string, unknown>;
|
|
43
|
-
files_modified: string[];
|
|
44
|
-
blockedBy?: string[];
|
|
45
|
-
}
|
|
46
|
-
/** Structure of `.claude/apex/task.json`. */
|
|
47
|
-
interface ApexTaskFile {
|
|
48
|
-
current_task: string;
|
|
49
|
-
created_at: string;
|
|
50
|
-
tasks: Record<string, ApexTask>;
|
|
51
|
-
}
|
|
52
|
-
/** Add a new pending task. */
|
|
53
|
-
declare function taskCreate(file: string, id: string, subject: string, desc: string): Promise<void>;
|
|
54
|
-
/** Mark a task in_progress (creating a stub if absent). */
|
|
55
|
-
declare function taskStart(file: string, id: string, subject?: string, desc?: string, blocked?: string): Promise<void>;
|
|
56
|
-
/** Mark a task completed. */
|
|
57
|
-
declare function taskComplete(file: string, id: string): Promise<void>;
|
|
58
|
-
//#endregion
|
|
1
|
+
import { a as taskStart, c as ensureStateDir, d as stateFilePath, f as acquireLock, i as taskCreate, l as loadState, n as ApexTaskFile, o as ApexState, r as taskComplete, s as apexStateDir, t as ApexTask, u as saveState } from "../index-CPoF_hLP.mjs";
|
|
59
2
|
export { ApexState, ApexTask, ApexTaskFile, acquireLock, apexStateDir, ensureStateDir, loadState, saveState, stateFilePath, taskComplete, taskCreate, taskStart };
|
package/dist/state/index.mjs
CHANGED
|
@@ -1,104 +1,2 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { mkdir, rmdir } from "node:fs/promises";
|
|
3
|
-
//#region src/state/lock.ts
|
|
4
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
5
|
-
/**
|
|
6
|
-
* Acquire a directory-based lock (atomic `mkdir`, EEXIST = already held) with a timeout.
|
|
7
|
-
* @returns a release function, or null if the lock could not be acquired in time.
|
|
8
|
-
*/
|
|
9
|
-
async function acquireLock(lockDir, timeoutMs = 5e3) {
|
|
10
|
-
const start = Date.now();
|
|
11
|
-
while (Date.now() - start < timeoutMs) try {
|
|
12
|
-
await mkdir(lockDir, { recursive: false });
|
|
13
|
-
return async () => {
|
|
14
|
-
try {
|
|
15
|
-
await rmdir(lockDir);
|
|
16
|
-
} catch {}
|
|
17
|
-
};
|
|
18
|
-
} catch {
|
|
19
|
-
await sleep(100);
|
|
20
|
-
}
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/state/apex-state.ts
|
|
25
|
-
const DEFAULT_STATE = {
|
|
26
|
-
$schema: "apex-state-v1",
|
|
27
|
-
description: "APEX/SOLID state - sessions[] + 2min expiry",
|
|
28
|
-
target: {},
|
|
29
|
-
authorizations: {}
|
|
30
|
-
};
|
|
31
|
-
/** APEX state directory under a home dir. */
|
|
32
|
-
function apexStateDir(home = process.env.HOME ?? "") {
|
|
33
|
-
return `${home}/.claude/logs/00-apex`;
|
|
34
|
-
}
|
|
35
|
-
/** Daily state file path: `<home>/.claude/logs/00-apex/<YYYY-MM-DD>-state.json`. */
|
|
36
|
-
function stateFilePath(home = process.env.HOME ?? "", today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)) {
|
|
37
|
-
return `${apexStateDir(home)}/${today}-state.json`;
|
|
38
|
-
}
|
|
39
|
-
/** Ensure the state directory exists and return its path. */
|
|
40
|
-
async function ensureStateDir(home) {
|
|
41
|
-
const dir = apexStateDir(home);
|
|
42
|
-
await ensureDir(dir);
|
|
43
|
-
return dir;
|
|
44
|
-
}
|
|
45
|
-
/** Load APEX state, or a fresh default. */
|
|
46
|
-
async function loadState(path) {
|
|
47
|
-
return await readJsonFile(path) ?? { ...DEFAULT_STATE };
|
|
48
|
-
}
|
|
49
|
-
/** Save APEX state. */
|
|
50
|
-
async function saveState(path, state) {
|
|
51
|
-
await writeJsonFile(path, state);
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/state/task-helpers.ts
|
|
55
|
-
/** Add a new pending task. */
|
|
56
|
-
async function taskCreate(file, id, subject, desc) {
|
|
57
|
-
const data = await readJsonFile(file);
|
|
58
|
-
if (!data) return;
|
|
59
|
-
data.tasks[id] = {
|
|
60
|
-
subject,
|
|
61
|
-
description: desc,
|
|
62
|
-
status: "pending",
|
|
63
|
-
phase: "pending",
|
|
64
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
65
|
-
doc_consulted: {},
|
|
66
|
-
files_modified: [],
|
|
67
|
-
blockedBy: []
|
|
68
|
-
};
|
|
69
|
-
await writeJsonFile(file, data);
|
|
70
|
-
}
|
|
71
|
-
/** Mark a task in_progress (creating a stub if absent). */
|
|
72
|
-
async function taskStart(file, id, subject, desc, blocked) {
|
|
73
|
-
const data = await readJsonFile(file);
|
|
74
|
-
if (!data) return;
|
|
75
|
-
const task = data.tasks[id] ?? {
|
|
76
|
-
subject: "",
|
|
77
|
-
description: "",
|
|
78
|
-
status: "in_progress",
|
|
79
|
-
phase: "analyze",
|
|
80
|
-
doc_consulted: {},
|
|
81
|
-
files_modified: []
|
|
82
|
-
};
|
|
83
|
-
data.tasks[id] = task;
|
|
84
|
-
data.current_task = id;
|
|
85
|
-
task.status = "in_progress";
|
|
86
|
-
task.phase = "analyze";
|
|
87
|
-
task.started_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
88
|
-
if (subject) task.subject = subject;
|
|
89
|
-
if (desc) task.description = desc;
|
|
90
|
-
if (blocked) task.blockedBy = blocked.split(",");
|
|
91
|
-
await writeJsonFile(file, data);
|
|
92
|
-
}
|
|
93
|
-
/** Mark a task completed. */
|
|
94
|
-
async function taskComplete(file, id) {
|
|
95
|
-
const data = await readJsonFile(file);
|
|
96
|
-
const task = data?.tasks[id];
|
|
97
|
-
if (!data || !task) return;
|
|
98
|
-
task.status = "completed";
|
|
99
|
-
task.phase = "completed";
|
|
100
|
-
task.completed_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
101
|
-
await writeJsonFile(file, data);
|
|
102
|
-
}
|
|
103
|
-
//#endregion
|
|
1
|
+
import { a as ensureStateDir, c as stateFilePath, i as apexStateDir, l as acquireLock, n as taskCreate, o as loadState, r as taskStart, s as saveState, t as taskComplete } from "../state-Bc4wdnCG.mjs";
|
|
104
2
|
export { acquireLock, apexStateDir, ensureStateDir, loadState, saveState, stateFilePath, taskComplete, taskCreate, taskStart };
|