clinkx 0.2.0 → 0.2.1

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 (149) hide show
  1. package/clinkx-workflows/dist/artifacts.d.ts +65 -0
  2. package/clinkx-workflows/dist/artifacts.js +268 -0
  3. package/clinkx-workflows/dist/artifacts.js.map +1 -0
  4. package/clinkx-workflows/dist/backend.d.ts +33 -0
  5. package/clinkx-workflows/dist/backend.js +9 -0
  6. package/clinkx-workflows/dist/backend.js.map +1 -0
  7. package/clinkx-workflows/dist/child-env.d.ts +23 -0
  8. package/clinkx-workflows/dist/child-env.js +53 -0
  9. package/clinkx-workflows/dist/child-env.js.map +1 -0
  10. package/clinkx-workflows/dist/clink-client.d.ts +51 -0
  11. package/clinkx-workflows/dist/clink-client.js +216 -0
  12. package/clinkx-workflows/dist/clink-client.js.map +1 -0
  13. package/clinkx-workflows/dist/config.d.ts +126 -0
  14. package/clinkx-workflows/dist/config.js +226 -0
  15. package/clinkx-workflows/dist/config.js.map +1 -0
  16. package/clinkx-workflows/dist/definition-normalizer.d.ts +59 -0
  17. package/clinkx-workflows/dist/definition-normalizer.js +75 -0
  18. package/clinkx-workflows/dist/definition-normalizer.js.map +1 -0
  19. package/clinkx-workflows/dist/engine.d.ts +235 -0
  20. package/clinkx-workflows/dist/engine.js +1044 -0
  21. package/clinkx-workflows/dist/engine.js.map +1 -0
  22. package/clinkx-workflows/dist/errors.d.ts +74 -0
  23. package/clinkx-workflows/dist/errors.js +84 -0
  24. package/clinkx-workflows/dist/errors.js.map +1 -0
  25. package/clinkx-workflows/dist/fidelity.d.ts +112 -0
  26. package/clinkx-workflows/dist/fidelity.js +140 -0
  27. package/clinkx-workflows/dist/fidelity.js.map +1 -0
  28. package/clinkx-workflows/dist/fingerprint.d.ts +69 -0
  29. package/clinkx-workflows/dist/fingerprint.js +143 -0
  30. package/clinkx-workflows/dist/fingerprint.js.map +1 -0
  31. package/clinkx-workflows/dist/index.d.ts +16 -0
  32. package/clinkx-workflows/dist/index.js +42 -0
  33. package/clinkx-workflows/dist/index.js.map +1 -0
  34. package/clinkx-workflows/dist/loader.d.ts +64 -0
  35. package/clinkx-workflows/dist/loader.js +371 -0
  36. package/clinkx-workflows/dist/loader.js.map +1 -0
  37. package/clinkx-workflows/dist/logger.d.ts +16 -0
  38. package/clinkx-workflows/dist/logger.js +31 -0
  39. package/clinkx-workflows/dist/logger.js.map +1 -0
  40. package/clinkx-workflows/dist/path-validation.d.ts +23 -0
  41. package/clinkx-workflows/dist/path-validation.js +73 -0
  42. package/clinkx-workflows/dist/path-validation.js.map +1 -0
  43. package/clinkx-workflows/dist/prompt-budget.d.ts +31 -0
  44. package/clinkx-workflows/dist/prompt-budget.js +78 -0
  45. package/clinkx-workflows/dist/prompt-budget.js.map +1 -0
  46. package/clinkx-workflows/dist/queue.d.ts +16 -0
  47. package/clinkx-workflows/dist/queue.js +46 -0
  48. package/clinkx-workflows/dist/queue.js.map +1 -0
  49. package/clinkx-workflows/dist/ranking-reducer.d.ts +11 -0
  50. package/clinkx-workflows/dist/ranking-reducer.js +245 -0
  51. package/clinkx-workflows/dist/ranking-reducer.js.map +1 -0
  52. package/clinkx-workflows/dist/reducers/index.d.ts +8 -0
  53. package/clinkx-workflows/dist/reducers/index.js +12 -0
  54. package/clinkx-workflows/dist/reducers/index.js.map +1 -0
  55. package/clinkx-workflows/dist/run-id.d.ts +17 -0
  56. package/clinkx-workflows/dist/run-id.js +26 -0
  57. package/clinkx-workflows/dist/run-id.js.map +1 -0
  58. package/clinkx-workflows/dist/run-summary/cards/council-answer.d.ts +8 -0
  59. package/clinkx-workflows/dist/run-summary/cards/council-answer.js +75 -0
  60. package/clinkx-workflows/dist/run-summary/cards/council-answer.js.map +1 -0
  61. package/clinkx-workflows/dist/run-summary/cards/council-code-review.d.ts +13 -0
  62. package/clinkx-workflows/dist/run-summary/cards/council-code-review.js +90 -0
  63. package/clinkx-workflows/dist/run-summary/cards/council-code-review.js.map +1 -0
  64. package/clinkx-workflows/dist/run-summary/cards/council-debug.d.ts +9 -0
  65. package/clinkx-workflows/dist/run-summary/cards/council-debug.js +79 -0
  66. package/clinkx-workflows/dist/run-summary/cards/council-debug.js.map +1 -0
  67. package/clinkx-workflows/dist/run-summary/cards/council-default.d.ts +11 -0
  68. package/clinkx-workflows/dist/run-summary/cards/council-default.js +57 -0
  69. package/clinkx-workflows/dist/run-summary/cards/council-default.js.map +1 -0
  70. package/clinkx-workflows/dist/run-summary/cards/council-discover.d.ts +10 -0
  71. package/clinkx-workflows/dist/run-summary/cards/council-discover.js +79 -0
  72. package/clinkx-workflows/dist/run-summary/cards/council-discover.js.map +1 -0
  73. package/clinkx-workflows/dist/run-summary/cards/generic.d.ts +2 -0
  74. package/clinkx-workflows/dist/run-summary/cards/generic.js +4 -0
  75. package/clinkx-workflows/dist/run-summary/cards/generic.js.map +1 -0
  76. package/clinkx-workflows/dist/run-summary/cards/index.d.ts +6 -0
  77. package/clinkx-workflows/dist/run-summary/cards/index.js +17 -0
  78. package/clinkx-workflows/dist/run-summary/cards/index.js.map +1 -0
  79. package/clinkx-workflows/dist/run-summary/utils.d.ts +6 -0
  80. package/clinkx-workflows/dist/run-summary/utils.js +30 -0
  81. package/clinkx-workflows/dist/run-summary/utils.js.map +1 -0
  82. package/clinkx-workflows/dist/run-summary-derived.d.ts +19 -0
  83. package/clinkx-workflows/dist/run-summary-derived.js +100 -0
  84. package/clinkx-workflows/dist/run-summary-derived.js.map +1 -0
  85. package/clinkx-workflows/dist/run-summary.d.ts +70 -0
  86. package/clinkx-workflows/dist/run-summary.js +125 -0
  87. package/clinkx-workflows/dist/run-summary.js.map +1 -0
  88. package/clinkx-workflows/dist/schema.d.ts +609 -0
  89. package/clinkx-workflows/dist/schema.js +123 -0
  90. package/clinkx-workflows/dist/schema.js.map +1 -0
  91. package/clinkx-workflows/dist/server.d.ts +16 -0
  92. package/clinkx-workflows/dist/server.js +33 -0
  93. package/clinkx-workflows/dist/server.js.map +1 -0
  94. package/clinkx-workflows/dist/shutdown.d.ts +54 -0
  95. package/clinkx-workflows/dist/shutdown.js +120 -0
  96. package/clinkx-workflows/dist/shutdown.js.map +1 -0
  97. package/clinkx-workflows/dist/state-schema.d.ts +141 -0
  98. package/clinkx-workflows/dist/state-schema.js +21 -0
  99. package/clinkx-workflows/dist/state-schema.js.map +1 -0
  100. package/clinkx-workflows/dist/state.d.ts +37 -0
  101. package/clinkx-workflows/dist/state.js +838 -0
  102. package/clinkx-workflows/dist/state.js.map +1 -0
  103. package/clinkx-workflows/dist/template-loader.d.ts +30 -0
  104. package/clinkx-workflows/dist/template-loader.js +77 -0
  105. package/clinkx-workflows/dist/template-loader.js.map +1 -0
  106. package/clinkx-workflows/dist/template.d.ts +54 -0
  107. package/clinkx-workflows/dist/template.js +128 -0
  108. package/clinkx-workflows/dist/template.js.map +1 -0
  109. package/clinkx-workflows/dist/transport.d.ts +91 -0
  110. package/clinkx-workflows/dist/transport.js +249 -0
  111. package/clinkx-workflows/dist/transport.js.map +1 -0
  112. package/clinkx-workflows/dist/types.d.ts +137 -0
  113. package/clinkx-workflows/dist/types.js +11 -0
  114. package/clinkx-workflows/dist/types.js.map +1 -0
  115. package/clinkx-workflows/dist/validators/council.d.ts +1488 -0
  116. package/clinkx-workflows/dist/validators/council.js +509 -0
  117. package/clinkx-workflows/dist/validators/council.js.map +1 -0
  118. package/clinkx-workflows/dist/validators/index.d.ts +40 -0
  119. package/clinkx-workflows/dist/validators/index.js +43 -0
  120. package/clinkx-workflows/dist/validators/index.js.map +1 -0
  121. package/clinkx-workflows/dist/workflow-receipt.d.ts +4 -0
  122. package/clinkx-workflows/dist/workflow-receipt.js +177 -0
  123. package/clinkx-workflows/dist/workflow-receipt.js.map +1 -0
  124. package/clinkx-workflows/dist/workflow-tools.d.ts +77 -0
  125. package/clinkx-workflows/dist/workflow-tools.js +1131 -0
  126. package/clinkx-workflows/dist/workflow-tools.js.map +1 -0
  127. package/clinkx-workflows/dist/workflows/council-default.d.ts +123 -0
  128. package/clinkx-workflows/dist/workflows/council-default.js +141 -0
  129. package/clinkx-workflows/dist/workflows/council-default.js.map +1 -0
  130. package/clinkx-workflows/dist/workflows/index.d.ts +12 -0
  131. package/clinkx-workflows/dist/workflows/index.js +15 -0
  132. package/clinkx-workflows/dist/workflows/index.js.map +1 -0
  133. package/conf/adapters/codex.json +2 -2
  134. package/conf/adapters/hapi/codex.json +2 -2
  135. package/dist/config.d.ts +5 -0
  136. package/dist/config.js +17 -0
  137. package/dist/config.js.map +1 -1
  138. package/dist/parsers/extract.d.ts +2 -0
  139. package/dist/parsers/extract.js +29 -20
  140. package/dist/parsers/extract.js.map +1 -1
  141. package/dist/pipeline.d.ts +2 -4
  142. package/dist/pipeline.js +93 -8
  143. package/dist/pipeline.js.map +1 -1
  144. package/dist/result-contract.d.ts +6 -1
  145. package/dist/result-contract.js +10 -22
  146. package/dist/result-contract.js.map +1 -1
  147. package/dist/runner.js +43 -1
  148. package/dist/runner.js.map +1 -1
  149. package/package.json +11 -5
@@ -0,0 +1,177 @@
1
+ export const RECEIPT_SEPARATOR = "--- workflow receipt ---";
2
+ export const RECEIPT_MAX_CHARS = 1200;
3
+ const STAGE_NAME_WIDTH = 16;
4
+ const STAGE_STATE_WIDTH = 3;
5
+ const STAGE_CALLS_WIDTH = 5;
6
+ const ANSI_PATTERN = /\u001B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g;
7
+ export function renderWorkflowReceipt(summary) {
8
+ const prefixLines = [
9
+ RECEIPT_SEPARATOR,
10
+ renderHeader(summary),
11
+ "",
12
+ ...summary.stages.map(renderStageLine),
13
+ ];
14
+ const cardSection = renderCardSection(summary.card);
15
+ const failureSection = renderFailureSection(summary);
16
+ const composed = joinReceiptLines(prefixLines, cardSection.requiredLines, fitOptionalLines(prefixLines, cardSection.requiredLines, cardSection.optionalLines, failureSection.requiredLines), failureSection.requiredLines);
17
+ if (composed.length <= RECEIPT_MAX_CHARS) {
18
+ return composed;
19
+ }
20
+ const codePoints = Array.from(composed);
21
+ return codePoints.slice(0, RECEIPT_MAX_CHARS - 3).join("") + "...";
22
+ }
23
+ function renderHeader(summary) {
24
+ const totalCalls = summary.stages.reduce((sum, stage) => sum + stage.completedCalls, 0);
25
+ const wallSeconds = formatSeconds(diffSeconds(summary.attemptStartedAt, summary.attemptCompletedAt));
26
+ return [
27
+ normalizeInlineText(summary.workflow.name),
28
+ normalizeInlineText(summary.runId),
29
+ `${summary.stages.length} stages`,
30
+ `${totalCalls} calls`,
31
+ `wall ${wallSeconds}`,
32
+ ].join(" · ");
33
+ }
34
+ function renderStageLine(stage) {
35
+ const base = [
36
+ normalizeInlineText(stage.label).padEnd(STAGE_NAME_WIDTH, " "),
37
+ normalizeInlineText(stage.state).padEnd(STAGE_STATE_WIDTH, " "),
38
+ `${stage.completedCalls}/${stage.totalCalls}`.padEnd(STAGE_CALLS_WIDTH, " "),
39
+ formatSeconds(Math.round(stage.wallDurationMs / 1000)),
40
+ ].join(" ");
41
+ if (stage.retryEvents <= 0) {
42
+ return base;
43
+ }
44
+ return `${base} retry x${stage.retryEvents}`;
45
+ }
46
+ function renderCardSection(card) {
47
+ switch (card.kind) {
48
+ case "council-default": {
49
+ const headerLine = joinParts([
50
+ card.confidence != null ? `confidence ${card.confidence}` : undefined,
51
+ card.selectedApproach != null ? `selected ${normalizeInlineText(card.selectedApproach)}` : undefined,
52
+ ]);
53
+ return {
54
+ requiredLines: compactLines([
55
+ headerLine,
56
+ `agreements: ${card.agreements} · disagreements: ${card.disagreements}`,
57
+ ]),
58
+ optionalLines: [],
59
+ };
60
+ }
61
+ case "council-code-review":
62
+ return {
63
+ requiredLines: [
64
+ joinParts([
65
+ normalizeInlineText(card.status),
66
+ card.confidence != null ? `confidence ${card.confidence}` : undefined,
67
+ ]),
68
+ `blocking: ${card.blockingCount} · non-blocking: ${card.nonBlockingCount} · tests: ${card.testsCount}`,
69
+ ],
70
+ optionalLines: renderNumberedLines(card.topBlockingIssues),
71
+ };
72
+ case "council-debug":
73
+ return {
74
+ requiredLines: compactLines([
75
+ joinParts([
76
+ card.confidence != null ? `confidence ${card.confidence}` : undefined,
77
+ card.riskLevel != null ? `risk ${normalizeInlineText(card.riskLevel)}` : undefined,
78
+ ]),
79
+ "hypotheses:",
80
+ ]),
81
+ optionalLines: renderNumberedLines(card.topHypotheses),
82
+ };
83
+ case "council-discover":
84
+ return {
85
+ requiredLines: compactLines([
86
+ joinParts([
87
+ card.confidence != null ? `confidence ${card.confidence}` : undefined,
88
+ `open questions: ${card.openQuestionCount}`,
89
+ ]),
90
+ "findings:",
91
+ ]),
92
+ optionalLines: renderNumberedLines(card.topFindings),
93
+ };
94
+ case "council-answer":
95
+ return {
96
+ requiredLines: compactLines([
97
+ joinParts([
98
+ card.confidence != null ? `confidence ${card.confidence}` : undefined,
99
+ `caveats: ${card.caveatCount}`,
100
+ ]),
101
+ ]),
102
+ optionalLines: renderNumberedLines(card.topCaveats),
103
+ };
104
+ case "generic":
105
+ return { requiredLines: [], optionalLines: [] };
106
+ }
107
+ }
108
+ function renderFailureSection(summary) {
109
+ if (summary.failure == null) {
110
+ return { requiredLines: [], optionalLines: [] };
111
+ }
112
+ return {
113
+ requiredLines: [
114
+ `FAILED at ${normalizeInlineText(summary.failure.location)} · ${normalizeInlineText(summary.failure.failureClass)}`,
115
+ ` ${normalizeInlineText(summary.failure.message)}`,
116
+ `resumable: ${summary.resumable ? "yes" : "no"}`,
117
+ ],
118
+ optionalLines: [],
119
+ };
120
+ }
121
+ function fitOptionalLines(prefixLines, cardRequiredLines, cardOptionalLines, failureRequiredLines) {
122
+ const chosen = [];
123
+ for (const line of cardOptionalLines) {
124
+ const candidate = joinReceiptLines(prefixLines, cardRequiredLines, [...chosen, line], failureRequiredLines);
125
+ if (candidate.length > RECEIPT_MAX_CHARS) {
126
+ break;
127
+ }
128
+ chosen.push(line);
129
+ }
130
+ return chosen;
131
+ }
132
+ function joinReceiptLines(prefixLines, cardRequiredLines, cardOptionalLines, failureRequiredLines) {
133
+ const lines = [...prefixLines];
134
+ if (cardRequiredLines.length > 0 || cardOptionalLines.length > 0) {
135
+ lines.push("");
136
+ lines.push(...cardRequiredLines);
137
+ lines.push(...cardOptionalLines);
138
+ }
139
+ if (failureRequiredLines.length > 0) {
140
+ lines.push("");
141
+ lines.push(...failureRequiredLines);
142
+ }
143
+ return lines.join("\n");
144
+ }
145
+ function renderNumberedLines(items) {
146
+ return items
147
+ .map((item, index) => {
148
+ const text = normalizeInlineText(item);
149
+ return text.length > 0 ? ` ${index + 1}. ${text}` : "";
150
+ })
151
+ .filter((line) => line.length > 0);
152
+ }
153
+ function normalizeInlineText(value) {
154
+ return value
155
+ .replace(ANSI_PATTERN, "")
156
+ .replace(/\r?\n+/g, " ")
157
+ .replace(/\s+/g, " ")
158
+ .trim();
159
+ }
160
+ function joinParts(parts) {
161
+ return parts.filter((part) => part != null && part.length > 0).join(" · ");
162
+ }
163
+ function compactLines(lines) {
164
+ return lines.filter((line) => line != null && line.length > 0);
165
+ }
166
+ function diffSeconds(startedAt, completedAt) {
167
+ const started = Date.parse(startedAt);
168
+ const completed = Date.parse(completedAt);
169
+ if (!Number.isFinite(started) || !Number.isFinite(completed)) {
170
+ return 0;
171
+ }
172
+ return Math.max(0, Math.round((completed - started) / 1000));
173
+ }
174
+ function formatSeconds(seconds) {
175
+ return `${Math.max(0, seconds)}s`;
176
+ }
177
+ //# sourceMappingURL=workflow-receipt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-receipt.js","sourceRoot":"","sources":["../src/workflow-receipt.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAC5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAEtC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,YAAY,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AO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC;AACpC,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Reusable workflow tool registration for any MCP Server instance.
3
+ *
4
+ * Extracted from server.ts to allow both:
5
+ * - Standalone STDIO server (ClinkSession child process backend)
6
+ * - In-process integration (LocalClinkBackend via root ClinkX)
7
+ *
8
+ * The `registerWorkflowTools()` function registers three tools on a Server:
9
+ * - run_workflow: start a new workflow execution
10
+ * - resume_workflow: resume a failed/cancelled run
11
+ * - list_workflows: list available workflow definitions
12
+ *
13
+ * The caller provides a `createBackend` factory that determines how clink
14
+ * calls are dispatched — either via child process or in-process.
15
+ */
16
+ import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
17
+ import type { ClinkBackend } from "./backend.js";
18
+ export interface WorkflowToolsOptions {
19
+ /**
20
+ * Factory that creates a ClinkBackend for a given run.
21
+ * For standalone server: `(runId) => new ClinkSession({ runId })`
22
+ * For in-process: `(runId) => new LocalClinkBackend(...)`
23
+ */
24
+ readonly createBackend: (runId: string) => ClinkBackend;
25
+ /** Override templates root path (default: from config). */
26
+ readonly templatesRoot?: string | undefined;
27
+ /** Override workflows search path. */
28
+ readonly workflowsPath?: string | undefined;
29
+ }
30
+ /**
31
+ * Humanize a stage ID: replace underscores with spaces, capitalize first letter only.
32
+ * e.g. "cross_review" → "Cross review", "ranking_analysis" → "Ranking analysis"
33
+ */
34
+ export declare function humanizeStageId(id: string): string;
35
+ /** MCP tool definition shape (matches SDK's Tool type). */
36
+ export interface WorkflowToolDefinition {
37
+ readonly name: string;
38
+ readonly description: string;
39
+ readonly inputSchema: Record<string, unknown>;
40
+ readonly annotations?: Record<string, unknown> | undefined;
41
+ }
42
+ /**
43
+ * Return the three workflow tool definitions for tools/list.
44
+ *
45
+ * Dynamically discovers available workflows to include in the
46
+ * run_workflow description. Safe to call repeatedly — no side effects.
47
+ */
48
+ export declare function getWorkflowToolDefinitions(): WorkflowToolDefinition[];
49
+ /** Names of the workflow tools (for dispatch matching). */
50
+ export declare const WORKFLOW_TOOL_NAMES: Set<string>;
51
+ /**
52
+ * Dispatch a workflow tool call.
53
+ *
54
+ * Returns the tool result, or null if the tool name is not recognized
55
+ * as a workflow tool (caller should handle it as an unknown tool).
56
+ */
57
+ export declare function handleWorkflowToolCall(server: Server, options: WorkflowToolsOptions, name: string, args: Record<string, unknown>, signal: AbortSignal, progressToken: string | number | undefined): Promise<{
58
+ content: Array<{
59
+ type: "text";
60
+ text: string;
61
+ }>;
62
+ isError?: boolean;
63
+ } | null>;
64
+ /**
65
+ * Register workflow tools on an MCP Server instance.
66
+ *
67
+ * This is the reusable core extracted from createWorkflowServer().
68
+ * It registers three tools: run_workflow, resume_workflow, list_workflows.
69
+ *
70
+ * The `options.createBackend` factory determines how clink calls are
71
+ * dispatched — callers provide either a child-process or in-process backend.
72
+ *
73
+ * NOTE: This calls setRequestHandler which REPLACES any existing handlers.
74
+ * For combined servers (root + workflows), use getWorkflowToolDefinitions()
75
+ * and handleWorkflowToolCall() instead and build a unified handler.
76
+ */
77
+ export declare function registerWorkflowTools(server: Server, options: WorkflowToolsOptions): void;