self-evolving-workflow 0.0.0-stage → 0.1.3
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/LICENSE +27 -0
- package/README.md +90 -2
- package/dist/agent-memory-prompts.d.ts +13 -0
- package/dist/agent-memory-prompts.js +55 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +6 -0
- package/dist/closeout.d.ts +105 -0
- package/dist/closeout.js +479 -0
- package/dist/code.d.ts +39 -0
- package/dist/code.js +124 -0
- package/dist/common.d.ts +9 -0
- package/dist/common.js +42 -0
- package/dist/context-envelope.d.ts +59 -0
- package/dist/context-envelope.js +23 -0
- package/dist/host-adapters.d.ts +34 -0
- package/dist/host-adapters.js +151 -0
- package/dist/http.d.ts +3 -0
- package/dist/http.js +90 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +13 -0
- package/dist/knowledge-cli.d.ts +183 -0
- package/dist/knowledge-cli.js +654 -0
- package/dist/knowledge-reads.d.ts +71 -0
- package/dist/knowledge-reads.js +193 -0
- package/dist/memory.d.ts +97 -0
- package/dist/memory.js +250 -0
- package/dist/retrospective.d.ts +57 -0
- package/dist/retrospective.js +248 -0
- package/dist/search.d.ts +36 -0
- package/dist/search.js +112 -0
- package/dist/skill-addition.d.ts +25 -0
- package/dist/skill-addition.js +89 -0
- package/dist/skill-design.d.ts +96 -0
- package/dist/skill-design.js +226 -0
- package/dist/skill-replay.d.ts +55 -0
- package/dist/skill-replay.js +451 -0
- package/dist/skill-route.d.ts +30 -0
- package/dist/skill-route.js +75 -0
- package/dist/transcript-evidence.d.ts +3 -0
- package/dist/transcript-evidence.js +58 -0
- package/dist/upstream/chunker.d.ts +24 -0
- package/dist/upstream/chunker.js +96 -0
- package/dist/upstream/file-protocol.d.ts +45 -0
- package/dist/upstream/file-protocol.js +117 -0
- package/dist/upstream/frontmatter.d.ts +47 -0
- package/dist/upstream/frontmatter.js +86 -0
- package/dist/upstream/graph-search.d.ts +33 -0
- package/dist/upstream/graph-search.js +67 -0
- package/dist/upstream/l1-extraction.d.ts +26 -0
- package/dist/upstream/l1-extraction.js +405 -0
- package/dist/upstream/llm.d.ts +8 -0
- package/dist/upstream/llm.js +1 -0
- package/dist/upstream/merge.d.ts +50 -0
- package/dist/upstream/merge.js +153 -0
- package/dist/upstream/prompts.d.ts +53 -0
- package/dist/upstream/prompts.js +185 -0
- package/dist/upstream/search-utils.d.ts +34 -0
- package/dist/upstream/search-utils.js +55 -0
- package/dist/upstream/slug.d.ts +26 -0
- package/dist/upstream/slug.js +103 -0
- package/dist/upstream/template.d.ts +29 -0
- package/dist/upstream/template.js +80 -0
- package/dist/upstream/tokenize.d.ts +4 -0
- package/dist/upstream/tokenize.js +29 -0
- package/dist/wiki-change.d.ts +76 -0
- package/dist/wiki-change.js +299 -0
- package/dist/wiki-entry.d.ts +26 -0
- package/dist/wiki-entry.js +93 -0
- package/dist/wiki-ingest.d.ts +12 -0
- package/dist/wiki-ingest.js +126 -0
- package/dist/wiki-migration.d.ts +16 -0
- package/dist/wiki-migration.js +268 -0
- package/dist/wiki-tokens.d.ts +1 -0
- package/dist/wiki-tokens.js +46 -0
- package/dist/wiki.d.ts +103 -0
- package/dist/wiki.js +330 -0
- package/dist/workflow-cli.d.ts +2 -0
- package/dist/workflow-cli.js +258 -0
- package/dist/workflow-install.d.ts +36 -0
- package/dist/workflow-install.js +148 -0
- package/dist/workflow-knowledge.d.ts +16 -0
- package/dist/workflow-knowledge.js +24 -0
- package/dist/workflow-mcp.d.ts +2 -0
- package/dist/workflow-mcp.js +144 -0
- package/dist/workflow-names.d.ts +4 -0
- package/dist/workflow-names.js +18 -0
- package/dist/workflow-runtime.d.ts +622 -0
- package/dist/workflow-runtime.js +627 -0
- package/dist/workflow-skills.d.ts +48 -0
- package/dist/workflow-skills.js +141 -0
- package/package.json +76 -4
- package/skills/ew-odyssey/SKILL.md +237 -0
- package/skills/ew-odyssey/references/audit-artifacts.md +7 -0
- package/skills/ew-odyssey/references/odyssey-base-codex.md +3 -0
- package/skills/ew-odyssey/references/odyssey-base.md +278 -0
- package/skills/ew-odyssey/references/odyssey-debug.codex.md +305 -0
- package/skills/ew-odyssey/references/odyssey-debug.md +283 -0
- package/skills/ew-odyssey/references/odyssey-defensive.codex.md +395 -0
- package/skills/ew-odyssey/references/odyssey-defensive.md +369 -0
- package/skills/ew-odyssey/references/odyssey-improve.codex.md +270 -0
- package/skills/ew-odyssey/references/odyssey-improve.md +248 -0
- package/skills/ew-odyssey/references/odyssey-planex.codex.md +352 -0
- package/skills/ew-odyssey/references/odyssey-planex.md +312 -0
- package/skills/ew-odyssey/references/odyssey-review.codex.md +283 -0
- package/skills/ew-odyssey/references/odyssey-review.md +251 -0
- package/skills/ew-odyssey/references/odyssey-security.md +249 -0
- package/skills/ew-odyssey/references/odyssey-ui.codex.md +294 -0
- package/skills/ew-odyssey/references/odyssey-ui.md +250 -0
- package/skills/ew-odyssey/references/prepare/odyssey-debug.md +105 -0
- package/skills/ew-odyssey/references/prepare/odyssey-defensive.md +121 -0
- package/skills/ew-odyssey/references/prepare/odyssey-improve.md +93 -0
- package/skills/ew-odyssey/references/prepare/odyssey-planex.md +104 -0
- package/skills/ew-odyssey/references/prepare/odyssey-review.md +98 -0
- package/skills/ew-odyssey/references/prepare/odyssey-security.md +94 -0
- package/skills/ew-odyssey/references/prepare/odyssey-ui.md +87 -0
- package/skills/ew-orchestrate/SKILL.md +236 -0
- package/skills/ew-orchestrate/references/auto-policy.md +165 -0
- package/skills/ew-orchestrate/references/companion-route.md +52 -0
- package/skills/ew-orchestrate/references/ew-orchestrate.md +27 -0
- package/skills/ew-orchestrate/references/goal.md +53 -0
- package/skills/ew-orchestrate/references/knowledge-route.md +163 -0
- package/skills/ew-orchestrate/references/orchestrator-run-loop.md +36 -0
- package/skills/ew-orchestrate/references/planning.md +137 -0
- package/skills/ew-orchestrate/steps/ew-analyze/SKILL.md +62 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/boundary-grill.md +50 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/issue-gaps-analyze.md +59 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/prepare.md +42 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/workflow.md +401 -0
- package/skills/ew-orchestrate/steps/ew-brainstorm/SKILL.md +32 -0
- package/skills/ew-orchestrate/steps/ew-companion/SKILL.md +9 -0
- package/skills/ew-orchestrate/steps/ew-execute/SKILL.md +71 -0
- package/skills/ew-orchestrate/steps/ew-execute/references/prepare.md +69 -0
- package/skills/ew-orchestrate/steps/ew-execute/references/workflow.md +373 -0
- package/skills/ew-orchestrate/steps/ew-plan/SKILL.md +102 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/boundary-grill.md +50 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/prepare.md +51 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/tdd.md +53 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/workflow.md +278 -0
- package/skills/ew-orchestrate/steps/ew-review/SKILL.md +44 -0
- package/skills/ew-orchestrate/steps/ew-review/references/odyssey-base-codex.md +3 -0
- package/skills/ew-orchestrate/steps/ew-review/references/prepare.md +76 -0
- package/skills/ew-orchestrate/steps/ew-review/references/workflow.md +283 -0
- package/skills/ew-skill-design/SKILL.md +28 -0
- package/skills/ew-skill-design/references/package-contract.md +28 -0
- package/skills/ew-skill-design/references/validation.md +7 -0
- package/skills/team-swarm/SKILL.md +231 -0
- package/skills/team-swarm/references/mcp-coordination.md +10 -0
- package/skills/team-swarm/roles/analyst/role.md +181 -0
- package/skills/team-swarm/roles/ant/role.md +149 -0
- package/skills/team-swarm/roles/coordinator/commands/converge.md +154 -0
- package/skills/team-swarm/roles/coordinator/commands/init-swarm.md +134 -0
- package/skills/team-swarm/roles/coordinator/commands/iterate.md +202 -0
- package/skills/team-swarm/roles/coordinator/role.md +228 -0
- package/skills/team-swarm/roles/scorer/role.md +150 -0
- package/skills/team-swarm/scripts/aco.py +646 -0
- package/skills/team-swarm/scripts/pheromone.py +144 -0
- package/skills/team-swarm/scripts/scoring.py +111 -0
- package/skills/team-swarm/scripts/test_aco.py +606 -0
- package/skills/team-swarm/specs/ant-output-schema.md +127 -0
- package/skills/team-swarm/specs/convergence-criteria.md +108 -0
- package/skills/team-swarm/specs/pheromone-schema.md +125 -0
- package/skills/team-swarm/specs/swarm-config-template.json +71 -0
- package/skills/team-swarm/specs/swarm-protocol.md +123 -0
- package/skills/workflow-closeout/SKILL.md +10 -0
- package/skills/workflow-evolve/SKILL.md +79 -0
- package/skills/workflow-evolve/references/agy-gate.md +27 -0
- package/skills/workflow-evolve/references/auto-loop.md +20 -0
- package/skills/workflow-evolve/references/history-review.md +14 -0
- package/skills/workflow-evolve/scripts/codex-memory-replay.mjs +76 -0
- package/skills/workflow-evolve/scripts/codex-replay.mjs +1 -0
- package/skills/workflow-evolve/scripts/evolve-loop.mjs +259 -0
- package/skills/workflow-evolve/scripts/memory-codex-mcp.mjs +124 -0
- package/workflows/index.json +23 -0
package/dist/common.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
export class InputError extends Error {
|
|
3
|
+
}
|
|
4
|
+
export class NotFoundError extends Error {
|
|
5
|
+
}
|
|
6
|
+
export function requireText(value, label) {
|
|
7
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
8
|
+
throw new InputError(`${label} must be a non-empty string`);
|
|
9
|
+
}
|
|
10
|
+
return value.trim();
|
|
11
|
+
}
|
|
12
|
+
export function searchLimit(limit = 10) {
|
|
13
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) {
|
|
14
|
+
throw new InputError('limit must be an integer between 1 and 100');
|
|
15
|
+
}
|
|
16
|
+
return limit;
|
|
17
|
+
}
|
|
18
|
+
export function openDb(path, readOnly = false) {
|
|
19
|
+
const db = new DatabaseSync(path, { readOnly });
|
|
20
|
+
try {
|
|
21
|
+
db.exec('PRAGMA busy_timeout = 5000');
|
|
22
|
+
if (!readOnly)
|
|
23
|
+
db.exec('PRAGMA journal_mode = WAL');
|
|
24
|
+
return db;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
db.close();
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function transaction(db, run) {
|
|
32
|
+
db.exec('BEGIN IMMEDIATE');
|
|
33
|
+
try {
|
|
34
|
+
const result = run();
|
|
35
|
+
db.exec('COMMIT');
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
db.exec('ROLLBACK');
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare const AGENT_MEMORY_ENVELOPE_VERSION = "agent-memory-envelope/1.0";
|
|
2
|
+
export declare const AGENT_MEMORY_TRUST_BOUNDARY = "untrusted_evidence_data_only";
|
|
3
|
+
export declare const AGENT_MEMORY_CONTEXT_LEVEL = "L3";
|
|
4
|
+
export type MemoryAuthority = 'binding' | 'advisory' | 'unverified_episodic';
|
|
5
|
+
export interface AgentMemoryContextScope {
|
|
6
|
+
repository_id?: string;
|
|
7
|
+
session_id?: string;
|
|
8
|
+
run_id?: string;
|
|
9
|
+
task_kind?: string;
|
|
10
|
+
paths?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface AgentMemoryConstraint {
|
|
13
|
+
knowledge_id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
mode: 'constraint';
|
|
16
|
+
authority: 'binding';
|
|
17
|
+
scope: string[];
|
|
18
|
+
categories?: string[];
|
|
19
|
+
content: string;
|
|
20
|
+
content_sha256?: string;
|
|
21
|
+
sources?: string[];
|
|
22
|
+
source_count?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface AgentMemoryReference {
|
|
25
|
+
knowledge_id: string;
|
|
26
|
+
title: string;
|
|
27
|
+
mode: 'reference';
|
|
28
|
+
authority: 'advisory';
|
|
29
|
+
score: number;
|
|
30
|
+
hop: number;
|
|
31
|
+
snippet: string;
|
|
32
|
+
sources: string[];
|
|
33
|
+
related_knowledge_ids: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface AgentMemoryWorkingMemory {
|
|
36
|
+
memory_id: string;
|
|
37
|
+
session_id: string;
|
|
38
|
+
type: string;
|
|
39
|
+
authority: 'unverified_episodic';
|
|
40
|
+
content: string;
|
|
41
|
+
source_ids: string[];
|
|
42
|
+
linked_knowledge_id?: string | null;
|
|
43
|
+
}
|
|
44
|
+
export interface AgentMemoryEnvelope {
|
|
45
|
+
schema_version: typeof AGENT_MEMORY_ENVELOPE_VERSION;
|
|
46
|
+
trust_boundary: typeof AGENT_MEMORY_TRUST_BOUNDARY;
|
|
47
|
+
memory_level: typeof AGENT_MEMORY_CONTEXT_LEVEL;
|
|
48
|
+
context_scope: AgentMemoryContextScope;
|
|
49
|
+
constraints: AgentMemoryConstraint[];
|
|
50
|
+
references: AgentMemoryReference[];
|
|
51
|
+
working_memories: AgentMemoryWorkingMemory[];
|
|
52
|
+
}
|
|
53
|
+
export interface AgentMemoryEnvelopeInput {
|
|
54
|
+
contextScope?: AgentMemoryContextScope;
|
|
55
|
+
constraints?: AgentMemoryConstraint[];
|
|
56
|
+
references?: AgentMemoryReference[];
|
|
57
|
+
workingMemories?: AgentMemoryWorkingMemory[];
|
|
58
|
+
}
|
|
59
|
+
export declare function createAgentMemoryEnvelope(input?: AgentMemoryEnvelopeInput): AgentMemoryEnvelope;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const AGENT_MEMORY_ENVELOPE_VERSION = 'agent-memory-envelope/1.0';
|
|
2
|
+
export const AGENT_MEMORY_TRUST_BOUNDARY = 'untrusted_evidence_data_only';
|
|
3
|
+
export const AGENT_MEMORY_CONTEXT_LEVEL = 'L3';
|
|
4
|
+
function paths(values) {
|
|
5
|
+
if (!values?.length)
|
|
6
|
+
return undefined;
|
|
7
|
+
return [...new Set(values.map(value => value.trim()).filter(Boolean))];
|
|
8
|
+
}
|
|
9
|
+
export function createAgentMemoryEnvelope(input = {}) {
|
|
10
|
+
const contextScope = input.contextScope ?? {};
|
|
11
|
+
return {
|
|
12
|
+
schema_version: AGENT_MEMORY_ENVELOPE_VERSION,
|
|
13
|
+
trust_boundary: AGENT_MEMORY_TRUST_BOUNDARY,
|
|
14
|
+
memory_level: AGENT_MEMORY_CONTEXT_LEVEL,
|
|
15
|
+
context_scope: {
|
|
16
|
+
...contextScope,
|
|
17
|
+
...(paths(contextScope.paths) ? { paths: paths(contextScope.paths) } : {}),
|
|
18
|
+
},
|
|
19
|
+
constraints: [...(input.constraints ?? [])],
|
|
20
|
+
references: [...(input.references ?? [])],
|
|
21
|
+
working_memories: [...(input.workingMemories ?? [])],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ConversationMessage } from './memory.js';
|
|
2
|
+
export type HostKind = 'codex' | 'agy' | 'claude';
|
|
3
|
+
export interface HostTranscriptAdapter {
|
|
4
|
+
kind: HostKind;
|
|
5
|
+
parse(value: unknown, index: number, capturedAt: string): ConversationMessage | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface HostTranscriptCapture {
|
|
8
|
+
host_kind: HostKind;
|
|
9
|
+
host_session_id: string;
|
|
10
|
+
messages: ConversationMessage[];
|
|
11
|
+
snapshots: TranscriptEvidenceSnapshot[];
|
|
12
|
+
refs: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface TranscriptEvidenceSnapshot {
|
|
15
|
+
schema_version: 'transcript-evidence/1.0';
|
|
16
|
+
sha256: string;
|
|
17
|
+
normalized_sha256: string;
|
|
18
|
+
host_kind: HostKind;
|
|
19
|
+
host_session_id: string;
|
|
20
|
+
entry_id: string;
|
|
21
|
+
quote: string;
|
|
22
|
+
captured_at: string;
|
|
23
|
+
file_name: string;
|
|
24
|
+
ref: string;
|
|
25
|
+
}
|
|
26
|
+
export declare const hostTranscriptAdapters: Record<HostKind, HostTranscriptAdapter>;
|
|
27
|
+
export declare function isHostKind(value: unknown): value is HostKind;
|
|
28
|
+
export declare function captureHostTranscript(input: {
|
|
29
|
+
hostKind: HostKind;
|
|
30
|
+
session: string;
|
|
31
|
+
source: string;
|
|
32
|
+
capturedAt?: string;
|
|
33
|
+
}): HostTranscriptCapture;
|
|
34
|
+
export declare function writeHostTranscriptEvidence(directory: string, capture: HostTranscriptCapture): string[];
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { InputError, requireText } from './common.js';
|
|
5
|
+
function object(value) {
|
|
6
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
7
|
+
}
|
|
8
|
+
function text(value) {
|
|
9
|
+
if (typeof value === 'string' && value.trim())
|
|
10
|
+
return value.trim();
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
const parts = value.map(text).filter((part) => Boolean(part));
|
|
13
|
+
return parts.length ? parts.join('\n') : undefined;
|
|
14
|
+
}
|
|
15
|
+
const record = object(value);
|
|
16
|
+
if (!record)
|
|
17
|
+
return undefined;
|
|
18
|
+
for (const key of ['text', 'value', 'output_text', 'content']) {
|
|
19
|
+
const valueText = text(record[key]);
|
|
20
|
+
if (valueText)
|
|
21
|
+
return valueText;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
function nestedRecord(value) {
|
|
26
|
+
for (const key of ['message', 'item', 'event']) {
|
|
27
|
+
const nested = object(value[key]);
|
|
28
|
+
if (nested)
|
|
29
|
+
return { ...value, ...nested };
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
function role(value) {
|
|
34
|
+
const candidate = value.role;
|
|
35
|
+
if (candidate === 'user' || candidate === 'assistant' || candidate === 'system' || candidate === 'tool') {
|
|
36
|
+
return candidate;
|
|
37
|
+
}
|
|
38
|
+
const type = typeof value.type === 'string' ? value.type.toLowerCase() : '';
|
|
39
|
+
if (type.includes('user'))
|
|
40
|
+
return 'user';
|
|
41
|
+
if (type.includes('assistant') || type.includes('response'))
|
|
42
|
+
return 'assistant';
|
|
43
|
+
return 'tool';
|
|
44
|
+
}
|
|
45
|
+
function safePart(value, label) {
|
|
46
|
+
const textValue = requireText(value, label);
|
|
47
|
+
if (/[:\p{Cc}]/u.test(textValue))
|
|
48
|
+
throw new InputError(`${label} contains a colon or control character`);
|
|
49
|
+
return textValue;
|
|
50
|
+
}
|
|
51
|
+
function parseHostMessage(value, kind, index, capturedAt) {
|
|
52
|
+
const record = object(value);
|
|
53
|
+
if (!record)
|
|
54
|
+
return undefined;
|
|
55
|
+
const merged = nestedRecord(record);
|
|
56
|
+
const content = text(merged.content ?? merged.text ?? merged.output_text);
|
|
57
|
+
if (!content)
|
|
58
|
+
return undefined;
|
|
59
|
+
const rawId = merged.id ?? merged.message_id ?? `${kind}-${index + 1}`;
|
|
60
|
+
const id = safePart(String(rawId).replace(/[:\p{Cc}]/gu, '-'), 'transcript entry ID');
|
|
61
|
+
const timestamp = typeof merged.timestamp === 'string' || typeof merged.timestamp === 'number'
|
|
62
|
+
? merged.timestamp : capturedAt;
|
|
63
|
+
return {
|
|
64
|
+
id,
|
|
65
|
+
role: role(merged),
|
|
66
|
+
timestamp,
|
|
67
|
+
content,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function adapter(kind) {
|
|
71
|
+
return { kind, parse: (value, index, capturedAt) => parseHostMessage(value, kind, index, capturedAt) };
|
|
72
|
+
}
|
|
73
|
+
export const hostTranscriptAdapters = {
|
|
74
|
+
codex: adapter('codex'),
|
|
75
|
+
agy: adapter('agy'),
|
|
76
|
+
claude: adapter('claude'),
|
|
77
|
+
};
|
|
78
|
+
export function isHostKind(value) {
|
|
79
|
+
return value === 'codex' || value === 'agy' || value === 'claude';
|
|
80
|
+
}
|
|
81
|
+
function locatorHash(hostKind, session, entry) {
|
|
82
|
+
return createHash('sha256').update([hostKind, session, entry].join('\0')).digest('hex').slice(0, 16);
|
|
83
|
+
}
|
|
84
|
+
function snapshotFor(hostKind, session, message, capturedAt) {
|
|
85
|
+
const quote = requireText(message.content, 'transcript quote');
|
|
86
|
+
const sha256 = createHash('sha256').update(quote).digest('hex');
|
|
87
|
+
const suffix = locatorHash(hostKind, session, message.id);
|
|
88
|
+
return {
|
|
89
|
+
schema_version: 'transcript-evidence/1.0',
|
|
90
|
+
sha256,
|
|
91
|
+
normalized_sha256: sha256,
|
|
92
|
+
host_kind: hostKind,
|
|
93
|
+
host_session_id: session,
|
|
94
|
+
entry_id: message.id,
|
|
95
|
+
quote,
|
|
96
|
+
captured_at: capturedAt,
|
|
97
|
+
file_name: `${sha256}-${suffix}.json`,
|
|
98
|
+
ref: `transcript:${hostKind}:${session}:${message.id}:${sha256.slice(0, 16)}`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export function captureHostTranscript(input) {
|
|
102
|
+
const adapter = hostTranscriptAdapters[input.hostKind];
|
|
103
|
+
const session = safePart(input.session, 'host session');
|
|
104
|
+
const capturedAt = input.capturedAt ?? new Date().toISOString();
|
|
105
|
+
const messages = [];
|
|
106
|
+
const lines = readFileSync(input.source, 'utf8').split(/\r?\n/);
|
|
107
|
+
for (const [index, line] of lines.entries()) {
|
|
108
|
+
if (!line.trim())
|
|
109
|
+
continue;
|
|
110
|
+
let value;
|
|
111
|
+
try {
|
|
112
|
+
value = JSON.parse(line);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
throw new InputError(`Invalid ${input.hostKind} transcript JSON at line ${index + 1}: ${error instanceof Error ? error.message : String(error)}`);
|
|
116
|
+
}
|
|
117
|
+
const message = adapter.parse(value, index, capturedAt);
|
|
118
|
+
if (message)
|
|
119
|
+
messages.push(message);
|
|
120
|
+
}
|
|
121
|
+
const ids = new Set(messages.map(message => message.id));
|
|
122
|
+
if (ids.size !== messages.length)
|
|
123
|
+
throw new InputError(`Duplicate ${input.hostKind} transcript entry ID`);
|
|
124
|
+
const snapshots = messages.map(message => snapshotFor(input.hostKind, session, message, capturedAt));
|
|
125
|
+
return { host_kind: input.hostKind, host_session_id: session, messages, snapshots, refs: snapshots.map(snapshot => snapshot.ref) };
|
|
126
|
+
}
|
|
127
|
+
export function writeHostTranscriptEvidence(directory, capture) {
|
|
128
|
+
mkdirSync(directory, { recursive: true });
|
|
129
|
+
const paths = [];
|
|
130
|
+
for (const snapshot of capture.snapshots) {
|
|
131
|
+
const target = join(directory, snapshot.file_name);
|
|
132
|
+
const temporary = join(dirname(target), `.${randomUUID()}.tmp`);
|
|
133
|
+
const { file_name: _fileName, ref: _ref, ...payload } = snapshot;
|
|
134
|
+
const serialized = `${JSON.stringify(payload)}\n`;
|
|
135
|
+
if (existsSync(target)) {
|
|
136
|
+
if (readFileSync(target, 'utf8') !== serialized)
|
|
137
|
+
throw new InputError(`Transcript evidence changed: ${snapshot.file_name}`);
|
|
138
|
+
paths.push(target);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
writeFileSync(temporary, serialized, { flag: 'wx' });
|
|
143
|
+
renameSync(temporary, target);
|
|
144
|
+
paths.push(target);
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
rmSync(temporary, { force: true });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return paths;
|
|
151
|
+
}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type SearchSources } from './search.js';
|
|
2
|
+
/** GET /search or /context with q, scope, limit and optional Wiki/Memory filters. */
|
|
3
|
+
export declare function createSearchServer(sources: SearchSources): import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { InputError, NotFoundError } from './common.js';
|
|
3
|
+
import { context as buildContext, parseScope, search } from './search.js';
|
|
4
|
+
import { isRepositoryId, isWikiCategory } from './wiki-entry.js';
|
|
5
|
+
import { KnowledgeReads } from './knowledge-reads.js';
|
|
6
|
+
/** GET /search or /context with q, scope, limit and optional Wiki/Memory filters. */
|
|
7
|
+
export function createSearchServer(sources) {
|
|
8
|
+
const server = createServer(async (request, response) => {
|
|
9
|
+
response.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
10
|
+
response.setHeader('Cache-Control', 'no-store');
|
|
11
|
+
const send = (status, payload) => {
|
|
12
|
+
response.writeHead(status);
|
|
13
|
+
response.end(JSON.stringify(payload));
|
|
14
|
+
};
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL(request.url ?? '/', 'http://localhost');
|
|
17
|
+
if (url.pathname !== '/search' && url.pathname !== '/context')
|
|
18
|
+
return send(404, { error: 'Route not found' });
|
|
19
|
+
if (request.method !== 'GET') {
|
|
20
|
+
response.setHeader('Allow', 'GET');
|
|
21
|
+
return send(405, { error: 'Use GET /search or /context' });
|
|
22
|
+
}
|
|
23
|
+
const params = url.searchParams;
|
|
24
|
+
const scope = parseScope(params.get('scope') ?? 'all');
|
|
25
|
+
const limit = params.has('limit') ? Number(params.get('limit')) : undefined;
|
|
26
|
+
const knowledgeReads = params.get('trace') === 'true' || params.get('trace') === '1' ? new KnowledgeReads() : undefined;
|
|
27
|
+
const withTrace = (payload) => {
|
|
28
|
+
if (!knowledgeReads)
|
|
29
|
+
return payload;
|
|
30
|
+
return payload && typeof payload === 'object' && !Array.isArray(payload)
|
|
31
|
+
? { ...payload, knowledge_reads: knowledgeReads.toJSON() }
|
|
32
|
+
: { result: payload, knowledge_reads: knowledgeReads.toJSON() };
|
|
33
|
+
};
|
|
34
|
+
const categories = params.getAll('category');
|
|
35
|
+
const validCategories = categories.filter(isWikiCategory);
|
|
36
|
+
if (validCategories.length !== categories.length)
|
|
37
|
+
throw new InputError('Unknown Wiki context category');
|
|
38
|
+
const repository = params.get('repository') ?? undefined;
|
|
39
|
+
if (repository !== undefined && !isRepositoryId(repository))
|
|
40
|
+
throw new InputError('Expected a persisted repository UUID');
|
|
41
|
+
if (url.pathname === '/context') {
|
|
42
|
+
return send(200, withTrace(await buildContext(sources, params.get('q') ?? '', {
|
|
43
|
+
limit,
|
|
44
|
+
context: {
|
|
45
|
+
task: params.get('task') ?? undefined,
|
|
46
|
+
paths: params.getAll('path'),
|
|
47
|
+
categories: validCategories.length ? validCategories : undefined,
|
|
48
|
+
repository,
|
|
49
|
+
keyword: params.get('keyword') ?? undefined,
|
|
50
|
+
includePathScoped: params.get('include_path_scoped') === 'true' || params.get('include_path_scoped') === '1',
|
|
51
|
+
},
|
|
52
|
+
wiki: { hop: params.has('hop') ? Number(params.get('hop')) : undefined },
|
|
53
|
+
memory: {
|
|
54
|
+
type: params.get('type') ?? undefined,
|
|
55
|
+
scene: params.get('scene') ?? undefined,
|
|
56
|
+
session: params.get('memory_session') ?? undefined,
|
|
57
|
+
},
|
|
58
|
+
includeWorkingMemory: params.get('include_memory') === 'true' || params.get('include_memory') === '1',
|
|
59
|
+
knowledgeReads,
|
|
60
|
+
contextScope: {
|
|
61
|
+
...(params.get('session') ? { session_id: params.get('session') } : {}),
|
|
62
|
+
...(params.get('task') ? { task_kind: params.get('task') } : {}),
|
|
63
|
+
...(params.getAll('path').length ? { paths: params.getAll('path') } : {}),
|
|
64
|
+
},
|
|
65
|
+
})));
|
|
66
|
+
}
|
|
67
|
+
const results = await search(sources, params.get('q') ?? '', {
|
|
68
|
+
scope,
|
|
69
|
+
limit,
|
|
70
|
+
wiki: { hop: params.has('hop') ? Number(params.get('hop')) : undefined },
|
|
71
|
+
memory: {
|
|
72
|
+
type: params.get('type') ?? undefined,
|
|
73
|
+
scene: params.get('scene') ?? undefined,
|
|
74
|
+
session: params.get('session') ?? undefined,
|
|
75
|
+
},
|
|
76
|
+
knowledgeReads,
|
|
77
|
+
});
|
|
78
|
+
send(200, withTrace(results));
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error instanceof InputError)
|
|
82
|
+
return send(400, { error: error.message });
|
|
83
|
+
if (error instanceof NotFoundError)
|
|
84
|
+
return send(404, { error: error.message });
|
|
85
|
+
send(500, { error: 'Search failed' });
|
|
86
|
+
server.emit('searchError', error);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return server;
|
|
90
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { CodeGraph } from './code.js';
|
|
2
|
+
export { AGENT_MEMORY_ENVELOPE_VERSION, AGENT_MEMORY_CONTEXT_LEVEL, AGENT_MEMORY_TRUST_BOUNDARY, createAgentMemoryEnvelope, type AgentMemoryConstraint, type AgentMemoryContextScope, type AgentMemoryEnvelope, type AgentMemoryEnvelopeInput, type AgentMemoryReference, type AgentMemoryWorkingMemory, type MemoryAuthority, } from './context-envelope.js';
|
|
3
|
+
export { AGENT_MEMORY_PROMPT_VERSION, buildCloseoutHarvestPrompt, buildSessionSignalPrompt, buildWikiMergePrompt, buildWikiRelationPrompt, createAgentMemoryPrompt, type AgentMemoryPrompt, type AgentMemoryPromptKind, } from './agent-memory-prompts.js';
|
|
4
|
+
export { Wiki, type WikiHit, type WikiReadOptions, type WikiSearchOptions } from './wiki.js';
|
|
5
|
+
export type { WikiContext, WikiEntryMetadata } from './wiki-entry.js';
|
|
6
|
+
export { reviewSession, reviewSkillExecution, type ReviewedRun, type SkillSignal } from './retrospective.js';
|
|
7
|
+
export { draftSkillAddition, type SkillPriority } from './skill-addition.js';
|
|
8
|
+
export { decideSkillRoute, type SkillRetentionRoute, type SkillRouteContext, type SkillRouteDecision } from './skill-route.js';
|
|
9
|
+
export { applySkillDesign, createSkillDesignTask, readSkillDesignTask, replaySkillDesign, reviewSkillDesign, runSkillDesign, type SkillDesignReceipt, type SkillDesignTask, } from './skill-design.js';
|
|
10
|
+
export type { WikiIngestOptions } from './wiki-ingest.js';
|
|
11
|
+
export { MemoryStore, type MemoryInput, type MemoryRecord, type MemorySearchOptions, type MemoryStoreOptions, type ConversationMessage } from './memory.js';
|
|
12
|
+
export { context, search, type ContextOptions, type SearchSources, type SearchScope, type SearchOptions, type SearchResults, } from './search.js';
|
|
13
|
+
export { createSearchServer } from './http.js';
|
|
14
|
+
export { KNOWLEDGE_READS_VERSION, KnowledgeReads, contentSha256, validateKnowledgeReads, type KnowledgeConstraintInput, type KnowledgeConstraintRecord, type KnowledgeReadInput, type KnowledgeReadKind, type KnowledgeReadRecord, type KnowledgeReadsReceipt, type KnowledgeSearchInput, type KnowledgeSearchRecord, type KnowledgeSearchSource, } from './knowledge-reads.js';
|
|
15
|
+
export { InputError, NotFoundError } from './common.js';
|
|
16
|
+
export type { LlmClient, ChatParams } from './upstream/llm.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { CodeGraph } from './code.js';
|
|
2
|
+
export { AGENT_MEMORY_ENVELOPE_VERSION, AGENT_MEMORY_CONTEXT_LEVEL, AGENT_MEMORY_TRUST_BOUNDARY, createAgentMemoryEnvelope, } from './context-envelope.js';
|
|
3
|
+
export { AGENT_MEMORY_PROMPT_VERSION, buildCloseoutHarvestPrompt, buildSessionSignalPrompt, buildWikiMergePrompt, buildWikiRelationPrompt, createAgentMemoryPrompt, } from './agent-memory-prompts.js';
|
|
4
|
+
export { Wiki } from './wiki.js';
|
|
5
|
+
export { reviewSession, reviewSkillExecution } from './retrospective.js';
|
|
6
|
+
export { draftSkillAddition } from './skill-addition.js';
|
|
7
|
+
export { decideSkillRoute } from './skill-route.js';
|
|
8
|
+
export { applySkillDesign, createSkillDesignTask, readSkillDesignTask, replaySkillDesign, reviewSkillDesign, runSkillDesign, } from './skill-design.js';
|
|
9
|
+
export { MemoryStore } from './memory.js';
|
|
10
|
+
export { context, search, } from './search.js';
|
|
11
|
+
export { createSearchServer } from './http.js';
|
|
12
|
+
export { KNOWLEDGE_READS_VERSION, KnowledgeReads, contentSha256, validateKnowledgeReads, } from './knowledge-reads.js';
|
|
13
|
+
export { InputError, NotFoundError } from './common.js';
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
export declare function knowledgeHelp(invocation: 'agent-memory' | 'evolve'): string;
|
|
2
|
+
export declare const knowledgeOptions: {
|
|
3
|
+
readonly root: {
|
|
4
|
+
readonly type: "string";
|
|
5
|
+
};
|
|
6
|
+
readonly 'wiki-root': {
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
};
|
|
9
|
+
readonly db: {
|
|
10
|
+
readonly type: "string";
|
|
11
|
+
};
|
|
12
|
+
readonly namespace: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
};
|
|
15
|
+
readonly scope: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
};
|
|
18
|
+
readonly limit: {
|
|
19
|
+
readonly type: "string";
|
|
20
|
+
};
|
|
21
|
+
readonly depth: {
|
|
22
|
+
readonly type: "string";
|
|
23
|
+
};
|
|
24
|
+
readonly hop: {
|
|
25
|
+
readonly type: "string";
|
|
26
|
+
};
|
|
27
|
+
readonly type: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
};
|
|
30
|
+
readonly scene: {
|
|
31
|
+
readonly type: "string";
|
|
32
|
+
};
|
|
33
|
+
readonly session: {
|
|
34
|
+
readonly type: "string";
|
|
35
|
+
};
|
|
36
|
+
readonly 'memory-session': {
|
|
37
|
+
readonly type: "string";
|
|
38
|
+
};
|
|
39
|
+
readonly 'context-file': {
|
|
40
|
+
readonly type: "string";
|
|
41
|
+
};
|
|
42
|
+
readonly id: {
|
|
43
|
+
readonly type: "string";
|
|
44
|
+
};
|
|
45
|
+
readonly priority: {
|
|
46
|
+
readonly type: "string";
|
|
47
|
+
};
|
|
48
|
+
readonly port: {
|
|
49
|
+
readonly type: "string";
|
|
50
|
+
};
|
|
51
|
+
readonly mode: {
|
|
52
|
+
readonly type: "string";
|
|
53
|
+
};
|
|
54
|
+
readonly skill: {
|
|
55
|
+
readonly type: "string";
|
|
56
|
+
};
|
|
57
|
+
readonly task: {
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
};
|
|
60
|
+
readonly category: {
|
|
61
|
+
readonly type: "string";
|
|
62
|
+
readonly multiple: true;
|
|
63
|
+
};
|
|
64
|
+
readonly keyword: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
};
|
|
67
|
+
readonly repository: {
|
|
68
|
+
readonly type: "string";
|
|
69
|
+
};
|
|
70
|
+
readonly 'include-path-scoped': {
|
|
71
|
+
readonly type: "boolean";
|
|
72
|
+
};
|
|
73
|
+
readonly 'include-memory': {
|
|
74
|
+
readonly type: "boolean";
|
|
75
|
+
};
|
|
76
|
+
readonly trace: {
|
|
77
|
+
readonly type: "boolean";
|
|
78
|
+
};
|
|
79
|
+
readonly 'trace-file': {
|
|
80
|
+
readonly type: "string";
|
|
81
|
+
};
|
|
82
|
+
readonly reads: {
|
|
83
|
+
readonly type: "string";
|
|
84
|
+
};
|
|
85
|
+
readonly 'from-search': {
|
|
86
|
+
readonly type: "string";
|
|
87
|
+
};
|
|
88
|
+
readonly resolved: {
|
|
89
|
+
readonly type: "boolean";
|
|
90
|
+
};
|
|
91
|
+
readonly path: {
|
|
92
|
+
readonly type: "string";
|
|
93
|
+
readonly multiple: true;
|
|
94
|
+
};
|
|
95
|
+
readonly history: {
|
|
96
|
+
readonly type: "boolean";
|
|
97
|
+
};
|
|
98
|
+
readonly project: {
|
|
99
|
+
readonly type: "string";
|
|
100
|
+
};
|
|
101
|
+
readonly uid: {
|
|
102
|
+
readonly type: "string";
|
|
103
|
+
};
|
|
104
|
+
readonly 'knowhow-only': {
|
|
105
|
+
readonly type: "boolean";
|
|
106
|
+
};
|
|
107
|
+
readonly apply: {
|
|
108
|
+
readonly type: "boolean";
|
|
109
|
+
};
|
|
110
|
+
readonly transcript: {
|
|
111
|
+
readonly type: "string";
|
|
112
|
+
};
|
|
113
|
+
readonly 'knowledge-receipt': {
|
|
114
|
+
readonly type: "string";
|
|
115
|
+
};
|
|
116
|
+
readonly receipt: {
|
|
117
|
+
readonly type: "string";
|
|
118
|
+
};
|
|
119
|
+
readonly 'skill-version': {
|
|
120
|
+
readonly type: "string";
|
|
121
|
+
};
|
|
122
|
+
readonly 'repeat-count': {
|
|
123
|
+
readonly type: "string";
|
|
124
|
+
};
|
|
125
|
+
readonly 'step-count': {
|
|
126
|
+
readonly type: "string";
|
|
127
|
+
};
|
|
128
|
+
readonly 'signal-kind': {
|
|
129
|
+
readonly type: "string";
|
|
130
|
+
readonly multiple: true;
|
|
131
|
+
};
|
|
132
|
+
readonly 'cross-skill': {
|
|
133
|
+
readonly type: "boolean";
|
|
134
|
+
};
|
|
135
|
+
readonly 'new-contract': {
|
|
136
|
+
readonly type: "boolean";
|
|
137
|
+
};
|
|
138
|
+
readonly 'new-artifacts': {
|
|
139
|
+
readonly type: "boolean";
|
|
140
|
+
};
|
|
141
|
+
readonly 'requires-routing': {
|
|
142
|
+
readonly type: "boolean";
|
|
143
|
+
};
|
|
144
|
+
readonly 'skill-intent': {
|
|
145
|
+
readonly type: "boolean";
|
|
146
|
+
};
|
|
147
|
+
readonly status: {
|
|
148
|
+
readonly type: "string";
|
|
149
|
+
};
|
|
150
|
+
readonly 'record-only': {
|
|
151
|
+
readonly type: "boolean";
|
|
152
|
+
};
|
|
153
|
+
readonly evidence: {
|
|
154
|
+
readonly type: "string";
|
|
155
|
+
readonly multiple: true;
|
|
156
|
+
};
|
|
157
|
+
readonly entry: {
|
|
158
|
+
readonly type: "string";
|
|
159
|
+
};
|
|
160
|
+
readonly closeout: {
|
|
161
|
+
readonly type: "string";
|
|
162
|
+
};
|
|
163
|
+
readonly candidate: {
|
|
164
|
+
readonly type: "string";
|
|
165
|
+
};
|
|
166
|
+
readonly when: {
|
|
167
|
+
readonly type: "string";
|
|
168
|
+
};
|
|
169
|
+
readonly runner: {
|
|
170
|
+
readonly type: "string";
|
|
171
|
+
};
|
|
172
|
+
readonly scenarios: {
|
|
173
|
+
readonly type: "string";
|
|
174
|
+
};
|
|
175
|
+
readonly help: {
|
|
176
|
+
readonly type: "boolean";
|
|
177
|
+
readonly short: "h";
|
|
178
|
+
};
|
|
179
|
+
readonly json: {
|
|
180
|
+
readonly type: "boolean";
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
export declare function runKnowledgeCli(argv: string[], invocation?: 'agent-memory' | 'evolve'): Promise<boolean | undefined>;
|