This repository was archived by the owner on Oct 15, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathdemo-workflow.mjs
More file actions
169 lines (160 loc) · 7.22 KB
/
Copy pathdemo-workflow.mjs
File metadata and controls
169 lines (160 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { execFileSync } from 'node:child_process';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { resetDemoFixture } from './demo-fixture.mjs';
export async function runDemoWorkflow({ presentation = true } = {}) {
const fixture = resetDemoFixture();
const environment = { ...process.env, GITPIN_REGISTRY: fixture.registryPath };
const serverPath = resolve(process.cwd(), 'dist', 'server.js');
const doctor = execFileSync(process.execPath, [serverPath, 'doctor'], {
cwd: process.cwd(),
env: environment,
encoding: 'utf8',
windowsHide: true,
});
const client = new Client({ name: 'gitpin-demo-workflow', version: '1.0.0' });
const transport = new StdioClientTransport({
command: process.execPath,
args: [serverPath],
cwd: process.cwd(),
env: Object.fromEntries(Object.entries(environment).filter((entry) => typeof entry[1] === 'string')),
stderr: 'pipe',
});
try {
await client.connect(transport);
const tools = await client.listTools();
const catalogEnvelope = toolJson(
await client.callTool({ name: 'pin.catalog', arguments: { view: 'repositories' } }),
);
const catalog = Array.isArray(catalogEnvelope) ? catalogEnvelope : catalogEnvelope.repositories;
const searchEnvelope = toolJson(
await client.callTool({ name: 'pin.search_docs', arguments: { query: 'release gate', repository: 'atlas-api' } }),
);
const search = Array.isArray(searchEnvelope) ? searchEnvelope : searchEnvelope.hits;
const comparison = toolJson(
await client.callTool({
name: 'pin.compare',
arguments: {
repository: fixture.expected.changedRepository,
base: fixture.repositories['atlas-api'].initialCommit,
head: fixture.repositories['atlas-api'].headCommit,
},
}),
);
const brief = toolJson(
await client.callTool({
name: 'pin.analyze',
arguments: { operation: 'brief', audience: 'leadership' },
}),
);
const repeatedBrief = toolJson(
await client.callTool({
name: 'pin.analyze',
arguments: { operation: 'brief', audience: 'technical' },
}),
);
const result = verifyWorkflow({ fixture, tools, catalog, search, comparison, brief, repeatedBrief, doctor });
if (presentation) printPresentation(result);
return result;
} finally {
await client.close();
}
}
function verifyWorkflow({ fixture, tools, catalog, search, comparison, brief, repeatedBrief, doctor }) {
const toolNames = tools.tools.map((tool) => tool.name).sort();
const staleRepository = catalog.find((repository) => repository.name === 'merchant-web');
const staleGap = brief.gaps.find((gap) => gap.id === 'stale:merchant-web');
if (!doctor.includes('GitPin readiness: attention')) throw new Error('Expected doctor to flag stale demo evidence.');
if (catalog.length !== fixture.expected.repositories)
throw new Error('The demo catalog did not include every synthetic repository.');
if (brief.scope.totalDocuments !== fixture.expected.documents)
throw new Error('The demo brief document count diverged from fixture truth.');
if (!staleRepository?.stale || !staleGap) throw new Error('The demo did not surface the stale-evidence guardrail.');
if (brief.evidenceSetId !== repeatedBrief.evidenceSetId)
throw new Error('EvidenceBrief evidence changed across presentation audiences.');
if (toolNames.length !== 12 || !tools.tools.every((tool) => tool.annotations?.readOnlyHint === true)) {
throw new Error('The demo MCP server did not expose the expected read-only tool surface.');
}
if (!toolNames.includes('pin.prove') || !toolNames.includes('pin.verify')) {
throw new Error('The demo MCP server must expose pin.prove and pin.verify (product loop).');
}
if (!Array.isArray(comparison.files) || comparison.files.length !== fixture.expected.changedPaths.length) {
throw new Error('The demo comparison did not return the expected changed path.');
}
if (!Array.isArray(search) || search.length === 0)
throw new Error('The demo search did not return committed source evidence.');
return { fixture, toolNames, catalog, search, comparison, brief, doctor };
}
function printPresentation({ fixture, toolNames, catalog, search, comparison, brief }) {
const searchHit = search[0];
const sourceTrace = brief.technicalTrace.slice(0, 3);
line('GitPin · release evidence in one reviewable brief');
line(
`Synthetic fixture: ${fixture.expected.repositories} Git repositories · ${fixture.expected.documents} committed documents`,
);
pause();
line(`MCP contract: ${toolNames.length} tools · all read-only`);
line('1. Catalog committed documentation');
for (const repository of catalog) {
line(
` ${repository.name.padEnd(13)} docs=${repository.docCount} stale=${repository.stale} commit=${short(repository.commitSha)}`,
);
}
pause();
line('2. Find the source before making a release call');
line(` ${searchHit.repository} ${searchHit.sourcePath}:${searchHit.line} · ${searchHit.snippet.trim()}`);
line(` Compare ${comparison.files.length} changed path · ${comparison.files.map((file) => file.path).join(', ')}`);
pause();
line('3. Generate the source-cited EvidenceBrief');
line(` ${brief.presentation.summary}`);
line(` Evidence set: ${brief.evidenceSetId}`);
for (const trace of sourceTrace) {
line(` Proof: ${trace.repository} ${trace.sourcePath}:${trace.line} @ ${short(trace.commitSha)}`);
}
pause();
line('Guardrail: merchant-web has uncommitted documentation. It is marked stale and excluded from pinned evidence.');
line('Outcome: a release lead gets the known facts, gaps, and source traces before asking an agent to act.');
}
function toolJson(result) {
const text = result.content
.filter((item) => item.type === 'text')
.map((item) => item.text)
.join('\n');
return JSON.parse(text);
}
function line(value) {
process.stdout.write(`${value}\n`);
}
function pause() {
const delay = Number.parseInt(process.env.GITPIN_DEMO_PACE_MS ?? process.env.REPOCONTEXT_DEMO_PACE_MS ?? '0', 10);
if (!Number.isInteger(delay) || delay <= 0) return;
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delay);
}
function short(value) {
return typeof value === 'string' ? value.slice(0, 12) : 'unavailable';
}
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
const presentation = !process.argv.includes('--json');
runDemoWorkflow({ presentation })
.then((result) => {
if (!presentation) {
console.log(
JSON.stringify({
status: 'ready',
evidenceSetId: result.brief.evidenceSetId,
repositories: result.brief.scope.examinedRepositories,
documents: result.brief.scope.totalDocuments,
staleRepositories: result.brief.scope.staleRepositories,
comparedPaths: result.comparison.files.length,
tools: result.toolNames.length,
}),
);
}
})
.catch((error) => {
console.error(error instanceof Error ? error.message : error);
process.exitCode = 1;
});
}