@modelprofile.com/flexharness 3.6.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +18 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.flexharness.d.ts +71 -1
- package/dist_ts/classes.flexharness.js +2374 -138
- package/dist_ts/classes.stores.js +1 -1
- package/dist_ts/errors.d.ts +8 -0
- package/dist_ts/errors.js +17 -1
- package/dist_ts/index.d.ts +1 -0
- package/dist_ts/index.js +2 -1
- package/dist_ts/interfaces.d.ts +272 -5
- package/dist_ts/interfaces.js +18 -2
- package/dist_ts/plugins.d.ts +2 -2
- package/dist_ts/plugins.js +3 -3
- package/dist_ts/utils.json.d.ts +5 -2
- package/dist_ts/utils.json.js +485 -10
- package/dist_ts/utils.slashcommands.d.ts +7 -0
- package/dist_ts/utils.slashcommands.js +164 -0
- package/dist_ts_migration/v3_legacyflexharness.js +6 -2
- package/package.json +1 -1
- package/readme.hints.md +4 -0
- package/readme.md +190 -3
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.flexharness.ts +3210 -190
- package/ts/classes.stores.ts +9 -8
- package/ts/errors.ts +25 -0
- package/ts/index.ts +4 -0
- package/ts/interfaces.ts +378 -5
- package/ts/plugins.ts +2 -0
- package/ts/utils.json.ts +543 -12
- package/ts/utils.slashcommands.ts +178 -0
- package/ts_migration/v3_legacyflexharness.ts +10 -5
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { FlexHarnessValidationError } from './errors.js';
|
|
2
|
+
import type {
|
|
3
|
+
IFlexParsedSlashCommand,
|
|
4
|
+
TFlexSlashCommandParseResult,
|
|
5
|
+
} from './interfaces.js';
|
|
6
|
+
|
|
7
|
+
export const FLEX_SLASH_COMMAND_MAX_INPUT_BYTES = 768 * 1024;
|
|
8
|
+
|
|
9
|
+
const slashCommandNamePattern = /^[a-z][a-z0-9-]{0,63}$/u;
|
|
10
|
+
const slashCommandPattern = /^\/([a-z][a-z0-9-]{0,63})(?:$|(\s+)([\s\S]*))$/u;
|
|
11
|
+
const slashCommandArgumentsPattern = /(?:\[Image\s+\d+\]|"[^"]*"|'[^']*'|[^\s"']+)/gi;
|
|
12
|
+
const slashCommandQuoteTrimPattern = /^["']|["']$/g;
|
|
13
|
+
const slashCommandPlaceholderPattern = /\$(\d+)/g;
|
|
14
|
+
const slashCommandAllPlaceholderPattern = /\$ARGUMENTS|\$(\d+)/g;
|
|
15
|
+
|
|
16
|
+
export const FLEX_SLASH_COMMAND_INITIALIZE_TEMPLATE = `Create or update \`AGENTS.md\` for this repository.
|
|
17
|
+
|
|
18
|
+
The goal is a compact instruction file that helps future OpenCode sessions avoid mistakes and ramp up quickly. Every line should answer: "Would an agent likely miss this without help?" If not, leave it out.
|
|
19
|
+
|
|
20
|
+
User-provided focus or constraints (honor these):
|
|
21
|
+
$ARGUMENTS
|
|
22
|
+
|
|
23
|
+
## How to investigate
|
|
24
|
+
|
|
25
|
+
Read the highest-value sources first:
|
|
26
|
+
- \`README*\`, root manifests, workspace config, lockfiles
|
|
27
|
+
- build, test, lint, formatter, typecheck, and codegen config
|
|
28
|
+
- CI workflows and pre-commit / task runner config
|
|
29
|
+
- existing instruction files (\`AGENTS.md\`, \`CLAUDE.md\`, \`.cursor/rules/\`, \`.cursorrules\`, \`.github/copilot-instructions.md\`)
|
|
30
|
+
- repo-local OpenCode config such as \`opencode.json\`
|
|
31
|
+
|
|
32
|
+
If architecture is still unclear after reading config and docs, inspect a small number of representative code files to find the real entrypoints, package boundaries, and execution flow. Prefer reading the files that explain how the system is wired together over random leaf files.
|
|
33
|
+
|
|
34
|
+
Prefer executable sources of truth over prose. If docs conflict with config or scripts, trust the executable source and only keep what you can verify.
|
|
35
|
+
|
|
36
|
+
## What to extract
|
|
37
|
+
|
|
38
|
+
Look for the highest-signal facts for an agent working in this repo:
|
|
39
|
+
- exact developer commands, especially non-obvious ones
|
|
40
|
+
- how to run a single test, a single package, or a focused verification step
|
|
41
|
+
- required command order when it matters, such as \`lint -> typecheck -> test\`
|
|
42
|
+
- monorepo or multi-package boundaries, ownership of major directories, and the real app/library entrypoints
|
|
43
|
+
- framework or toolchain quirks: generated code, migrations, codegen, build artifacts, special env loading, dev servers, infra deploy flow
|
|
44
|
+
- repo-specific style or workflow conventions that differ from defaults
|
|
45
|
+
- testing quirks: fixtures, integration test prerequisites, snapshot workflows, required services, flaky or expensive suites
|
|
46
|
+
- important constraints from existing instruction files worth preserving
|
|
47
|
+
|
|
48
|
+
Good \`AGENTS.md\` content is usually hard-earned context that took reading multiple files to infer.
|
|
49
|
+
|
|
50
|
+
## Questions
|
|
51
|
+
|
|
52
|
+
Only ask the user questions if the repo cannot answer something important. Use the \`question\` tool for one short batch at most.
|
|
53
|
+
|
|
54
|
+
Good questions:
|
|
55
|
+
- undocumented team conventions
|
|
56
|
+
- branch / PR / release expectations
|
|
57
|
+
- missing setup or test prerequisites that are known but not written down
|
|
58
|
+
|
|
59
|
+
Do not ask about anything the repo already makes clear.
|
|
60
|
+
|
|
61
|
+
## Writing rules
|
|
62
|
+
|
|
63
|
+
Include only high-signal, repo-specific guidance such as:
|
|
64
|
+
- exact commands and shortcuts the agent would otherwise guess wrong
|
|
65
|
+
- architecture notes that are not obvious from filenames
|
|
66
|
+
- conventions that differ from language or framework defaults
|
|
67
|
+
- setup requirements, environment quirks, and operational gotchas
|
|
68
|
+
- references to existing instruction sources that matter
|
|
69
|
+
|
|
70
|
+
Exclude:
|
|
71
|
+
- generic software advice
|
|
72
|
+
- long tutorials or exhaustive file trees
|
|
73
|
+
- obvious language conventions
|
|
74
|
+
- speculative claims or anything you could not verify
|
|
75
|
+
- content better stored in another file referenced via \`opencode.json\` \`instructions\`
|
|
76
|
+
|
|
77
|
+
When in doubt, omit.
|
|
78
|
+
|
|
79
|
+
Prefer short sections and bullets. If the repo is simple, keep the file simple. If the repo is large, summarize the few structural facts that actually change how an agent should work.
|
|
80
|
+
|
|
81
|
+
If \`AGENTS.md\` already exists in the active workspace, improve it in place rather than rewriting blindly. Preserve verified useful guidance, delete fluff or stale claims, and reconcile it with the current codebase.
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
export function isValidSlashCommandName(name: string): boolean {
|
|
85
|
+
return slashCommandNamePattern.test(name);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function tokenizeSlashCommandArguments(rawArguments: string): string[] {
|
|
89
|
+
const tokens = rawArguments.match(slashCommandArgumentsPattern) ?? [];
|
|
90
|
+
return tokens.map((token) => token.replace(slashCommandQuoteTrimPattern, ''));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function parseSlashCommand(input: string): TFlexSlashCommandParseResult {
|
|
94
|
+
if (typeof input !== 'string') {
|
|
95
|
+
throw new FlexHarnessValidationError('Slash command input must be a string.');
|
|
96
|
+
}
|
|
97
|
+
if (!input.startsWith('/')) return Object.freeze({ type: 'not-command' });
|
|
98
|
+
if (Buffer.byteLength(input, 'utf8') > FLEX_SLASH_COMMAND_MAX_INPUT_BYTES) {
|
|
99
|
+
return Object.freeze({
|
|
100
|
+
type: 'malformed',
|
|
101
|
+
reason: `Slash command input exceeds ${FLEX_SLASH_COMMAND_MAX_INPUT_BYTES} UTF-8 bytes.`,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const match = slashCommandPattern.exec(input);
|
|
105
|
+
if (!match) {
|
|
106
|
+
return Object.freeze({
|
|
107
|
+
type: 'malformed',
|
|
108
|
+
reason: 'Slash command syntax is invalid.',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const arguments_ = tokenizeSlashCommandArguments(match[3] ?? '');
|
|
112
|
+
Object.freeze(arguments_);
|
|
113
|
+
return Object.freeze({
|
|
114
|
+
type: 'parsed',
|
|
115
|
+
input,
|
|
116
|
+
name: match[1],
|
|
117
|
+
rawArguments: match[3] ?? '',
|
|
118
|
+
arguments: arguments_,
|
|
119
|
+
} satisfies IFlexParsedSlashCommand);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function slashCommandTemplateHints(template: string): string[] {
|
|
123
|
+
const hints = [...new Set(template.match(/\$\d+/g) ?? [])].sort();
|
|
124
|
+
if (template.includes('$ARGUMENTS')) hints.push('$ARGUMENTS');
|
|
125
|
+
return hints;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function expandSlashCommandTemplate(
|
|
129
|
+
template: string,
|
|
130
|
+
rawArguments: string,
|
|
131
|
+
arguments_: readonly string[],
|
|
132
|
+
): string {
|
|
133
|
+
const placeholders = template.match(slashCommandPlaceholderPattern) ?? [];
|
|
134
|
+
let highestPosition = 0;
|
|
135
|
+
for (const placeholder of placeholders) {
|
|
136
|
+
highestPosition = Math.max(highestPosition, Number(placeholder.slice(1)));
|
|
137
|
+
}
|
|
138
|
+
const segments: string[] = [];
|
|
139
|
+
let lastIndex = 0;
|
|
140
|
+
let expandedBytes = 0;
|
|
141
|
+
for (const match of template.matchAll(slashCommandAllPlaceholderPattern)) {
|
|
142
|
+
const literal = template.slice(lastIndex, match.index);
|
|
143
|
+
let replacement: string;
|
|
144
|
+
if (match[0] === '$ARGUMENTS') {
|
|
145
|
+
replacement = rawArguments;
|
|
146
|
+
} else {
|
|
147
|
+
const position = Number(match[1]);
|
|
148
|
+
const argumentIndex = position - 1;
|
|
149
|
+
replacement = argumentIndex < 0 || argumentIndex >= arguments_.length
|
|
150
|
+
? ''
|
|
151
|
+
: position === highestPosition
|
|
152
|
+
? arguments_.slice(argumentIndex).join(' ')
|
|
153
|
+
: arguments_[argumentIndex];
|
|
154
|
+
}
|
|
155
|
+
expandedBytes += Buffer.byteLength(literal, 'utf8') + Buffer.byteLength(replacement, 'utf8');
|
|
156
|
+
if (expandedBytes > FLEX_SLASH_COMMAND_MAX_INPUT_BYTES) {
|
|
157
|
+
throw new FlexHarnessValidationError('Expanded slash command prompt exceeds the input limit.');
|
|
158
|
+
}
|
|
159
|
+
segments.push(literal, replacement);
|
|
160
|
+
lastIndex = match.index + match[0].length;
|
|
161
|
+
}
|
|
162
|
+
segments.push(template.slice(lastIndex));
|
|
163
|
+
expandedBytes += Buffer.byteLength(segments.at(-1)!, 'utf8');
|
|
164
|
+
if (expandedBytes > FLEX_SLASH_COMMAND_MAX_INPUT_BYTES) {
|
|
165
|
+
throw new FlexHarnessValidationError('Expanded slash command prompt exceeds the input limit.');
|
|
166
|
+
}
|
|
167
|
+
let expanded = segments.join('');
|
|
168
|
+
if (placeholders.length === 0 && !template.includes('$ARGUMENTS') && rawArguments.trim()) {
|
|
169
|
+
if (
|
|
170
|
+
expandedBytes + Buffer.byteLength(rawArguments, 'utf8') + 2
|
|
171
|
+
> FLEX_SLASH_COMMAND_MAX_INPUT_BYTES
|
|
172
|
+
) {
|
|
173
|
+
throw new FlexHarnessValidationError('Expanded slash command prompt exceeds the input limit.');
|
|
174
|
+
}
|
|
175
|
+
expanded += `\n\n${rawArguments}`;
|
|
176
|
+
}
|
|
177
|
+
return expanded;
|
|
178
|
+
}
|
|
@@ -4,10 +4,11 @@ import type {
|
|
|
4
4
|
IFlexHarnessStores,
|
|
5
5
|
IFlexMessage,
|
|
6
6
|
IFlexPermissionSnapshot,
|
|
7
|
-
|
|
7
|
+
IFlexProjectionSnapshotCurrent,
|
|
8
8
|
IFlexScopeSnapshot,
|
|
9
9
|
IFlexSession,
|
|
10
10
|
TFlexAgentModelMessage,
|
|
11
|
+
TFlexProjectionSnapshot,
|
|
11
12
|
TJsonValue,
|
|
12
13
|
} from '../ts/interfaces.js';
|
|
13
14
|
import {
|
|
@@ -44,7 +45,7 @@ interface ILegacyRun {
|
|
|
44
45
|
|
|
45
46
|
interface ILegacySessionMigrationPlan {
|
|
46
47
|
sessionId: string;
|
|
47
|
-
projectionSnapshot:
|
|
48
|
+
projectionSnapshot: IFlexProjectionSnapshotCurrent;
|
|
48
49
|
permissionSnapshot: IFlexPermissionSnapshot;
|
|
49
50
|
agentEvents: plugins.TAgentEvent[];
|
|
50
51
|
}
|
|
@@ -56,7 +57,7 @@ interface ILegacyMigrationPlan {
|
|
|
56
57
|
|
|
57
58
|
interface IInspectedSessionDestination {
|
|
58
59
|
plan: ILegacySessionMigrationPlan;
|
|
59
|
-
projection:
|
|
60
|
+
projection: TFlexProjectionSnapshot | undefined;
|
|
60
61
|
permission: IFlexPermissionSnapshot | undefined;
|
|
61
62
|
eventStore: plugins.IAgentEventStoreV2;
|
|
62
63
|
eventSnapshot: plugins.IAgentEventSnapshotV2 | undefined;
|
|
@@ -403,11 +404,15 @@ function createMigrationPlan(
|
|
|
403
404
|
sessions: [stored.session],
|
|
404
405
|
tombstones: [],
|
|
405
406
|
};
|
|
406
|
-
const projectionSnapshot:
|
|
407
|
-
schemaVersion:
|
|
407
|
+
const projectionSnapshot: IFlexProjectionSnapshotCurrent = {
|
|
408
|
+
schemaVersion: 3,
|
|
408
409
|
revision: 1,
|
|
409
410
|
messages: stored.messages,
|
|
410
411
|
stagedTerminals: [],
|
|
412
|
+
reversionSegments: [],
|
|
413
|
+
revertCursor: 0,
|
|
414
|
+
excludedRunIds: [],
|
|
415
|
+
pendingReversionReleases: [],
|
|
411
416
|
};
|
|
412
417
|
const permissionSnapshot: IFlexPermissionSnapshot = {
|
|
413
418
|
schemaVersion: 1,
|