dayloom 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +1146 -0
  2. package/dist/cli/daily.js +41 -0
  3. package/dist/cli/index.js +33 -0
  4. package/dist/cli/init.js +40 -0
  5. package/dist/cli/next.js +60 -0
  6. package/dist/cli/play.js +39 -0
  7. package/dist/cli/revise.js +41 -0
  8. package/dist/cli/settle.js +45 -0
  9. package/dist/daily/apply-plan.js +25 -0
  10. package/dist/daily/constants.js +16 -0
  11. package/dist/daily/dialogue-loop.js +147 -0
  12. package/dist/daily/finalize.js +23 -0
  13. package/dist/daily/guard.js +54 -0
  14. package/dist/daily/index.js +27 -0
  15. package/dist/daily/intent-router.js +65 -0
  16. package/dist/daily/mcp-gateway.js +5 -0
  17. package/dist/daily/mcp-tools.js +8 -0
  18. package/dist/daily/parse-assistant.js +38 -0
  19. package/dist/daily/parse-payload.js +10 -0
  20. package/dist/daily/player-context.js +85 -0
  21. package/dist/daily/project-plan.js +15 -0
  22. package/dist/daily/promptpile-loop.js +41 -0
  23. package/dist/daily/prompts.js +11 -0
  24. package/dist/daily/read-user-input.js +6 -0
  25. package/dist/daily/session.js +119 -0
  26. package/dist/daily/types.js +2 -0
  27. package/dist/daily/validate-plan.js +46 -0
  28. package/dist/i18n/detect.js +23 -0
  29. package/dist/i18n/index.js +22 -0
  30. package/dist/i18n/messages.js +149 -0
  31. package/dist/index.js +27 -0
  32. package/dist/init/apply-payload.js +18 -0
  33. package/dist/init/archive-transcript.js +28 -0
  34. package/dist/init/checklist.js +74 -0
  35. package/dist/init/cleanup.js +12 -0
  36. package/dist/init/constants.js +21 -0
  37. package/dist/init/errors.js +11 -0
  38. package/dist/init/finalize.js +35 -0
  39. package/dist/init/guard.js +31 -0
  40. package/dist/init/index.js +59 -0
  41. package/dist/init/interview-loop.js +103 -0
  42. package/dist/init/parse-assistant.js +50 -0
  43. package/dist/init/project-payload.js +78 -0
  44. package/dist/init/promptpile-run.js +80 -0
  45. package/dist/init/prompts.js +16 -0
  46. package/dist/init/read-user-input.js +44 -0
  47. package/dist/init/scaffold.js +66 -0
  48. package/dist/init/session.js +98 -0
  49. package/dist/init/types.js +2 -0
  50. package/dist/next/index.js +79 -0
  51. package/dist/next/inspect.js +90 -0
  52. package/dist/play/ai.js +11 -0
  53. package/dist/play/event-loop.js +244 -0
  54. package/dist/play/guard.js +14 -0
  55. package/dist/play/index.js +21 -0
  56. package/dist/play/parse-assistant.js +39 -0
  57. package/dist/play/player-context.js +20 -0
  58. package/dist/play/prompts.js +9 -0
  59. package/dist/play/session.js +14 -0
  60. package/dist/play/state.js +117 -0
  61. package/dist/play/types.js +2 -0
  62. package/dist/play/validate.js +156 -0
  63. package/dist/revise/apply-payload.js +58 -0
  64. package/dist/revise/bin-resolve.js +38 -0
  65. package/dist/revise/constants.js +17 -0
  66. package/dist/revise/dialogue-loop.js +116 -0
  67. package/dist/revise/diff.js +24 -0
  68. package/dist/revise/file-hash.js +27 -0
  69. package/dist/revise/finalize.js +23 -0
  70. package/dist/revise/guard.js +17 -0
  71. package/dist/revise/index.js +24 -0
  72. package/dist/revise/mcp-gateway.js +74 -0
  73. package/dist/revise/mcp-tools.js +91 -0
  74. package/dist/revise/parse-assistant.js +41 -0
  75. package/dist/revise/parse-payload.js +22 -0
  76. package/dist/revise/process-run.js +77 -0
  77. package/dist/revise/project-payload.js +62 -0
  78. package/dist/revise/promptpile-loop.js +41 -0
  79. package/dist/revise/prompts.js +16 -0
  80. package/dist/revise/read-user-input.js +35 -0
  81. package/dist/revise/session.js +119 -0
  82. package/dist/revise/types.js +2 -0
  83. package/dist/revise/validate-payload.js +47 -0
  84. package/dist/settle/ai.js +23 -0
  85. package/dist/settle/apply.js +58 -0
  86. package/dist/settle/context.js +69 -0
  87. package/dist/settle/derive.js +56 -0
  88. package/dist/settle/guard.js +71 -0
  89. package/dist/settle/index.js +105 -0
  90. package/dist/settle/parse-assistant.js +14 -0
  91. package/dist/settle/parse-payload.js +19 -0
  92. package/dist/settle/project.js +58 -0
  93. package/dist/settle/session.js +45 -0
  94. package/dist/settle/types.js +2 -0
  95. package/dist/settle/validate.js +100 -0
  96. package/dist/shared/filtered-stream-output.js +41 -0
  97. package/dist/shared/promptpile-stream.js +59 -0
  98. package/dist/shared/run-promptpile-with-stream.js +34 -0
  99. package/dist/utils/loading.js +54 -0
  100. package/package.json +39 -0
  101. package/prompts/README.md +39 -0
  102. package/prompts/choice.system.md +0 -0
  103. package/prompts/daily-dialogue.system.md +37 -0
  104. package/prompts/daily-finalize-plan.system.md +34 -0
  105. package/prompts/daily-intent-router.system.md +34 -0
  106. package/prompts/day-planner.system.md +0 -0
  107. package/prompts/day-summarizer.system.md +0 -0
  108. package/prompts/dialogue.system.md +0 -0
  109. package/prompts/diary-writer.system.md +0 -0
  110. package/prompts/event-runner.system.md +0 -0
  111. package/prompts/init-finalize.system.md +59 -0
  112. package/prompts/init-interviewer.system.md +37 -0
  113. package/prompts/memory-updater.system.md +0 -0
  114. package/prompts/next-day-seeder.system.md +0 -0
  115. package/prompts/play-event-dialogue.system.md +20 -0
  116. package/prompts/play-event-generator.system.md +19 -0
  117. package/prompts/play-event-resolver.system.md +26 -0
  118. package/prompts/play-replanner.system.md +21 -0
  119. package/prompts/revise-dialogue.system.md +22 -0
  120. package/prompts/revise-finalize.system.md +40 -0
  121. package/prompts/settle.system.md +28 -0
  122. package/prompts/spec.md +320 -0
  123. package/prompts/state-resolver.system.md +0 -0
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerDailyCommand = registerDailyCommand;
4
+ const daily_1 = require("../daily");
5
+ const i18n_1 = require("../i18n");
6
+ function registerDailyCommand(program, t) {
7
+ const command = program.command('daily')
8
+ .description(t('cli.daily.description'))
9
+ .requiredOption('-d, --dir <path>', t('cli.common.dir'))
10
+ .option('--proposal <path>', t('cli.daily.proposal'))
11
+ .option('--dry-run', t('cli.daily.dryRun'))
12
+ .option('--yes', t('cli.daily.yes'))
13
+ .option('--keep-session', t('cli.daily.keepSession'))
14
+ .option('--max-tool-rounds <n>', t('cli.daily.maxToolRounds'), parsePositiveInt(t), 8)
15
+ .option('--mcp-base-url <url>', t('cli.common.mcpBaseUrl'))
16
+ .option('--mcp-token <token>', t('cli.common.mcpToken'));
17
+ (0, i18n_1.addLangOption)(command, t)
18
+ .action(async (opts) => {
19
+ try {
20
+ if (!opts.proposal) {
21
+ await (0, daily_1.dailyInteractive)(opts.dir, { dryRun: opts.dryRun, yes: opts.yes, keepSession: opts.keepSession, maxToolRounds: opts.maxToolRounds, mcpBaseUrl: opts.mcpBaseUrl, mcpToken: opts.mcpToken ?? process.env.PROMPTPILE_MCP_TOKEN });
22
+ return;
23
+ }
24
+ const result = (0, daily_1.dailyFromProposal)(opts.dir, opts.proposal, { dryRun: opts.dryRun, yes: opts.yes });
25
+ process.stdout.write(`${result.description}\n`);
26
+ process.stdout.write(result.applied ? `${t('cli.daily.applied')}\n` : `${t('cli.common.dryRunOnly')}\n`);
27
+ }
28
+ catch (err) {
29
+ console.error(t('cli.error'), err instanceof Error ? err.message : err);
30
+ process.exitCode = 1;
31
+ }
32
+ });
33
+ }
34
+ function parsePositiveInt(t) {
35
+ return value => {
36
+ const parsed = Number(value);
37
+ if (!Number.isInteger(parsed) || parsed < 1)
38
+ throw new Error(t('cli.positiveInteger'));
39
+ return parsed;
40
+ };
41
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCli = parseCli;
4
+ const commander_1 = require("commander");
5
+ const daily_1 = require("./daily");
6
+ const init_1 = require("./init");
7
+ const next_1 = require("./next");
8
+ const revise_1 = require("./revise");
9
+ const play_1 = require("./play");
10
+ const settle_1 = require("./settle");
11
+ const i18n_1 = require("../i18n");
12
+ function parseCli(argv = process.argv) {
13
+ const t = (0, i18n_1.createTranslator)((0, i18n_1.detectLocale)(argv, process.env));
14
+ const program = new commander_1.Command();
15
+ program
16
+ .name('dayloom')
17
+ .description(t('cli.description'))
18
+ .version(readPackageVersion(), '-V, --version', t('cli.version'))
19
+ .helpOption('-h, --help', t('cli.help'))
20
+ .helpCommand('help [command]', t('cli.helpCommand'));
21
+ (0, i18n_1.addLangOption)(program, t);
22
+ (0, init_1.registerInitCommand)(program, t);
23
+ (0, next_1.registerNextCommand)(program, t);
24
+ (0, daily_1.registerDailyCommand)(program, t);
25
+ (0, play_1.registerPlayCommand)(program, t);
26
+ (0, settle_1.registerSettleCommand)(program, t);
27
+ (0, revise_1.registerReviseCommand)(program, t);
28
+ program.parse(argv);
29
+ }
30
+ function readPackageVersion() {
31
+ const packageJson = require('../../package.json');
32
+ return packageJson.version ?? '0.0.0';
33
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerInitCommand = registerInitCommand;
4
+ const errors_1 = require("../init/errors");
5
+ const init_1 = require("../init");
6
+ const i18n_1 = require("../i18n");
7
+ function registerInitCommand(program, t) {
8
+ const command = program
9
+ .command('init')
10
+ .description(t('cli.init.description'))
11
+ .requiredOption('-d, --dir <path>', t('cli.common.dir'))
12
+ .option('--quick', t('cli.init.quick'))
13
+ .option('--id <id>', t('cli.init.id'))
14
+ .option('--title <title>', t('cli.init.title'))
15
+ .option('--max-rounds <n>', t('cli.init.maxRounds'), (v) => parseInt(v, 10), 12)
16
+ .option('--keep-session', t('cli.init.keepSession'));
17
+ (0, i18n_1.addLangOption)(command, t)
18
+ .action(async (opts) => {
19
+ try {
20
+ const options = {
21
+ id: opts.id,
22
+ title: opts.title,
23
+ maxRounds: opts.maxRounds,
24
+ keepSessionOnError: opts.keepSession,
25
+ };
26
+ const worldRoot = opts.quick
27
+ ? (0, init_1.initWorldQuick)(opts.dir, options)
28
+ : await (0, init_1.initWorldInteractive)(opts.dir, options);
29
+ process.stdout.write(`Initialized World save: ${worldRoot}\n`);
30
+ }
31
+ catch (err) {
32
+ if (err instanceof errors_1.InitCancelledError) {
33
+ process.stderr.write(`${err.message}\n`);
34
+ process.exit(0);
35
+ }
36
+ console.error(t('cli.error'), err instanceof Error ? err.message : err);
37
+ process.exit(1);
38
+ }
39
+ });
40
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerNextCommand = registerNextCommand;
4
+ const i18n_1 = require("../i18n");
5
+ const next_1 = require("../next");
6
+ function registerNextCommand(program, t) {
7
+ const command = program.command('next')
8
+ .description(t('cli.next.description'))
9
+ .requiredOption('-d, --dir <path>', t('cli.common.dir'))
10
+ .option('--status', t('cli.next.status'))
11
+ .option('--confirm', t('cli.next.confirm'))
12
+ .option('--quick', t('cli.next.quick'))
13
+ .option('--id <id>', t('cli.next.id'))
14
+ .option('--title <title>', t('cli.next.title'))
15
+ .option('--max-rounds <n>', t('cli.next.maxRounds'), parsePositiveInt(t), 12)
16
+ .option('--dry-run', t('cli.next.dryRun'))
17
+ .option('--yes', t('cli.next.yes'))
18
+ .option('--keep-session', t('cli.next.keepSession'))
19
+ .option('--max-tool-rounds <n>', t('cli.next.maxToolRounds'), parsePositiveInt(t), 8)
20
+ .option('--max-event-rounds <n>', t('cli.next.maxEventRounds'), parsePositiveInt(t), 20)
21
+ .option('--mcp-base-url <url>', t('cli.common.mcpBaseUrl'))
22
+ .option('--mcp-token <token>', t('cli.common.mcpToken'));
23
+ (0, i18n_1.addLangOption)(command, t)
24
+ .action(async (opts) => {
25
+ try {
26
+ await (0, next_1.runNext)(opts.dir, {
27
+ statusOnly: opts.status,
28
+ confirm: opts.confirm,
29
+ quick: opts.quick,
30
+ id: opts.id,
31
+ title: opts.title,
32
+ maxRounds: opts.maxRounds,
33
+ dryRun: opts.dryRun,
34
+ yes: opts.yes,
35
+ keepSession: opts.keepSession,
36
+ maxToolRounds: opts.maxToolRounds,
37
+ maxEventRounds: opts.maxEventRounds,
38
+ mcpBaseUrl: opts.mcpBaseUrl,
39
+ mcpToken: opts.mcpToken ?? process.env.PROMPTPILE_MCP_TOKEN,
40
+ t,
41
+ });
42
+ }
43
+ catch (err) {
44
+ if (err instanceof next_1.InitCancelledError) {
45
+ process.stderr.write(`${err.message}\n`);
46
+ process.exit(0);
47
+ }
48
+ console.error(t('cli.error'), err instanceof Error ? err.message : err);
49
+ process.exitCode = 1;
50
+ }
51
+ });
52
+ }
53
+ function parsePositiveInt(t) {
54
+ return value => {
55
+ const parsed = Number(value);
56
+ if (!Number.isInteger(parsed) || parsed < 1)
57
+ throw new Error(t('cli.positiveInteger'));
58
+ return parsed;
59
+ };
60
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerPlayCommand = registerPlayCommand;
4
+ const i18n_1 = require("../i18n");
5
+ const play_1 = require("../play");
6
+ function registerPlayCommand(program, t) {
7
+ const command = program.command('play')
8
+ .description(t('cli.play.description'))
9
+ .requiredOption('-d, --dir <path>', t('cli.common.dir'))
10
+ .option('--keep-session', t('cli.play.keepSession'))
11
+ .option('--max-tool-rounds <n>', t('cli.play.maxToolRounds'), positive(t), 8)
12
+ .option('--max-event-rounds <n>', t('cli.play.maxEventRounds'), positive(t), 20)
13
+ .option('--mcp-base-url <url>', t('cli.common.mcpBaseUrl'))
14
+ .option('--mcp-token <token>', t('cli.common.mcpToken'));
15
+ (0, i18n_1.addLangOption)(command, t)
16
+ .action(async (opts) => {
17
+ try {
18
+ await (0, play_1.playInteractive)(opts.dir, {
19
+ keepSession: opts.keepSession,
20
+ maxToolRounds: opts.maxToolRounds,
21
+ maxEventRounds: opts.maxEventRounds,
22
+ mcpBaseUrl: opts.mcpBaseUrl,
23
+ mcpToken: opts.mcpToken ?? process.env.PROMPTPILE_MCP_TOKEN,
24
+ });
25
+ }
26
+ catch (err) {
27
+ console.error(t('cli.error'), err instanceof Error ? err.message : err);
28
+ process.exitCode = 1;
29
+ }
30
+ });
31
+ }
32
+ function positive(t) {
33
+ return value => {
34
+ const n = Number(value);
35
+ if (!Number.isInteger(n) || n < 1)
36
+ throw new Error(t('cli.positiveInteger'));
37
+ return n;
38
+ };
39
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerReviseCommand = registerReviseCommand;
4
+ const revise_1 = require("../revise");
5
+ const i18n_1 = require("../i18n");
6
+ function registerReviseCommand(program, t) {
7
+ const command = program.command('revise')
8
+ .description(t('cli.revise.description'))
9
+ .requiredOption('-d, --dir <path>', t('cli.common.dir'))
10
+ .option('--proposal <path>', t('cli.revise.proposal'))
11
+ .option('--dry-run', t('cli.revise.dryRun'))
12
+ .option('--yes', t('cli.revise.yes'))
13
+ .option('--keep-session', t('cli.revise.keepSession'))
14
+ .option('--max-tool-rounds <n>', t('cli.revise.maxToolRounds'), parsePositiveInt(t), 8)
15
+ .option('--mcp-base-url <url>', t('cli.common.mcpBaseUrl'))
16
+ .option('--mcp-token <token>', t('cli.common.mcpToken'));
17
+ (0, i18n_1.addLangOption)(command, t)
18
+ .action(async (opts) => {
19
+ try {
20
+ if (!opts.proposal) {
21
+ await (0, revise_1.reviseWorldInteractive)(opts.dir, { dryRun: opts.dryRun, yes: opts.yes, keepSession: opts.keepSession, maxToolRounds: opts.maxToolRounds, mcpBaseUrl: opts.mcpBaseUrl, mcpToken: opts.mcpToken ?? process.env.PROMPTPILE_MCP_TOKEN });
22
+ return;
23
+ }
24
+ const result = (0, revise_1.reviseWorldFromProposal)(opts.dir, opts.proposal, { dryRun: opts.dryRun, yes: opts.yes });
25
+ process.stdout.write(`${result.description}\n`);
26
+ process.stdout.write(result.revisionId ? `${t('cli.revise.applied', { revisionId: result.revisionId })}\n` : `${t('cli.common.dryRunOnly')}\n`);
27
+ }
28
+ catch (err) {
29
+ console.error(t('cli.error'), err instanceof Error ? err.message : err);
30
+ process.exitCode = 1;
31
+ }
32
+ });
33
+ }
34
+ function parsePositiveInt(t) {
35
+ return value => {
36
+ const parsed = Number(value);
37
+ if (!Number.isInteger(parsed) || parsed < 1)
38
+ throw new Error(t('cli.positiveInteger'));
39
+ return parsed;
40
+ };
41
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerSettleCommand = registerSettleCommand;
4
+ const settle_1 = require("../settle");
5
+ const i18n_1 = require("../i18n");
6
+ function registerSettleCommand(program, t) {
7
+ const command = program.command('settle')
8
+ .description(t('cli.settle.description'))
9
+ .requiredOption('-d, --dir <path>', t('cli.common.dir'))
10
+ .option('--proposal <path>', t('cli.settle.proposal'))
11
+ .option('--dry-run', t('cli.settle.dryRun'))
12
+ .option('--yes', t('cli.settle.yes'))
13
+ .option('--keep-session', t('cli.settle.keepSession'))
14
+ .option('--max-tool-rounds <n>', t('cli.settle.maxToolRounds'), parsePositiveInt(t), 8)
15
+ .option('--mcp-base-url <url>', t('cli.common.mcpBaseUrl'))
16
+ .option('--mcp-token <token>', t('cli.common.mcpToken'));
17
+ (0, i18n_1.addLangOption)(command, t)
18
+ .action(async (opts) => {
19
+ try {
20
+ const common = { dryRun: opts.dryRun, yes: opts.yes };
21
+ const result = opts.proposal
22
+ ? (0, settle_1.settleFromProposal)(opts.dir, opts.proposal, common)
23
+ : await (0, settle_1.settleWithAi)(opts.dir, { ...common, keepSession: opts.keepSession, maxToolRounds: opts.maxToolRounds, mcpBaseUrl: opts.mcpBaseUrl, mcpToken: opts.mcpToken ?? process.env.PROMPTPILE_MCP_TOKEN });
24
+ process.stdout.write(`${result.description}\n`);
25
+ if (result.applied)
26
+ process.stdout.write(`${t('cli.settle.settled', { day: result.day, nextDay: result.nextDay })}\n`);
27
+ else if ('proposalPath' in result && typeof result.proposalPath === 'string')
28
+ process.stdout.write(`${t('cli.settle.generatedProposal', { proposalPath: result.proposalPath })}\n${t('cli.settle.reviewProposal')}\n`);
29
+ else
30
+ process.stdout.write(`${t('cli.common.dryRunOnly')}\n`);
31
+ }
32
+ catch (err) {
33
+ console.error(t('cli.error'), err instanceof Error ? err.message : err);
34
+ process.exitCode = 1;
35
+ }
36
+ });
37
+ }
38
+ function parsePositiveInt(t) {
39
+ return value => {
40
+ const parsed = Number(value);
41
+ if (!Number.isInteger(parsed) || parsed < 1)
42
+ throw new Error(t('cli.positiveInteger'));
43
+ return parsed;
44
+ };
45
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.describeChanges = describeChanges;
7
+ exports.applyDailyPlan = applyDailyPlan;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ function describeChanges(worldRoot, changes) {
11
+ return changes.map(change => `${fs_1.default.existsSync(path_1.default.join(worldRoot, change.relativePath)) ? 'update' : 'create'} ${change.relativePath}`).join('\n');
12
+ }
13
+ function applyDailyPlan(worldRoot, plan, changes) {
14
+ for (const change of changes) {
15
+ const filePath = path_1.default.join(worldRoot, change.relativePath);
16
+ fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
17
+ fs_1.default.writeFileSync(filePath, change.content, 'utf8');
18
+ }
19
+ appendStateChange(worldRoot, { type: 'daily_plan_created', day: plan.day, summary: plan.user_intent, beats: plan.planned_beats.map(beat => beat.id) });
20
+ }
21
+ function appendStateChange(worldRoot, entry) {
22
+ const logPath = path_1.default.join(worldRoot, 'logs', 'state_changes.jsonl');
23
+ fs_1.default.mkdirSync(path_1.default.dirname(logPath), { recursive: true });
24
+ fs_1.default.appendFileSync(logPath, `${JSON.stringify(entry)}\n`, 'utf8');
25
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPENING_ASSISTANT = exports.READONLY_MCP_TOOL_NAMES = exports.DEFAULT_MAX_TOOL_ROUNDS = void 0;
4
+ exports.DEFAULT_MAX_TOOL_ROUNDS = 8;
5
+ exports.READONLY_MCP_TOOL_NAMES = new Set([
6
+ 'mcp__world__list_allowed_directories',
7
+ 'mcp__world__list_directory',
8
+ 'mcp__world__directory_tree',
9
+ 'mcp__world__search_files',
10
+ 'mcp__world__read_text_file',
11
+ 'mcp__world__read_multiple_files',
12
+ 'mcp__world__get_file_info',
13
+ ]);
14
+ exports.OPENING_ASSISTANT = `你好,我是 dayloom 的当日计划助手。
15
+
16
+ 我只能根据主角视角已知的信息回答问题和协助制定今日计划。你可以先询问过往信息,也可以直接说明今天想做什么。每轮可输入多行内容,结束时按 Ctrl+D(macOS/Linux)或 Ctrl+Z 后 Enter(Windows)提交。你可以直接用自然语言要求查看、确认、取消或保存计划;系统会识别你的意图。`;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dailyInteractive = dailyInteractive;
4
+ const filtered_stream_output_1 = require("../shared/filtered-stream-output");
5
+ const loading_1 = require("../utils/loading");
6
+ const constants_1 = require("./constants");
7
+ const apply_plan_1 = require("./apply-plan");
8
+ const finalize_1 = require("./finalize");
9
+ const guard_1 = require("./guard");
10
+ const intent_router_1 = require("./intent-router");
11
+ const mcp_gateway_1 = require("./mcp-gateway");
12
+ const mcp_tools_1 = require("./mcp-tools");
13
+ const parse_assistant_1 = require("./parse-assistant");
14
+ const player_context_1 = require("./player-context");
15
+ const project_plan_1 = require("./project-plan");
16
+ const promptpile_loop_1 = require("./promptpile-loop");
17
+ const read_user_input_1 = require("./read-user-input");
18
+ const session_1 = require("./session");
19
+ const validate_plan_1 = require("./validate-plan");
20
+ async function dailyInteractive(dir, options = {}) {
21
+ if (!process.env.DEEPSEEK_API_KEY?.trim())
22
+ throw new Error('DEEPSEEK_API_KEY is not set. Interactive daily requires an API key.');
23
+ const worldRoot = (0, guard_1.resolveWorldRoot)(dir);
24
+ (0, guard_1.assertInitializedWorld)(worldRoot);
25
+ (0, guard_1.assertDailyCanStart)(worldRoot);
26
+ const day = (0, guard_1.readCurrentDay)(worldRoot);
27
+ const lastCommittedDay = (0, guard_1.readLastCommittedDay)(worldRoot);
28
+ const session = (0, session_1.createDailySession)();
29
+ let preserveSession = options.keepSession ?? false;
30
+ let gateway;
31
+ const maxToolRounds = options.maxToolRounds ?? constants_1.DEFAULT_MAX_TOOL_ROUNDS;
32
+ try {
33
+ await (0, loading_1.withLoading)('正在准备当日计划...', async (loading) => {
34
+ (0, player_context_1.buildPlayerContext)(worldRoot, session.playerContextRoot);
35
+ loading.update('正在启动只读服务...');
36
+ gateway = await (0, mcp_gateway_1.connectOrStartGateway)(session.root, session.playerContextRoot, options.mcpBaseUrl, options.mcpToken);
37
+ loading.update('正在准备主角上下文...');
38
+ await (0, mcp_tools_1.exportReadonlyTools)(gateway.baseUrl, gateway.token, session.toolsFile);
39
+ await (0, mcp_tools_1.assertAllowedPlayerContextRoot)(gateway.baseUrl, gateway.token, session.playerContextRoot, session.root);
40
+ });
41
+ if (!gateway)
42
+ throw new Error('Failed to initialize readonly gateway');
43
+ process.stdout.write(`\n--- Daily planning session ---\n\n${constants_1.OPENING_ASSISTANT}\n`);
44
+ while (true) {
45
+ const input = await (0, read_user_input_1.readDailyUserInput)();
46
+ if (input === undefined) {
47
+ preserveSession = true;
48
+ process.stdout.write(`Daily draft saved in session: ${session.root}\n`);
49
+ return;
50
+ }
51
+ const explicit = (0, intent_router_1.parseExplicitDailyAction)(input);
52
+ if (explicit === 'help') {
53
+ printHelp();
54
+ continue;
55
+ }
56
+ let action;
57
+ if (explicit)
58
+ action = explicit;
59
+ else {
60
+ let intent = (0, intent_router_1.fallbackDailyIntent)('Intent router was not called');
61
+ try {
62
+ intent = await (0, loading_1.withLoading)('正在识别操作...', () => (0, intent_router_1.routeDailyIntent)(input, (0, session_1.readDraft)(session), (0, session_1.getLatestAssistantText)(session.messagesDir), gateway.baseUrl, gateway.token, maxToolRounds, false));
63
+ }
64
+ catch (error) {
65
+ process.stderr.write(`Warning: daily intent router failed; treating input as a planning message: ${error instanceof Error ? error.message : error}\n`);
66
+ intent = (0, intent_router_1.fallbackDailyIntent)('Router failure');
67
+ }
68
+ action = (0, intent_router_1.effectiveDailyAction)(intent);
69
+ }
70
+ if (action === 'pending') {
71
+ process.stdout.write(`${JSON.stringify((0, session_1.readDraft)(session), null, 2)}\n`);
72
+ continue;
73
+ }
74
+ if (action === 'exit') {
75
+ preserveSession = true;
76
+ process.stdout.write(`Daily draft saved in session: ${session.root}\n`);
77
+ return;
78
+ }
79
+ if (action === 'cancel') {
80
+ if (await (0, read_user_input_1.askYesNo)('Discard the current daily draft? (Y/N): ')) {
81
+ process.stdout.write('Daily planning cancelled.\n');
82
+ return;
83
+ }
84
+ process.stdout.write('Daily planning continues.\n');
85
+ continue;
86
+ }
87
+ if (action === 'start') {
88
+ if (!explicit)
89
+ (0, session_1.appendUserMessage)(session.messagesDir, input);
90
+ const applied = await finalizeAndApplyPlan(worldRoot, day, lastCommittedDay, session, gateway.baseUrl, gateway.token, maxToolRounds, options);
91
+ if (applied)
92
+ return;
93
+ continue;
94
+ }
95
+ (0, session_1.appendUserMessage)(session.messagesDir, input);
96
+ process.stdout.write('\nAI> ');
97
+ const stream = (0, filtered_stream_output_1.createFilteredStreamOutput)({ hiddenBlocks: ['daily-status'] });
98
+ const reply = await (0, promptpile_loop_1.runPromptpileUntilText)(session, gateway.baseUrl, gateway.token, maxToolRounds, text => stream.push(text));
99
+ stream.flush();
100
+ try {
101
+ const status = (0, parse_assistant_1.parseDailyStatus)(reply);
102
+ if (status)
103
+ (0, session_1.writeDraft)(session, status);
104
+ }
105
+ catch (error) {
106
+ process.stderr.write(`Warning: ${error instanceof Error ? error.message : error}\n`);
107
+ }
108
+ process.stdout.write('\n');
109
+ }
110
+ }
111
+ finally {
112
+ if (gateway)
113
+ await gateway.stop();
114
+ if (preserveSession)
115
+ process.stderr.write(`Daily session preserved at: ${session.root}\n`);
116
+ else
117
+ (0, session_1.cleanupSession)(session);
118
+ }
119
+ }
120
+ async function finalizeAndApplyPlan(worldRoot, day, lastCommittedDay, session, baseUrl, token, maxToolRounds, options) {
121
+ const draft = (0, session_1.readDraft)(session);
122
+ if (!draft.user_intent.trim()) {
123
+ process.stdout.write('No daily intent collected yet.\n');
124
+ return false;
125
+ }
126
+ const transcript = (0, session_1.buildTranscript)(session.messagesDir);
127
+ const plan = await (0, loading_1.withLoading)('正在生成正式计划...', () => (0, finalize_1.finalizeDailyPlan)(transcript, draft, day, session.toolsFile, baseUrl, token, maxToolRounds, options.keepSession));
128
+ (0, validate_plan_1.validateDailyPlan)(plan, day);
129
+ const changes = (0, project_plan_1.projectDailyPlan)(plan, transcript, lastCommittedDay);
130
+ const description = (0, apply_plan_1.describeChanges)(worldRoot, changes);
131
+ process.stdout.write(`\n${description}\n`);
132
+ if (options.dryRun) {
133
+ process.stdout.write('Dry run only. No files changed.\n');
134
+ return false;
135
+ }
136
+ if (!options.yes && !await (0, read_user_input_1.askYesNo)(`Generate and apply the ${day} plan? (Y/N): `)) {
137
+ process.stdout.write('Daily plan not applied.\n');
138
+ return false;
139
+ }
140
+ (0, guard_1.assertDailyCanStart)(worldRoot);
141
+ (0, apply_plan_1.applyDailyPlan)(worldRoot, plan, changes);
142
+ process.stdout.write('Applied daily plan.\n');
143
+ return true;
144
+ }
145
+ function printHelp() {
146
+ process.stdout.write('Use natural language to discuss, inspect, confirm, cancel, or save the plan. Commands remain available: /pending /start /cancel /exit\n');
147
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.finalizeDailyPlan = finalizeDailyPlan;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const parse_assistant_1 = require("./parse-assistant");
9
+ const promptpile_loop_1 = require("./promptpile-loop");
10
+ const session_1 = require("./session");
11
+ async function finalizeDailyPlan(transcript, draft, day, toolsFile, baseUrl, token, maxToolRounds, keepSession = false) {
12
+ const session = (0, session_1.createFinalizeSession)(transcript, draft, day);
13
+ fs_1.default.copyFileSync(toolsFile, session.toolsFile);
14
+ try {
15
+ return (0, parse_assistant_1.parseDailyPlan)(await (0, promptpile_loop_1.runPromptpileUntilText)(session, baseUrl, token, maxToolRounds));
16
+ }
17
+ finally {
18
+ if (keepSession)
19
+ process.stderr.write(`Daily finalize session preserved at: ${session.root}\n`);
20
+ else
21
+ (0, session_1.cleanupSession)(session);
22
+ }
23
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveWorldRoot = resolveWorldRoot;
7
+ exports.assertInitializedWorld = assertInitializedWorld;
8
+ exports.readCurrentDay = readCurrentDay;
9
+ exports.readLastCommittedDay = readLastCommittedDay;
10
+ exports.readCurrentPhase = readCurrentPhase;
11
+ exports.assertDailyCanStart = assertDailyCanStart;
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const path_1 = __importDefault(require("path"));
14
+ function resolveWorldRoot(dir) { return path_1.default.resolve(dir); }
15
+ function assertInitializedWorld(worldRoot) {
16
+ if (!fs_1.default.existsSync(path_1.default.join(worldRoot, 'manifest.yaml')))
17
+ throw new Error(`World save is not initialized: ${worldRoot}`);
18
+ }
19
+ function readCurrentDay(worldRoot) {
20
+ const current = readCurrentYaml(worldRoot);
21
+ const match = current.match(/^day:\s*(\S+)\s*$/m);
22
+ if (!match)
23
+ throw new Error('current.yaml missing day');
24
+ return match[1];
25
+ }
26
+ function readLastCommittedDay(worldRoot) {
27
+ const current = readCurrentYaml(worldRoot);
28
+ const match = current.match(/^last_committed_day:\s*(\S+)\s*$/m);
29
+ if (!match)
30
+ throw new Error('current.yaml missing last_committed_day');
31
+ return match[1];
32
+ }
33
+ function readCurrentPhase(worldRoot) {
34
+ const current = readCurrentYaml(worldRoot);
35
+ const match = current.match(/^phase:\s*(\S+)\s*$/m);
36
+ if (!match)
37
+ throw new Error('current.yaml missing phase');
38
+ return match[1];
39
+ }
40
+ function assertDailyCanStart(worldRoot) {
41
+ const phase = readCurrentPhase(worldRoot);
42
+ if (phase !== 'idle')
43
+ throw new Error(`Daily planning requires current phase idle, got: ${phase}`);
44
+ const day = readCurrentDay(worldRoot);
45
+ const dayRoot = path_1.default.join(worldRoot, 'days', day);
46
+ if (fs_1.default.existsSync(dayRoot) && fs_1.default.readdirSync(dayRoot).length > 0)
47
+ throw new Error(`Daily directory already exists and is not empty: days/${day}`);
48
+ }
49
+ function readCurrentYaml(worldRoot) {
50
+ const filePath = path_1.default.join(worldRoot, 'current.yaml');
51
+ if (!fs_1.default.existsSync(filePath))
52
+ throw new Error('World save missing current.yaml');
53
+ return fs_1.default.readFileSync(filePath, 'utf8');
54
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dailyInteractive = void 0;
4
+ exports.dailyFromProposal = dailyFromProposal;
5
+ const apply_plan_1 = require("./apply-plan");
6
+ const guard_1 = require("./guard");
7
+ const parse_payload_1 = require("./parse-payload");
8
+ const project_plan_1 = require("./project-plan");
9
+ const validate_plan_1 = require("./validate-plan");
10
+ function dailyFromProposal(dir, proposalPath, options = {}) {
11
+ const worldRoot = (0, guard_1.resolveWorldRoot)(dir);
12
+ (0, guard_1.assertInitializedWorld)(worldRoot);
13
+ (0, guard_1.assertDailyCanStart)(worldRoot);
14
+ const day = (0, guard_1.readCurrentDay)(worldRoot);
15
+ const plan = (0, parse_payload_1.readDailyPlan)(proposalPath);
16
+ (0, validate_plan_1.validateDailyPlan)(plan, day);
17
+ const changes = (0, project_plan_1.projectDailyPlan)(plan, undefined, (0, guard_1.readLastCommittedDay)(worldRoot));
18
+ const description = (0, apply_plan_1.describeChanges)(worldRoot, changes);
19
+ if (options.dryRun)
20
+ return { worldRoot, description, applied: false };
21
+ if (!options.yes)
22
+ throw new Error('Applying a daily plan requires --yes. Use --dry-run to inspect changes.');
23
+ (0, apply_plan_1.applyDailyPlan)(worldRoot, plan, changes);
24
+ return { worldRoot, description, applied: true };
25
+ }
26
+ var dialogue_loop_1 = require("./dialogue-loop");
27
+ Object.defineProperty(exports, "dailyInteractive", { enumerable: true, get: function () { return dialogue_loop_1.dailyInteractive; } });