@inixiative/foundry-core 0.5.7 → 0.5.9
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/package.json +3 -3
- package/src/feedback/archive-turns.ts +21 -2
- package/src/index.ts +13 -0
- package/src/native-tools.ts +76 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inixiative/foundry-core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"bun": ">=1.4.2"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@inixiative/archive": "^0.
|
|
36
|
+
"@inixiative/archive": "^0.24.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependenciesMeta": {
|
|
39
39
|
"@inixiative/archive": {
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@inixiative/archive": "^0.
|
|
44
|
+
"@inixiative/archive": "^0.24.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -6,12 +6,31 @@ import type { TranscriptTurn } from './correction';
|
|
|
6
6
|
// `foundry repeats` and Oracle's session miner; its own export, so the core root never loads Archive.
|
|
7
7
|
|
|
8
8
|
const INTERRUPTED = /^\s*\[Request interrupted by user/;
|
|
9
|
-
const COMMIT_BRACKET = /\[[^[\]\n]
|
|
9
|
+
const COMMIT_BRACKET = /\[([^[\]\n]+?)\s([0-9a-f]{7,40})\]/g;
|
|
10
|
+
/** `git commit` adds this to the branch on a repository's first commit. */
|
|
11
|
+
const ROOT_COMMIT = /\s+\(root-commit\)$/;
|
|
10
12
|
const COMMIT_LINE = /^commit ([0-9a-f]{40})/gm;
|
|
11
13
|
|
|
14
|
+
/** A commit a session made, as `git commit` printed it: the branch it was on, and its short SHA. */
|
|
15
|
+
export interface MadeCommit {
|
|
16
|
+
/** As git printed it: `main`, `feat/x`, `detached HEAD`; `(root-commit)` dropped. */
|
|
17
|
+
readonly branch: string;
|
|
18
|
+
readonly sha: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Commits a tool result says were made: `git commit`'s `[branch sha]` line only, with the branch,
|
|
23
|
+
* so a reader can tell work on a PR's own branch (amended or rebased away later) from other work.
|
|
24
|
+
*/
|
|
25
|
+
export const commitsMade = (text: string): MadeCommit[] =>
|
|
26
|
+
[...text.matchAll(COMMIT_BRACKET)].map((m) => ({
|
|
27
|
+
branch: m[1]!.replace(ROOT_COMMIT, ''),
|
|
28
|
+
sha: m[2]!,
|
|
29
|
+
}));
|
|
30
|
+
|
|
12
31
|
/** Commit SHAs a tool result printed: `git commit`'s `[branch sha]` line, `git log`'s `commit <sha>`. */
|
|
13
32
|
export const commitsIn = (text: string) => [
|
|
14
|
-
...
|
|
33
|
+
...commitsMade(text).map((made) => made.sha),
|
|
15
34
|
...[...text.matchAll(COMMIT_LINE)].map((m) => m[1]!),
|
|
16
35
|
];
|
|
17
36
|
|
package/src/index.ts
CHANGED
|
@@ -372,6 +372,19 @@ export {
|
|
|
372
372
|
vendorOfProvider,
|
|
373
373
|
} from './model-registry';
|
|
374
374
|
export * from './native-evidence';
|
|
375
|
+
// Native tools by what they do (tool gate, work items, Oracle's session reader)
|
|
376
|
+
export {
|
|
377
|
+
DEFAULT_CONSUMED_TOOLS,
|
|
378
|
+
FETCH_TOOLS,
|
|
379
|
+
LINEAR_ISSUE_TOOLS,
|
|
380
|
+
READ_TOOLS,
|
|
381
|
+
SHELL_TOOLS,
|
|
382
|
+
toolCapability,
|
|
383
|
+
toolGlobMatcher,
|
|
384
|
+
WORK_ITEM_ID_KEYS,
|
|
385
|
+
WRITE_TOOLS,
|
|
386
|
+
workItemId,
|
|
387
|
+
} from './native-tools';
|
|
375
388
|
// Retry middleware
|
|
376
389
|
export { type RetryConfig, retryMiddleware } from './retry';
|
|
377
390
|
export { type Route, type RouteHandler, Router, type RouterConfig } from './router';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Capability } from './capability';
|
|
2
|
+
|
|
3
|
+
// Native harness tools by what they do: one list for Foundry's tool gate and work items, and for
|
|
4
|
+
// Oracle, which reads the same calls out of Archive sessions and never imports Foundry.
|
|
5
|
+
|
|
6
|
+
/** Shell tools: Claude Code's Bash and its job tools, Codex's shell and exec_command. */
|
|
7
|
+
export const SHELL_TOOLS: ReadonlySet<string> = new Set([
|
|
8
|
+
'Bash',
|
|
9
|
+
'BashOutput',
|
|
10
|
+
'KillShell',
|
|
11
|
+
'shell',
|
|
12
|
+
'exec_command',
|
|
13
|
+
]);
|
|
14
|
+
/** Tools whose path argument is a file the call writes: Claude Code's editors, Codex's patch. */
|
|
15
|
+
export const WRITE_TOOLS: ReadonlySet<string> = new Set([
|
|
16
|
+
'Write',
|
|
17
|
+
'Edit',
|
|
18
|
+
'MultiEdit',
|
|
19
|
+
'NotebookEdit',
|
|
20
|
+
'apply_patch',
|
|
21
|
+
]);
|
|
22
|
+
export const READ_TOOLS: ReadonlySet<string> = new Set([
|
|
23
|
+
'Read',
|
|
24
|
+
'NotebookRead',
|
|
25
|
+
'LS',
|
|
26
|
+
'Glob',
|
|
27
|
+
'Grep',
|
|
28
|
+
]);
|
|
29
|
+
export const FETCH_TOOLS: ReadonlySet<string> = new Set(['WebFetch', 'WebSearch']);
|
|
30
|
+
|
|
31
|
+
/** The capability a native tool call exercises, by its name alone. */
|
|
32
|
+
export function toolCapability(toolName: string): Capability {
|
|
33
|
+
if (SHELL_TOOLS.has(toolName)) return 'exec:shell';
|
|
34
|
+
if (WRITE_TOOLS.has(toolName)) return 'file:write';
|
|
35
|
+
if (READ_TOOLS.has(toolName)) return 'file:read';
|
|
36
|
+
if (FETCH_TOOLS.has(toolName)) return 'net:fetch';
|
|
37
|
+
if (toolName.startsWith('mcp__')) return 'net:api';
|
|
38
|
+
return `tool:${toolName}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A Linear issue fetch under any MCP server name. Globs match case-insensitively (`toolGlobMatcher`). */
|
|
42
|
+
export const LINEAR_ISSUE_TOOLS: readonly string[] = Object.freeze(['mcp__*linear*__get_issue']);
|
|
43
|
+
|
|
44
|
+
/** Tools that fetch a work item: Linear issues and documents, Notion pages, under any MCP server name. */
|
|
45
|
+
export const DEFAULT_CONSUMED_TOOLS: readonly string[] = Object.freeze([
|
|
46
|
+
...LINEAR_ISSUE_TOOLS,
|
|
47
|
+
'mcp__*linear*__get_document',
|
|
48
|
+
'mcp__*notion*__*fetch*',
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
/** Whether a tool name matches any of the globs, case-insensitively. */
|
|
52
|
+
export function toolGlobMatcher(globs: readonly string[]): (toolName: string) => boolean {
|
|
53
|
+
const compiled = globs.map((glob) => new Bun.Glob(glob.toLowerCase()));
|
|
54
|
+
return (toolName) => {
|
|
55
|
+
const name = toolName.toLowerCase();
|
|
56
|
+
return compiled.some((glob) => glob.match(name));
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Fields a fetch tool names its item by, in the order they are tried. */
|
|
61
|
+
export const WORK_ITEM_ID_KEYS = [
|
|
62
|
+
'id',
|
|
63
|
+
'issueId',
|
|
64
|
+
'issue_id',
|
|
65
|
+
'documentId',
|
|
66
|
+
'pageId',
|
|
67
|
+
'page_id',
|
|
68
|
+
'url',
|
|
69
|
+
] as const;
|
|
70
|
+
|
|
71
|
+
/** The item a fetch call names: the first non-empty string among `WORK_ITEM_ID_KEYS`. */
|
|
72
|
+
export function workItemId(input: Readonly<Record<string, unknown>>): string | undefined {
|
|
73
|
+
return WORK_ITEM_ID_KEYS.map((key) => input[key]).find(
|
|
74
|
+
(value): value is string => typeof value === 'string' && value.trim().length > 0,
|
|
75
|
+
);
|
|
76
|
+
}
|