@supaku/agentfactory 0.1.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.
- package/LICENSE +21 -0
- package/dist/src/deployment/deployment-checker.d.ts +110 -0
- package/dist/src/deployment/deployment-checker.d.ts.map +1 -0
- package/dist/src/deployment/deployment-checker.js +242 -0
- package/dist/src/deployment/index.d.ts +3 -0
- package/dist/src/deployment/index.d.ts.map +1 -0
- package/dist/src/deployment/index.js +2 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +4 -0
- package/dist/src/logger.d.ts +117 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +430 -0
- package/dist/src/orchestrator/activity-emitter.d.ts +128 -0
- package/dist/src/orchestrator/activity-emitter.d.ts.map +1 -0
- package/dist/src/orchestrator/activity-emitter.js +406 -0
- package/dist/src/orchestrator/api-activity-emitter.d.ts +167 -0
- package/dist/src/orchestrator/api-activity-emitter.d.ts.map +1 -0
- package/dist/src/orchestrator/api-activity-emitter.js +469 -0
- package/dist/src/orchestrator/heartbeat-writer.d.ts +57 -0
- package/dist/src/orchestrator/heartbeat-writer.d.ts.map +1 -0
- package/dist/src/orchestrator/heartbeat-writer.js +137 -0
- package/dist/src/orchestrator/index.d.ts +20 -0
- package/dist/src/orchestrator/index.d.ts.map +1 -0
- package/dist/src/orchestrator/index.js +22 -0
- package/dist/src/orchestrator/log-analyzer.d.ts +160 -0
- package/dist/src/orchestrator/log-analyzer.d.ts.map +1 -0
- package/dist/src/orchestrator/log-analyzer.js +572 -0
- package/dist/src/orchestrator/log-config.d.ts +39 -0
- package/dist/src/orchestrator/log-config.d.ts.map +1 -0
- package/dist/src/orchestrator/log-config.js +45 -0
- package/dist/src/orchestrator/orchestrator.d.ts +246 -0
- package/dist/src/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/src/orchestrator/orchestrator.js +2525 -0
- package/dist/src/orchestrator/parse-work-result.d.ts +16 -0
- package/dist/src/orchestrator/parse-work-result.d.ts.map +1 -0
- package/dist/src/orchestrator/parse-work-result.js +73 -0
- package/dist/src/orchestrator/progress-logger.d.ts +72 -0
- package/dist/src/orchestrator/progress-logger.d.ts.map +1 -0
- package/dist/src/orchestrator/progress-logger.js +135 -0
- package/dist/src/orchestrator/session-logger.d.ts +159 -0
- package/dist/src/orchestrator/session-logger.d.ts.map +1 -0
- package/dist/src/orchestrator/session-logger.js +275 -0
- package/dist/src/orchestrator/state-recovery.d.ts +96 -0
- package/dist/src/orchestrator/state-recovery.d.ts.map +1 -0
- package/dist/src/orchestrator/state-recovery.js +301 -0
- package/dist/src/orchestrator/state-types.d.ts +165 -0
- package/dist/src/orchestrator/state-types.d.ts.map +1 -0
- package/dist/src/orchestrator/state-types.js +7 -0
- package/dist/src/orchestrator/stream-parser.d.ts +145 -0
- package/dist/src/orchestrator/stream-parser.d.ts.map +1 -0
- package/dist/src/orchestrator/stream-parser.js +131 -0
- package/dist/src/orchestrator/types.d.ts +205 -0
- package/dist/src/orchestrator/types.d.ts.map +1 -0
- package/dist/src/orchestrator/types.js +4 -0
- package/dist/src/providers/amp-provider.d.ts +20 -0
- package/dist/src/providers/amp-provider.d.ts.map +1 -0
- package/dist/src/providers/amp-provider.js +24 -0
- package/dist/src/providers/claude-provider.d.ts +18 -0
- package/dist/src/providers/claude-provider.d.ts.map +1 -0
- package/dist/src/providers/claude-provider.js +267 -0
- package/dist/src/providers/codex-provider.d.ts +21 -0
- package/dist/src/providers/codex-provider.d.ts.map +1 -0
- package/dist/src/providers/codex-provider.js +25 -0
- package/dist/src/providers/index.d.ts +42 -0
- package/dist/src/providers/index.d.ts.map +1 -0
- package/dist/src/providers/index.js +77 -0
- package/dist/src/providers/types.d.ts +147 -0
- package/dist/src/providers/types.d.ts.map +1 -0
- package/dist/src/providers/types.js +13 -0
- package/package.json +63 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AgentWorkType } from '@supaku/agentfactory-linear';
|
|
2
|
+
import type { AgentWorkResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Parse the agent's result message to determine whether the work passed or failed.
|
|
5
|
+
*
|
|
6
|
+
* Detection priority:
|
|
7
|
+
* 1. Structured marker: `<!-- WORK_RESULT:passed/failed -->`
|
|
8
|
+
* 2. Heuristic heading/pattern matching scoped to the work type
|
|
9
|
+
* 3. Returns 'unknown' if nothing matches (safe default: no transition)
|
|
10
|
+
*
|
|
11
|
+
* @param resultMessage - The agent's final output message
|
|
12
|
+
* @param workType - The type of work performed (qa, acceptance, etc.)
|
|
13
|
+
* @returns 'passed', 'failed', or 'unknown'
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseWorkResult(resultMessage: string | undefined, workType: AgentWorkType): AgentWorkResult;
|
|
16
|
+
//# sourceMappingURL=parse-work-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-work-result.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/parse-work-result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAuC9C;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,QAAQ,EAAE,aAAa,GACtB,eAAe,CAgCjB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured marker pattern embedded in agent output.
|
|
3
|
+
* Agents are instructed to include this marker in their final output.
|
|
4
|
+
*
|
|
5
|
+
* Format: <!-- WORK_RESULT:passed --> or <!-- WORK_RESULT:failed -->
|
|
6
|
+
*/
|
|
7
|
+
const STRUCTURED_MARKER_RE = /<!--\s*WORK_RESULT:(passed|failed)\s*-->/i;
|
|
8
|
+
/**
|
|
9
|
+
* Heuristic patterns for detecting QA pass/fail when structured marker is absent.
|
|
10
|
+
* Patterns are checked case-insensitively against the result message.
|
|
11
|
+
*/
|
|
12
|
+
const QA_PASS_PATTERNS = [
|
|
13
|
+
/##\s*QA\s+Passed/i,
|
|
14
|
+
/QA\s+Result:\s*Pass/i,
|
|
15
|
+
/QA\s+Status:\s*Passed/i,
|
|
16
|
+
];
|
|
17
|
+
const QA_FAIL_PATTERNS = [
|
|
18
|
+
/##\s*QA\s+Failed/i,
|
|
19
|
+
/QA\s+Result:\s*Fail/i,
|
|
20
|
+
/QA\s+Status:\s*Failed/i,
|
|
21
|
+
];
|
|
22
|
+
const ACCEPTANCE_PASS_PATTERNS = [
|
|
23
|
+
/##\s*Acceptance\s+Complete/i,
|
|
24
|
+
/Acceptance\s+Result:\s*Pass/i,
|
|
25
|
+
/PR\s+has\s+been\s+merged\s+successfully/i,
|
|
26
|
+
];
|
|
27
|
+
const ACCEPTANCE_FAIL_PATTERNS = [
|
|
28
|
+
/##\s*Acceptance\s+(?:Processing\s+)?Failed/i,
|
|
29
|
+
/Acceptance\s+(?:Processing\s+)?Blocked/i,
|
|
30
|
+
/Acceptance\s+Result:\s*Fail/i,
|
|
31
|
+
/Cannot\s+merge\s+PR/i,
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Parse the agent's result message to determine whether the work passed or failed.
|
|
35
|
+
*
|
|
36
|
+
* Detection priority:
|
|
37
|
+
* 1. Structured marker: `<!-- WORK_RESULT:passed/failed -->`
|
|
38
|
+
* 2. Heuristic heading/pattern matching scoped to the work type
|
|
39
|
+
* 3. Returns 'unknown' if nothing matches (safe default: no transition)
|
|
40
|
+
*
|
|
41
|
+
* @param resultMessage - The agent's final output message
|
|
42
|
+
* @param workType - The type of work performed (qa, acceptance, etc.)
|
|
43
|
+
* @returns 'passed', 'failed', or 'unknown'
|
|
44
|
+
*/
|
|
45
|
+
export function parseWorkResult(resultMessage, workType) {
|
|
46
|
+
if (!resultMessage) {
|
|
47
|
+
return 'unknown';
|
|
48
|
+
}
|
|
49
|
+
// 1. Check for structured marker (highest priority, work-type agnostic)
|
|
50
|
+
const markerMatch = resultMessage.match(STRUCTURED_MARKER_RE);
|
|
51
|
+
if (markerMatch) {
|
|
52
|
+
return markerMatch[1].toLowerCase();
|
|
53
|
+
}
|
|
54
|
+
// 2. Fall back to heuristic patterns scoped by work type
|
|
55
|
+
if (workType === 'qa') {
|
|
56
|
+
if (QA_FAIL_PATTERNS.some((p) => p.test(resultMessage))) {
|
|
57
|
+
return 'failed';
|
|
58
|
+
}
|
|
59
|
+
if (QA_PASS_PATTERNS.some((p) => p.test(resultMessage))) {
|
|
60
|
+
return 'passed';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (workType === 'acceptance') {
|
|
64
|
+
if (ACCEPTANCE_FAIL_PATTERNS.some((p) => p.test(resultMessage))) {
|
|
65
|
+
return 'failed';
|
|
66
|
+
}
|
|
67
|
+
if (ACCEPTANCE_PASS_PATTERNS.some((p) => p.test(resultMessage))) {
|
|
68
|
+
return 'passed';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// 3. Unknown — safe default
|
|
72
|
+
return 'unknown';
|
|
73
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Progress Logger
|
|
3
|
+
*
|
|
4
|
+
* Append-only log for debugging agent activity.
|
|
5
|
+
* Format: timestamp|event_type|details
|
|
6
|
+
*/
|
|
7
|
+
import type { ProgressLoggerConfig, ProgressEventType } from './state-types';
|
|
8
|
+
/**
|
|
9
|
+
* ProgressLogger appends events to a log file for debugging
|
|
10
|
+
*/
|
|
11
|
+
export declare class ProgressLogger {
|
|
12
|
+
private readonly config;
|
|
13
|
+
private readonly logPath;
|
|
14
|
+
private stopped;
|
|
15
|
+
constructor(config: ProgressLoggerConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the logger (create directory if needed)
|
|
18
|
+
*/
|
|
19
|
+
init(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Stop the logger
|
|
22
|
+
*/
|
|
23
|
+
stop(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Log an event
|
|
26
|
+
*/
|
|
27
|
+
log(eventType: ProgressEventType, details: string | object): void;
|
|
28
|
+
/**
|
|
29
|
+
* Log agent start
|
|
30
|
+
*/
|
|
31
|
+
logStart(details: {
|
|
32
|
+
issueId: string;
|
|
33
|
+
workType: string;
|
|
34
|
+
prompt: string;
|
|
35
|
+
}): void;
|
|
36
|
+
/**
|
|
37
|
+
* Log phase change
|
|
38
|
+
*/
|
|
39
|
+
logPhase(phase: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Log tool call
|
|
42
|
+
*/
|
|
43
|
+
logTool(toolName: string, input?: object): void;
|
|
44
|
+
/**
|
|
45
|
+
* Log error
|
|
46
|
+
*/
|
|
47
|
+
logError(message: string, error?: Error | unknown): void;
|
|
48
|
+
/**
|
|
49
|
+
* Log recovery attempt
|
|
50
|
+
*/
|
|
51
|
+
logRecovery(attempt: number, reason?: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Log completion
|
|
54
|
+
*/
|
|
55
|
+
logComplete(details?: {
|
|
56
|
+
prUrl?: string;
|
|
57
|
+
message?: string;
|
|
58
|
+
}): void;
|
|
59
|
+
/**
|
|
60
|
+
* Log stop
|
|
61
|
+
*/
|
|
62
|
+
logStop(reason: 'user_request' | 'timeout' | 'error'): void;
|
|
63
|
+
/**
|
|
64
|
+
* Rotate log file if it exceeds max size
|
|
65
|
+
*/
|
|
66
|
+
private maybeRotate;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create a progress logger for an agent
|
|
70
|
+
*/
|
|
71
|
+
export declare function createProgressLogger(config: ProgressLoggerConfig): ProgressLogger;
|
|
72
|
+
//# sourceMappingURL=progress-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress-logger.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/progress-logger.ts"],"names":[],"mappings":"AAAA;;;;;GA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BAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc,CAIjF"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Progress Logger
|
|
3
|
+
*
|
|
4
|
+
* Append-only log for debugging agent activity.
|
|
5
|
+
* Format: timestamp|event_type|details
|
|
6
|
+
*/
|
|
7
|
+
import { appendFileSync, existsSync, mkdirSync, statSync, renameSync } from 'fs';
|
|
8
|
+
import { resolve, dirname } from 'path';
|
|
9
|
+
// Default max log size: 1MB
|
|
10
|
+
const DEFAULT_MAX_SIZE_BYTES = 1024 * 1024;
|
|
11
|
+
/**
|
|
12
|
+
* ProgressLogger appends events to a log file for debugging
|
|
13
|
+
*/
|
|
14
|
+
export class ProgressLogger {
|
|
15
|
+
config;
|
|
16
|
+
logPath;
|
|
17
|
+
stopped = false;
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.config = {
|
|
20
|
+
...config,
|
|
21
|
+
maxSizeBytes: config.maxSizeBytes ?? DEFAULT_MAX_SIZE_BYTES,
|
|
22
|
+
};
|
|
23
|
+
this.logPath = resolve(this.config.agentDir, 'progress.log');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the logger (create directory if needed)
|
|
27
|
+
*/
|
|
28
|
+
init() {
|
|
29
|
+
const dir = dirname(this.logPath);
|
|
30
|
+
if (!existsSync(dir)) {
|
|
31
|
+
mkdirSync(dir, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Stop the logger
|
|
36
|
+
*/
|
|
37
|
+
stop() {
|
|
38
|
+
this.stopped = true;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Log an event
|
|
42
|
+
*/
|
|
43
|
+
log(eventType, details) {
|
|
44
|
+
if (this.stopped)
|
|
45
|
+
return;
|
|
46
|
+
const timestamp = Date.now();
|
|
47
|
+
const detailsStr = typeof details === 'object' ? JSON.stringify(details) : details;
|
|
48
|
+
const line = `${timestamp}|${eventType}|${detailsStr}\n`;
|
|
49
|
+
try {
|
|
50
|
+
// Check if rotation is needed
|
|
51
|
+
this.maybeRotate();
|
|
52
|
+
// Append to log
|
|
53
|
+
appendFileSync(this.logPath, line);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
// Silently ignore errors - progress logging is best-effort
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Log agent start
|
|
61
|
+
*/
|
|
62
|
+
logStart(details) {
|
|
63
|
+
this.log('start', details);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Log phase change
|
|
67
|
+
*/
|
|
68
|
+
logPhase(phase) {
|
|
69
|
+
this.log('phase', { phase });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Log tool call
|
|
73
|
+
*/
|
|
74
|
+
logTool(toolName, input) {
|
|
75
|
+
this.log('tool', { toolName, input: input ? JSON.stringify(input).substring(0, 200) : undefined });
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Log error
|
|
79
|
+
*/
|
|
80
|
+
logError(message, error) {
|
|
81
|
+
this.log('error', {
|
|
82
|
+
message,
|
|
83
|
+
error: error instanceof Error ? error.message : String(error),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Log recovery attempt
|
|
88
|
+
*/
|
|
89
|
+
logRecovery(attempt, reason) {
|
|
90
|
+
this.log('recovery', { attempt, reason });
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Log completion
|
|
94
|
+
*/
|
|
95
|
+
logComplete(details) {
|
|
96
|
+
this.log('complete', details ?? {});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Log stop
|
|
100
|
+
*/
|
|
101
|
+
logStop(reason) {
|
|
102
|
+
this.log('stop', { reason });
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Rotate log file if it exceeds max size
|
|
106
|
+
*/
|
|
107
|
+
maybeRotate() {
|
|
108
|
+
try {
|
|
109
|
+
if (!existsSync(this.logPath))
|
|
110
|
+
return;
|
|
111
|
+
const stats = statSync(this.logPath);
|
|
112
|
+
if (stats.size >= this.config.maxSizeBytes) {
|
|
113
|
+
// Rotate: rename current to .old
|
|
114
|
+
const oldPath = `${this.logPath}.old`;
|
|
115
|
+
try {
|
|
116
|
+
renameSync(this.logPath, oldPath);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// Ignore rotation errors
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// Ignore stat errors
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create a progress logger for an agent
|
|
130
|
+
*/
|
|
131
|
+
export function createProgressLogger(config) {
|
|
132
|
+
const logger = new ProgressLogger(config);
|
|
133
|
+
logger.init();
|
|
134
|
+
return logger;
|
|
135
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Logger
|
|
3
|
+
*
|
|
4
|
+
* Verbose logging of agent sessions for analysis and improvement.
|
|
5
|
+
* Uses JSON Lines format for append efficiency and easy parsing.
|
|
6
|
+
*
|
|
7
|
+
* Logs are stored at: .agent-logs/sessions/{session-id}/
|
|
8
|
+
* - metadata.json: Session metadata
|
|
9
|
+
* - events.jsonl: Event log (JSON Lines)
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentWorkType } from '@supaku/agentfactory-linear';
|
|
12
|
+
/**
|
|
13
|
+
* Session event types for categorization
|
|
14
|
+
*/
|
|
15
|
+
export type SessionEventType = 'init' | 'tool_use' | 'tool_result' | 'assistant' | 'user' | 'error' | 'warning' | 'status' | 'complete' | 'stop';
|
|
16
|
+
/**
|
|
17
|
+
* A single logged event
|
|
18
|
+
*/
|
|
19
|
+
export interface SessionEvent {
|
|
20
|
+
/** Unix timestamp (milliseconds) */
|
|
21
|
+
timestamp: number;
|
|
22
|
+
/** Event type for categorization */
|
|
23
|
+
type: SessionEventType;
|
|
24
|
+
/** Tool name (for tool_use/tool_result events) */
|
|
25
|
+
tool?: string;
|
|
26
|
+
/** Event content/details */
|
|
27
|
+
content: string | object;
|
|
28
|
+
/** Whether this was an error */
|
|
29
|
+
isError?: boolean;
|
|
30
|
+
/** Additional metadata */
|
|
31
|
+
metadata?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Session metadata stored in metadata.json
|
|
35
|
+
*/
|
|
36
|
+
export interface SessionMetadata {
|
|
37
|
+
/** Unique session ID */
|
|
38
|
+
sessionId: string;
|
|
39
|
+
/** Linear issue ID */
|
|
40
|
+
issueId: string;
|
|
41
|
+
/** Human-readable issue identifier */
|
|
42
|
+
issueIdentifier: string;
|
|
43
|
+
/** Type of work being performed */
|
|
44
|
+
workType: AgentWorkType;
|
|
45
|
+
/** Initial prompt */
|
|
46
|
+
prompt: string;
|
|
47
|
+
/** Unix timestamp when session started */
|
|
48
|
+
startedAt: number;
|
|
49
|
+
/** Unix timestamp when session ended */
|
|
50
|
+
endedAt?: number;
|
|
51
|
+
/** Final status */
|
|
52
|
+
status: 'running' | 'completed' | 'failed' | 'stopped';
|
|
53
|
+
/** Error message if failed */
|
|
54
|
+
errorMessage?: string;
|
|
55
|
+
/** PR URL if created */
|
|
56
|
+
pullRequestUrl?: string;
|
|
57
|
+
/** Total tool calls count */
|
|
58
|
+
toolCallsCount: number;
|
|
59
|
+
/** Total errors count */
|
|
60
|
+
errorsCount: number;
|
|
61
|
+
/** Worker ID if remote */
|
|
62
|
+
workerId?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Configuration for SessionLogger
|
|
66
|
+
*/
|
|
67
|
+
export interface SessionLoggerConfig {
|
|
68
|
+
/** Session ID (used for directory name) */
|
|
69
|
+
sessionId: string;
|
|
70
|
+
/** Linear issue ID */
|
|
71
|
+
issueId: string;
|
|
72
|
+
/** Human-readable issue identifier */
|
|
73
|
+
issueIdentifier: string;
|
|
74
|
+
/** Type of work being performed */
|
|
75
|
+
workType: AgentWorkType;
|
|
76
|
+
/** Initial prompt */
|
|
77
|
+
prompt: string;
|
|
78
|
+
/** Base directory for logs (default: .agent-logs) */
|
|
79
|
+
logsDir?: string;
|
|
80
|
+
/** Worker ID if remote */
|
|
81
|
+
workerId?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* SessionLogger handles verbose logging of agent sessions
|
|
85
|
+
*/
|
|
86
|
+
export declare class SessionLogger {
|
|
87
|
+
private readonly config;
|
|
88
|
+
private readonly sessionDir;
|
|
89
|
+
private readonly metadataPath;
|
|
90
|
+
private readonly eventsPath;
|
|
91
|
+
private metadata;
|
|
92
|
+
private stopped;
|
|
93
|
+
constructor(config: SessionLoggerConfig);
|
|
94
|
+
/**
|
|
95
|
+
* Initialize the logger - create directory and write initial metadata
|
|
96
|
+
*/
|
|
97
|
+
initialize(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Log a generic event
|
|
100
|
+
*/
|
|
101
|
+
logEvent(event: SessionEvent): void;
|
|
102
|
+
/**
|
|
103
|
+
* Log a tool use event
|
|
104
|
+
*/
|
|
105
|
+
logToolUse(toolName: string, input?: unknown): void;
|
|
106
|
+
/**
|
|
107
|
+
* Log a tool result event
|
|
108
|
+
*/
|
|
109
|
+
logToolResult(toolName: string, result: unknown, isError?: boolean): void;
|
|
110
|
+
/**
|
|
111
|
+
* Log an assistant message/thought
|
|
112
|
+
*/
|
|
113
|
+
logAssistant(content: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* Log an error
|
|
116
|
+
*/
|
|
117
|
+
logError(message: string, error?: unknown, metadata?: Record<string, unknown>): void;
|
|
118
|
+
/**
|
|
119
|
+
* Log a warning (non-fatal issue)
|
|
120
|
+
*/
|
|
121
|
+
logWarning(message: string, details?: Record<string, unknown>): void;
|
|
122
|
+
/**
|
|
123
|
+
* Log a status change
|
|
124
|
+
*/
|
|
125
|
+
logStatus(status: string, details?: Record<string, unknown>): void;
|
|
126
|
+
/**
|
|
127
|
+
* Finalize the session with a final status
|
|
128
|
+
*/
|
|
129
|
+
finalize(status: 'completed' | 'failed' | 'stopped', options?: {
|
|
130
|
+
errorMessage?: string;
|
|
131
|
+
pullRequestUrl?: string;
|
|
132
|
+
}): void;
|
|
133
|
+
/**
|
|
134
|
+
* Get the session directory path
|
|
135
|
+
*/
|
|
136
|
+
getSessionDir(): string;
|
|
137
|
+
/**
|
|
138
|
+
* Get current metadata
|
|
139
|
+
*/
|
|
140
|
+
getMetadata(): SessionMetadata;
|
|
141
|
+
/**
|
|
142
|
+
* Write metadata to file
|
|
143
|
+
*/
|
|
144
|
+
private writeMetadata;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Create and initialize a session logger
|
|
148
|
+
*/
|
|
149
|
+
export declare function createSessionLogger(config: SessionLoggerConfig): SessionLogger;
|
|
150
|
+
/**
|
|
151
|
+
* Read session metadata from a session directory
|
|
152
|
+
*/
|
|
153
|
+
export declare function readSessionMetadata(sessionDir: string): SessionMetadata | null;
|
|
154
|
+
/**
|
|
155
|
+
* Read events from a session directory
|
|
156
|
+
* Returns an async generator for memory efficiency
|
|
157
|
+
*/
|
|
158
|
+
export declare function readSessionEvents(sessionDir: string): Generator<SessionEvent>;
|
|
159
|
+
//# sourceMappingURL=session-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-logger.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/session-logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAUH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAEhE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,UAAU,GACV,aAAa,GACb,WAAW,GACX,MAAM,GACN,OAAO,GACP,SAAS,GACT,QAAQ,GACR,UAAU,GACV,MAAM,CAAA;AAEV;;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