@aiwg/cli 2026.10.14 → 2026.10.16
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/agentic/code/addons/aiwg-utils/rules/anti-laziness.core.md +13 -0
- package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +118 -0
- package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
- package/dist/src/artifacts/citation-parser.js +7 -6
- package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
- package/dist/src/artifacts/corpus-tools/cli.js +37 -0
- package/dist/src/artifacts/corpus-tools/discovery-log.js +27 -25
- package/dist/src/artifacts/corpus-tools/expand-cli.js +90 -0
- package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
- package/dist/src/artifacts/corpus-tools/expand-queue.js +41 -0
- package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
- package/dist/src/artifacts/corpus-tools/expand-state.js +56 -0
- package/dist/src/artifacts/corpus-tools/expand.js +124 -0
- package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
- package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
- package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
- package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
- package/dist/src/artifacts/corpus-tools/resolve-cli.js +99 -0
- package/dist/src/artifacts/corpus-tools/resolve-corpus.js +41 -0
- package/dist/src/artifacts/corpus-tools/resolve.js +119 -0
- package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
- package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
- package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
- package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
- package/dist/src/artifacts/graph-query.js +5 -3
- package/dist/src/artifacts/hybrid-query.js +11 -2
- package/dist/src/artifacts/index-refresh.js +2 -0
- package/dist/src/cli/handlers/daemon.js +17 -1
- package/dist/src/cli/handlers/doctor-args.js +45 -0
- package/dist/src/cli/handlers/doctor-help.js +8 -3
- package/dist/src/cli/handlers/index.js +2 -2
- package/dist/src/cli/handlers/models-resource-sample.js +10 -0
- package/dist/src/cli/handlers/models.js +3 -2
- package/dist/src/cli/handlers/regenerate.js +8 -16
- package/dist/src/cli/handlers/sessions.js +7 -7
- package/dist/src/cli/handlers/subcommands.js +8 -0
- package/dist/src/cli/handlers/update.js +157 -0
- package/dist/src/cli/handlers/use.js +14 -4
- package/dist/src/cli/handlers/utilities.js +3 -586
- package/dist/src/cli/handlers/utility-doctor.js +412 -0
- package/dist/src/cli/services/deployment-verification.js +0 -1
- package/dist/src/config/aiwg-config.js +2 -1
- package/dist/src/config/authorization-cli.js +7 -3
- package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
- package/dist/src/config/dispatch-thresholds-runtime.mjs +17 -7
- package/dist/src/config/framework-aliases.js +12 -0
- package/dist/src/config/host-resource-report.d.mts +19 -0
- package/dist/src/config/host-resource-report.mjs +80 -0
- package/dist/src/config/host-resource-runtime.d.mts +34 -0
- package/dist/src/config/host-resource-runtime.mjs +293 -0
- package/dist/src/config/installed-selection.js +22 -0
- package/dist/src/config/worker-context.js +33 -4
- package/dist/src/config/worker-invocation-marker.d.mts +1 -0
- package/dist/src/config/worker-invocation-marker.mjs +2 -0
- package/dist/src/decision/heldout/access.js +74 -0
- package/dist/src/decision/heldout/calibration.js +1 -0
- package/dist/src/decision/heldout/collector.js +9 -2
- package/dist/src/effects/verifiers/file.js +22 -5
- package/dist/src/extensions/claude-attribution.js +82 -0
- package/dist/src/extensions/claude-hooks-installer.js +115 -69
- package/dist/src/extensions/commands/daemon.js +109 -0
- package/dist/src/extensions/commands/definitions.js +5 -89
- package/dist/src/features/catalog.js +1 -1
- package/dist/src/gates/evaluate.js +2 -2
- package/dist/src/gates/heldout.js +52 -0
- package/dist/src/gates/index.js +2 -1
- package/dist/src/lint/check-patterns.js +163 -0
- package/dist/src/lint/checks.js +268 -0
- package/dist/src/lint/reference-resolution.js +54 -0
- package/dist/src/lint/runner.js +3 -465
- package/dist/src/mcp/helpers.mjs +11 -1
- package/dist/src/memory/project-registry.js +44 -4
- package/dist/src/models/worker-installation-store.mjs +228 -0
- package/dist/src/models/worker-installation.mjs +7 -162
- package/dist/src/models/worker-plan.js +36 -5
- package/dist/src/models/wrapper-deployment.js +25 -12
- package/dist/src/models/wrapper-enforcement.js +47 -7
- package/dist/src/network-analysis/research.js +2 -1
- package/dist/src/policy/hitl-check.js +14 -4
- package/dist/src/policy/hitl-consume.js +54 -0
- package/dist/src/policy/hitl-receipt.js +2 -0
- package/dist/src/policy/hitl.js +11 -3
- package/dist/src/providers/provider-context-contracts.js +162 -0
- package/dist/src/providers/provider-definition-schema.js +136 -0
- package/dist/src/providers/provider-definitions.js +8 -1298
- package/dist/src/providers/provider-seeds-1.js +360 -0
- package/dist/src/providers/provider-seeds-2.js +387 -0
- package/dist/src/providers/provider-seeds-3.js +262 -0
- package/dist/src/research/clients/arxiv.js +14 -34
- package/dist/src/research/clients/base.js +53 -26
- package/dist/src/research/clients/crossref.js +9 -1
- package/dist/src/research/clients/semantic-scholar.js +73 -44
- package/dist/src/research/identity.js +117 -0
- package/dist/src/research/index.js +1 -0
- package/dist/src/research/query-cli.js +3 -87
- package/dist/src/research/query-options.js +87 -0
- package/dist/src/research/reference-match.js +135 -0
- package/dist/src/research/services/acquisition.js +9 -7
- package/dist/src/research/services/citation.js +5 -2
- package/dist/src/research/types.js +2 -0
- package/dist/src/rules/core-startup.d.mts +2 -0
- package/dist/src/rules/core-startup.mjs +31 -0
- package/dist/src/serve/mission-conductor.js +48 -4
- package/dist/src/sessions/adapters/grok-build-native.js +23 -0
- package/dist/src/sessions/adapters/grok-build.js +14 -7
- package/dist/src/sessions/workspace-discovery.js +5 -5
- package/dist/src/smiths/context-pipeline/agents-md.js +34 -0
- package/dist/src/smiths/context-pipeline/aiwg-md.js +19 -46
- package/dist/src/smiths/context-pipeline/bridge-ownership.js +50 -0
- package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
- package/dist/src/smiths/context-pipeline/finalization.js +81 -51
- package/dist/src/smiths/context-pipeline/generator.js +49 -114
- package/dist/src/smiths/context-pipeline/managed-hook.js +11 -1
- package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
- package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
- package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
- package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
- package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
- package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
- package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
- package/package.json +13 -2
- package/schemas/decision/D29Study.v10.schema.json +65 -0
- package/tools/agents/deploy-agents.mjs +12 -123
- package/tools/agents/providers/antigravity.mjs +1 -1
- package/tools/agents/providers/claude-post-deploy.mjs +12 -1
- package/tools/agents/providers/context-write.mjs +16 -0
- package/tools/agents/providers/grok-build.mjs +8 -5
- package/tools/agents/providers/hermes-skill-lifecycle.mjs +144 -0
- package/tools/agents/providers/hermes-startup.mjs +209 -0
- package/tools/agents/providers/hermes.mjs +9 -359
- package/tools/agents/providers/model-wrapper.mjs +5 -1
- package/tools/agents/providers/muse.mjs +3 -3
- package/tools/agents/providers/pi.mjs +4 -2
- package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
- package/tools/agents/providers/rule-delivery.mjs +20 -1346
- package/tools/agents/providers/rule-deployment-commit.mjs +144 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +452 -0
- package/tools/agents/providers/rule-deployment-state.mjs +300 -0
- package/tools/agents/providers/rule-presentation.mjs +13 -4
- package/tools/agents/providers/rule-projection.mjs +119 -0
- package/tools/agents/providers/rule-startup.mjs +70 -0
- package/tools/agents/providers/stale-artifact-prune.mjs +128 -0
- package/tools/agents/providers/warp.mjs +2 -2
- package/tools/agents/providers/windsurf.mjs +11 -57
- package/tools/daemon/README.md +511 -0
- package/tools/daemon/adapters/base-adapter.mjs +84 -0
- package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
- package/tools/daemon/agent-supervisor.mjs +299 -0
- package/tools/daemon/automation-engine.mjs +310 -0
- package/tools/daemon/autonomous-engine.mjs +346 -0
- package/tools/daemon/behavior-loader.mjs +316 -0
- package/tools/daemon/behavior.mjs +174 -0
- package/tools/daemon/concierge/intent-router.mjs +401 -0
- package/tools/daemon/concierge/orchestrator.mjs +272 -0
- package/tools/daemon/concierge/response-translator.mjs +462 -0
- package/tools/daemon/config.mjs +377 -0
- package/tools/daemon/cron-scheduler.mjs +178 -0
- package/tools/daemon/daemon-main.mjs +1169 -0
- package/tools/daemon/event-router.mjs +84 -0
- package/tools/daemon/file-watcher.mjs +383 -0
- package/tools/daemon/index.mjs +1181 -0
- package/tools/daemon/init-profile.mjs +124 -0
- package/tools/daemon/ipc-client.mjs +197 -0
- package/tools/daemon/ipc-ops-handlers.mjs +236 -0
- package/tools/daemon/ipc-server.mjs +275 -0
- package/tools/daemon/maintenance-owner.mjs +79 -0
- package/tools/daemon/memory-manager.mjs +386 -0
- package/tools/daemon/message-router.mjs +194 -0
- package/tools/daemon/provider-watcher.mjs +585 -0
- package/tools/daemon/pty-adapter.mjs +420 -0
- package/tools/daemon/repl-chat.mjs +359 -0
- package/tools/daemon/resource-bounds.mjs +88 -0
- package/tools/daemon/sandbox-transport.mjs +295 -0
- package/tools/daemon/scheduled-task-runner.mjs +535 -0
- package/tools/daemon/task-store.mjs +450 -0
- package/tools/daemon/tmux-manager.mjs +324 -0
- package/tools/daemon/update-policy.mjs +517 -0
- package/tools/daemon/web-server.mjs +399 -0
- package/tools/daemon/web-ui/index.html +585 -0
- package/tools/daemon/web-ui/styles.css +156 -0
- package/tools/docker/Dockerfile.daemon +35 -0
- package/tools/docker/container-manager.mjs +291 -0
- package/tools/messaging/adapter-registry.mjs +230 -0
- package/tools/messaging/adapters/base.mjs +326 -0
- package/tools/messaging/adapters/discord.mjs +462 -0
- package/tools/messaging/adapters/slack.mjs +402 -0
- package/tools/messaging/adapters/telegram.mjs +552 -0
- package/tools/messaging/chat-handler.mjs +297 -0
- package/tools/messaging/command-router.mjs +269 -0
- package/tools/messaging/event-bus.mjs +199 -0
- package/tools/messaging/index.mjs +456 -0
- package/tools/messaging/message-formatter.mjs +320 -0
- package/tools/messaging/room-manager.mjs +277 -0
- package/tools/messaging/types.mjs +94 -0
- package/tools/plugin/plugin-links.mjs +3 -0
- package/tools/providers/pi-bridge-policy.mjs +4 -0
- package/tools/ralph-external/daemon-supervisor.mjs +394 -0
- package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +3 -2
- package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
- package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
- package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
- package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
- package/tools/ralph-external/session-launcher.mjs +7 -7
- package/tools/scripts/resource-preflight.mjs +3 -242
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DaemonBehaviorLoader — discovers, loads, and activates daemon behaviors.
|
|
3
|
+
*
|
|
4
|
+
* Behaviors are BEHAVIOR.md (or .behavior.md) files with YAML frontmatter.
|
|
5
|
+
* The canonical shape (per #1025) nests behavior fields under `metadata:`:
|
|
6
|
+
*
|
|
7
|
+
* ---
|
|
8
|
+
* name: my-behavior
|
|
9
|
+
* module: tools/daemon/my-behavior/orchestrator.mjs
|
|
10
|
+
* metadata:
|
|
11
|
+
* scope: daemon
|
|
12
|
+
* triggers: [session-start, pre-response, on-error, chat-message]
|
|
13
|
+
* ---
|
|
14
|
+
*
|
|
15
|
+
* - `name` and `module` stay at top level.
|
|
16
|
+
* - `scope` and `triggers` (plural) live inside `metadata:` so they share
|
|
17
|
+
* shape with the validator (see src/plugin/metadata-validator.ts:604).
|
|
18
|
+
*
|
|
19
|
+
* The module must export a class with a standard interface:
|
|
20
|
+
* - constructor(options) — receives { supervisor, memoryManager, provider, config }
|
|
21
|
+
* - onSessionStart(ctx) — called on session-start trigger (optional)
|
|
22
|
+
* - handleMessage(msg, ctx) — called on chat-message trigger (optional)
|
|
23
|
+
* - translateResponse(raw) — called on pre-response trigger (optional)
|
|
24
|
+
* - onError(error, ctx) — called on on-error trigger (optional)
|
|
25
|
+
* - getStatus() — returns status object for IPC (optional)
|
|
26
|
+
*
|
|
27
|
+
* Discovery tiers (later overrides earlier):
|
|
28
|
+
* 1. agentic/code/addons/\*\/behaviors/ — addon-shipped
|
|
29
|
+
* 2. .aiwg/behaviors/ — project-local
|
|
30
|
+
*
|
|
31
|
+
* @issue #642
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
35
|
+
import { join, resolve } from 'node:path';
|
|
36
|
+
import yaml from 'js-yaml';
|
|
37
|
+
|
|
38
|
+
export class DaemonBehaviorLoader {
|
|
39
|
+
/**
|
|
40
|
+
* @param {Object} options
|
|
41
|
+
* @param {string} options.projectRoot Project root directory
|
|
42
|
+
* @param {Object} options.supervisor AgentSupervisor instance
|
|
43
|
+
* @param {Object} [options.memoryManager] MemoryManager instance
|
|
44
|
+
* @param {string} [options.provider] Current provider key
|
|
45
|
+
* @param {Object} [options.config] Daemon config accessor
|
|
46
|
+
*/
|
|
47
|
+
constructor(options = {}) {
|
|
48
|
+
this.projectRoot = options.projectRoot || process.cwd();
|
|
49
|
+
this.supervisor = options.supervisor;
|
|
50
|
+
this.memoryManager = options.memoryManager || null;
|
|
51
|
+
this.provider = options.provider || null;
|
|
52
|
+
this.config = options.config || null;
|
|
53
|
+
|
|
54
|
+
/** @type {Map<string, LoadedBehavior>} */
|
|
55
|
+
this._active = new Map();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Discover all .behavior.md files across addon and project tiers.
|
|
60
|
+
* @returns {Promise<DiscoveredBehavior[]>}
|
|
61
|
+
*/
|
|
62
|
+
async discover() {
|
|
63
|
+
const discovered = [];
|
|
64
|
+
|
|
65
|
+
// Tier 1: addon behaviors
|
|
66
|
+
const addonsDir = join(this.projectRoot, 'agentic', 'code', 'addons');
|
|
67
|
+
try {
|
|
68
|
+
const addons = await readdir(addonsDir);
|
|
69
|
+
for (const addon of addons) {
|
|
70
|
+
const behaviorsDir = join(addonsDir, addon, 'behaviors');
|
|
71
|
+
try {
|
|
72
|
+
const files = await readdir(behaviorsDir);
|
|
73
|
+
for (const file of files.filter(f => f.endsWith('.behavior.md'))) {
|
|
74
|
+
discovered.push({ tier: 'addon', addon, path: join(behaviorsDir, file), file });
|
|
75
|
+
}
|
|
76
|
+
} catch { /* no behaviors dir — skip */ }
|
|
77
|
+
}
|
|
78
|
+
} catch { /* no addons dir — skip */ }
|
|
79
|
+
|
|
80
|
+
// Tier 2: project-local behaviors (override addon)
|
|
81
|
+
const projectBehaviors = join(this.projectRoot, '.aiwg', 'behaviors');
|
|
82
|
+
try {
|
|
83
|
+
const files = await readdir(projectBehaviors);
|
|
84
|
+
for (const file of files.filter(f => f.endsWith('.behavior.md'))) {
|
|
85
|
+
discovered.push({ tier: 'project', addon: null, path: join(projectBehaviors, file), file });
|
|
86
|
+
}
|
|
87
|
+
} catch { /* no project behaviors — skip */ }
|
|
88
|
+
|
|
89
|
+
return discovered;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Parse YAML frontmatter from a BEHAVIOR.md file.
|
|
94
|
+
*
|
|
95
|
+
* Uses js-yaml for full YAML support, including nested mappings —
|
|
96
|
+
* required for the canonical metadata.* shape (#1025).
|
|
97
|
+
*
|
|
98
|
+
* @param {string} filePath
|
|
99
|
+
* @returns {Promise<Object|null>}
|
|
100
|
+
*/
|
|
101
|
+
async parseFrontmatter(filePath) {
|
|
102
|
+
const content = await readFile(filePath, 'utf-8');
|
|
103
|
+
const match = content.match(/^---\n([\s\S]*?)\n---/);
|
|
104
|
+
if (!match) return null;
|
|
105
|
+
|
|
106
|
+
let parsed;
|
|
107
|
+
try {
|
|
108
|
+
parsed = yaml.load(match[1]);
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return (parsed && typeof parsed === 'object') ? parsed : null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Load and activate all discovered daemon-scoped behaviors.
|
|
117
|
+
* @returns {Promise<Map<string, LoadedBehavior>>}
|
|
118
|
+
*/
|
|
119
|
+
async loadAll() {
|
|
120
|
+
const discovered = await this.discover();
|
|
121
|
+
|
|
122
|
+
// Group by name — later tiers override earlier
|
|
123
|
+
const byName = new Map();
|
|
124
|
+
for (const entry of discovered) {
|
|
125
|
+
try {
|
|
126
|
+
const meta = await this.parseFrontmatter(entry.path);
|
|
127
|
+
if (!meta || meta.metadata?.scope !== 'daemon') continue;
|
|
128
|
+
if (!meta.name) continue;
|
|
129
|
+
if (!meta.module) {
|
|
130
|
+
// No module = prompt-only behavior (no orchestrator to load)
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
byName.set(meta.name, { ...entry, meta });
|
|
134
|
+
} catch (err) {
|
|
135
|
+
// Skip unparseable behaviors
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Activate each behavior
|
|
140
|
+
for (const [name, entry] of byName) {
|
|
141
|
+
try {
|
|
142
|
+
const orchestrator = await this._activate(entry);
|
|
143
|
+
if (orchestrator) {
|
|
144
|
+
this._active.set(name, {
|
|
145
|
+
name,
|
|
146
|
+
meta: entry.meta,
|
|
147
|
+
orchestrator,
|
|
148
|
+
path: entry.path,
|
|
149
|
+
tier: entry.tier,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
} catch (err) {
|
|
153
|
+
// Non-fatal — log but continue
|
|
154
|
+
console.warn(`Behavior '${name}' activation failed: ${err.message}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return this._active;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Dynamically import and instantiate a behavior's orchestrator module.
|
|
163
|
+
* @param {Object} entry Discovered behavior entry with meta
|
|
164
|
+
* @returns {Promise<Object|null>}
|
|
165
|
+
*/
|
|
166
|
+
async _activate(entry) {
|
|
167
|
+
const modulePath = entry.meta.module;
|
|
168
|
+
|
|
169
|
+
// Resolve module path relative to project root
|
|
170
|
+
const resolved = resolve(this.projectRoot, modulePath);
|
|
171
|
+
const mod = await import(resolved);
|
|
172
|
+
|
|
173
|
+
// Find the exported class — look for default export or first class export
|
|
174
|
+
const OrchestratorClass = mod.default || Object.values(mod).find(v => typeof v === 'function');
|
|
175
|
+
if (!OrchestratorClass) {
|
|
176
|
+
throw new Error(`No class exported from ${modulePath}`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return new OrchestratorClass({
|
|
180
|
+
supervisor: this.supervisor,
|
|
181
|
+
memoryManager: this.memoryManager,
|
|
182
|
+
provider: this.provider,
|
|
183
|
+
config: this.config,
|
|
184
|
+
behaviorMeta: entry.meta,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Hot-apply a behavior by name — discovers it on disk and activates it.
|
|
190
|
+
* If a behavior with the same name is already active, it is replaced.
|
|
191
|
+
*
|
|
192
|
+
* @param {string} name Behavior name to apply
|
|
193
|
+
* @returns {Promise<{applied: boolean, name: string}>}
|
|
194
|
+
* @throws {Error} If the behavior is not found in any discovery tier
|
|
195
|
+
*/
|
|
196
|
+
async apply(name) {
|
|
197
|
+
// Discover all available behaviors
|
|
198
|
+
const discovered = await this.discover();
|
|
199
|
+
|
|
200
|
+
// Find matching entry by name
|
|
201
|
+
let matchedEntry = null;
|
|
202
|
+
for (const entry of discovered) {
|
|
203
|
+
try {
|
|
204
|
+
const meta = await this.parseFrontmatter(entry.path);
|
|
205
|
+
if (!meta || meta.metadata?.scope !== 'daemon') continue;
|
|
206
|
+
if (!meta.name || meta.name !== name) continue;
|
|
207
|
+
if (!meta.module) continue;
|
|
208
|
+
matchedEntry = { ...entry, meta };
|
|
209
|
+
break;
|
|
210
|
+
} catch { /* skip */ }
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!matchedEntry) {
|
|
214
|
+
throw new Error(`Behavior '${name}' not found or is not a daemon-scoped behavior with a module`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Deactivate existing instance if present
|
|
218
|
+
this._active.delete(name);
|
|
219
|
+
|
|
220
|
+
// Activate the new instance
|
|
221
|
+
const orchestrator = await this._activate(matchedEntry);
|
|
222
|
+
if (!orchestrator) {
|
|
223
|
+
throw new Error(`Behavior '${name}' activation returned null`);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
this._active.set(name, {
|
|
227
|
+
name,
|
|
228
|
+
meta: matchedEntry.meta,
|
|
229
|
+
orchestrator,
|
|
230
|
+
path: matchedEntry.path,
|
|
231
|
+
tier: matchedEntry.tier,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return { applied: true, name };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Remove an active behavior by name.
|
|
239
|
+
* If the orchestrator exposes a `deactivate()` method, it is called first.
|
|
240
|
+
*
|
|
241
|
+
* @param {string} name Behavior name to remove
|
|
242
|
+
* @returns {{ removed: boolean, name: string }}
|
|
243
|
+
*/
|
|
244
|
+
remove(name) {
|
|
245
|
+
const loaded = this._active.get(name);
|
|
246
|
+
if (!loaded) {
|
|
247
|
+
return { removed: false, name };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Call optional cleanup hook
|
|
251
|
+
try {
|
|
252
|
+
if (typeof loaded.orchestrator.deactivate === 'function') {
|
|
253
|
+
loaded.orchestrator.deactivate();
|
|
254
|
+
}
|
|
255
|
+
} catch { /* non-fatal */ }
|
|
256
|
+
|
|
257
|
+
this._active.delete(name);
|
|
258
|
+
return { removed: true, name };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Get the active behavior orchestrator for a given trigger type.
|
|
263
|
+
* Returns all behaviors that declare this trigger.
|
|
264
|
+
* @param {string} trigger e.g. 'chat-message', 'session-start', 'pre-response', 'on-error'
|
|
265
|
+
* @returns {Object[]} Array of orchestrator instances
|
|
266
|
+
*/
|
|
267
|
+
getForTrigger(trigger) {
|
|
268
|
+
const result = [];
|
|
269
|
+
for (const [, loaded] of this._active) {
|
|
270
|
+
const triggers = loaded.meta.metadata?.triggers || [];
|
|
271
|
+
if (triggers.includes(trigger)) {
|
|
272
|
+
result.push(loaded.orchestrator);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Get a specific active behavior by name.
|
|
280
|
+
* @param {string} name
|
|
281
|
+
* @returns {Object|null}
|
|
282
|
+
*/
|
|
283
|
+
get(name) {
|
|
284
|
+
return this._active.get(name)?.orchestrator || null;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Check if a behavior is active.
|
|
289
|
+
* @param {string} name
|
|
290
|
+
* @returns {boolean}
|
|
291
|
+
*/
|
|
292
|
+
has(name) {
|
|
293
|
+
return this._active.has(name);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Get status summary for IPC/CLI. */
|
|
297
|
+
getStatus() {
|
|
298
|
+
return {
|
|
299
|
+
active: Object.fromEntries(
|
|
300
|
+
[...this._active].map(([name, loaded]) => [
|
|
301
|
+
name,
|
|
302
|
+
{
|
|
303
|
+
triggers: loaded.meta.metadata?.triggers || [],
|
|
304
|
+
module: loaded.meta.module,
|
|
305
|
+
tier: loaded.tier,
|
|
306
|
+
path: loaded.path,
|
|
307
|
+
hasStatus: typeof loaded.orchestrator.getStatus === 'function',
|
|
308
|
+
},
|
|
309
|
+
])
|
|
310
|
+
),
|
|
311
|
+
count: this._active.size,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export default DaemonBehaviorLoader;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Behavior management CLI
|
|
5
|
+
*
|
|
6
|
+
* Manage behavior YAML bundles that bind directives and toolsets to agent types.
|
|
7
|
+
* Usage: aiwg behavior <list|info|apply|remove> [name] [options]
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import fs from 'fs';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import { fileURLToPath } from 'url';
|
|
13
|
+
import { createClient } from './ipc-client.mjs';
|
|
14
|
+
|
|
15
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const repoRoot = path.join(__dirname, '..', '..');
|
|
17
|
+
|
|
18
|
+
const SOCKET_PATH = '.aiwg/daemon/daemon.sock';
|
|
19
|
+
|
|
20
|
+
const args = process.argv.slice(2);
|
|
21
|
+
const subcommand = args[0];
|
|
22
|
+
const name = args[1];
|
|
23
|
+
|
|
24
|
+
function getBehaviorDirs() {
|
|
25
|
+
const dirs = [];
|
|
26
|
+
|
|
27
|
+
// Cross-framework behaviors
|
|
28
|
+
const globalDir = path.join(repoRoot, 'agentic', 'code', 'behaviors');
|
|
29
|
+
if (fs.existsSync(globalDir)) {
|
|
30
|
+
for (const entry of fs.readdirSync(globalDir, { withFileTypes: true })) {
|
|
31
|
+
if (entry.isDirectory() && fs.existsSync(path.join(globalDir, entry.name, 'BEHAVIOR.md'))) {
|
|
32
|
+
dirs.push({ name: entry.name, path: path.join(globalDir, entry.name), scope: 'global' });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Per-framework behaviors
|
|
38
|
+
const frameworksDir = path.join(repoRoot, 'agentic', 'code', 'frameworks');
|
|
39
|
+
if (fs.existsSync(frameworksDir)) {
|
|
40
|
+
for (const fw of fs.readdirSync(frameworksDir, { withFileTypes: true })) {
|
|
41
|
+
if (!fw.isDirectory()) continue;
|
|
42
|
+
const fwBehaviorsDir = path.join(frameworksDir, fw.name, 'behaviors');
|
|
43
|
+
if (!fs.existsSync(fwBehaviorsDir)) continue;
|
|
44
|
+
for (const entry of fs.readdirSync(fwBehaviorsDir, { withFileTypes: true })) {
|
|
45
|
+
if (entry.isDirectory() && fs.existsSync(path.join(fwBehaviorsDir, entry.name, 'BEHAVIOR.md'))) {
|
|
46
|
+
dirs.push({ name: entry.name, path: path.join(fwBehaviorsDir, entry.name), scope: fw.name });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return dirs;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function listBehaviors() {
|
|
56
|
+
const behaviors = getBehaviorDirs();
|
|
57
|
+
if (behaviors.length === 0) {
|
|
58
|
+
console.log('No behaviors found.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
console.log(`\nBehaviors (${behaviors.length}):\n`);
|
|
63
|
+
for (const b of behaviors) {
|
|
64
|
+
console.log(` ${b.name} (${b.scope})`);
|
|
65
|
+
}
|
|
66
|
+
console.log('');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function infoBehavior(behaviorName) {
|
|
70
|
+
if (!behaviorName) {
|
|
71
|
+
console.error('Usage: aiwg behavior info <name>');
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const behaviors = getBehaviorDirs();
|
|
76
|
+
const found = behaviors.find(b => b.name === behaviorName);
|
|
77
|
+
if (!found) {
|
|
78
|
+
console.error(`Behavior not found: ${behaviorName}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const content = fs.readFileSync(path.join(found.path, 'BEHAVIOR.md'), 'utf-8');
|
|
83
|
+
console.log(content);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function printHelp() {
|
|
87
|
+
console.log(`
|
|
88
|
+
Usage: aiwg behavior <subcommand> [name] [options]
|
|
89
|
+
|
|
90
|
+
Subcommands:
|
|
91
|
+
list List all available behaviors
|
|
92
|
+
info <name> Show behavior details (BEHAVIOR.md)
|
|
93
|
+
apply <name> Apply a behavior to the daemon (not yet implemented)
|
|
94
|
+
remove <name> Remove a behavior from the daemon (not yet implemented)
|
|
95
|
+
|
|
96
|
+
Examples:
|
|
97
|
+
aiwg behavior list
|
|
98
|
+
aiwg behavior info security-sentinel
|
|
99
|
+
`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function applyBehavior(behaviorName) {
|
|
103
|
+
if (!behaviorName) {
|
|
104
|
+
console.error('Usage: aiwg behavior apply <name>');
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let client;
|
|
109
|
+
try {
|
|
110
|
+
client = await createClient(SOCKET_PATH);
|
|
111
|
+
const result = await client.call('behaviors.apply', { name: behaviorName });
|
|
112
|
+
console.log(`Behavior applied: ${result.name}`);
|
|
113
|
+
} catch (err) {
|
|
114
|
+
if (err.message && err.message.includes('not running')) {
|
|
115
|
+
console.error('Daemon is not running. Start it with: aiwg daemon start');
|
|
116
|
+
} else {
|
|
117
|
+
console.error(`Failed to apply behavior '${behaviorName}': ${err.message}`);
|
|
118
|
+
}
|
|
119
|
+
process.exit(1);
|
|
120
|
+
} finally {
|
|
121
|
+
client?.disconnect();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function removeBehavior(behaviorName) {
|
|
126
|
+
if (!behaviorName) {
|
|
127
|
+
console.error('Usage: aiwg behavior remove <name>');
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let client;
|
|
132
|
+
try {
|
|
133
|
+
client = await createClient(SOCKET_PATH);
|
|
134
|
+
const result = await client.call('behaviors.remove', { name: behaviorName });
|
|
135
|
+
if (result.removed) {
|
|
136
|
+
console.log(`Behavior removed: ${result.name}`);
|
|
137
|
+
} else {
|
|
138
|
+
console.log(`Behavior '${behaviorName}' was not active`);
|
|
139
|
+
}
|
|
140
|
+
} catch (err) {
|
|
141
|
+
if (err.message && err.message.includes('not running')) {
|
|
142
|
+
console.error('Daemon is not running. Start it with: aiwg daemon start');
|
|
143
|
+
} else {
|
|
144
|
+
console.error(`Failed to remove behavior '${behaviorName}': ${err.message}`);
|
|
145
|
+
}
|
|
146
|
+
process.exit(1);
|
|
147
|
+
} finally {
|
|
148
|
+
client?.disconnect();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
switch (subcommand) {
|
|
153
|
+
case 'list':
|
|
154
|
+
listBehaviors();
|
|
155
|
+
break;
|
|
156
|
+
case 'info':
|
|
157
|
+
infoBehavior(name);
|
|
158
|
+
break;
|
|
159
|
+
case 'apply':
|
|
160
|
+
applyBehavior(name);
|
|
161
|
+
break;
|
|
162
|
+
case 'remove':
|
|
163
|
+
removeBehavior(name);
|
|
164
|
+
break;
|
|
165
|
+
case '--help':
|
|
166
|
+
case '-h':
|
|
167
|
+
case undefined:
|
|
168
|
+
printHelp();
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
console.error(`Unknown subcommand: ${subcommand}`);
|
|
172
|
+
printHelp();
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|