codeksei 0.1.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 (80) hide show
  1. package/LICENSE +661 -0
  2. package/README.en.md +215 -0
  3. package/README.md +259 -0
  4. package/bin/codeksei.js +10 -0
  5. package/bin/cyberboss.js +11 -0
  6. package/package.json +86 -0
  7. package/scripts/install-background-tasks.ps1 +135 -0
  8. package/scripts/open_shared_wechat_thread.sh +94 -0
  9. package/scripts/open_wechat_thread.sh +117 -0
  10. package/scripts/shared-common.js +791 -0
  11. package/scripts/shared-open.js +46 -0
  12. package/scripts/shared-start.js +41 -0
  13. package/scripts/shared-status.js +74 -0
  14. package/scripts/shared-supervisor.js +141 -0
  15. package/scripts/shared-task-runner.ps1 +87 -0
  16. package/scripts/shared-watchdog.js +290 -0
  17. package/scripts/show_shared_status.sh +53 -0
  18. package/scripts/start_shared_app_server.sh +65 -0
  19. package/scripts/start_shared_wechat.sh +108 -0
  20. package/scripts/timeline-screenshot.sh +15 -0
  21. package/scripts/uninstall-background-tasks.ps1 +23 -0
  22. package/src/adapters/channel/weixin/account-store.js +135 -0
  23. package/src/adapters/channel/weixin/api-v2.js +258 -0
  24. package/src/adapters/channel/weixin/api.js +180 -0
  25. package/src/adapters/channel/weixin/context-token-store.js +84 -0
  26. package/src/adapters/channel/weixin/index.js +605 -0
  27. package/src/adapters/channel/weixin/legacy.js +567 -0
  28. package/src/adapters/channel/weixin/login-common.js +63 -0
  29. package/src/adapters/channel/weixin/login-legacy.js +124 -0
  30. package/src/adapters/channel/weixin/login-v2.js +186 -0
  31. package/src/adapters/channel/weixin/media-mime.js +22 -0
  32. package/src/adapters/channel/weixin/media-receive.js +370 -0
  33. package/src/adapters/channel/weixin/media-send.js +331 -0
  34. package/src/adapters/channel/weixin/message-utils-v2.js +282 -0
  35. package/src/adapters/channel/weixin/message-utils.js +199 -0
  36. package/src/adapters/channel/weixin/protocol.js +77 -0
  37. package/src/adapters/channel/weixin/redact.js +41 -0
  38. package/src/adapters/channel/weixin/reminder-queue-store.js +101 -0
  39. package/src/adapters/channel/weixin/sync-buffer-store.js +35 -0
  40. package/src/adapters/runtime/codex/events.js +252 -0
  41. package/src/adapters/runtime/codex/index.js +502 -0
  42. package/src/adapters/runtime/codex/message-utils.js +141 -0
  43. package/src/adapters/runtime/codex/model-catalog.js +106 -0
  44. package/src/adapters/runtime/codex/protocol-leak-monitor.js +75 -0
  45. package/src/adapters/runtime/codex/rpc-client.js +443 -0
  46. package/src/adapters/runtime/codex/session-store.js +376 -0
  47. package/src/app/channel-send-file-cli.js +57 -0
  48. package/src/app/diary-write-cli.js +620 -0
  49. package/src/app/note-auto-cli.js +201 -0
  50. package/src/app/note-sync-cli.js +130 -0
  51. package/src/app/project-radar-cli.js +165 -0
  52. package/src/app/reminder-write-cli.js +210 -0
  53. package/src/app/review-cli.js +134 -0
  54. package/src/app/system-checkin-poller.js +100 -0
  55. package/src/app/system-send-cli.js +129 -0
  56. package/src/app/timeline-event-cli.js +273 -0
  57. package/src/app/timeline-screenshot-cli.js +109 -0
  58. package/src/core/app.js +1810 -0
  59. package/src/core/branding.js +167 -0
  60. package/src/core/command-registry.js +609 -0
  61. package/src/core/config.js +84 -0
  62. package/src/core/default-targets.js +163 -0
  63. package/src/core/durable-note-schema.js +325 -0
  64. package/src/core/instructions-template.js +31 -0
  65. package/src/core/note-sync.js +433 -0
  66. package/src/core/project-radar.js +402 -0
  67. package/src/core/review-semantic.js +524 -0
  68. package/src/core/review.js +1081 -0
  69. package/src/core/shared-bridge-heartbeat.js +140 -0
  70. package/src/core/stream-delivery.js +990 -0
  71. package/src/core/system-message-dispatcher.js +68 -0
  72. package/src/core/system-message-queue-store.js +128 -0
  73. package/src/core/thread-state-store.js +135 -0
  74. package/src/core/timeline-screenshot-queue-store.js +134 -0
  75. package/src/core/workspace-alias.js +163 -0
  76. package/src/core/workspace-bootstrap.js +338 -0
  77. package/src/index.js +270 -0
  78. package/src/integrations/timeline/index.js +191 -0
  79. package/templates/weixin-instructions.md +53 -0
  80. package/templates/weixin-operations.md +69 -0
@@ -0,0 +1,140 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const DEFAULT_SHARED_BRIDGE_HEARTBEAT_MAX_AGE_MS = 120_000;
5
+
6
+ function readSharedBridgeHeartbeat(filePath) {
7
+ try {
8
+ const raw = fs.readFileSync(filePath, "utf8");
9
+ return normalizeHeartbeat(JSON.parse(raw));
10
+ } catch {
11
+ return null;
12
+ }
13
+ }
14
+
15
+ function writeSharedBridgeHeartbeat(filePath, patch) {
16
+ const current = readSharedBridgeHeartbeat(filePath) || {};
17
+ const next = normalizeHeartbeat({
18
+ ...current,
19
+ ...(patch || {}),
20
+ updatedAt: new Date().toISOString(),
21
+ });
22
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
23
+ fs.writeFileSync(filePath, JSON.stringify(next, null, 2), "utf8");
24
+ return next;
25
+ }
26
+
27
+ function classifySharedBridgeHeartbeat(record, { expectedPid = 0, maxAgeMs = DEFAULT_SHARED_BRIDGE_HEARTBEAT_MAX_AGE_MS } = {}) {
28
+ if (!record) {
29
+ return {
30
+ status: "missing",
31
+ healthy: false,
32
+ updatedAt: "",
33
+ };
34
+ }
35
+
36
+ if (record.status === "stopped") {
37
+ return {
38
+ status: "stopped",
39
+ healthy: false,
40
+ updatedAt: record.updatedAt,
41
+ };
42
+ }
43
+
44
+ // The managed pid is the truth source for "is the shared bridge actually
45
+ // online right now". A fresh heartbeat without a live adopted pid only means
46
+ // we have leftover state on disk, not a bridge the operator can trust.
47
+ if (!expectedPid) {
48
+ return {
49
+ status: "missing_process",
50
+ healthy: false,
51
+ updatedAt: record.updatedAt,
52
+ };
53
+ }
54
+
55
+ if (expectedPid && Number(record.pid) !== Number(expectedPid)) {
56
+ return {
57
+ status: "pid_mismatch",
58
+ healthy: false,
59
+ updatedAt: record.updatedAt,
60
+ };
61
+ }
62
+
63
+ const updatedAtMs = Date.parse(record.updatedAt || "");
64
+ if (!Number.isFinite(updatedAtMs)) {
65
+ return {
66
+ status: "stale",
67
+ healthy: false,
68
+ updatedAt: record.updatedAt,
69
+ };
70
+ }
71
+
72
+ // The bridge can sit inside a 35s long-poll and also briefly back off after
73
+ // transient failures. Use a larger heartbeat window so "quiet but healthy"
74
+ // does not get misclassified as dead and trigger restart loops.
75
+ if (Date.now() - updatedAtMs > maxAgeMs) {
76
+ return {
77
+ status: "stale",
78
+ healthy: false,
79
+ updatedAt: record.updatedAt,
80
+ };
81
+ }
82
+
83
+ return {
84
+ status: "ok",
85
+ healthy: true,
86
+ updatedAt: record.updatedAt,
87
+ };
88
+ }
89
+
90
+ function normalizeHeartbeat(value) {
91
+ if (!value || typeof value !== "object") {
92
+ return null;
93
+ }
94
+
95
+ return {
96
+ pid: normalizePid(value.pid),
97
+ status: normalizeText(value.status),
98
+ accountId: normalizeText(value.accountId),
99
+ workspaceRoot: normalizeText(value.workspaceRoot),
100
+ codexEndpoint: normalizeText(value.codexEndpoint),
101
+ startedAt: normalizeIso(value.startedAt),
102
+ updatedAt: normalizeIso(value.updatedAt),
103
+ stoppedAt: normalizeIso(value.stoppedAt),
104
+ lastPollStartedAt: normalizeIso(value.lastPollStartedAt),
105
+ lastPollSucceededAt: normalizeIso(value.lastPollSucceededAt),
106
+ lastPollFailedAt: normalizeIso(value.lastPollFailedAt),
107
+ consecutiveFailures: normalizeCount(value.consecutiveFailures),
108
+ lastError: normalizeText(value.lastError),
109
+ };
110
+ }
111
+
112
+ function normalizePid(value) {
113
+ const numeric = Number.parseInt(String(value || ""), 10);
114
+ return Number.isInteger(numeric) && numeric > 0 ? numeric : 0;
115
+ }
116
+
117
+ function normalizeIso(value) {
118
+ const normalized = normalizeText(value);
119
+ if (!normalized) {
120
+ return "";
121
+ }
122
+ const parsed = Date.parse(normalized);
123
+ return Number.isFinite(parsed) ? new Date(parsed).toISOString() : "";
124
+ }
125
+
126
+ function normalizeCount(value) {
127
+ const numeric = Number.parseInt(String(value || ""), 10);
128
+ return Number.isInteger(numeric) && numeric >= 0 ? numeric : 0;
129
+ }
130
+
131
+ function normalizeText(value) {
132
+ return typeof value === "string" ? value.trim() : "";
133
+ }
134
+
135
+ module.exports = {
136
+ DEFAULT_SHARED_BRIDGE_HEARTBEAT_MAX_AGE_MS,
137
+ classifySharedBridgeHeartbeat,
138
+ readSharedBridgeHeartbeat,
139
+ writeSharedBridgeHeartbeat,
140
+ };