opencode-manifold 0.5.5 → 0.5.7
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/dist/index.js +375 -3990
- package/package.json +1 -1
- package/src/templates/agents/clerk.md +330 -60
- package/src/templates/agents/debug.md +1 -1
- package/src/templates/agents/junior-dev.md +1 -1
- package/src/templates/agents/manifold.md +186 -36
- package/src/templates/agents/senior-dev.md +1 -1
- package/src/templates/agents/todo.md +70 -22
package/dist/index.js
CHANGED
|
@@ -266,4004 +266,396 @@ async function initProject(directory, client) {
|
|
|
266
266
|
|
|
267
267
|
// src/tools/dispatch-task.ts
|
|
268
268
|
import { tool } from "@opencode-ai/plugin";
|
|
269
|
-
import { readFile as
|
|
270
|
-
import { existsSync as
|
|
271
|
-
import { join as
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
import { existsSync as existsSync4 } from "fs";
|
|
276
|
-
import { join as join4 } from "path";
|
|
277
|
-
|
|
278
|
-
// src/session-spawner.ts
|
|
279
|
-
async function cleanupSession(client, sessionId) {
|
|
280
|
-
try {
|
|
281
|
-
await client.session.delete({ path: { id: sessionId } });
|
|
282
|
-
} catch {}
|
|
283
|
-
}
|
|
284
|
-
async function waitForSessionIdle(client, sessionId, timeoutMs) {
|
|
285
|
-
const startTime = Date.now();
|
|
286
|
-
const lastLogTime = startTime;
|
|
287
|
-
let pollCount = 0;
|
|
288
|
-
while (Date.now() - startTime < timeoutMs) {
|
|
289
|
-
const statusResponse = await client.session.status({});
|
|
290
|
-
const statusData = statusResponse.data;
|
|
291
|
-
if (statusData && statusData[sessionId]) {
|
|
292
|
-
const status = statusData[sessionId];
|
|
293
|
-
if (status.type === "idle") {
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
if (status.type === "retry") {
|
|
297
|
-
const waitTime = status.next - Date.now();
|
|
298
|
-
if (waitTime > 0) {
|
|
299
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(waitTime, 1000)));
|
|
300
|
-
}
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
} else {
|
|
304
|
-
const messagesResponse = await client.session.messages({
|
|
305
|
-
path: { id: sessionId }
|
|
306
|
-
});
|
|
307
|
-
const messages = messagesResponse.data;
|
|
308
|
-
if (messages && Array.isArray(messages) && messages.length > 0) {
|
|
309
|
-
for (let i = messages.length - 1;i >= 0; i--) {
|
|
310
|
-
const msg = messages[i];
|
|
311
|
-
if (msg.info && msg.info.role === "assistant") {
|
|
312
|
-
return true;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
pollCount++;
|
|
318
|
-
const elapsed = Date.now() - startTime;
|
|
319
|
-
if (elapsed % 1e4 < 1000 && elapsed > 0 && Date.now() - lastLogTime > 1e4) {
|
|
320
|
-
await client.app.log({
|
|
321
|
-
body: {
|
|
322
|
-
service: "opencode-manifold",
|
|
323
|
-
level: "info",
|
|
324
|
-
message: `Still waiting for session ${sessionId}... (${Math.round(elapsed / 1000)}s elapsed)`
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
329
|
-
}
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
async function getLastAssistantMessage(client, sessionId) {
|
|
333
|
-
const messagesResponse = await client.session.messages({
|
|
334
|
-
path: { id: sessionId }
|
|
335
|
-
});
|
|
336
|
-
const messages = messagesResponse.data;
|
|
337
|
-
if (!messages || !Array.isArray(messages)) {
|
|
338
|
-
return "";
|
|
339
|
-
}
|
|
340
|
-
for (let i = messages.length - 1;i >= 0; i--) {
|
|
341
|
-
const msg = messages[i];
|
|
342
|
-
if (msg.info && msg.info.role === "assistant") {
|
|
343
|
-
if (msg.parts && Array.isArray(msg.parts)) {
|
|
344
|
-
for (const part of msg.parts) {
|
|
345
|
-
if (part.type === "text" && part.text) {
|
|
346
|
-
return part.text;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return "";
|
|
353
|
-
}
|
|
354
|
-
async function spawnSession(client, agent, prompt, timeoutSeconds) {
|
|
355
|
-
const timeoutMs = timeoutSeconds * 1000;
|
|
356
|
-
try {
|
|
357
|
-
const createResponse = await client.session.create({});
|
|
358
|
-
const session = createResponse.data;
|
|
359
|
-
if (!session || !session.id) {
|
|
360
|
-
return {
|
|
361
|
-
content: "",
|
|
362
|
-
success: false,
|
|
363
|
-
error: "Failed to create session"
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
const sessionId = session.id;
|
|
367
|
-
await client.app.log({
|
|
368
|
-
body: {
|
|
369
|
-
service: "opencode-manifold",
|
|
370
|
-
level: "info",
|
|
371
|
-
message: `Created session ${sessionId} for agent ${agent}`
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
try {
|
|
375
|
-
await client.session.promptAsync({
|
|
376
|
-
path: { id: sessionId },
|
|
377
|
-
body: {
|
|
378
|
-
agent,
|
|
379
|
-
noReply: true,
|
|
380
|
-
parts: [{ type: "text", text: prompt }]
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
const isIdle = await waitForSessionIdle(client, sessionId, timeoutMs);
|
|
384
|
-
if (!isIdle) {
|
|
385
|
-
await client.session.abort({ path: { id: sessionId } });
|
|
386
|
-
return {
|
|
387
|
-
content: "",
|
|
388
|
-
success: false,
|
|
389
|
-
error: `Session timed out after ${timeoutSeconds}s`
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
const content = await getLastAssistantMessage(client, sessionId);
|
|
393
|
-
await client.app.log({
|
|
394
|
-
body: {
|
|
395
|
-
service: "opencode-manifold",
|
|
396
|
-
level: "info",
|
|
397
|
-
message: `Session ${sessionId} completed, content length: ${content.length}`
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
return {
|
|
401
|
-
content,
|
|
402
|
-
success: true
|
|
403
|
-
};
|
|
404
|
-
} finally {
|
|
405
|
-
await cleanupSession(client, sessionId);
|
|
406
|
-
}
|
|
407
|
-
} catch (error) {
|
|
408
|
-
return {
|
|
409
|
-
content: "",
|
|
410
|
-
success: false,
|
|
411
|
-
error: error instanceof Error ? error.message : String(error)
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
async function spawnClerkSession(client, prompt, agent, timeout) {
|
|
416
|
-
await client.app.log({
|
|
417
|
-
body: {
|
|
418
|
-
service: "opencode-manifold",
|
|
419
|
-
level: "info",
|
|
420
|
-
message: `Spawning Clerk session (agent: ${agent}, timeout: ${timeout}s)`
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
return spawnSession(client, agent, prompt, timeout);
|
|
424
|
-
}
|
|
425
|
-
async function spawnSeniorDevSession(client, prompt, agent, timeout) {
|
|
426
|
-
await client.app.log({
|
|
427
|
-
body: {
|
|
428
|
-
service: "opencode-manifold",
|
|
429
|
-
level: "info",
|
|
430
|
-
message: `Spawning Senior Dev session (agent: ${agent}, timeout: ${timeout}s)`
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
return spawnSession(client, agent, prompt, timeout);
|
|
434
|
-
}
|
|
435
|
-
async function spawnJuniorDevSession(client, prompt, seniorOutput, agent, timeout) {
|
|
436
|
-
await client.app.log({
|
|
437
|
-
body: {
|
|
438
|
-
service: "opencode-manifold",
|
|
439
|
-
level: "info",
|
|
440
|
-
message: `Spawning Junior Dev session (agent: ${agent}, timeout: ${timeout}s)`
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
const fullPrompt = `${prompt}
|
|
444
|
-
|
|
445
|
-
---
|
|
446
|
-
|
|
447
|
-
Senior Dev's Implementation:
|
|
448
|
-
${seniorOutput}`;
|
|
449
|
-
return spawnSession(client, agent, fullPrompt, timeout);
|
|
450
|
-
}
|
|
451
|
-
async function spawnDebugSession(client, prompt, loopHistory, agent, timeout) {
|
|
452
|
-
await client.app.log({
|
|
453
|
-
body: {
|
|
454
|
-
service: "opencode-manifold",
|
|
455
|
-
level: "info",
|
|
456
|
-
message: `Spawning Debug session (agent: ${agent}, timeout: ${timeout}s)`
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
const fullPrompt = `${prompt}
|
|
460
|
-
|
|
461
|
-
---
|
|
462
|
-
|
|
463
|
-
Loop History:
|
|
464
|
-
${loopHistory}`;
|
|
465
|
-
return spawnSession(client, agent, fullPrompt, timeout);
|
|
466
|
-
}
|
|
467
|
-
function parseJuniorFirstWord(response) {
|
|
468
|
-
const firstWord = response.trim().split(/\s+/)[0].toUpperCase();
|
|
469
|
-
if (firstWord === "COMPLETE") {
|
|
470
|
-
return "COMPLETE";
|
|
471
|
-
}
|
|
472
|
-
return "QUESTIONS";
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// src/error-handler.ts
|
|
476
|
-
class ModelCallError extends Error {
|
|
477
|
-
agent;
|
|
478
|
-
attempt;
|
|
479
|
-
constructor(message, agent, attempt) {
|
|
480
|
-
super(message);
|
|
481
|
-
this.agent = agent;
|
|
482
|
-
this.attempt = attempt;
|
|
483
|
-
this.name = "ModelCallError";
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
async function retryWithBackoff(fn, options) {
|
|
487
|
-
let lastError;
|
|
488
|
-
for (let attempt = 0;attempt <= options.maxRetries; attempt++) {
|
|
489
|
-
try {
|
|
490
|
-
return await fn();
|
|
491
|
-
} catch (error) {
|
|
492
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
493
|
-
if (attempt < options.maxRetries) {
|
|
494
|
-
options.onRetry?.(attempt + 1, lastError);
|
|
495
|
-
const delay = Math.pow(2, attempt) * 100;
|
|
496
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
throw lastError;
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// src/graph.ts
|
|
504
|
-
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
505
|
-
import { existsSync as existsSync2 } from "fs";
|
|
506
|
-
import { join as join2, dirname as dirname2 } from "path";
|
|
507
|
-
|
|
508
|
-
// node_modules/js-yaml/dist/js-yaml.mjs
|
|
509
|
-
/*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT */
|
|
510
|
-
function isNothing(subject) {
|
|
511
|
-
return typeof subject === "undefined" || subject === null;
|
|
512
|
-
}
|
|
513
|
-
function isObject(subject) {
|
|
514
|
-
return typeof subject === "object" && subject !== null;
|
|
515
|
-
}
|
|
516
|
-
function toArray(sequence) {
|
|
517
|
-
if (Array.isArray(sequence))
|
|
518
|
-
return sequence;
|
|
519
|
-
else if (isNothing(sequence))
|
|
520
|
-
return [];
|
|
521
|
-
return [sequence];
|
|
522
|
-
}
|
|
523
|
-
function extend(target, source) {
|
|
524
|
-
var index, length, key, sourceKeys;
|
|
525
|
-
if (source) {
|
|
526
|
-
sourceKeys = Object.keys(source);
|
|
527
|
-
for (index = 0, length = sourceKeys.length;index < length; index += 1) {
|
|
528
|
-
key = sourceKeys[index];
|
|
529
|
-
target[key] = source[key];
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
return target;
|
|
533
|
-
}
|
|
534
|
-
function repeat(string, count) {
|
|
535
|
-
var result = "", cycle;
|
|
536
|
-
for (cycle = 0;cycle < count; cycle += 1) {
|
|
537
|
-
result += string;
|
|
538
|
-
}
|
|
539
|
-
return result;
|
|
540
|
-
}
|
|
541
|
-
function isNegativeZero(number) {
|
|
542
|
-
return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
|
|
543
|
-
}
|
|
544
|
-
var isNothing_1 = isNothing;
|
|
545
|
-
var isObject_1 = isObject;
|
|
546
|
-
var toArray_1 = toArray;
|
|
547
|
-
var repeat_1 = repeat;
|
|
548
|
-
var isNegativeZero_1 = isNegativeZero;
|
|
549
|
-
var extend_1 = extend;
|
|
550
|
-
var common = {
|
|
551
|
-
isNothing: isNothing_1,
|
|
552
|
-
isObject: isObject_1,
|
|
553
|
-
toArray: toArray_1,
|
|
554
|
-
repeat: repeat_1,
|
|
555
|
-
isNegativeZero: isNegativeZero_1,
|
|
556
|
-
extend: extend_1
|
|
557
|
-
};
|
|
558
|
-
function formatError(exception, compact) {
|
|
559
|
-
var where = "", message = exception.reason || "(unknown reason)";
|
|
560
|
-
if (!exception.mark)
|
|
561
|
-
return message;
|
|
562
|
-
if (exception.mark.name) {
|
|
563
|
-
where += 'in "' + exception.mark.name + '" ';
|
|
564
|
-
}
|
|
565
|
-
where += "(" + (exception.mark.line + 1) + ":" + (exception.mark.column + 1) + ")";
|
|
566
|
-
if (!compact && exception.mark.snippet) {
|
|
567
|
-
where += `
|
|
568
|
-
|
|
569
|
-
` + exception.mark.snippet;
|
|
570
|
-
}
|
|
571
|
-
return message + " " + where;
|
|
572
|
-
}
|
|
573
|
-
function YAMLException$1(reason, mark) {
|
|
574
|
-
Error.call(this);
|
|
575
|
-
this.name = "YAMLException";
|
|
576
|
-
this.reason = reason;
|
|
577
|
-
this.mark = mark;
|
|
578
|
-
this.message = formatError(this, false);
|
|
579
|
-
if (Error.captureStackTrace) {
|
|
580
|
-
Error.captureStackTrace(this, this.constructor);
|
|
581
|
-
} else {
|
|
582
|
-
this.stack = new Error().stack || "";
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
YAMLException$1.prototype = Object.create(Error.prototype);
|
|
586
|
-
YAMLException$1.prototype.constructor = YAMLException$1;
|
|
587
|
-
YAMLException$1.prototype.toString = function toString(compact) {
|
|
588
|
-
return this.name + ": " + formatError(this, compact);
|
|
589
|
-
};
|
|
590
|
-
var exception = YAMLException$1;
|
|
591
|
-
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
592
|
-
var head = "";
|
|
593
|
-
var tail = "";
|
|
594
|
-
var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
595
|
-
if (position - lineStart > maxHalfLength) {
|
|
596
|
-
head = " ... ";
|
|
597
|
-
lineStart = position - maxHalfLength + head.length;
|
|
598
|
-
}
|
|
599
|
-
if (lineEnd - position > maxHalfLength) {
|
|
600
|
-
tail = " ...";
|
|
601
|
-
lineEnd = position + maxHalfLength - tail.length;
|
|
602
|
-
}
|
|
603
|
-
return {
|
|
604
|
-
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail,
|
|
605
|
-
pos: position - lineStart + head.length
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
function padStart(string, max) {
|
|
609
|
-
return common.repeat(" ", max - string.length) + string;
|
|
610
|
-
}
|
|
611
|
-
function makeSnippet(mark, options) {
|
|
612
|
-
options = Object.create(options || null);
|
|
613
|
-
if (!mark.buffer)
|
|
614
|
-
return null;
|
|
615
|
-
if (!options.maxLength)
|
|
616
|
-
options.maxLength = 79;
|
|
617
|
-
if (typeof options.indent !== "number")
|
|
618
|
-
options.indent = 1;
|
|
619
|
-
if (typeof options.linesBefore !== "number")
|
|
620
|
-
options.linesBefore = 3;
|
|
621
|
-
if (typeof options.linesAfter !== "number")
|
|
622
|
-
options.linesAfter = 2;
|
|
623
|
-
var re = /\r?\n|\r|\0/g;
|
|
624
|
-
var lineStarts = [0];
|
|
625
|
-
var lineEnds = [];
|
|
626
|
-
var match;
|
|
627
|
-
var foundLineNo = -1;
|
|
628
|
-
while (match = re.exec(mark.buffer)) {
|
|
629
|
-
lineEnds.push(match.index);
|
|
630
|
-
lineStarts.push(match.index + match[0].length);
|
|
631
|
-
if (mark.position <= match.index && foundLineNo < 0) {
|
|
632
|
-
foundLineNo = lineStarts.length - 2;
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
if (foundLineNo < 0)
|
|
636
|
-
foundLineNo = lineStarts.length - 1;
|
|
637
|
-
var result = "", i, line;
|
|
638
|
-
var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
|
|
639
|
-
var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
|
|
640
|
-
for (i = 1;i <= options.linesBefore; i++) {
|
|
641
|
-
if (foundLineNo - i < 0)
|
|
642
|
-
break;
|
|
643
|
-
line = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength);
|
|
644
|
-
result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + `
|
|
645
|
-
` + result;
|
|
646
|
-
}
|
|
647
|
-
line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
648
|
-
result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + `
|
|
649
|
-
`;
|
|
650
|
-
result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^" + `
|
|
651
|
-
`;
|
|
652
|
-
for (i = 1;i <= options.linesAfter; i++) {
|
|
653
|
-
if (foundLineNo + i >= lineEnds.length)
|
|
654
|
-
break;
|
|
655
|
-
line = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength);
|
|
656
|
-
result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + `
|
|
657
|
-
`;
|
|
658
|
-
}
|
|
659
|
-
return result.replace(/\n$/, "");
|
|
660
|
-
}
|
|
661
|
-
var snippet = makeSnippet;
|
|
662
|
-
var TYPE_CONSTRUCTOR_OPTIONS = [
|
|
663
|
-
"kind",
|
|
664
|
-
"multi",
|
|
665
|
-
"resolve",
|
|
666
|
-
"construct",
|
|
667
|
-
"instanceOf",
|
|
668
|
-
"predicate",
|
|
669
|
-
"represent",
|
|
670
|
-
"representName",
|
|
671
|
-
"defaultStyle",
|
|
672
|
-
"styleAliases"
|
|
673
|
-
];
|
|
674
|
-
var YAML_NODE_KINDS = [
|
|
675
|
-
"scalar",
|
|
676
|
-
"sequence",
|
|
677
|
-
"mapping"
|
|
678
|
-
];
|
|
679
|
-
function compileStyleAliases(map) {
|
|
680
|
-
var result = {};
|
|
681
|
-
if (map !== null) {
|
|
682
|
-
Object.keys(map).forEach(function(style) {
|
|
683
|
-
map[style].forEach(function(alias) {
|
|
684
|
-
result[String(alias)] = style;
|
|
685
|
-
});
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
return result;
|
|
689
|
-
}
|
|
690
|
-
function Type$1(tag, options) {
|
|
691
|
-
options = options || {};
|
|
692
|
-
Object.keys(options).forEach(function(name) {
|
|
693
|
-
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
|
694
|
-
throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
this.options = options;
|
|
698
|
-
this.tag = tag;
|
|
699
|
-
this.kind = options["kind"] || null;
|
|
700
|
-
this.resolve = options["resolve"] || function() {
|
|
701
|
-
return true;
|
|
702
|
-
};
|
|
703
|
-
this.construct = options["construct"] || function(data) {
|
|
704
|
-
return data;
|
|
705
|
-
};
|
|
706
|
-
this.instanceOf = options["instanceOf"] || null;
|
|
707
|
-
this.predicate = options["predicate"] || null;
|
|
708
|
-
this.represent = options["represent"] || null;
|
|
709
|
-
this.representName = options["representName"] || null;
|
|
710
|
-
this.defaultStyle = options["defaultStyle"] || null;
|
|
711
|
-
this.multi = options["multi"] || false;
|
|
712
|
-
this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
|
|
713
|
-
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|
714
|
-
throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
var type = Type$1;
|
|
718
|
-
function compileList(schema, name) {
|
|
719
|
-
var result = [];
|
|
720
|
-
schema[name].forEach(function(currentType) {
|
|
721
|
-
var newIndex = result.length;
|
|
722
|
-
result.forEach(function(previousType, previousIndex) {
|
|
723
|
-
if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
|
|
724
|
-
newIndex = previousIndex;
|
|
725
|
-
}
|
|
726
|
-
});
|
|
727
|
-
result[newIndex] = currentType;
|
|
728
|
-
});
|
|
729
|
-
return result;
|
|
730
|
-
}
|
|
731
|
-
function compileMap() {
|
|
732
|
-
var result = {
|
|
733
|
-
scalar: {},
|
|
734
|
-
sequence: {},
|
|
735
|
-
mapping: {},
|
|
736
|
-
fallback: {},
|
|
737
|
-
multi: {
|
|
738
|
-
scalar: [],
|
|
739
|
-
sequence: [],
|
|
740
|
-
mapping: [],
|
|
741
|
-
fallback: []
|
|
742
|
-
}
|
|
743
|
-
}, index, length;
|
|
744
|
-
function collectType(type2) {
|
|
745
|
-
if (type2.multi) {
|
|
746
|
-
result.multi[type2.kind].push(type2);
|
|
747
|
-
result.multi["fallback"].push(type2);
|
|
748
|
-
} else {
|
|
749
|
-
result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
for (index = 0, length = arguments.length;index < length; index += 1) {
|
|
753
|
-
arguments[index].forEach(collectType);
|
|
754
|
-
}
|
|
755
|
-
return result;
|
|
756
|
-
}
|
|
757
|
-
function Schema$1(definition) {
|
|
758
|
-
return this.extend(definition);
|
|
759
|
-
}
|
|
760
|
-
Schema$1.prototype.extend = function extend2(definition) {
|
|
761
|
-
var implicit = [];
|
|
762
|
-
var explicit = [];
|
|
763
|
-
if (definition instanceof type) {
|
|
764
|
-
explicit.push(definition);
|
|
765
|
-
} else if (Array.isArray(definition)) {
|
|
766
|
-
explicit = explicit.concat(definition);
|
|
767
|
-
} else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
|
|
768
|
-
if (definition.implicit)
|
|
769
|
-
implicit = implicit.concat(definition.implicit);
|
|
770
|
-
if (definition.explicit)
|
|
771
|
-
explicit = explicit.concat(definition.explicit);
|
|
772
|
-
} else {
|
|
773
|
-
throw new exception("Schema.extend argument should be a Type, [ Type ], " + "or a schema definition ({ implicit: [...], explicit: [...] })");
|
|
774
|
-
}
|
|
775
|
-
implicit.forEach(function(type$1) {
|
|
776
|
-
if (!(type$1 instanceof type)) {
|
|
777
|
-
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
778
|
-
}
|
|
779
|
-
if (type$1.loadKind && type$1.loadKind !== "scalar") {
|
|
780
|
-
throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
|
|
781
|
-
}
|
|
782
|
-
if (type$1.multi) {
|
|
783
|
-
throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
explicit.forEach(function(type$1) {
|
|
787
|
-
if (!(type$1 instanceof type)) {
|
|
788
|
-
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
789
|
-
}
|
|
790
|
-
});
|
|
791
|
-
var result = Object.create(Schema$1.prototype);
|
|
792
|
-
result.implicit = (this.implicit || []).concat(implicit);
|
|
793
|
-
result.explicit = (this.explicit || []).concat(explicit);
|
|
794
|
-
result.compiledImplicit = compileList(result, "implicit");
|
|
795
|
-
result.compiledExplicit = compileList(result, "explicit");
|
|
796
|
-
result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
|
|
797
|
-
return result;
|
|
798
|
-
};
|
|
799
|
-
var schema = Schema$1;
|
|
800
|
-
var str = new type("tag:yaml.org,2002:str", {
|
|
801
|
-
kind: "scalar",
|
|
802
|
-
construct: function(data) {
|
|
803
|
-
return data !== null ? data : "";
|
|
804
|
-
}
|
|
805
|
-
});
|
|
806
|
-
var seq = new type("tag:yaml.org,2002:seq", {
|
|
807
|
-
kind: "sequence",
|
|
808
|
-
construct: function(data) {
|
|
809
|
-
return data !== null ? data : [];
|
|
810
|
-
}
|
|
811
|
-
});
|
|
812
|
-
var map = new type("tag:yaml.org,2002:map", {
|
|
813
|
-
kind: "mapping",
|
|
814
|
-
construct: function(data) {
|
|
815
|
-
return data !== null ? data : {};
|
|
816
|
-
}
|
|
817
|
-
});
|
|
818
|
-
var failsafe = new schema({
|
|
819
|
-
explicit: [
|
|
820
|
-
str,
|
|
821
|
-
seq,
|
|
822
|
-
map
|
|
823
|
-
]
|
|
824
|
-
});
|
|
825
|
-
function resolveYamlNull(data) {
|
|
826
|
-
if (data === null)
|
|
827
|
-
return true;
|
|
828
|
-
var max = data.length;
|
|
829
|
-
return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
|
|
830
|
-
}
|
|
831
|
-
function constructYamlNull() {
|
|
832
|
-
return null;
|
|
833
|
-
}
|
|
834
|
-
function isNull(object) {
|
|
835
|
-
return object === null;
|
|
836
|
-
}
|
|
837
|
-
var _null = new type("tag:yaml.org,2002:null", {
|
|
838
|
-
kind: "scalar",
|
|
839
|
-
resolve: resolveYamlNull,
|
|
840
|
-
construct: constructYamlNull,
|
|
841
|
-
predicate: isNull,
|
|
842
|
-
represent: {
|
|
843
|
-
canonical: function() {
|
|
844
|
-
return "~";
|
|
845
|
-
},
|
|
846
|
-
lowercase: function() {
|
|
847
|
-
return "null";
|
|
848
|
-
},
|
|
849
|
-
uppercase: function() {
|
|
850
|
-
return "NULL";
|
|
851
|
-
},
|
|
852
|
-
camelcase: function() {
|
|
853
|
-
return "Null";
|
|
854
|
-
},
|
|
855
|
-
empty: function() {
|
|
856
|
-
return "";
|
|
857
|
-
}
|
|
858
|
-
},
|
|
859
|
-
defaultStyle: "lowercase"
|
|
860
|
-
});
|
|
861
|
-
function resolveYamlBoolean(data) {
|
|
862
|
-
if (data === null)
|
|
863
|
-
return false;
|
|
864
|
-
var max = data.length;
|
|
865
|
-
return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
|
|
866
|
-
}
|
|
867
|
-
function constructYamlBoolean(data) {
|
|
868
|
-
return data === "true" || data === "True" || data === "TRUE";
|
|
869
|
-
}
|
|
870
|
-
function isBoolean(object) {
|
|
871
|
-
return Object.prototype.toString.call(object) === "[object Boolean]";
|
|
872
|
-
}
|
|
873
|
-
var bool = new type("tag:yaml.org,2002:bool", {
|
|
874
|
-
kind: "scalar",
|
|
875
|
-
resolve: resolveYamlBoolean,
|
|
876
|
-
construct: constructYamlBoolean,
|
|
877
|
-
predicate: isBoolean,
|
|
878
|
-
represent: {
|
|
879
|
-
lowercase: function(object) {
|
|
880
|
-
return object ? "true" : "false";
|
|
881
|
-
},
|
|
882
|
-
uppercase: function(object) {
|
|
883
|
-
return object ? "TRUE" : "FALSE";
|
|
884
|
-
},
|
|
885
|
-
camelcase: function(object) {
|
|
886
|
-
return object ? "True" : "False";
|
|
887
|
-
}
|
|
888
|
-
},
|
|
889
|
-
defaultStyle: "lowercase"
|
|
890
|
-
});
|
|
891
|
-
function isHexCode(c) {
|
|
892
|
-
return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
|
|
893
|
-
}
|
|
894
|
-
function isOctCode(c) {
|
|
895
|
-
return 48 <= c && c <= 55;
|
|
896
|
-
}
|
|
897
|
-
function isDecCode(c) {
|
|
898
|
-
return 48 <= c && c <= 57;
|
|
899
|
-
}
|
|
900
|
-
function resolveYamlInteger(data) {
|
|
901
|
-
if (data === null)
|
|
902
|
-
return false;
|
|
903
|
-
var max = data.length, index = 0, hasDigits = false, ch;
|
|
904
|
-
if (!max)
|
|
905
|
-
return false;
|
|
906
|
-
ch = data[index];
|
|
907
|
-
if (ch === "-" || ch === "+") {
|
|
908
|
-
ch = data[++index];
|
|
909
|
-
}
|
|
910
|
-
if (ch === "0") {
|
|
911
|
-
if (index + 1 === max)
|
|
912
|
-
return true;
|
|
913
|
-
ch = data[++index];
|
|
914
|
-
if (ch === "b") {
|
|
915
|
-
index++;
|
|
916
|
-
for (;index < max; index++) {
|
|
917
|
-
ch = data[index];
|
|
918
|
-
if (ch === "_")
|
|
919
|
-
continue;
|
|
920
|
-
if (ch !== "0" && ch !== "1")
|
|
921
|
-
return false;
|
|
922
|
-
hasDigits = true;
|
|
923
|
-
}
|
|
924
|
-
return hasDigits && ch !== "_";
|
|
925
|
-
}
|
|
926
|
-
if (ch === "x") {
|
|
927
|
-
index++;
|
|
928
|
-
for (;index < max; index++) {
|
|
929
|
-
ch = data[index];
|
|
930
|
-
if (ch === "_")
|
|
931
|
-
continue;
|
|
932
|
-
if (!isHexCode(data.charCodeAt(index)))
|
|
933
|
-
return false;
|
|
934
|
-
hasDigits = true;
|
|
935
|
-
}
|
|
936
|
-
return hasDigits && ch !== "_";
|
|
937
|
-
}
|
|
938
|
-
if (ch === "o") {
|
|
939
|
-
index++;
|
|
940
|
-
for (;index < max; index++) {
|
|
941
|
-
ch = data[index];
|
|
942
|
-
if (ch === "_")
|
|
943
|
-
continue;
|
|
944
|
-
if (!isOctCode(data.charCodeAt(index)))
|
|
945
|
-
return false;
|
|
946
|
-
hasDigits = true;
|
|
947
|
-
}
|
|
948
|
-
return hasDigits && ch !== "_";
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
if (ch === "_")
|
|
952
|
-
return false;
|
|
953
|
-
for (;index < max; index++) {
|
|
954
|
-
ch = data[index];
|
|
955
|
-
if (ch === "_")
|
|
956
|
-
continue;
|
|
957
|
-
if (!isDecCode(data.charCodeAt(index))) {
|
|
958
|
-
return false;
|
|
959
|
-
}
|
|
960
|
-
hasDigits = true;
|
|
961
|
-
}
|
|
962
|
-
if (!hasDigits || ch === "_")
|
|
963
|
-
return false;
|
|
964
|
-
return true;
|
|
965
|
-
}
|
|
966
|
-
function constructYamlInteger(data) {
|
|
967
|
-
var value = data, sign = 1, ch;
|
|
968
|
-
if (value.indexOf("_") !== -1) {
|
|
969
|
-
value = value.replace(/_/g, "");
|
|
970
|
-
}
|
|
971
|
-
ch = value[0];
|
|
972
|
-
if (ch === "-" || ch === "+") {
|
|
973
|
-
if (ch === "-")
|
|
974
|
-
sign = -1;
|
|
975
|
-
value = value.slice(1);
|
|
976
|
-
ch = value[0];
|
|
977
|
-
}
|
|
978
|
-
if (value === "0")
|
|
979
|
-
return 0;
|
|
980
|
-
if (ch === "0") {
|
|
981
|
-
if (value[1] === "b")
|
|
982
|
-
return sign * parseInt(value.slice(2), 2);
|
|
983
|
-
if (value[1] === "x")
|
|
984
|
-
return sign * parseInt(value.slice(2), 16);
|
|
985
|
-
if (value[1] === "o")
|
|
986
|
-
return sign * parseInt(value.slice(2), 8);
|
|
987
|
-
}
|
|
988
|
-
return sign * parseInt(value, 10);
|
|
989
|
-
}
|
|
990
|
-
function isInteger(object) {
|
|
991
|
-
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
|
|
992
|
-
}
|
|
993
|
-
var int = new type("tag:yaml.org,2002:int", {
|
|
994
|
-
kind: "scalar",
|
|
995
|
-
resolve: resolveYamlInteger,
|
|
996
|
-
construct: constructYamlInteger,
|
|
997
|
-
predicate: isInteger,
|
|
998
|
-
represent: {
|
|
999
|
-
binary: function(obj) {
|
|
1000
|
-
return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
|
|
1001
|
-
},
|
|
1002
|
-
octal: function(obj) {
|
|
1003
|
-
return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
|
|
1004
|
-
},
|
|
1005
|
-
decimal: function(obj) {
|
|
1006
|
-
return obj.toString(10);
|
|
1007
|
-
},
|
|
1008
|
-
hexadecimal: function(obj) {
|
|
1009
|
-
return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
|
|
1010
|
-
}
|
|
1011
|
-
},
|
|
1012
|
-
defaultStyle: "decimal",
|
|
1013
|
-
styleAliases: {
|
|
1014
|
-
binary: [2, "bin"],
|
|
1015
|
-
octal: [8, "oct"],
|
|
1016
|
-
decimal: [10, "dec"],
|
|
1017
|
-
hexadecimal: [16, "hex"]
|
|
1018
|
-
}
|
|
1019
|
-
});
|
|
1020
|
-
var YAML_FLOAT_PATTERN = new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?" + "|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?" + "|[-+]?\\.(?:inf|Inf|INF)" + "|\\.(?:nan|NaN|NAN))$");
|
|
1021
|
-
function resolveYamlFloat(data) {
|
|
1022
|
-
if (data === null)
|
|
1023
|
-
return false;
|
|
1024
|
-
if (!YAML_FLOAT_PATTERN.test(data) || data[data.length - 1] === "_") {
|
|
1025
|
-
return false;
|
|
1026
|
-
}
|
|
1027
|
-
return true;
|
|
1028
|
-
}
|
|
1029
|
-
function constructYamlFloat(data) {
|
|
1030
|
-
var value, sign;
|
|
1031
|
-
value = data.replace(/_/g, "").toLowerCase();
|
|
1032
|
-
sign = value[0] === "-" ? -1 : 1;
|
|
1033
|
-
if ("+-".indexOf(value[0]) >= 0) {
|
|
1034
|
-
value = value.slice(1);
|
|
1035
|
-
}
|
|
1036
|
-
if (value === ".inf") {
|
|
1037
|
-
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
1038
|
-
} else if (value === ".nan") {
|
|
1039
|
-
return NaN;
|
|
1040
|
-
}
|
|
1041
|
-
return sign * parseFloat(value, 10);
|
|
1042
|
-
}
|
|
1043
|
-
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
|
1044
|
-
function representYamlFloat(object, style) {
|
|
1045
|
-
var res;
|
|
1046
|
-
if (isNaN(object)) {
|
|
1047
|
-
switch (style) {
|
|
1048
|
-
case "lowercase":
|
|
1049
|
-
return ".nan";
|
|
1050
|
-
case "uppercase":
|
|
1051
|
-
return ".NAN";
|
|
1052
|
-
case "camelcase":
|
|
1053
|
-
return ".NaN";
|
|
1054
|
-
}
|
|
1055
|
-
} else if (Number.POSITIVE_INFINITY === object) {
|
|
1056
|
-
switch (style) {
|
|
1057
|
-
case "lowercase":
|
|
1058
|
-
return ".inf";
|
|
1059
|
-
case "uppercase":
|
|
1060
|
-
return ".INF";
|
|
1061
|
-
case "camelcase":
|
|
1062
|
-
return ".Inf";
|
|
1063
|
-
}
|
|
1064
|
-
} else if (Number.NEGATIVE_INFINITY === object) {
|
|
1065
|
-
switch (style) {
|
|
1066
|
-
case "lowercase":
|
|
1067
|
-
return "-.inf";
|
|
1068
|
-
case "uppercase":
|
|
1069
|
-
return "-.INF";
|
|
1070
|
-
case "camelcase":
|
|
1071
|
-
return "-.Inf";
|
|
1072
|
-
}
|
|
1073
|
-
} else if (common.isNegativeZero(object)) {
|
|
1074
|
-
return "-0.0";
|
|
1075
|
-
}
|
|
1076
|
-
res = object.toString(10);
|
|
1077
|
-
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
|
|
1078
|
-
}
|
|
1079
|
-
function isFloat(object) {
|
|
1080
|
-
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
|
|
1081
|
-
}
|
|
1082
|
-
var float = new type("tag:yaml.org,2002:float", {
|
|
1083
|
-
kind: "scalar",
|
|
1084
|
-
resolve: resolveYamlFloat,
|
|
1085
|
-
construct: constructYamlFloat,
|
|
1086
|
-
predicate: isFloat,
|
|
1087
|
-
represent: representYamlFloat,
|
|
1088
|
-
defaultStyle: "lowercase"
|
|
1089
|
-
});
|
|
1090
|
-
var json = failsafe.extend({
|
|
1091
|
-
implicit: [
|
|
1092
|
-
_null,
|
|
1093
|
-
bool,
|
|
1094
|
-
int,
|
|
1095
|
-
float
|
|
1096
|
-
]
|
|
1097
|
-
});
|
|
1098
|
-
var core = json;
|
|
1099
|
-
var YAML_DATE_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + "-([0-9][0-9])" + "-([0-9][0-9])$");
|
|
1100
|
-
var YAML_TIMESTAMP_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + "-([0-9][0-9]?)" + "-([0-9][0-9]?)" + "(?:[Tt]|[ \\t]+)" + "([0-9][0-9]?)" + ":([0-9][0-9])" + ":([0-9][0-9])" + "(?:\\.([0-9]*))?" + "(?:[ \\t]*(Z|([-+])([0-9][0-9]?)" + "(?::([0-9][0-9]))?))?$");
|
|
1101
|
-
function resolveYamlTimestamp(data) {
|
|
1102
|
-
if (data === null)
|
|
1103
|
-
return false;
|
|
1104
|
-
if (YAML_DATE_REGEXP.exec(data) !== null)
|
|
1105
|
-
return true;
|
|
1106
|
-
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null)
|
|
1107
|
-
return true;
|
|
1108
|
-
return false;
|
|
1109
|
-
}
|
|
1110
|
-
function constructYamlTimestamp(data) {
|
|
1111
|
-
var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
|
|
1112
|
-
match = YAML_DATE_REGEXP.exec(data);
|
|
1113
|
-
if (match === null)
|
|
1114
|
-
match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|
1115
|
-
if (match === null)
|
|
1116
|
-
throw new Error("Date resolve error");
|
|
1117
|
-
year = +match[1];
|
|
1118
|
-
month = +match[2] - 1;
|
|
1119
|
-
day = +match[3];
|
|
1120
|
-
if (!match[4]) {
|
|
1121
|
-
return new Date(Date.UTC(year, month, day));
|
|
1122
|
-
}
|
|
1123
|
-
hour = +match[4];
|
|
1124
|
-
minute = +match[5];
|
|
1125
|
-
second = +match[6];
|
|
1126
|
-
if (match[7]) {
|
|
1127
|
-
fraction = match[7].slice(0, 3);
|
|
1128
|
-
while (fraction.length < 3) {
|
|
1129
|
-
fraction += "0";
|
|
1130
|
-
}
|
|
1131
|
-
fraction = +fraction;
|
|
1132
|
-
}
|
|
1133
|
-
if (match[9]) {
|
|
1134
|
-
tz_hour = +match[10];
|
|
1135
|
-
tz_minute = +(match[11] || 0);
|
|
1136
|
-
delta = (tz_hour * 60 + tz_minute) * 60000;
|
|
1137
|
-
if (match[9] === "-")
|
|
1138
|
-
delta = -delta;
|
|
1139
|
-
}
|
|
1140
|
-
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
1141
|
-
if (delta)
|
|
1142
|
-
date.setTime(date.getTime() - delta);
|
|
1143
|
-
return date;
|
|
1144
|
-
}
|
|
1145
|
-
function representYamlTimestamp(object) {
|
|
1146
|
-
return object.toISOString();
|
|
1147
|
-
}
|
|
1148
|
-
var timestamp = new type("tag:yaml.org,2002:timestamp", {
|
|
1149
|
-
kind: "scalar",
|
|
1150
|
-
resolve: resolveYamlTimestamp,
|
|
1151
|
-
construct: constructYamlTimestamp,
|
|
1152
|
-
instanceOf: Date,
|
|
1153
|
-
represent: representYamlTimestamp
|
|
1154
|
-
});
|
|
1155
|
-
function resolveYamlMerge(data) {
|
|
1156
|
-
return data === "<<" || data === null;
|
|
1157
|
-
}
|
|
1158
|
-
var merge = new type("tag:yaml.org,2002:merge", {
|
|
1159
|
-
kind: "scalar",
|
|
1160
|
-
resolve: resolveYamlMerge
|
|
1161
|
-
});
|
|
1162
|
-
var BASE64_MAP = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
|
|
1163
|
-
\r`;
|
|
1164
|
-
function resolveYamlBinary(data) {
|
|
1165
|
-
if (data === null)
|
|
1166
|
-
return false;
|
|
1167
|
-
var code, idx, bitlen = 0, max = data.length, map2 = BASE64_MAP;
|
|
1168
|
-
for (idx = 0;idx < max; idx++) {
|
|
1169
|
-
code = map2.indexOf(data.charAt(idx));
|
|
1170
|
-
if (code > 64)
|
|
1171
|
-
continue;
|
|
1172
|
-
if (code < 0)
|
|
1173
|
-
return false;
|
|
1174
|
-
bitlen += 6;
|
|
1175
|
-
}
|
|
1176
|
-
return bitlen % 8 === 0;
|
|
1177
|
-
}
|
|
1178
|
-
function constructYamlBinary(data) {
|
|
1179
|
-
var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map2 = BASE64_MAP, bits = 0, result = [];
|
|
1180
|
-
for (idx = 0;idx < max; idx++) {
|
|
1181
|
-
if (idx % 4 === 0 && idx) {
|
|
1182
|
-
result.push(bits >> 16 & 255);
|
|
1183
|
-
result.push(bits >> 8 & 255);
|
|
1184
|
-
result.push(bits & 255);
|
|
1185
|
-
}
|
|
1186
|
-
bits = bits << 6 | map2.indexOf(input.charAt(idx));
|
|
1187
|
-
}
|
|
1188
|
-
tailbits = max % 4 * 6;
|
|
1189
|
-
if (tailbits === 0) {
|
|
1190
|
-
result.push(bits >> 16 & 255);
|
|
1191
|
-
result.push(bits >> 8 & 255);
|
|
1192
|
-
result.push(bits & 255);
|
|
1193
|
-
} else if (tailbits === 18) {
|
|
1194
|
-
result.push(bits >> 10 & 255);
|
|
1195
|
-
result.push(bits >> 2 & 255);
|
|
1196
|
-
} else if (tailbits === 12) {
|
|
1197
|
-
result.push(bits >> 4 & 255);
|
|
1198
|
-
}
|
|
1199
|
-
return new Uint8Array(result);
|
|
1200
|
-
}
|
|
1201
|
-
function representYamlBinary(object) {
|
|
1202
|
-
var result = "", bits = 0, idx, tail, max = object.length, map2 = BASE64_MAP;
|
|
1203
|
-
for (idx = 0;idx < max; idx++) {
|
|
1204
|
-
if (idx % 3 === 0 && idx) {
|
|
1205
|
-
result += map2[bits >> 18 & 63];
|
|
1206
|
-
result += map2[bits >> 12 & 63];
|
|
1207
|
-
result += map2[bits >> 6 & 63];
|
|
1208
|
-
result += map2[bits & 63];
|
|
1209
|
-
}
|
|
1210
|
-
bits = (bits << 8) + object[idx];
|
|
1211
|
-
}
|
|
1212
|
-
tail = max % 3;
|
|
1213
|
-
if (tail === 0) {
|
|
1214
|
-
result += map2[bits >> 18 & 63];
|
|
1215
|
-
result += map2[bits >> 12 & 63];
|
|
1216
|
-
result += map2[bits >> 6 & 63];
|
|
1217
|
-
result += map2[bits & 63];
|
|
1218
|
-
} else if (tail === 2) {
|
|
1219
|
-
result += map2[bits >> 10 & 63];
|
|
1220
|
-
result += map2[bits >> 4 & 63];
|
|
1221
|
-
result += map2[bits << 2 & 63];
|
|
1222
|
-
result += map2[64];
|
|
1223
|
-
} else if (tail === 1) {
|
|
1224
|
-
result += map2[bits >> 2 & 63];
|
|
1225
|
-
result += map2[bits << 4 & 63];
|
|
1226
|
-
result += map2[64];
|
|
1227
|
-
result += map2[64];
|
|
1228
|
-
}
|
|
1229
|
-
return result;
|
|
1230
|
-
}
|
|
1231
|
-
function isBinary(obj) {
|
|
1232
|
-
return Object.prototype.toString.call(obj) === "[object Uint8Array]";
|
|
1233
|
-
}
|
|
1234
|
-
var binary = new type("tag:yaml.org,2002:binary", {
|
|
1235
|
-
kind: "scalar",
|
|
1236
|
-
resolve: resolveYamlBinary,
|
|
1237
|
-
construct: constructYamlBinary,
|
|
1238
|
-
predicate: isBinary,
|
|
1239
|
-
represent: representYamlBinary
|
|
1240
|
-
});
|
|
1241
|
-
var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
1242
|
-
var _toString$2 = Object.prototype.toString;
|
|
1243
|
-
function resolveYamlOmap(data) {
|
|
1244
|
-
if (data === null)
|
|
1245
|
-
return true;
|
|
1246
|
-
var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
|
|
1247
|
-
for (index = 0, length = object.length;index < length; index += 1) {
|
|
1248
|
-
pair = object[index];
|
|
1249
|
-
pairHasKey = false;
|
|
1250
|
-
if (_toString$2.call(pair) !== "[object Object]")
|
|
1251
|
-
return false;
|
|
1252
|
-
for (pairKey in pair) {
|
|
1253
|
-
if (_hasOwnProperty$3.call(pair, pairKey)) {
|
|
1254
|
-
if (!pairHasKey)
|
|
1255
|
-
pairHasKey = true;
|
|
1256
|
-
else
|
|
1257
|
-
return false;
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
if (!pairHasKey)
|
|
1261
|
-
return false;
|
|
1262
|
-
if (objectKeys.indexOf(pairKey) === -1)
|
|
1263
|
-
objectKeys.push(pairKey);
|
|
1264
|
-
else
|
|
1265
|
-
return false;
|
|
1266
|
-
}
|
|
1267
|
-
return true;
|
|
1268
|
-
}
|
|
1269
|
-
function constructYamlOmap(data) {
|
|
1270
|
-
return data !== null ? data : [];
|
|
1271
|
-
}
|
|
1272
|
-
var omap = new type("tag:yaml.org,2002:omap", {
|
|
1273
|
-
kind: "sequence",
|
|
1274
|
-
resolve: resolveYamlOmap,
|
|
1275
|
-
construct: constructYamlOmap
|
|
1276
|
-
});
|
|
1277
|
-
var _toString$1 = Object.prototype.toString;
|
|
1278
|
-
function resolveYamlPairs(data) {
|
|
1279
|
-
if (data === null)
|
|
1280
|
-
return true;
|
|
1281
|
-
var index, length, pair, keys, result, object = data;
|
|
1282
|
-
result = new Array(object.length);
|
|
1283
|
-
for (index = 0, length = object.length;index < length; index += 1) {
|
|
1284
|
-
pair = object[index];
|
|
1285
|
-
if (_toString$1.call(pair) !== "[object Object]")
|
|
1286
|
-
return false;
|
|
1287
|
-
keys = Object.keys(pair);
|
|
1288
|
-
if (keys.length !== 1)
|
|
1289
|
-
return false;
|
|
1290
|
-
result[index] = [keys[0], pair[keys[0]]];
|
|
1291
|
-
}
|
|
1292
|
-
return true;
|
|
1293
|
-
}
|
|
1294
|
-
function constructYamlPairs(data) {
|
|
1295
|
-
if (data === null)
|
|
1296
|
-
return [];
|
|
1297
|
-
var index, length, pair, keys, result, object = data;
|
|
1298
|
-
result = new Array(object.length);
|
|
1299
|
-
for (index = 0, length = object.length;index < length; index += 1) {
|
|
1300
|
-
pair = object[index];
|
|
1301
|
-
keys = Object.keys(pair);
|
|
1302
|
-
result[index] = [keys[0], pair[keys[0]]];
|
|
1303
|
-
}
|
|
1304
|
-
return result;
|
|
1305
|
-
}
|
|
1306
|
-
var pairs = new type("tag:yaml.org,2002:pairs", {
|
|
1307
|
-
kind: "sequence",
|
|
1308
|
-
resolve: resolveYamlPairs,
|
|
1309
|
-
construct: constructYamlPairs
|
|
1310
|
-
});
|
|
1311
|
-
var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
1312
|
-
function resolveYamlSet(data) {
|
|
1313
|
-
if (data === null)
|
|
1314
|
-
return true;
|
|
1315
|
-
var key, object = data;
|
|
1316
|
-
for (key in object) {
|
|
1317
|
-
if (_hasOwnProperty$2.call(object, key)) {
|
|
1318
|
-
if (object[key] !== null)
|
|
1319
|
-
return false;
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
return true;
|
|
1323
|
-
}
|
|
1324
|
-
function constructYamlSet(data) {
|
|
1325
|
-
return data !== null ? data : {};
|
|
1326
|
-
}
|
|
1327
|
-
var set = new type("tag:yaml.org,2002:set", {
|
|
1328
|
-
kind: "mapping",
|
|
1329
|
-
resolve: resolveYamlSet,
|
|
1330
|
-
construct: constructYamlSet
|
|
1331
|
-
});
|
|
1332
|
-
var _default = core.extend({
|
|
1333
|
-
implicit: [
|
|
1334
|
-
timestamp,
|
|
1335
|
-
merge
|
|
1336
|
-
],
|
|
1337
|
-
explicit: [
|
|
1338
|
-
binary,
|
|
1339
|
-
omap,
|
|
1340
|
-
pairs,
|
|
1341
|
-
set
|
|
1342
|
-
]
|
|
1343
|
-
});
|
|
1344
|
-
var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
1345
|
-
var CONTEXT_FLOW_IN = 1;
|
|
1346
|
-
var CONTEXT_FLOW_OUT = 2;
|
|
1347
|
-
var CONTEXT_BLOCK_IN = 3;
|
|
1348
|
-
var CONTEXT_BLOCK_OUT = 4;
|
|
1349
|
-
var CHOMPING_CLIP = 1;
|
|
1350
|
-
var CHOMPING_STRIP = 2;
|
|
1351
|
-
var CHOMPING_KEEP = 3;
|
|
1352
|
-
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
1353
|
-
var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
|
1354
|
-
var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
|
1355
|
-
var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
|
1356
|
-
var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
|
1357
|
-
function _class(obj) {
|
|
1358
|
-
return Object.prototype.toString.call(obj);
|
|
1359
|
-
}
|
|
1360
|
-
function is_EOL(c) {
|
|
1361
|
-
return c === 10 || c === 13;
|
|
1362
|
-
}
|
|
1363
|
-
function is_WHITE_SPACE(c) {
|
|
1364
|
-
return c === 9 || c === 32;
|
|
1365
|
-
}
|
|
1366
|
-
function is_WS_OR_EOL(c) {
|
|
1367
|
-
return c === 9 || c === 32 || c === 10 || c === 13;
|
|
1368
|
-
}
|
|
1369
|
-
function is_FLOW_INDICATOR(c) {
|
|
1370
|
-
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
1371
|
-
}
|
|
1372
|
-
function fromHexCode(c) {
|
|
1373
|
-
var lc;
|
|
1374
|
-
if (48 <= c && c <= 57) {
|
|
1375
|
-
return c - 48;
|
|
1376
|
-
}
|
|
1377
|
-
lc = c | 32;
|
|
1378
|
-
if (97 <= lc && lc <= 102) {
|
|
1379
|
-
return lc - 97 + 10;
|
|
1380
|
-
}
|
|
1381
|
-
return -1;
|
|
1382
|
-
}
|
|
1383
|
-
function escapedHexLen(c) {
|
|
1384
|
-
if (c === 120) {
|
|
1385
|
-
return 2;
|
|
1386
|
-
}
|
|
1387
|
-
if (c === 117) {
|
|
1388
|
-
return 4;
|
|
1389
|
-
}
|
|
1390
|
-
if (c === 85) {
|
|
1391
|
-
return 8;
|
|
1392
|
-
}
|
|
1393
|
-
return 0;
|
|
1394
|
-
}
|
|
1395
|
-
function fromDecimalCode(c) {
|
|
1396
|
-
if (48 <= c && c <= 57) {
|
|
1397
|
-
return c - 48;
|
|
1398
|
-
}
|
|
1399
|
-
return -1;
|
|
1400
|
-
}
|
|
1401
|
-
function simpleEscapeSequence(c) {
|
|
1402
|
-
return c === 48 ? "\x00" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? "\t" : c === 9 ? "\t" : c === 110 ? `
|
|
1403
|
-
` : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "
" : c === 95 ? " " : c === 76 ? "\u2028" : c === 80 ? "\u2029" : "";
|
|
1404
|
-
}
|
|
1405
|
-
function charFromCodepoint(c) {
|
|
1406
|
-
if (c <= 65535) {
|
|
1407
|
-
return String.fromCharCode(c);
|
|
1408
|
-
}
|
|
1409
|
-
return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
|
|
1410
|
-
}
|
|
1411
|
-
function setProperty(object, key, value) {
|
|
1412
|
-
if (key === "__proto__") {
|
|
1413
|
-
Object.defineProperty(object, key, {
|
|
1414
|
-
configurable: true,
|
|
1415
|
-
enumerable: true,
|
|
1416
|
-
writable: true,
|
|
1417
|
-
value
|
|
1418
|
-
});
|
|
1419
|
-
} else {
|
|
1420
|
-
object[key] = value;
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
var simpleEscapeCheck = new Array(256);
|
|
1424
|
-
var simpleEscapeMap = new Array(256);
|
|
1425
|
-
for (i = 0;i < 256; i++) {
|
|
1426
|
-
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
1427
|
-
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
1428
|
-
}
|
|
1429
|
-
var i;
|
|
1430
|
-
function State$1(input, options) {
|
|
1431
|
-
this.input = input;
|
|
1432
|
-
this.filename = options["filename"] || null;
|
|
1433
|
-
this.schema = options["schema"] || _default;
|
|
1434
|
-
this.onWarning = options["onWarning"] || null;
|
|
1435
|
-
this.legacy = options["legacy"] || false;
|
|
1436
|
-
this.json = options["json"] || false;
|
|
1437
|
-
this.listener = options["listener"] || null;
|
|
1438
|
-
this.implicitTypes = this.schema.compiledImplicit;
|
|
1439
|
-
this.typeMap = this.schema.compiledTypeMap;
|
|
1440
|
-
this.length = input.length;
|
|
1441
|
-
this.position = 0;
|
|
1442
|
-
this.line = 0;
|
|
1443
|
-
this.lineStart = 0;
|
|
1444
|
-
this.lineIndent = 0;
|
|
1445
|
-
this.firstTabInLine = -1;
|
|
1446
|
-
this.documents = [];
|
|
1447
|
-
}
|
|
1448
|
-
function generateError(state, message) {
|
|
1449
|
-
var mark = {
|
|
1450
|
-
name: state.filename,
|
|
1451
|
-
buffer: state.input.slice(0, -1),
|
|
1452
|
-
position: state.position,
|
|
1453
|
-
line: state.line,
|
|
1454
|
-
column: state.position - state.lineStart
|
|
1455
|
-
};
|
|
1456
|
-
mark.snippet = snippet(mark);
|
|
1457
|
-
return new exception(message, mark);
|
|
1458
|
-
}
|
|
1459
|
-
function throwError(state, message) {
|
|
1460
|
-
throw generateError(state, message);
|
|
1461
|
-
}
|
|
1462
|
-
function throwWarning(state, message) {
|
|
1463
|
-
if (state.onWarning) {
|
|
1464
|
-
state.onWarning.call(null, generateError(state, message));
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
var directiveHandlers = {
|
|
1468
|
-
YAML: function handleYamlDirective(state, name, args) {
|
|
1469
|
-
var match, major, minor;
|
|
1470
|
-
if (state.version !== null) {
|
|
1471
|
-
throwError(state, "duplication of %YAML directive");
|
|
1472
|
-
}
|
|
1473
|
-
if (args.length !== 1) {
|
|
1474
|
-
throwError(state, "YAML directive accepts exactly one argument");
|
|
1475
|
-
}
|
|
1476
|
-
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
1477
|
-
if (match === null) {
|
|
1478
|
-
throwError(state, "ill-formed argument of the YAML directive");
|
|
1479
|
-
}
|
|
1480
|
-
major = parseInt(match[1], 10);
|
|
1481
|
-
minor = parseInt(match[2], 10);
|
|
1482
|
-
if (major !== 1) {
|
|
1483
|
-
throwError(state, "unacceptable YAML version of the document");
|
|
1484
|
-
}
|
|
1485
|
-
state.version = args[0];
|
|
1486
|
-
state.checkLineBreaks = minor < 2;
|
|
1487
|
-
if (minor !== 1 && minor !== 2) {
|
|
1488
|
-
throwWarning(state, "unsupported YAML version of the document");
|
|
1489
|
-
}
|
|
1490
|
-
},
|
|
1491
|
-
TAG: function handleTagDirective(state, name, args) {
|
|
1492
|
-
var handle, prefix;
|
|
1493
|
-
if (args.length !== 2) {
|
|
1494
|
-
throwError(state, "TAG directive accepts exactly two arguments");
|
|
1495
|
-
}
|
|
1496
|
-
handle = args[0];
|
|
1497
|
-
prefix = args[1];
|
|
1498
|
-
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|
1499
|
-
throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
1500
|
-
}
|
|
1501
|
-
if (_hasOwnProperty$1.call(state.tagMap, handle)) {
|
|
1502
|
-
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|
1503
|
-
}
|
|
1504
|
-
if (!PATTERN_TAG_URI.test(prefix)) {
|
|
1505
|
-
throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
1506
|
-
}
|
|
1507
|
-
try {
|
|
1508
|
-
prefix = decodeURIComponent(prefix);
|
|
1509
|
-
} catch (err) {
|
|
1510
|
-
throwError(state, "tag prefix is malformed: " + prefix);
|
|
1511
|
-
}
|
|
1512
|
-
state.tagMap[handle] = prefix;
|
|
1513
|
-
}
|
|
1514
|
-
};
|
|
1515
|
-
function captureSegment(state, start, end, checkJson) {
|
|
1516
|
-
var _position, _length, _character, _result;
|
|
1517
|
-
if (start < end) {
|
|
1518
|
-
_result = state.input.slice(start, end);
|
|
1519
|
-
if (checkJson) {
|
|
1520
|
-
for (_position = 0, _length = _result.length;_position < _length; _position += 1) {
|
|
1521
|
-
_character = _result.charCodeAt(_position);
|
|
1522
|
-
if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
|
|
1523
|
-
throwError(state, "expected valid JSON character");
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|
1527
|
-
throwError(state, "the stream contains non-printable characters");
|
|
1528
|
-
}
|
|
1529
|
-
state.result += _result;
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
function mergeMappings(state, destination, source, overridableKeys) {
|
|
1533
|
-
var sourceKeys, key, index, quantity;
|
|
1534
|
-
if (!common.isObject(source)) {
|
|
1535
|
-
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1536
|
-
}
|
|
1537
|
-
sourceKeys = Object.keys(source);
|
|
1538
|
-
for (index = 0, quantity = sourceKeys.length;index < quantity; index += 1) {
|
|
1539
|
-
key = sourceKeys[index];
|
|
1540
|
-
if (!_hasOwnProperty$1.call(destination, key)) {
|
|
1541
|
-
setProperty(destination, key, source[key]);
|
|
1542
|
-
overridableKeys[key] = true;
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
|
|
1547
|
-
var index, quantity;
|
|
1548
|
-
if (Array.isArray(keyNode)) {
|
|
1549
|
-
keyNode = Array.prototype.slice.call(keyNode);
|
|
1550
|
-
for (index = 0, quantity = keyNode.length;index < quantity; index += 1) {
|
|
1551
|
-
if (Array.isArray(keyNode[index])) {
|
|
1552
|
-
throwError(state, "nested arrays are not supported inside keys");
|
|
1553
|
-
}
|
|
1554
|
-
if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
|
|
1555
|
-
keyNode[index] = "[object Object]";
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
|
|
1560
|
-
keyNode = "[object Object]";
|
|
1561
|
-
}
|
|
1562
|
-
keyNode = String(keyNode);
|
|
1563
|
-
if (_result === null) {
|
|
1564
|
-
_result = {};
|
|
1565
|
-
}
|
|
1566
|
-
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
1567
|
-
if (Array.isArray(valueNode)) {
|
|
1568
|
-
for (index = 0, quantity = valueNode.length;index < quantity; index += 1) {
|
|
1569
|
-
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
1570
|
-
}
|
|
1571
|
-
} else {
|
|
1572
|
-
mergeMappings(state, _result, valueNode, overridableKeys);
|
|
1573
|
-
}
|
|
1574
|
-
} else {
|
|
1575
|
-
if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
|
|
1576
|
-
state.line = startLine || state.line;
|
|
1577
|
-
state.lineStart = startLineStart || state.lineStart;
|
|
1578
|
-
state.position = startPos || state.position;
|
|
1579
|
-
throwError(state, "duplicated mapping key");
|
|
1580
|
-
}
|
|
1581
|
-
setProperty(_result, keyNode, valueNode);
|
|
1582
|
-
delete overridableKeys[keyNode];
|
|
1583
|
-
}
|
|
1584
|
-
return _result;
|
|
1585
|
-
}
|
|
1586
|
-
function readLineBreak(state) {
|
|
1587
|
-
var ch;
|
|
1588
|
-
ch = state.input.charCodeAt(state.position);
|
|
1589
|
-
if (ch === 10) {
|
|
1590
|
-
state.position++;
|
|
1591
|
-
} else if (ch === 13) {
|
|
1592
|
-
state.position++;
|
|
1593
|
-
if (state.input.charCodeAt(state.position) === 10) {
|
|
1594
|
-
state.position++;
|
|
1595
|
-
}
|
|
1596
|
-
} else {
|
|
1597
|
-
throwError(state, "a line break is expected");
|
|
1598
|
-
}
|
|
1599
|
-
state.line += 1;
|
|
1600
|
-
state.lineStart = state.position;
|
|
1601
|
-
state.firstTabInLine = -1;
|
|
1602
|
-
}
|
|
1603
|
-
function skipSeparationSpace(state, allowComments, checkIndent) {
|
|
1604
|
-
var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
|
|
1605
|
-
while (ch !== 0) {
|
|
1606
|
-
while (is_WHITE_SPACE(ch)) {
|
|
1607
|
-
if (ch === 9 && state.firstTabInLine === -1) {
|
|
1608
|
-
state.firstTabInLine = state.position;
|
|
1609
|
-
}
|
|
1610
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1611
|
-
}
|
|
1612
|
-
if (allowComments && ch === 35) {
|
|
1613
|
-
do {
|
|
1614
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1615
|
-
} while (ch !== 10 && ch !== 13 && ch !== 0);
|
|
1616
|
-
}
|
|
1617
|
-
if (is_EOL(ch)) {
|
|
1618
|
-
readLineBreak(state);
|
|
1619
|
-
ch = state.input.charCodeAt(state.position);
|
|
1620
|
-
lineBreaks++;
|
|
1621
|
-
state.lineIndent = 0;
|
|
1622
|
-
while (ch === 32) {
|
|
1623
|
-
state.lineIndent++;
|
|
1624
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1625
|
-
}
|
|
1626
|
-
} else {
|
|
1627
|
-
break;
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
1631
|
-
throwWarning(state, "deficient indentation");
|
|
1632
|
-
}
|
|
1633
|
-
return lineBreaks;
|
|
1634
|
-
}
|
|
1635
|
-
function testDocumentSeparator(state) {
|
|
1636
|
-
var _position = state.position, ch;
|
|
1637
|
-
ch = state.input.charCodeAt(_position);
|
|
1638
|
-
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
|
|
1639
|
-
_position += 3;
|
|
1640
|
-
ch = state.input.charCodeAt(_position);
|
|
1641
|
-
if (ch === 0 || is_WS_OR_EOL(ch)) {
|
|
1642
|
-
return true;
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
return false;
|
|
1646
|
-
}
|
|
1647
|
-
function writeFoldedLines(state, count) {
|
|
1648
|
-
if (count === 1) {
|
|
1649
|
-
state.result += " ";
|
|
1650
|
-
} else if (count > 1) {
|
|
1651
|
-
state.result += common.repeat(`
|
|
1652
|
-
`, count - 1);
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
1656
|
-
var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
|
|
1657
|
-
ch = state.input.charCodeAt(state.position);
|
|
1658
|
-
if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) {
|
|
1659
|
-
return false;
|
|
1660
|
-
}
|
|
1661
|
-
if (ch === 63 || ch === 45) {
|
|
1662
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
1663
|
-
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1664
|
-
return false;
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
state.kind = "scalar";
|
|
1668
|
-
state.result = "";
|
|
1669
|
-
captureStart = captureEnd = state.position;
|
|
1670
|
-
hasPendingContent = false;
|
|
1671
|
-
while (ch !== 0) {
|
|
1672
|
-
if (ch === 58) {
|
|
1673
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
1674
|
-
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1675
|
-
break;
|
|
1676
|
-
}
|
|
1677
|
-
} else if (ch === 35) {
|
|
1678
|
-
preceding = state.input.charCodeAt(state.position - 1);
|
|
1679
|
-
if (is_WS_OR_EOL(preceding)) {
|
|
1680
|
-
break;
|
|
1681
|
-
}
|
|
1682
|
-
} else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
|
1683
|
-
break;
|
|
1684
|
-
} else if (is_EOL(ch)) {
|
|
1685
|
-
_line = state.line;
|
|
1686
|
-
_lineStart = state.lineStart;
|
|
1687
|
-
_lineIndent = state.lineIndent;
|
|
1688
|
-
skipSeparationSpace(state, false, -1);
|
|
1689
|
-
if (state.lineIndent >= nodeIndent) {
|
|
1690
|
-
hasPendingContent = true;
|
|
1691
|
-
ch = state.input.charCodeAt(state.position);
|
|
1692
|
-
continue;
|
|
1693
|
-
} else {
|
|
1694
|
-
state.position = captureEnd;
|
|
1695
|
-
state.line = _line;
|
|
1696
|
-
state.lineStart = _lineStart;
|
|
1697
|
-
state.lineIndent = _lineIndent;
|
|
1698
|
-
break;
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
if (hasPendingContent) {
|
|
1702
|
-
captureSegment(state, captureStart, captureEnd, false);
|
|
1703
|
-
writeFoldedLines(state, state.line - _line);
|
|
1704
|
-
captureStart = captureEnd = state.position;
|
|
1705
|
-
hasPendingContent = false;
|
|
1706
|
-
}
|
|
1707
|
-
if (!is_WHITE_SPACE(ch)) {
|
|
1708
|
-
captureEnd = state.position + 1;
|
|
1709
|
-
}
|
|
1710
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1711
|
-
}
|
|
1712
|
-
captureSegment(state, captureStart, captureEnd, false);
|
|
1713
|
-
if (state.result) {
|
|
1714
|
-
return true;
|
|
1715
|
-
}
|
|
1716
|
-
state.kind = _kind;
|
|
1717
|
-
state.result = _result;
|
|
1718
|
-
return false;
|
|
1719
|
-
}
|
|
1720
|
-
function readSingleQuotedScalar(state, nodeIndent) {
|
|
1721
|
-
var ch, captureStart, captureEnd;
|
|
1722
|
-
ch = state.input.charCodeAt(state.position);
|
|
1723
|
-
if (ch !== 39) {
|
|
1724
|
-
return false;
|
|
1725
|
-
}
|
|
1726
|
-
state.kind = "scalar";
|
|
1727
|
-
state.result = "";
|
|
1728
|
-
state.position++;
|
|
1729
|
-
captureStart = captureEnd = state.position;
|
|
1730
|
-
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1731
|
-
if (ch === 39) {
|
|
1732
|
-
captureSegment(state, captureStart, state.position, true);
|
|
1733
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1734
|
-
if (ch === 39) {
|
|
1735
|
-
captureStart = state.position;
|
|
1736
|
-
state.position++;
|
|
1737
|
-
captureEnd = state.position;
|
|
1738
|
-
} else {
|
|
1739
|
-
return true;
|
|
1740
|
-
}
|
|
1741
|
-
} else if (is_EOL(ch)) {
|
|
1742
|
-
captureSegment(state, captureStart, captureEnd, true);
|
|
1743
|
-
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1744
|
-
captureStart = captureEnd = state.position;
|
|
1745
|
-
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1746
|
-
throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
1747
|
-
} else {
|
|
1748
|
-
state.position++;
|
|
1749
|
-
captureEnd = state.position;
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
1753
|
-
}
|
|
1754
|
-
function readDoubleQuotedScalar(state, nodeIndent) {
|
|
1755
|
-
var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
|
|
1756
|
-
ch = state.input.charCodeAt(state.position);
|
|
1757
|
-
if (ch !== 34) {
|
|
1758
|
-
return false;
|
|
1759
|
-
}
|
|
1760
|
-
state.kind = "scalar";
|
|
1761
|
-
state.result = "";
|
|
1762
|
-
state.position++;
|
|
1763
|
-
captureStart = captureEnd = state.position;
|
|
1764
|
-
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1765
|
-
if (ch === 34) {
|
|
1766
|
-
captureSegment(state, captureStart, state.position, true);
|
|
1767
|
-
state.position++;
|
|
1768
|
-
return true;
|
|
1769
|
-
} else if (ch === 92) {
|
|
1770
|
-
captureSegment(state, captureStart, state.position, true);
|
|
1771
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1772
|
-
if (is_EOL(ch)) {
|
|
1773
|
-
skipSeparationSpace(state, false, nodeIndent);
|
|
1774
|
-
} else if (ch < 256 && simpleEscapeCheck[ch]) {
|
|
1775
|
-
state.result += simpleEscapeMap[ch];
|
|
1776
|
-
state.position++;
|
|
1777
|
-
} else if ((tmp = escapedHexLen(ch)) > 0) {
|
|
1778
|
-
hexLength = tmp;
|
|
1779
|
-
hexResult = 0;
|
|
1780
|
-
for (;hexLength > 0; hexLength--) {
|
|
1781
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1782
|
-
if ((tmp = fromHexCode(ch)) >= 0) {
|
|
1783
|
-
hexResult = (hexResult << 4) + tmp;
|
|
1784
|
-
} else {
|
|
1785
|
-
throwError(state, "expected hexadecimal character");
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
state.result += charFromCodepoint(hexResult);
|
|
1789
|
-
state.position++;
|
|
1790
|
-
} else {
|
|
1791
|
-
throwError(state, "unknown escape sequence");
|
|
1792
|
-
}
|
|
1793
|
-
captureStart = captureEnd = state.position;
|
|
1794
|
-
} else if (is_EOL(ch)) {
|
|
1795
|
-
captureSegment(state, captureStart, captureEnd, true);
|
|
1796
|
-
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1797
|
-
captureStart = captureEnd = state.position;
|
|
1798
|
-
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1799
|
-
throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
1800
|
-
} else {
|
|
1801
|
-
state.position++;
|
|
1802
|
-
captureEnd = state.position;
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
1806
|
-
}
|
|
1807
|
-
function readFlowCollection(state, nodeIndent) {
|
|
1808
|
-
var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = Object.create(null), keyNode, keyTag, valueNode, ch;
|
|
1809
|
-
ch = state.input.charCodeAt(state.position);
|
|
1810
|
-
if (ch === 91) {
|
|
1811
|
-
terminator = 93;
|
|
1812
|
-
isMapping = false;
|
|
1813
|
-
_result = [];
|
|
1814
|
-
} else if (ch === 123) {
|
|
1815
|
-
terminator = 125;
|
|
1816
|
-
isMapping = true;
|
|
1817
|
-
_result = {};
|
|
1818
|
-
} else {
|
|
1819
|
-
return false;
|
|
1820
|
-
}
|
|
1821
|
-
if (state.anchor !== null) {
|
|
1822
|
-
state.anchorMap[state.anchor] = _result;
|
|
1823
|
-
}
|
|
1824
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1825
|
-
while (ch !== 0) {
|
|
1826
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
1827
|
-
ch = state.input.charCodeAt(state.position);
|
|
1828
|
-
if (ch === terminator) {
|
|
1829
|
-
state.position++;
|
|
1830
|
-
state.tag = _tag;
|
|
1831
|
-
state.anchor = _anchor;
|
|
1832
|
-
state.kind = isMapping ? "mapping" : "sequence";
|
|
1833
|
-
state.result = _result;
|
|
1834
|
-
return true;
|
|
1835
|
-
} else if (!readNext) {
|
|
1836
|
-
throwError(state, "missed comma between flow collection entries");
|
|
1837
|
-
} else if (ch === 44) {
|
|
1838
|
-
throwError(state, "expected the node content, but found ','");
|
|
1839
|
-
}
|
|
1840
|
-
keyTag = keyNode = valueNode = null;
|
|
1841
|
-
isPair = isExplicitPair = false;
|
|
1842
|
-
if (ch === 63) {
|
|
1843
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
1844
|
-
if (is_WS_OR_EOL(following)) {
|
|
1845
|
-
isPair = isExplicitPair = true;
|
|
1846
|
-
state.position++;
|
|
1847
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
_line = state.line;
|
|
1851
|
-
_lineStart = state.lineStart;
|
|
1852
|
-
_pos = state.position;
|
|
1853
|
-
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1854
|
-
keyTag = state.tag;
|
|
1855
|
-
keyNode = state.result;
|
|
1856
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
1857
|
-
ch = state.input.charCodeAt(state.position);
|
|
1858
|
-
if ((isExplicitPair || state.line === _line) && ch === 58) {
|
|
1859
|
-
isPair = true;
|
|
1860
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1861
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
1862
|
-
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1863
|
-
valueNode = state.result;
|
|
1864
|
-
}
|
|
1865
|
-
if (isMapping) {
|
|
1866
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
|
|
1867
|
-
} else if (isPair) {
|
|
1868
|
-
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
|
|
1869
|
-
} else {
|
|
1870
|
-
_result.push(keyNode);
|
|
1871
|
-
}
|
|
1872
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
1873
|
-
ch = state.input.charCodeAt(state.position);
|
|
1874
|
-
if (ch === 44) {
|
|
1875
|
-
readNext = true;
|
|
1876
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1877
|
-
} else {
|
|
1878
|
-
readNext = false;
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
throwError(state, "unexpected end of the stream within a flow collection");
|
|
1882
|
-
}
|
|
1883
|
-
function readBlockScalar(state, nodeIndent) {
|
|
1884
|
-
var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
|
|
1885
|
-
ch = state.input.charCodeAt(state.position);
|
|
1886
|
-
if (ch === 124) {
|
|
1887
|
-
folding = false;
|
|
1888
|
-
} else if (ch === 62) {
|
|
1889
|
-
folding = true;
|
|
1890
|
-
} else {
|
|
1891
|
-
return false;
|
|
1892
|
-
}
|
|
1893
|
-
state.kind = "scalar";
|
|
1894
|
-
state.result = "";
|
|
1895
|
-
while (ch !== 0) {
|
|
1896
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1897
|
-
if (ch === 43 || ch === 45) {
|
|
1898
|
-
if (CHOMPING_CLIP === chomping) {
|
|
1899
|
-
chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
1900
|
-
} else {
|
|
1901
|
-
throwError(state, "repeat of a chomping mode identifier");
|
|
1902
|
-
}
|
|
1903
|
-
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|
1904
|
-
if (tmp === 0) {
|
|
1905
|
-
throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
1906
|
-
} else if (!detectedIndent) {
|
|
1907
|
-
textIndent = nodeIndent + tmp - 1;
|
|
1908
|
-
detectedIndent = true;
|
|
1909
|
-
} else {
|
|
1910
|
-
throwError(state, "repeat of an indentation width identifier");
|
|
1911
|
-
}
|
|
1912
|
-
} else {
|
|
1913
|
-
break;
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
if (is_WHITE_SPACE(ch)) {
|
|
1917
|
-
do {
|
|
1918
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1919
|
-
} while (is_WHITE_SPACE(ch));
|
|
1920
|
-
if (ch === 35) {
|
|
1921
|
-
do {
|
|
1922
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1923
|
-
} while (!is_EOL(ch) && ch !== 0);
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
while (ch !== 0) {
|
|
1927
|
-
readLineBreak(state);
|
|
1928
|
-
state.lineIndent = 0;
|
|
1929
|
-
ch = state.input.charCodeAt(state.position);
|
|
1930
|
-
while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
|
|
1931
|
-
state.lineIndent++;
|
|
1932
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1933
|
-
}
|
|
1934
|
-
if (!detectedIndent && state.lineIndent > textIndent) {
|
|
1935
|
-
textIndent = state.lineIndent;
|
|
1936
|
-
}
|
|
1937
|
-
if (is_EOL(ch)) {
|
|
1938
|
-
emptyLines++;
|
|
1939
|
-
continue;
|
|
1940
|
-
}
|
|
1941
|
-
if (state.lineIndent < textIndent) {
|
|
1942
|
-
if (chomping === CHOMPING_KEEP) {
|
|
1943
|
-
state.result += common.repeat(`
|
|
1944
|
-
`, didReadContent ? 1 + emptyLines : emptyLines);
|
|
1945
|
-
} else if (chomping === CHOMPING_CLIP) {
|
|
1946
|
-
if (didReadContent) {
|
|
1947
|
-
state.result += `
|
|
1948
|
-
`;
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
break;
|
|
1952
|
-
}
|
|
1953
|
-
if (folding) {
|
|
1954
|
-
if (is_WHITE_SPACE(ch)) {
|
|
1955
|
-
atMoreIndented = true;
|
|
1956
|
-
state.result += common.repeat(`
|
|
1957
|
-
`, didReadContent ? 1 + emptyLines : emptyLines);
|
|
1958
|
-
} else if (atMoreIndented) {
|
|
1959
|
-
atMoreIndented = false;
|
|
1960
|
-
state.result += common.repeat(`
|
|
1961
|
-
`, emptyLines + 1);
|
|
1962
|
-
} else if (emptyLines === 0) {
|
|
1963
|
-
if (didReadContent) {
|
|
1964
|
-
state.result += " ";
|
|
1965
|
-
}
|
|
1966
|
-
} else {
|
|
1967
|
-
state.result += common.repeat(`
|
|
1968
|
-
`, emptyLines);
|
|
1969
|
-
}
|
|
1970
|
-
} else {
|
|
1971
|
-
state.result += common.repeat(`
|
|
1972
|
-
`, didReadContent ? 1 + emptyLines : emptyLines);
|
|
1973
|
-
}
|
|
1974
|
-
didReadContent = true;
|
|
1975
|
-
detectedIndent = true;
|
|
1976
|
-
emptyLines = 0;
|
|
1977
|
-
captureStart = state.position;
|
|
1978
|
-
while (!is_EOL(ch) && ch !== 0) {
|
|
1979
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1980
|
-
}
|
|
1981
|
-
captureSegment(state, captureStart, state.position, false);
|
|
1982
|
-
}
|
|
1983
|
-
return true;
|
|
1984
|
-
}
|
|
1985
|
-
function readBlockSequence(state, nodeIndent) {
|
|
1986
|
-
var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
|
|
1987
|
-
if (state.firstTabInLine !== -1)
|
|
1988
|
-
return false;
|
|
1989
|
-
if (state.anchor !== null) {
|
|
1990
|
-
state.anchorMap[state.anchor] = _result;
|
|
1991
|
-
}
|
|
1992
|
-
ch = state.input.charCodeAt(state.position);
|
|
1993
|
-
while (ch !== 0) {
|
|
1994
|
-
if (state.firstTabInLine !== -1) {
|
|
1995
|
-
state.position = state.firstTabInLine;
|
|
1996
|
-
throwError(state, "tab characters must not be used in indentation");
|
|
1997
|
-
}
|
|
1998
|
-
if (ch !== 45) {
|
|
1999
|
-
break;
|
|
2000
|
-
}
|
|
2001
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
2002
|
-
if (!is_WS_OR_EOL(following)) {
|
|
2003
|
-
break;
|
|
2004
|
-
}
|
|
2005
|
-
detected = true;
|
|
2006
|
-
state.position++;
|
|
2007
|
-
if (skipSeparationSpace(state, true, -1)) {
|
|
2008
|
-
if (state.lineIndent <= nodeIndent) {
|
|
2009
|
-
_result.push(null);
|
|
2010
|
-
ch = state.input.charCodeAt(state.position);
|
|
2011
|
-
continue;
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
_line = state.line;
|
|
2015
|
-
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
2016
|
-
_result.push(state.result);
|
|
2017
|
-
skipSeparationSpace(state, true, -1);
|
|
2018
|
-
ch = state.input.charCodeAt(state.position);
|
|
2019
|
-
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
2020
|
-
throwError(state, "bad indentation of a sequence entry");
|
|
2021
|
-
} else if (state.lineIndent < nodeIndent) {
|
|
2022
|
-
break;
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
if (detected) {
|
|
2026
|
-
state.tag = _tag;
|
|
2027
|
-
state.anchor = _anchor;
|
|
2028
|
-
state.kind = "sequence";
|
|
2029
|
-
state.result = _result;
|
|
2030
|
-
return true;
|
|
2031
|
-
}
|
|
2032
|
-
return false;
|
|
2033
|
-
}
|
|
2034
|
-
function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
2035
|
-
var following, allowCompact, _line, _keyLine, _keyLineStart, _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = Object.create(null), keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch;
|
|
2036
|
-
if (state.firstTabInLine !== -1)
|
|
2037
|
-
return false;
|
|
2038
|
-
if (state.anchor !== null) {
|
|
2039
|
-
state.anchorMap[state.anchor] = _result;
|
|
2040
|
-
}
|
|
2041
|
-
ch = state.input.charCodeAt(state.position);
|
|
2042
|
-
while (ch !== 0) {
|
|
2043
|
-
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
2044
|
-
state.position = state.firstTabInLine;
|
|
2045
|
-
throwError(state, "tab characters must not be used in indentation");
|
|
2046
|
-
}
|
|
2047
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
2048
|
-
_line = state.line;
|
|
2049
|
-
if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
|
|
2050
|
-
if (ch === 63) {
|
|
2051
|
-
if (atExplicitKey) {
|
|
2052
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
2053
|
-
keyTag = keyNode = valueNode = null;
|
|
2054
|
-
}
|
|
2055
|
-
detected = true;
|
|
2056
|
-
atExplicitKey = true;
|
|
2057
|
-
allowCompact = true;
|
|
2058
|
-
} else if (atExplicitKey) {
|
|
2059
|
-
atExplicitKey = false;
|
|
2060
|
-
allowCompact = true;
|
|
2061
|
-
} else {
|
|
2062
|
-
throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
|
|
2063
|
-
}
|
|
2064
|
-
state.position += 1;
|
|
2065
|
-
ch = following;
|
|
2066
|
-
} else {
|
|
2067
|
-
_keyLine = state.line;
|
|
2068
|
-
_keyLineStart = state.lineStart;
|
|
2069
|
-
_keyPos = state.position;
|
|
2070
|
-
if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
|
2071
|
-
break;
|
|
2072
|
-
}
|
|
2073
|
-
if (state.line === _line) {
|
|
2074
|
-
ch = state.input.charCodeAt(state.position);
|
|
2075
|
-
while (is_WHITE_SPACE(ch)) {
|
|
2076
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2077
|
-
}
|
|
2078
|
-
if (ch === 58) {
|
|
2079
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2080
|
-
if (!is_WS_OR_EOL(ch)) {
|
|
2081
|
-
throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
2082
|
-
}
|
|
2083
|
-
if (atExplicitKey) {
|
|
2084
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
2085
|
-
keyTag = keyNode = valueNode = null;
|
|
2086
|
-
}
|
|
2087
|
-
detected = true;
|
|
2088
|
-
atExplicitKey = false;
|
|
2089
|
-
allowCompact = false;
|
|
2090
|
-
keyTag = state.tag;
|
|
2091
|
-
keyNode = state.result;
|
|
2092
|
-
} else if (detected) {
|
|
2093
|
-
throwError(state, "can not read an implicit mapping pair; a colon is missed");
|
|
2094
|
-
} else {
|
|
2095
|
-
state.tag = _tag;
|
|
2096
|
-
state.anchor = _anchor;
|
|
2097
|
-
return true;
|
|
2098
|
-
}
|
|
2099
|
-
} else if (detected) {
|
|
2100
|
-
throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
2101
|
-
} else {
|
|
2102
|
-
state.tag = _tag;
|
|
2103
|
-
state.anchor = _anchor;
|
|
2104
|
-
return true;
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
if (state.line === _line || state.lineIndent > nodeIndent) {
|
|
2108
|
-
if (atExplicitKey) {
|
|
2109
|
-
_keyLine = state.line;
|
|
2110
|
-
_keyLineStart = state.lineStart;
|
|
2111
|
-
_keyPos = state.position;
|
|
2112
|
-
}
|
|
2113
|
-
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
|
2114
|
-
if (atExplicitKey) {
|
|
2115
|
-
keyNode = state.result;
|
|
2116
|
-
} else {
|
|
2117
|
-
valueNode = state.result;
|
|
2118
|
-
}
|
|
2119
|
-
}
|
|
2120
|
-
if (!atExplicitKey) {
|
|
2121
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
|
|
2122
|
-
keyTag = keyNode = valueNode = null;
|
|
2123
|
-
}
|
|
2124
|
-
skipSeparationSpace(state, true, -1);
|
|
2125
|
-
ch = state.input.charCodeAt(state.position);
|
|
2126
|
-
}
|
|
2127
|
-
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
2128
|
-
throwError(state, "bad indentation of a mapping entry");
|
|
2129
|
-
} else if (state.lineIndent < nodeIndent) {
|
|
2130
|
-
break;
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
if (atExplicitKey) {
|
|
2134
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
2135
|
-
}
|
|
2136
|
-
if (detected) {
|
|
2137
|
-
state.tag = _tag;
|
|
2138
|
-
state.anchor = _anchor;
|
|
2139
|
-
state.kind = "mapping";
|
|
2140
|
-
state.result = _result;
|
|
2141
|
-
}
|
|
2142
|
-
return detected;
|
|
2143
|
-
}
|
|
2144
|
-
function readTagProperty(state) {
|
|
2145
|
-
var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
|
|
2146
|
-
ch = state.input.charCodeAt(state.position);
|
|
2147
|
-
if (ch !== 33)
|
|
2148
|
-
return false;
|
|
2149
|
-
if (state.tag !== null) {
|
|
2150
|
-
throwError(state, "duplication of a tag property");
|
|
2151
|
-
}
|
|
2152
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2153
|
-
if (ch === 60) {
|
|
2154
|
-
isVerbatim = true;
|
|
2155
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2156
|
-
} else if (ch === 33) {
|
|
2157
|
-
isNamed = true;
|
|
2158
|
-
tagHandle = "!!";
|
|
2159
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2160
|
-
} else {
|
|
2161
|
-
tagHandle = "!";
|
|
2162
|
-
}
|
|
2163
|
-
_position = state.position;
|
|
2164
|
-
if (isVerbatim) {
|
|
2165
|
-
do {
|
|
2166
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2167
|
-
} while (ch !== 0 && ch !== 62);
|
|
2168
|
-
if (state.position < state.length) {
|
|
2169
|
-
tagName = state.input.slice(_position, state.position);
|
|
2170
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2171
|
-
} else {
|
|
2172
|
-
throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
2173
|
-
}
|
|
2174
|
-
} else {
|
|
2175
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2176
|
-
if (ch === 33) {
|
|
2177
|
-
if (!isNamed) {
|
|
2178
|
-
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|
2179
|
-
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
2180
|
-
throwError(state, "named tag handle cannot contain such characters");
|
|
2181
|
-
}
|
|
2182
|
-
isNamed = true;
|
|
2183
|
-
_position = state.position + 1;
|
|
2184
|
-
} else {
|
|
2185
|
-
throwError(state, "tag suffix cannot contain exclamation marks");
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2189
|
-
}
|
|
2190
|
-
tagName = state.input.slice(_position, state.position);
|
|
2191
|
-
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
2192
|
-
throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|
2196
|
-
throwError(state, "tag name cannot contain such characters: " + tagName);
|
|
2197
|
-
}
|
|
2198
|
-
try {
|
|
2199
|
-
tagName = decodeURIComponent(tagName);
|
|
2200
|
-
} catch (err) {
|
|
2201
|
-
throwError(state, "tag name is malformed: " + tagName);
|
|
2202
|
-
}
|
|
2203
|
-
if (isVerbatim) {
|
|
2204
|
-
state.tag = tagName;
|
|
2205
|
-
} else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
|
|
2206
|
-
state.tag = state.tagMap[tagHandle] + tagName;
|
|
2207
|
-
} else if (tagHandle === "!") {
|
|
2208
|
-
state.tag = "!" + tagName;
|
|
2209
|
-
} else if (tagHandle === "!!") {
|
|
2210
|
-
state.tag = "tag:yaml.org,2002:" + tagName;
|
|
2211
|
-
} else {
|
|
2212
|
-
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|
2213
|
-
}
|
|
2214
|
-
return true;
|
|
2215
|
-
}
|
|
2216
|
-
function readAnchorProperty(state) {
|
|
2217
|
-
var _position, ch;
|
|
2218
|
-
ch = state.input.charCodeAt(state.position);
|
|
2219
|
-
if (ch !== 38)
|
|
2220
|
-
return false;
|
|
2221
|
-
if (state.anchor !== null) {
|
|
2222
|
-
throwError(state, "duplication of an anchor property");
|
|
2223
|
-
}
|
|
2224
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2225
|
-
_position = state.position;
|
|
2226
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
2227
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2228
|
-
}
|
|
2229
|
-
if (state.position === _position) {
|
|
2230
|
-
throwError(state, "name of an anchor node must contain at least one character");
|
|
2231
|
-
}
|
|
2232
|
-
state.anchor = state.input.slice(_position, state.position);
|
|
2233
|
-
return true;
|
|
2234
|
-
}
|
|
2235
|
-
function readAlias(state) {
|
|
2236
|
-
var _position, alias, ch;
|
|
2237
|
-
ch = state.input.charCodeAt(state.position);
|
|
2238
|
-
if (ch !== 42)
|
|
2239
|
-
return false;
|
|
2240
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2241
|
-
_position = state.position;
|
|
2242
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
2243
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2244
|
-
}
|
|
2245
|
-
if (state.position === _position) {
|
|
2246
|
-
throwError(state, "name of an alias node must contain at least one character");
|
|
2247
|
-
}
|
|
2248
|
-
alias = state.input.slice(_position, state.position);
|
|
2249
|
-
if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
|
|
2250
|
-
throwError(state, 'unidentified alias "' + alias + '"');
|
|
2251
|
-
}
|
|
2252
|
-
state.result = state.anchorMap[alias];
|
|
2253
|
-
skipSeparationSpace(state, true, -1);
|
|
2254
|
-
return true;
|
|
2255
|
-
}
|
|
2256
|
-
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|
2257
|
-
var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
|
|
2258
|
-
if (state.listener !== null) {
|
|
2259
|
-
state.listener("open", state);
|
|
2260
|
-
}
|
|
2261
|
-
state.tag = null;
|
|
2262
|
-
state.anchor = null;
|
|
2263
|
-
state.kind = null;
|
|
2264
|
-
state.result = null;
|
|
2265
|
-
allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
|
|
2266
|
-
if (allowToSeek) {
|
|
2267
|
-
if (skipSeparationSpace(state, true, -1)) {
|
|
2268
|
-
atNewLine = true;
|
|
2269
|
-
if (state.lineIndent > parentIndent) {
|
|
2270
|
-
indentStatus = 1;
|
|
2271
|
-
} else if (state.lineIndent === parentIndent) {
|
|
2272
|
-
indentStatus = 0;
|
|
2273
|
-
} else if (state.lineIndent < parentIndent) {
|
|
2274
|
-
indentStatus = -1;
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
if (indentStatus === 1) {
|
|
2279
|
-
while (readTagProperty(state) || readAnchorProperty(state)) {
|
|
2280
|
-
if (skipSeparationSpace(state, true, -1)) {
|
|
2281
|
-
atNewLine = true;
|
|
2282
|
-
allowBlockCollections = allowBlockStyles;
|
|
2283
|
-
if (state.lineIndent > parentIndent) {
|
|
2284
|
-
indentStatus = 1;
|
|
2285
|
-
} else if (state.lineIndent === parentIndent) {
|
|
2286
|
-
indentStatus = 0;
|
|
2287
|
-
} else if (state.lineIndent < parentIndent) {
|
|
2288
|
-
indentStatus = -1;
|
|
2289
|
-
}
|
|
2290
|
-
} else {
|
|
2291
|
-
allowBlockCollections = false;
|
|
2292
|
-
}
|
|
2293
|
-
}
|
|
2294
|
-
}
|
|
2295
|
-
if (allowBlockCollections) {
|
|
2296
|
-
allowBlockCollections = atNewLine || allowCompact;
|
|
2297
|
-
}
|
|
2298
|
-
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
|
2299
|
-
if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
|
2300
|
-
flowIndent = parentIndent;
|
|
2301
|
-
} else {
|
|
2302
|
-
flowIndent = parentIndent + 1;
|
|
2303
|
-
}
|
|
2304
|
-
blockIndent = state.position - state.lineStart;
|
|
2305
|
-
if (indentStatus === 1) {
|
|
2306
|
-
if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
|
|
2307
|
-
hasContent = true;
|
|
2308
|
-
} else {
|
|
2309
|
-
if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
|
|
2310
|
-
hasContent = true;
|
|
2311
|
-
} else if (readAlias(state)) {
|
|
2312
|
-
hasContent = true;
|
|
2313
|
-
if (state.tag !== null || state.anchor !== null) {
|
|
2314
|
-
throwError(state, "alias node should not have any properties");
|
|
2315
|
-
}
|
|
2316
|
-
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|
2317
|
-
hasContent = true;
|
|
2318
|
-
if (state.tag === null) {
|
|
2319
|
-
state.tag = "?";
|
|
2320
|
-
}
|
|
2321
|
-
}
|
|
2322
|
-
if (state.anchor !== null) {
|
|
2323
|
-
state.anchorMap[state.anchor] = state.result;
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
} else if (indentStatus === 0) {
|
|
2327
|
-
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
if (state.tag === null) {
|
|
2331
|
-
if (state.anchor !== null) {
|
|
2332
|
-
state.anchorMap[state.anchor] = state.result;
|
|
2333
|
-
}
|
|
2334
|
-
} else if (state.tag === "?") {
|
|
2335
|
-
if (state.result !== null && state.kind !== "scalar") {
|
|
2336
|
-
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|
2337
|
-
}
|
|
2338
|
-
for (typeIndex = 0, typeQuantity = state.implicitTypes.length;typeIndex < typeQuantity; typeIndex += 1) {
|
|
2339
|
-
type2 = state.implicitTypes[typeIndex];
|
|
2340
|
-
if (type2.resolve(state.result)) {
|
|
2341
|
-
state.result = type2.construct(state.result);
|
|
2342
|
-
state.tag = type2.tag;
|
|
2343
|
-
if (state.anchor !== null) {
|
|
2344
|
-
state.anchorMap[state.anchor] = state.result;
|
|
2345
|
-
}
|
|
2346
|
-
break;
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
} else if (state.tag !== "!") {
|
|
2350
|
-
if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
|
|
2351
|
-
type2 = state.typeMap[state.kind || "fallback"][state.tag];
|
|
2352
|
-
} else {
|
|
2353
|
-
type2 = null;
|
|
2354
|
-
typeList = state.typeMap.multi[state.kind || "fallback"];
|
|
2355
|
-
for (typeIndex = 0, typeQuantity = typeList.length;typeIndex < typeQuantity; typeIndex += 1) {
|
|
2356
|
-
if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
|
|
2357
|
-
type2 = typeList[typeIndex];
|
|
2358
|
-
break;
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
if (!type2) {
|
|
2363
|
-
throwError(state, "unknown tag !<" + state.tag + ">");
|
|
2364
|
-
}
|
|
2365
|
-
if (state.result !== null && type2.kind !== state.kind) {
|
|
2366
|
-
throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
|
|
2367
|
-
}
|
|
2368
|
-
if (!type2.resolve(state.result, state.tag)) {
|
|
2369
|
-
throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
|
|
2370
|
-
} else {
|
|
2371
|
-
state.result = type2.construct(state.result, state.tag);
|
|
2372
|
-
if (state.anchor !== null) {
|
|
2373
|
-
state.anchorMap[state.anchor] = state.result;
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
}
|
|
2377
|
-
if (state.listener !== null) {
|
|
2378
|
-
state.listener("close", state);
|
|
2379
|
-
}
|
|
2380
|
-
return state.tag !== null || state.anchor !== null || hasContent;
|
|
2381
|
-
}
|
|
2382
|
-
function readDocument(state) {
|
|
2383
|
-
var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
|
|
2384
|
-
state.version = null;
|
|
2385
|
-
state.checkLineBreaks = state.legacy;
|
|
2386
|
-
state.tagMap = Object.create(null);
|
|
2387
|
-
state.anchorMap = Object.create(null);
|
|
2388
|
-
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
2389
|
-
skipSeparationSpace(state, true, -1);
|
|
2390
|
-
ch = state.input.charCodeAt(state.position);
|
|
2391
|
-
if (state.lineIndent > 0 || ch !== 37) {
|
|
2392
|
-
break;
|
|
2393
|
-
}
|
|
2394
|
-
hasDirectives = true;
|
|
2395
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2396
|
-
_position = state.position;
|
|
2397
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2398
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2399
|
-
}
|
|
2400
|
-
directiveName = state.input.slice(_position, state.position);
|
|
2401
|
-
directiveArgs = [];
|
|
2402
|
-
if (directiveName.length < 1) {
|
|
2403
|
-
throwError(state, "directive name must not be less than one character in length");
|
|
2404
|
-
}
|
|
2405
|
-
while (ch !== 0) {
|
|
2406
|
-
while (is_WHITE_SPACE(ch)) {
|
|
2407
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2408
|
-
}
|
|
2409
|
-
if (ch === 35) {
|
|
2410
|
-
do {
|
|
2411
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2412
|
-
} while (ch !== 0 && !is_EOL(ch));
|
|
2413
|
-
break;
|
|
2414
|
-
}
|
|
2415
|
-
if (is_EOL(ch))
|
|
2416
|
-
break;
|
|
2417
|
-
_position = state.position;
|
|
2418
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2419
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2420
|
-
}
|
|
2421
|
-
directiveArgs.push(state.input.slice(_position, state.position));
|
|
2422
|
-
}
|
|
2423
|
-
if (ch !== 0)
|
|
2424
|
-
readLineBreak(state);
|
|
2425
|
-
if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
|
|
2426
|
-
directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
|
2427
|
-
} else {
|
|
2428
|
-
throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
|
2429
|
-
}
|
|
2430
|
-
}
|
|
2431
|
-
skipSeparationSpace(state, true, -1);
|
|
2432
|
-
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
|
|
2433
|
-
state.position += 3;
|
|
2434
|
-
skipSeparationSpace(state, true, -1);
|
|
2435
|
-
} else if (hasDirectives) {
|
|
2436
|
-
throwError(state, "directives end mark is expected");
|
|
2437
|
-
}
|
|
2438
|
-
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|
2439
|
-
skipSeparationSpace(state, true, -1);
|
|
2440
|
-
if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
2441
|
-
throwWarning(state, "non-ASCII line breaks are interpreted as content");
|
|
2442
|
-
}
|
|
2443
|
-
state.documents.push(state.result);
|
|
2444
|
-
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2445
|
-
if (state.input.charCodeAt(state.position) === 46) {
|
|
2446
|
-
state.position += 3;
|
|
2447
|
-
skipSeparationSpace(state, true, -1);
|
|
2448
|
-
}
|
|
2449
|
-
return;
|
|
2450
|
-
}
|
|
2451
|
-
if (state.position < state.length - 1) {
|
|
2452
|
-
throwError(state, "end of the stream or a document separator is expected");
|
|
2453
|
-
} else {
|
|
2454
|
-
return;
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
function loadDocuments(input, options) {
|
|
2458
|
-
input = String(input);
|
|
2459
|
-
options = options || {};
|
|
2460
|
-
if (input.length !== 0) {
|
|
2461
|
-
if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
|
|
2462
|
-
input += `
|
|
2463
|
-
`;
|
|
2464
|
-
}
|
|
2465
|
-
if (input.charCodeAt(0) === 65279) {
|
|
2466
|
-
input = input.slice(1);
|
|
2467
|
-
}
|
|
2468
|
-
}
|
|
2469
|
-
var state = new State$1(input, options);
|
|
2470
|
-
var nullpos = input.indexOf("\x00");
|
|
2471
|
-
if (nullpos !== -1) {
|
|
2472
|
-
state.position = nullpos;
|
|
2473
|
-
throwError(state, "null byte is not allowed in input");
|
|
2474
|
-
}
|
|
2475
|
-
state.input += "\x00";
|
|
2476
|
-
while (state.input.charCodeAt(state.position) === 32) {
|
|
2477
|
-
state.lineIndent += 1;
|
|
2478
|
-
state.position += 1;
|
|
2479
|
-
}
|
|
2480
|
-
while (state.position < state.length - 1) {
|
|
2481
|
-
readDocument(state);
|
|
2482
|
-
}
|
|
2483
|
-
return state.documents;
|
|
2484
|
-
}
|
|
2485
|
-
function loadAll$1(input, iterator, options) {
|
|
2486
|
-
if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
|
|
2487
|
-
options = iterator;
|
|
2488
|
-
iterator = null;
|
|
2489
|
-
}
|
|
2490
|
-
var documents = loadDocuments(input, options);
|
|
2491
|
-
if (typeof iterator !== "function") {
|
|
2492
|
-
return documents;
|
|
2493
|
-
}
|
|
2494
|
-
for (var index = 0, length = documents.length;index < length; index += 1) {
|
|
2495
|
-
iterator(documents[index]);
|
|
2496
|
-
}
|
|
2497
|
-
}
|
|
2498
|
-
function load$1(input, options) {
|
|
2499
|
-
var documents = loadDocuments(input, options);
|
|
2500
|
-
if (documents.length === 0) {
|
|
2501
|
-
return;
|
|
2502
|
-
} else if (documents.length === 1) {
|
|
2503
|
-
return documents[0];
|
|
2504
|
-
}
|
|
2505
|
-
throw new exception("expected a single document in the stream, but found more");
|
|
2506
|
-
}
|
|
2507
|
-
var loadAll_1 = loadAll$1;
|
|
2508
|
-
var load_1 = load$1;
|
|
2509
|
-
var loader = {
|
|
2510
|
-
loadAll: loadAll_1,
|
|
2511
|
-
load: load_1
|
|
2512
|
-
};
|
|
2513
|
-
var _toString = Object.prototype.toString;
|
|
2514
|
-
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2515
|
-
var CHAR_BOM = 65279;
|
|
2516
|
-
var CHAR_TAB = 9;
|
|
2517
|
-
var CHAR_LINE_FEED = 10;
|
|
2518
|
-
var CHAR_CARRIAGE_RETURN = 13;
|
|
2519
|
-
var CHAR_SPACE = 32;
|
|
2520
|
-
var CHAR_EXCLAMATION = 33;
|
|
2521
|
-
var CHAR_DOUBLE_QUOTE = 34;
|
|
2522
|
-
var CHAR_SHARP = 35;
|
|
2523
|
-
var CHAR_PERCENT = 37;
|
|
2524
|
-
var CHAR_AMPERSAND = 38;
|
|
2525
|
-
var CHAR_SINGLE_QUOTE = 39;
|
|
2526
|
-
var CHAR_ASTERISK = 42;
|
|
2527
|
-
var CHAR_COMMA = 44;
|
|
2528
|
-
var CHAR_MINUS = 45;
|
|
2529
|
-
var CHAR_COLON = 58;
|
|
2530
|
-
var CHAR_EQUALS = 61;
|
|
2531
|
-
var CHAR_GREATER_THAN = 62;
|
|
2532
|
-
var CHAR_QUESTION = 63;
|
|
2533
|
-
var CHAR_COMMERCIAL_AT = 64;
|
|
2534
|
-
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
2535
|
-
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
2536
|
-
var CHAR_GRAVE_ACCENT = 96;
|
|
2537
|
-
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
2538
|
-
var CHAR_VERTICAL_LINE = 124;
|
|
2539
|
-
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
2540
|
-
var ESCAPE_SEQUENCES = {};
|
|
2541
|
-
ESCAPE_SEQUENCES[0] = "\\0";
|
|
2542
|
-
ESCAPE_SEQUENCES[7] = "\\a";
|
|
2543
|
-
ESCAPE_SEQUENCES[8] = "\\b";
|
|
2544
|
-
ESCAPE_SEQUENCES[9] = "\\t";
|
|
2545
|
-
ESCAPE_SEQUENCES[10] = "\\n";
|
|
2546
|
-
ESCAPE_SEQUENCES[11] = "\\v";
|
|
2547
|
-
ESCAPE_SEQUENCES[12] = "\\f";
|
|
2548
|
-
ESCAPE_SEQUENCES[13] = "\\r";
|
|
2549
|
-
ESCAPE_SEQUENCES[27] = "\\e";
|
|
2550
|
-
ESCAPE_SEQUENCES[34] = "\\\"";
|
|
2551
|
-
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
2552
|
-
ESCAPE_SEQUENCES[133] = "\\N";
|
|
2553
|
-
ESCAPE_SEQUENCES[160] = "\\_";
|
|
2554
|
-
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
2555
|
-
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
2556
|
-
var DEPRECATED_BOOLEANS_SYNTAX = [
|
|
2557
|
-
"y",
|
|
2558
|
-
"Y",
|
|
2559
|
-
"yes",
|
|
2560
|
-
"Yes",
|
|
2561
|
-
"YES",
|
|
2562
|
-
"on",
|
|
2563
|
-
"On",
|
|
2564
|
-
"ON",
|
|
2565
|
-
"n",
|
|
2566
|
-
"N",
|
|
2567
|
-
"no",
|
|
2568
|
-
"No",
|
|
2569
|
-
"NO",
|
|
2570
|
-
"off",
|
|
2571
|
-
"Off",
|
|
2572
|
-
"OFF"
|
|
2573
|
-
];
|
|
2574
|
-
var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
|
|
2575
|
-
function compileStyleMap(schema2, map2) {
|
|
2576
|
-
var result, keys, index, length, tag, style, type2;
|
|
2577
|
-
if (map2 === null)
|
|
2578
|
-
return {};
|
|
2579
|
-
result = {};
|
|
2580
|
-
keys = Object.keys(map2);
|
|
2581
|
-
for (index = 0, length = keys.length;index < length; index += 1) {
|
|
2582
|
-
tag = keys[index];
|
|
2583
|
-
style = String(map2[tag]);
|
|
2584
|
-
if (tag.slice(0, 2) === "!!") {
|
|
2585
|
-
tag = "tag:yaml.org,2002:" + tag.slice(2);
|
|
2586
|
-
}
|
|
2587
|
-
type2 = schema2.compiledTypeMap["fallback"][tag];
|
|
2588
|
-
if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
|
|
2589
|
-
style = type2.styleAliases[style];
|
|
2590
|
-
}
|
|
2591
|
-
result[tag] = style;
|
|
2592
|
-
}
|
|
2593
|
-
return result;
|
|
2594
|
-
}
|
|
2595
|
-
function encodeHex(character) {
|
|
2596
|
-
var string, handle, length;
|
|
2597
|
-
string = character.toString(16).toUpperCase();
|
|
2598
|
-
if (character <= 255) {
|
|
2599
|
-
handle = "x";
|
|
2600
|
-
length = 2;
|
|
2601
|
-
} else if (character <= 65535) {
|
|
2602
|
-
handle = "u";
|
|
2603
|
-
length = 4;
|
|
2604
|
-
} else if (character <= 4294967295) {
|
|
2605
|
-
handle = "U";
|
|
2606
|
-
length = 8;
|
|
2607
|
-
} else {
|
|
2608
|
-
throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
|
|
2609
|
-
}
|
|
2610
|
-
return "\\" + handle + common.repeat("0", length - string.length) + string;
|
|
2611
|
-
}
|
|
2612
|
-
var QUOTING_TYPE_SINGLE = 1;
|
|
2613
|
-
var QUOTING_TYPE_DOUBLE = 2;
|
|
2614
|
-
function State(options) {
|
|
2615
|
-
this.schema = options["schema"] || _default;
|
|
2616
|
-
this.indent = Math.max(1, options["indent"] || 2);
|
|
2617
|
-
this.noArrayIndent = options["noArrayIndent"] || false;
|
|
2618
|
-
this.skipInvalid = options["skipInvalid"] || false;
|
|
2619
|
-
this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
|
|
2620
|
-
this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
|
|
2621
|
-
this.sortKeys = options["sortKeys"] || false;
|
|
2622
|
-
this.lineWidth = options["lineWidth"] || 80;
|
|
2623
|
-
this.noRefs = options["noRefs"] || false;
|
|
2624
|
-
this.noCompatMode = options["noCompatMode"] || false;
|
|
2625
|
-
this.condenseFlow = options["condenseFlow"] || false;
|
|
2626
|
-
this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
|
|
2627
|
-
this.forceQuotes = options["forceQuotes"] || false;
|
|
2628
|
-
this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
|
|
2629
|
-
this.implicitTypes = this.schema.compiledImplicit;
|
|
2630
|
-
this.explicitTypes = this.schema.compiledExplicit;
|
|
2631
|
-
this.tag = null;
|
|
2632
|
-
this.result = "";
|
|
2633
|
-
this.duplicates = [];
|
|
2634
|
-
this.usedDuplicates = null;
|
|
2635
|
-
}
|
|
2636
|
-
function indentString(string, spaces) {
|
|
2637
|
-
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
|
|
2638
|
-
while (position < length) {
|
|
2639
|
-
next = string.indexOf(`
|
|
2640
|
-
`, position);
|
|
2641
|
-
if (next === -1) {
|
|
2642
|
-
line = string.slice(position);
|
|
2643
|
-
position = length;
|
|
2644
|
-
} else {
|
|
2645
|
-
line = string.slice(position, next + 1);
|
|
2646
|
-
position = next + 1;
|
|
2647
|
-
}
|
|
2648
|
-
if (line.length && line !== `
|
|
2649
|
-
`)
|
|
2650
|
-
result += ind;
|
|
2651
|
-
result += line;
|
|
2652
|
-
}
|
|
2653
|
-
return result;
|
|
2654
|
-
}
|
|
2655
|
-
function generateNextLine(state, level) {
|
|
2656
|
-
return `
|
|
2657
|
-
` + common.repeat(" ", state.indent * level);
|
|
2658
|
-
}
|
|
2659
|
-
function testImplicitResolving(state, str2) {
|
|
2660
|
-
var index, length, type2;
|
|
2661
|
-
for (index = 0, length = state.implicitTypes.length;index < length; index += 1) {
|
|
2662
|
-
type2 = state.implicitTypes[index];
|
|
2663
|
-
if (type2.resolve(str2)) {
|
|
2664
|
-
return true;
|
|
2665
|
-
}
|
|
2666
|
-
}
|
|
2667
|
-
return false;
|
|
2668
|
-
}
|
|
2669
|
-
function isWhitespace(c) {
|
|
2670
|
-
return c === CHAR_SPACE || c === CHAR_TAB;
|
|
2671
|
-
}
|
|
2672
|
-
function isPrintable(c) {
|
|
2673
|
-
return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
|
|
2674
|
-
}
|
|
2675
|
-
function isNsCharOrWhitespace(c) {
|
|
2676
|
-
return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
|
|
2677
|
-
}
|
|
2678
|
-
function isPlainSafe(c, prev, inblock) {
|
|
2679
|
-
var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
|
|
2680
|
-
var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
|
|
2681
|
-
return (inblock ? cIsNsCharOrWhitespace : cIsNsCharOrWhitespace && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && c !== CHAR_SHARP && !(prev === CHAR_COLON && !cIsNsChar) || isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP || prev === CHAR_COLON && cIsNsChar;
|
|
2682
|
-
}
|
|
2683
|
-
function isPlainSafeFirst(c) {
|
|
2684
|
-
return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
|
|
2685
|
-
}
|
|
2686
|
-
function isPlainSafeLast(c) {
|
|
2687
|
-
return !isWhitespace(c) && c !== CHAR_COLON;
|
|
2688
|
-
}
|
|
2689
|
-
function codePointAt(string, pos) {
|
|
2690
|
-
var first = string.charCodeAt(pos), second;
|
|
2691
|
-
if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
|
|
2692
|
-
second = string.charCodeAt(pos + 1);
|
|
2693
|
-
if (second >= 56320 && second <= 57343) {
|
|
2694
|
-
return (first - 55296) * 1024 + second - 56320 + 65536;
|
|
2695
|
-
}
|
|
2696
|
-
}
|
|
2697
|
-
return first;
|
|
2698
|
-
}
|
|
2699
|
-
function needIndentIndicator(string) {
|
|
2700
|
-
var leadingSpaceRe = /^\n* /;
|
|
2701
|
-
return leadingSpaceRe.test(string);
|
|
2702
|
-
}
|
|
2703
|
-
var STYLE_PLAIN = 1;
|
|
2704
|
-
var STYLE_SINGLE = 2;
|
|
2705
|
-
var STYLE_LITERAL = 3;
|
|
2706
|
-
var STYLE_FOLDED = 4;
|
|
2707
|
-
var STYLE_DOUBLE = 5;
|
|
2708
|
-
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
|
|
2709
|
-
var i2;
|
|
2710
|
-
var char = 0;
|
|
2711
|
-
var prevChar = null;
|
|
2712
|
-
var hasLineBreak = false;
|
|
2713
|
-
var hasFoldableLine = false;
|
|
2714
|
-
var shouldTrackWidth = lineWidth !== -1;
|
|
2715
|
-
var previousLineBreak = -1;
|
|
2716
|
-
var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
|
|
2717
|
-
if (singleLineOnly || forceQuotes) {
|
|
2718
|
-
for (i2 = 0;i2 < string.length; char >= 65536 ? i2 += 2 : i2++) {
|
|
2719
|
-
char = codePointAt(string, i2);
|
|
2720
|
-
if (!isPrintable(char)) {
|
|
2721
|
-
return STYLE_DOUBLE;
|
|
2722
|
-
}
|
|
2723
|
-
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2724
|
-
prevChar = char;
|
|
2725
|
-
}
|
|
2726
|
-
} else {
|
|
2727
|
-
for (i2 = 0;i2 < string.length; char >= 65536 ? i2 += 2 : i2++) {
|
|
2728
|
-
char = codePointAt(string, i2);
|
|
2729
|
-
if (char === CHAR_LINE_FEED) {
|
|
2730
|
-
hasLineBreak = true;
|
|
2731
|
-
if (shouldTrackWidth) {
|
|
2732
|
-
hasFoldableLine = hasFoldableLine || i2 - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2733
|
-
previousLineBreak = i2;
|
|
2734
|
-
}
|
|
2735
|
-
} else if (!isPrintable(char)) {
|
|
2736
|
-
return STYLE_DOUBLE;
|
|
2737
|
-
}
|
|
2738
|
-
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2739
|
-
prevChar = char;
|
|
2740
|
-
}
|
|
2741
|
-
hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i2 - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
|
|
2742
|
-
}
|
|
2743
|
-
if (!hasLineBreak && !hasFoldableLine) {
|
|
2744
|
-
if (plain && !forceQuotes && !testAmbiguousType(string)) {
|
|
2745
|
-
return STYLE_PLAIN;
|
|
2746
|
-
}
|
|
2747
|
-
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2748
|
-
}
|
|
2749
|
-
if (indentPerLevel > 9 && needIndentIndicator(string)) {
|
|
2750
|
-
return STYLE_DOUBLE;
|
|
2751
|
-
}
|
|
2752
|
-
if (!forceQuotes) {
|
|
2753
|
-
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
2754
|
-
}
|
|
2755
|
-
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2756
|
-
}
|
|
2757
|
-
function writeScalar(state, string, level, iskey, inblock) {
|
|
2758
|
-
state.dump = function() {
|
|
2759
|
-
if (string.length === 0) {
|
|
2760
|
-
return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
|
|
2761
|
-
}
|
|
2762
|
-
if (!state.noCompatMode) {
|
|
2763
|
-
if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
|
|
2764
|
-
return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
|
|
2765
|
-
}
|
|
2766
|
-
}
|
|
2767
|
-
var indent = state.indent * Math.max(1, level);
|
|
2768
|
-
var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
|
2769
|
-
var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
|
|
2770
|
-
function testAmbiguity(string2) {
|
|
2771
|
-
return testImplicitResolving(state, string2);
|
|
2772
|
-
}
|
|
2773
|
-
switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity, state.quotingType, state.forceQuotes && !iskey, inblock)) {
|
|
2774
|
-
case STYLE_PLAIN:
|
|
2775
|
-
return string;
|
|
2776
|
-
case STYLE_SINGLE:
|
|
2777
|
-
return "'" + string.replace(/'/g, "''") + "'";
|
|
2778
|
-
case STYLE_LITERAL:
|
|
2779
|
-
return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
|
|
2780
|
-
case STYLE_FOLDED:
|
|
2781
|
-
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
2782
|
-
case STYLE_DOUBLE:
|
|
2783
|
-
return '"' + escapeString(string) + '"';
|
|
2784
|
-
default:
|
|
2785
|
-
throw new exception("impossible error: invalid scalar style");
|
|
2786
|
-
}
|
|
2787
|
-
}();
|
|
2788
|
-
}
|
|
2789
|
-
function blockHeader(string, indentPerLevel) {
|
|
2790
|
-
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2791
|
-
var clip = string[string.length - 1] === `
|
|
2792
|
-
`;
|
|
2793
|
-
var keep = clip && (string[string.length - 2] === `
|
|
2794
|
-
` || string === `
|
|
2795
|
-
`);
|
|
2796
|
-
var chomp = keep ? "+" : clip ? "" : "-";
|
|
2797
|
-
return indentIndicator + chomp + `
|
|
2798
|
-
`;
|
|
2799
|
-
}
|
|
2800
|
-
function dropEndingNewline(string) {
|
|
2801
|
-
return string[string.length - 1] === `
|
|
2802
|
-
` ? string.slice(0, -1) : string;
|
|
2803
|
-
}
|
|
2804
|
-
function foldString(string, width) {
|
|
2805
|
-
var lineRe = /(\n+)([^\n]*)/g;
|
|
2806
|
-
var result = function() {
|
|
2807
|
-
var nextLF = string.indexOf(`
|
|
2808
|
-
`);
|
|
2809
|
-
nextLF = nextLF !== -1 ? nextLF : string.length;
|
|
2810
|
-
lineRe.lastIndex = nextLF;
|
|
2811
|
-
return foldLine(string.slice(0, nextLF), width);
|
|
2812
|
-
}();
|
|
2813
|
-
var prevMoreIndented = string[0] === `
|
|
2814
|
-
` || string[0] === " ";
|
|
2815
|
-
var moreIndented;
|
|
2816
|
-
var match;
|
|
2817
|
-
while (match = lineRe.exec(string)) {
|
|
2818
|
-
var prefix = match[1], line = match[2];
|
|
2819
|
-
moreIndented = line[0] === " ";
|
|
2820
|
-
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? `
|
|
2821
|
-
` : "") + foldLine(line, width);
|
|
2822
|
-
prevMoreIndented = moreIndented;
|
|
2823
|
-
}
|
|
2824
|
-
return result;
|
|
2825
|
-
}
|
|
2826
|
-
function foldLine(line, width) {
|
|
2827
|
-
if (line === "" || line[0] === " ")
|
|
2828
|
-
return line;
|
|
2829
|
-
var breakRe = / [^ ]/g;
|
|
2830
|
-
var match;
|
|
2831
|
-
var start = 0, end, curr = 0, next = 0;
|
|
2832
|
-
var result = "";
|
|
2833
|
-
while (match = breakRe.exec(line)) {
|
|
2834
|
-
next = match.index;
|
|
2835
|
-
if (next - start > width) {
|
|
2836
|
-
end = curr > start ? curr : next;
|
|
2837
|
-
result += `
|
|
2838
|
-
` + line.slice(start, end);
|
|
2839
|
-
start = end + 1;
|
|
2840
|
-
}
|
|
2841
|
-
curr = next;
|
|
2842
|
-
}
|
|
2843
|
-
result += `
|
|
2844
|
-
`;
|
|
2845
|
-
if (line.length - start > width && curr > start) {
|
|
2846
|
-
result += line.slice(start, curr) + `
|
|
2847
|
-
` + line.slice(curr + 1);
|
|
2848
|
-
} else {
|
|
2849
|
-
result += line.slice(start);
|
|
2850
|
-
}
|
|
2851
|
-
return result.slice(1);
|
|
2852
|
-
}
|
|
2853
|
-
function escapeString(string) {
|
|
2854
|
-
var result = "";
|
|
2855
|
-
var char = 0;
|
|
2856
|
-
var escapeSeq;
|
|
2857
|
-
for (var i2 = 0;i2 < string.length; char >= 65536 ? i2 += 2 : i2++) {
|
|
2858
|
-
char = codePointAt(string, i2);
|
|
2859
|
-
escapeSeq = ESCAPE_SEQUENCES[char];
|
|
2860
|
-
if (!escapeSeq && isPrintable(char)) {
|
|
2861
|
-
result += string[i2];
|
|
2862
|
-
if (char >= 65536)
|
|
2863
|
-
result += string[i2 + 1];
|
|
2864
|
-
} else {
|
|
2865
|
-
result += escapeSeq || encodeHex(char);
|
|
2866
|
-
}
|
|
2867
|
-
}
|
|
2868
|
-
return result;
|
|
2869
|
-
}
|
|
2870
|
-
function writeFlowSequence(state, level, object) {
|
|
2871
|
-
var _result = "", _tag = state.tag, index, length, value;
|
|
2872
|
-
for (index = 0, length = object.length;index < length; index += 1) {
|
|
2873
|
-
value = object[index];
|
|
2874
|
-
if (state.replacer) {
|
|
2875
|
-
value = state.replacer.call(object, String(index), value);
|
|
2876
|
-
}
|
|
2877
|
-
if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
|
|
2878
|
-
if (_result !== "")
|
|
2879
|
-
_result += "," + (!state.condenseFlow ? " " : "");
|
|
2880
|
-
_result += state.dump;
|
|
2881
|
-
}
|
|
2882
|
-
}
|
|
2883
|
-
state.tag = _tag;
|
|
2884
|
-
state.dump = "[" + _result + "]";
|
|
2885
|
-
}
|
|
2886
|
-
function writeBlockSequence(state, level, object, compact) {
|
|
2887
|
-
var _result = "", _tag = state.tag, index, length, value;
|
|
2888
|
-
for (index = 0, length = object.length;index < length; index += 1) {
|
|
2889
|
-
value = object[index];
|
|
2890
|
-
if (state.replacer) {
|
|
2891
|
-
value = state.replacer.call(object, String(index), value);
|
|
2892
|
-
}
|
|
2893
|
-
if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
|
|
2894
|
-
if (!compact || _result !== "") {
|
|
2895
|
-
_result += generateNextLine(state, level);
|
|
2896
|
-
}
|
|
2897
|
-
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2898
|
-
_result += "-";
|
|
2899
|
-
} else {
|
|
2900
|
-
_result += "- ";
|
|
2901
|
-
}
|
|
2902
|
-
_result += state.dump;
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
2905
|
-
state.tag = _tag;
|
|
2906
|
-
state.dump = _result || "[]";
|
|
2907
|
-
}
|
|
2908
|
-
function writeFlowMapping(state, level, object) {
|
|
2909
|
-
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
|
|
2910
|
-
for (index = 0, length = objectKeyList.length;index < length; index += 1) {
|
|
2911
|
-
pairBuffer = "";
|
|
2912
|
-
if (_result !== "")
|
|
2913
|
-
pairBuffer += ", ";
|
|
2914
|
-
if (state.condenseFlow)
|
|
2915
|
-
pairBuffer += '"';
|
|
2916
|
-
objectKey = objectKeyList[index];
|
|
2917
|
-
objectValue = object[objectKey];
|
|
2918
|
-
if (state.replacer) {
|
|
2919
|
-
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
2920
|
-
}
|
|
2921
|
-
if (!writeNode(state, level, objectKey, false, false)) {
|
|
2922
|
-
continue;
|
|
2923
|
-
}
|
|
2924
|
-
if (state.dump.length > 1024)
|
|
2925
|
-
pairBuffer += "? ";
|
|
2926
|
-
pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
|
|
2927
|
-
if (!writeNode(state, level, objectValue, false, false)) {
|
|
2928
|
-
continue;
|
|
2929
|
-
}
|
|
2930
|
-
pairBuffer += state.dump;
|
|
2931
|
-
_result += pairBuffer;
|
|
2932
|
-
}
|
|
2933
|
-
state.tag = _tag;
|
|
2934
|
-
state.dump = "{" + _result + "}";
|
|
2935
|
-
}
|
|
2936
|
-
function writeBlockMapping(state, level, object, compact) {
|
|
2937
|
-
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
|
|
2938
|
-
if (state.sortKeys === true) {
|
|
2939
|
-
objectKeyList.sort();
|
|
2940
|
-
} else if (typeof state.sortKeys === "function") {
|
|
2941
|
-
objectKeyList.sort(state.sortKeys);
|
|
2942
|
-
} else if (state.sortKeys) {
|
|
2943
|
-
throw new exception("sortKeys must be a boolean or a function");
|
|
2944
|
-
}
|
|
2945
|
-
for (index = 0, length = objectKeyList.length;index < length; index += 1) {
|
|
2946
|
-
pairBuffer = "";
|
|
2947
|
-
if (!compact || _result !== "") {
|
|
2948
|
-
pairBuffer += generateNextLine(state, level);
|
|
2949
|
-
}
|
|
2950
|
-
objectKey = objectKeyList[index];
|
|
2951
|
-
objectValue = object[objectKey];
|
|
2952
|
-
if (state.replacer) {
|
|
2953
|
-
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
2954
|
-
}
|
|
2955
|
-
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
|
2956
|
-
continue;
|
|
2957
|
-
}
|
|
2958
|
-
explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
|
|
2959
|
-
if (explicitPair) {
|
|
2960
|
-
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2961
|
-
pairBuffer += "?";
|
|
2962
|
-
} else {
|
|
2963
|
-
pairBuffer += "? ";
|
|
2964
|
-
}
|
|
2965
|
-
}
|
|
2966
|
-
pairBuffer += state.dump;
|
|
2967
|
-
if (explicitPair) {
|
|
2968
|
-
pairBuffer += generateNextLine(state, level);
|
|
2969
|
-
}
|
|
2970
|
-
if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
|
2971
|
-
continue;
|
|
2972
|
-
}
|
|
2973
|
-
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2974
|
-
pairBuffer += ":";
|
|
2975
|
-
} else {
|
|
2976
|
-
pairBuffer += ": ";
|
|
2977
|
-
}
|
|
2978
|
-
pairBuffer += state.dump;
|
|
2979
|
-
_result += pairBuffer;
|
|
2980
|
-
}
|
|
2981
|
-
state.tag = _tag;
|
|
2982
|
-
state.dump = _result || "{}";
|
|
2983
|
-
}
|
|
2984
|
-
function detectType(state, object, explicit) {
|
|
2985
|
-
var _result, typeList, index, length, type2, style;
|
|
2986
|
-
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
|
2987
|
-
for (index = 0, length = typeList.length;index < length; index += 1) {
|
|
2988
|
-
type2 = typeList[index];
|
|
2989
|
-
if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) {
|
|
2990
|
-
if (explicit) {
|
|
2991
|
-
if (type2.multi && type2.representName) {
|
|
2992
|
-
state.tag = type2.representName(object);
|
|
2993
|
-
} else {
|
|
2994
|
-
state.tag = type2.tag;
|
|
2995
|
-
}
|
|
2996
|
-
} else {
|
|
2997
|
-
state.tag = "?";
|
|
2998
|
-
}
|
|
2999
|
-
if (type2.represent) {
|
|
3000
|
-
style = state.styleMap[type2.tag] || type2.defaultStyle;
|
|
3001
|
-
if (_toString.call(type2.represent) === "[object Function]") {
|
|
3002
|
-
_result = type2.represent(object, style);
|
|
3003
|
-
} else if (_hasOwnProperty.call(type2.represent, style)) {
|
|
3004
|
-
_result = type2.represent[style](object, style);
|
|
3005
|
-
} else {
|
|
3006
|
-
throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
|
|
3007
|
-
}
|
|
3008
|
-
state.dump = _result;
|
|
3009
|
-
}
|
|
3010
|
-
return true;
|
|
3011
|
-
}
|
|
3012
|
-
}
|
|
3013
|
-
return false;
|
|
3014
|
-
}
|
|
3015
|
-
function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
3016
|
-
state.tag = null;
|
|
3017
|
-
state.dump = object;
|
|
3018
|
-
if (!detectType(state, object, false)) {
|
|
3019
|
-
detectType(state, object, true);
|
|
3020
|
-
}
|
|
3021
|
-
var type2 = _toString.call(state.dump);
|
|
3022
|
-
var inblock = block;
|
|
3023
|
-
var tagStr;
|
|
3024
|
-
if (block) {
|
|
3025
|
-
block = state.flowLevel < 0 || state.flowLevel > level;
|
|
3026
|
-
}
|
|
3027
|
-
var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
|
|
3028
|
-
if (objectOrArray) {
|
|
3029
|
-
duplicateIndex = state.duplicates.indexOf(object);
|
|
3030
|
-
duplicate = duplicateIndex !== -1;
|
|
3031
|
-
}
|
|
3032
|
-
if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
|
|
3033
|
-
compact = false;
|
|
3034
|
-
}
|
|
3035
|
-
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
|
3036
|
-
state.dump = "*ref_" + duplicateIndex;
|
|
3037
|
-
} else {
|
|
3038
|
-
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
|
3039
|
-
state.usedDuplicates[duplicateIndex] = true;
|
|
3040
|
-
}
|
|
3041
|
-
if (type2 === "[object Object]") {
|
|
3042
|
-
if (block && Object.keys(state.dump).length !== 0) {
|
|
3043
|
-
writeBlockMapping(state, level, state.dump, compact);
|
|
3044
|
-
if (duplicate) {
|
|
3045
|
-
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
3046
|
-
}
|
|
3047
|
-
} else {
|
|
3048
|
-
writeFlowMapping(state, level, state.dump);
|
|
3049
|
-
if (duplicate) {
|
|
3050
|
-
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
3051
|
-
}
|
|
3052
|
-
}
|
|
3053
|
-
} else if (type2 === "[object Array]") {
|
|
3054
|
-
if (block && state.dump.length !== 0) {
|
|
3055
|
-
if (state.noArrayIndent && !isblockseq && level > 0) {
|
|
3056
|
-
writeBlockSequence(state, level - 1, state.dump, compact);
|
|
3057
|
-
} else {
|
|
3058
|
-
writeBlockSequence(state, level, state.dump, compact);
|
|
3059
|
-
}
|
|
3060
|
-
if (duplicate) {
|
|
3061
|
-
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
3062
|
-
}
|
|
3063
|
-
} else {
|
|
3064
|
-
writeFlowSequence(state, level, state.dump);
|
|
3065
|
-
if (duplicate) {
|
|
3066
|
-
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
3067
|
-
}
|
|
3068
|
-
}
|
|
3069
|
-
} else if (type2 === "[object String]") {
|
|
3070
|
-
if (state.tag !== "?") {
|
|
3071
|
-
writeScalar(state, state.dump, level, iskey, inblock);
|
|
3072
|
-
}
|
|
3073
|
-
} else if (type2 === "[object Undefined]") {
|
|
3074
|
-
return false;
|
|
3075
|
-
} else {
|
|
3076
|
-
if (state.skipInvalid)
|
|
3077
|
-
return false;
|
|
3078
|
-
throw new exception("unacceptable kind of an object to dump " + type2);
|
|
3079
|
-
}
|
|
3080
|
-
if (state.tag !== null && state.tag !== "?") {
|
|
3081
|
-
tagStr = encodeURI(state.tag[0] === "!" ? state.tag.slice(1) : state.tag).replace(/!/g, "%21");
|
|
3082
|
-
if (state.tag[0] === "!") {
|
|
3083
|
-
tagStr = "!" + tagStr;
|
|
3084
|
-
} else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
|
|
3085
|
-
tagStr = "!!" + tagStr.slice(18);
|
|
3086
|
-
} else {
|
|
3087
|
-
tagStr = "!<" + tagStr + ">";
|
|
3088
|
-
}
|
|
3089
|
-
state.dump = tagStr + " " + state.dump;
|
|
3090
|
-
}
|
|
3091
|
-
}
|
|
3092
|
-
return true;
|
|
3093
|
-
}
|
|
3094
|
-
function getDuplicateReferences(object, state) {
|
|
3095
|
-
var objects = [], duplicatesIndexes = [], index, length;
|
|
3096
|
-
inspectNode(object, objects, duplicatesIndexes);
|
|
3097
|
-
for (index = 0, length = duplicatesIndexes.length;index < length; index += 1) {
|
|
3098
|
-
state.duplicates.push(objects[duplicatesIndexes[index]]);
|
|
3099
|
-
}
|
|
3100
|
-
state.usedDuplicates = new Array(length);
|
|
3101
|
-
}
|
|
3102
|
-
function inspectNode(object, objects, duplicatesIndexes) {
|
|
3103
|
-
var objectKeyList, index, length;
|
|
3104
|
-
if (object !== null && typeof object === "object") {
|
|
3105
|
-
index = objects.indexOf(object);
|
|
3106
|
-
if (index !== -1) {
|
|
3107
|
-
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
3108
|
-
duplicatesIndexes.push(index);
|
|
3109
|
-
}
|
|
3110
|
-
} else {
|
|
3111
|
-
objects.push(object);
|
|
3112
|
-
if (Array.isArray(object)) {
|
|
3113
|
-
for (index = 0, length = object.length;index < length; index += 1) {
|
|
3114
|
-
inspectNode(object[index], objects, duplicatesIndexes);
|
|
3115
|
-
}
|
|
3116
|
-
} else {
|
|
3117
|
-
objectKeyList = Object.keys(object);
|
|
3118
|
-
for (index = 0, length = objectKeyList.length;index < length; index += 1) {
|
|
3119
|
-
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
|
3120
|
-
}
|
|
3121
|
-
}
|
|
3122
|
-
}
|
|
3123
|
-
}
|
|
3124
|
-
}
|
|
3125
|
-
function dump$1(input, options) {
|
|
3126
|
-
options = options || {};
|
|
3127
|
-
var state = new State(options);
|
|
3128
|
-
if (!state.noRefs)
|
|
3129
|
-
getDuplicateReferences(input, state);
|
|
3130
|
-
var value = input;
|
|
3131
|
-
if (state.replacer) {
|
|
3132
|
-
value = state.replacer.call({ "": value }, "", value);
|
|
3133
|
-
}
|
|
3134
|
-
if (writeNode(state, 0, value, true, true))
|
|
3135
|
-
return state.dump + `
|
|
3136
|
-
`;
|
|
3137
|
-
return "";
|
|
3138
|
-
}
|
|
3139
|
-
var dump_1 = dump$1;
|
|
3140
|
-
var dumper = {
|
|
3141
|
-
dump: dump_1
|
|
3142
|
-
};
|
|
3143
|
-
function renamed(from, to) {
|
|
3144
|
-
return function() {
|
|
3145
|
-
throw new Error("Function yaml." + from + " is removed in js-yaml 4. " + "Use yaml." + to + " instead, which is now safe by default.");
|
|
3146
|
-
};
|
|
3147
|
-
}
|
|
3148
|
-
var Type = type;
|
|
3149
|
-
var Schema = schema;
|
|
3150
|
-
var FAILSAFE_SCHEMA = failsafe;
|
|
3151
|
-
var JSON_SCHEMA = json;
|
|
3152
|
-
var CORE_SCHEMA = core;
|
|
3153
|
-
var DEFAULT_SCHEMA = _default;
|
|
3154
|
-
var load = loader.load;
|
|
3155
|
-
var loadAll = loader.loadAll;
|
|
3156
|
-
var dump = dumper.dump;
|
|
3157
|
-
var YAMLException = exception;
|
|
3158
|
-
var types = {
|
|
3159
|
-
binary,
|
|
3160
|
-
float,
|
|
3161
|
-
map,
|
|
3162
|
-
null: _null,
|
|
3163
|
-
pairs,
|
|
3164
|
-
set,
|
|
3165
|
-
timestamp,
|
|
3166
|
-
bool,
|
|
3167
|
-
int,
|
|
3168
|
-
merge,
|
|
3169
|
-
omap,
|
|
3170
|
-
seq,
|
|
3171
|
-
str
|
|
3172
|
-
};
|
|
3173
|
-
var safeLoad = renamed("safeLoad", "load");
|
|
3174
|
-
var safeLoadAll = renamed("safeLoadAll", "loadAll");
|
|
3175
|
-
var safeDump = renamed("safeDump", "dump");
|
|
3176
|
-
var jsYaml = {
|
|
3177
|
-
Type,
|
|
3178
|
-
Schema,
|
|
3179
|
-
FAILSAFE_SCHEMA,
|
|
3180
|
-
JSON_SCHEMA,
|
|
3181
|
-
CORE_SCHEMA,
|
|
3182
|
-
DEFAULT_SCHEMA,
|
|
3183
|
-
load,
|
|
3184
|
-
loadAll,
|
|
3185
|
-
dump,
|
|
3186
|
-
YAMLException,
|
|
3187
|
-
types,
|
|
3188
|
-
safeLoad,
|
|
3189
|
-
safeLoadAll,
|
|
3190
|
-
safeDump
|
|
3191
|
-
};
|
|
3192
|
-
|
|
3193
|
-
// src/graph.ts
|
|
3194
|
-
var ENCODE_MAP = { "/": "__SL__", ".": "__DT__" };
|
|
3195
|
-
var ENCODE_RE = /[/.]/g;
|
|
3196
|
-
function pathToGraphFilename(filePath) {
|
|
3197
|
-
return filePath.replace(ENCODE_RE, (ch) => ENCODE_MAP[ch]) + ".md";
|
|
3198
|
-
}
|
|
3199
|
-
function parseGraphContent(content) {
|
|
3200
|
-
const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
3201
|
-
if (fmMatch) {
|
|
3202
|
-
try {
|
|
3203
|
-
const fm = jsYaml.load(fmMatch[1]);
|
|
3204
|
-
if (fm && fm.filePath) {
|
|
3205
|
-
return {
|
|
3206
|
-
filePath: fm.filePath,
|
|
3207
|
-
calls: fm.calls || [],
|
|
3208
|
-
dependsOn: fm.dependsOn || [],
|
|
3209
|
-
tasksThatEdited: fm.tasksThatEdited || []
|
|
3210
|
-
};
|
|
3211
|
-
}
|
|
3212
|
-
} catch {}
|
|
3213
|
-
}
|
|
3214
|
-
return parseLegacyContent(content);
|
|
269
|
+
import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
270
|
+
import { existsSync as existsSync2 } from "fs";
|
|
271
|
+
import { join as join2 } from "path";
|
|
272
|
+
var pluginClient = null;
|
|
273
|
+
function setPluginContext(client) {
|
|
274
|
+
pluginClient = client;
|
|
3215
275
|
}
|
|
3216
|
-
function
|
|
3217
|
-
const
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
calls: [],
|
|
3222
|
-
dependsOn: [],
|
|
3223
|
-
tasksThatEdited: []
|
|
3224
|
-
};
|
|
3225
|
-
let inSection = null;
|
|
3226
|
-
for (const line of lines) {
|
|
3227
|
-
const trimmed = line.trim();
|
|
3228
|
-
if (trimmed.startsWith("# ") && !entry.filePath) {
|
|
3229
|
-
entry.filePath = trimmed.substring(2).trim();
|
|
3230
|
-
continue;
|
|
3231
|
-
}
|
|
3232
|
-
if (trimmed === "## Calls") {
|
|
3233
|
-
inSection = "calls";
|
|
3234
|
-
continue;
|
|
3235
|
-
}
|
|
3236
|
-
if (trimmed === "## Depends On") {
|
|
3237
|
-
inSection = "dependsOn";
|
|
3238
|
-
continue;
|
|
3239
|
-
}
|
|
3240
|
-
if (trimmed === "## Tasks That Edited") {
|
|
3241
|
-
inSection = "tasks";
|
|
3242
|
-
continue;
|
|
3243
|
-
}
|
|
3244
|
-
if (trimmed.startsWith("- [[") && trimmed.endsWith("]]")) {
|
|
3245
|
-
const ref = trimmed.slice(4, -2).trim();
|
|
3246
|
-
if (inSection === "calls")
|
|
3247
|
-
entry.calls.push(ref);
|
|
3248
|
-
else if (inSection === "dependsOn")
|
|
3249
|
-
entry.dependsOn.push(ref);
|
|
3250
|
-
else if (inSection === "tasks")
|
|
3251
|
-
entry.tasksThatEdited.push(ref);
|
|
3252
|
-
} else if (trimmed.startsWith("- `") && trimmed.endsWith("`")) {
|
|
3253
|
-
const ref = trimmed.slice(3, -1).trim();
|
|
3254
|
-
if (inSection === "calls" && !entry.calls.includes(ref))
|
|
3255
|
-
entry.calls.push(ref);
|
|
3256
|
-
else if (inSection === "dependsOn" && !entry.dependsOn.includes(ref))
|
|
3257
|
-
entry.dependsOn.push(ref);
|
|
3258
|
-
} else if (trimmed.startsWith("- ")) {
|
|
3259
|
-
const ref = trimmed.slice(2).trim();
|
|
3260
|
-
if (inSection === "calls" && !entry.calls.includes(ref))
|
|
3261
|
-
entry.calls.push(ref);
|
|
3262
|
-
else if (inSection === "dependsOn" && !entry.dependsOn.includes(ref))
|
|
3263
|
-
entry.dependsOn.push(ref);
|
|
3264
|
-
else if (inSection === "tasks" && !entry.tasksThatEdited.includes(ref))
|
|
3265
|
-
entry.tasksThatEdited.push(ref);
|
|
3266
|
-
}
|
|
276
|
+
async function readSettings(directory) {
|
|
277
|
+
const settingsPath = join2(directory, "Manifold", "settings.json");
|
|
278
|
+
if (existsSync2(settingsPath)) {
|
|
279
|
+
const content = await readFile2(settingsPath, "utf-8");
|
|
280
|
+
return JSON.parse(content);
|
|
3267
281
|
}
|
|
3268
|
-
return
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
282
|
+
return {
|
|
283
|
+
maxLoops: 3,
|
|
284
|
+
maxRetries: 1,
|
|
285
|
+
maxResults: 10,
|
|
286
|
+
recentTaskCount: 3,
|
|
287
|
+
clerkRetryEnabled: true,
|
|
288
|
+
timeout: 300,
|
|
289
|
+
testCommand: null
|
|
3276
290
|
};
|
|
3277
|
-
const fmYaml = jsYaml.dump(fm, { lineWidth: -1, quotingType: "'", forceQuotes: false });
|
|
3278
|
-
const callsSection = entry.calls.length > 0 ? `## Calls
|
|
3279
|
-
` + entry.calls.map((c) => `- ${c}`).join(`
|
|
3280
|
-
`) : `## Calls
|
|
3281
|
-
`;
|
|
3282
|
-
const dependsSection = entry.dependsOn.length > 0 ? `## Depends On
|
|
3283
|
-
` + entry.dependsOn.map((d) => `- ${d}`).join(`
|
|
3284
|
-
`) : `## Depends On
|
|
3285
|
-
`;
|
|
3286
|
-
const tasksSection = entry.tasksThatEdited.length > 0 ? `## Tasks That Edited
|
|
3287
|
-
` + entry.tasksThatEdited.map((t) => `- [[${t}]]`).join(`
|
|
3288
|
-
`) : `## Tasks That Edited
|
|
3289
|
-
`;
|
|
3290
|
-
return `---
|
|
3291
|
-
${fmYaml.trim()}
|
|
3292
|
-
---
|
|
3293
|
-
|
|
3294
|
-
${callsSection}
|
|
3295
|
-
|
|
3296
|
-
${dependsSection}
|
|
3297
|
-
|
|
3298
|
-
${tasksSection}
|
|
3299
|
-
`.trim();
|
|
3300
291
|
}
|
|
3301
|
-
async function
|
|
3302
|
-
const
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
try {
|
|
3308
|
-
const content = await readFile2(graphPath, "utf-8");
|
|
3309
|
-
return parseGraphContent(content);
|
|
3310
|
-
} catch {
|
|
3311
|
-
return null;
|
|
292
|
+
async function readDispatcherState(directory, taskNumber) {
|
|
293
|
+
const statePath = join2(directory, "Manifold", "dispatcher-state.json");
|
|
294
|
+
if (existsSync2(statePath)) {
|
|
295
|
+
const content = await readFile2(statePath, "utf-8");
|
|
296
|
+
const states = JSON.parse(content);
|
|
297
|
+
return states[taskNumber] || null;
|
|
3312
298
|
}
|
|
299
|
+
return null;
|
|
3313
300
|
}
|
|
3314
|
-
async function
|
|
3315
|
-
const
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
entry = existing || {
|
|
3321
|
-
filePath,
|
|
3322
|
-
calls: [],
|
|
3323
|
-
dependsOn: [],
|
|
3324
|
-
tasksThatEdited: []
|
|
3325
|
-
};
|
|
3326
|
-
} else {
|
|
3327
|
-
entry = {
|
|
3328
|
-
filePath,
|
|
3329
|
-
calls: calls || [],
|
|
3330
|
-
dependsOn: dependsOn || [],
|
|
3331
|
-
tasksThatEdited: []
|
|
3332
|
-
};
|
|
3333
|
-
}
|
|
3334
|
-
if (calls) {
|
|
3335
|
-
entry.calls = [...new Set([...entry.calls, ...calls])];
|
|
3336
|
-
}
|
|
3337
|
-
if (dependsOn) {
|
|
3338
|
-
entry.dependsOn = [...new Set([...entry.dependsOn, ...dependsOn])];
|
|
301
|
+
async function writeDispatcherState(directory, state) {
|
|
302
|
+
const statePath = join2(directory, "Manifold", "dispatcher-state.json");
|
|
303
|
+
let states = {};
|
|
304
|
+
if (existsSync2(statePath)) {
|
|
305
|
+
const content = await readFile2(statePath, "utf-8");
|
|
306
|
+
states = JSON.parse(content);
|
|
3339
307
|
}
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
}
|
|
3343
|
-
const graphDir = dirname2(graphPath);
|
|
3344
|
-
if (!existsSync2(graphDir)) {
|
|
3345
|
-
await mkdir2(graphDir, { recursive: true });
|
|
3346
|
-
}
|
|
3347
|
-
const content = formatGraphContent(entry);
|
|
3348
|
-
await writeFile2(graphPath, content, "utf-8");
|
|
308
|
+
states[state.task_number] = state;
|
|
309
|
+
await writeFile2(statePath, JSON.stringify(states, null, 2));
|
|
3349
310
|
}
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
311
|
+
function extractTaskFromPlan(planContent, taskNumber) {
|
|
312
|
+
const taskPattern = /###?\s*Task\s+(\d+):\s*(.+)/gi;
|
|
313
|
+
let match;
|
|
314
|
+
while ((match = taskPattern.exec(planContent)) !== null) {
|
|
315
|
+
if (parseInt(match[1]) === taskNumber) {
|
|
316
|
+
const description = match[2].trim();
|
|
317
|
+
const slug = description.toLowerCase().replace(/[^a-z0-9]+/g, "-").substring(0, 30);
|
|
318
|
+
return { description, slug };
|
|
3356
319
|
}
|
|
3357
320
|
}
|
|
321
|
+
return null;
|
|
3358
322
|
}
|
|
3359
|
-
|
|
3360
|
-
const
|
|
3361
|
-
const
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
323
|
+
function runDispatcherLogic(args, state, settings) {
|
|
324
|
+
const isNewTask = args.newTask === true;
|
|
325
|
+
const taskNumber = args.task_number || (state?.task_number || 0);
|
|
326
|
+
const planFile = args.plan_file || (state?.plan_file || "");
|
|
327
|
+
const slug = state?.slug || "";
|
|
328
|
+
let currentState;
|
|
329
|
+
if (isNewTask || !state) {
|
|
330
|
+
currentState = {
|
|
331
|
+
task_number: taskNumber,
|
|
332
|
+
plan_file: planFile,
|
|
333
|
+
slug,
|
|
334
|
+
loops: 0,
|
|
335
|
+
clerkRetries: 0,
|
|
336
|
+
researchSummary: "",
|
|
337
|
+
implementationOutput: "",
|
|
338
|
+
reviewFeedback: "",
|
|
339
|
+
debugAnalysis: ""
|
|
3370
340
|
};
|
|
3371
341
|
} else {
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
342
|
+
currentState = { ...state };
|
|
343
|
+
}
|
|
344
|
+
if (args.researchSummary)
|
|
345
|
+
currentState.researchSummary = args.researchSummary;
|
|
346
|
+
if (args.implementationOutput)
|
|
347
|
+
currentState.implementationOutput = args.implementationOutput;
|
|
348
|
+
if (args.reviewFeedback)
|
|
349
|
+
currentState.reviewFeedback = args.reviewFeedback;
|
|
350
|
+
if (args.debugAnalysis)
|
|
351
|
+
currentState.debugAnalysis = args.debugAnalysis;
|
|
352
|
+
if (isNewTask) {
|
|
353
|
+
return {
|
|
354
|
+
route: "research",
|
|
355
|
+
agent: "clerk",
|
|
356
|
+
prompt: buildResearchPrompt(args, currentState, settings),
|
|
357
|
+
state: {
|
|
358
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
359
|
+
loops: 0,
|
|
360
|
+
maxLoops: settings.maxLoops,
|
|
361
|
+
clerkRetries: 0
|
|
362
|
+
},
|
|
363
|
+
message: "Researching codebase and wiki context"
|
|
3377
364
|
};
|
|
3378
365
|
}
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
import { join as join3 } from "path";
|
|
3393
|
-
function openIndexDb(projectRoot) {
|
|
3394
|
-
const dbPath = join3(projectRoot, ".opencode", "index", "codebase.db");
|
|
3395
|
-
if (!existsSync3(dbPath)) {
|
|
3396
|
-
return null;
|
|
3397
|
-
}
|
|
3398
|
-
try {
|
|
3399
|
-
const db = new Database(dbPath, { readonly: true });
|
|
3400
|
-
db.pragma("journal_mode = WAL");
|
|
3401
|
-
return db;
|
|
3402
|
-
} catch {
|
|
3403
|
-
return null;
|
|
3404
|
-
}
|
|
3405
|
-
}
|
|
3406
|
-
function getFileCallEdges(db, filePath, branch) {
|
|
3407
|
-
const calls = new Set;
|
|
3408
|
-
const dependsOn = new Set;
|
|
3409
|
-
const outEdges = db.prepare(`
|
|
3410
|
-
SELECT s_to.file_path AS target_file
|
|
3411
|
-
FROM call_edges ce
|
|
3412
|
-
INNER JOIN symbols s_from ON ce.from_symbol_id = s_from.id
|
|
3413
|
-
INNER JOIN branch_symbols bs ON s_from.id = bs.symbol_id AND bs.branch = ?
|
|
3414
|
-
LEFT JOIN symbols s_to ON ce.to_symbol_id = s_to.id
|
|
3415
|
-
WHERE s_from.file_path = ?
|
|
3416
|
-
AND ce.is_resolved = 1
|
|
3417
|
-
AND s_to.file_path IS NOT NULL
|
|
3418
|
-
AND s_to.file_path != ?
|
|
3419
|
-
`).all(branch, filePath, filePath);
|
|
3420
|
-
for (const row of outEdges) {
|
|
3421
|
-
if (row.target_file) {
|
|
3422
|
-
calls.add(row.target_file);
|
|
3423
|
-
dependsOn.add(row.target_file);
|
|
3424
|
-
}
|
|
3425
|
-
}
|
|
3426
|
-
const unresolvedEdges = db.prepare(`
|
|
3427
|
-
SELECT DISTINCT ce.target_name
|
|
3428
|
-
FROM call_edges ce
|
|
3429
|
-
INNER JOIN symbols s_from ON ce.from_symbol_id = s_from.id
|
|
3430
|
-
INNER JOIN branch_symbols bs ON s_from.id = bs.symbol_id AND bs.branch = ?
|
|
3431
|
-
WHERE s_from.file_path = ?
|
|
3432
|
-
AND ce.is_resolved = 0
|
|
3433
|
-
`).all(branch, filePath);
|
|
3434
|
-
const symbolByName = db.prepare(`
|
|
3435
|
-
SELECT DISTINCT s.file_path
|
|
3436
|
-
FROM symbols s
|
|
3437
|
-
INNER JOIN branch_symbols bs ON s.id = bs.symbol_id AND bs.branch = ?
|
|
3438
|
-
WHERE s.name = ?
|
|
3439
|
-
AND s.file_path != ?
|
|
3440
|
-
`);
|
|
3441
|
-
for (const row of unresolvedEdges) {
|
|
3442
|
-
const candidates = symbolByName.all(branch, row.target_name, filePath);
|
|
3443
|
-
if (candidates.length === 1) {
|
|
3444
|
-
calls.add(candidates[0].file_path);
|
|
3445
|
-
dependsOn.add(candidates[0].file_path);
|
|
3446
|
-
}
|
|
3447
|
-
}
|
|
3448
|
-
return {
|
|
3449
|
-
calls: [...calls].sort(),
|
|
3450
|
-
dependsOn: [...dependsOn].sort()
|
|
3451
|
-
};
|
|
3452
|
-
}
|
|
3453
|
-
function getCurrentBranch(db) {
|
|
3454
|
-
const row = db.prepare("SELECT value FROM metadata WHERE key = 'current_branch'").get();
|
|
3455
|
-
return row?.value || "main";
|
|
3456
|
-
}
|
|
3457
|
-
async function syncGraphFilesFromIndex(projectRoot, files) {
|
|
3458
|
-
const db = openIndexDb(projectRoot);
|
|
3459
|
-
if (!db) {
|
|
3460
|
-
return { synced: 0, skipped: files.length };
|
|
3461
|
-
}
|
|
3462
|
-
try {
|
|
3463
|
-
const branch = getCurrentBranch(db);
|
|
3464
|
-
let synced = 0;
|
|
3465
|
-
let skipped = 0;
|
|
3466
|
-
for (const filePath of files) {
|
|
3467
|
-
try {
|
|
3468
|
-
const edges = getFileCallEdges(db, filePath, branch);
|
|
3469
|
-
await replaceGraphCalls(projectRoot, filePath, edges.calls, edges.dependsOn);
|
|
3470
|
-
synced++;
|
|
3471
|
-
} catch {
|
|
3472
|
-
skipped++;
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
return { synced, skipped };
|
|
3476
|
-
} finally {
|
|
3477
|
-
db.close();
|
|
3478
|
-
}
|
|
3479
|
-
}
|
|
3480
|
-
|
|
3481
|
-
// src/state-machine.ts
|
|
3482
|
-
async function readState(directory) {
|
|
3483
|
-
const statePath = join4(directory, "Manifold", "state.json");
|
|
3484
|
-
if (existsSync4(statePath)) {
|
|
3485
|
-
const content = await readFile3(statePath, "utf-8");
|
|
3486
|
-
return JSON.parse(content);
|
|
3487
|
-
}
|
|
3488
|
-
return {
|
|
3489
|
-
current_task: null,
|
|
3490
|
-
state: "idle",
|
|
3491
|
-
loop_count: 0,
|
|
3492
|
-
clerk_retry_count: 0,
|
|
3493
|
-
scoped_prompt: null,
|
|
3494
|
-
senior_output: null,
|
|
3495
|
-
junior_response: null,
|
|
3496
|
-
debug_suggestion: null,
|
|
3497
|
-
loop_history: []
|
|
3498
|
-
};
|
|
3499
|
-
}
|
|
3500
|
-
async function writeState(directory, state) {
|
|
3501
|
-
const statePath = join4(directory, "Manifold", "state.json");
|
|
3502
|
-
await writeFile3(statePath, JSON.stringify(state, null, 2));
|
|
3503
|
-
}
|
|
3504
|
-
function buildLoopHistory(state) {
|
|
3505
|
-
if (state.loop_history.length === 0) {
|
|
3506
|
-
return "No previous loops.";
|
|
3507
|
-
}
|
|
3508
|
-
return state.loop_history.map((entry, i2) => `### Loop ${i2 + 1}
|
|
3509
|
-
${entry}`).join(`
|
|
3510
|
-
|
|
3511
|
-
`);
|
|
3512
|
-
}
|
|
3513
|
-
async function readRecentTaskLogs(directory, count) {
|
|
3514
|
-
const tasksDir = join4(directory, "Manifold", "tasks");
|
|
3515
|
-
if (!existsSync4(tasksDir)) {
|
|
3516
|
-
return [];
|
|
3517
|
-
}
|
|
3518
|
-
try {
|
|
3519
|
-
const files = await readdir2(tasksDir);
|
|
3520
|
-
const mdFiles = files.filter((f) => f.endsWith(".md")).sort();
|
|
3521
|
-
const recentFiles = mdFiles.slice(-count);
|
|
3522
|
-
const tasks = await Promise.all(recentFiles.map(async (filename) => {
|
|
3523
|
-
const content = await readFile3(join4(tasksDir, filename), "utf-8");
|
|
3524
|
-
return { filename, content };
|
|
3525
|
-
}));
|
|
3526
|
-
return tasks;
|
|
3527
|
-
} catch {
|
|
3528
|
-
return [];
|
|
366
|
+
if (args.researchComplete === true && !args.hasImplementation) {
|
|
367
|
+
return {
|
|
368
|
+
route: "implement",
|
|
369
|
+
agent: "senior-dev",
|
|
370
|
+
prompt: buildScopedPrompt(currentState.researchSummary, args),
|
|
371
|
+
state: {
|
|
372
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
373
|
+
loops: 0,
|
|
374
|
+
maxLoops: settings.maxLoops,
|
|
375
|
+
clerkRetries: 0
|
|
376
|
+
},
|
|
377
|
+
message: "Sending to senior-dev for implementation"
|
|
378
|
+
};
|
|
3529
379
|
}
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
const clerkLoggingPrompt = `You are the Clerk. Log the completed task to the project wiki.
|
|
3544
|
-
|
|
3545
|
-
Task ID: ${taskId}
|
|
3546
|
-
Task Description: ${task.description}
|
|
3547
|
-
Date: ${date}
|
|
3548
|
-
Status: COMPLETED
|
|
3549
|
-
Loops: ${state.loop_count}
|
|
3550
|
-
|
|
3551
|
-
Scoped Prompt Used:
|
|
3552
|
-
${state.scoped_prompt}
|
|
3553
|
-
|
|
3554
|
-
Senior Developer's Final Implementation:
|
|
3555
|
-
${state.senior_output}
|
|
3556
|
-
|
|
3557
|
-
Junior Developer's Approval Response:
|
|
3558
|
-
${state.junior_response}
|
|
3559
|
-
|
|
3560
|
-
Loop History:
|
|
3561
|
-
${buildLoopHistory(state)}
|
|
3562
|
-
|
|
3563
|
-
Please perform the following logging actions:
|
|
3564
|
-
|
|
3565
|
-
1. Create/Update Task File at \`Manifold/tasks/${taskId}.md\`:
|
|
3566
|
-
- Header with date, status, loops, task description
|
|
3567
|
-
- Scoped Prompt section
|
|
3568
|
-
- Design Decisions section (extract from Senior's implementation reasoning)
|
|
3569
|
-
- Files Touched section (extract file paths from Senior's implementation)
|
|
3570
|
-
- Complete Loop History section
|
|
3571
|
-
|
|
3572
|
-
2. Update \`Manifold/index.md\`:
|
|
3573
|
-
- Add entry under the plan's section:
|
|
3574
|
-
\`- [[${taskId}]] — ${task.description} | ${date} | COMPLETED\`
|
|
3575
|
-
|
|
3576
|
-
3. Append to \`Manifold/log.md\`:
|
|
3577
|
-
\`## [${date}] ${taskId} | ${task.description} | COMPLETED | ${state.loop_count} loops\`
|
|
3578
|
-
|
|
3579
|
-
4. Update graph files for each touched file:
|
|
3580
|
-
- Read the implementation and identify all files that were created or modified
|
|
3581
|
-
- For each file, create or update \`Manifold/graph/<graph-name>.md\`
|
|
3582
|
-
- Add the task ID to the "Tasks That Edited" section
|
|
3583
|
-
- Do NOT populate "Calls" or "Depends On" sections — those are synced automatically from the codebase index
|
|
3584
|
-
- Graph filename format: replace \`/\` with \`__SL__\` and \`.\` with \`__DT__\`, append \`.md\`
|
|
3585
|
-
- Example: \`src/middleware/auth.ts\` → \`src__SL__middleware__SL__auth__DT__ts.md\`
|
|
3586
|
-
|
|
3587
|
-
Extract the list of files touched from the Senior's implementation and include it in your response.`;
|
|
3588
|
-
const clerkLoggingResult = await retryWithBackoff(() => spawnClerkSession(client, clerkLoggingPrompt, "clerk", settings.timeout), {
|
|
3589
|
-
maxRetries: settings.maxRetries,
|
|
3590
|
-
onRetry: (attempt, error) => {
|
|
3591
|
-
client.app.log({
|
|
3592
|
-
body: {
|
|
3593
|
-
service: "opencode-manifold",
|
|
3594
|
-
level: "warn",
|
|
3595
|
-
message: `Clerk logging retry ${attempt}: ${error.message}`
|
|
3596
|
-
}
|
|
3597
|
-
});
|
|
3598
|
-
}
|
|
3599
|
-
});
|
|
3600
|
-
if (!clerkLoggingResult.success) {
|
|
3601
|
-
await client.app.log({
|
|
3602
|
-
body: {
|
|
3603
|
-
service: "opencode-manifold",
|
|
3604
|
-
level: "error",
|
|
3605
|
-
message: `Clerk logging failed: ${clerkLoggingResult.error}. Task completed but wiki not updated.`
|
|
3606
|
-
}
|
|
3607
|
-
});
|
|
3608
|
-
return { files_changed: [] };
|
|
380
|
+
if (args.hasImplementation === true && args.reviewDone === false) {
|
|
381
|
+
return {
|
|
382
|
+
route: "review",
|
|
383
|
+
agent: "junior-dev",
|
|
384
|
+
prompt: buildReviewPrompt(currentState.implementationOutput, args),
|
|
385
|
+
state: {
|
|
386
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
387
|
+
loops: 0,
|
|
388
|
+
maxLoops: settings.maxLoops,
|
|
389
|
+
clerkRetries: 0
|
|
390
|
+
},
|
|
391
|
+
message: "Sending to junior-dev for review"
|
|
392
|
+
};
|
|
3609
393
|
}
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
service: "opencode-manifold",
|
|
3624
|
-
level: "info",
|
|
3625
|
-
message: `Graph files updated successfully`
|
|
3626
|
-
}
|
|
3627
|
-
});
|
|
3628
|
-
const syncResult = await syncGraphFilesFromIndex(directory, filesChanged);
|
|
3629
|
-
await client.app.log({
|
|
3630
|
-
body: {
|
|
3631
|
-
service: "opencode-manifold",
|
|
3632
|
-
level: "info",
|
|
3633
|
-
message: `Graph sync from codebase-index: ${syncResult.synced} synced, ${syncResult.skipped} skipped`
|
|
3634
|
-
}
|
|
3635
|
-
});
|
|
3636
|
-
} catch (error) {
|
|
3637
|
-
await client.app.log({
|
|
3638
|
-
body: {
|
|
3639
|
-
service: "opencode-manifold",
|
|
3640
|
-
level: "warn",
|
|
3641
|
-
message: `Graph file update failed: ${error instanceof Error ? error.message : String(error)}`
|
|
3642
|
-
}
|
|
3643
|
-
});
|
|
3644
|
-
}
|
|
394
|
+
if (args.reviewDone === true && args.reviewPassed === true) {
|
|
395
|
+
return {
|
|
396
|
+
route: "logging",
|
|
397
|
+
agent: "clerk",
|
|
398
|
+
prompt: buildLoggingPrompt(currentState, args),
|
|
399
|
+
state: {
|
|
400
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
401
|
+
loops: currentState.loops,
|
|
402
|
+
maxLoops: settings.maxLoops,
|
|
403
|
+
clerkRetries: currentState.clerkRetries
|
|
404
|
+
},
|
|
405
|
+
message: "Logging task to wiki and graph"
|
|
406
|
+
};
|
|
3645
407
|
}
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
for (const pattern of patterns) {
|
|
3663
|
-
const matches = content.matchAll(pattern);
|
|
3664
|
-
for (const match of matches) {
|
|
3665
|
-
const file = match[1] || match[0];
|
|
3666
|
-
if (file && !files.includes(file)) {
|
|
3667
|
-
files.push(file);
|
|
408
|
+
if (args.reviewDone === true && args.reviewPassed === false) {
|
|
409
|
+
currentState.loops++;
|
|
410
|
+
if (currentState.loops >= settings.maxLoops) {
|
|
411
|
+
if (!args.debugComplete && currentState.clerkRetries === 0) {
|
|
412
|
+
return {
|
|
413
|
+
route: "debug",
|
|
414
|
+
agent: "debug",
|
|
415
|
+
prompt: buildDebugPrompt(currentState, args),
|
|
416
|
+
state: {
|
|
417
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
418
|
+
loops: currentState.loops,
|
|
419
|
+
maxLoops: settings.maxLoops,
|
|
420
|
+
clerkRetries: 0
|
|
421
|
+
},
|
|
422
|
+
message: `Loop ${currentState.loops}/${settings.maxLoops} - escalating to debug`
|
|
423
|
+
};
|
|
3668
424
|
}
|
|
425
|
+
if (args.debugComplete === true && settings.clerkRetryEnabled && currentState.clerkRetries === 0) {
|
|
426
|
+
currentState.clerkRetries = 1;
|
|
427
|
+
currentState.loops = 0;
|
|
428
|
+
return {
|
|
429
|
+
route: "re-research",
|
|
430
|
+
agent: "clerk",
|
|
431
|
+
prompt: buildReResearchPrompt(currentState, args),
|
|
432
|
+
state: {
|
|
433
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
434
|
+
loops: 0,
|
|
435
|
+
maxLoops: settings.maxLoops,
|
|
436
|
+
clerkRetries: 1
|
|
437
|
+
},
|
|
438
|
+
message: "Clerk re-researching with failure context"
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
return {
|
|
442
|
+
route: "escalate_user",
|
|
443
|
+
agent: null,
|
|
444
|
+
prompt: `Task ${taskNumber} has exhausted all loops (${settings.maxLoops}) and debug analysis. Last feedback: ${currentState.reviewFeedback}`,
|
|
445
|
+
state: {
|
|
446
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
447
|
+
loops: currentState.loops,
|
|
448
|
+
maxLoops: settings.maxLoops,
|
|
449
|
+
clerkRetries: currentState.clerkRetries
|
|
450
|
+
},
|
|
451
|
+
message: "ESCALATING TO USER - all loops exhausted"
|
|
452
|
+
};
|
|
3669
453
|
}
|
|
454
|
+
return {
|
|
455
|
+
route: "re-implement",
|
|
456
|
+
agent: "senior-dev",
|
|
457
|
+
prompt: buildReImplementPrompt(currentState, args),
|
|
458
|
+
state: {
|
|
459
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
460
|
+
loops: currentState.loops,
|
|
461
|
+
maxLoops: settings.maxLoops,
|
|
462
|
+
clerkRetries: currentState.clerkRetries
|
|
463
|
+
},
|
|
464
|
+
message: `Loop ${currentState.loops}/${settings.maxLoops} - re-implementing with junior feedback`
|
|
465
|
+
};
|
|
3670
466
|
}
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
let inPrompt = false;
|
|
3685
|
-
for (const line of lines) {
|
|
3686
|
-
if (line.includes("SCOPED_PROMPT_END")) {
|
|
3687
|
-
inPrompt = false;
|
|
3688
|
-
}
|
|
3689
|
-
if (inPrompt) {
|
|
3690
|
-
promptLines.push(line);
|
|
3691
|
-
}
|
|
3692
|
-
if (line.includes("SCOPED_PROMPT_START")) {
|
|
3693
|
-
inPrompt = true;
|
|
3694
|
-
}
|
|
3695
|
-
}
|
|
3696
|
-
if (promptLines.length > 0) {
|
|
3697
|
-
return promptLines.join(`
|
|
3698
|
-
`).trim();
|
|
467
|
+
if (args.debugComplete === true && args.reResearched === false) {
|
|
468
|
+
return {
|
|
469
|
+
route: "re-implement",
|
|
470
|
+
agent: "senior-dev",
|
|
471
|
+
prompt: buildDebugImplementPrompt(currentState, args),
|
|
472
|
+
state: {
|
|
473
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
474
|
+
loops: currentState.loops,
|
|
475
|
+
maxLoops: settings.maxLoops,
|
|
476
|
+
clerkRetries: currentState.clerkRetries
|
|
477
|
+
},
|
|
478
|
+
message: "Re-implementing with debug suggestion"
|
|
479
|
+
};
|
|
3699
480
|
}
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
await writeState(directory, state);
|
|
3715
|
-
await client.app.log({
|
|
3716
|
-
body: {
|
|
3717
|
-
service: "opencode-manifold",
|
|
3718
|
-
level: "info",
|
|
3719
|
-
message: `Starting state machine for task ${task.task_number}: ${task.description}`
|
|
3720
|
-
}
|
|
3721
|
-
});
|
|
3722
|
-
state.state = "clerk_researched";
|
|
3723
|
-
await writeState(directory, state);
|
|
3724
|
-
await client.app.log({
|
|
3725
|
-
body: {
|
|
3726
|
-
service: "opencode-manifold",
|
|
3727
|
-
level: "info",
|
|
3728
|
-
message: "State: clerk_researched - Pre-reading wiki context for Clerk"
|
|
3729
|
-
}
|
|
3730
|
-
});
|
|
3731
|
-
const recentTasks = await readRecentTaskLogs(directory, settings.recentTaskCount);
|
|
3732
|
-
let recentTasksContext = "";
|
|
3733
|
-
if (recentTasks.length > 0) {
|
|
3734
|
-
recentTasksContext = `
|
|
3735
|
-
|
|
3736
|
-
Recent Task Logs from Manifold:
|
|
3737
|
-
` + recentTasks.map((t) => `--- ${t.filename} ---
|
|
3738
|
-
${t.content}`).join(`
|
|
3739
|
-
|
|
3740
|
-
`);
|
|
3741
|
-
} else {
|
|
3742
|
-
recentTasksContext = `
|
|
3743
|
-
|
|
3744
|
-
(No prior task logs found - this appears to be a new project.)`;
|
|
481
|
+
if (args.reResearched === true) {
|
|
482
|
+
currentState.loops = 0;
|
|
483
|
+
return {
|
|
484
|
+
route: "implement",
|
|
485
|
+
agent: "senior-dev",
|
|
486
|
+
prompt: buildScopedPrompt(currentState.researchSummary, args),
|
|
487
|
+
state: {
|
|
488
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
489
|
+
loops: 0,
|
|
490
|
+
maxLoops: settings.maxLoops,
|
|
491
|
+
clerkRetries: currentState.clerkRetries
|
|
492
|
+
},
|
|
493
|
+
message: "Starting fresh loop with new research"
|
|
494
|
+
};
|
|
3745
495
|
}
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
496
|
+
return {
|
|
497
|
+
route: "escalate_user",
|
|
498
|
+
agent: null,
|
|
499
|
+
prompt: "Dispatcher encountered an unexpected state combination",
|
|
500
|
+
state: {
|
|
501
|
+
task_id: `${currentState.slug}-${currentState.task_number.toString().padStart(3, "0")}`,
|
|
502
|
+
loops: currentState.loops,
|
|
503
|
+
maxLoops: settings.maxLoops,
|
|
504
|
+
clerkRetries: currentState.clerkRetries
|
|
505
|
+
},
|
|
506
|
+
message: "ESCALATING TO USER - unexpected state"
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
function buildResearchPrompt(args, state, settings) {
|
|
510
|
+
const needsTodo = args.needsDecomposition === true;
|
|
511
|
+
return `You are the Clerk. Research this task and compose a scoped prompt.
|
|
3757
512
|
|
|
3758
|
-
|
|
3759
|
-
- The codebase-index tool for semantic code search (use it to find relevant code)
|
|
3760
|
-
- File reading tools to read additional context if needed
|
|
513
|
+
Task ${state.task_number}: ${args.description}
|
|
3761
514
|
|
|
3762
515
|
Research steps:
|
|
3763
516
|
1. Use codebase-index to search for relevant code (max ${settings.maxResults} results)
|
|
3764
|
-
2. Read graph files from Manifold/graph/ for relevant files
|
|
3765
|
-
3.
|
|
517
|
+
2. Read graph files from Manifold/graph/ for relevant files
|
|
518
|
+
3. Read recent task logs from Manifold/tasks/ (${settings.recentTaskCount} most recent)
|
|
519
|
+
${needsTodo ? `4. Read the full plan file (${args.plan_file}) for project-wide context` : ""}
|
|
520
|
+
|
|
521
|
+
${needsTodo ? `IMPORTANT: This task requires project-wide decomposition. After researching, you will need to:
|
|
522
|
+
- Identify all files that need to be created or modified
|
|
523
|
+
- Break the work into logical subtasks
|
|
524
|
+
- Prepare context for each subtask` : ""}
|
|
3766
525
|
|
|
3767
526
|
Output Format - STRICTLY FOLLOW THIS:
|
|
3768
527
|
|
|
3769
528
|
===SCOPED_PROMPT_START===
|
|
3770
|
-
[Your composed scoped prompt
|
|
529
|
+
[Your composed scoped prompt - include task goal, relevant code snippets, prior decisions, design guidelines]
|
|
3771
530
|
===SCOPED_PROMPT_END===
|
|
3772
531
|
|
|
3773
532
|
===CONTEXT_USED_START===
|
|
3774
533
|
[List of context documents you used - file paths and brief descriptions]
|
|
3775
534
|
===CONTEXT_USED_END===`;
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
state.state = "escalate_user";
|
|
3790
|
-
await writeState(directory, state);
|
|
3791
|
-
return {
|
|
3792
|
-
status: "escalated_user",
|
|
3793
|
-
summary: `Task ${task.task_number}: Clerk failed - ${clerkResult.error}`,
|
|
3794
|
-
files_changed: [],
|
|
3795
|
-
loops: state.loop_count,
|
|
3796
|
-
wiki_entry: `Manifold/tasks/${task.slug}-${task.task_number.toString().padStart(3, "0")}.md`
|
|
3797
|
-
};
|
|
3798
|
-
}
|
|
3799
|
-
state.scoped_prompt = extractScopedPrompt(clerkResult.content);
|
|
3800
|
-
await writeState(directory, state);
|
|
3801
|
-
let finalResult;
|
|
3802
|
-
const runSeniorJuniorLoop = async () => {
|
|
3803
|
-
state.state = "senior_done";
|
|
3804
|
-
await writeState(directory, state);
|
|
3805
|
-
await client.app.log({
|
|
3806
|
-
body: {
|
|
3807
|
-
service: "opencode-manifold",
|
|
3808
|
-
level: "info",
|
|
3809
|
-
message: "State: senior_done - Spawning Senior Dev"
|
|
3810
|
-
}
|
|
3811
|
-
});
|
|
3812
|
-
const seniorPrompt = state.scoped_prompt;
|
|
3813
|
-
const seniorResult = await retryWithBackoff(() => spawnSeniorDevSession(client, seniorPrompt, "senior-dev", settings.timeout), {
|
|
3814
|
-
maxRetries: settings.maxRetries,
|
|
3815
|
-
onRetry: (attempt, error) => {
|
|
3816
|
-
client.app.log({
|
|
3817
|
-
body: {
|
|
3818
|
-
service: "opencode-manifold",
|
|
3819
|
-
level: "warn",
|
|
3820
|
-
message: `Senior Dev retry ${attempt}: ${error.message}`
|
|
3821
|
-
}
|
|
3822
|
-
});
|
|
3823
|
-
}
|
|
3824
|
-
});
|
|
3825
|
-
if (!seniorResult.success) {
|
|
3826
|
-
throw new ModelCallError(`Senior Dev failed: ${seniorResult.error}`, "senior-dev", 1);
|
|
3827
|
-
}
|
|
3828
|
-
state.senior_output = seniorResult.content;
|
|
3829
|
-
await writeState(directory, state);
|
|
3830
|
-
state.state = "junior_review";
|
|
3831
|
-
await writeState(directory, state);
|
|
3832
|
-
await client.app.log({
|
|
3833
|
-
body: {
|
|
3834
|
-
service: "opencode-manifold",
|
|
3835
|
-
level: "info",
|
|
3836
|
-
message: "State: junior_review - Spawning Junior Dev"
|
|
3837
|
-
}
|
|
3838
|
-
});
|
|
3839
|
-
const juniorPrompt = `You are the Junior Developer reviewing the Senior Developer's implementation.
|
|
535
|
+
}
|
|
536
|
+
function buildScopedPrompt(researchSummary, args) {
|
|
537
|
+
return `You are the Senior Developer. Implement this task.
|
|
538
|
+
|
|
539
|
+
Task: ${args.description}
|
|
540
|
+
|
|
541
|
+
Research Context:
|
|
542
|
+
${researchSummary}
|
|
543
|
+
|
|
544
|
+
Implement the task following the requirements and patterns from the research context.`;
|
|
545
|
+
}
|
|
546
|
+
function buildReviewPrompt(implementation, args) {
|
|
547
|
+
return `You are the Junior Developer reviewing the Senior Developer's implementation.
|
|
3840
548
|
|
|
3841
|
-
Task
|
|
3842
|
-
${state.scoped_prompt}
|
|
549
|
+
Task: ${args.description}
|
|
3843
550
|
|
|
3844
551
|
Senior Developer's Implementation:
|
|
3845
|
-
${
|
|
552
|
+
${implementation}
|
|
3846
553
|
|
|
3847
554
|
Review the implementation against the task requirements. Your response MUST begin with exactly "COMPLETE" or "QUESTIONS" as the first word.
|
|
3848
555
|
|
|
3849
556
|
If COMPLETE: Briefly explain why the implementation is acceptable.
|
|
3850
557
|
If QUESTIONS: List specific issues blocking approval with actionable feedback.`;
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
client.app.log({
|
|
3855
|
-
body: {
|
|
3856
|
-
service: "opencode-manifold",
|
|
3857
|
-
level: "warn",
|
|
3858
|
-
message: `Junior Dev retry ${attempt}: ${error.message}`
|
|
3859
|
-
}
|
|
3860
|
-
});
|
|
3861
|
-
}
|
|
3862
|
-
});
|
|
3863
|
-
if (!juniorResult.success) {
|
|
3864
|
-
throw new ModelCallError(`Junior Dev failed: ${juniorResult.error}`, "junior-dev", 1);
|
|
3865
|
-
}
|
|
3866
|
-
state.junior_response = juniorResult.content;
|
|
3867
|
-
state.loop_history.push(`**Senior:** ${seniorResult.content.substring(0, 200)}...
|
|
3868
|
-
**Junior:** ${juniorResult.content}`);
|
|
3869
|
-
await writeState(directory, state);
|
|
3870
|
-
const firstWord = parseJuniorFirstWord(juniorResult.content);
|
|
3871
|
-
if (firstWord === "COMPLETE") {
|
|
3872
|
-
state.state = "junior_approved";
|
|
3873
|
-
await writeState(directory, state);
|
|
3874
|
-
return { approved: true, seniorOutput: seniorResult.content, juniorResponse: juniorResult.content };
|
|
3875
|
-
} else {
|
|
3876
|
-
state.state = "junior_rejected";
|
|
3877
|
-
await writeState(directory, state);
|
|
3878
|
-
return { approved: false, seniorOutput: seniorResult.content, juniorResponse: juniorResult.content };
|
|
3879
|
-
}
|
|
3880
|
-
};
|
|
3881
|
-
let loopResult = await runSeniorJuniorLoop();
|
|
3882
|
-
while (!loopResult.approved) {
|
|
3883
|
-
state.loop_count++;
|
|
3884
|
-
await client.app.log({
|
|
3885
|
-
body: {
|
|
3886
|
-
service: "opencode-manifold",
|
|
3887
|
-
level: "info",
|
|
3888
|
-
message: `Junior rejected, loop_count: ${state.loop_count}/${settings.maxLoops}`
|
|
3889
|
-
}
|
|
3890
|
-
});
|
|
3891
|
-
if (state.loop_count >= settings.maxLoops) {
|
|
3892
|
-
state.state = "escalate_debug";
|
|
3893
|
-
await writeState(directory, state);
|
|
3894
|
-
await client.app.log({
|
|
3895
|
-
body: {
|
|
3896
|
-
service: "opencode-manifold",
|
|
3897
|
-
level: "info",
|
|
3898
|
-
message: "State: escalate_debug - Spawning Debug agent"
|
|
3899
|
-
}
|
|
3900
|
-
});
|
|
3901
|
-
const debugPrompt = `You are the Debug Agent. The Senior/Junior loop has failed ${settings.maxLoops} times.
|
|
558
|
+
}
|
|
559
|
+
function buildReImplementPrompt(state, args) {
|
|
560
|
+
return `You are the Senior Developer. Re-implement this task addressing the Junior Developer's feedback.
|
|
3902
561
|
|
|
3903
|
-
Task: ${
|
|
562
|
+
Task: ${args.description}
|
|
3904
563
|
|
|
3905
|
-
|
|
3906
|
-
${
|
|
564
|
+
Original Scoped Prompt:
|
|
565
|
+
${state.researchSummary}
|
|
3907
566
|
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
maxRetries: settings.maxRetries,
|
|
3911
|
-
onRetry: (attempt, error) => {
|
|
3912
|
-
client.app.log({
|
|
3913
|
-
body: {
|
|
3914
|
-
service: "opencode-manifold",
|
|
3915
|
-
level: "warn",
|
|
3916
|
-
message: `Debug retry ${attempt}: ${error.message}`
|
|
3917
|
-
}
|
|
3918
|
-
});
|
|
3919
|
-
}
|
|
3920
|
-
});
|
|
3921
|
-
if (!debugResult.success) {
|
|
3922
|
-
state.state = "escalate_user";
|
|
3923
|
-
await writeState(directory, state);
|
|
3924
|
-
return {
|
|
3925
|
-
status: "escalated_user",
|
|
3926
|
-
summary: `Task ${task.task_number}: Debug failed - ${debugResult.error}`,
|
|
3927
|
-
files_changed: [],
|
|
3928
|
-
loops: state.loop_count,
|
|
3929
|
-
wiki_entry: `Manifold/tasks/${task.slug}-${task.task_number.toString().padStart(3, "0")}.md`
|
|
3930
|
-
};
|
|
3931
|
-
}
|
|
3932
|
-
state.debug_suggestion = debugResult.content;
|
|
3933
|
-
state.loop_history.push(`**Debug Analysis:** ${debugResult.content}`);
|
|
3934
|
-
await writeState(directory, state);
|
|
3935
|
-
state.state = "debug_done";
|
|
3936
|
-
await writeState(directory, state);
|
|
3937
|
-
await client.app.log({
|
|
3938
|
-
body: {
|
|
3939
|
-
service: "opencode-manifold",
|
|
3940
|
-
level: "info",
|
|
3941
|
-
message: "State: debug_done - Senior implements Debug suggestion"
|
|
3942
|
-
}
|
|
3943
|
-
});
|
|
3944
|
-
const debugSeniorPrompt = `You are the Senior Developer. A Debug agent has identified a root cause issue.
|
|
567
|
+
Junior Developer's Feedback:
|
|
568
|
+
${state.reviewFeedback}
|
|
3945
569
|
|
|
3946
|
-
|
|
570
|
+
Address these issues and resubmit your implementation.`;
|
|
571
|
+
}
|
|
572
|
+
function buildDebugPrompt(state, args) {
|
|
573
|
+
return `You are the Debug Agent. The Senior/Junior loop has failed ${state.loops} times.
|
|
3947
574
|
|
|
3948
|
-
|
|
3949
|
-
${debugResult.content}
|
|
575
|
+
Task: ${args.description}
|
|
3950
576
|
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
maxRetries: settings.maxRetries,
|
|
3954
|
-
onRetry: (attempt, error) => {
|
|
3955
|
-
client.app.log({
|
|
3956
|
-
body: {
|
|
3957
|
-
service: "opencode-manifold",
|
|
3958
|
-
level: "warn",
|
|
3959
|
-
message: `Debug Senior retry ${attempt}: ${error.message}`
|
|
3960
|
-
}
|
|
3961
|
-
});
|
|
3962
|
-
}
|
|
3963
|
-
});
|
|
3964
|
-
if (!debugSeniorResult.success) {
|
|
3965
|
-
state.state = "escalate_user";
|
|
3966
|
-
await writeState(directory, state);
|
|
3967
|
-
return {
|
|
3968
|
-
status: "escalated_user",
|
|
3969
|
-
summary: `Task ${task.task_number}: Debug Senior failed - ${debugSeniorResult.error}`,
|
|
3970
|
-
files_changed: [],
|
|
3971
|
-
loops: state.loop_count,
|
|
3972
|
-
wiki_entry: `Manifold/tasks/${task.slug}-${task.task_number.toString().padStart(3, "0")}.md`
|
|
3973
|
-
};
|
|
3974
|
-
}
|
|
3975
|
-
state.senior_output = debugSeniorResult.content;
|
|
3976
|
-
state.loop_history.push(`**Debug Senior:** ${debugSeniorResult.content.substring(0, 200)}...`);
|
|
3977
|
-
await writeState(directory, state);
|
|
3978
|
-
state.state = "debug_review";
|
|
3979
|
-
await writeState(directory, state);
|
|
3980
|
-
await client.app.log({
|
|
3981
|
-
body: {
|
|
3982
|
-
service: "opencode-manifold",
|
|
3983
|
-
level: "info",
|
|
3984
|
-
message: "State: debug_review - Debug reviews implementation"
|
|
3985
|
-
}
|
|
3986
|
-
});
|
|
3987
|
-
const debugReviewPrompt = `You are the Debug Agent reviewing the Senior Developer's implementation of your suggestion.
|
|
577
|
+
Research Context:
|
|
578
|
+
${state.researchSummary}
|
|
3988
579
|
|
|
3989
|
-
|
|
580
|
+
Failed Implementation:
|
|
581
|
+
${state.implementationOutput}
|
|
3990
582
|
|
|
3991
|
-
|
|
3992
|
-
${state.
|
|
583
|
+
Junior Developer's Feedback:
|
|
584
|
+
${state.reviewFeedback}
|
|
3993
585
|
|
|
3994
|
-
|
|
3995
|
-
|
|
586
|
+
Analyze why the loop is stuck and suggest a concrete alternative approach.`;
|
|
587
|
+
}
|
|
588
|
+
function buildDebugImplementPrompt(state, args) {
|
|
589
|
+
return `You are the Senior Developer. Implement the Debug Agent's suggestion.
|
|
3996
590
|
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
client.app.log({
|
|
4002
|
-
body: {
|
|
4003
|
-
service: "opencode-manifold",
|
|
4004
|
-
level: "warn",
|
|
4005
|
-
message: `Debug review retry ${attempt}: ${error.message}`
|
|
4006
|
-
}
|
|
4007
|
-
});
|
|
4008
|
-
}
|
|
4009
|
-
});
|
|
4010
|
-
if (!debugReviewResult.success) {
|
|
4011
|
-
state.state = "escalate_user";
|
|
4012
|
-
await writeState(directory, state);
|
|
4013
|
-
return {
|
|
4014
|
-
status: "escalated_user",
|
|
4015
|
-
summary: `Task ${task.task_number}: Debug review failed - ${debugReviewResult.error}`,
|
|
4016
|
-
files_changed: [],
|
|
4017
|
-
loops: state.loop_count,
|
|
4018
|
-
wiki_entry: `Manifold/tasks/${task.slug}-${task.task_number.toString().padStart(3, "0")}.md`
|
|
4019
|
-
};
|
|
4020
|
-
}
|
|
4021
|
-
const debugReviewWord = parseJuniorFirstWord(debugReviewResult.content);
|
|
4022
|
-
if (debugReviewWord === "COMPLETE") {
|
|
4023
|
-
state.state = "junior_approved";
|
|
4024
|
-
await writeState(directory, state);
|
|
4025
|
-
loopResult = {
|
|
4026
|
-
approved: true,
|
|
4027
|
-
seniorOutput: debugSeniorResult.content,
|
|
4028
|
-
juniorResponse: debugReviewResult.content
|
|
4029
|
-
};
|
|
4030
|
-
break;
|
|
4031
|
-
}
|
|
4032
|
-
if (settings.clerkRetryEnabled && state.clerk_retry_count === 0) {
|
|
4033
|
-
state.state = "escalate_clerk_retry";
|
|
4034
|
-
await writeState(directory, state);
|
|
4035
|
-
await client.app.log({
|
|
4036
|
-
body: {
|
|
4037
|
-
service: "opencode-manifold",
|
|
4038
|
-
level: "info",
|
|
4039
|
-
message: "State: escalate_clerk_retry - Clerk re-researches with failure context"
|
|
4040
|
-
}
|
|
4041
|
-
});
|
|
4042
|
-
state.clerk_retry_count++;
|
|
4043
|
-
state.loop_count = 0;
|
|
4044
|
-
state.loop_history = [];
|
|
4045
|
-
await writeState(directory, state);
|
|
4046
|
-
const clerkRetryPrompt = `You are the Clerk. The previous implementation attempt failed. Re-research with failure context.
|
|
591
|
+
Task: ${args.description}
|
|
592
|
+
|
|
593
|
+
Debug Agent's Analysis:
|
|
594
|
+
${state.debugAnalysis}
|
|
4047
595
|
|
|
4048
|
-
|
|
596
|
+
Implement the task following the Debug agent's suggestion.`;
|
|
597
|
+
}
|
|
598
|
+
function buildReResearchPrompt(state, args) {
|
|
599
|
+
return `You are the Clerk. The previous implementation attempt failed. Re-research with failure context.
|
|
600
|
+
|
|
601
|
+
Original Task: ${args.description}
|
|
4049
602
|
|
|
4050
603
|
Previous Implementation (failed):
|
|
4051
|
-
${state.
|
|
604
|
+
${state.implementationOutput}
|
|
4052
605
|
|
|
4053
|
-
Junior
|
|
4054
|
-
${state.
|
|
606
|
+
Junior Developer's Feedback:
|
|
607
|
+
${state.reviewFeedback}
|
|
4055
608
|
|
|
4056
609
|
Debug Agent's Suggestion (also didn't work):
|
|
4057
|
-
${state.
|
|
610
|
+
${state.debugAnalysis}
|
|
4058
611
|
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
service: "opencode-manifold",
|
|
4066
|
-
level: "warn",
|
|
4067
|
-
message: `Clerk retry retry ${attempt}: ${error.message}`
|
|
4068
|
-
}
|
|
4069
|
-
});
|
|
4070
|
-
}
|
|
4071
|
-
});
|
|
4072
|
-
if (!clerkRetryResult.success) {
|
|
4073
|
-
state.state = "escalate_user";
|
|
4074
|
-
await writeState(directory, state);
|
|
4075
|
-
return {
|
|
4076
|
-
status: "escalated_user",
|
|
4077
|
-
summary: `Task ${task.task_number}: Clerk retry failed - ${clerkRetryResult.error}`,
|
|
4078
|
-
files_changed: [],
|
|
4079
|
-
loops: state.loop_count,
|
|
4080
|
-
wiki_entry: `Manifold/tasks/${task.slug}-${task.task_number.toString().padStart(3, "0")}.md`
|
|
4081
|
-
};
|
|
4082
|
-
}
|
|
4083
|
-
state.scoped_prompt = clerkRetryResult.content;
|
|
4084
|
-
state.state = "clerk_retry";
|
|
4085
|
-
await writeState(directory, state);
|
|
4086
|
-
await client.app.log({
|
|
4087
|
-
body: {
|
|
4088
|
-
service: "opencode-manifold",
|
|
4089
|
-
level: "info",
|
|
4090
|
-
message: "State: clerk_retry - Starting fresh loop with new prompt"
|
|
4091
|
-
}
|
|
4092
|
-
});
|
|
4093
|
-
loopResult = await runSeniorJuniorLoop();
|
|
4094
|
-
} else {
|
|
4095
|
-
state.state = "escalate_user";
|
|
4096
|
-
await writeState(directory, state);
|
|
4097
|
-
return {
|
|
4098
|
-
status: "escalated_user",
|
|
4099
|
-
summary: `Task ${task.task_number}: All loops exhausted. Last feedback: ${state.junior_response}`,
|
|
4100
|
-
files_changed: [],
|
|
4101
|
-
loops: state.loop_count,
|
|
4102
|
-
wiki_entry: `Manifold/tasks/${task.slug}-${task.task_number.toString().padStart(3, "0")}.md`
|
|
4103
|
-
};
|
|
4104
|
-
}
|
|
4105
|
-
} else {
|
|
4106
|
-
state.state = "junior_rejected";
|
|
4107
|
-
await writeState(directory, state);
|
|
4108
|
-
await client.app.log({
|
|
4109
|
-
body: {
|
|
4110
|
-
service: "opencode-manifold",
|
|
4111
|
-
level: "info",
|
|
4112
|
-
message: `Junior rejected, looping back to Senior with feedback (loop ${state.loop_count + 1})`
|
|
4113
|
-
}
|
|
4114
|
-
});
|
|
4115
|
-
const basePrompt = state.scoped_prompt ?? "";
|
|
4116
|
-
const feedbackSection = `
|
|
612
|
+
Re-research the task with this failure context and compose a new scoped prompt that addresses the underlying issues.`;
|
|
613
|
+
}
|
|
614
|
+
function buildLoggingPrompt(state, args) {
|
|
615
|
+
const taskId = `${state.slug}-${state.task_number.toString().padStart(3, "0")}`;
|
|
616
|
+
const date = new Date().toISOString().split("T")[0];
|
|
617
|
+
return `You are the Clerk. Log the completed task to the project wiki.
|
|
4117
618
|
|
|
4118
|
-
|
|
619
|
+
Task ID: ${taskId}
|
|
620
|
+
Task Description: ${args.description}
|
|
621
|
+
Date: ${date}
|
|
622
|
+
Status: COMPLETED
|
|
623
|
+
Loops: ${state.loops}
|
|
4119
624
|
|
|
4120
|
-
|
|
4121
|
-
|
|
625
|
+
Scoped Prompt Used:
|
|
626
|
+
${state.researchSummary}
|
|
4122
627
|
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
state.scoped_prompt = seniorRetryPrompt;
|
|
4126
|
-
await writeState(directory, state);
|
|
4127
|
-
loopResult = await runSeniorJuniorLoop();
|
|
4128
|
-
}
|
|
4129
|
-
}
|
|
4130
|
-
const { files_changed } = await runClerkLoggingPhase(client, task, state, settings, directory);
|
|
4131
|
-
state.state = "complete";
|
|
4132
|
-
await writeState(directory, state);
|
|
4133
|
-
await client.app.log({
|
|
4134
|
-
body: {
|
|
4135
|
-
service: "opencode-manifold",
|
|
4136
|
-
level: "info",
|
|
4137
|
-
message: `State: complete - Task ${task.task_number} completed in ${state.loop_count} loops`
|
|
4138
|
-
}
|
|
4139
|
-
});
|
|
4140
|
-
return {
|
|
4141
|
-
status: "completed",
|
|
4142
|
-
summary: `Task ${task.task_number}: ${task.description} - Completed successfully`,
|
|
4143
|
-
files_changed,
|
|
4144
|
-
loops: state.loop_count,
|
|
4145
|
-
wiki_entry: `Manifold/tasks/${task.slug}-${task.task_number.toString().padStart(3, "0")}.md`
|
|
4146
|
-
};
|
|
4147
|
-
}
|
|
628
|
+
Senior Developer's Final Implementation:
|
|
629
|
+
${state.implementationOutput}
|
|
4148
630
|
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
async function runTest(directory, taskDescription, options) {
|
|
4152
|
-
const testCommand = extractTestCommand(taskDescription) || options.testCommand;
|
|
4153
|
-
if (!testCommand) {
|
|
4154
|
-
return { skip: true };
|
|
4155
|
-
}
|
|
4156
|
-
return new Promise((resolve) => {
|
|
4157
|
-
const child = spawn(testCommand, [], {
|
|
4158
|
-
shell: true,
|
|
4159
|
-
cwd: directory
|
|
4160
|
-
});
|
|
4161
|
-
let stdout = "";
|
|
4162
|
-
let stderr = "";
|
|
4163
|
-
child.stdout?.on("data", (data) => {
|
|
4164
|
-
stdout += data.toString();
|
|
4165
|
-
});
|
|
4166
|
-
child.stderr?.on("data", (data) => {
|
|
4167
|
-
stderr += data.toString();
|
|
4168
|
-
});
|
|
4169
|
-
const timeout = setTimeout(() => {
|
|
4170
|
-
child.kill();
|
|
4171
|
-
resolve({
|
|
4172
|
-
skip: false,
|
|
4173
|
-
result: {
|
|
4174
|
-
passed: false,
|
|
4175
|
-
output: `Test timed out after ${options.timeout}s`,
|
|
4176
|
-
exitCode: 124
|
|
4177
|
-
}
|
|
4178
|
-
});
|
|
4179
|
-
}, options.timeout * 1000);
|
|
4180
|
-
child.on("close", (code) => {
|
|
4181
|
-
clearTimeout(timeout);
|
|
4182
|
-
const exitCode = code ?? 0;
|
|
4183
|
-
const output = stdout + (stderr ? `
|
|
4184
|
-
STDERR:
|
|
4185
|
-
` + stderr : "");
|
|
4186
|
-
resolve({
|
|
4187
|
-
skip: false,
|
|
4188
|
-
result: {
|
|
4189
|
-
passed: exitCode === 0,
|
|
4190
|
-
output: output || "No output",
|
|
4191
|
-
exitCode
|
|
4192
|
-
}
|
|
4193
|
-
});
|
|
4194
|
-
});
|
|
4195
|
-
child.on("error", (error) => {
|
|
4196
|
-
clearTimeout(timeout);
|
|
4197
|
-
resolve({
|
|
4198
|
-
skip: false,
|
|
4199
|
-
result: {
|
|
4200
|
-
passed: false,
|
|
4201
|
-
output: error.message,
|
|
4202
|
-
exitCode: 1
|
|
4203
|
-
}
|
|
4204
|
-
});
|
|
4205
|
-
});
|
|
4206
|
-
});
|
|
4207
|
-
}
|
|
4208
|
-
function extractTestCommand(taskDescription) {
|
|
4209
|
-
const testPatterns = [
|
|
4210
|
-
/test:\s*(.+)/i,
|
|
4211
|
-
/run:\s*(.+)/i,
|
|
4212
|
-
/execute:\s*(.+)/i,
|
|
4213
|
-
/```bash\n(.+)\n```/,
|
|
4214
|
-
/`([^`]+)`/
|
|
4215
|
-
];
|
|
4216
|
-
for (const pattern of testPatterns) {
|
|
4217
|
-
const match = taskDescription.match(pattern);
|
|
4218
|
-
if (match && match[1]) {
|
|
4219
|
-
return match[1].trim();
|
|
4220
|
-
}
|
|
4221
|
-
}
|
|
4222
|
-
return null;
|
|
4223
|
-
}
|
|
631
|
+
Junior Developer's Approval Response:
|
|
632
|
+
${state.reviewFeedback}
|
|
4224
633
|
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
if (existsSync5(plansPath)) {
|
|
4251
|
-
const content = await readFile4(plansPath, "utf-8");
|
|
4252
|
-
plans = JSON.parse(content);
|
|
4253
|
-
}
|
|
4254
|
-
const planSlug = planFile.replace(/[^a-zA-Z0-9]/g, "-").toLowerCase().substring(0, 30);
|
|
4255
|
-
if (!plans[planSlug]) {
|
|
4256
|
-
plans[planSlug] = {
|
|
4257
|
-
full_title: planFile,
|
|
4258
|
-
task_count: 0,
|
|
4259
|
-
status: "in_progress",
|
|
4260
|
-
created: new Date().toISOString().split("T")[0],
|
|
4261
|
-
plan_file: planFile
|
|
4262
|
-
};
|
|
4263
|
-
}
|
|
4264
|
-
plans[planSlug].task_count++;
|
|
4265
|
-
await writeFile4(plansPath, JSON.stringify(plans, null, 2));
|
|
4266
|
-
return plans[planSlug].task_count;
|
|
634
|
+
Please perform the following logging actions:
|
|
635
|
+
|
|
636
|
+
1. Create/Update Task File at \`Manifold/tasks/${taskId}.md\`:
|
|
637
|
+
- Header with date, status, loops, task description
|
|
638
|
+
- Scoped Prompt section
|
|
639
|
+
- Design Decisions section (extract from Senior's implementation reasoning)
|
|
640
|
+
- Files Touched section (extract file paths from Senior's implementation)
|
|
641
|
+
- Complete Loop History section
|
|
642
|
+
|
|
643
|
+
2. Update \`Manifold/index.md\`:
|
|
644
|
+
- Add entry under the plan's section:
|
|
645
|
+
\`- [[${taskId}]] — ${args.description} | ${date} | COMPLETED\`
|
|
646
|
+
|
|
647
|
+
3. Append to \`Manifold/log.md\`:
|
|
648
|
+
\`## [${date}] ${taskId} | ${args.description} | COMPLETED | ${state.loops} loops\`
|
|
649
|
+
|
|
650
|
+
4. Update graph files for each touched file:
|
|
651
|
+
- Read the implementation and identify all files that were created or modified
|
|
652
|
+
- For each file, create or update \`Manifold/graph/<graph-name>.md\`
|
|
653
|
+
- Add the task ID to the "Tasks That Edited" section
|
|
654
|
+
- Do NOT populate "Calls" or "Depends On" sections — those are synced automatically from the codebase index
|
|
655
|
+
- Graph filename format: replace \`/\` with \`__SL__\` and \`.\` with \`__DT__\`, append \`.md\`
|
|
656
|
+
- Example: \`src/middleware/auth.ts\` → \`src__SL__middleware__SL__auth__DT__ts.md\`
|
|
657
|
+
|
|
658
|
+
Extract the list of files touched from the Senior's implementation and include it in your response.`;
|
|
4267
659
|
}
|
|
4268
660
|
function getClient() {
|
|
4269
661
|
if (!pluginClient) {
|
|
@@ -4272,89 +664,82 @@ function getClient() {
|
|
|
4272
664
|
return pluginClient;
|
|
4273
665
|
}
|
|
4274
666
|
var dispatchTaskTool = tool({
|
|
4275
|
-
description: "
|
|
667
|
+
description: "Dispatcher for the multi-agent development system. Returns routing instructions based on bool state. Clerk calls this to determine the next step in the task workflow.",
|
|
4276
668
|
args: {
|
|
4277
|
-
task_number: tool.schema.number().describe("Sequential task number"),
|
|
4278
|
-
|
|
4279
|
-
|
|
669
|
+
task_number: tool.schema.number().optional().describe("Sequential task number (required on first call)"),
|
|
670
|
+
plan_file: tool.schema.string().optional().describe("Path to the plan document (required on first call)"),
|
|
671
|
+
newTask: tool.schema.boolean().optional().describe("TRUE: First call for this task. Resets all state."),
|
|
672
|
+
researchComplete: tool.schema.boolean().optional().describe("TRUE: Clerk has finished researching the codebase"),
|
|
673
|
+
hasImplementation: tool.schema.boolean().optional().describe("TRUE: Senior-dev returned working code"),
|
|
674
|
+
reviewDone: tool.schema.boolean().optional().describe("TRUE: Junior-dev has responded (regardless of pass/fail)"),
|
|
675
|
+
reviewPassed: tool.schema.boolean().optional().describe("TRUE: Junior-dev responded with COMPLETE"),
|
|
676
|
+
needsDecomposition: tool.schema.boolean().optional().describe("TRUE: Task requires project-wide decomposition"),
|
|
677
|
+
debugComplete: tool.schema.boolean().optional().describe("TRUE: Debug agent has finished analyzing"),
|
|
678
|
+
reResearched: tool.schema.boolean().optional().describe("TRUE: Clerk has re-researched with failure context"),
|
|
679
|
+
researchSummary: tool.schema.string().optional().describe("Clerk's research findings"),
|
|
680
|
+
implementationOutput: tool.schema.string().optional().describe("Senior-dev's full output"),
|
|
681
|
+
reviewFeedback: tool.schema.string().optional().describe("Junior-dev's full response"),
|
|
682
|
+
debugAnalysis: tool.schema.string().optional().describe("Debug agent's full analysis"),
|
|
683
|
+
notes: tool.schema.string().optional().describe("Optional free-text reasoning")
|
|
4280
684
|
},
|
|
4281
685
|
async execute(args, context) {
|
|
4282
|
-
const { task_number,
|
|
686
|
+
const { task_number, plan_file } = args;
|
|
4283
687
|
const client = getClient();
|
|
4284
|
-
await client.app.log({
|
|
4285
|
-
body: {
|
|
4286
|
-
service: "opencode-manifold",
|
|
4287
|
-
level: "info",
|
|
4288
|
-
message: `dispatchTask called: task ${task_number} - ${description}`
|
|
4289
|
-
}
|
|
4290
|
-
});
|
|
4291
688
|
const directory = context.directory;
|
|
4292
|
-
const settings = await readSettings(directory);
|
|
4293
|
-
await updatePlansRegistry(directory, plan_file);
|
|
4294
|
-
await client.app.log({
|
|
4295
|
-
body: {
|
|
4296
|
-
service: "opencode-manifold",
|
|
4297
|
-
level: "info",
|
|
4298
|
-
message: `Settings loaded: maxLoops=${settings.maxLoops}, timeout=${settings.timeout}s`
|
|
4299
|
-
}
|
|
4300
|
-
});
|
|
4301
|
-
const slug = plan_file.replace(/[^a-zA-Z0-9]/g, "-").toLowerCase().substring(0, 30);
|
|
4302
|
-
const stateMachineResult = await runStateMachine({
|
|
4303
|
-
task_number,
|
|
4304
|
-
description,
|
|
4305
|
-
plan_file,
|
|
4306
|
-
slug
|
|
4307
|
-
}, settings, { client, directory });
|
|
4308
689
|
await client.app.log({
|
|
4309
690
|
body: {
|
|
4310
691
|
service: "opencode-manifold",
|
|
4311
692
|
level: "info",
|
|
4312
|
-
message: `
|
|
693
|
+
message: `dispatchTask called: task ${task_number || "unknown"} - ${args.newTask ? "new task" : "continuing"}`
|
|
4313
694
|
}
|
|
4314
695
|
});
|
|
4315
|
-
const
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
}
|
|
4325
|
-
}
|
|
696
|
+
const settings = await readSettings(directory);
|
|
697
|
+
const existingState = task_number ? await readDispatcherState(directory, task_number) : null;
|
|
698
|
+
let taskInfo = null;
|
|
699
|
+
if (args.newTask && plan_file) {
|
|
700
|
+
try {
|
|
701
|
+
const planPath = join2(directory, plan_file);
|
|
702
|
+
if (existsSync2(planPath)) {
|
|
703
|
+
const planContent = await readFile2(planPath, "utf-8");
|
|
704
|
+
taskInfo = extractTaskFromPlan(planContent, task_number);
|
|
705
|
+
}
|
|
706
|
+
} catch (error) {
|
|
4326
707
|
await client.app.log({
|
|
4327
708
|
body: {
|
|
4328
709
|
service: "opencode-manifold",
|
|
4329
710
|
level: "error",
|
|
4330
|
-
message: `
|
|
711
|
+
message: `Failed to read plan file: ${error}`
|
|
4331
712
|
}
|
|
4332
713
|
});
|
|
4333
|
-
return JSON.stringify({
|
|
4334
|
-
status: "escalated_user",
|
|
4335
|
-
summary: `Task ${task_number}: ${description} - Test failed
|
|
4336
|
-
|
|
4337
|
-
${testResult.result.output}`,
|
|
4338
|
-
files_changed: stateMachineResult.files_changed,
|
|
4339
|
-
loops: stateMachineResult.loops,
|
|
4340
|
-
wiki_entry: stateMachineResult.wiki_entry
|
|
4341
|
-
});
|
|
4342
714
|
}
|
|
4343
715
|
}
|
|
716
|
+
const mergedArgs = {
|
|
717
|
+
...args,
|
|
718
|
+
description: taskInfo?.description || args.description
|
|
719
|
+
};
|
|
720
|
+
const result = runDispatcherLogic(mergedArgs, existingState, settings);
|
|
721
|
+
if (task_number && result.state.task_id) {
|
|
722
|
+
const newState = {
|
|
723
|
+
task_number,
|
|
724
|
+
plan_file: plan_file || "",
|
|
725
|
+
slug: result.state.task_id.split("-")[0],
|
|
726
|
+
loops: result.state.loops,
|
|
727
|
+
clerkRetries: result.state.clerkRetries,
|
|
728
|
+
researchSummary: args.researchSummary || existingState?.researchSummary || "",
|
|
729
|
+
implementationOutput: args.implementationOutput || existingState?.implementationOutput || "",
|
|
730
|
+
reviewFeedback: args.reviewFeedback || existingState?.reviewFeedback || "",
|
|
731
|
+
debugAnalysis: args.debugAnalysis || existingState?.debugAnalysis || ""
|
|
732
|
+
};
|
|
733
|
+
await writeDispatcherState(directory, newState);
|
|
734
|
+
}
|
|
4344
735
|
await client.app.log({
|
|
4345
736
|
body: {
|
|
4346
737
|
service: "opencode-manifold",
|
|
4347
738
|
level: "info",
|
|
4348
|
-
message: `dispatchTask
|
|
739
|
+
message: `dispatchTask result: ${result.route} → ${result.agent || "none"} (${result.message})`
|
|
4349
740
|
}
|
|
4350
741
|
});
|
|
4351
|
-
return JSON.stringify(
|
|
4352
|
-
status: stateMachineResult.status,
|
|
4353
|
-
summary: stateMachineResult.summary,
|
|
4354
|
-
files_changed: stateMachineResult.files_changed,
|
|
4355
|
-
loops: stateMachineResult.loops,
|
|
4356
|
-
wiki_entry: stateMachineResult.wiki_entry
|
|
4357
|
-
});
|
|
742
|
+
return JSON.stringify(result);
|
|
4358
743
|
}
|
|
4359
744
|
});
|
|
4360
745
|
|