github-issue-tower-defence-management 2.151.5 → 2.151.6
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/bin/adapter/repositories/ProcTakeOwnershipSpawnRepository.js +8 -61
- package/bin/adapter/repositories/ProcTakeOwnershipSpawnRepository.js.map +1 -1
- package/bin/adapter/repositories/ProcTakeOwnershipWorkerSessionReader.js +211 -0
- package/bin/adapter/repositories/ProcTakeOwnershipWorkerSessionReader.js.map +1 -0
- package/bin/adapter/repositories/ProxyClaudeTokenUsageRepository.js +5 -97
- package/bin/adapter/repositories/ProxyClaudeTokenUsageRepository.js.map +1 -1
- package/package.json +1 -1
- package/types/adapter/repositories/ProcTakeOwnershipSpawnRepository.d.ts +1 -2
- package/types/adapter/repositories/ProcTakeOwnershipSpawnRepository.d.ts.map +1 -1
- package/types/adapter/repositories/ProcTakeOwnershipWorkerSessionReader.d.ts +21 -0
- package/types/adapter/repositories/ProcTakeOwnershipWorkerSessionReader.d.ts.map +1 -0
- package/types/adapter/repositories/ProxyClaudeTokenUsageRepository.d.ts +1 -2
- package/types/adapter/repositories/ProxyClaudeTokenUsageRepository.d.ts.map +1 -1
|
@@ -36,13 +36,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.ProcTakeOwnershipSpawnRepository = void 0;
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
|
+
const ProcTakeOwnershipWorkerSessionReader_1 = require("./ProcTakeOwnershipWorkerSessionReader");
|
|
39
40
|
const DEFAULT_PROC_DIRECTORY = '/proc';
|
|
40
|
-
const OAUTH_TOKEN_ENVIRON_KEY = 'CLAUDE_CODE_OAUTH_TOKEN';
|
|
41
|
-
const TAKE_OWNERSHIP_MARKER = 'Take ownership';
|
|
42
41
|
const LOG_PATH_PATTERN = /\/logs-aw\/[^\0"]+\.log/;
|
|
43
42
|
const ISSUE_URL_PATTERN = /Take ownership of (https:\/\/github\.com\/[^ \0"]+)/;
|
|
44
|
-
const parseCommandLineArguments = (cmdline) => cmdline.split('\0').filter((argument) => argument.length > 0);
|
|
45
|
-
const isTakeOwnershipSpawn = (commandArguments) => commandArguments.some((argument) => argument.includes(TAKE_OWNERSHIP_MARKER));
|
|
46
43
|
const extractLogPath = (cmdline) => {
|
|
47
44
|
const match = cmdline.match(LOG_PATH_PATTERN);
|
|
48
45
|
return match === null ? null : match[0];
|
|
@@ -50,16 +47,12 @@ const extractLogPath = (cmdline) => {
|
|
|
50
47
|
class ProcTakeOwnershipSpawnRepository {
|
|
51
48
|
constructor(procDirectory = DEFAULT_PROC_DIRECTORY) {
|
|
52
49
|
this.procDirectory = procDirectory;
|
|
53
|
-
this.listSpawns = () => {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return spawns;
|
|
62
|
-
};
|
|
50
|
+
this.listSpawns = () => this.workerSessionReader.listWorkerSessions().flatMap((session) => session.workerProcesses.flatMap((workerProcess) => {
|
|
51
|
+
const logPath = extractLogPath(workerProcess.rawCommandLine);
|
|
52
|
+
return logPath === null
|
|
53
|
+
? []
|
|
54
|
+
: [{ token: session.sessionToken, logPath }];
|
|
55
|
+
}));
|
|
63
56
|
this.listRunningIssueUrls = () => {
|
|
64
57
|
const urls = [];
|
|
65
58
|
for (const pidDirectory of this.listProcessIdDirectories()) {
|
|
@@ -84,29 +77,6 @@ class ProcTakeOwnershipSpawnRepository {
|
|
|
84
77
|
}
|
|
85
78
|
return entries.filter((entry) => /^\d+$/.test(entry));
|
|
86
79
|
};
|
|
87
|
-
this.readSpawn = (processIdDirectory) => {
|
|
88
|
-
const rawCmdline = this.readRawCmdline(processIdDirectory);
|
|
89
|
-
if (rawCmdline === null) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
const commandArguments = parseCommandLineArguments(rawCmdline);
|
|
93
|
-
if (!isTakeOwnershipSpawn(commandArguments)) {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
const logPath = extractLogPath(rawCmdline);
|
|
97
|
-
if (logPath === null) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const environ = this.readEnviron(processIdDirectory);
|
|
101
|
-
if (environ === null) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
const token = environ.get(OAUTH_TOKEN_ENVIRON_KEY);
|
|
105
|
-
if (token === undefined || token.length === 0) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
return { token, logPath };
|
|
109
|
-
};
|
|
110
80
|
this.readRawCmdline = (processIdDirectory) => {
|
|
111
81
|
const cmdlinePath = path.join(this.procDirectory, processIdDirectory, 'cmdline');
|
|
112
82
|
try {
|
|
@@ -116,30 +86,7 @@ class ProcTakeOwnershipSpawnRepository {
|
|
|
116
86
|
return null;
|
|
117
87
|
}
|
|
118
88
|
};
|
|
119
|
-
this.
|
|
120
|
-
const environPath = path.join(this.procDirectory, processIdDirectory, 'environ');
|
|
121
|
-
let raw;
|
|
122
|
-
try {
|
|
123
|
-
raw = fs.readFileSync(environPath, 'utf8');
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
const environ = new Map();
|
|
129
|
-
for (const entry of raw.split('\0')) {
|
|
130
|
-
if (entry.length === 0) {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
const separatorIndex = entry.indexOf('=');
|
|
134
|
-
if (separatorIndex <= 0) {
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
const key = entry.slice(0, separatorIndex);
|
|
138
|
-
const value = entry.slice(separatorIndex + 1);
|
|
139
|
-
environ.set(key, value);
|
|
140
|
-
}
|
|
141
|
-
return environ;
|
|
142
|
-
};
|
|
89
|
+
this.workerSessionReader = new ProcTakeOwnershipWorkerSessionReader_1.ProcTakeOwnershipWorkerSessionReader(procDirectory);
|
|
143
90
|
}
|
|
144
91
|
}
|
|
145
92
|
exports.ProcTakeOwnershipSpawnRepository = ProcTakeOwnershipSpawnRepository;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcTakeOwnershipSpawnRepository.js","sourceRoot":"","sources":["../../../src/adapter/repositories/ProcTakeOwnershipSpawnRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;
|
|
1
|
+
{"version":3,"file":"ProcTakeOwnershipSpawnRepository.js","sourceRoot":"","sources":["../../../src/adapter/repositories/ProcTakeOwnershipSpawnRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAK7B,iGAA8F;AAE9F,MAAM,sBAAsB,GAAG,OAAO,CAAC;AACvC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AACnD,MAAM,iBAAiB,GAAG,qDAAqD,CAAC;AAEhF,MAAM,cAAc,GAAG,CAAC,OAAe,EAAiB,EAAE;IACxD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC9C,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAa,gCAAgC;IAG3C,YAA6B,gBAAwB,sBAAsB;QAA9C,kBAAa,GAAb,aAAa,CAAiC;QAM3E,eAAU,GAAG,GAAyB,EAAE,CACtC,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAChE,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;YAChD,MAAM,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;YAC7D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AY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;YAC9C,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC,CAAC;QAnDA,IAAI,CAAC,mBAAmB,GAAG,IAAI,2EAAoC,CACjE,aAAa,CACd,CAAC;IACJ,CAAC;CAiDF;AAxDD,4EAwDC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ProcTakeOwnershipWorkerSessionReader = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const OAUTH_TOKEN_ENVIRON_PREFIX = 'CLAUDE_CODE_OAUTH_TOKEN=';
|
|
40
|
+
const TAKE_OWNERSHIP_MARKER = 'Take ownership';
|
|
41
|
+
const CLAUDE_COMMAND_NAME = 'claude';
|
|
42
|
+
const parseProcessStat = (rawStat) => {
|
|
43
|
+
const commandNameStart = rawStat.indexOf('(');
|
|
44
|
+
const commandNameEnd = rawStat.lastIndexOf(')');
|
|
45
|
+
if (commandNameStart < 0 || commandNameEnd < commandNameStart) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const fieldsAfterCommandName = rawStat
|
|
49
|
+
.slice(commandNameEnd + 1)
|
|
50
|
+
.trim()
|
|
51
|
+
.split(/\s+/);
|
|
52
|
+
const parentProcessId = Number(fieldsAfterCommandName[1]);
|
|
53
|
+
if (!Number.isInteger(parentProcessId)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
commandName: rawStat.slice(commandNameStart + 1, commandNameEnd),
|
|
58
|
+
parentProcessId,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const parseOauthToken = (rawEnviron) => {
|
|
62
|
+
const tokenEntry = rawEnviron
|
|
63
|
+
.split('\0')
|
|
64
|
+
.find((entry) => entry.startsWith(OAUTH_TOKEN_ENVIRON_PREFIX));
|
|
65
|
+
if (tokenEntry === undefined) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const token = tokenEntry.slice(OAUTH_TOKEN_ENVIRON_PREFIX.length);
|
|
69
|
+
return token.length === 0 ? null : token;
|
|
70
|
+
};
|
|
71
|
+
class ProcTakeOwnershipWorkerSessionReader {
|
|
72
|
+
constructor(procDirectory) {
|
|
73
|
+
this.procDirectory = procDirectory;
|
|
74
|
+
this.listWorkerSessions = () => {
|
|
75
|
+
const snapshotsByProcessId = this.readProcessSnapshots();
|
|
76
|
+
const childProcessIdsByParent = this.groupChildProcessIdsByParent(snapshotsByProcessId);
|
|
77
|
+
const workerProcessesById = this.readTokenHoldingWorkerProcesses(snapshotsByProcessId);
|
|
78
|
+
const sessions = [];
|
|
79
|
+
for (const rootProcess of workerProcessesById.values()) {
|
|
80
|
+
const parentProcessId = snapshotsByProcessId.get(rootProcess.processId)?.stat
|
|
81
|
+
?.parentProcessId ?? null;
|
|
82
|
+
if (parentProcessId !== null &&
|
|
83
|
+
workerProcessesById.has(parentProcessId)) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const descendantSnapshots = this.listDescendantsShallowestFirst(rootProcess.processId, childProcessIdsByParent).flatMap((processId) => {
|
|
87
|
+
const snapshot = snapshotsByProcessId.get(processId);
|
|
88
|
+
return snapshot === undefined ? [] : [snapshot];
|
|
89
|
+
});
|
|
90
|
+
const claudeDescendant = descendantSnapshots.find((snapshot) => snapshot.stat?.commandName === CLAUDE_COMMAND_NAME &&
|
|
91
|
+
snapshot.oauthToken !== null);
|
|
92
|
+
sessions.push({
|
|
93
|
+
rootProcessId: rootProcess.processId,
|
|
94
|
+
sessionToken: claudeDescendant?.oauthToken ?? rootProcess.oauthToken,
|
|
95
|
+
workerProcesses: this.listWorkerProcessesOfSession(rootProcess.processId, childProcessIdsByParent, workerProcessesById),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return sessions.sort((left, right) => left.rootProcessId - right.rootProcessId);
|
|
99
|
+
};
|
|
100
|
+
this.readProcessSnapshots = () => {
|
|
101
|
+
const snapshotsByProcessId = new Map();
|
|
102
|
+
let entries;
|
|
103
|
+
try {
|
|
104
|
+
entries = fs.readdirSync(this.procDirectory);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return snapshotsByProcessId;
|
|
108
|
+
}
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
if (!/^\d+$/.test(entry)) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const rawStat = this.readProcessFile(entry, 'stat');
|
|
114
|
+
const rawEnviron = this.readProcessFile(entry, 'environ');
|
|
115
|
+
snapshotsByProcessId.set(Number(entry), {
|
|
116
|
+
processId: Number(entry),
|
|
117
|
+
stat: rawStat === null ? null : parseProcessStat(rawStat),
|
|
118
|
+
oauthToken: rawEnviron === null ? null : parseOauthToken(rawEnviron),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return snapshotsByProcessId;
|
|
122
|
+
};
|
|
123
|
+
this.groupChildProcessIdsByParent = (snapshotsByProcessId) => {
|
|
124
|
+
const childProcessIdsByParent = new Map();
|
|
125
|
+
for (const snapshot of snapshotsByProcessId.values()) {
|
|
126
|
+
if (snapshot.stat === null) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const childProcessIds = childProcessIdsByParent.get(snapshot.stat.parentProcessId) ?? [];
|
|
130
|
+
childProcessIds.push(snapshot.processId);
|
|
131
|
+
childProcessIdsByParent.set(snapshot.stat.parentProcessId, childProcessIds);
|
|
132
|
+
}
|
|
133
|
+
for (const childProcessIds of childProcessIdsByParent.values()) {
|
|
134
|
+
childProcessIds.sort((left, right) => left - right);
|
|
135
|
+
}
|
|
136
|
+
return childProcessIdsByParent;
|
|
137
|
+
};
|
|
138
|
+
this.readTokenHoldingWorkerProcesses = (snapshotsByProcessId) => {
|
|
139
|
+
const workerProcessesById = new Map();
|
|
140
|
+
for (const snapshot of snapshotsByProcessId.values()) {
|
|
141
|
+
if (snapshot.oauthToken === null) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const rawCommandLine = this.readProcessFile(String(snapshot.processId), 'cmdline');
|
|
145
|
+
if (rawCommandLine === null ||
|
|
146
|
+
!rawCommandLine.includes(TAKE_OWNERSHIP_MARKER)) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
workerProcessesById.set(snapshot.processId, {
|
|
150
|
+
processId: snapshot.processId,
|
|
151
|
+
rawCommandLine,
|
|
152
|
+
oauthToken: snapshot.oauthToken,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return workerProcessesById;
|
|
156
|
+
};
|
|
157
|
+
this.listDescendantsShallowestFirst = (rootProcessId, childProcessIdsByParent) => {
|
|
158
|
+
const descendants = [];
|
|
159
|
+
const visitedProcessIds = new Set([rootProcessId]);
|
|
160
|
+
const pendingProcessIds = [rootProcessId];
|
|
161
|
+
for (let pendingProcessId = pendingProcessIds.shift(); pendingProcessId !== undefined; pendingProcessId = pendingProcessIds.shift()) {
|
|
162
|
+
for (const childProcessId of childProcessIdsByParent.get(pendingProcessId) ?? []) {
|
|
163
|
+
if (visitedProcessIds.has(childProcessId)) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
visitedProcessIds.add(childProcessId);
|
|
167
|
+
descendants.push(childProcessId);
|
|
168
|
+
pendingProcessIds.push(childProcessId);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return descendants;
|
|
172
|
+
};
|
|
173
|
+
this.listWorkerProcessesOfSession = (rootProcessId, childProcessIdsByParent, workerProcessesById) => {
|
|
174
|
+
const sessionProcessIds = new Set([rootProcessId]);
|
|
175
|
+
const pendingProcessIds = [rootProcessId];
|
|
176
|
+
for (let pendingProcessId = pendingProcessIds.shift(); pendingProcessId !== undefined; pendingProcessId = pendingProcessIds.shift()) {
|
|
177
|
+
for (const childProcessId of childProcessIdsByParent.get(pendingProcessId) ?? []) {
|
|
178
|
+
if (sessionProcessIds.has(childProcessId) ||
|
|
179
|
+
!workerProcessesById.has(childProcessId)) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
sessionProcessIds.add(childProcessId);
|
|
183
|
+
pendingProcessIds.push(childProcessId);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return [...sessionProcessIds]
|
|
187
|
+
.sort((left, right) => left - right)
|
|
188
|
+
.flatMap((processId) => {
|
|
189
|
+
const workerProcess = workerProcessesById.get(processId);
|
|
190
|
+
return workerProcess === undefined
|
|
191
|
+
? []
|
|
192
|
+
: [
|
|
193
|
+
{
|
|
194
|
+
processId: workerProcess.processId,
|
|
195
|
+
rawCommandLine: workerProcess.rawCommandLine,
|
|
196
|
+
},
|
|
197
|
+
];
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
this.readProcessFile = (processIdDirectory, fileName) => {
|
|
201
|
+
try {
|
|
202
|
+
return fs.readFileSync(path.join(this.procDirectory, processIdDirectory, fileName), 'utf8');
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.ProcTakeOwnershipWorkerSessionReader = ProcTakeOwnershipWorkerSessionReader;
|
|
211
|
+
//# sourceMappingURL=ProcTakeOwnershipWorkerSessionReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcTakeOwnershipWorkerSessionReader.js","sourceRoot":"","sources":["../../../src/adapter/repositories/ProcTakeOwnershipWorkerSessionReader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAE7B,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAC9D,MAAM,qBAAqB,GAAG,gBAAgB,CAAC;AAC/C,MAAM,mBAAmB,GAAG,QAAQ,CAAC;AA4BrC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAsB,EAAE;IAC/D,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,cAAc,GAAG,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|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.ProxyClaudeTokenUsageRepository = void 0;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
4
|
const ensureProxyRunning_1 = require("../proxy/ensureProxyRunning");
|
|
40
5
|
const RateLimitCache_1 = require("../proxy/RateLimitCache");
|
|
41
6
|
const TokenListLoader_1 = require("../proxy/TokenListLoader");
|
|
42
|
-
const
|
|
7
|
+
const ProcTakeOwnershipWorkerSessionReader_1 = require("./ProcTakeOwnershipWorkerSessionReader");
|
|
8
|
+
const PROC_DIRECTORY = '/proc';
|
|
43
9
|
class ProxyClaudeTokenUsageRepository {
|
|
44
10
|
constructor(tokenListJsonPath, port = RateLimitCache_1.PROXY_PORT) {
|
|
45
11
|
this.tokenListJsonPath = tokenListJsonPath;
|
|
46
12
|
this.port = port;
|
|
13
|
+
this.workerSessionReader = new ProcTakeOwnershipWorkerSessionReader_1.ProcTakeOwnershipWorkerSessionReader(PROC_DIRECTORY);
|
|
47
14
|
this.ensureObservable = async () => {
|
|
48
15
|
await (0, ensureProxyRunning_1.ensureProxyRunning)(this.port);
|
|
49
16
|
};
|
|
@@ -131,70 +98,11 @@ class ProxyClaudeTokenUsageRepository {
|
|
|
131
98
|
};
|
|
132
99
|
this.getTokenInFlightCounts = async () => {
|
|
133
100
|
const counts = {};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
procEntries = fs.readdirSync('/proc');
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
return counts;
|
|
140
|
-
}
|
|
141
|
-
const tokenByPid = new Map();
|
|
142
|
-
for (const entry of procEntries) {
|
|
143
|
-
if (!/^\d+$/.test(entry))
|
|
144
|
-
continue;
|
|
145
|
-
const environPath = path.join('/proc', entry, 'environ');
|
|
146
|
-
let environ;
|
|
147
|
-
try {
|
|
148
|
-
environ = fs.readFileSync(environPath, 'utf8');
|
|
149
|
-
}
|
|
150
|
-
catch {
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
const vars = environ.split('\0');
|
|
154
|
-
const tokenEntry = vars.find((v) => v.startsWith('CLAUDE_CODE_OAUTH_TOKEN='));
|
|
155
|
-
if (tokenEntry === undefined)
|
|
156
|
-
continue;
|
|
157
|
-
const token = tokenEntry.slice('CLAUDE_CODE_OAUTH_TOKEN='.length);
|
|
158
|
-
if (token.length === 0)
|
|
159
|
-
continue;
|
|
160
|
-
if (!this.isPreparationWorkerProcess(entry))
|
|
161
|
-
continue;
|
|
162
|
-
tokenByPid.set(Number(entry), token);
|
|
163
|
-
}
|
|
164
|
-
for (const [pid, token] of tokenByPid) {
|
|
165
|
-
const parentPid = this.readParentPid(pid);
|
|
166
|
-
if (parentPid !== null && tokenByPid.has(parentPid))
|
|
167
|
-
continue;
|
|
168
|
-
counts[token] = (counts[token] ?? 0) + 1;
|
|
101
|
+
for (const session of this.workerSessionReader.listWorkerSessions()) {
|
|
102
|
+
counts[session.sessionToken] = (counts[session.sessionToken] ?? 0) + 1;
|
|
169
103
|
}
|
|
170
104
|
return counts;
|
|
171
105
|
};
|
|
172
|
-
this.isPreparationWorkerProcess = (procEntry) => {
|
|
173
|
-
const commandLinePath = path.join('/proc', procEntry, 'cmdline');
|
|
174
|
-
let commandLine;
|
|
175
|
-
try {
|
|
176
|
-
commandLine = fs.readFileSync(commandLinePath, 'utf8');
|
|
177
|
-
}
|
|
178
|
-
catch {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
return commandLine.includes(TAKE_OWNERSHIP_COMMAND_MARKER);
|
|
182
|
-
};
|
|
183
|
-
this.readParentPid = (pid) => {
|
|
184
|
-
let stat;
|
|
185
|
-
try {
|
|
186
|
-
stat = fs.readFileSync(path.join('/proc', String(pid), 'stat'), 'utf8');
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
const afterComm = stat.slice(stat.lastIndexOf(') ') + 2);
|
|
192
|
-
const fields = afterComm.trim().split(/\s+/);
|
|
193
|
-
const parentPid = Number(fields[1]);
|
|
194
|
-
if (!Number.isInteger(parentPid))
|
|
195
|
-
return null;
|
|
196
|
-
return parentPid;
|
|
197
|
-
};
|
|
198
106
|
this.proxyBaseUrl = () => `http://127.0.0.1:${this.port}`;
|
|
199
107
|
}
|
|
200
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyClaudeTokenUsageRepository.js","sourceRoot":"","sources":["../../../src/adapter/repositories/ProxyClaudeTokenUsageRepository.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ProxyClaudeTokenUsageRepository.js","sourceRoot":"","sources":["../../../src/adapter/repositories/ProxyClaudeTokenUsageRepository.ts"],"names":[],"mappings":";;;AAEA,oEAAiE;AACjE,4DAAoE;AACpE,8DAA4D;AAC5D,iGAA8F;AAE9F,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B,MAAa,+BAA+B;IAI1C,YACmB,iBAAgC,EAChC,OAAe,2BAAU;QADzB,sBAAiB,GAAjB,iBAAiB,CAAe;QAChC,SAAI,GAAJ,IAAI,CAAqB;QAL3B,wBAAmB,GAClC,IAAI,2EAAoC,CAAC,cAAc,CAAC,CAAC;QAO3D,qBAAgB,GAAG,KAAK,IAAmB,EAAE;YAC3C,MAAM,IAAA,uCAAkB,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC,CAAC;QAEF,4BAAuB,GAAG,KAAK,IAAiC,EAAE;YAChE,IAAI,IAAI,CAAC,iBAAiB,KAAK,IAAI,EAAE,CAAC;gBACpC,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,MAAM,OAAO,GAAG,IAAA,kCAAgB,EAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YACzD,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBACrB,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;YAC1C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CACxB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,eAAe,EAAE,EAA2B,EAAE;gBAC5D,MAAM,QAAQ,GAAG,IAAA,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AC,CAAC,CAAC;oBAClE,eAAe;iBAChB,CAAC;YACJ,CAAC,CACF,CAAC;YACF,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAA6B,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;QAC7E,CAAC,CAAC;QAEF,2BAAsB,GAAG,KAAK,IAAqC,EAAE;YACnE,MAAM,MAAM,GAA2B,EAAE,CAAC;YAC1C,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,EAAE,CAAC;gBACpE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACzE,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;QAEF,iBAAY,GAAG,GAAW,EAAE,CAAC,oBAAoB,IAAI,CAAC,IAAI,EAAE,CAAC;IApH1D,CAAC;CAqHL;AA5HD,0EA4HC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { TakeOwnershipSpawn, TakeOwnershipSpawnRepository } from '../../domain/usecases/adapter-interfaces/TakeOwnershipSpawnRepository';
|
|
2
2
|
export declare class ProcTakeOwnershipSpawnRepository implements TakeOwnershipSpawnRepository {
|
|
3
3
|
private readonly procDirectory;
|
|
4
|
+
private readonly workerSessionReader;
|
|
4
5
|
constructor(procDirectory?: string);
|
|
5
6
|
listSpawns: () => TakeOwnershipSpawn[];
|
|
6
7
|
listRunningIssueUrls: () => string[];
|
|
7
8
|
private listProcessIdDirectories;
|
|
8
|
-
private readSpawn;
|
|
9
9
|
private readRawCmdline;
|
|
10
|
-
private readEnviron;
|
|
11
10
|
}
|
|
12
11
|
//# sourceMappingURL=ProcTakeOwnershipSpawnRepository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcTakeOwnershipSpawnRepository.d.ts","sourceRoot":"","sources":["../../../src/adapter/repositories/ProcTakeOwnershipSpawnRepository.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC7B,MAAM,uEAAuE,CAAC;
|
|
1
|
+
{"version":3,"file":"ProcTakeOwnershipSpawnRepository.d.ts","sourceRoot":"","sources":["../../../src/adapter/repositories/ProcTakeOwnershipSpawnRepository.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC7B,MAAM,uEAAuE,CAAC;AAY/E,qBAAa,gCAAiC,YAAW,4BAA4B;IAGvE,OAAO,CAAC,QAAQ,CAAC,aAAa;IAF1C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAuC;gBAE9C,aAAa,GAAE,MAA+B;IAM3E,UAAU,QAAO,kBAAkB,EAAE,CAQjC;IAEJ,oBAAoB,QAAO,MAAM,EAAE,CAajC;IAEF,OAAO,CAAC,wBAAwB,CAQ9B;IAEF,OAAO,CAAC,cAAc,CAWpB;CACH"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type TakeOwnershipWorkerProcess = {
|
|
2
|
+
processId: number;
|
|
3
|
+
rawCommandLine: string;
|
|
4
|
+
};
|
|
5
|
+
export type TakeOwnershipWorkerSession = {
|
|
6
|
+
rootProcessId: number;
|
|
7
|
+
sessionToken: string;
|
|
8
|
+
workerProcesses: TakeOwnershipWorkerProcess[];
|
|
9
|
+
};
|
|
10
|
+
export declare class ProcTakeOwnershipWorkerSessionReader {
|
|
11
|
+
private readonly procDirectory;
|
|
12
|
+
constructor(procDirectory: string);
|
|
13
|
+
listWorkerSessions: () => TakeOwnershipWorkerSession[];
|
|
14
|
+
private readProcessSnapshots;
|
|
15
|
+
private groupChildProcessIdsByParent;
|
|
16
|
+
private readTokenHoldingWorkerProcesses;
|
|
17
|
+
private listDescendantsShallowestFirst;
|
|
18
|
+
private listWorkerProcessesOfSession;
|
|
19
|
+
private readProcessFile;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=ProcTakeOwnershipWorkerSessionReader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcTakeOwnershipWorkerSessionReader.d.ts","sourceRoot":"","sources":["../../../src/adapter/repositories/ProcTakeOwnershipWorkerSessionReader.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,0BAA0B,EAAE,CAAC;CAC/C,CAAC;AAgDF,qBAAa,oCAAoC;IACnC,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAAb,aAAa,EAAE,MAAM;IAElD,kBAAkB,QAAO,0BAA0B,EAAE,CA0CnD;IAEF,OAAO,CAAC,oBAAoB,CAqB1B;IAEF,OAAO,CAAC,4BAA4B,CAoBlC;IAEF,OAAO,CAAC,+BAA+B,CAyBrC;IAEF,OAAO,CAAC,8BAA8B,CAwBpC;IAEF,OAAO,CAAC,4BAA4B,CAsClC;IAEF,OAAO,CAAC,eAAe,CAYrB;CACH"}
|
|
@@ -3,12 +3,11 @@ import { ClaudeTokenUsageRepository } from '../../domain/usecases/adapter-interf
|
|
|
3
3
|
export declare class ProxyClaudeTokenUsageRepository implements ClaudeTokenUsageRepository {
|
|
4
4
|
private readonly tokenListJsonPath;
|
|
5
5
|
private readonly port;
|
|
6
|
+
private readonly workerSessionReader;
|
|
6
7
|
constructor(tokenListJsonPath: string | null, port?: number);
|
|
7
8
|
ensureObservable: () => Promise<void>;
|
|
8
9
|
getAvailableTokenUsages: () => Promise<ClaudeTokenUsage[]>;
|
|
9
10
|
getTokenInFlightCounts: () => Promise<Record<string, number>>;
|
|
10
|
-
private isPreparationWorkerProcess;
|
|
11
|
-
private readParentPid;
|
|
12
11
|
proxyBaseUrl: () => string;
|
|
13
12
|
}
|
|
14
13
|
//# sourceMappingURL=ProxyClaudeTokenUsageRepository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyClaudeTokenUsageRepository.d.ts","sourceRoot":"","sources":["../../../src/adapter/repositories/ProxyClaudeTokenUsageRepository.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ProxyClaudeTokenUsageRepository.d.ts","sourceRoot":"","sources":["../../../src/adapter/repositories/ProxyClaudeTokenUsageRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,MAAM,qEAAqE,CAAC;AAQjH,qBAAa,+BAAgC,YAAW,0BAA0B;IAK9E,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,IAAI;IALvB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CACuB;gBAGxC,iBAAiB,EAAE,MAAM,GAAG,IAAI,EAChC,IAAI,GAAE,MAAmB;IAG5C,gBAAgB,QAAa,OAAO,CAAC,IAAI,CAAC,CAExC;IAEF,uBAAuB,QAAa,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAoG7D;IAEF,sBAAsB,QAAa,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAMhE;IAEF,YAAY,QAAO,MAAM,CAAoC;CAC9D"}
|