agentweaver 0.1.16 → 0.1.17

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.
Files changed (40) hide show
  1. package/README.md +50 -10
  2. package/dist/artifacts.js +73 -3
  3. package/dist/doctor/checks/executors.js +2 -2
  4. package/dist/flow-state.js +138 -1
  5. package/dist/index.js +175 -61
  6. package/dist/interactive/controller.js +56 -23
  7. package/dist/interactive/ink/index.js +22 -1
  8. package/dist/interactive/tree.js +2 -2
  9. package/dist/pipeline/auto-flow.js +9 -6
  10. package/dist/pipeline/context.js +6 -5
  11. package/dist/pipeline/declarative-flows.js +39 -20
  12. package/dist/pipeline/flow-catalog.js +36 -14
  13. package/dist/pipeline/flow-specs/auto-common.json +1 -0
  14. package/dist/pipeline/flow-specs/auto-golang.json +27 -1
  15. package/dist/pipeline/flow-specs/design-review/design-review-loop.json +13 -1
  16. package/dist/pipeline/flow-specs/plan.json +4 -2
  17. package/dist/pipeline/launch-profile-config.js +30 -18
  18. package/dist/pipeline/node-contract.js +1 -0
  19. package/dist/pipeline/node-registry.js +74 -5
  20. package/dist/pipeline/nodes/flow-run-node.js +188 -173
  21. package/dist/pipeline/nodes/llm-prompt-node.js +15 -33
  22. package/dist/pipeline/plugin-loader.js +389 -0
  23. package/dist/pipeline/plugin-types.js +1 -0
  24. package/dist/pipeline/registry.js +71 -4
  25. package/dist/pipeline/spec-compiler.js +1 -0
  26. package/dist/pipeline/spec-loader.js +14 -0
  27. package/dist/pipeline/spec-validator.js +6 -0
  28. package/dist/pipeline/value-resolver.js +2 -1
  29. package/dist/plugin-sdk.js +1 -0
  30. package/dist/runtime/artifact-registry.js +3 -0
  31. package/dist/runtime/execution-routing.js +25 -19
  32. package/dist/runtime/interactive-execution-routing.js +66 -57
  33. package/docs/example/.flows/examples/claude-example.json +50 -0
  34. package/docs/example/.plugins/claude-example-plugin/index.js +149 -0
  35. package/docs/example/.plugins/claude-example-plugin/plugin.json +8 -0
  36. package/docs/examples/.flows/claude-example.json +50 -0
  37. package/docs/examples/.plugins/claude-example-plugin/index.js +149 -0
  38. package/docs/examples/.plugins/claude-example-plugin/plugin.json +8 -0
  39. package/docs/plugin-sdk.md +731 -0
  40. package/package.json +6 -2
@@ -0,0 +1,149 @@
1
+ import { AGENTWEAVER_PLUGIN_SDK_VERSION } from "agentweaver/plugin-sdk";
2
+
3
+ export const CLAUDE_EXAMPLE_PLUGIN_SDK_VERSION = AGENTWEAVER_PLUGIN_SDK_VERSION;
4
+ export const CLAUDE_EXECUTOR_ID = "claude";
5
+ export const CLAUDE_AUTH_STATUS_ERROR = "Claude CLI authentication is required. Run 'claude auth status' and sign in before using the example flow.";
6
+ export const CLAUDE_NORMALIZATION_ERROR =
7
+ "Claude JSON normalization failed: no supported assistant text was found in result, message.content[*].text, or content[*].text.";
8
+
9
+ function nonEmptyString(value) {
10
+ return typeof value === "string" && value.trim().length > 0 ? value : null;
11
+ }
12
+
13
+ function resolveSetting(override, env, envKey, defaultValue) {
14
+ const direct = nonEmptyString(typeof override === "number" ? String(override) : override);
15
+ if (direct) {
16
+ return direct;
17
+ }
18
+ const fromEnv = nonEmptyString(env?.[envKey]);
19
+ if (fromEnv) {
20
+ return fromEnv;
21
+ }
22
+ return nonEmptyString(defaultValue);
23
+ }
24
+
25
+ function resolveStringListSetting(override, env, envKey, defaultValue) {
26
+ const direct = nonEmptyString(override);
27
+ const envValue = nonEmptyString(env?.[envKey]);
28
+ const effective = direct ?? envValue ?? nonEmptyString(defaultValue);
29
+ if (!effective) {
30
+ return [];
31
+ }
32
+ return effective
33
+ .split(/[,\s]+/)
34
+ .map((item) => item.trim())
35
+ .filter((item) => item.length > 0);
36
+ }
37
+
38
+ function extractTextFragments(items) {
39
+ if (!Array.isArray(items)) {
40
+ return null;
41
+ }
42
+ const fragments = items
43
+ .map((item) => (item && typeof item === "object" ? item.text : undefined))
44
+ .filter((text) => typeof text === "string" && text.trim().length > 0);
45
+ return fragments.length > 0 ? fragments.join("\n") : null;
46
+ }
47
+
48
+ export function normalizeClaudePayload(payload, effectiveModel = "") {
49
+ const resultText = nonEmptyString(payload?.result);
50
+ const messageContentText = extractTextFragments(payload?.message?.content);
51
+ const contentText = extractTextFragments(payload?.content);
52
+ const output = resultText ?? messageContentText ?? contentText;
53
+ if (!output) {
54
+ throw new Error(CLAUDE_NORMALIZATION_ERROR);
55
+ }
56
+ return {
57
+ output,
58
+ model: nonEmptyString(payload?.model) ?? effectiveModel,
59
+ rawResponse: payload,
60
+ };
61
+ }
62
+
63
+ export async function verifyClaudeAuth(runtime, env, config) {
64
+ const command = runtime.resolveCmd(config.defaultCommand, config.commandEnvVar);
65
+ try {
66
+ await runtime.runCommand([command, "auth", "status"], {
67
+ env,
68
+ label: "claude:auth-status",
69
+ printFailureOutput: false,
70
+ });
71
+ } catch {
72
+ throw new Error(CLAUDE_AUTH_STATUS_ERROR);
73
+ }
74
+ return command;
75
+ }
76
+
77
+ export const claudeExecutorDefinition = {
78
+ kind: CLAUDE_EXECUTOR_ID,
79
+ version: 1,
80
+ defaultConfig: {
81
+ commandEnvVar: "CLAUDE_BIN",
82
+ defaultCommand: "claude",
83
+ modelEnvVar: "CLAUDE_MODEL",
84
+ defaultModel: "",
85
+ maxTurnsEnvVar: "CLAUDE_MAX_TURNS",
86
+ defaultMaxTurns: "",
87
+ permissionModeEnvVar: "CLAUDE_PERMISSION_MODE",
88
+ defaultPermissionMode: "bypassPermissions",
89
+ allowedToolsEnvVar: "CLAUDE_ALLOWED_TOOLS",
90
+ defaultAllowedTools: "",
91
+ disallowedToolsEnvVar: "CLAUDE_DISALLOWED_TOOLS",
92
+ defaultDisallowedTools: "",
93
+ addCwdAsAllowedDir: true,
94
+ },
95
+ async execute(context, input, config) {
96
+ const env = input?.env ?? context.env;
97
+ const command = input?.command ?? context.runtime.resolveCmd(config.defaultCommand, config.commandEnvVar);
98
+ const effectiveModel = resolveSetting(input?.model, env, config.modelEnvVar, config.defaultModel);
99
+ const effectiveMaxTurns = resolveSetting(input?.maxTurns, env, config.maxTurnsEnvVar, config.defaultMaxTurns);
100
+ const permissionMode = resolveSetting(undefined, env, config.permissionModeEnvVar, config.defaultPermissionMode);
101
+ const allowedTools = resolveStringListSetting(undefined, env, config.allowedToolsEnvVar, config.defaultAllowedTools);
102
+ const disallowedTools = resolveStringListSetting(undefined, env, config.disallowedToolsEnvVar, config.defaultDisallowedTools);
103
+ const argv = [
104
+ command,
105
+ "-p",
106
+ String(input?.prompt ?? ""),
107
+ "--output-format",
108
+ "json",
109
+ ...(config.addCwdAsAllowedDir ? ["--add-dir", context.cwd] : []),
110
+ ...(permissionMode ? ["--permission-mode", permissionMode] : []),
111
+ ...(allowedTools.length > 0 ? ["--allowedTools", ...allowedTools] : []),
112
+ ...(disallowedTools.length > 0 ? ["--disallowedTools", ...disallowedTools] : []),
113
+ ...(effectiveModel ? ["--model", effectiveModel] : []),
114
+ ...(effectiveMaxTurns ? ["--max-turns", effectiveMaxTurns] : []),
115
+ ];
116
+ const stdout = await context.runtime.runCommand(argv, {
117
+ env,
118
+ dryRun: context.dryRun,
119
+ verbose: context.verbose,
120
+ label: `claude:${effectiveModel || "default"}`,
121
+ printFailureOutput: true,
122
+ });
123
+ let payload;
124
+ try {
125
+ payload = JSON.parse(stdout);
126
+ } catch (error) {
127
+ throw new Error(`Claude CLI returned invalid JSON: ${error.message}`);
128
+ }
129
+ const normalized = normalizeClaudePayload(payload, effectiveModel ?? "");
130
+ return {
131
+ output: normalized.output,
132
+ command,
133
+ model: normalized.model ?? "",
134
+ rawResponse: normalized.rawResponse,
135
+ };
136
+ },
137
+ };
138
+
139
+ export const executors = [
140
+ {
141
+ id: CLAUDE_EXECUTOR_ID,
142
+ definition: claudeExecutorDefinition,
143
+ routing: {
144
+ kind: "llm",
145
+ defaultModel: "sonnet",
146
+ models: ["sonnet", "opus", "haiku"],
147
+ },
148
+ },
149
+ ];
@@ -0,0 +1,8 @@
1
+ {
2
+ "id": "claude-example-plugin",
3
+ "sdk_version": 1,
4
+ "entrypoint": "index.js",
5
+ "name": "Claude Example Plugin",
6
+ "version": "0.1.0",
7
+ "description": "Project-local Claude CLI reference plugin for AgentWeaver."
8
+ }