cortico 0.1.0 → 0.1.1

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 (63) hide show
  1. package/README.md +4 -11
  2. package/package.json +1 -3
  3. package/src/bot.ts +1 -1
  4. package/src/core/README.md +0 -4
  5. package/src/core/types.ts +1 -1
  6. package/src/core/util.ts +2 -1
  7. package/src/deploy.ts +8 -6
  8. package/src/providers/README.md +4 -5
  9. package/src/providers/base.ts +1 -1
  10. package/src/providers/configuration.ts +2 -1
  11. package/src/providers/console/settings.ts +8 -10
  12. package/src/providers/llamacpp/console/runtime-panel.ts +73 -32
  13. package/src/providers/llamacpp/console/server.ts +1 -20
  14. package/src/providers/llamacpp/index.ts +0 -2
  15. package/src/providers/llamacpp/options.ts +0 -2
  16. package/src/providers/llamacpp/strings.ts +6 -6
  17. package/src/providers/openai-responses-compat/index.ts +0 -3
  18. package/src/web/README.md +1 -5
  19. package/src/web/client/console-pages/builtins/llm-settings/panel.ts +35 -41
  20. package/src/web/client/console-pages/builtins/llm-settings/strings.ts +4 -4
  21. package/src/web/client/console-pages/host.ts +2 -2
  22. package/src/web/client/features/core/strings.ts +2 -2
  23. package/src/web/client/features/feature.ts +1 -1
  24. package/src/web/client/features/live/index.ts +8 -1
  25. package/src/web/client/features/live/onboarding.ts +4 -1
  26. package/src/web/client/features/live/strings.ts +11 -11
  27. package/src/web/client/features/live/timeline.ts +2 -1
  28. package/src/web/client/features/settings/general.ts +1 -0
  29. package/src/web/client/features/settings/index.ts +1 -0
  30. package/src/web/client/features/worlds/index.ts +1 -0
  31. package/src/web/client/shell/index.ts +27 -47
  32. package/src/web/client/shell/strings.ts +0 -22
  33. package/src/web/client/ui/icons.ts +5 -0
  34. package/src/web/console-pages.ts +1 -1
  35. package/src/web/public/styles.css +21 -8
  36. package/src/web/server.ts +11 -3
  37. package/src/web/shared/client-panel.ts +1 -1
  38. package/src/web/shared/console-protocol.ts +2 -1
  39. package/src/worlds/minecraft/README.md +61 -11
  40. package/src/worlds/minecraft/cell-facts.ts +226 -0
  41. package/src/worlds/minecraft/chests.ts +5 -0
  42. package/src/worlds/minecraft/containers.ts +325 -0
  43. package/src/worlds/minecraft/entity-facts.ts +31 -5
  44. package/src/worlds/minecraft/executor.ts +283 -10348
  45. package/src/worlds/minecraft/inventory.ts +268 -0
  46. package/src/worlds/minecraft/melee.ts +419 -0
  47. package/src/worlds/minecraft/placed-ledger.ts +152 -0
  48. package/src/worlds/minecraft/placement.ts +1038 -0
  49. package/src/worlds/minecraft/receipt.ts +340 -0
  50. package/src/worlds/minecraft/skill-context.ts +358 -0
  51. package/src/worlds/minecraft/skills-build.ts +1169 -0
  52. package/src/worlds/minecraft/skills-container.ts +1343 -0
  53. package/src/worlds/minecraft/skills-craft.ts +333 -0
  54. package/src/worlds/minecraft/skills-dig.ts +624 -0
  55. package/src/worlds/minecraft/skills-gather.ts +1230 -0
  56. package/src/worlds/minecraft/skills-interact.ts +1559 -0
  57. package/src/worlds/minecraft/tools.ts +331 -0
  58. package/src/worlds/minecraft/travel.ts +763 -0
  59. package/src/worlds/minecraft/until.ts +75 -0
  60. package/src/worlds/terminal/world.ts +8 -5
  61. package/src/providers/console/config.ts +0 -21
  62. package/src/providers/llamacpp/config.ts +0 -36
  63. package/src/providers/openai-responses-compat/config.ts +0 -20
@@ -0,0 +1,152 @@
1
+ /**
2
+ * 挂在 bot 实例上的几本小账:这一场放过哪些格、锄过哪几格、放了三次还没上去的那些格。
3
+ *
4
+ * 跟着连接走,换实例即清;跨任务跨场次的成果登记在 works.ts。
5
+ */
6
+ import type { Bot } from 'mineflayer';
7
+ import { type SkillCall } from './skills.ts';
8
+ import { type SkillContext } from './skill-context.ts';
9
+ import { type Cell } from './geometry.ts';
10
+ import { blockAtCell, cellKeyOf, dimensionOf } from './cell-facts.ts';
11
+ import { HOE_TILLED } from './blueprint-registry.ts';
12
+ import { zhName } from './names.ts';
13
+ import { FURNACE_BLOCKS } from './chests.ts';
14
+
15
+ /** 这些技能的放置整段是本意,回执自己会说;其余步骤里的放置都是寻路垫脚/搭路 */
16
+ export const INTENTIONAL_PLACERS = new Set<SkillCall['skill']>(['craft', 'use']);
17
+
18
+ export function placedLedgerOf(bot: Bot): Array<{ name: string; x: number; y: number; z: number }> {
19
+ const b = bot as unknown as { placedLedger?: Array<{ name: string; x: number; y: number; z: number }> };
20
+ return (b.placedLedger ??= []);
21
+ }
22
+
23
+ /**
24
+ * 这一场锄成过耕地的那些格(内存,换 bot 实例即清)。
25
+ *
26
+ * 同一格再锄一次成功 = 那块耕地已经被踩回泥土:站在耕地上跳一下 60% 踩坏,
27
+ * 落差 ≥2 格必坏。它是「反复重锄」的成因,不是掉墒。
28
+ */
29
+ export function tilledOf(bot: Bot): Set<string> {
30
+ const b = bot as unknown as { tilledCells?: Set<string> };
31
+ return (b.tilledCells ??= new Set<string>());
32
+ }
33
+
34
+ /**
35
+ * 一次成功的右键落进成果登记:锄成的耕地记这一格,种下的作物记它上面那一格
36
+ * (作物长在耕地上面,不在被点的那一格)。别的右键不进登记。
37
+ */
38
+ export function noteWork(bot: Bot, ctx: SkillContext, item: string | null, cell: Cell, target: string): void {
39
+ if (!ctx.works || item === null) return;
40
+ const dim = dimensionOf(bot);
41
+ if (item.endsWith('_hoe') && HOE_TILLED[target] === 'farmland') {
42
+ ctx.works.note(dim, cell.x, cell.y, cell.z, { kind: 'farmland', block: 'farmland', site: null });
43
+ return;
44
+ }
45
+ const crop = SEED_CROP[item] ?? (item === 'nether_wart' ? 'nether_wart' : undefined);
46
+ if (crop !== undefined) {
47
+ ctx.works.note(dim, cell.x, cell.y + 1, cell.z, { kind: 'crop', block: crop, site: null });
48
+ }
49
+ }
50
+
51
+ /** 这一场上次真吃进去的时刻(内存,换 bot 实例即清);`[口粮]` 那行的四个数之一 */
52
+ export function lastAteOf(bot: Bot): number | null {
53
+ return (bot as unknown as { lastAteAt?: number }).lastAteAt ?? null;
54
+ }
55
+
56
+ export function noteAte(bot: Bot): void {
57
+ (bot as unknown as { lastAteAt?: number }).lastAteAt = Date.now();
58
+ }
59
+
60
+ /** 记下这一格锄成了耕地;记过一次的补一句事实,不拦 */
61
+ export function noteTilled(bot: Bot, cell: Cell): string {
62
+ const key = `${dimensionOf(bot)}:${cellKeyOf(cell)}`;
63
+ const seen = tilledOf(bot);
64
+ if (!seen.has(key)) {
65
+ seen.add(key);
66
+ return '';
67
+ }
68
+ return ';这格之前翻过,是被踩回泥土的;种上作物或别在上面跳';
69
+ }
70
+
71
+ /** 放了三次回读还是老样子的那些格(mineflayer-fixes 记的另一半台账) */
72
+ export function placeMissesOf(bot: Bot): Array<{ was: string; x: number; y: number; z: number }> {
73
+ const b = bot as unknown as { placeMisses?: Array<{ was: string; x: number; y: number; z: number }> };
74
+ return (b.placeMisses ??= []);
75
+ }
76
+
77
+ /** 一步开工时两本台账各记到哪一条:回执报的是这一步之内的那一段 */
78
+ export interface PlaceMarks { placed: number; missed: number }
79
+
80
+ export function placeMarksOf(bot: Bot): PlaceMarks {
81
+ return { placed: placedLedgerOf(bot).length, missed: placeMissesOf(bot).length };
82
+ }
83
+
84
+ /** 从寻路耗材台账摘除技能有意放置的格,由该技能回报;同一步的其他垫脚仍记耗材。 */
85
+ export function forgetPlaced(bot: Bot, at: { x: number; y: number; z: number }): void {
86
+ const ledger = placedLedgerOf(bot);
87
+ for (let i = ledger.length - 1; i >= 0; i--) {
88
+ if (ledger[i].x === at.x && ledger[i].y === at.y && ledger[i].z === at.z) {
89
+ ledger.splice(i, 1);
90
+ return;
91
+ }
92
+ }
93
+ }
94
+
95
+ /**
96
+ * 回报寻路垫脚的成功与未确认放置;服务端拒绝放置时客户端仍可能扣物品。
97
+ * 成功项按 INTENTIONAL_PLACERS 与 intended 豁免,未确认项只豁免逐格回报的 build。
98
+ * 寻路承重失败另由 pathSupportFailure 裁决。
99
+ */
100
+ export function placedNote(
101
+ bot: Bot, mark: PlaceMarks, skill: SkillCall['skill'], intended: ReadonlySet<string>,
102
+ ): string {
103
+ const placed = INTENTIONAL_PLACERS.has(skill)
104
+ ? []
105
+ : placedLedgerOf(bot).slice(mark.placed).filter((p) => !intended.has(cellKeyOf(p)));
106
+ const missed = skill === 'build' ? [] : placeMissesOf(bot).slice(mark.missed);
107
+ let out = '';
108
+ if (placed.length > 0) {
109
+ const byName = new Map<string, number>();
110
+ for (const p of placed) byName.set(p.name, (byName.get(p.name) ?? 0) + 1);
111
+ const last = placed[placed.length - 1];
112
+ out += `;路上垫脚/搭路用掉了 ${[...byName].map(([n, c]) => `${zhName(n)}×${c}`).join('、')}` +
113
+ `(最后一块在 (${last.x}, ${last.y}, ${last.z}))`;
114
+ }
115
+ if (missed.length > 0) {
116
+ const last = missed[missed.length - 1];
117
+ out += `;路上还有 ${missed.length} 次放置服务端没认` +
118
+ `(最后一次在 (${last.x}, ${last.y}, ${last.z}),那一格还是${zhName(last.was)})`;
119
+ }
120
+ return out;
121
+ }
122
+
123
+ /** 这一格是不是账本上还记着有东西的容器;是就给出一句点名现场事实(tunnel 停步用) */
124
+ export function ledgerBlockFact(bot: Bot, ctx: SkillContext, c: Cell): string | null {
125
+ const rec = ctx.chests?.get(dimensionOf(bot), c);
126
+ if (!rec || rec.items.length === 0) return null;
127
+ const b = blockAtCell(bot, c);
128
+ if (!b || !LEDGER_GUARD_BLOCKS.has(b.name)) return null;
129
+ const inside = rec.items.slice(0, 3).map((i) => `${zhName(i.name)}×${i.count}`).join('、');
130
+ return `(${c.x}, ${c.y}, ${c.z}) 的${zhName(b.name)}(账本记着里头有 ${inside})`;
131
+ }
132
+
133
+ /**
134
+ * 种子种下去长出来的是哪种作物。**作物在耕地上面那一格**,不在被点的那一格。
135
+ * (把握:前六种确定;torchflower_seeds/pitcher_pod 比较确定。)
136
+ */
137
+ export const SEED_CROP: Record<string, string> = {
138
+ wheat_seeds: 'wheat',
139
+ beetroot_seeds: 'beetroots',
140
+ carrot: 'carrots',
141
+ potato: 'potatoes',
142
+ melon_seeds: 'melon_stem',
143
+ pumpkin_seeds: 'pumpkin_stem',
144
+ torchflower_seeds: 'torchflower_crop',
145
+ pitcher_pod: 'pitcher_crop',
146
+ };
147
+
148
+ /** 账本保护容器:excavate 跳过,tunnel 停步回报;拆除前先取空内容再 collect 点名。 */
149
+ export const LEDGER_GUARD_BLOCKS = new Set<string>([
150
+ ...FURNACE_BLOCKS, 'chest', 'trapped_chest', 'barrel', 'ender_chest', 'crafting_table',
151
+ ]);
152
+