paseo-office 0.2.0 → 0.2.2
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/OVERVIEW.md +27 -0
- package/README.md +65 -134
- package/client/action-button.tsx +4 -1
- package/client/activity-panel.tsx +6 -4
- package/client/agent-appearance.tsx +257 -0
- package/client/agent-card.tsx +2 -1
- package/client/agent-picker-text.ts +23 -4
- package/client/agent-picker.tsx +5 -8
- package/client/board-sheet.tsx +48 -16
- package/client/board-text.ts +12 -2
- package/client/brand.ts +1 -0
- package/client/chat-chrome.tsx +318 -0
- package/client/chat-compose-tools.tsx +314 -0
- package/client/chat-dictation.tsx +133 -0
- package/client/chat-more.tsx +119 -0
- package/client/chat-panel.tsx +401 -146
- package/client/chat-quick.tsx +198 -0
- package/client/chat-text.ts +25 -6
- package/client/column-sheet.tsx +93 -23
- package/client/conversation-model.ts +19 -5
- package/client/duty-sheet.tsx +321 -0
- package/client/duty-text.ts +20 -0
- package/client/fullscreen-header.tsx +28 -13
- package/client/fullscreen-theme.ts +38 -0
- package/client/host-details.tsx +269 -0
- package/client/host-styles.ts +129 -0
- package/client/host-switches.tsx +212 -83
- package/client/incidents-card.tsx +2 -1
- package/client/janitor-card.tsx +1 -1
- package/client/library-card.tsx +2 -1
- package/client/list-text.ts +8 -6
- package/client/lobby-board.tsx +73 -53
- package/client/machine-card.tsx +225 -85
- package/client/messenger-styles.ts +216 -0
- package/client/new-agent-form.tsx +153 -61
- package/client/new-agent-model.ts +2 -0
- package/client/notes-card.tsx +111 -83
- package/client/notes-days.tsx +1 -1
- package/client/office-brand-context.ts +44 -0
- package/client/office-column.tsx +2 -1
- package/client/office-keyboard.ts +79 -0
- package/client/office-link.ts +7 -1
- package/client/office-mark.tsx +29 -0
- package/client/office-modal.tsx +440 -0
- package/client/office-settings.tsx +75 -30
- package/client/office-state.ts +12 -2
- package/client/office-surface.tsx +591 -81
- package/client/pixel/actors.ts +2 -1
- package/client/pixel/art.ts +33 -19
- package/client/pixel/pixel-office.tsx +2 -2
- package/client/prompt-coach.tsx +152 -0
- package/client/qa-card.tsx +2 -1
- package/client/review-card.tsx +2 -1
- package/client/room-board.tsx +26 -2
- package/client/scene-picker.tsx +158 -0
- package/client/scene-previews.ts +10 -0
- package/client/session-pane.tsx +25 -5
- package/client/session-panel-detail.tsx +238 -0
- package/client/session-panel.tsx +222 -137
- package/client/session-styles.ts +224 -1
- package/client/session-transcript.tsx +243 -0
- package/client/sessions-panel.tsx +181 -22
- package/client/sessions-text.ts +18 -0
- package/client/settings-sections.tsx +126 -0
- package/client/sidebar-launcher.ts +29 -0
- package/client/ssh-hosts.tsx +331 -0
- package/client/ssh-metrics.ts +76 -0
- package/client/standup-card.tsx +2 -1
- package/client/structure-view.tsx +20 -3
- package/client/styles.ts +170 -62
- package/client/team-chat-preview.tsx +96 -0
- package/client/tracker-connections.tsx +252 -0
- package/client/transcript-styles.ts +90 -0
- package/client/use-device-switch.ts +21 -12
- package/client/use-duty-actions.ts +43 -0
- package/client/use-group-photo.ts +48 -0
- package/client/use-new-agent.ts +4 -0
- package/client/use-street.ts +8 -0
- package/client/workspace-office-tools.tsx +102 -0
- package/client/workspace-overlay-route.web.ts +47 -0
- package/client/workspace-overlay.tsx +195 -0
- package/client/world/adapter.ts +37 -2
- package/client/world/escape.ts +58 -0
- package/client/world/use-world-feed.ts +6 -2
- package/client/world/workspace-dock.ts +6 -0
- package/client/world/world-api.ts +45 -4
- package/client/world/world-bridge-page.ts +14 -3
- package/client/world/world-bridge.ts +50 -5
- package/client/world/world-frame.web.ts +8 -0
- package/client/world/world-view-native.tsx +31 -10
- package/client/world/world-view-shared.ts +36 -7
- package/client/world/world-view.tsx +93 -21
- package/docs/office.md +165 -64
- package/index.client.tsx +13 -6
- package/index.server.ts +232 -16
- package/package.json +2 -1
- package/server/activity.ts +42 -19
- package/server/agent-tools.ts +11 -5
- package/server/board-service.ts +381 -10
- package/server/brand-logo.ts +34 -0
- package/server/chat-group.ts +83 -0
- package/server/chat-service.ts +406 -62
- package/server/chat-store.ts +1 -4
- package/server/directory.ts +22 -7
- package/server/duty-service.ts +230 -0
- package/server/group-photo.ts +39 -0
- package/server/home-departure.ts +47 -0
- package/server/hub.ts +43 -1
- package/server/incidents-jira.ts +19 -7
- package/server/incidents-schedule.ts +10 -10
- package/server/incidents-sentry.ts +34 -8
- package/server/live-ports.ts +114 -18
- package/server/lobby-pickup.ts +170 -0
- package/server/machine/details.ts +91 -0
- package/server/mention-queue.ts +14 -0
- package/server/office.ts +110 -6
- package/server/paths.ts +14 -0
- package/server/ssh/LICENSE.paseo +211 -0
- package/server/ssh/client.ts +401 -0
- package/server/ssh/discovery.ts +230 -0
- package/server/ssh/installed.ts +104 -0
- package/server/ssh/monitor.ts +104 -0
- package/server/ssh/pid-files.ts +194 -0
- package/server/ssh/read.ts +136 -0
- package/server/subagent-names.ts +4 -0
- package/server/tracker-credentials.ts +141 -0
- package/server/words.generated.ts +1 -1
- package/server/world.generated.ts +1 -1
- package/shared/appearance.ts +43 -0
- package/shared/branding.ts +53 -0
- package/shared/chat-words.ts +2 -2
- package/shared/contracts.ts +199 -5
- package/shared/duties.ts +100 -0
- package/shared/host-details.ts +25 -0
- package/shared/lobby-assignment.ts +34 -0
- package/shared/model.ts +9 -1
- package/shared/names.ts +2 -0
- package/shared/settings.ts +14 -3
- package/shared/ssh.ts +34 -0
- package/shared/upstream/README.md +1 -3
- package/shared/upstream/chat-engine.d.ts +4 -0
- package/shared/upstream/prompt-coach.d.ts +6 -0
- package/shared/upstream/prompt-coach.js +178 -0
package/shared/names.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
/** The host-wide board. Every other board id is a workspace id. */
|
|
5
5
|
export const LOBBY = "lobby";
|
|
6
|
+
/** The host-wide board of the day's duties, posted from the duty list. */
|
|
7
|
+
export const DUTY = "duty";
|
|
6
8
|
/** The author of a post the user made in the office. */
|
|
7
9
|
export const USER_AUTHOR = "user";
|
|
8
10
|
|
package/shared/settings.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { brandFields } from "./branding.js";
|
|
1
2
|
import { LANGUAGE_CHOICES } from "./scene-language.js";
|
|
2
3
|
import { defineSettings } from "@getpaseo/plugin";
|
|
3
4
|
import { WEATHER_MODES, MANUAL_CHOICES } from "./weather.js";
|
|
@@ -46,6 +47,8 @@ export const FLOOR_PLANS = ["pro", "cozy", "hq"] as const;
|
|
|
46
47
|
export type FloorPlanChoice = (typeof FLOOR_PLANS)[number];
|
|
47
48
|
|
|
48
49
|
const HostValuesSchema = z.object({
|
|
50
|
+
...brandFields,
|
|
51
|
+
archiveOnDeparture: z.boolean().default(false),
|
|
49
52
|
agentTools: z.boolean().default(true),
|
|
50
53
|
notesFolder: z.string().default(""),
|
|
51
54
|
notesTimeZone: z.string().default(""),
|
|
@@ -123,7 +126,7 @@ const SUNDAY_TO_THURSDAY = [0, 1, 2, 3, 4];
|
|
|
123
126
|
export const officeHostSettings = defineSettings({
|
|
124
127
|
id: "office",
|
|
125
128
|
scope: "host",
|
|
126
|
-
version:
|
|
129
|
+
version: 6,
|
|
127
130
|
schema: HostValuesSchema.superRefine(refuseBadTrackerValues)
|
|
128
131
|
.superRefine(refuseBadDays)
|
|
129
132
|
.superRefine(({ weatherUrl }, ctx) => {
|
|
@@ -144,7 +147,13 @@ export const officeHostSettings = defineSettings({
|
|
|
144
147
|
: values,
|
|
145
148
|
});
|
|
146
149
|
|
|
147
|
-
/**
|
|
150
|
+
/** Outdoor environments for the 3D floor. */
|
|
151
|
+
export const OFFICE_SCENES = ["plain", "city", "countryside", "beach"] as const;
|
|
152
|
+
export type OfficeScene = (typeof OFFICE_SCENES)[number];
|
|
153
|
+
export const OFFICE_LIGHTING = ["auto", "day", "night"] as const;
|
|
154
|
+
export type OfficeLighting = (typeof OFFICE_LIGHTING)[number];
|
|
155
|
+
|
|
156
|
+
/** The 3D floor, the 2D pixel floor and the list. */
|
|
148
157
|
export const OFFICE_VIEWS = ["3d", "2d", "list"] as const;
|
|
149
158
|
export type OfficeViewChoice = (typeof OFFICE_VIEWS)[number];
|
|
150
159
|
|
|
@@ -152,7 +161,7 @@ export type OfficeViewChoice = (typeof OFFICE_VIEWS)[number];
|
|
|
152
161
|
* Per device. `view` is the view somebody chose. A device that never chose has only `threeD`,
|
|
153
162
|
* from when the office had a 3D switch: off is the list, on leaves the choice to the device. A
|
|
154
163
|
* save writes both. A client from before version 2 reads neither: it refuses the newer version.
|
|
155
|
-
*
|
|
164
|
+
* Earlier devices chose City or Plain with `street`. An explicit `scene` takes precedence.
|
|
156
165
|
* `rungIncidents` is when this device rang its alarm for each incident, epoch ms by incident id.
|
|
157
166
|
* `lastAgent` is the provider and model of the last agent started from the office, the next
|
|
158
167
|
* form's start. Every save of this setting writes the document whole and carries it through.
|
|
@@ -164,6 +173,8 @@ export const officeDeviceSettings = defineSettings({
|
|
|
164
173
|
schema: z.object({
|
|
165
174
|
threeD: z.boolean().default(true),
|
|
166
175
|
street: z.boolean().optional(),
|
|
176
|
+
scene: z.enum(OFFICE_SCENES).optional(),
|
|
177
|
+
lighting: z.enum(OFFICE_LIGHTING).optional(),
|
|
167
178
|
sessionsHidden: z.boolean().optional(),
|
|
168
179
|
view: z.enum(OFFICE_VIEWS).optional(),
|
|
169
180
|
rungIncidents: z.record(z.string(), z.number()).default({}),
|
package/shared/ssh.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
const host = z.object({
|
|
5
|
+
name: z.string(),
|
|
6
|
+
reachable: z.boolean(),
|
|
7
|
+
memoryUsedBytes: z.number().nullable(),
|
|
8
|
+
memoryTotalBytes: z.number().nullable(),
|
|
9
|
+
load1: z.number().nullable(),
|
|
10
|
+
load5: z.number().nullable(),
|
|
11
|
+
load15: z.number().nullable(),
|
|
12
|
+
cores: z.number().nullable(),
|
|
13
|
+
diskMount: z.string().nullable(),
|
|
14
|
+
diskUsedBytes: z.number().nullable(),
|
|
15
|
+
diskTotalBytes: z.number().nullable(),
|
|
16
|
+
});
|
|
17
|
+
const reading = z.object({ status: z.enum(["ok", "unavailable"]), hosts: z.array(host) });
|
|
18
|
+
const servers = z.object({
|
|
19
|
+
servers: z.array(z.object({ id: z.string(), name: z.string() })),
|
|
20
|
+
discoveryIncomplete: z.boolean(),
|
|
21
|
+
});
|
|
22
|
+
export type SshHost = z.output<typeof host>;
|
|
23
|
+
export type SshReading = z.output<typeof reading>;
|
|
24
|
+
export type SshDiscovery = z.output<typeof servers>;
|
|
25
|
+
export const sshServersRpc = defineRpc({
|
|
26
|
+
name: "office.ssh.servers",
|
|
27
|
+
input: z.strictObject({}),
|
|
28
|
+
output: servers,
|
|
29
|
+
});
|
|
30
|
+
export const sshReadingRpc = defineRpc({
|
|
31
|
+
name: "office.ssh.reading",
|
|
32
|
+
input: z.strictObject({ id: z.string().regex(/^[0-9a-f]{16}$/) }),
|
|
33
|
+
output: reading,
|
|
34
|
+
});
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
([vendor/my-office/LICENSE](../../vendor/my-office/LICENSE)). The two `.d.ts` files beside them are
|
|
3
|
-
this plugin's. [vendor/SOURCES.md](../../vendor/SOURCES.md) says how they are taken.
|
|
1
|
+
The team chat engine, prompt coach and English chat strings come from my-office under its [MIT licence](../../vendor/my-office/LICENSE). The adjacent `.d.ts` files describe the APIs the plugin uses. [Import details](../../vendor/SOURCES.md)
|
|
@@ -79,7 +79,11 @@ export interface ChatEngine {
|
|
|
79
79
|
system(text: string): EngineMessage;
|
|
80
80
|
send(input: { text?: string; sticker?: number | null; replyTo?: string | null }): void;
|
|
81
81
|
working(from: string, on: boolean): void;
|
|
82
|
+
fresh(key: string): boolean;
|
|
83
|
+
photo(dataUrl: string): void;
|
|
82
84
|
react(id: string, by: string, emoji: string): void;
|
|
85
|
+
poll(from: string, question: string, options: string[]): void;
|
|
86
|
+
pin(id: string, byName: string): void;
|
|
83
87
|
vote(id: string, by: string, index: number): void;
|
|
84
88
|
rsvp(id: string, by: string, yes: boolean): void;
|
|
85
89
|
recall(id: string): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type PromptHint =
|
|
2
|
+
| { id: "photoBare" | "tooShort" }
|
|
3
|
+
| { id: "dangling" | "vague"; phrase: string }
|
|
4
|
+
| { id: "multi"; n: number };
|
|
5
|
+
export function coach(input: { text: string; photos: number; quoted: boolean }): PromptHint[];
|
|
6
|
+
export function numberTasks(text: string): string;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// The prompt helper ("Trợ lý soạn prompt") of the group chat (ui/group-chat-view.js): what you are about to send Claude,
|
|
2
|
+
// looked at here, in the page, for what would cost a round trip. Nothing leaves the page and nothing is ever blocked:
|
|
3
|
+
// it only says so, one hint at a time. The rules come from 2,441 of the owner's own prompts: half were under 40
|
|
4
|
+
// characters, nearly half carried screenshots, and the ones that went back and forth were a screenshot with one to
|
|
5
|
+
// three words ("sao", "điền sao", "config gì"), a quality word with no criterion ("khác đi", "hay hơn", "đừng làm qua
|
|
6
|
+
// loa"), a reference to a number or "cái này" with nothing to point at ("4 đâu có xem giải thích gì đâu", "phần của
|
|
7
|
+
// vĩ"), and several jobs in one message ("gợi ý thêm… trước đó push lên github"). Vietnamese with or without its
|
|
8
|
+
// diacritics (and the shorthand typed for speed: j, ko, dc, r, z), and English.
|
|
9
|
+
|
|
10
|
+
/* ---------- words: a token matches a word when they are the same, or when it was typed without diacritics and is the
|
|
11
|
+
same letters ("khac di" is "khác đi", but "đến" is never "đen"); a run of one letter counts once ("hơnnn") ---------- */
|
|
12
|
+
const plain = (s) => s.normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/đ/g, 'd');
|
|
13
|
+
const squeeze = (s) => s.replace(/(\p{L})\1+/gu, '$1');
|
|
14
|
+
const keyOf = (w) => squeeze(w.normalize('NFC').toLowerCase());
|
|
15
|
+
const same = (tok, word) => tok.k === word || (tok.bare && tok.p === plain(word));
|
|
16
|
+
// shorthand, read as the words it stands for
|
|
17
|
+
const SHORT = { j: 'gì', z: 'vậy', dz: 'vậy', ko: 'không', k: 'không', hok: 'không', khum: 'không', kh: 'không', dc: 'được', đc: 'được', r: 'rồi', s: 'sao', vs: 'với',
|
|
18
|
+
ntn: 'như thế nào', bt: 'biết', cx: 'cũng', ms: 'mới', mn: 'mọi người', nài: 'này', nì: 'này', kái: 'cái', đy: 'đi', dy: 'đi', oke: 'ok', okie: 'ok', okay: 'ok', okela: 'ok', pls: 'please', plz: 'please' };
|
|
19
|
+
|
|
20
|
+
/** text -> [{ k: its key, p: without diacritics, bare: typed without them, at, end: where it is in the text }] */
|
|
21
|
+
export function tokens(text) {
|
|
22
|
+
const out = [];
|
|
23
|
+
for (const m of String(text || '').normalize('NFC').matchAll(/[\p{L}\p{M}\p{N}]+/gu)) {
|
|
24
|
+
const k = keyOf(m[0]), at = m.index, end = at + m[0].length;
|
|
25
|
+
for (const w of (SHORT[k] || k).split(' ')) { const kk = keyOf(w); out.push({ k: kk, p: plain(kk), bare: plain(k) === k && !SHORT[k], at, end }); }
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
const phrases = (list) => list.map((s) => s.split(' ').map(keyOf));
|
|
30
|
+
// the phrase from the list that starts at token i (the longest), or null
|
|
31
|
+
function phraseAt(toks, i, list) {
|
|
32
|
+
let best = null;
|
|
33
|
+
for (const ph of list) if (ph.length <= toks.length - i && ph.every((w, j) => same(toks[i + j], w)) && (!best || ph.length > best.length)) best = ph;
|
|
34
|
+
return best;
|
|
35
|
+
}
|
|
36
|
+
function findPhrase(toks, list, from = 0) {
|
|
37
|
+
for (let i = from; i < toks.length; i++) { const ph = phraseAt(toks, i, list); if (ph) return { i, n: ph.length }; }
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const inList = (tok, set) => set.some((w) => same(tok, w));
|
|
41
|
+
const words = (s) => s.split(' ').map(keyOf);
|
|
42
|
+
|
|
43
|
+
/* ---------- what the rules look for ---------- */
|
|
44
|
+
// words that carry no request on their own: with a photo and only these, Claude has to guess
|
|
45
|
+
const FILLER = words('sao này cái đó đây kia đấy nữa nhé nhe nha ạ à ơi đi vậy thế gì nào hả hở chứ luôn với giúp dùm giùm hộ xem coi check fix help em anh chị mình tôi tao bạn sếp cho ra lại thử được không có rồi là thì mà ok cũng như thế ở trong please the this that it what why how here there now again do can you i me a an to is of on in pls ?');
|
|
46
|
+
// complete as they are, short or not ("oke rồi deploy", "push đi", an answer to Claude's question)
|
|
47
|
+
const DONE = words('ok oki rồi đi luôn nhé nhe nha ạ dạ vâng ừ ừm uh với yes yep yeah no nope có không đúng sai được xong push deploy commit merge rebase tag release continue go ahead on tiếp tục làm lại thử chạy test tests build lint sửa fix revert undo retry run it the again now please do that dừng stop huỷ hủy cancel cảm ơn cám thanks thank you thx tks lgtm đồng ý duyệt approve ship cả hai 2 both all tất phương án option chọn số pick lên github main pr');
|
|
48
|
+
const VAGUE = phrases(['khác đi', 'khác hơn', 'khác khác', 'khác chút', 'khác đy', 'hay hơn', 'hay lên', 'hay ho hơn', 'đẹp hơn', 'đẹp lên', 'đẹp đẹp', 'tốt hơn', 'xịn hơn', 'xịn lên', 'xịn xò', 'ngon hơn', 'chất hơn', 'ổn hơn', 'sang hơn', 'pro hơn', 'đỉnh hơn',
|
|
49
|
+
'chuyên nghiệp hơn', 'hiện đại hơn', 'chỉn chu hơn', 'tinh tế hơn', 'ấn tượng hơn', 'bắt mắt hơn', 'hấp dẫn hơn', 'thu hút hơn', 'giống thật', 'như thật', 'thật hơn', 'qua loa', 'làm cho có', 'cẩu thả', 'làm ẩu', 'đàng hoàng', 'tử tế',
|
|
50
|
+
'xấu quá', 'dở quá', 'chán quá', 'chưa ổn', 'chưa đẹp', 'không ổn',
|
|
51
|
+
'make it better', 'do better', 'look better', 'looks better', 'nicer', 'prettier', 'more professional', 'more modern', 'more polished', 'fancier', 'cooler', 'more real', 'look real', 'looks real', 'more realistic',
|
|
52
|
+
'something different', 'make it different', 'not lazy', 'sloppy', 'improve it', 'polish it', 'make it pop', 'not good', 'looks bad', 'looks off', 'not right']);
|
|
53
|
+
// right after a quality word, these bring its criterion ("đẹp hơn như trang chủ", "better than…") or say it is already so
|
|
54
|
+
// ("đẹp hơn rồi", "looks better now"); before it, "đã" and "thấy" say the same ("đã đẹp hơn")
|
|
55
|
+
const FOLLOW = words('là nếu nên bằng như kiểu giống theo với than by like with using rồi nhiều hẳn now already');
|
|
56
|
+
const BEFORE = words('đã thấy');
|
|
57
|
+
// a criterion anywhere: a size, a colour, a direction that can be measured, an example (no "đỏ", "đen" or "cam": typed
|
|
58
|
+
// without diacritics they are English's "do", "den" and "cam")
|
|
59
|
+
const CRITERIA = phrases(['màu', 'xanh', 'vàng', 'tím', 'hồng', 'xám', 'trắng', 'font', 'phông', 'chữ', 'cỡ', 'size', 'nền', 'background', 'layout', 'bố cục', 'icon', 'bóng', 'shadow', 'viền', 'border', 'hiệu ứng', 'animation',
|
|
60
|
+
'to hơn', 'nhỏ hơn', 'lớn hơn', 'đậm hơn', 'nhạt hơn', 'sáng hơn', 'tối hơn', 'rộng hơn', 'hẹp hơn', 'cao hơn', 'thấp hơn', 'nhanh hơn', 'chậm hơn', 'ngắn hơn', 'dài hơn', 'ít hơn', 'nhiều hơn', 'gọn hơn', 'thưa hơn', 'sát hơn',
|
|
61
|
+
'ví dụ', 'vd', 'tiêu chí', 'cụ thể', 'chẳng hạn', 'giống như', 'kiểu như', 'tham khảo',
|
|
62
|
+
'bigger', 'smaller', 'larger', 'bolder', 'darker', 'lighter', 'faster', 'slower', 'shorter', 'longer', 'wider', 'narrower', 'color', 'colour', 'spacing', 'padding', 'margin', 'for example', 'such as', 'e g', 'eg', 'criteria', 'specifically']);
|
|
63
|
+
// pointing at something the message doesn't show
|
|
64
|
+
const DANGLING = phrases(['cái này', 'cái đó', 'cái đấy', 'cái kia', 'cái ấy', 'chỗ này', 'chỗ đó', 'chỗ đấy', 'chỗ kia', 'đoạn này', 'đoạn đó', 'đoạn trên', 'phần này', 'phần đó', 'như trên', 'ở trên', 'bên trên', 'như lúc nãy', 'lúc nãy', 'hồi nãy', 'vừa nãy',
|
|
65
|
+
'this one', 'that one', 'this thing', 'that thing', 'the above', 'as above', 'same as before', 'like before', 'the previous one', 'that part']);
|
|
66
|
+
const NUMBERED = phrases(['số', 'ý', 'mục', 'câu', 'bước', 'cái thứ', 'item', 'number', 'point', 'step']);
|
|
67
|
+
// after a bare number at the start, these say what it counts ("3 phút", "2 file"), so it isn't a reference
|
|
68
|
+
const UNIT = words('px phút giây s ms ngày tiếng giờ lần người k tr triệu nghìn ngàn đồng file dòng trang cột hàng màu cái chiếc con bài câu nút lỗi bug test task việc ảnh hình chỗ tab màn min mins sec days hours times em rem kb mb gb');
|
|
69
|
+
// the jobs a message can ask for, by kind: shipping, thinking it over, changing something, checking it
|
|
70
|
+
const VERBS = [
|
|
71
|
+
['ship', ['push', 'deploy', 'commit', 'merge', 'release', 'publish', 'đẩy lên', 'đẩy code', 'up lên', 'lên github', 'tạo pr', 'mở pr', 'ship']],
|
|
72
|
+
['think', ['gợi ý', 'đề xuất', 'giải thích', 'phân tích', 'review', 'so sánh', 'tìm hiểu', 'nghiên cứu', 'đánh giá', 'tư vấn', 'lên kế hoạch', 'lập kế hoạch', 'nhận xét', 'cho ý kiến', 'brainstorm', 'suggest', 'explain', 'analyse', 'analyze', 'compare', 'research', 'propose', 'investigate', 'plan']],
|
|
73
|
+
['change', ['sửa', 'thêm', 'xoá', 'xóa', 'bỏ', 'đổi', 'thay', 'viết', 'tạo', 'cập nhật', 'làm', 'chỉnh', 'dời', 'chuyển', 'gộp', 'tách', 'cài', 'dịch', 'fix', 'add', 'remove', 'delete', 'change', 'replace', 'write', 'create', 'update', 'refactor', 'implement', 'rename', 'move', 'make', 'install', 'translate']],
|
|
74
|
+
['check', ['test', 'chạy test', 'chạy', 'kiểm tra', 'check', 'verify', 'chụp', 'xem lại', 'đo', 'run', 'lint', 'build']],
|
|
75
|
+
].map(([kind, list]) => [kind, phrases(list)]);
|
|
76
|
+
const ALL_VERBS = VERBS.flatMap(([, l]) => l);
|
|
77
|
+
const kindOf = (ph) => VERBS.find(([, l]) => l.includes(ph))[0];
|
|
78
|
+
// what joins two jobs: some always do ("trước đó", "sau đó"), some only before a verb ("và", "rồi"); "trước đó" turns the order round
|
|
79
|
+
const STRONG = phrases(['trước đó', 'trước tiên', 'trước hết', 'sau đó', 'rồi sau đó', 'và sau đó', 'xong thì', 'xong rồi', 'xong rồi thì', 'rồi thì', 'then', 'and then', 'and also', 'after that', 'afterwards', 'before that', 'but first']);
|
|
80
|
+
const REVERSE = phrases(['trước đó', 'trước tiên', 'trước hết', 'before that', 'but first']);
|
|
81
|
+
const WEAK = phrases(['rồi', 'và', 'xong', 'với lại', 'thêm nữa', 'đồng thời', 'ngoài ra', 'and', 'also', 'plus']);
|
|
82
|
+
|
|
83
|
+
const meaningful = (text) => (String(text).match(/[\p{L}\p{N}]/gu) || []).length;
|
|
84
|
+
// something the message points at for itself: a quote, a file, a path, a link
|
|
85
|
+
// (a straight single quote only round words, so "it's" and "don't" aren't quotes)
|
|
86
|
+
const ANCHOR = /["“«‘`][^"”»’`\n]{2,}["”»’`]|(?:^|\s)'[^'\n]{2,}'(?=$|[\s.,!?;:])|\b[\w-]+\.(?:[cm]?[jt]sx?|css|scss|html?|py|md|json|ya?ml|sh|go|rs|java|kt|swift|rb|php|sql|vue|svelte|txt|csv|env|png|jpe?g)\b|(?:^|\s)(?:~|\.{1,2})?\/[\w.-]+\/[\w./-]*|https?:\/\/\S+/i;
|
|
87
|
+
const CRITERION = /\d|#[0-9a-f]{3,8}\b|:\s*\S+\s+\S+|\n\s*(?:[-*•]|\d+[.)])\s/i;
|
|
88
|
+
|
|
89
|
+
/* ---------- jobs: the message cut where one job ends and the next begins ---------- */
|
|
90
|
+
const startsJob = (toks, i) => i < toks.length && (phraseAt(toks, i, ALL_VERBS) || (i + 1 < toks.length && inList(toks[i], FILLER) && phraseAt(toks, i + 1, ALL_VERBS)));
|
|
91
|
+
/** text -> [{ text, kind }] in the order they should be done (a job after "trước đó" first) */
|
|
92
|
+
export function splitTasks(text) {
|
|
93
|
+
const src = String(text || '').normalize('NFC'), out = [];
|
|
94
|
+
// sentences: . ! ? ; or a new line (a dot in "Header.tsx" or "1.5" isn't one), then the joiners inside each
|
|
95
|
+
for (const m of src.matchAll(/[^\n.!?;]+(?:\.(?=\S)[^\n.!?;]*)*/g)) {
|
|
96
|
+
const sent = m[0], toks = tokens(sent);
|
|
97
|
+
let from = 0, startTok = 0, reverse = false;
|
|
98
|
+
// the job so far ends at token endTok (character to); the next starts at nextFrom (token nextTok), after "trước đó" (rev)
|
|
99
|
+
const cut = (endTok, to, nextFrom, nextTok, rev) => {
|
|
100
|
+
const piece = sent.slice(from, to).replace(/^[\s,…:–-]+|[\s,…:–-]+$/g, '');
|
|
101
|
+
if (piece) out.push({ text: piece, reverse, toks: toks.slice(startTok, endTok) });
|
|
102
|
+
from = nextFrom; startTok = nextTok; reverse = rev;
|
|
103
|
+
};
|
|
104
|
+
for (let i = 1; i < toks.length; i++) {
|
|
105
|
+
const strong = phraseAt(toks, i, STRONG), weak = !strong && phraseAt(toks, i, WEAK);
|
|
106
|
+
const comma = !strong && !weak && /[,…]\s*$/.test(sent.slice(toks[i - 1].end, toks[i].at)) && startsJob(toks, i);
|
|
107
|
+
const ph = strong || weak;
|
|
108
|
+
if (!ph && !comma) continue;
|
|
109
|
+
const n = ph ? ph.length : 0;
|
|
110
|
+
if (weak && !startsJob(toks, i + n)) continue;
|
|
111
|
+
cut(i, toks[i].at, ph ? toks[i + n - 1].end : toks[i].at, i + n, !!strong && phraseAt(toks, i, REVERSE)?.length === n);
|
|
112
|
+
i += Math.max(0, n - 1);
|
|
113
|
+
}
|
|
114
|
+
cut(toks.length, sent.length, sent.length, toks.length, false);
|
|
115
|
+
}
|
|
116
|
+
// a job after "trước đó" goes before the one it follows
|
|
117
|
+
const ordered = [];
|
|
118
|
+
for (const p of out) { if (p.reverse && ordered.length) ordered.splice(ordered.length - 1, 0, p); else ordered.push(p); }
|
|
119
|
+
return ordered.map((p) => {
|
|
120
|
+
const v = p.toks.findIndex((_, i) => phraseAt(p.toks, i, ALL_VERBS));
|
|
121
|
+
return { text: p.text, kind: v >= 0 ? kindOf(phraseAt(p.toks, v, ALL_VERBS)) : null };
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/** The jobs as numbered lines, every word kept: "head\n1. …\n2. …" (the text as it is when there's only one). */
|
|
125
|
+
export function numberTasks(text, head = '') {
|
|
126
|
+
const jobs = splitTasks(text);
|
|
127
|
+
if (jobs.length < 2) return String(text || '');
|
|
128
|
+
const cap = (s) => s.charAt(0).toLocaleUpperCase() + s.slice(1);
|
|
129
|
+
return `${head ? `${head}\n` : ''}${jobs.map((j, i) => `${i + 1}. ${cap(j.text)}`).join('\n')}`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* ---------- the rules ---------- */
|
|
133
|
+
const PRIORITY = ['photoBare', 'dangling', 'vague', 'multi', 'tooShort'];
|
|
134
|
+
/**
|
|
135
|
+
* What would save a round trip in a message to Claude, the most useful first.
|
|
136
|
+
* { text, photos: how many go with it, quoted: it answers a message (so "cái này" has something to point at), lang: not
|
|
137
|
+
* needed, both languages are always read }
|
|
138
|
+
* -> [{ id: 'photoBare' | 'dangling' | 'vague' | 'multi' | 'tooShort', phrase?: the words it is about, n?: how many jobs }]
|
|
139
|
+
*/
|
|
140
|
+
export function coach({ text = '', photos = 0, quoted = false } = {}) {
|
|
141
|
+
const src = String(text || '').normalize('NFC'), toks = tokens(src), len = meaningful(src), out = [];
|
|
142
|
+
if (/^\s*\//.test(src)) return out; // (a slash command: Claude Code's own)
|
|
143
|
+
if (!photos && !len) return out;
|
|
144
|
+
const content = toks.filter((t) => !inList(t, FILLER));
|
|
145
|
+
const said = (h) => src.slice(toks[h.i].at, toks[h.i + h.n - 1].end);
|
|
146
|
+
// a photo with one to three words: "sao", "điền sao", "config gì", "cái này nữa nhé"
|
|
147
|
+
if (photos > 0 && content.length <= 2 && len < 25) out.push({ id: 'photoBare' });
|
|
148
|
+
const anchored = photos > 0 || quoted || ANCHOR.test(src);
|
|
149
|
+
// "cái này", "phần của vĩ", "ý 4…", "4 đâu có…": pointing at something the message doesn't show
|
|
150
|
+
if (!anchored) {
|
|
151
|
+
let hit = findPhrase(toks, DANGLING);
|
|
152
|
+
const of = !hit && toks.findIndex((t, i) => same(t, 'phần') && toks[i + 1] && same(toks[i + 1], 'của') && toks[i + 2]);
|
|
153
|
+
if (!hit && of >= 0) hit = { i: of, n: 3 };
|
|
154
|
+
for (let i = 0; !hit && i < toks.length; i++) {
|
|
155
|
+
const ph = phraseAt(toks, i, NUMBERED), j = i + (ph?.length || 0);
|
|
156
|
+
if (ph && /^\d{1,2}$/.test(toks[j]?.k || '') && toks.length - (ph.length + 1) >= 4) hit = { i, n: ph.length + 1 };
|
|
157
|
+
}
|
|
158
|
+
if (!hit && /^\s*\d{1,2}\s+\p{L}/u.test(src) && toks.length >= 5 && !inList(toks[1], UNIT) && !/\n\s*2\s*[.):-]?\s+\p{L}/u.test(src)) hit = { i: 0, n: 1 }; // (not a list you numbered yourself: "1 …\n2. …")
|
|
159
|
+
if (hit) out.push({ id: 'dangling', phrase: said(hit) });
|
|
160
|
+
}
|
|
161
|
+
// "khác đi", "hay hơn", "làm giống thật đừng làm qua loa": a quality with nothing to measure it by
|
|
162
|
+
const vague = [];
|
|
163
|
+
for (let h = findPhrase(toks, VAGUE); h; h = findPhrase(toks, VAGUE, h.i + h.n)) {
|
|
164
|
+
const next = toks[h.i + h.n], prev = toks[h.i - 1], after = src.slice(toks[h.i + h.n - 1].end).trimStart();
|
|
165
|
+
if (!(next && inList(next, FOLLOW)) && !(prev && inList(prev, BEFORE)) && !after.startsWith(':')) vague.push(h);
|
|
166
|
+
}
|
|
167
|
+
if (vague.length) {
|
|
168
|
+
const used = new Set(vague.flatMap((h) => Array.from({ length: h.n }, (_, k) => h.i + k)));
|
|
169
|
+
const rest = toks.filter((t, i) => !used.has(i) && !inList(t, FILLER));
|
|
170
|
+
if (!CRITERION.test(src) && !ANCHOR.test(src) && !findPhrase(toks, CRITERIA) && rest.length < 10) out.push({ id: 'vague', phrase: said(vague[0]) });
|
|
171
|
+
}
|
|
172
|
+
// several jobs: of different kinds ("gợi ý…, trước đó push lên github") in a message of some length, or three or more
|
|
173
|
+
const jobs = splitTasks(src).filter((j) => j.kind), kinds = new Set(jobs.map((j) => j.kind));
|
|
174
|
+
if (jobs.length >= 3 || (jobs.length === 2 && kinds.size >= 2 && (content.length >= 6 || findPhrase(toks, REVERSE)))) out.push({ id: 'multi', n: jobs.length });
|
|
175
|
+
// under 12 characters, and not a whole answer on its own ("oke", "push đi", "2" are)
|
|
176
|
+
if (!out.length && !photos && [...src.trim()].length < 12 && !toks.every((t) => inList(t, DONE) || /^\d{1,2}$/.test(t.k) || /^[a-e]$/.test(t.k))) out.push({ id: 'tooShort' });
|
|
177
|
+
return out.sort((a, b) => PRIORITY.indexOf(a.id) - PRIORITY.indexOf(b.id));
|
|
178
|
+
}
|