@dezycro-ai/agent-plugin 2.1.2 → 2.2.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.
Files changed (52) hide show
  1. package/README.md +14 -98
  2. package/dist/cli/dezycro.js +50 -0
  3. package/dist/cli/install.js +7 -0
  4. package/dist/dezycro-config.d.ts +52 -0
  5. package/dist/dezycro-config.js +167 -0
  6. package/dist/gateway/compact-cli.js +8 -0
  7. package/dist/gateway/proxy.js +35 -0
  8. package/dist/hooks/lib/router.js +14 -830
  9. package/dist/schemas/anthropic.d.ts +119 -0
  10. package/dist/schemas/anthropic.js +43 -0
  11. package/dist/schemas/dezycro.d.ts +19 -0
  12. package/dist/schemas/dezycro.js +22 -0
  13. package/dist/schemas/gateway.d.ts +40 -0
  14. package/dist/schemas/gateway.js +30 -0
  15. package/dist/schemas/gating.d.ts +32 -0
  16. package/dist/schemas/gating.js +15 -0
  17. package/dist/schemas/index.d.ts +14 -0
  18. package/dist/schemas/index.js +29 -0
  19. package/package.json +21 -13
  20. package/LICENSE +0 -18
  21. package/bin/resolve-auth.js +0 -112
  22. package/dist/hooks/lib/authoring.d.ts +0 -118
  23. package/dist/hooks/lib/authoring.js +0 -277
  24. package/dist/hooks/lib/command-bus.d.ts +0 -66
  25. package/dist/hooks/lib/command-bus.js +0 -357
  26. package/dist/hooks/lib/config.d.ts +0 -28
  27. package/dist/hooks/lib/config.js +0 -175
  28. package/dist/hooks/lib/controller-match.d.ts +0 -16
  29. package/dist/hooks/lib/controller-match.js +0 -96
  30. package/dist/hooks/lib/coverage.d.ts +0 -17
  31. package/dist/hooks/lib/coverage.js +0 -66
  32. package/dist/hooks/lib/hashing.d.ts +0 -8
  33. package/dist/hooks/lib/hashing.js +0 -49
  34. package/dist/hooks/lib/logging.d.ts +0 -13
  35. package/dist/hooks/lib/logging.js +0 -72
  36. package/dist/hooks/lib/publish-spec.d.ts +0 -17
  37. package/dist/hooks/lib/publish-spec.js +0 -64
  38. package/dist/hooks/lib/quality-gate.d.ts +0 -67
  39. package/dist/hooks/lib/quality-gate.js +0 -187
  40. package/dist/hooks/lib/router.d.ts +0 -32
  41. package/dist/hooks/lib/state.d.ts +0 -34
  42. package/dist/hooks/lib/state.js +0 -245
  43. package/dist/hooks/lib/undo.d.ts +0 -11
  44. package/dist/hooks/lib/undo.js +0 -71
  45. package/dist/hooks/lib/verify.d.ts +0 -28
  46. package/dist/hooks/lib/verify.js +0 -94
  47. package/dist/hooks/lib/workbook.d.ts +0 -21
  48. package/dist/hooks/lib/workbook.js +0 -77
  49. package/dist/hooks/types.d.ts +0 -293
  50. package/dist/hooks/types.js +0 -14
  51. package/install.js +0 -84
  52. package/setup.js +0 -53
@@ -1,277 +0,0 @@
1
- /**
2
- * authoring.ts — state machine helpers for /dezycro:author (TRD §5.5.1).
3
- *
4
- * The skill markdown drives the agent turn-by-turn; this module owns the
5
- * persisted side effects (authoring mode in companion-state.json, the
6
- * transcript at .dezycro/authoring-transcript.json, and the most-recent-draft
7
- * sidecar at .dezycro/authoring-current-draft.json).
8
- *
9
- * No LLM calls live here.
10
- */
11
- 'use strict';
12
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- var desc = Object.getOwnPropertyDescriptor(m, k);
15
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
- desc = { enumerable: true, get: function() { return m[k]; } };
17
- }
18
- Object.defineProperty(o, k2, desc);
19
- }) : (function(o, m, k, k2) {
20
- if (k2 === undefined) k2 = k;
21
- o[k2] = m[k];
22
- }));
23
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
- Object.defineProperty(o, "default", { enumerable: true, value: v });
25
- }) : function(o, v) {
26
- o["default"] = v;
27
- });
28
- var __importStar = (this && this.__importStar) || (function () {
29
- var ownKeys = function(o) {
30
- ownKeys = Object.getOwnPropertyNames || function (o) {
31
- var ar = [];
32
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
- return ar;
34
- };
35
- return ownKeys(o);
36
- };
37
- return function (mod) {
38
- if (mod && mod.__esModule) return mod;
39
- var result = {};
40
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
- __setModuleDefault(result, mod);
42
- return result;
43
- };
44
- })();
45
- Object.defineProperty(exports, "__esModule", { value: true });
46
- exports._draftSidecarPath = exports._transcriptPath = exports.DRAFT_SIDECAR_FILENAME = exports.TRANSCRIPT_FILENAME = exports.NON_SKIPPABLE_STATES = exports.SKIP_PHRASES = exports.DOC_TYPES = exports.STATES = void 0;
47
- exports.enter = enter;
48
- exports.exit = exit;
49
- exports.isActive = isActive;
50
- exports.getState = getState;
51
- exports.recordAnswer = recordAnswer;
52
- exports.recordDiscoverySummary = recordDiscoverySummary;
53
- exports.recordDraft = recordDraft;
54
- exports.recordGateResult = recordGateResult;
55
- exports.readTranscript = readTranscript;
56
- exports.writeDraftSidecar = writeDraftSidecar;
57
- exports.readDraftSidecar = readDraftSidecar;
58
- exports.isSkipPhrase = isSkipPhrase;
59
- exports.isNonSkippableState = isNonSkippableState;
60
- const fs = __importStar(require("fs"));
61
- const path = __importStar(require("path"));
62
- const state = __importStar(require("./state"));
63
- exports.STATES = Object.freeze({
64
- IDLE: 'IDLE',
65
- DETECT_INTENT: 'DETECT_INTENT',
66
- SCAN_EXISTING_WORK: 'SCAN_EXISTING_WORK',
67
- CLARIFY: 'CLARIFY',
68
- PROPOSE_PLACEMENT: 'PROPOSE_PLACEMENT',
69
- CREATE_FEATURE: 'CREATE_FEATURE',
70
- TRD_DISCOVERY: 'TRD_DISCOVERY',
71
- MIN_CONTEXT_GATE: 'MIN_CONTEXT_GATE',
72
- DRAFT: 'DRAFT',
73
- ITERATE: 'ITERATE',
74
- QUALITY_GATE: 'QUALITY_GATE',
75
- FINALIZE: 'FINALIZE',
76
- });
77
- exports.DOC_TYPES = Object.freeze({ PRD: 'PRD', TRD: 'TRD' });
78
- exports.SKIP_PHRASES = Object.freeze(['skip', 'draft it', 'just write it', 'next']);
79
- exports.NON_SKIPPABLE_STATES = Object.freeze([
80
- exports.STATES.MIN_CONTEXT_GATE,
81
- exports.STATES.QUALITY_GATE,
82
- ]);
83
- exports.TRANSCRIPT_FILENAME = 'authoring-transcript.json';
84
- exports.DRAFT_SIDECAR_FILENAME = 'authoring-current-draft.json';
85
- function transcriptPath(repoRoot) {
86
- return path.join(repoRoot, '.dezycro', exports.TRANSCRIPT_FILENAME);
87
- }
88
- function draftSidecarPath(repoRoot) {
89
- return path.join(repoRoot, '.dezycro', exports.DRAFT_SIDECAR_FILENAME);
90
- }
91
- function ensureDezycroDir(repoRoot) {
92
- fs.mkdirSync(path.join(repoRoot, '.dezycro'), { recursive: true });
93
- }
94
- function writeJsonAtomic(filePath, data) {
95
- const tmp = `${filePath}.tmp`;
96
- const fd = fs.openSync(tmp, 'w');
97
- try {
98
- fs.writeSync(fd, JSON.stringify(data, null, 2));
99
- fs.fsyncSync(fd);
100
- }
101
- finally {
102
- fs.closeSync(fd);
103
- }
104
- fs.renameSync(tmp, filePath);
105
- }
106
- function readJson(filePath) {
107
- try {
108
- const raw = fs.readFileSync(filePath, 'utf8');
109
- return JSON.parse(raw);
110
- }
111
- catch {
112
- return null;
113
- }
114
- }
115
- function enter(repoRoot, opts) {
116
- if (!opts || !opts.docId || !opts.docType) {
117
- throw new Error('authoring.enter: docId and docType required');
118
- }
119
- if (opts.docType !== exports.DOC_TYPES.PRD && opts.docType !== exports.DOC_TYPES.TRD) {
120
- throw new Error(`authoring.enter: invalid docType ${opts.docType}`);
121
- }
122
- ensureDezycroDir(repoRoot);
123
- const tp = transcriptPath(repoRoot);
124
- const now = new Date().toISOString();
125
- const existing = readJson(tp);
126
- const transcript = existing && existing.docId === opts.docId
127
- ? existing
128
- : {
129
- docId: opts.docId,
130
- docType: opts.docType,
131
- featureId: opts.featureId || null,
132
- seed: opts.seed || null,
133
- startedTs: now,
134
- discoverySummary: null,
135
- qaTurns: [],
136
- draftHistory: [],
137
- qualityGateHistory: [],
138
- };
139
- writeJsonAtomic(tp, transcript);
140
- state.patch(repoRoot, {
141
- authoringMode: true,
142
- authoringDocId: opts.docId,
143
- authoringDocType: opts.docType,
144
- authoringTranscriptPath: tp,
145
- authoringStartedTs: now,
146
- });
147
- return transcript;
148
- }
149
- function exit(repoRoot) {
150
- state.patch(repoRoot, {
151
- authoringMode: false,
152
- authoringDocId: null,
153
- authoringDocType: null,
154
- authoringTranscriptPath: null,
155
- authoringStartedTs: null,
156
- });
157
- for (const p of [transcriptPath(repoRoot), draftSidecarPath(repoRoot)]) {
158
- try {
159
- fs.unlinkSync(p);
160
- }
161
- catch { /* ignore */ }
162
- }
163
- }
164
- function isActive(repoRoot) {
165
- const s = state.read(repoRoot);
166
- return Boolean(s && s.authoringMode);
167
- }
168
- function getState(repoRoot) {
169
- const s = state.read(repoRoot);
170
- return {
171
- active: Boolean(s && s.authoringMode),
172
- docId: s ? s.authoringDocId : null,
173
- docType: s ? s.authoringDocType : null,
174
- transcriptPath: s ? s.authoringTranscriptPath : null,
175
- startedTs: s ? s.authoringStartedTs : null,
176
- };
177
- }
178
- function recordAnswer(repoRoot, opts) {
179
- if (!opts || typeof opts.question !== 'string' || typeof opts.answer !== 'string') {
180
- throw new Error('authoring.recordAnswer: question and answer required');
181
- }
182
- const tp = transcriptPath(repoRoot);
183
- const t = readJson(tp);
184
- if (!t)
185
- return null;
186
- t.qaTurns = (t.qaTurns || []).concat([{
187
- ts: new Date().toISOString(),
188
- question: opts.question,
189
- answer: opts.answer,
190
- category: opts.category || null,
191
- }]);
192
- writeJsonAtomic(tp, t);
193
- return t;
194
- }
195
- function recordDiscoverySummary(repoRoot, discoverySummary) {
196
- const tp = transcriptPath(repoRoot);
197
- const t = readJson(tp);
198
- if (!t)
199
- return null;
200
- t.discoverySummary = discoverySummary || null;
201
- writeJsonAtomic(tp, t);
202
- return t;
203
- }
204
- function recordDraft(repoRoot, opts) {
205
- if (!opts || typeof opts.contentHash !== 'string') {
206
- throw new Error('authoring.recordDraft: contentHash required');
207
- }
208
- const tp = transcriptPath(repoRoot);
209
- const t = readJson(tp);
210
- if (!t)
211
- return null;
212
- t.draftHistory = (t.draftHistory || []).concat([{
213
- ts: new Date().toISOString(),
214
- contentHash: opts.contentHash,
215
- }]);
216
- writeJsonAtomic(tp, t);
217
- return t;
218
- }
219
- function recordGateResult(repoRoot, opts) {
220
- if (!opts || typeof opts.passed !== 'boolean') {
221
- throw new Error('authoring.recordGateResult: passed required');
222
- }
223
- const tp = transcriptPath(repoRoot);
224
- const t = readJson(tp);
225
- if (!t)
226
- return null;
227
- t.qualityGateHistory = (t.qualityGateHistory || []).concat([{
228
- ts: new Date().toISOString(),
229
- passed: opts.passed,
230
- blockingIssues: opts.blockingIssues || [],
231
- score: typeof opts.score === 'number' ? opts.score : null,
232
- deterministic: opts.deterministic === true,
233
- }]);
234
- writeJsonAtomic(tp, t);
235
- return t;
236
- }
237
- function readTranscript(repoRoot) {
238
- return readJson(transcriptPath(repoRoot));
239
- }
240
- function writeDraftSidecar(repoRoot, opts) {
241
- if (!opts || !opts.docId || !opts.docType || typeof opts.content !== 'string') {
242
- throw new Error('authoring.writeDraftSidecar: docId, docType, content required');
243
- }
244
- ensureDezycroDir(repoRoot);
245
- writeJsonAtomic(draftSidecarPath(repoRoot), {
246
- docId: opts.docId,
247
- docType: opts.docType,
248
- content: opts.content,
249
- prdDocId: opts.prdDocId || null,
250
- prdContent: opts.prdContent || null,
251
- updatedTs: new Date().toISOString(),
252
- });
253
- }
254
- function readDraftSidecar(repoRoot) {
255
- return readJson(draftSidecarPath(repoRoot));
256
- }
257
- function isSkipPhrase(userMessage) {
258
- if (typeof userMessage !== 'string')
259
- return false;
260
- const trimmed = userMessage.trim().toLowerCase();
261
- if (!trimmed)
262
- return false;
263
- const stripped = trimmed.replace(/[.!?,;:]+$/g, '').trim();
264
- for (const phrase of exports.SKIP_PHRASES) {
265
- if (stripped === phrase)
266
- return true;
267
- if (stripped.startsWith(`${phrase} `) || stripped.startsWith(`${phrase},`))
268
- return true;
269
- }
270
- return false;
271
- }
272
- function isNonSkippableState(stateName) {
273
- return exports.NON_SKIPPABLE_STATES.includes(stateName);
274
- }
275
- // Path helpers exposed for tests and the router.
276
- exports._transcriptPath = transcriptPath;
277
- exports._draftSidecarPath = draftSidecarPath;
@@ -1,66 +0,0 @@
1
- /**
2
- * command-bus.ts — pulls the Agent Command Bus inbox on hook boundaries and renders
3
- * unseen events for the agent transcript.
4
- *
5
- * Polling model (per the Agent Command Bus TRD):
6
- * * `session-start` always polls (no floor).
7
- * * `user-prompt-submit`, `stop`, `post-tool-use` poll only if `minPollIntervalSeconds`
8
- * has elapsed since the last successful poll.
9
- * * On 2xx: advance cursor + lastPollTs, dedup by `eventId` (recent ring, cap 200),
10
- * return new events for surfacing.
11
- * * On non-2xx / network failure: cursor stays put, consecutiveFailures++, and
12
- * `lastAttemptTs` advances so the floor throttles repeated failures. Once
13
- * failures cross `circuitBreakerThreshold` the floor grows exponentially
14
- * (capped at `maxBackoffSeconds`), so an unreachable endpoint is not polled on
15
- * every hook fire. A single success resets the counter and the interval.
16
- *
17
- * Auth: a bearer token from `.dezycro/companion-token.local.json` (`{"token": "dzy_…"}`)
18
- * is sent on every request. Separate from the MCP server token (the user maintains both).
19
- *
20
- * URL: `<environments[default].apiUrl>/api/v1/workspaces/<wsId>/features/<fId>/inbox`.
21
- * Active feature comes from `.dezycro/active-feature.json` written by `/dezycro:work`.
22
- */
23
- import type { CommandBusConfig, CommandBusHook, CommandBusReactionMode, CompanionState, InboxEvent, StatePatch } from '../types';
24
- export interface PollResult {
25
- events: InboxEvent[];
26
- statePatch: StatePatch | null;
27
- reactionMode: CommandBusReactionMode;
28
- }
29
- interface ResolvedConfig {
30
- enabled: boolean;
31
- hooks: ReadonlySet<CommandBusHook>;
32
- minPollIntervalSeconds: number;
33
- reactionMode: CommandBusReactionMode;
34
- circuitBreakerThreshold: number;
35
- maxBackoffSeconds: number;
36
- }
37
- /**
38
- * Effective poll interval given the number of consecutive failures so far.
39
- * Returns the base interval until `threshold` failures, then doubles per extra
40
- * failure, capped at `maxSeconds`. Never throws.
41
- */
42
- export declare function backoffSeconds(baseSeconds: number, consecutiveFailures: number, threshold: number, maxSeconds: number): number;
43
- /**
44
- * Entry point called from each hook handler. Returns the events that should be surfaced
45
- * to the agent on this hook fire, plus a state patch the caller must apply.
46
- *
47
- * Never throws — failures are logged and result in `{events: [], statePatch: null}`.
48
- */
49
- export declare function pollIfDue(repoRoot: string, hookEvent: CommandBusHook, config: CommandBusConfig | undefined, state: CompanionState): Promise<PollResult>;
50
- /**
51
- * Render zero or more events as a chat-ready Markdown block. Returns the empty string
52
- * when there is nothing to surface — callers can guard with the return value's length.
53
- */
54
- export declare function renderForAgent(events: InboxEvent[], reactionMode: CommandBusReactionMode): string;
55
- declare function renderEvent(e: InboxEvent): string;
56
- declare function reactionGuidance(mode: CommandBusReactionMode): string;
57
- declare function resolveConfig(c: CommandBusConfig | undefined): ResolvedConfig;
58
- declare function trimRecent(ids: string[]): string[];
59
- export declare const _internals: {
60
- resolveConfig: typeof resolveConfig;
61
- renderEvent: typeof renderEvent;
62
- reactionGuidance: typeof reactionGuidance;
63
- trimRecent: typeof trimRecent;
64
- backoffSeconds: typeof backoffSeconds;
65
- };
66
- export {};