@agents-tower/core 0.1.1 → 0.1.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.
@@ -0,0 +1,17 @@
1
+ import type { DashboardSnapshot } from "./types";
2
+ export type HistoryEventKind = "wait.opened" | "wait.resolved" | "session.started" | "session.finished";
3
+ export interface HistoryEvent {
4
+ at: string;
5
+ kind: HistoryEventKind;
6
+ projectLabel: string;
7
+ agentLabel: string;
8
+ provenance: string;
9
+ detail: string | null;
10
+ waitMs?: number;
11
+ }
12
+ export interface HistoryFleetView {
13
+ projects: Pick<DashboardSnapshot, "projectLabel" | "agents">[];
14
+ }
15
+ export declare function diffFleetForHistory(previous: HistoryFleetView | null, next: HistoryFleetView, nowMs?: number): HistoryEvent[];
16
+ export declare function appendHistoryEvents(events: HistoryEvent[]): void;
17
+ export declare function readHistoryEvents(sinceMs: number, nowMs?: number): HistoryEvent[];
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.diffFleetForHistory = diffFleetForHistory;
4
+ exports.appendHistoryEvents = appendHistoryEvents;
5
+ exports.readHistoryEvents = readHistoryEvents;
6
+ const node_fs_1 = require("node:fs");
7
+ const node_path_1 = require("node:path");
8
+ const app_settings_1 = require("./app-settings");
9
+ const HISTORY_JOURNAL_MAX_BYTES = 2 * 1024 * 1024;
10
+ function historyDirectory() {
11
+ return (0, node_path_1.join)((0, app_settings_1.getAppDataDirectory)(), "history");
12
+ }
13
+ function historyJournalPath() {
14
+ return (0, node_path_1.join)(historyDirectory(), "journal.jsonl");
15
+ }
16
+ function isBusy(agent) {
17
+ return agent.isCurrent === true || agent.isOngoing === true;
18
+ }
19
+ function trackedAgents(fleet) {
20
+ const tracked = new Map();
21
+ for (const project of fleet.projects) {
22
+ for (const agent of project.agents) {
23
+ tracked.set(agent.id, { agent, projectLabel: project.projectLabel });
24
+ }
25
+ }
26
+ return tracked;
27
+ }
28
+ function diffFleetForHistory(previous, next, nowMs = Date.now()) {
29
+ const at = new Date(nowMs).toISOString();
30
+ const events = [];
31
+ const before = previous ? trackedAgents(previous) : new Map();
32
+ const after = trackedAgents(next);
33
+ for (const [id, { agent, projectLabel }] of after) {
34
+ const prior = before.get(id);
35
+ if (agent.needsUser && !prior?.agent.needsUser) {
36
+ events.push({
37
+ at,
38
+ kind: "wait.opened",
39
+ projectLabel,
40
+ agentLabel: agent.label,
41
+ provenance: agent.provenance,
42
+ detail: agent.needsUser.kind
43
+ });
44
+ }
45
+ if (!agent.needsUser && prior?.agent.needsUser) {
46
+ const openedMs = Date.parse(prior.agent.updatedAt);
47
+ events.push({
48
+ at,
49
+ kind: "wait.resolved",
50
+ projectLabel,
51
+ agentLabel: agent.label,
52
+ provenance: agent.provenance,
53
+ detail: prior.agent.needsUser?.kind ?? null,
54
+ waitMs: Number.isFinite(openedMs) ? Math.max(0, nowMs - openedMs) : undefined
55
+ });
56
+ }
57
+ if (previous && isBusy(agent) && (!prior || !isBusy(prior.agent))) {
58
+ events.push({
59
+ at,
60
+ kind: "session.started",
61
+ projectLabel,
62
+ agentLabel: agent.label,
63
+ provenance: agent.provenance,
64
+ detail: agent.detail || null
65
+ });
66
+ }
67
+ if (prior && isBusy(prior.agent) && !isBusy(agent)) {
68
+ events.push({
69
+ at,
70
+ kind: "session.finished",
71
+ projectLabel,
72
+ agentLabel: agent.label,
73
+ provenance: agent.provenance,
74
+ detail: agent.detail || null
75
+ });
76
+ }
77
+ }
78
+ for (const [id, { agent, projectLabel }] of before) {
79
+ if (after.has(id)) {
80
+ continue;
81
+ }
82
+ if (isBusy(agent)) {
83
+ events.push({
84
+ at,
85
+ kind: "session.finished",
86
+ projectLabel,
87
+ agentLabel: agent.label,
88
+ provenance: agent.provenance,
89
+ detail: agent.detail || null
90
+ });
91
+ }
92
+ if (agent.needsUser) {
93
+ const openedMs = Date.parse(agent.updatedAt);
94
+ events.push({
95
+ at,
96
+ kind: "wait.resolved",
97
+ projectLabel,
98
+ agentLabel: agent.label,
99
+ provenance: agent.provenance,
100
+ detail: agent.needsUser.kind,
101
+ waitMs: Number.isFinite(openedMs) ? Math.max(0, nowMs - openedMs) : undefined
102
+ });
103
+ }
104
+ }
105
+ return events;
106
+ }
107
+ function appendHistoryEvents(events) {
108
+ if (events.length === 0) {
109
+ return;
110
+ }
111
+ (0, node_fs_1.mkdirSync)(historyDirectory(), { recursive: true });
112
+ const path = historyJournalPath();
113
+ try {
114
+ if ((0, node_fs_1.existsSync)(path) && (0, node_fs_1.statSync)(path).size > HISTORY_JOURNAL_MAX_BYTES) {
115
+ (0, node_fs_1.renameSync)(path, (0, node_path_1.join)(historyDirectory(), "journal.previous.jsonl"));
116
+ }
117
+ }
118
+ catch {
119
+ // Rotation is best-effort; appending still proceeds.
120
+ }
121
+ (0, node_fs_1.appendFileSync)(path, events.map((event) => JSON.stringify(event)).join("\n") + "\n");
122
+ }
123
+ function readHistoryEvents(sinceMs, nowMs = Date.now()) {
124
+ const events = [];
125
+ for (const file of ["journal.previous.jsonl", "journal.jsonl"]) {
126
+ const path = (0, node_path_1.join)(historyDirectory(), file);
127
+ if (!(0, node_fs_1.existsSync)(path)) {
128
+ continue;
129
+ }
130
+ for (const line of (0, node_fs_1.readFileSync)(path, "utf8").split(/\r?\n/)) {
131
+ if (!line) {
132
+ continue;
133
+ }
134
+ try {
135
+ const event = JSON.parse(line);
136
+ const atMs = Date.parse(event.at);
137
+ if (Number.isFinite(atMs) && atMs >= sinceMs && atMs <= nowMs) {
138
+ events.push(event);
139
+ }
140
+ }
141
+ catch {
142
+ // Skip corrupted lines.
143
+ }
144
+ }
145
+ }
146
+ return events.sort((left, right) => left.at.localeCompare(right.at));
147
+ }
148
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":";;AAmDA,kDAqFC;AAED,kDAcC;AAED,8CAuBC;AAjLD,qCAAoG;AACpG,yCAA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Ae,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,GAAG,IAAA,gBAAI,EAAC,gBAAgB,EAAE,EAAE,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAA,oBAAU,EAAC,IAAI,CAAC,EAAE,CAAC;YACtB,SAAS;QACX,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,IAAA,sBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7D,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,SAAS;YACX,CAAC;YACD,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAiB,CAAC;gBAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBAClC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;oBAC9D,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACrB,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AACvE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from "./claude-home-cache";
11
11
  export * from "./codex-command";
12
12
  export { normalizeRepositoryUrl } from "./cursor-lib/shared";
13
13
  export * from "./domain/workspace-activity";
14
+ export * from "./history";
14
15
  export * from "./hermes";
15
16
  export * from "./hermes-hook-install";
16
17
  export * from "./openclaw";
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ __exportStar(require("./codex-command"), exports);
29
29
  var shared_1 = require("./cursor-lib/shared");
30
30
  Object.defineProperty(exports, "normalizeRepositoryUrl", { enumerable: true, get: function () { return shared_1.normalizeRepositoryUrl; } });
31
31
  __exportStar(require("./domain/workspace-activity"), exports);
32
+ __exportStar(require("./history"), exports);
32
33
  __exportStar(require("./hermes"), exports);
33
34
  __exportStar(require("./hermes-hook-install"), exports);
34
35
  __exportStar(require("./openclaw"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,iDAA+B;AAC/B,qDAAmC;AACnC,sDAAoC;AACpC,kDAAgC;AAChC,8CAA6D;AAApD,gHAAA,sBAAsB,OAAA;AAC/B,8DAA4C;AAC5C,2CAAyB;AACzB,wDAAsC;AACtC,6CAA2B;AAC3B,6CAA2B;AAC3B,qDAAmC;AACnC,kDAAgC;AAChC,oDAAkC;AAClC,gDAA8B;AAC9B,+DAA6C;AAC7C,kEAAgD;AAChD,0EAAwD;AACxD,+DAA6C;AAC7C,gEAA8C;AAC9C,0DAAwC;AACxC,6CAA2B;AAC3B,0CAAwB;AACxB,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,iDAA+B;AAC/B,qDAAmC;AACnC,sDAAoC;AACpC,kDAAgC;AAChC,8CAA6D;AAApD,gHAAA,sBAAsB,OAAA;AAC/B,8DAA4C;AAC5C,4CAA0B;AAC1B,2CAAyB;AACzB,wDAAsC;AACtC,6CAA2B;AAC3B,6CAA2B;AAC3B,qDAAmC;AACnC,kDAAgC;AAChC,oDAAkC;AAClC,gDAA8B;AAC9B,+DAA6C;AAC7C,kEAAgD;AAChD,0EAAwD;AACxD,+DAA6C;AAC7C,gEAA8C;AAC9C,0DAAwC;AACxC,6CAA2B;AAC3B,0CAAwB;AACxB,6CAA2B"}
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@agents-tower/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/Kundara/AgentsOfficeTower.git",
8
+ "directory": "packages/core"
9
+ },
5
10
  "main": "dist/index.js",
6
11
  "types": "dist/index.d.ts",
7
12
  "files": [