aamp-openclaw-plugin 0.1.24 → 0.1.26

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.
@@ -62,9 +62,113 @@ function expandHome(pathValue) {
62
62
  return pathValue
63
63
  }
64
64
 
65
+ function stripJsonComments(text) {
66
+ let result = ''
67
+ let inString = false
68
+ let stringQuote = ''
69
+ let escaped = false
70
+
71
+ for (let i = 0; i < text.length; i += 1) {
72
+ const char = text[i]
73
+ const next = text[i + 1]
74
+
75
+ if (inString) {
76
+ result += char
77
+ if (escaped) {
78
+ escaped = false
79
+ } else if (char === '\\') {
80
+ escaped = true
81
+ } else if (char === stringQuote) {
82
+ inString = false
83
+ stringQuote = ''
84
+ }
85
+ continue
86
+ }
87
+
88
+ if (char === '"' || char === "'") {
89
+ inString = true
90
+ stringQuote = char
91
+ result += char
92
+ continue
93
+ }
94
+
95
+ if (char === '/' && next === '/') {
96
+ i += 2
97
+ while (i < text.length && text[i] !== '\n') i += 1
98
+ if (i < text.length) result += text[i]
99
+ continue
100
+ }
101
+
102
+ if (char === '/' && next === '*') {
103
+ i += 2
104
+ while (i < text.length && !(text[i] === '*' && text[i + 1] === '/')) i += 1
105
+ i += 1
106
+ continue
107
+ }
108
+
109
+ result += char
110
+ }
111
+
112
+ return result
113
+ }
114
+
115
+ function stripTrailingCommas(text) {
116
+ let result = ''
117
+ let inString = false
118
+ let stringQuote = ''
119
+ let escaped = false
120
+
121
+ for (let i = 0; i < text.length; i += 1) {
122
+ const char = text[i]
123
+
124
+ if (inString) {
125
+ result += char
126
+ if (escaped) {
127
+ escaped = false
128
+ } else if (char === '\\') {
129
+ escaped = true
130
+ } else if (char === stringQuote) {
131
+ inString = false
132
+ stringQuote = ''
133
+ }
134
+ continue
135
+ }
136
+
137
+ if (char === '"' || char === "'") {
138
+ inString = true
139
+ stringQuote = char
140
+ result += char
141
+ continue
142
+ }
143
+
144
+ if (char === ',') {
145
+ let lookahead = i + 1
146
+ while (lookahead < text.length && /\s/.test(text[lookahead])) lookahead += 1
147
+ if (text[lookahead] === '}' || text[lookahead] === ']') {
148
+ continue
149
+ }
150
+ }
151
+
152
+ result += char
153
+ }
154
+
155
+ return result
156
+ }
157
+
158
+ function parseJsonConfig(raw, path) {
159
+ const normalized = raw.replace(/^\uFEFF/, '')
160
+ const sanitized = stripTrailingCommas(stripJsonComments(normalized))
161
+ try {
162
+ return JSON.parse(sanitized)
163
+ } catch (error) {
164
+ const reason = error instanceof Error ? error.message : String(error)
165
+ throw new Error(`Failed to parse ${path}: ${reason}`)
166
+ }
167
+ }
168
+
65
169
  function readJsonFile(path) {
66
170
  if (!existsSync(path)) return null
67
- return JSON.parse(readFileSync(path, 'utf-8'))
171
+ return parseJsonConfig(readFileSync(path, 'utf-8'), path)
68
172
  }
69
173
 
70
174
  function writeJsonFile(path, value) {
@@ -332,7 +436,12 @@ function restartGateway() {
332
436
  async function ensureMailboxIdentity({ aampHost, slug, credentialsFile }) {
333
437
  const resolvedCreds = expandHome(credentialsFile)
334
438
  if (existsSync(resolvedCreds)) {
335
- return { created: false, email: null, credentialsPath: resolvedCreds }
439
+ const cachedIdentity = readJsonFile(resolvedCreds)
440
+ return {
441
+ created: false,
442
+ email: cachedIdentity?.email ?? null,
443
+ credentialsPath: resolvedCreds,
444
+ }
336
445
  }
337
446
 
338
447
  const base = normalizeBaseUrl(aampHost)
@@ -545,7 +654,9 @@ async function runInit() {
545
654
  ` codingBaselineAdded: ${toolPolicyPlan.missingCodingTools.length > 0 && includeCodingBaseline ? 'yes' : 'no'}`,
546
655
  identityResult.created
547
656
  ? ` mailbox: ${identityResult.email} (registered and saved to ${identityResult.credentialsPath})`
548
- : ` mailbox: existing credentials reused from ${identityResult.credentialsPath}`,
657
+ : identityResult.email
658
+ ? ` mailbox: ${identityResult.email} (existing credentials reused from ${identityResult.credentialsPath})`
659
+ : ` mailbox: existing credentials reused from ${identityResult.credentialsPath}`,
549
660
  '',
550
661
  restartResult.ok
551
662
  ? `Gateway restart: ${restartResult.message}`
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "skills"
8
8
  ],
9
9
  "license": "MIT",
10
- "version": "0.1.24",
10
+ "version": "0.1.26",
11
11
  "description": "AAMP Agent Mail Protocol — OpenClaw plugin. Gives OpenClaw an AAMP mailbox identity and lets it receive, process and reply to AAMP tasks.",
12
12
  "type": "module",
13
13
  "main": "dist/index.js",