feat: write subagent completion receipt state
This commit is contained in:
@@ -122,6 +122,66 @@ function writeDispatchReceiptState(payload) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function writeCompletionReceiptState(payload) {
|
||||||
|
if (!payload || typeof payload !== 'object') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { runId } = payload;
|
||||||
|
const completionReceivedAt = payload.completionReceivedAt ?? payload.completionReceiptAt ?? null;
|
||||||
|
const forwardedToMain = payload.forwardedToMain;
|
||||||
|
const resultSource = payload.resultSource;
|
||||||
|
|
||||||
|
if (typeof runId !== 'string' || runId.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const completionUpdates = {};
|
||||||
|
|
||||||
|
if (typeof completionReceivedAt === 'string' && completionReceivedAt.length > 0) {
|
||||||
|
completionUpdates.completionReceivedAt = completionReceivedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof forwardedToMain === 'boolean') {
|
||||||
|
completionUpdates.forwardedToMain = forwardedToMain;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof resultSource === 'string' && resultSource.length > 0) {
|
||||||
|
completionUpdates.resultSource = resultSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(completionUpdates).length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.mkdirSync(STATE_DIR, { recursive: true });
|
||||||
|
|
||||||
|
const statePath = path.join(STATE_DIR, `${runId}.json`);
|
||||||
|
let currentRecord = {};
|
||||||
|
|
||||||
|
if (fs.existsSync(statePath)) {
|
||||||
|
try {
|
||||||
|
currentRecord = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
||||||
|
} catch {
|
||||||
|
currentRecord = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextRecord = {
|
||||||
|
...currentRecord,
|
||||||
|
runId,
|
||||||
|
...completionUpdates,
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.writeFileSync(statePath, `${JSON.stringify(nextRecord, null, 2)}\n`, 'utf8');
|
||||||
|
|
||||||
|
return {
|
||||||
|
statePath,
|
||||||
|
record: nextRecord,
|
||||||
|
updatedFields: Object.keys(completionUpdates),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
const args = parseArgs(process.argv.slice(2));
|
const args = parseArgs(process.argv.slice(2));
|
||||||
|
|
||||||
@@ -133,16 +193,25 @@ function main() {
|
|||||||
const input = tryReadInput(args.input);
|
const input = tryReadInput(args.input);
|
||||||
const inputPayload = input.exists ? tryParseJson(input.content) : null;
|
const inputPayload = input.exists ? tryParseJson(input.content) : null;
|
||||||
const dispatchWrite = writeDispatchReceiptState(inputPayload);
|
const dispatchWrite = writeDispatchReceiptState(inputPayload);
|
||||||
|
const completionWrite = writeCompletionReceiptState(inputPayload);
|
||||||
|
|
||||||
if ('content' in input) {
|
if ('content' in input) {
|
||||||
delete input.content;
|
delete input.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const records = [];
|
||||||
|
if (dispatchWrite) {
|
||||||
|
records.push(dispatchWrite.record);
|
||||||
|
}
|
||||||
|
if (completionWrite) {
|
||||||
|
records.push(completionWrite.record);
|
||||||
|
}
|
||||||
|
|
||||||
const response = {
|
const response = {
|
||||||
ok: true,
|
ok: true,
|
||||||
tool: 'subagent_delivery_watchdog',
|
tool: 'subagent_delivery_watchdog',
|
||||||
version: 'skeleton-v2',
|
version: 'skeleton-v3',
|
||||||
mode: 'dispatch-receipt-write',
|
mode: 'receipt-write',
|
||||||
args: {
|
args: {
|
||||||
compact: args.compact,
|
compact: args.compact,
|
||||||
input: args.input,
|
input: args.input,
|
||||||
@@ -150,9 +219,10 @@ function main() {
|
|||||||
input,
|
input,
|
||||||
result: {
|
result: {
|
||||||
status: 'not_implemented',
|
status: 'not_implemented',
|
||||||
message: 'Dispatch receipt write is implemented; status recompute remains pending.',
|
message: 'Dispatch and completion receipt writes are implemented; status recompute remains pending.',
|
||||||
records: dispatchWrite ? [dispatchWrite.record] : [],
|
records,
|
||||||
dispatchReceiptWrite: dispatchWrite,
|
dispatchReceiptWrite: dispatchWrite,
|
||||||
|
completionReceiptWrite: completionWrite,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user