gestalt-mobile 0.75.3 → 0.76.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.
@@ -0,0 +1,181 @@
1
+ /*
2
+ * Copyright (C) 2026 Dyne.org foundation
3
+ * Designed by Denis Roio <jaromil@dyne.org>
4
+ * SPDX-License-Identifier: AGPL-3.0-or-later
5
+ */
6
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
7
+ if (value !== null && value !== void 0) {
8
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
9
+ var dispose, inner;
10
+ if (async) {
11
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
12
+ dispose = value[Symbol.asyncDispose];
13
+ }
14
+ if (dispose === void 0) {
15
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
16
+ dispose = value[Symbol.dispose];
17
+ if (async) inner = dispose;
18
+ }
19
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
20
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
21
+ env.stack.push({ value: value, dispose: dispose, async: async });
22
+ }
23
+ else if (async) {
24
+ env.stack.push({ async: true });
25
+ }
26
+ return value;
27
+ };
28
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
29
+ return function (env) {
30
+ function fail(e) {
31
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
32
+ env.hasError = true;
33
+ }
34
+ var r, s = 0;
35
+ function next() {
36
+ while (r = env.stack.pop()) {
37
+ try {
38
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
39
+ if (r.dispose) {
40
+ var result = r.dispose.call(r.value);
41
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
42
+ }
43
+ else s |= 1;
44
+ }
45
+ catch (e) {
46
+ fail(e);
47
+ }
48
+ }
49
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
50
+ if (env.hasError) throw env.error;
51
+ }
52
+ return next();
53
+ };
54
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
55
+ var e = new Error(message);
56
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
+ });
58
+ import { closeSync, mkdirSync, openSync, statSync } from 'node:fs';
59
+ import { dirname, join } from 'node:path';
60
+ import { DatabaseSync } from 'node:sqlite';
61
+ import { resetCreditCooldownMs, } from '../../features/catalog/application/codex-auto-reset.js';
62
+ /** All workspaces share this account-level ledger, independent of relay.sqlite. */
63
+ export class SqliteCodexResetStore {
64
+ path;
65
+ constructor(homeDirectory) {
66
+ this.path = join(homeDirectory, '.gestalt', 'codex-reset-credits.sqlite');
67
+ }
68
+ open() {
69
+ if (!statSync(this.path, { throwIfNoEntry: false }))
70
+ return undefined;
71
+ const db = new DatabaseSync(this.path, { timeout: 1_000 });
72
+ try {
73
+ if (db
74
+ .prepare("SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = 'codex_reset_settings'")
75
+ .get())
76
+ return db;
77
+ }
78
+ catch (error) {
79
+ db.close();
80
+ throw error;
81
+ }
82
+ db.close();
83
+ return undefined;
84
+ }
85
+ enabled() {
86
+ const env_1 = { stack: [], error: void 0, hasError: false };
87
+ try {
88
+ const db = __addDisposableResource(env_1, this.open(), false);
89
+ return (db?.prepare('SELECT enabled FROM codex_reset_settings WHERE id = 1').get()?.enabled === 1);
90
+ }
91
+ catch (e_1) {
92
+ env_1.error = e_1;
93
+ env_1.hasError = true;
94
+ }
95
+ finally {
96
+ __disposeResources(env_1);
97
+ }
98
+ }
99
+ status() {
100
+ const env_2 = { stack: [], error: void 0, hasError: false };
101
+ try {
102
+ const db = __addDisposableResource(env_2, this.open(), false);
103
+ if (!db)
104
+ return { enabled: false, resets: [] };
105
+ return {
106
+ enabled: db.prepare('SELECT enabled FROM codex_reset_settings WHERE id = 1').get()?.enabled === 1,
107
+ resets: db
108
+ .prepare('SELECT id, reset_at AS occurredAt FROM codex_reset_attempts WHERE reset_at IS NOT NULL ORDER BY reset_at DESC LIMIT 50')
109
+ .all(),
110
+ };
111
+ }
112
+ catch (e_2) {
113
+ env_2.error = e_2;
114
+ env_2.hasError = true;
115
+ }
116
+ finally {
117
+ __disposeResources(env_2);
118
+ }
119
+ }
120
+ setEnabled(enabled) {
121
+ const env_3 = { stack: [], error: void 0, hasError: false };
122
+ try {
123
+ mkdirSync(dirname(this.path), { recursive: true, mode: 0o700 });
124
+ closeSync(openSync(this.path, 'a', 0o600));
125
+ const db = __addDisposableResource(env_3, new DatabaseSync(this.path, { timeout: 1_000 }), false);
126
+ db.exec(`BEGIN IMMEDIATE;
127
+ CREATE TABLE IF NOT EXISTS codex_reset_settings (id INTEGER PRIMARY KEY CHECK (id = 1), enabled INTEGER NOT NULL);
128
+ CREATE TABLE IF NOT EXISTS codex_reset_attempts (
129
+ id TEXT PRIMARY KEY, attempted_at INTEGER NOT NULL, weekly_resets_at INTEGER NOT NULL, reset_at INTEGER
130
+ );
131
+ COMMIT;`);
132
+ db.prepare(`INSERT INTO codex_reset_settings (id, enabled) VALUES (1, ?)
133
+ ON CONFLICT(id) DO UPDATE SET enabled = excluded.enabled`).run(Number(enabled));
134
+ }
135
+ catch (e_3) {
136
+ env_3.error = e_3;
137
+ env_3.hasError = true;
138
+ }
139
+ finally {
140
+ __disposeResources(env_3);
141
+ }
142
+ }
143
+ claim(id, now, weeklyResetsAt) {
144
+ const env_4 = { stack: [], error: void 0, hasError: false };
145
+ try {
146
+ const db = __addDisposableResource(env_4, this.open(), false);
147
+ // One atomic write across processes checks opt-in, cooldown and original
148
+ // window. Keeping attempted windows fences stale reads and uncertain replies.
149
+ return (db
150
+ ?.prepare(`INSERT INTO codex_reset_attempts (id, attempted_at, weekly_resets_at)
151
+ SELECT ?, ?, ?
152
+ WHERE EXISTS (SELECT 1 FROM codex_reset_settings WHERE id = 1 AND enabled = 1)
153
+ AND NOT EXISTS (
154
+ SELECT 1 FROM codex_reset_attempts
155
+ WHERE attempted_at > ? OR reset_at > ? OR weekly_resets_at >= ?
156
+ )`)
157
+ .run(id, now, weeklyResetsAt, now - resetCreditCooldownMs, now - resetCreditCooldownMs, weeklyResetsAt).changes === 1);
158
+ }
159
+ catch (e_4) {
160
+ env_4.error = e_4;
161
+ env_4.hasError = true;
162
+ }
163
+ finally {
164
+ __disposeResources(env_4);
165
+ }
166
+ }
167
+ recordReset(id, occurredAt) {
168
+ const env_5 = { stack: [], error: void 0, hasError: false };
169
+ try {
170
+ const db = __addDisposableResource(env_5, this.open(), false);
171
+ db?.prepare('UPDATE codex_reset_attempts SET reset_at = ? WHERE id = ? AND reset_at IS NULL').run(occurredAt, id);
172
+ }
173
+ catch (e_5) {
174
+ env_5.error = e_5;
175
+ env_5.hasError = true;
176
+ }
177
+ finally {
178
+ __disposeResources(env_5);
179
+ }
180
+ }
181
+ }
@@ -3,4 +3,13 @@
3
3
  * Designed by Denis Roio <jaromil@dyne.org>
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
- export {};
6
+ import { z } from 'zod';
7
+ export const codexAutoResetStatusSchema = z.object({
8
+ enabled: z.boolean(),
9
+ resets: z
10
+ .array(z.object({
11
+ id: z.string().min(1).max(80),
12
+ occurredAt: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
13
+ }))
14
+ .max(50),
15
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.75.3",
3
+ "version": "0.76.0",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",