@kirkchinese/harness-forge-core 0.4.0 → 0.5.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/lib/assess.js +24 -4
- package/lib/contracts.d.ts +1 -1
- package/lib/dialects/claude-code/index.js +38 -41
- package/lib/dialects/claude-code/sessions/discover.js +31 -17
- package/lib/dialects/claude-code/sessions/parse.js +89 -83
- package/lib/dialects/claude-code/sessions/title.d.ts +23 -0
- package/lib/dialects/claude-code/sessions/title.js +74 -0
- package/lib/dialects/claude-code/statusline.d.ts +12 -0
- package/lib/dialects/claude-code/statusline.js +74 -0
- package/lib/dialects/claude-code/user-assets.d.ts +37 -6
- package/lib/dialects/claude-code/user-assets.js +155 -34
- package/lib/dialects/codex/index.js +8 -1
- package/lib/dialects/codex/mcp-server.d.ts +17 -0
- package/lib/dialects/codex/mcp-server.js +116 -0
- package/lib/dialects/codex/plugins.d.ts +16 -0
- package/lib/dialects/codex/plugins.js +120 -0
- package/lib/dialects/codex/user-assets.d.ts +10 -6
- package/lib/dialects/codex/user-assets.js +26 -42
- package/lib/dialects/opencode/index.js +43 -8
- package/lib/dialects/opencode/inventory.d.ts +100 -0
- package/lib/dialects/opencode/inventory.js +318 -0
- package/lib/dialects/opencode/plugin-id.d.ts +21 -0
- package/lib/dialects/opencode/plugin-id.js +296 -0
- package/lib/dialects/opencode/scan.d.ts +22 -0
- package/lib/dialects/opencode/scan.js +119 -121
- package/lib/dialects/types.d.ts +60 -6
- package/lib/discover.d.ts +32 -7
- package/lib/discover.js +58 -17
- package/lib/fingerprint.js +7 -0
- package/lib/harness-installs.d.ts +42 -0
- package/lib/harness-installs.js +59 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +5 -0
- package/lib/instructions.d.ts +28 -2
- package/lib/instructions.js +202 -30
- package/lib/license.js +12 -11
- package/lib/manifest.d.ts +6 -0
- package/lib/manifest.js +41 -12
- package/lib/marketplace.d.ts +15 -1
- package/lib/marketplace.js +55 -38
- package/lib/paths.d.ts +65 -0
- package/lib/paths.js +152 -2
- package/lib/plan.js +3 -1
- package/lib/port-brief.d.ts +28 -5
- package/lib/port-brief.js +52 -10
- package/lib/remote.d.ts +121 -0
- package/lib/remote.js +352 -0
- package/lib/sessions/index.d.ts +1 -0
- package/lib/sessions/index.js +1 -0
- package/lib/sessions/lines.d.ts +57 -0
- package/lib/sessions/lines.js +122 -0
- package/lib/text.d.ts +9 -0
- package/lib/text.js +19 -0
- package/lib/trust.js +19 -6
- package/lib/types.d.ts +48 -1
- package/package.json +1 -1
package/lib/manifest.js
CHANGED
|
@@ -11,8 +11,9 @@ import { childId, kebabCase, pluginId, uniqueName } from './naming.js';
|
|
|
11
11
|
import { fingerprintPlugin } from './fingerprint.js';
|
|
12
12
|
import { detectLicense } from './license.js';
|
|
13
13
|
import { codexSkillPolicy } from './dialects/codex/skill-policy.js';
|
|
14
|
+
import { codexMcpServer, notStartedBy } from './dialects/codex/mcp-server.js';
|
|
14
15
|
import { usesAgentMcpSchema, usesAgentPluginSchema, validateAgentMcp, validateAgentPlugin } from './schema.js';
|
|
15
|
-
import { childDirectories, isDirectory, isFile, isInside, isPlainObject, readJsonObject, readText, realOrLexical, resolveInside, stem, stringArrayField, stringField, toPosix, } from './paths.js';
|
|
16
|
+
import { childDirectories, isDirectory, isFile, isInside, isPlainObject, leadsToShare, readJsonObject, readText, realOrLexical, resolveInside, stem, stringArrayField, stringField, toPosix, } from './paths.js';
|
|
16
17
|
const AGENT_PLUGINS_SCHEMA = 'https://agent-plugins.org/schemas/1.0.0/plugin.schema.json';
|
|
17
18
|
/** Detect the manifest convention at a plugin root. */
|
|
18
19
|
export function detectManifest(root, explicitPath, source) {
|
|
@@ -90,8 +91,15 @@ function classifyPortableManifest(data) {
|
|
|
90
91
|
return 'unknown';
|
|
91
92
|
}
|
|
92
93
|
function looksLikeClaudeLayout(root) {
|
|
93
|
-
return ['skills', 'commands', 'agents', 'hooks', 'output-styles', 'workflows']
|
|
94
|
-
|
|
94
|
+
return hasLayoutDirectory(root, ['skills', 'commands', 'agents', 'hooks', 'output-styles', 'workflows']) || isFile(join(root, '.mcp.json'));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Whether `root` holds one of the named plugin-layout directories. A directory
|
|
98
|
+
* that is itself a skill (it has a `SKILL.md`) is a skill folder that happens
|
|
99
|
+
* to be called `agents` or `hooks`, not a layout directory.
|
|
100
|
+
*/
|
|
101
|
+
export function hasLayoutDirectory(root, names) {
|
|
102
|
+
return names.some(name => isDirectory(join(root, name)) && !isFile(join(root, name, 'SKILL.md')));
|
|
95
103
|
}
|
|
96
104
|
/**
|
|
97
105
|
* Scan one plugin directory. The scan is read-only and tolerant: a malformed
|
|
@@ -148,11 +156,16 @@ export function scanPlugin(root, options) {
|
|
|
148
156
|
warn('schema-invalid', `plugin.json: ${error}`, { path: 'plugin.json' });
|
|
149
157
|
}
|
|
150
158
|
addSkills(root, id, manifest, manifestKind, push, warn, usedSkillNames);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
// A folder of Agent Skills holds skills and MCP servers only: its `commands/` or `agents/` is a skill, not a plugin directory.
|
|
160
|
+
const skillsOnly = manifestKind === 'agent-skills';
|
|
161
|
+
if (!skillsOnly) {
|
|
162
|
+
addCommands(root, id, manifest, manifestKind, push, warn, usedCommandNames);
|
|
163
|
+
addAgents(root, id, manifest, manifestKind, push, warn, usedAgentNames);
|
|
164
|
+
addHooks(root, id, manifest, manifestKind, push, warn);
|
|
165
|
+
}
|
|
166
|
+
addMcp(root, id, manifest, options.source === 'codex' || manifestKind === 'codex', push, warn);
|
|
167
|
+
if (!skillsOnly)
|
|
168
|
+
addUi(root, id, manifest, manifestKind, push, warn);
|
|
156
169
|
addCode(root, id, manifest, manifestKind, components, push, warn);
|
|
157
170
|
// A hooks file that only lists a mod's modules has no hooks of its own: the modules are the code components.
|
|
158
171
|
for (let index = components.length - 1; index >= 0; index--) {
|
|
@@ -563,7 +576,13 @@ function addUnmapped(root, plugin, manifest, push) {
|
|
|
563
576
|
// ---------------------------------------------------------------------------
|
|
564
577
|
// MCP
|
|
565
578
|
// ---------------------------------------------------------------------------
|
|
566
|
-
|
|
579
|
+
/**
|
|
580
|
+
* A plugin's MCP servers. A Codex plugin's entries are read as Codex reads
|
|
581
|
+
* them ({@link codexMcpServer}); any server marked `enabled: false` is kept,
|
|
582
|
+
* marked as not started, since no harness starts a server its configuration
|
|
583
|
+
* switches off.
|
|
584
|
+
*/
|
|
585
|
+
function addMcp(root, plugin, manifest, codex, push, warn) {
|
|
567
586
|
const maps = [];
|
|
568
587
|
for (const file of [join(root, 'mcp.json'), join(root, '.mcp.json')]) {
|
|
569
588
|
const data = readJsonObject(file);
|
|
@@ -622,6 +641,12 @@ function addMcp(root, plugin, manifest, kind, push, warn) {
|
|
|
622
641
|
seenConfigs.add(configKey);
|
|
623
642
|
const serverName = uniqueName(name, seen, `${plugin}:${map.path}:${name}`);
|
|
624
643
|
seen.add(serverName);
|
|
644
|
+
const id = childId(plugin, 'mcp', serverName);
|
|
645
|
+
const path = toPosix(relative(root, map.path));
|
|
646
|
+
if (codex) {
|
|
647
|
+
push(codexMcpServer(raw, { id, name: serverName, declaredName: name, path, scope: 'plugin', disabledCode: 'disabled-in-plugin' }));
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
625
650
|
const transport = mcpTransport(raw);
|
|
626
651
|
const command = stringField(raw, 'command');
|
|
627
652
|
const url = stringField(raw, 'url');
|
|
@@ -630,10 +655,11 @@ function addMcp(root, plugin, manifest, kind, push, warn) {
|
|
|
630
655
|
const headers = stringRecord(raw['headers']);
|
|
631
656
|
const cwd = stringField(raw, 'cwd');
|
|
632
657
|
push({
|
|
633
|
-
id
|
|
658
|
+
id,
|
|
634
659
|
kind: 'mcp',
|
|
635
660
|
name: serverName,
|
|
636
|
-
|
|
661
|
+
declaredName: name,
|
|
662
|
+
path,
|
|
637
663
|
description: stringField(raw, 'description') ?? `${transport} MCP server`,
|
|
638
664
|
transport,
|
|
639
665
|
...(command !== undefined ? { command } : {}),
|
|
@@ -642,10 +668,10 @@ function addMcp(root, plugin, manifest, kind, push, warn) {
|
|
|
642
668
|
...(cwd !== undefined ? { cwd } : {}),
|
|
643
669
|
...(url !== undefined ? { url } : {}),
|
|
644
670
|
...(headers !== undefined ? { headers } : {}),
|
|
671
|
+
...(raw['enabled'] === false ? { notStarted: notStartedBy('disabled-in-plugin') } : {}),
|
|
645
672
|
});
|
|
646
673
|
}
|
|
647
674
|
}
|
|
648
|
-
void kind;
|
|
649
675
|
}
|
|
650
676
|
function mcpTransport(raw) {
|
|
651
677
|
const declared = stringField(raw, 'type') ?? stringField(raw, 'transport');
|
|
@@ -750,6 +776,9 @@ function addCode(root, plugin, manifest, kind, components, push, warn) {
|
|
|
750
776
|
// Filesystem helpers
|
|
751
777
|
// ---------------------------------------------------------------------------
|
|
752
778
|
function safeEntries(root) {
|
|
779
|
+
// On a link to a network share the path is not on: as unreadable (see `leadsToShare`).
|
|
780
|
+
if (leadsToShare(root))
|
|
781
|
+
return [];
|
|
753
782
|
try {
|
|
754
783
|
return readdirSync(root, { withFileTypes: true });
|
|
755
784
|
}
|
package/lib/marketplace.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export interface MarketplaceSource {
|
|
|
15
15
|
/** npm package name. */
|
|
16
16
|
readonly package?: string;
|
|
17
17
|
readonly version?: string;
|
|
18
|
+
/** npm registry URL. */
|
|
19
|
+
readonly registry?: string;
|
|
20
|
+
/** Zip URL of an `archive` source is `url`; this is its pinned digest. */
|
|
21
|
+
readonly sha256?: string;
|
|
18
22
|
/** Original declaration for diagnostics. */
|
|
19
23
|
readonly raw: unknown;
|
|
20
24
|
}
|
|
@@ -27,6 +31,8 @@ export interface MarketplaceEntry {
|
|
|
27
31
|
readonly category?: string;
|
|
28
32
|
readonly tags: readonly string[];
|
|
29
33
|
readonly source: MarketplaceSource;
|
|
34
|
+
/** The entry as written: with no `plugin.json` of its own, the plugin's manifest (Claude Code's rule). */
|
|
35
|
+
readonly fields: Readonly<Record<string, unknown>>;
|
|
30
36
|
}
|
|
31
37
|
/** A parsed marketplace index. */
|
|
32
38
|
export interface MarketplaceIndex {
|
|
@@ -49,5 +55,13 @@ export declare class MarketplaceError extends HarnessError {
|
|
|
49
55
|
* @throws {MarketplaceError} when no manifest or invalid JSON is found.
|
|
50
56
|
*/
|
|
51
57
|
export declare function readMarketplace(path: string): MarketplaceIndex;
|
|
58
|
+
/** Options of {@link parseMarketplace}. */
|
|
59
|
+
export interface ParseMarketplaceOptions {
|
|
60
|
+
/**
|
|
61
|
+
* False for a `marketplace.json` fetched by URL: there are no files beside it,
|
|
62
|
+
* so its relative entries cannot be installed (Claude Code's rule).
|
|
63
|
+
*/
|
|
64
|
+
readonly filesAvailable?: boolean;
|
|
65
|
+
}
|
|
52
66
|
/** Parse a marketplace document rooted at `root`. */
|
|
53
|
-
export declare function parseMarketplace(data: Record<string, unknown>, root: string, manifestPath?: string): MarketplaceIndex;
|
|
67
|
+
export declare function parseMarketplace(data: Record<string, unknown>, root: string, manifestPath?: string, options?: ParseMarketplaceOptions): MarketplaceIndex;
|
package/lib/marketplace.js
CHANGED
|
@@ -51,13 +51,18 @@ function marketplaceRoot(manifestPath) {
|
|
|
51
51
|
return dirname(manifestPath);
|
|
52
52
|
}
|
|
53
53
|
/** Parse a marketplace document rooted at `root`. */
|
|
54
|
-
export function parseMarketplace(data, root, manifestPath = join(root, 'marketplace.json')) {
|
|
54
|
+
export function parseMarketplace(data, root, manifestPath = join(root, 'marketplace.json'), options = {}) {
|
|
55
55
|
const warnings = [];
|
|
56
56
|
const name = typeof data['name'] === 'string' && data['name'].trim().length > 0 ? data['name'].trim() : 'unnamed-marketplace';
|
|
57
|
-
const description = typeof data['description'] === 'string'
|
|
57
|
+
const description = typeof data['description'] === 'string'
|
|
58
|
+
? data['description']
|
|
59
|
+
: isPlainObject(data['metadata']) && typeof data['metadata']['description'] === 'string' ? data['metadata']['description'] : undefined;
|
|
58
60
|
const owner = isPlainObject(data['owner']) && typeof data['owner']['name'] === 'string'
|
|
59
61
|
? data['owner']['name']
|
|
60
62
|
: undefined;
|
|
63
|
+
const metadata = isPlainObject(data['metadata']) ? data['metadata'] : {};
|
|
64
|
+
const pluginRoot = typeof metadata['pluginRoot'] === 'string' ? metadata['pluginRoot'] : undefined;
|
|
65
|
+
const context = { root, warnings, filesAvailable: options.filesAvailable !== false, ...(pluginRoot !== undefined ? { pluginRoot } : {}) };
|
|
61
66
|
const plugins = data['plugins'];
|
|
62
67
|
if (!Array.isArray(plugins))
|
|
63
68
|
throw new MarketplaceError('plugins-missing', `marketplace ${name} has no plugins array`);
|
|
@@ -72,7 +77,7 @@ export function parseMarketplace(data, root, manifestPath = join(root, 'marketpl
|
|
|
72
77
|
warnings.push(`entry ${index + 1} has no name`);
|
|
73
78
|
continue;
|
|
74
79
|
}
|
|
75
|
-
const source = parseSource(raw['source'],
|
|
80
|
+
const source = parseSource(raw['source'], context, entryName);
|
|
76
81
|
if (source === undefined)
|
|
77
82
|
continue;
|
|
78
83
|
entries.push({
|
|
@@ -83,22 +88,32 @@ export function parseMarketplace(data, root, manifestPath = join(root, 'marketpl
|
|
|
83
88
|
...(typeof raw['category'] === 'string' ? { category: raw['category'] } : {}),
|
|
84
89
|
tags: Array.isArray(raw['tags']) ? raw['tags'].filter((tag) => typeof tag === 'string') : [],
|
|
85
90
|
source,
|
|
91
|
+
fields: raw,
|
|
86
92
|
});
|
|
87
93
|
}
|
|
88
94
|
return { name, ...(description !== undefined ? { description } : {}), ...(owner !== undefined ? { owner } : {}), root, manifestPath, entries, warnings };
|
|
89
95
|
}
|
|
90
|
-
|
|
96
|
+
/** A relative entry path inside the marketplace root, or undefined (with a warning) when it leaves it. */
|
|
97
|
+
function insideRoot(declared, context, entryName, raw) {
|
|
98
|
+
if (!context.filesAvailable) {
|
|
99
|
+
context.warnings.push(`entry ${entryName} uses a relative path, which a marketplace.json fetched by URL cannot provide`);
|
|
100
|
+
return { kind: 'unknown', raw };
|
|
101
|
+
}
|
|
102
|
+
const path = resolve(context.root, declared);
|
|
103
|
+
if (!isInside(context.root, path)) {
|
|
104
|
+
context.warnings.push(`entry ${entryName} source escapes the marketplace root: ${declared}`);
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
return { kind: 'path', path, raw };
|
|
108
|
+
}
|
|
109
|
+
function parseSource(raw, context, entryName) {
|
|
110
|
+
const { warnings } = context;
|
|
91
111
|
if (typeof raw === 'string') {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (path !== undefined)
|
|
98
|
-
return { kind: 'path', path, raw };
|
|
99
|
-
// Claude relative sources must start with './'; a bare name may be
|
|
100
|
-
// resolved under metadata.pluginRoot, which this first reader does not
|
|
101
|
-
// model. Report rather than invent a location.
|
|
112
|
+
if (raw.startsWith('.') || isAbsolute(raw))
|
|
113
|
+
return insideRoot(raw, context, entryName, raw);
|
|
114
|
+
// A bare name resolves under metadata.pluginRoot (Claude Code v2.1.239+).
|
|
115
|
+
if (context.pluginRoot !== undefined && /^[^/\\]+$/u.test(raw))
|
|
116
|
+
return insideRoot(join(context.pluginRoot, raw), context, entryName, raw);
|
|
102
117
|
warnings.push(`entry ${entryName} has an unsupported relative source: ${raw}`);
|
|
103
118
|
return { kind: 'unknown', raw };
|
|
104
119
|
}
|
|
@@ -108,42 +123,35 @@ function parseSource(raw, root, entryName, warnings) {
|
|
|
108
123
|
}
|
|
109
124
|
const type = typeof raw['source'] === 'string' ? raw['source'] : '';
|
|
110
125
|
if (type === 'local' || type === 'path' || type === '') {
|
|
111
|
-
const declared = typeof raw['path'] === 'string' ? raw['path'] :
|
|
126
|
+
const declared = typeof raw['path'] === 'string' ? raw['path'] : undefined;
|
|
112
127
|
if (declared === undefined) {
|
|
113
128
|
warnings.push(`entry ${entryName} local source has no path`);
|
|
114
129
|
return { kind: 'unknown', raw };
|
|
115
130
|
}
|
|
116
|
-
|
|
117
|
-
if (!isInside(root, path)) {
|
|
118
|
-
warnings.push(`entry ${entryName} source escapes the marketplace root: ${declared}`);
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
return { kind: 'path', path, raw };
|
|
131
|
+
return insideRoot(declared, context, entryName, raw);
|
|
122
132
|
}
|
|
133
|
+
const pins = {
|
|
134
|
+
...(typeof raw['ref'] === 'string' ? { ref: raw['ref'] } : {}),
|
|
135
|
+
...(typeof raw['sha'] === 'string' ? { sha: raw['sha'] } : {}),
|
|
136
|
+
};
|
|
123
137
|
if (type === 'github') {
|
|
124
138
|
const repo = typeof raw['repo'] === 'string' ? raw['repo'] : undefined;
|
|
125
139
|
if (repo === undefined)
|
|
126
140
|
return { kind: 'unknown', raw };
|
|
127
|
-
return {
|
|
128
|
-
kind: 'git',
|
|
129
|
-
url: `https://github.com/${repo}.git`,
|
|
130
|
-
...(typeof raw['ref'] === 'string' ? { ref: raw['ref'] } : {}),
|
|
131
|
-
...(typeof raw['sha'] === 'string' ? { sha: raw['sha'] } : {}),
|
|
132
|
-
raw,
|
|
133
|
-
};
|
|
141
|
+
return { kind: 'git', url: `https://github.com/${repo}.git`, ...pins, raw };
|
|
134
142
|
}
|
|
135
143
|
if (type === 'url' || type === 'git' || type === 'git-subdir') {
|
|
136
144
|
const url = typeof raw['url'] === 'string' ? raw['url'] : undefined;
|
|
137
145
|
if (url === undefined)
|
|
138
146
|
return { kind: 'unknown', raw };
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
};
|
|
147
|
+
const subpath = typeof raw['path'] === 'string' ? raw['path'].replace(/^\.\//u, '') : undefined;
|
|
148
|
+
if (subpath !== undefined && (subpath.split(/[\\/]/u).includes('..') || isAbsolute(subpath))) {
|
|
149
|
+
warnings.push(`entry ${entryName} source path escapes its repository: ${subpath}`);
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
// git-subdir takes GitHub owner/repo shorthand; url and git take a full URL.
|
|
153
|
+
const full = type === 'git-subdir' && /^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/u.test(url) ? `https://github.com/${url}.git` : url;
|
|
154
|
+
return { kind: 'git', url: full, ...(subpath !== undefined && subpath.length > 0 && subpath !== '.' ? { subpath } : {}), ...pins, raw };
|
|
147
155
|
}
|
|
148
156
|
if (type === 'npm') {
|
|
149
157
|
const pkg = typeof raw['package'] === 'string' ? raw['package'] : undefined;
|
|
@@ -153,10 +161,19 @@ function parseSource(raw, root, entryName, warnings) {
|
|
|
153
161
|
kind: 'npm',
|
|
154
162
|
package: pkg,
|
|
155
163
|
...(typeof raw['version'] === 'string' ? { version: raw['version'] } : {}),
|
|
164
|
+
...(typeof raw['registry'] === 'string' ? { registry: raw['registry'] } : {}),
|
|
165
|
+
raw,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
if (type === 'archive') {
|
|
169
|
+
return {
|
|
170
|
+
kind: 'archive',
|
|
171
|
+
...(typeof raw['url'] === 'string' ? { url: raw['url'] } : {}),
|
|
172
|
+
...(typeof raw['sha256'] === 'string' ? { sha256: raw['sha256'] } : {}),
|
|
156
173
|
raw,
|
|
157
174
|
};
|
|
158
175
|
}
|
|
159
|
-
if (type === '
|
|
160
|
-
return { kind:
|
|
176
|
+
if (type === 'command')
|
|
177
|
+
return { kind: 'command', raw };
|
|
161
178
|
return { kind: 'unknown', raw };
|
|
162
179
|
}
|
package/lib/paths.d.ts
CHANGED
|
@@ -1,7 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `\\server\share` a Windows path names, when it names one: a UNC path, also as `//server/share` or
|
|
3
|
+
* `\\?\UNC\server\share`. Device paths (`\\.\…`, `\\?\…` other than a drive) count too: none is a plain
|
|
4
|
+
* local file. Undefined for a drive path, and for any path on another platform, where `//` is the root.
|
|
5
|
+
*/
|
|
6
|
+
export declare function networkShareOf(path: string, platform?: NodeJS.Platform): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Whether reading `path` would reach a network share or device that `base` is not already on. Windows reads a
|
|
9
|
+
* UNC path over SMB and signs in to that server with the person's credentials, so a path a configuration names
|
|
10
|
+
* must not make it reach a new one.
|
|
11
|
+
*/
|
|
12
|
+
export declare function reachesNewShare(path: string, base: string, platform?: NodeJS.Platform): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The most symbolic links one resolution follows: Linux's limit (path_resolution(7): "a maximum of 40 symbolic
|
|
15
|
+
* links"). macOS stops at 32 (`MAXSYMLINKS`) and Windows at 63 reparse points; a chain longer than this is
|
|
16
|
+
* treated as one that cannot be resolved.
|
|
17
|
+
*/
|
|
18
|
+
export declare const SYMLINK_HOPS = 40;
|
|
19
|
+
/** The two calls that read a link without following it: neither opens the link's target. */
|
|
20
|
+
export interface LinkReader {
|
|
21
|
+
lstat(path: string): {
|
|
22
|
+
isSymbolicLink(): boolean;
|
|
23
|
+
};
|
|
24
|
+
readlink(path: string): string;
|
|
25
|
+
}
|
|
26
|
+
/** The system's own link reader. */
|
|
27
|
+
export declare const SYSTEM_LINKS: LinkReader;
|
|
28
|
+
/**
|
|
29
|
+
* Whether resolving `path` would reach a network share or device that `base` is not on (see
|
|
30
|
+
* {@link reachesNewShare}), through the path itself or through any symbolic link or junction on the way,
|
|
31
|
+
* followed within {@link SYMLINK_HOPS}. Only `lstat` and `readlink` are called, and never on a new share, so
|
|
32
|
+
* nothing connects to one; a resolver (realpath, open) may follow the path once this says no. A loop, too many
|
|
33
|
+
* links or a link that cannot be read counts as reaching one. Off Windows there are no shares and no calls.
|
|
34
|
+
*/
|
|
35
|
+
export declare function linksReachNewShare(path: string, base: string, platform?: NodeJS.Platform, links?: LinkReader): boolean;
|
|
1
36
|
/** Return true when `candidate` is inside `root` (or equals it). */
|
|
2
37
|
export declare function isInside(root: string, candidate: string): boolean;
|
|
3
38
|
/** Resolve a plugin-relative path and reject escapes. */
|
|
4
39
|
export declare function resolveInside(root: string, path: string): string | undefined;
|
|
40
|
+
/** Why a helper below did not read a path {@link leadsToShare} refused. */
|
|
41
|
+
export declare const LEADS_TO_SHARE = "leads to a network share";
|
|
42
|
+
/**
|
|
43
|
+
* Whether reading `path` would take a link to a network share the path is not on: a local path led to any share,
|
|
44
|
+
* or a share's path to another. The one guard every file helper below runs before its first stat, open or
|
|
45
|
+
* realpath, since on Windows touching a share signs in to its server. Off Windows it returns at once
|
|
46
|
+
* (`linksReachNewShare` makes no call there).
|
|
47
|
+
*/
|
|
48
|
+
export declare function leadsToShare(path: string, platform?: NodeJS.Platform): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* A path a file's content names (a manifest field, a config entry, an import, a link), resolved against
|
|
51
|
+
* `origin`, the folder of the file it came from; undefined when, on Windows, the value, the resolved path or a
|
|
52
|
+
* link on its way reaches a network share `origin` is not on. Every value read from a file goes through this
|
|
53
|
+
* before the first filesystem call: {@link leadsToShare} checks a path against itself, so a value naming a share
|
|
54
|
+
* outright would pass it. Paths found by walking a folder are the helpers' own concern.
|
|
55
|
+
*/
|
|
56
|
+
export declare function contentPath(value: string, origin: string, platform?: NodeJS.Platform): string | undefined;
|
|
5
57
|
/** Resolve symlinks when the path exists, falling back to the lexical path. */
|
|
6
58
|
export declare function realOrLexical(path: string): string;
|
|
7
59
|
/** Return true when a path exists and is a regular file. */
|
|
@@ -17,6 +69,19 @@ export declare function childDirectories(root: string): string[];
|
|
|
17
69
|
export declare function readText(path: string): string | undefined;
|
|
18
70
|
/** Read and parse JSON, returning undefined instead of throwing. */
|
|
19
71
|
export declare function readJson(path: string): unknown;
|
|
72
|
+
/**
|
|
73
|
+
* A file a harness keeps its record in, as read: absent (`{}`: a missing file records nothing, which is a complete
|
|
74
|
+
* read), its object, or why it could not be read. A harness writing it may leave it malformed or cut off for a moment;
|
|
75
|
+
* that must never read as "it records nothing".
|
|
76
|
+
*/
|
|
77
|
+
export interface RecordRead<T> {
|
|
78
|
+
readonly value?: T;
|
|
79
|
+
readonly problem?: string;
|
|
80
|
+
}
|
|
81
|
+
/** Read a harness's record file as text: absent, its text, or why it could not be read. */
|
|
82
|
+
export declare function readRecordText(path: string): RecordRead<string>;
|
|
83
|
+
/** Read a harness's JSON object record (see {@link RecordRead}). */
|
|
84
|
+
export declare function readJsonRecord(path: string): RecordRead<Record<string, unknown>>;
|
|
20
85
|
/** Parse JSON and require a plain object. */
|
|
21
86
|
export declare function readJsonObject(path: string): Record<string, unknown> | undefined;
|
|
22
87
|
/** A plain (non-null, non-array) object. */
|
package/lib/paths.js
CHANGED
|
@@ -4,8 +4,95 @@
|
|
|
4
4
|
* same check before handing a path to a DSH service.
|
|
5
5
|
* @module @kirkchinese/harness-forge-core
|
|
6
6
|
*/
|
|
7
|
-
import { readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
8
|
-
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
7
|
+
import { lstatSync, readFileSync, readdirSync, readlinkSync, realpathSync, statSync } from 'node:fs';
|
|
8
|
+
import { isAbsolute, relative, resolve, sep, win32 } from 'node:path';
|
|
9
|
+
/**
|
|
10
|
+
* The `\\server\share` a Windows path names, when it names one: a UNC path, also as `//server/share` or
|
|
11
|
+
* `\\?\UNC\server\share`. Device paths (`\\.\…`, `\\?\…` other than a drive) count too: none is a plain
|
|
12
|
+
* local file. Undefined for a drive path, and for any path on another platform, where `//` is the root.
|
|
13
|
+
*/
|
|
14
|
+
export function networkShareOf(path, platform = process.platform) {
|
|
15
|
+
if (platform !== 'win32')
|
|
16
|
+
return undefined;
|
|
17
|
+
const normalized = win32.normalize(path);
|
|
18
|
+
if (/^\\\\\?\\[A-Za-z]:\\/u.test(normalized))
|
|
19
|
+
return undefined;
|
|
20
|
+
const unc = /^\\\\\?\\UNC\\([^\\]+)\\([^\\]+)/iu.exec(normalized) ?? /^\\\\([^\\?.][^\\]*)\\([^\\]+)/u.exec(normalized);
|
|
21
|
+
if (unc !== null)
|
|
22
|
+
return `\\\\${(unc[1] ?? '').toLowerCase()}\\${(unc[2] ?? '').toLowerCase()}`;
|
|
23
|
+
return normalized.startsWith('\\\\') ? normalized : undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether reading `path` would reach a network share or device that `base` is not already on. Windows reads a
|
|
27
|
+
* UNC path over SMB and signs in to that server with the person's credentials, so a path a configuration names
|
|
28
|
+
* must not make it reach a new one.
|
|
29
|
+
*/
|
|
30
|
+
export function reachesNewShare(path, base, platform = process.platform) {
|
|
31
|
+
const share = networkShareOf(path, platform);
|
|
32
|
+
return share !== undefined && share !== networkShareOf(base, platform);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The most symbolic links one resolution follows: Linux's limit (path_resolution(7): "a maximum of 40 symbolic
|
|
36
|
+
* links"). macOS stops at 32 (`MAXSYMLINKS`) and Windows at 63 reparse points; a chain longer than this is
|
|
37
|
+
* treated as one that cannot be resolved.
|
|
38
|
+
*/
|
|
39
|
+
export const SYMLINK_HOPS = 40;
|
|
40
|
+
/** The system's own link reader. */
|
|
41
|
+
export const SYSTEM_LINKS = { lstat: lstatSync, readlink: readlinkSync };
|
|
42
|
+
/**
|
|
43
|
+
* Whether resolving `path` would reach a network share or device that `base` is not on (see
|
|
44
|
+
* {@link reachesNewShare}), through the path itself or through any symbolic link or junction on the way,
|
|
45
|
+
* followed within {@link SYMLINK_HOPS}. Only `lstat` and `readlink` are called, and never on a new share, so
|
|
46
|
+
* nothing connects to one; a resolver (realpath, open) may follow the path once this says no. A loop, too many
|
|
47
|
+
* links or a link that cannot be read counts as reaching one. Off Windows there are no shares and no calls.
|
|
48
|
+
*/
|
|
49
|
+
export function linksReachNewShare(path, base, platform = process.platform, links = SYSTEM_LINKS) {
|
|
50
|
+
if (platform !== 'win32')
|
|
51
|
+
return false;
|
|
52
|
+
if (reachesNewShare(path, base, platform))
|
|
53
|
+
return true;
|
|
54
|
+
const parsed = win32.parse(win32.resolve(path));
|
|
55
|
+
let current = parsed.root;
|
|
56
|
+
const parts = win32.resolve(path).slice(parsed.root.length).split(/[\\/]+/u).filter(part => part.length > 0);
|
|
57
|
+
for (let hops = 0; parts.length > 0;) {
|
|
58
|
+
const part = parts.shift() ?? '';
|
|
59
|
+
if (part === '.')
|
|
60
|
+
continue;
|
|
61
|
+
if (part === '..') {
|
|
62
|
+
current = win32.dirname(current);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const next = win32.join(current, part);
|
|
66
|
+
let link;
|
|
67
|
+
try {
|
|
68
|
+
link = links.lstat(next).isSymbolicLink();
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
// Nothing there: nothing below it can be a link. Any other failure leaves the path unknown.
|
|
72
|
+
return error.code !== 'ENOENT';
|
|
73
|
+
}
|
|
74
|
+
if (!link) {
|
|
75
|
+
current = next;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (++hops > SYMLINK_HOPS)
|
|
79
|
+
return true;
|
|
80
|
+
let target;
|
|
81
|
+
try {
|
|
82
|
+
target = links.readlink(next);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
const resolved = win32.resolve(current, target);
|
|
88
|
+
if (reachesNewShare(target, base, platform) || reachesNewShare(resolved, base, platform))
|
|
89
|
+
return true;
|
|
90
|
+
const root = win32.parse(resolved).root;
|
|
91
|
+
parts.unshift(...resolved.slice(root.length).split(/[\\/]+/u).filter(segment => segment.length > 0));
|
|
92
|
+
current = root;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
9
96
|
/** Return true when `candidate` is inside `root` (or equals it). */
|
|
10
97
|
export function isInside(root, candidate) {
|
|
11
98
|
const rel = relative(resolve(root), resolve(candidate));
|
|
@@ -16,8 +103,34 @@ export function resolveInside(root, path) {
|
|
|
16
103
|
const candidate = resolve(root, path);
|
|
17
104
|
return isInside(root, candidate) ? candidate : undefined;
|
|
18
105
|
}
|
|
106
|
+
/** Why a helper below did not read a path {@link leadsToShare} refused. */
|
|
107
|
+
export const LEADS_TO_SHARE = 'leads to a network share';
|
|
108
|
+
/**
|
|
109
|
+
* Whether reading `path` would take a link to a network share the path is not on: a local path led to any share,
|
|
110
|
+
* or a share's path to another. The one guard every file helper below runs before its first stat, open or
|
|
111
|
+
* realpath, since on Windows touching a share signs in to its server. Off Windows it returns at once
|
|
112
|
+
* (`linksReachNewShare` makes no call there).
|
|
113
|
+
*/
|
|
114
|
+
export function leadsToShare(path, platform = process.platform) {
|
|
115
|
+
return linksReachNewShare(path, path, platform);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A path a file's content names (a manifest field, a config entry, an import, a link), resolved against
|
|
119
|
+
* `origin`, the folder of the file it came from; undefined when, on Windows, the value, the resolved path or a
|
|
120
|
+
* link on its way reaches a network share `origin` is not on. Every value read from a file goes through this
|
|
121
|
+
* before the first filesystem call: {@link leadsToShare} checks a path against itself, so a value naming a share
|
|
122
|
+
* outright would pass it. Paths found by walking a folder are the helpers' own concern.
|
|
123
|
+
*/
|
|
124
|
+
export function contentPath(value, origin, platform = process.platform) {
|
|
125
|
+
if (reachesNewShare(value, origin, platform))
|
|
126
|
+
return undefined;
|
|
127
|
+
const path = resolve(origin, value);
|
|
128
|
+
return linksReachNewShare(path, origin, platform) ? undefined : path;
|
|
129
|
+
}
|
|
19
130
|
/** Resolve symlinks when the path exists, falling back to the lexical path. */
|
|
20
131
|
export function realOrLexical(path) {
|
|
132
|
+
if (leadsToShare(path))
|
|
133
|
+
return resolve(path);
|
|
21
134
|
try {
|
|
22
135
|
return realpathSync(path);
|
|
23
136
|
}
|
|
@@ -27,6 +140,8 @@ export function realOrLexical(path) {
|
|
|
27
140
|
}
|
|
28
141
|
/** Return true when a path exists and is a regular file. */
|
|
29
142
|
export function isFile(path) {
|
|
143
|
+
if (leadsToShare(path))
|
|
144
|
+
return false;
|
|
30
145
|
try {
|
|
31
146
|
return statSync(path).isFile();
|
|
32
147
|
}
|
|
@@ -36,6 +151,8 @@ export function isFile(path) {
|
|
|
36
151
|
}
|
|
37
152
|
/** Return true when a path exists and is a directory. */
|
|
38
153
|
export function isDirectory(path) {
|
|
154
|
+
if (leadsToShare(path))
|
|
155
|
+
return false;
|
|
39
156
|
try {
|
|
40
157
|
return statSync(path).isDirectory();
|
|
41
158
|
}
|
|
@@ -48,6 +165,8 @@ export function isDirectory(path) {
|
|
|
48
165
|
* to a directory counts, as harnesses follow linked skill directories.
|
|
49
166
|
*/
|
|
50
167
|
export function childDirectories(root) {
|
|
168
|
+
if (leadsToShare(root))
|
|
169
|
+
return [];
|
|
51
170
|
try {
|
|
52
171
|
return readdirSync(root, { withFileTypes: true })
|
|
53
172
|
.filter(entry => entry.isDirectory() || (entry.isSymbolicLink() && isDirectory(`${root}/${entry.name}`)))
|
|
@@ -60,6 +179,8 @@ export function childDirectories(root) {
|
|
|
60
179
|
}
|
|
61
180
|
/** Read a UTF-8 file, returning undefined instead of throwing. */
|
|
62
181
|
export function readText(path) {
|
|
182
|
+
if (leadsToShare(path))
|
|
183
|
+
return undefined;
|
|
63
184
|
try {
|
|
64
185
|
return readFileSync(path, 'utf8');
|
|
65
186
|
}
|
|
@@ -79,6 +200,35 @@ export function readJson(path) {
|
|
|
79
200
|
return undefined;
|
|
80
201
|
}
|
|
81
202
|
}
|
|
203
|
+
/** Errors that mean the file is not there: nothing recorded. */
|
|
204
|
+
const ABSENT = new Set(['ENOENT', 'ENOTDIR']);
|
|
205
|
+
/** Read a harness's record file as text: absent, its text, or why it could not be read. */
|
|
206
|
+
export function readRecordText(path) {
|
|
207
|
+
if (leadsToShare(path))
|
|
208
|
+
return { problem: `${path} could not be read (${LEADS_TO_SHARE})` };
|
|
209
|
+
try {
|
|
210
|
+
return { value: readFileSync(path, 'utf8') };
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
const code = error.code;
|
|
214
|
+
if (typeof code === 'string' && ABSENT.has(code))
|
|
215
|
+
return {};
|
|
216
|
+
return { problem: `${path} could not be read (${error instanceof Error ? error.message : String(error)})` };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** Read a harness's JSON object record (see {@link RecordRead}). */
|
|
220
|
+
export function readJsonRecord(path) {
|
|
221
|
+
const text = readRecordText(path);
|
|
222
|
+
if (text.value === undefined)
|
|
223
|
+
return text.problem === undefined ? {} : { problem: text.problem };
|
|
224
|
+
try {
|
|
225
|
+
const value = JSON.parse(text.value);
|
|
226
|
+
return isPlainObject(value) ? { value } : { problem: `${path} is not a JSON object` };
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
return { problem: `${path} is not valid JSON (${error instanceof Error ? error.message : String(error)})` };
|
|
230
|
+
}
|
|
231
|
+
}
|
|
82
232
|
/** Parse JSON and require a plain object. */
|
|
83
233
|
export function readJsonObject(path) {
|
|
84
234
|
const value = readJson(path);
|
package/lib/plan.js
CHANGED
|
@@ -80,7 +80,9 @@ function describe(component) {
|
|
|
80
80
|
case 'skill': return `Link skill root for ${component.name}`;
|
|
81
81
|
case 'command': return `Register slash command ${component.name}`;
|
|
82
82
|
case 'agent': return `Register agent preset ${component.name}`;
|
|
83
|
-
case 'mcp': return
|
|
83
|
+
case 'mcp': return component.notStarted !== undefined
|
|
84
|
+
? `Leave MCP server ${component.name} unstarted: ${component.notStarted.detail}`
|
|
85
|
+
: `Mount MCP server ${component.name} (${component.transport})`;
|
|
84
86
|
case 'hooks': return `Mount hook bridge ${component.name} (${component.events.join(', ') || 'no events'})`;
|
|
85
87
|
case 'code': return `Load ${component.runtime} ${component.name} through its runtime shim`;
|
|
86
88
|
case 'ui': return `Report UI surface ${component.name} (${component.surface}); not rendered`;
|
package/lib/port-brief.d.ts
CHANGED
|
@@ -9,14 +9,28 @@ export interface PortBriefInput {
|
|
|
9
9
|
readonly files: readonly string[];
|
|
10
10
|
/** The original's license when the manifest does not declare it (a detected LICENSE file). */
|
|
11
11
|
readonly license?: string;
|
|
12
|
+
/** Where the DSH that asks keeps its data, as DSH resolved it; absent when the caller does not know. */
|
|
13
|
+
readonly runtime?: PortRuntime;
|
|
12
14
|
}
|
|
15
|
+
/** The DSH home and profile of the session that asks for a port: facts for the creator, never for the adapter's source. */
|
|
16
|
+
export interface PortRuntime {
|
|
17
|
+
/** The effective DSH home: `$DSH_HOME`, else `~/.dsh`, resolved. */
|
|
18
|
+
readonly dshHome: string;
|
|
19
|
+
/** Whether `$DSH_HOME` set it. */
|
|
20
|
+
readonly dshHomeFromEnv: boolean;
|
|
21
|
+
/** The profile DSH runs (`profileContext`); absent when DSH was started without one. */
|
|
22
|
+
readonly profile?: {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly dir: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** The DSH home when `$DSH_HOME` is not set, as the user would type it. */
|
|
28
|
+
export declare const DEFAULT_DSH_HOME = "~/.dsh";
|
|
13
29
|
/** The npm name of the adapter for one part: unscoped, `dsh-adapter-<plugin>-<part>`. */
|
|
14
30
|
export declare function adapterPackageName(plugin: Pick<ForeignPlugin, 'name'>, component: Pick<ForeignComponent, 'name'>): string;
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* local install keeps pointing at it.
|
|
19
|
-
*/
|
|
31
|
+
/** Directory under the user's home where creation sessions author local adapters by default. */
|
|
32
|
+
export declare const ADAPTERS_DIR = "dsh-adapters";
|
|
33
|
+
/** Where the creator suggests authoring the adapter, as the user would type it. */
|
|
20
34
|
export declare function defaultAdapterDir(packageName: string): string;
|
|
21
35
|
/** The gaps a brief is about: the component's own, without license and version notes. */
|
|
22
36
|
export declare function gapsOf(component: Pick<ForeignComponent, 'id'>, gaps: readonly Gap[]): Gap[];
|
|
@@ -30,6 +44,15 @@ export declare function extensionPointsFor(component: ForeignComponent, gaps: re
|
|
|
30
44
|
* default the creator offers.
|
|
31
45
|
*/
|
|
32
46
|
export declare function openQuestionsFor(component: ForeignComponent, gaps: readonly Gap[]): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Where this DSH keeps its data, and how the adapter finds the same at run
|
|
49
|
+
* time (dsh-doc `references/plugin-development.md` and the `profileContext`
|
|
50
|
+
* and shell environment DSH provides). The resolved values are for the
|
|
51
|
+
* creator's checks only: the adapter's source must resolve them itself.
|
|
52
|
+
*/
|
|
53
|
+
export declare function dataLocationLines(runtime: PortRuntime | undefined): string[];
|
|
54
|
+
/** The rules every adapter keeps when it touches session, profile or harness data. */
|
|
55
|
+
export declare const DATA_RULES: readonly string[];
|
|
33
56
|
/**
|
|
34
57
|
* Write the brief for one part, as Markdown. It names the original's files
|
|
35
58
|
* by absolute path so the adapter reuses them where it can.
|