tribunal-kit 5.8.4 → 6.0.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/.agent/ARCHITECTURE.md +219 -215
- package/.agent/agents/accessibility-reviewer.md +66 -151
- package/.agent/agents/ai-code-reviewer.md +22 -2
- package/.agent/agents/anti-pattern-reviewer.md +99 -0
- package/.agent/agents/api-architect.md +19 -2
- package/.agent/agents/backend-specialist.md +25 -3
- package/.agent/agents/cloud-engineer.md +21 -0
- package/.agent/agents/code-archaeologist.md +20 -3
- package/.agent/agents/complexity-reviewer.md +22 -2
- package/.agent/agents/database-architect.md +24 -3
- package/.agent/agents/db-latency-auditor.md +22 -2
- package/.agent/agents/debugger.md +19 -3
- package/.agent/agents/dependency-reviewer.md +19 -2
- package/.agent/agents/devops-engineer.md +24 -3
- package/.agent/agents/documentation-writer.md +21 -3
- package/.agent/agents/explorer-agent.md +21 -3
- package/.agent/agents/frontend-reviewer.md +19 -3
- package/.agent/agents/frontend-specialist.md +72 -224
- package/.agent/agents/game-developer.md +22 -3
- package/.agent/agents/interaction-reviewer.md +118 -0
- package/.agent/agents/logic-reviewer.md +18 -3
- package/.agent/agents/minimalist-reviewer.md +98 -0
- package/.agent/agents/mobile-developer.md +21 -3
- package/.agent/agents/mobile-reviewer.md +22 -2
- package/.agent/agents/orchestrator.md +19 -3
- package/.agent/agents/penetration-tester.md +22 -3
- package/.agent/agents/performance-optimizer.md +21 -3
- package/.agent/agents/performance-reviewer.md +2 -0
- package/.agent/agents/precedence-reviewer.md +19 -5
- package/.agent/agents/product-manager.md +20 -3
- package/.agent/agents/product-owner.md +22 -1
- package/.agent/agents/product-reviewer.md +98 -0
- package/.agent/agents/project-planner.md +19 -3
- package/.agent/agents/qa-automation-engineer.md +24 -3
- package/.agent/agents/resilience-reviewer.md +21 -2
- package/.agent/agents/schema-reviewer.md +21 -2
- package/.agent/agents/security-auditor.md +7 -1
- package/.agent/agents/seo-specialist.md +18 -3
- package/.agent/agents/sql-reviewer.md +22 -2
- package/.agent/agents/supervisor-agent.md +22 -3
- package/.agent/agents/swarm-worker-registry.md +7 -0
- package/.agent/agents/system-architect.md +19 -0
- package/.agent/agents/test-coverage-reviewer.md +22 -2
- package/.agent/agents/test-engineer.md +21 -2
- package/.agent/agents/throughput-optimizer.md +22 -2
- package/.agent/agents/type-safety-reviewer.md +21 -2
- package/.agent/agents/ui-ux-auditor.md +44 -242
- package/.agent/agents/ui-visual-auditor.md +99 -0
- package/.agent/agents/ux-reviewer.md +104 -0
- package/.agent/agents/visual-reviewer.md +98 -0
- package/.agent/agents/vitals-reviewer.md +23 -2
- package/.agent/history/README.md +53 -0
- package/.agent/history/case-law/cases/template-case.json +19 -0
- package/.agent/history/integrity_manifest.json +131 -33
- package/.agent/history/memory/.memory.idx +1581 -1
- package/.agent/history/memory/MEMORY.md +105 -1
- package/.agent/routing_index.json +272 -690
- package/.agent/rules/GEMINI.md +10 -12
- package/.agent/rules/GEMINI_PLANNER.md +84 -0
- package/.agent/scripts/_utils.js +28 -7
- package/.agent/scripts/case_law_manager.js +2 -0
- package/.agent/scripts/context_broker.js +152 -19
- package/.agent/scripts/guardrail_engine.js +60 -5
- package/.agent/scripts/impact_classifier.js +167 -0
- package/.agent/scripts/integrity_manifest.js +10 -4
- package/.agent/scripts/marathon_harness.js +10 -1
- package/.agent/scripts/minimal_change_engine.js +437 -0
- package/.agent/scripts/pipeline_engine.js +856 -0
- package/.agent/scripts/skill_evolution.js +36 -21
- package/.agent/scripts/socratic_gate_policy.js +60 -0
- package/.agent/scripts/swarm_dispatcher.js +65 -6
- package/.agent/scripts/token_budget_broker.js +52 -0
- package/.agent/scripts/verify_all.js +13 -0
- package/.agent/scripts/visual_audit.js +92 -0
- package/.agent/skills/12-principles-of-animation/SKILL.md +19 -10
- package/.agent/skills/60fps-animation/SKILL.md +19 -10
- package/.agent/skills/accessible-animation/SKILL.md +19 -10
- package/.agent/skills/adapt/SKILL.md +19 -10
- package/.agent/skills/advanced-rag-pipelines/SKILL.md +21 -3
- package/.agent/skills/agent-organizer/SKILL.md +21 -7
- package/.agent/skills/agentic-patterns/SKILL.md +19 -7
- package/.agent/skills/ai-prompt-injection-defense/SKILL.md +21 -7
- package/.agent/skills/animation-on-scroll/SKILL.md +19 -10
- package/.agent/skills/animation-systems/SKILL.md +19 -10
- package/.agent/skills/antfu-conventions/SKILL.md +21 -10
- package/.agent/skills/api-patterns/SKILL.md +21 -7
- package/.agent/skills/api-patterns/scripts/__pycache__/api_validator.cpython-311.pyc +0 -0
- package/.agent/skills/api-security-auditor/SKILL.md +21 -7
- package/.agent/skills/app-builder/SKILL.md +21 -7
- package/.agent/skills/apple-design/SKILL.md +19 -10
- package/.agent/skills/architecture/SKILL.md +21 -7
- package/.agent/skills/audit-and-fix/SKILL.md +19 -10
- package/.agent/skills/authentication-best-practices/SKILL.md +21 -7
- package/.agent/skills/backend-security-expert/SKILL.md +21 -7
- package/.agent/skills/baseline-ui/SKILL.md +19 -10
- package/.agent/skills/bash-linux/SKILL.md +21 -7
- package/.agent/skills/behavioral-modes/SKILL.md +19 -7
- package/.agent/skills/better-colors/SKILL.md +31 -14
- package/.agent/skills/better-ui/SKILL.md +19 -10
- package/.agent/skills/bolder/SKILL.md +19 -10
- package/.agent/skills/brainstorming/SKILL.md +17 -7
- package/.agent/skills/browser-native-ai/SKILL.md +19 -3
- package/.agent/skills/build-primitive/SKILL.md +19 -10
- package/.agent/skills/building-native-ui/SKILL.md +21 -7
- package/.agent/skills/cicd-pro/SKILL.md +21 -10
- package/.agent/skills/clarify/SKILL.md +19 -10
- package/.agent/skills/clean-code/SKILL.md +21 -7
- package/.agent/skills/cloud-architect/SKILL.md +21 -10
- package/.agent/skills/cobejs/SKILL.md +19 -10
- package/.agent/skills/code-review-checklist/SKILL.md +21 -7
- package/.agent/skills/codebase-design/SKILL.md +21 -10
- package/.agent/skills/colorize/SKILL.md +19 -10
- package/.agent/skills/compact-landing/SKILL.md +19 -10
- package/.agent/skills/company-logos/SKILL.md +19 -10
- package/.agent/skills/config-validator/SKILL.md +21 -7
- package/.agent/skills/containerization-pro/SKILL.md +21 -10
- package/.agent/skills/create-design-md/SKILL.md +19 -10
- package/.agent/skills/critique/SKILL.md +19 -10
- package/.agent/skills/csharp-developer/SKILL.md +21 -7
- package/.agent/skills/data-validation-schemas/SKILL.md +21 -7
- package/.agent/skills/database-design/SKILL.md +21 -7
- package/.agent/skills/database-design/scripts/__pycache__/schema_validator.cpython-311.pyc +0 -0
- package/.agent/skills/delight/SKILL.md +19 -10
- package/.agent/skills/deployment-procedures/SKILL.md +21 -7
- package/.agent/skills/design-lab/SKILL.md +21 -10
- package/.agent/skills/devops-engineer/SKILL.md +21 -7
- package/.agent/skills/devops-incident-responder/SKILL.md +21 -7
- package/.agent/skills/diagnosing-bugs/SKILL.md +21 -10
- package/.agent/skills/distill/SKILL.md +19 -10
- package/.agent/skills/documentation-templates/SKILL.md +21 -7
- package/.agent/skills/domain-modeling/SKILL.md +21 -10
- package/.agent/skills/edge-computing/SKILL.md +21 -7
- package/.agent/skills/emil-design-eng/SKILL.md +19 -10
- package/.agent/skills/error-resilience/SKILL.md +21 -7
- package/.agent/skills/extract-design-system/SKILL.md +21 -7
- package/.agent/skills/fabel-protocol/SKILL.md +19 -2
- package/.agent/skills/fixing-accessibility/SKILL.md +25 -14
- package/.agent/skills/fixing-metadata/SKILL.md +19 -10
- package/.agent/skills/fixing-motion-performance/SKILL.md +19 -10
- package/.agent/skills/framer-motion-expert/SKILL.md +19 -6
- package/.agent/skills/frontend-design/SKILL.md +66 -204
- package/.agent/skills/frontend-design/scripts/__pycache__/accessibility_checker.cpython-311.pyc +0 -0
- package/.agent/skills/frontend-design/scripts/__pycache__/ux_audit.cpython-311.pyc +0 -0
- package/.agent/skills/frontend-security-expert/SKILL.md +21 -7
- package/.agent/skills/game-design-expert/SKILL.md +21 -7
- package/.agent/skills/game-engineering-expert/SKILL.md +21 -7
- package/.agent/skills/generative-ui-expert/SKILL.md +19 -3
- package/.agent/skills/geo-fundamentals/SKILL.md +21 -7
- package/.agent/skills/geo-fundamentals/scripts/__pycache__/geo_checker.cpython-311.pyc +0 -0
- package/.agent/skills/git-pro/SKILL.md +21 -10
- package/.agent/skills/github-operations/SKILL.md +21 -7
- package/.agent/skills/gpt-taste/SKILL.md +19 -10
- package/.agent/skills/gsap-core/SKILL.md +21 -4
- package/.agent/skills/gsap-frameworks/SKILL.md +21 -4
- package/.agent/skills/gsap-performance/SKILL.md +20 -5
- package/.agent/skills/gsap-plugins/SKILL.md +20 -5
- package/.agent/skills/gsap-react/SKILL.md +20 -5
- package/.agent/skills/gsap-scrolltrigger/SKILL.md +21 -4
- package/.agent/skills/gsap-timeline/SKILL.md +20 -5
- package/.agent/skills/gsap-utils/SKILL.md +20 -5
- package/.agent/skills/harden/SKILL.md +19 -10
- package/.agent/skills/harness-protocol/SKILL.md +20 -4
- package/.agent/skills/i18n-localization/SKILL.md +21 -7
- package/.agent/skills/i18n-localization/scripts/__pycache__/i18n_checker.cpython-311.pyc +0 -0
- package/.agent/skills/impeccable/SKILL.md +21 -10
- package/.agent/skills/improve-codebase-architecture/SKILL.md +21 -10
- package/.agent/skills/improve-ui/SKILL.md +19 -10
- package/.agent/skills/intelligent-routing/SKILL.md +19 -7
- package/.agent/skills/knowledge-graph/SKILL.md +20 -4
- package/.agent/skills/landing-page/SKILL.md +20 -10
- package/.agent/skills/lint-and-validate/SKILL.md +21 -7
- package/.agent/skills/lint-and-validate/scripts/__pycache__/lint_runner.cpython-311.pyc +0 -0
- package/.agent/skills/lint-and-validate/scripts/__pycache__/type_coverage.cpython-311.pyc +0 -0
- package/.agent/skills/llm-engineering/SKILL.md +21 -7
- package/.agent/skills/local-first/SKILL.md +21 -7
- package/.agent/skills/local-first-architecture/SKILL.md +19 -10
- package/.agent/skills/lottie-animation/SKILL.md +19 -10
- package/.agent/skills/marquee-loop/SKILL.md +19 -10
- package/.agent/skills/masked-reveal/SKILL.md +19 -10
- package/.agent/skills/mcp-builder/SKILL.md +21 -7
- package/.agent/skills/micro-interaction/SKILL.md +19 -10
- package/.agent/skills/mobile-design/SKILL.md +21 -6
- package/.agent/skills/mobile-design/scripts/__pycache__/mobile_audit.cpython-311.pyc +0 -0
- package/.agent/skills/monorepo-management/SKILL.md +21 -7
- package/.agent/skills/morphing-icons/SKILL.md +19 -10
- package/.agent/skills/motion-engineering/SKILL.md +86 -171
- package/.agent/skills/nextjs-react-expert/SKILL.md +19 -7
- package/.agent/skills/nextjs-react-expert/scripts/__pycache__/convert_rules.cpython-311.pyc +0 -0
- package/.agent/skills/nextjs-react-expert/scripts/__pycache__/react_performance_checker.cpython-311.pyc +0 -0
- package/.agent/skills/nodejs-best-practices/SKILL.md +21 -7
- package/.agent/skills/observability/SKILL.md +21 -7
- package/.agent/skills/page-transition-animation/SKILL.md +19 -10
- package/.agent/skills/parallel-agents/SKILL.md +23 -7
- package/.agent/skills/performance-profiling/SKILL.md +21 -7
- package/.agent/skills/performance-profiling/scripts/__pycache__/lighthouse_audit.cpython-311.pyc +0 -0
- package/.agent/skills/plan-writing/SKILL.md +21 -7
- package/.agent/skills/platform-engineer/SKILL.md +21 -7
- package/.agent/skills/playwright-best-practices/SKILL.md +21 -7
- package/.agent/skills/polish/SKILL.md +19 -10
- package/.agent/skills/powershell-windows/SKILL.md +21 -7
- package/.agent/skills/pricing-page/SKILL.md +19 -10
- package/.agent/skills/product-aware-heuristics/SKILL.md +358 -0
- package/.agent/skills/progressive-blur/SKILL.md +19 -10
- package/.agent/skills/project-idioms/SKILL.md +20 -8
- package/.agent/skills/python-patterns/SKILL.md +21 -7
- package/.agent/skills/python-pro/SKILL.md +21 -6
- package/.agent/skills/quieter/SKILL.md +19 -10
- package/.agent/skills/react-doctor/SKILL.md +19 -10
- package/.agent/skills/react-specialist/SKILL.md +19 -6
- package/.agent/skills/readme-builder/SKILL.md +21 -7
- package/.agent/skills/realtime-patterns/SKILL.md +21 -7
- package/.agent/skills/red-team-tactics/SKILL.md +21 -7
- package/.agent/skills/redesign-skill/SKILL.md +19 -10
- package/.agent/skills/review-animations/SKILL.md +21 -10
- package/.agent/skills/rust-pro/SKILL.md +21 -7
- package/.agent/skills/seo-fundamentals/SKILL.md +21 -7
- package/.agent/skills/seo-fundamentals/scripts/__pycache__/seo_checker.cpython-311.pyc +0 -0
- package/.agent/skills/server-management/SKILL.md +21 -7
- package/.agent/skills/shadcn-ui-expert/SKILL.md +21 -7
- package/.agent/skills/shape/SKILL.md +19 -10
- package/.agent/skills/skill-creator/SKILL.md +21 -7
- package/.agent/skills/soft-skill/SKILL.md +19 -10
- package/.agent/skills/sounds-on-the-web/SKILL.md +19 -10
- package/.agent/skills/sql-pro/SKILL.md +21 -7
- package/.agent/skills/supabase-postgres-best-practices/SKILL.md +21 -7
- package/.agent/skills/svg-animation/SKILL.md +19 -10
- package/.agent/skills/swiftui-expert/SKILL.md +21 -7
- package/.agent/skills/swiss-design/SKILL.md +19 -10
- package/.agent/skills/system-design-pro/SKILL.md +21 -9
- package/.agent/skills/systematic-debugging/SKILL.md +21 -7
- package/.agent/skills/tailwind-patterns/SKILL.md +21 -7
- package/.agent/skills/taste-skill/SKILL.md +19 -10
- package/.agent/skills/tdd-workflow/SKILL.md +21 -10
- package/.agent/skills/test-result-analyzer/SKILL.md +18 -6
- package/.agent/skills/testing-patterns/SKILL.md +21 -7
- package/.agent/skills/testing-patterns/scripts/__pycache__/test_runner.cpython-311.pyc +0 -0
- package/.agent/skills/thermo-nuclear-code-quality-review/SKILL.md +21 -10
- package/.agent/skills/thinking-protocol/SKILL.md +20 -8
- package/.agent/skills/to-spring-or-not-to-spring/SKILL.md +19 -10
- package/.agent/skills/transitions-dev/SKILL.md +19 -10
- package/.agent/skills/trend-researcher/SKILL.md +17 -6
- package/.agent/skills/typescript-advanced/SKILL.md +21 -7
- package/.agent/skills/typeset/SKILL.md +19 -10
- package/.agent/skills/ui-reasoning-engine/SKILL.md +154 -0
- package/.agent/skills/ui-skill-packs/SKILL.md +77 -0
- package/.agent/skills/ui-skills-root/SKILL.md +21 -9
- package/.agent/skills/ui-ux-pro-max/SKILL.md +62 -583
- package/.agent/skills/ui-ux-researcher/SKILL.md +17 -6
- package/.agent/skills/vue-expert/SKILL.md +19 -6
- package/.agent/skills/vulnerability-scanner/SKILL.md +21 -7
- package/.agent/skills/vulnerability-scanner/scripts/__pycache__/security_scan.cpython-311.pyc +0 -0
- package/.agent/skills/web-accessibility-auditor/SKILL.md +21 -7
- package/.agent/skills/web-design-guidelines/SKILL.md +32 -206
- package/.agent/skills/web-quality-audit/SKILL.md +19 -10
- package/.agent/skills/webapp-testing/SKILL.md +21 -7
- package/.agent/skills/webapp-testing/scripts/__pycache__/playwright_runner.cpython-311.pyc +0 -0
- package/.agent/skills/webgpu-performance/SKILL.md +19 -3
- package/.agent/skills/whimsy-injector/SKILL.md +20 -10
- package/.agent/skills/workflow-optimizer/SKILL.md +16 -6
- package/.agent/templates/DESIGN.md +292 -0
- package/.agent/templates/design-tokens.json +137 -0
- package/.agent/workflows/acf.md +13 -6
- package/.agent/workflows/api-tester.md +15 -8
- package/.agent/workflows/audit.md +19 -8
- package/.agent/workflows/brainstorm.md +14 -9
- package/.agent/workflows/changelog.md +14 -8
- package/.agent/workflows/create.md +16 -8
- package/.agent/workflows/debug.md +15 -10
- package/.agent/workflows/deploy.md +16 -8
- package/.agent/workflows/enhance.md +15 -10
- package/.agent/workflows/fix.md +15 -8
- package/.agent/workflows/generate.md +17 -11
- package/.agent/workflows/marathon.md +15 -8
- package/.agent/workflows/migrate.md +16 -8
- package/.agent/workflows/minimal.md +94 -0
- package/.agent/workflows/orchestrate.md +15 -8
- package/.agent/workflows/performance-benchmarker.md +15 -8
- package/.agent/workflows/pipeline.md +155 -0
- package/.agent/workflows/plan.md +14 -10
- package/.agent/workflows/preview.md +14 -7
- package/.agent/workflows/refactor.md +16 -8
- package/.agent/workflows/review-ai.md +15 -7
- package/.agent/workflows/review.md +15 -7
- package/.agent/workflows/session.md +14 -7
- package/.agent/workflows/status.md +13 -7
- package/.agent/workflows/strengthen-skills.md +15 -6
- package/.agent/workflows/super-prompt.md +19 -10
- package/.agent/workflows/swarm.md +15 -7
- package/.agent/workflows/test.md +15 -8
- package/.agent/workflows/tribunal-backend.md +16 -9
- package/.agent/workflows/tribunal-database.md +15 -8
- package/.agent/workflows/tribunal-frontend.md +26 -11
- package/.agent/workflows/tribunal-full.md +29 -14
- package/.agent/workflows/tribunal-mobile.md +15 -8
- package/.agent/workflows/tribunal-performance.md +15 -8
- package/.agent/workflows/tribunal-speed.md +16 -9
- package/.agent/workflows/tribunal-ui.md +82 -0
- package/.agent/workflows/ui-ux-pro-max.md +51 -107
- package/CONTRIBUTING.md +2 -2
- package/README.md +5 -5
- package/bin/mcp-server.js +126 -76
- package/bin/wrapper.js +67 -31
- package/dist/cli.js +39 -1
- package/dist/commands/compile.js +7 -0
- package/dist/commands/context.js +8 -3
- package/dist/commands/graph.js +8 -2
- package/dist/commands/init.js +37 -2
- package/dist/commands/memory.js +119 -68
- package/dist/commands/minimal.js +71 -0
- package/dist/commands/native.js +228 -0
- package/dist/commands/optimize.js +15 -5
- package/dist/commands/validate.js +67 -0
- package/dist/esm/index.mjs +26 -32
- package/dist/mcp/server.js +4 -138
- package/dist/utils/fs.js +10 -4
- package/dist/utils/helpers.js +10 -1
- package/dist/utils/version.js +9 -2
- package/mcp_config.json +10 -1
- package/package.json +19 -15
- package/scripts/benchmark.js +58 -0
- package/scripts/sync-version.js +129 -76
- package/scripts/visual_audit.js +126 -0
package/dist/commands/memory.js
CHANGED
|
@@ -31,6 +31,42 @@ const PROJECTION_FILE = 'MEMORY.md';
|
|
|
31
31
|
const MAX_ENTRIES = 500;
|
|
32
32
|
const EPISODIC_TTL_DAYS = 30;
|
|
33
33
|
|
|
34
|
+
function acquireLock(agentDest) {
|
|
35
|
+
const lockPath = getIndexPath(agentDest) + '.lock';
|
|
36
|
+
const maxRetries = 10;
|
|
37
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
38
|
+
try {
|
|
39
|
+
const fd = fs_1.default.openSync(lockPath, 'wx');
|
|
40
|
+
fs_1.default.closeSync(fd);
|
|
41
|
+
return lockPath;
|
|
42
|
+
} catch (err) {
|
|
43
|
+
if (err.code !== 'EEXIST') {
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
const start = Date.now();
|
|
47
|
+
while (Date.now() - start < 50) {}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const stats = fs_1.default.statSync(lockPath);
|
|
52
|
+
if (Date.now() - stats.mtimeMs > 10000) {
|
|
53
|
+
fs_1.default.unlinkSync(lockPath);
|
|
54
|
+
const fd = fs_1.default.openSync(lockPath, 'wx');
|
|
55
|
+
fs_1.default.closeSync(fd);
|
|
56
|
+
return lockPath;
|
|
57
|
+
}
|
|
58
|
+
} catch {}
|
|
59
|
+
throw new Error('Could not acquire lock for memory index');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function releaseLock(lockPath) {
|
|
63
|
+
try {
|
|
64
|
+
if (lockPath && fs_1.default.existsSync(lockPath)) {
|
|
65
|
+
fs_1.default.unlinkSync(lockPath);
|
|
66
|
+
}
|
|
67
|
+
} catch {}
|
|
68
|
+
}
|
|
69
|
+
|
|
34
70
|
function getMemoryDir(agentDest) {
|
|
35
71
|
return path_1.default.join(agentDest, MEMORY_DIR);
|
|
36
72
|
}
|
|
@@ -121,95 +157,110 @@ function memoryStore(agentDest, type, content, tags, sessionId) {
|
|
|
121
157
|
throw new Error('Memory content cannot be empty');
|
|
122
158
|
}
|
|
123
159
|
|
|
124
|
-
const
|
|
160
|
+
const lockPath = acquireLock(agentDest);
|
|
161
|
+
try {
|
|
162
|
+
const index = loadIndex(agentDest);
|
|
125
163
|
|
|
126
|
-
|
|
127
|
-
if (index.entries.length >= MAX_ENTRIES) {
|
|
128
|
-
index.entries = index.entries.filter(e => e.memory_type !== 'working');
|
|
129
|
-
if (index.entries.length >= MAX_ENTRIES) {
|
|
130
|
-
index.entries = index.entries.filter(e => {
|
|
131
|
-
if (e.memory_type === 'episodic') {
|
|
132
|
-
return daysSince(e.created_at) < EPISODIC_TTL_DAYS;
|
|
133
|
-
}
|
|
134
|
-
return true;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
164
|
+
// Enforce cap — auto-GC if needed
|
|
137
165
|
if (index.entries.length >= MAX_ENTRIES) {
|
|
138
|
-
|
|
166
|
+
index.entries = index.entries.filter(e => e.memory_type !== 'working');
|
|
167
|
+
if (index.entries.length >= MAX_ENTRIES) {
|
|
168
|
+
index.entries = index.entries.filter(e => {
|
|
169
|
+
if (e.memory_type === 'episodic') {
|
|
170
|
+
return daysSince(e.created_at) < EPISODIC_TTL_DAYS; // Typo correction or TTL match
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (index.entries.length >= MAX_ENTRIES) {
|
|
176
|
+
throw new Error(`Memory at capacity (${MAX_ENTRIES}). Run: tk memory gc`);
|
|
177
|
+
}
|
|
139
178
|
}
|
|
140
|
-
}
|
|
141
179
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
180
|
+
const now = nowEpochStr();
|
|
181
|
+
const id = index.next_id || (index.entries.length > 0 ? Math.max(...index.entries.map(e => e.id)) + 1 : 1);
|
|
182
|
+
const entry = {
|
|
183
|
+
id,
|
|
184
|
+
memory_type: type,
|
|
185
|
+
content: content.trim(),
|
|
186
|
+
tags: tags.filter(t => t.length > 0),
|
|
187
|
+
created_at: now,
|
|
188
|
+
last_accessed: now,
|
|
189
|
+
access_count: 0,
|
|
190
|
+
token_estimate: estimateTokens(content),
|
|
191
|
+
source: type === 'working' ? 'session' : 'manual',
|
|
192
|
+
session_id: sessionId || null,
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
index.entries.push(entry);
|
|
196
|
+
index.next_id = id + 1;
|
|
197
|
+
saveIndex(agentDest, index);
|
|
198
|
+
generateProjection(agentDest, index);
|
|
199
|
+
|
|
200
|
+
return { id, token_estimate: entry.token_estimate };
|
|
201
|
+
} finally {
|
|
202
|
+
releaseLock(lockPath);
|
|
203
|
+
}
|
|
163
204
|
}
|
|
164
205
|
|
|
165
206
|
// ── Recall ──────────────────────────────────────────────────────────────────
|
|
166
207
|
|
|
167
208
|
function memoryRecall(agentDest, query, budget = 2000) {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
209
|
+
const lockPath = acquireLock(agentDest);
|
|
210
|
+
try {
|
|
211
|
+
const index = loadIndex(agentDest);
|
|
212
|
+
|
|
213
|
+
const scored = index.entries
|
|
214
|
+
.map(entry => ({ entry, score: computeScore(entry, query) }))
|
|
215
|
+
.filter(s => s.score > 0)
|
|
216
|
+
.sort((a, b) => b.score - a.score);
|
|
217
|
+
|
|
218
|
+
let totalTokens = 0;
|
|
219
|
+
const results = [];
|
|
220
|
+
|
|
221
|
+
for (const { entry, score } of scored) {
|
|
222
|
+
if (totalTokens + entry.token_estimate > budget) break;
|
|
223
|
+
totalTokens += entry.token_estimate;
|
|
224
|
+
entry.last_accessed = nowEpochStr();
|
|
225
|
+
entry.access_count = (entry.access_count || 0) + 1;
|
|
226
|
+
results.push({ ...entry, score });
|
|
227
|
+
}
|
|
174
228
|
|
|
175
|
-
|
|
176
|
-
|
|
229
|
+
// Save updated access counts
|
|
230
|
+
saveIndex(agentDest, index);
|
|
177
231
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
entry.last_accessed = nowEpochStr();
|
|
182
|
-
entry.access_count = (entry.access_count || 0) + 1;
|
|
183
|
-
results.push({ ...entry, score });
|
|
232
|
+
return { results, tokens_used: totalTokens, budget };
|
|
233
|
+
} finally {
|
|
234
|
+
releaseLock(lockPath);
|
|
184
235
|
}
|
|
185
|
-
|
|
186
|
-
// Save updated access counts
|
|
187
|
-
saveIndex(agentDest, index);
|
|
188
|
-
|
|
189
|
-
return { results, tokens_used: totalTokens, budget };
|
|
190
236
|
}
|
|
191
237
|
|
|
192
238
|
// ── Garbage Collect ─────────────────────────────────────────────────────────
|
|
193
239
|
|
|
194
240
|
function memoryGc(agentDest) {
|
|
195
|
-
const
|
|
196
|
-
|
|
241
|
+
const lockPath = acquireLock(agentDest);
|
|
242
|
+
try {
|
|
243
|
+
const index = loadIndex(agentDest);
|
|
244
|
+
const before = index.entries.length;
|
|
197
245
|
|
|
198
|
-
|
|
199
|
-
|
|
246
|
+
let workingRemoved = 0;
|
|
247
|
+
let episodicRemoved = 0;
|
|
200
248
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
249
|
+
index.entries = index.entries.filter(e => {
|
|
250
|
+
if (e.memory_type === 'working') { workingRemoved++; return false; }
|
|
251
|
+
if (e.memory_type === 'episodic' && daysSince(e.created_at) >= EPISODIC_TTL_DAYS) {
|
|
252
|
+
episodicRemoved++; return false;
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
});
|
|
208
256
|
|
|
209
|
-
|
|
210
|
-
|
|
257
|
+
saveIndex(agentDest, index);
|
|
258
|
+
generateProjection(agentDest, index);
|
|
211
259
|
|
|
212
|
-
|
|
260
|
+
return { working_removed: workingRemoved, episodic_removed: episodicRemoved, before, after: index.entries.length };
|
|
261
|
+
} finally {
|
|
262
|
+
releaseLock(lockPath);
|
|
263
|
+
}
|
|
213
264
|
}
|
|
214
265
|
|
|
215
266
|
// ── Stats ───────────────────────────────────────────────────────────────────
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cmdMinimal = cmdMinimal;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const logger_1 = require("../utils/logger");
|
|
10
|
+
const helpers_1 = require("../utils/helpers");
|
|
11
|
+
|
|
12
|
+
function cmdMinimal(flags, quiet = false) {
|
|
13
|
+
const targetDir = flags.path ? path_1.default.resolve(flags.path) : process.cwd();
|
|
14
|
+
const agentDest = path_1.default.join(targetDir, '.agent');
|
|
15
|
+
(0, helpers_1.banner)(quiet);
|
|
16
|
+
|
|
17
|
+
if (!fs_1.default.existsSync(agentDest)) {
|
|
18
|
+
(0, logger_1.log)(` ${(0, logger_1.c)('red', '✖')} ${(0, logger_1.bold)('Not installed')} in this project`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const enginePath = path_1.default.join(agentDest, 'scripts', 'minimal_change_engine.js');
|
|
23
|
+
if (!fs_1.default.existsSync(enginePath)) {
|
|
24
|
+
(0, logger_1.log)(` ${(0, logger_1.c)('red', '✖')} minimal_change_engine.js not found`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const engine = require(enginePath);
|
|
30
|
+
const task = flags.task || flags._?.slice(1).join(' ') || 'Default task evaluation';
|
|
31
|
+
const mode = flags.mode || 'balanced';
|
|
32
|
+
const result = engine.evaluateMinimalChange(task, {
|
|
33
|
+
files_added: flags.filesAdded ? parseInt(flags.filesAdded, 10) : 0,
|
|
34
|
+
files_modified: flags.filesModified ? parseInt(flags.filesModified, 10) : 1,
|
|
35
|
+
estimated_lines_added: flags.linesAdded ? parseInt(flags.linesAdded, 10) : 20,
|
|
36
|
+
}, { mode, cwd: targetDir });
|
|
37
|
+
|
|
38
|
+
if (flags.json) {
|
|
39
|
+
console.log(JSON.stringify(result, null, 2));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
(0, logger_1.log)(` ${(0, logger_1.bold)('Minimal Change Governance Audit')}`);
|
|
44
|
+
(0, logger_1.log)(` Minimality Score: ${result.passed ? (0, logger_1.c)('green', result.minimality_score + '/100') : (0, logger_1.c)('red', result.minimality_score + '/100')}`);
|
|
45
|
+
(0, logger_1.log)(` Decision Classification: ${(0, logger_1.c)('cyan', result.minimality_classification)}`);
|
|
46
|
+
(0, logger_1.log)(` Strictness Mode: ${(0, logger_1.c)('yellow', mode)}`);
|
|
47
|
+
console.log();
|
|
48
|
+
|
|
49
|
+
if (result.change_budget) {
|
|
50
|
+
(0, logger_1.log)(` ${(0, logger_1.bold)('Change Budget:')}`);
|
|
51
|
+
(0, logger_1.log)(` files_added: ${result.change_budget.files_added}`);
|
|
52
|
+
(0, logger_1.log)(` files_modified: ${result.change_budget.files_modified}`);
|
|
53
|
+
(0, logger_1.log)(` dependencies_added: ${result.change_budget.dependencies_added}`);
|
|
54
|
+
(0, logger_1.log)(` new_abstractions: ${result.change_budget.new_abstractions}`);
|
|
55
|
+
console.log();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (result.complexity_flags.length > 0) {
|
|
59
|
+
(0, logger_1.log)(` ${(0, logger_1.c)('yellow', 'Complexity Flags Detected:')}`);
|
|
60
|
+
result.complexity_flags.forEach(f => {
|
|
61
|
+
(0, logger_1.log)(` • [${f.severity.toUpperCase()}] ${f.type}: ${f.evidence}`);
|
|
62
|
+
});
|
|
63
|
+
console.log();
|
|
64
|
+
} else {
|
|
65
|
+
(0, logger_1.log)(` ${(0, logger_1.c)('green', '✔ Zero Complexity Flags Detected')}`);
|
|
66
|
+
console.log();
|
|
67
|
+
}
|
|
68
|
+
} catch (err) {
|
|
69
|
+
(0, logger_1.log)(` ${(0, logger_1.c)('red', '✖ Error executing Minimal Change Engine:')} ${err.message}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
|
|
5
|
+
function getOption(args, names) {
|
|
6
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
7
|
+
const arg = args[index];
|
|
8
|
+
for (const name of names) {
|
|
9
|
+
if (arg === name) return args[index + 1] || null;
|
|
10
|
+
if (arg.startsWith(`${name}=`)) return arg.slice(name.length + 1);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function fail(message) {
|
|
17
|
+
console.error(message);
|
|
18
|
+
process.exitCode = 1;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function parseMaxLines(value) {
|
|
23
|
+
if (value === null) return null;
|
|
24
|
+
const parsed = Number.parseInt(value, 10);
|
|
25
|
+
return Number.isInteger(parsed) && parsed >= 0 ? parsed : undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function cmdMinContext(processArgs, quiet = false) {
|
|
29
|
+
const args = processArgs.slice(3);
|
|
30
|
+
const file = getOption(args, ["--file", "-f"]);
|
|
31
|
+
const maxLines = parseMaxLines(getOption(args, ["--max-lines"]));
|
|
32
|
+
if (!file) return fail("Usage: tk min-context --file <path> [--max-lines <count>]");
|
|
33
|
+
if (maxLines === undefined) return fail("--max-lines must be a non-negative integer.");
|
|
34
|
+
|
|
35
|
+
let content;
|
|
36
|
+
try {
|
|
37
|
+
content = fs.readFileSync(file, "utf8");
|
|
38
|
+
} catch (error) {
|
|
39
|
+
return fail(`Failed to read file: ${error.message}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const originalLines = content.split(/\r?\n/).length;
|
|
43
|
+
let lines = content.split(/\r?\n/).map((line) => line.trimEnd()).filter((line) => line.trim());
|
|
44
|
+
if (maxLines !== null) lines = lines.slice(0, maxLines);
|
|
45
|
+
const result = {
|
|
46
|
+
file,
|
|
47
|
+
original_lines: originalLines,
|
|
48
|
+
minified_lines: lines.length,
|
|
49
|
+
lines_reduced: Math.max(0, originalLines - lines.length),
|
|
50
|
+
minified: lines.join("\n"),
|
|
51
|
+
};
|
|
52
|
+
if (!quiet) console.error(`✓ Minified ${file}`);
|
|
53
|
+
console.log(JSON.stringify(result));
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function cmdDagSchedule(processArgs, quiet = false) {
|
|
58
|
+
const args = processArgs.slice(3);
|
|
59
|
+
const rawTasks = getOption(args, ["--tasks", "-t"]);
|
|
60
|
+
if (!rawTasks) return fail("Usage: tk dag-schedule --tasks '<json-array>'");
|
|
61
|
+
|
|
62
|
+
let tasks;
|
|
63
|
+
try {
|
|
64
|
+
tasks = JSON.parse(rawTasks);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
return fail(`Failed to parse task JSON: ${error.message}`);
|
|
67
|
+
}
|
|
68
|
+
if (!Array.isArray(tasks) || tasks.some((task) => !task || typeof task.id !== "string" || !task.id)) {
|
|
69
|
+
return fail("Each task must be an object with a non-empty id.");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const ids = new Set(tasks.map((task) => task.id));
|
|
73
|
+
const inDegree = new Map(tasks.map((task) => [task.id, 0]));
|
|
74
|
+
const dependents = new Map(tasks.map((task) => [task.id, []]));
|
|
75
|
+
for (const task of tasks) {
|
|
76
|
+
const dependencies = Array.isArray(task.dependencies) ? task.dependencies : [];
|
|
77
|
+
for (const dependency of dependencies) {
|
|
78
|
+
if (ids.has(dependency)) {
|
|
79
|
+
dependents.get(dependency).push(task.id);
|
|
80
|
+
inDegree.set(task.id, inDegree.get(task.id) + 1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const waves = [];
|
|
86
|
+
let wave = [...inDegree.entries()].filter(([, degree]) => degree === 0).map(([id]) => id).sort();
|
|
87
|
+
let processed = 0;
|
|
88
|
+
while (wave.length > 0) {
|
|
89
|
+
waves.push(wave);
|
|
90
|
+
processed += wave.length;
|
|
91
|
+
const next = [];
|
|
92
|
+
for (const id of wave) {
|
|
93
|
+
for (const dependent of dependents.get(id)) {
|
|
94
|
+
const nextDegree = inDegree.get(dependent) - 1;
|
|
95
|
+
inDegree.set(dependent, nextDegree);
|
|
96
|
+
if (nextDegree === 0) next.push(dependent);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
wave = [...new Set(next)].sort();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const result = {
|
|
103
|
+
success: processed === tasks.length,
|
|
104
|
+
total_tasks: tasks.length,
|
|
105
|
+
total_waves: waves.length,
|
|
106
|
+
waves,
|
|
107
|
+
is_cyclic: processed < tasks.length,
|
|
108
|
+
};
|
|
109
|
+
if (!quiet && result.is_cyclic) console.error("⚠ Dependency cycle detected.");
|
|
110
|
+
console.log(JSON.stringify(result));
|
|
111
|
+
return result.success;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function cmdContextCompress(processArgs, quiet = false) {
|
|
115
|
+
const args = processArgs.slice(3);
|
|
116
|
+
const file = getOption(args, ["--file", "-f"]);
|
|
117
|
+
const maxLines = parseMaxLines(getOption(args, ["--max-lines"]));
|
|
118
|
+
if (!file) return fail("Usage: tk context-compress --file <path> [--max-lines <count>]");
|
|
119
|
+
if (maxLines === undefined) return fail("--max-lines must be a non-negative integer.");
|
|
120
|
+
|
|
121
|
+
let content;
|
|
122
|
+
try {
|
|
123
|
+
content = fs.readFileSync(file, "utf8");
|
|
124
|
+
} catch (error) {
|
|
125
|
+
return fail(`Failed to read file: ${error.message}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const codeFile = /\.(?:js|ts|rs|json)$/i.test(file);
|
|
129
|
+
let lines = content.split(/\r?\n/).filter((line) => {
|
|
130
|
+
const trimmed = line.trim();
|
|
131
|
+
return trimmed && (!codeFile || !trimmed.startsWith("//") || trimmed.includes("// VERIFY"));
|
|
132
|
+
});
|
|
133
|
+
if (maxLines !== null && lines.length > maxLines) {
|
|
134
|
+
const omitted = lines.length - maxLines;
|
|
135
|
+
lines = lines.slice(0, maxLines);
|
|
136
|
+
lines.push(`// ... [Truncated ${omitted} lines for agent context optimization]`);
|
|
137
|
+
}
|
|
138
|
+
const compressedContent = lines.join("\n");
|
|
139
|
+
const originalBytes = Buffer.byteLength(content);
|
|
140
|
+
const compressedBytes = Buffer.byteLength(compressedContent);
|
|
141
|
+
const result = {
|
|
142
|
+
success: true,
|
|
143
|
+
original_bytes: originalBytes,
|
|
144
|
+
compressed_bytes: compressedBytes,
|
|
145
|
+
compression_ratio: originalBytes === 0 ? 1 : 1 - compressedBytes / originalBytes,
|
|
146
|
+
compressed_content: compressedContent,
|
|
147
|
+
};
|
|
148
|
+
if (!quiet) console.error(`✓ Compressed ${file}`);
|
|
149
|
+
console.log(JSON.stringify(result));
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function cmdOptimizeStep(processArgs, quiet = false) {
|
|
154
|
+
const args = processArgs.slice(3);
|
|
155
|
+
const skillPath = getOption(args, ["--skill-path"]);
|
|
156
|
+
const rawEdits = getOption(args, ["--edits-json"]);
|
|
157
|
+
const parsedBudget = parseMaxLines(getOption(args, ["--budget"]));
|
|
158
|
+
const budget = parsedBudget ?? 4;
|
|
159
|
+
if (!skillPath || !rawEdits) return fail("Usage: tk optimize-step --skill-path <path> --edits-json '<json-array>' [--budget <count>]");
|
|
160
|
+
if (parsedBudget === undefined) return fail("--budget must be a non-negative integer.");
|
|
161
|
+
|
|
162
|
+
let edits;
|
|
163
|
+
try {
|
|
164
|
+
edits = JSON.parse(rawEdits);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
return fail(`Failed to parse edits JSON: ${error.message}`);
|
|
167
|
+
}
|
|
168
|
+
if (!Array.isArray(edits)) return fail("--edits-json must be a JSON array.");
|
|
169
|
+
|
|
170
|
+
let text = fs.existsSync(skillPath) ? fs.readFileSync(skillPath, "utf8") : "";
|
|
171
|
+
const protectedStart = text.indexOf("<!-- SLOW_UPDATE_START -->");
|
|
172
|
+
const protectedEnd = text.indexOf("<!-- SLOW_UPDATE_END -->");
|
|
173
|
+
const isProtected = (position) => protectedStart !== -1 && protectedEnd !== -1 && position >= protectedStart && position < protectedEnd;
|
|
174
|
+
const reports = [];
|
|
175
|
+
let appliedCount = 0;
|
|
176
|
+
const ranked = [...edits].sort((left, right) => {
|
|
177
|
+
const leftFailure = left.source_type === "failure" ? 1 : 0;
|
|
178
|
+
const rightFailure = right.source_type === "failure" ? 1 : 0;
|
|
179
|
+
return rightFailure - leftFailure || (right.support_count || 1) - (left.support_count || 1);
|
|
180
|
+
}).slice(0, budget);
|
|
181
|
+
|
|
182
|
+
for (const edit of ranked) {
|
|
183
|
+
const operation = edit && edit.op;
|
|
184
|
+
const target = edit && edit.target;
|
|
185
|
+
const replacement = edit && edit.content;
|
|
186
|
+
if (operation === "append" && typeof replacement === "string") {
|
|
187
|
+
if (text.includes(replacement.trim())) reports.push("skip: append duplicate content");
|
|
188
|
+
else {
|
|
189
|
+
text = `${text}${text && !text.endsWith("\n") ? "\n" : ""}${replacement}\n`;
|
|
190
|
+
appliedCount += 1;
|
|
191
|
+
reports.push("applied: append content");
|
|
192
|
+
}
|
|
193
|
+
} else if (["delete", "replace", "insert_after"].includes(operation) && typeof target === "string") {
|
|
194
|
+
const position = text.indexOf(target);
|
|
195
|
+
if (position === -1) reports.push(`skip: ${operation} target not found`);
|
|
196
|
+
else if (isProtected(position)) reports.push(`skip: ${operation} target is inside protected region`);
|
|
197
|
+
else if (operation === "delete") {
|
|
198
|
+
text = text.replace(target, "");
|
|
199
|
+
appliedCount += 1;
|
|
200
|
+
reports.push("applied: deleted target");
|
|
201
|
+
} else if (typeof replacement !== "string") reports.push(`skip: ${operation} content missing`);
|
|
202
|
+
else if (operation === "replace") {
|
|
203
|
+
text = text.replace(target, replacement);
|
|
204
|
+
appliedCount += 1;
|
|
205
|
+
reports.push("applied: replaced target");
|
|
206
|
+
} else {
|
|
207
|
+
const before = text.slice(0, position + target.length);
|
|
208
|
+
const after = text.slice(position + target.length);
|
|
209
|
+
text = `${before}${replacement.startsWith("\n") ? "" : "\n"}${replacement}${replacement.endsWith("\n") ? "" : "\n"}${after}`;
|
|
210
|
+
appliedCount += 1;
|
|
211
|
+
reports.push("applied: inserted content after target");
|
|
212
|
+
}
|
|
213
|
+
} else reports.push(`skip: unknown or invalid operation ${String(operation)}`);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (appliedCount > 0) fs.writeFileSync(skillPath, text, "utf8");
|
|
217
|
+
const result = { success: true, applied_count: appliedCount, reports };
|
|
218
|
+
if (!quiet) console.error(`✓ Applied ${appliedCount} bounded SkillOpt edit(s)`);
|
|
219
|
+
console.log(JSON.stringify(result));
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
module.exports = {
|
|
224
|
+
cmdMinContext,
|
|
225
|
+
cmdDagSchedule,
|
|
226
|
+
cmdContextCompress,
|
|
227
|
+
cmdOptimizeStep,
|
|
228
|
+
};
|
|
@@ -9,7 +9,7 @@ const fs = __importDefault(require("fs"));
|
|
|
9
9
|
const path = __importDefault(require("path"));
|
|
10
10
|
const os = __importDefault(require("os"));
|
|
11
11
|
const https = __importDefault(require("https"));
|
|
12
|
-
const { execSync } = require("child_process");
|
|
12
|
+
const { execSync, spawnSync } = require("child_process");
|
|
13
13
|
const logger = require("../utils/logger");
|
|
14
14
|
const helpers = require("../utils/helpers");
|
|
15
15
|
|
|
@@ -253,10 +253,20 @@ Each edit must follow this schema:
|
|
|
253
253
|
const tempFile = path.default.join(os.default.tmpdir(), `edits-${Date.now()}.json`);
|
|
254
254
|
fs.default.writeFileSync(tempFile, cleanedJson, 'utf8');
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
const result = spawnSync(binPath, [
|
|
257
|
+
"optimize-step",
|
|
258
|
+
"--skill-path",
|
|
259
|
+
skillPath,
|
|
260
|
+
"--edits-json",
|
|
261
|
+
cleanedJson,
|
|
262
|
+
"--budget",
|
|
263
|
+
String(editBudget)
|
|
264
|
+
], { encoding: 'utf8', cwd: targetDir, stdio: 'pipe' });
|
|
265
|
+
|
|
266
|
+
if (result.error) {
|
|
267
|
+
throw result.error;
|
|
268
|
+
}
|
|
269
|
+
optResultStr = result.stdout || "";
|
|
260
270
|
|
|
261
271
|
try { fs.default.unlinkSync(tempFile); } catch {}
|
|
262
272
|
} catch (e) {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* validate.js — CLI command handler for `tk validate` (JS Fallback)
|
|
4
|
+
*
|
|
5
|
+
* Validates JSON payloads or .agent/ structure against strict schemas.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.cmdValidate = cmdValidate;
|
|
9
|
+
|
|
10
|
+
const fs = require("fs");
|
|
11
|
+
const path = require("path");
|
|
12
|
+
const logger_1 = require("../utils/logger");
|
|
13
|
+
|
|
14
|
+
async function cmdValidate(flags, quiet = false) {
|
|
15
|
+
const projectRoot = flags.path ? path.resolve(flags.path) : process.cwd();
|
|
16
|
+
const agentDir = path.join(projectRoot, ".agent");
|
|
17
|
+
|
|
18
|
+
if (!fs.existsSync(agentDir)) {
|
|
19
|
+
(0, logger_1.err)("No .agent/ directory found. Run `tk init` first.");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const fileToValidate = flags.file || flags.target;
|
|
24
|
+
|
|
25
|
+
if (fileToValidate) {
|
|
26
|
+
const fullPath = path.resolve(fileToValidate);
|
|
27
|
+
if (!fs.existsSync(fullPath)) {
|
|
28
|
+
(0, logger_1.err)(`File not found for validation: ${fileToValidate}`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const content = fs.readFileSync(fullPath, "utf8");
|
|
33
|
+
if (fullPath.endsWith(".json")) {
|
|
34
|
+
JSON.parse(content);
|
|
35
|
+
if (!quiet) {
|
|
36
|
+
(0, logger_1.log)(` ${(0, logger_1.c)("green", "✔")} ${(0, logger_1.bold)("Valid JSON payload:")} ${fullPath}`);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
if (!quiet) {
|
|
40
|
+
(0, logger_1.log)(` ${(0, logger_1.c)("green", "✔")} ${(0, logger_1.bold)("File validated successfully:")} ${fullPath}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
} catch (err) {
|
|
45
|
+
(0, logger_1.err)(`Validation failed for ${fileToValidate}: ${err.message}`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// General .agent validation
|
|
51
|
+
const scriptPath = path.join(agentDir, "scripts", "guardrail_engine.js");
|
|
52
|
+
if (fs.existsSync(scriptPath)) {
|
|
53
|
+
try {
|
|
54
|
+
const { runScan } = require(scriptPath);
|
|
55
|
+
if (typeof runScan === "function") {
|
|
56
|
+
await runScan({ projectRoot, quiet });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
} catch (_e) {
|
|
60
|
+
// Fallback below
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!quiet) {
|
|
65
|
+
(0, logger_1.log)(` ${(0, logger_1.c)("green", "✔")} ${(0, logger_1.bold)(".agent payload structure validated successfully")}`);
|
|
66
|
+
}
|
|
67
|
+
}
|