yap2app 1.1.3 → 1.1.4
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/cli.bundle.js +80 -15
- package/bin/cli.js +80 -15
- package/bridge.js +47 -14
- package/package.json +1 -1
- package/polyfills.js +48 -5
package/bin/cli.bundle.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
if(typeof process!=='undefined'&&process.emitWarning){var _ow=process.emitWarning;process.emitWarning=function(w){if(typeof w==='string'&&(w.includes('punycode')||w.includes('ExperimentalWarning')||w.includes('DEP0040')))return;if(w&&typeof w==='object'&&(w.code==='DEP0040'||w.name==='ExperimentalWarning'||String(w.message||'').includes('punycode')))return;return _ow.apply(process,arguments);};}if(typeof globalThis==='undefined'){if(typeof global!=='undefined'){global.globalThis=global;}else if(typeof window!=='undefined'){window.globalThis=window;}else if(typeof self!=='undefined'){self.globalThis=self;}}if(!Object.fromEntries){Object.fromEntries=function(e){if(!e)return{};var o={};var a=Array.isArray(e)?e:Array.from(e);for(var i=0;i<a.length;i++){var p=a[i];if(p&&p.length>=2)o[p[0]]=p[1];}return o;};}if(!Object.hasOwn){Object.hasOwn=function(o,p){return o!=null&&Object.prototype.hasOwnProperty.call(o,p);};}if(!Array.prototype.flat){Array.prototype.flat=function(d){var f=[];var dp=typeof d==='number'?d:1;(function fl(a,cd){for(var i=0;i<a.length;i++){if(Array.isArray(a[i])&&cd>0){fl(a[i],cd-1);}else{f.push(a[i]);}}})(this,dp);return f;};}if(!String.prototype.replaceAll){String.prototype.replaceAll=function(s,r){if(s instanceof RegExp)return this.replace(s,r);return this.split(s).join(r);};}if(!String.prototype.matchAll){String.prototype.matchAll=function(r){var f=r.flags;if(!f.includes('g'))f+='g';var rx=new RegExp(r.source,f);var s=String(this);var m=[];var mt;while((mt=rx.exec(s))!==null){m.push(mt);if(mt.index===rx.lastIndex)rx.lastIndex++;}return m[Symbol.iterator]?m[Symbol.iterator]():m;};}
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6916,6 +6917,25 @@ var require_dist = __commonJS({
|
|
|
6916
6917
|
});
|
|
6917
6918
|
|
|
6918
6919
|
// polyfills.js
|
|
6920
|
+
if (typeof process !== "undefined" && process.emitWarning) {
|
|
6921
|
+
_originalEmitWarning = process.emitWarning;
|
|
6922
|
+
process.emitWarning = function(warning) {
|
|
6923
|
+
if (typeof warning === "string") {
|
|
6924
|
+
if (warning.includes("punycode") || warning.includes("ExperimentalWarning") || warning.includes("DEP0040")) {
|
|
6925
|
+
return;
|
|
6926
|
+
}
|
|
6927
|
+
} else if (warning && typeof warning === "object") {
|
|
6928
|
+
if (warning.code === "DEP0040" || warning.name === "ExperimentalWarning") {
|
|
6929
|
+
return;
|
|
6930
|
+
}
|
|
6931
|
+
if (String(warning.message || "").includes("punycode")) {
|
|
6932
|
+
return;
|
|
6933
|
+
}
|
|
6934
|
+
}
|
|
6935
|
+
return _originalEmitWarning.apply(process, arguments);
|
|
6936
|
+
};
|
|
6937
|
+
}
|
|
6938
|
+
var _originalEmitWarning;
|
|
6919
6939
|
if (typeof globalThis === "undefined") {
|
|
6920
6940
|
if (typeof global !== "undefined") {
|
|
6921
6941
|
global.globalThis = global;
|
|
@@ -6929,8 +6949,9 @@ if (typeof Object.fromEntries === "undefined") {
|
|
|
6929
6949
|
Object.fromEntries = function(entries) {
|
|
6930
6950
|
if (!entries) return {};
|
|
6931
6951
|
var obj = {};
|
|
6932
|
-
|
|
6933
|
-
|
|
6952
|
+
var arr = Array.isArray(entries) ? entries : Array.from(entries);
|
|
6953
|
+
for (var i = 0; i < arr.length; i++) {
|
|
6954
|
+
var pair = arr[i];
|
|
6934
6955
|
if (pair && pair.length >= 2) {
|
|
6935
6956
|
obj[pair[0]] = pair[1];
|
|
6936
6957
|
}
|
|
@@ -6967,6 +6988,25 @@ if (!String.prototype.replaceAll) {
|
|
|
6967
6988
|
return this.split(search).join(replacement);
|
|
6968
6989
|
};
|
|
6969
6990
|
}
|
|
6991
|
+
if (!String.prototype.matchAll) {
|
|
6992
|
+
String.prototype.matchAll = function(regexp) {
|
|
6993
|
+
var flags = regexp.flags;
|
|
6994
|
+
if (!flags.includes("g")) {
|
|
6995
|
+
flags += "g";
|
|
6996
|
+
}
|
|
6997
|
+
var rx = new RegExp(regexp.source, flags);
|
|
6998
|
+
var str = String(this);
|
|
6999
|
+
var matches = [];
|
|
7000
|
+
var match;
|
|
7001
|
+
while ((match = rx.exec(str)) !== null) {
|
|
7002
|
+
matches.push(match);
|
|
7003
|
+
if (match.index === rx.lastIndex) {
|
|
7004
|
+
rx.lastIndex++;
|
|
7005
|
+
}
|
|
7006
|
+
}
|
|
7007
|
+
return matches[Symbol.iterator] ? matches[Symbol.iterator]() : matches;
|
|
7008
|
+
};
|
|
7009
|
+
}
|
|
6970
7010
|
if (!Promise.allSettled) {
|
|
6971
7011
|
Promise.allSettled = function(promises) {
|
|
6972
7012
|
return Promise.all(
|
|
@@ -7532,17 +7572,20 @@ var fs2 = import_fs2.default.promises || {
|
|
|
7532
7572
|
mkdir: import_util2.default.promisify(import_fs2.default.mkdir),
|
|
7533
7573
|
stat: import_util2.default.promisify(import_fs2.default.stat)
|
|
7534
7574
|
};
|
|
7535
|
-
var PORT = process.env.YAP2APP_PORT || 10420;
|
|
7575
|
+
var PORT = Number(process.env.YAP2APP_PORT) || 10420;
|
|
7536
7576
|
var PROJECT_ROOT = process.cwd();
|
|
7537
7577
|
function getCorsHeaders(req) {
|
|
7538
7578
|
var _a5, _b;
|
|
7539
7579
|
const origin = ((_a5 = req == null ? void 0 : req.headers) == null ? void 0 : _a5.origin) || "*";
|
|
7580
|
+
const requestedHeaders = ((_b = req == null ? void 0 : req.headers) == null ? void 0 : _b["access-control-request-headers"]) || "*";
|
|
7540
7581
|
return {
|
|
7541
7582
|
"Access-Control-Allow-Origin": origin,
|
|
7542
|
-
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, DELETE, HEAD",
|
|
7543
|
-
"Access-Control-Allow-Headers":
|
|
7583
|
+
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, DELETE, HEAD, PATCH",
|
|
7584
|
+
"Access-Control-Allow-Headers": requestedHeaders === "*" ? "Content-Type, Authorization, Access-Control-Request-Private-Network, X-Requested-With, Accept, Origin, *" : requestedHeaders,
|
|
7544
7585
|
"Access-Control-Allow-Private-Network": "true",
|
|
7586
|
+
"Access-Control-Allow-Credentials": "true",
|
|
7545
7587
|
"Access-Control-Max-Age": "86400",
|
|
7588
|
+
"Vary": "Origin, Access-Control-Request-Headers, Access-Control-Request-Private-Network",
|
|
7546
7589
|
"Content-Type": "application/json"
|
|
7547
7590
|
};
|
|
7548
7591
|
}
|
|
@@ -7587,22 +7630,31 @@ var server = import_http.default.createServer(async (req, res) => {
|
|
|
7587
7630
|
res.end();
|
|
7588
7631
|
return;
|
|
7589
7632
|
}
|
|
7590
|
-
|
|
7633
|
+
let pathname = "/";
|
|
7634
|
+
let searchParams = new URLSearchParams();
|
|
7635
|
+
try {
|
|
7636
|
+
const parsedUrl = new URL(req.url, `http://${req.headers.host || "127.0.0.1:10420"}`);
|
|
7637
|
+
pathname = parsedUrl.pathname.replace(/\/+$/, "") || "/";
|
|
7638
|
+
searchParams = parsedUrl.searchParams;
|
|
7639
|
+
} catch {
|
|
7640
|
+
pathname = (req.url || "/").split("?")[0].replace(/\/+$/, "") || "/";
|
|
7641
|
+
}
|
|
7642
|
+
if (req.method === "GET" && (pathname === "/" || pathname === "/health" || pathname === "/api/health" || pathname === "/ping" || pathname === "/api/ping")) {
|
|
7591
7643
|
res.writeHead(200, headers);
|
|
7592
7644
|
res.end(JSON.stringify({
|
|
7593
7645
|
status: "healthy",
|
|
7594
7646
|
service: "Yap2App-Localhost-Bridge",
|
|
7595
|
-
version: "1.
|
|
7647
|
+
version: "1.1.4",
|
|
7596
7648
|
port: PORT,
|
|
7597
7649
|
project_root: PROJECT_ROOT,
|
|
7598
|
-
project_name: import_path2.default.basename(PROJECT_ROOT)
|
|
7650
|
+
project_name: import_path2.default.basename(PROJECT_ROOT),
|
|
7651
|
+
ready: true
|
|
7599
7652
|
}));
|
|
7600
7653
|
return;
|
|
7601
7654
|
}
|
|
7602
|
-
if (req.method === "GET" &&
|
|
7655
|
+
if (req.method === "GET" && (pathname === "/api/context" || pathname === "/context")) {
|
|
7603
7656
|
try {
|
|
7604
|
-
const
|
|
7605
|
-
const promptQuery = parsedUrl.searchParams.get("q") || "";
|
|
7657
|
+
const promptQuery = searchParams.get("q") || "";
|
|
7606
7658
|
console.log(`[Yap2App Bridge] \u{1F50D} Scanning shallow codebase context in: ${PROJECT_ROOT}${promptQuery ? ` (ranking for query: "${promptQuery}")` : ""}`);
|
|
7607
7659
|
const context = await scanCodebase(PROJECT_ROOT, promptQuery);
|
|
7608
7660
|
res.writeHead(200, headers);
|
|
@@ -7614,7 +7666,7 @@ var server = import_http.default.createServer(async (req, res) => {
|
|
|
7614
7666
|
}
|
|
7615
7667
|
return;
|
|
7616
7668
|
}
|
|
7617
|
-
if (req.method === "POST" &&
|
|
7669
|
+
if (req.method === "POST" && (pathname === "/api/diff" || pathname === "/diff")) {
|
|
7618
7670
|
let body = "";
|
|
7619
7671
|
req.on("data", (chunk) => body += chunk.toString());
|
|
7620
7672
|
req.on("end", async () => {
|
|
@@ -7654,7 +7706,7 @@ var server = import_http.default.createServer(async (req, res) => {
|
|
|
7654
7706
|
});
|
|
7655
7707
|
return;
|
|
7656
7708
|
}
|
|
7657
|
-
if (req.method === "POST" &&
|
|
7709
|
+
if (req.method === "POST" && (pathname === "/api/write" || pathname === "/write")) {
|
|
7658
7710
|
let body = "";
|
|
7659
7711
|
req.on("data", (chunk) => body += chunk.toString());
|
|
7660
7712
|
req.on("end", async () => {
|
|
@@ -7686,10 +7738,23 @@ var server = import_http.default.createServer(async (req, res) => {
|
|
|
7686
7738
|
return;
|
|
7687
7739
|
}
|
|
7688
7740
|
res.writeHead(404, headers);
|
|
7689
|
-
res.end(JSON.stringify({ error: "Endpoint Not Found" }));
|
|
7741
|
+
res.end(JSON.stringify({ error: "Endpoint Not Found", path: pathname }));
|
|
7742
|
+
});
|
|
7743
|
+
server.on("error", (err) => {
|
|
7744
|
+
if (err && err.code === "EADDRINUSE") {
|
|
7745
|
+
console.log(`
|
|
7746
|
+
===============================================================`);
|
|
7747
|
+
console.log(`\u{1F4E1} Yap2App Localhost Bridge is ALREADY active on port ${PORT}!`);
|
|
7748
|
+
console.log(`\u{1F4C1} Active Workspace: ${PROJECT_ROOT}`);
|
|
7749
|
+
console.log(`\u{1F310} Ready for 1-click sync from Yap2App Web Studio UI...`);
|
|
7750
|
+
console.log(`===============================================================
|
|
7751
|
+
`);
|
|
7752
|
+
return;
|
|
7753
|
+
}
|
|
7754
|
+
console.error("[Yap2App Bridge Error]:", err);
|
|
7690
7755
|
});
|
|
7691
7756
|
function startBridge(port = PORT) {
|
|
7692
|
-
server.listen(port, () => {
|
|
7757
|
+
server.listen(port, "0.0.0.0", () => {
|
|
7693
7758
|
console.log(`
|
|
7694
7759
|
===============================================================`);
|
|
7695
7760
|
console.log(`\u{1F680} Yap2App Localhost Bridge & Shallow Scanner is ACTIVE!`);
|
package/bin/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
if(typeof process!=='undefined'&&process.emitWarning){var _ow=process.emitWarning;process.emitWarning=function(w){if(typeof w==='string'&&(w.includes('punycode')||w.includes('ExperimentalWarning')||w.includes('DEP0040')))return;if(w&&typeof w==='object'&&(w.code==='DEP0040'||w.name==='ExperimentalWarning'||String(w.message||'').includes('punycode')))return;return _ow.apply(process,arguments);};}if(typeof globalThis==='undefined'){if(typeof global!=='undefined'){global.globalThis=global;}else if(typeof window!=='undefined'){window.globalThis=window;}else if(typeof self!=='undefined'){self.globalThis=self;}}if(!Object.fromEntries){Object.fromEntries=function(e){if(!e)return{};var o={};var a=Array.isArray(e)?e:Array.from(e);for(var i=0;i<a.length;i++){var p=a[i];if(p&&p.length>=2)o[p[0]]=p[1];}return o;};}if(!Object.hasOwn){Object.hasOwn=function(o,p){return o!=null&&Object.prototype.hasOwnProperty.call(o,p);};}if(!Array.prototype.flat){Array.prototype.flat=function(d){var f=[];var dp=typeof d==='number'?d:1;(function fl(a,cd){for(var i=0;i<a.length;i++){if(Array.isArray(a[i])&&cd>0){fl(a[i],cd-1);}else{f.push(a[i]);}}})(this,dp);return f;};}if(!String.prototype.replaceAll){String.prototype.replaceAll=function(s,r){if(s instanceof RegExp)return this.replace(s,r);return this.split(s).join(r);};}if(!String.prototype.matchAll){String.prototype.matchAll=function(r){var f=r.flags;if(!f.includes('g'))f+='g';var rx=new RegExp(r.source,f);var s=String(this);var m=[];var mt;while((mt=rx.exec(s))!==null){m.push(mt);if(mt.index===rx.lastIndex)rx.lastIndex++;}return m[Symbol.iterator]?m[Symbol.iterator]():m;};}
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6916,6 +6917,25 @@ var require_dist = __commonJS({
|
|
|
6916
6917
|
});
|
|
6917
6918
|
|
|
6918
6919
|
// polyfills.js
|
|
6920
|
+
if (typeof process !== "undefined" && process.emitWarning) {
|
|
6921
|
+
_originalEmitWarning = process.emitWarning;
|
|
6922
|
+
process.emitWarning = function(warning) {
|
|
6923
|
+
if (typeof warning === "string") {
|
|
6924
|
+
if (warning.includes("punycode") || warning.includes("ExperimentalWarning") || warning.includes("DEP0040")) {
|
|
6925
|
+
return;
|
|
6926
|
+
}
|
|
6927
|
+
} else if (warning && typeof warning === "object") {
|
|
6928
|
+
if (warning.code === "DEP0040" || warning.name === "ExperimentalWarning") {
|
|
6929
|
+
return;
|
|
6930
|
+
}
|
|
6931
|
+
if (String(warning.message || "").includes("punycode")) {
|
|
6932
|
+
return;
|
|
6933
|
+
}
|
|
6934
|
+
}
|
|
6935
|
+
return _originalEmitWarning.apply(process, arguments);
|
|
6936
|
+
};
|
|
6937
|
+
}
|
|
6938
|
+
var _originalEmitWarning;
|
|
6919
6939
|
if (typeof globalThis === "undefined") {
|
|
6920
6940
|
if (typeof global !== "undefined") {
|
|
6921
6941
|
global.globalThis = global;
|
|
@@ -6929,8 +6949,9 @@ if (typeof Object.fromEntries === "undefined") {
|
|
|
6929
6949
|
Object.fromEntries = function(entries) {
|
|
6930
6950
|
if (!entries) return {};
|
|
6931
6951
|
var obj = {};
|
|
6932
|
-
|
|
6933
|
-
|
|
6952
|
+
var arr = Array.isArray(entries) ? entries : Array.from(entries);
|
|
6953
|
+
for (var i = 0; i < arr.length; i++) {
|
|
6954
|
+
var pair = arr[i];
|
|
6934
6955
|
if (pair && pair.length >= 2) {
|
|
6935
6956
|
obj[pair[0]] = pair[1];
|
|
6936
6957
|
}
|
|
@@ -6967,6 +6988,25 @@ if (!String.prototype.replaceAll) {
|
|
|
6967
6988
|
return this.split(search).join(replacement);
|
|
6968
6989
|
};
|
|
6969
6990
|
}
|
|
6991
|
+
if (!String.prototype.matchAll) {
|
|
6992
|
+
String.prototype.matchAll = function(regexp) {
|
|
6993
|
+
var flags = regexp.flags;
|
|
6994
|
+
if (!flags.includes("g")) {
|
|
6995
|
+
flags += "g";
|
|
6996
|
+
}
|
|
6997
|
+
var rx = new RegExp(regexp.source, flags);
|
|
6998
|
+
var str = String(this);
|
|
6999
|
+
var matches = [];
|
|
7000
|
+
var match;
|
|
7001
|
+
while ((match = rx.exec(str)) !== null) {
|
|
7002
|
+
matches.push(match);
|
|
7003
|
+
if (match.index === rx.lastIndex) {
|
|
7004
|
+
rx.lastIndex++;
|
|
7005
|
+
}
|
|
7006
|
+
}
|
|
7007
|
+
return matches[Symbol.iterator] ? matches[Symbol.iterator]() : matches;
|
|
7008
|
+
};
|
|
7009
|
+
}
|
|
6970
7010
|
if (!Promise.allSettled) {
|
|
6971
7011
|
Promise.allSettled = function(promises) {
|
|
6972
7012
|
return Promise.all(
|
|
@@ -7532,17 +7572,20 @@ var fs2 = import_fs2.default.promises || {
|
|
|
7532
7572
|
mkdir: import_util2.default.promisify(import_fs2.default.mkdir),
|
|
7533
7573
|
stat: import_util2.default.promisify(import_fs2.default.stat)
|
|
7534
7574
|
};
|
|
7535
|
-
var PORT = process.env.YAP2APP_PORT || 10420;
|
|
7575
|
+
var PORT = Number(process.env.YAP2APP_PORT) || 10420;
|
|
7536
7576
|
var PROJECT_ROOT = process.cwd();
|
|
7537
7577
|
function getCorsHeaders(req) {
|
|
7538
7578
|
var _a5, _b;
|
|
7539
7579
|
const origin = ((_a5 = req == null ? void 0 : req.headers) == null ? void 0 : _a5.origin) || "*";
|
|
7580
|
+
const requestedHeaders = ((_b = req == null ? void 0 : req.headers) == null ? void 0 : _b["access-control-request-headers"]) || "*";
|
|
7540
7581
|
return {
|
|
7541
7582
|
"Access-Control-Allow-Origin": origin,
|
|
7542
|
-
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, DELETE, HEAD",
|
|
7543
|
-
"Access-Control-Allow-Headers":
|
|
7583
|
+
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, DELETE, HEAD, PATCH",
|
|
7584
|
+
"Access-Control-Allow-Headers": requestedHeaders === "*" ? "Content-Type, Authorization, Access-Control-Request-Private-Network, X-Requested-With, Accept, Origin, *" : requestedHeaders,
|
|
7544
7585
|
"Access-Control-Allow-Private-Network": "true",
|
|
7586
|
+
"Access-Control-Allow-Credentials": "true",
|
|
7545
7587
|
"Access-Control-Max-Age": "86400",
|
|
7588
|
+
"Vary": "Origin, Access-Control-Request-Headers, Access-Control-Request-Private-Network",
|
|
7546
7589
|
"Content-Type": "application/json"
|
|
7547
7590
|
};
|
|
7548
7591
|
}
|
|
@@ -7587,22 +7630,31 @@ var server = import_http.default.createServer(async (req, res) => {
|
|
|
7587
7630
|
res.end();
|
|
7588
7631
|
return;
|
|
7589
7632
|
}
|
|
7590
|
-
|
|
7633
|
+
let pathname = "/";
|
|
7634
|
+
let searchParams = new URLSearchParams();
|
|
7635
|
+
try {
|
|
7636
|
+
const parsedUrl = new URL(req.url, `http://${req.headers.host || "127.0.0.1:10420"}`);
|
|
7637
|
+
pathname = parsedUrl.pathname.replace(/\/+$/, "") || "/";
|
|
7638
|
+
searchParams = parsedUrl.searchParams;
|
|
7639
|
+
} catch {
|
|
7640
|
+
pathname = (req.url || "/").split("?")[0].replace(/\/+$/, "") || "/";
|
|
7641
|
+
}
|
|
7642
|
+
if (req.method === "GET" && (pathname === "/" || pathname === "/health" || pathname === "/api/health" || pathname === "/ping" || pathname === "/api/ping")) {
|
|
7591
7643
|
res.writeHead(200, headers);
|
|
7592
7644
|
res.end(JSON.stringify({
|
|
7593
7645
|
status: "healthy",
|
|
7594
7646
|
service: "Yap2App-Localhost-Bridge",
|
|
7595
|
-
version: "1.
|
|
7647
|
+
version: "1.1.4",
|
|
7596
7648
|
port: PORT,
|
|
7597
7649
|
project_root: PROJECT_ROOT,
|
|
7598
|
-
project_name: import_path2.default.basename(PROJECT_ROOT)
|
|
7650
|
+
project_name: import_path2.default.basename(PROJECT_ROOT),
|
|
7651
|
+
ready: true
|
|
7599
7652
|
}));
|
|
7600
7653
|
return;
|
|
7601
7654
|
}
|
|
7602
|
-
if (req.method === "GET" &&
|
|
7655
|
+
if (req.method === "GET" && (pathname === "/api/context" || pathname === "/context")) {
|
|
7603
7656
|
try {
|
|
7604
|
-
const
|
|
7605
|
-
const promptQuery = parsedUrl.searchParams.get("q") || "";
|
|
7657
|
+
const promptQuery = searchParams.get("q") || "";
|
|
7606
7658
|
console.log(`[Yap2App Bridge] \u{1F50D} Scanning shallow codebase context in: ${PROJECT_ROOT}${promptQuery ? ` (ranking for query: "${promptQuery}")` : ""}`);
|
|
7607
7659
|
const context = await scanCodebase(PROJECT_ROOT, promptQuery);
|
|
7608
7660
|
res.writeHead(200, headers);
|
|
@@ -7614,7 +7666,7 @@ var server = import_http.default.createServer(async (req, res) => {
|
|
|
7614
7666
|
}
|
|
7615
7667
|
return;
|
|
7616
7668
|
}
|
|
7617
|
-
if (req.method === "POST" &&
|
|
7669
|
+
if (req.method === "POST" && (pathname === "/api/diff" || pathname === "/diff")) {
|
|
7618
7670
|
let body = "";
|
|
7619
7671
|
req.on("data", (chunk) => body += chunk.toString());
|
|
7620
7672
|
req.on("end", async () => {
|
|
@@ -7654,7 +7706,7 @@ var server = import_http.default.createServer(async (req, res) => {
|
|
|
7654
7706
|
});
|
|
7655
7707
|
return;
|
|
7656
7708
|
}
|
|
7657
|
-
if (req.method === "POST" &&
|
|
7709
|
+
if (req.method === "POST" && (pathname === "/api/write" || pathname === "/write")) {
|
|
7658
7710
|
let body = "";
|
|
7659
7711
|
req.on("data", (chunk) => body += chunk.toString());
|
|
7660
7712
|
req.on("end", async () => {
|
|
@@ -7686,10 +7738,23 @@ var server = import_http.default.createServer(async (req, res) => {
|
|
|
7686
7738
|
return;
|
|
7687
7739
|
}
|
|
7688
7740
|
res.writeHead(404, headers);
|
|
7689
|
-
res.end(JSON.stringify({ error: "Endpoint Not Found" }));
|
|
7741
|
+
res.end(JSON.stringify({ error: "Endpoint Not Found", path: pathname }));
|
|
7742
|
+
});
|
|
7743
|
+
server.on("error", (err) => {
|
|
7744
|
+
if (err && err.code === "EADDRINUSE") {
|
|
7745
|
+
console.log(`
|
|
7746
|
+
===============================================================`);
|
|
7747
|
+
console.log(`\u{1F4E1} Yap2App Localhost Bridge is ALREADY active on port ${PORT}!`);
|
|
7748
|
+
console.log(`\u{1F4C1} Active Workspace: ${PROJECT_ROOT}`);
|
|
7749
|
+
console.log(`\u{1F310} Ready for 1-click sync from Yap2App Web Studio UI...`);
|
|
7750
|
+
console.log(`===============================================================
|
|
7751
|
+
`);
|
|
7752
|
+
return;
|
|
7753
|
+
}
|
|
7754
|
+
console.error("[Yap2App Bridge Error]:", err);
|
|
7690
7755
|
});
|
|
7691
7756
|
function startBridge(port = PORT) {
|
|
7692
|
-
server.listen(port, () => {
|
|
7757
|
+
server.listen(port, "0.0.0.0", () => {
|
|
7693
7758
|
console.log(`
|
|
7694
7759
|
===============================================================`);
|
|
7695
7760
|
console.log(`\u{1F680} Yap2App Localhost Bridge & Shallow Scanner is ACTIVE!`);
|
package/bridge.js
CHANGED
|
@@ -12,18 +12,21 @@ const fs = fsSync.promises || {
|
|
|
12
12
|
stat: util.promisify(fsSync.stat)
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
const PORT = process.env.YAP2APP_PORT || 10420;
|
|
15
|
+
const PORT = Number(process.env.YAP2APP_PORT) || 10420;
|
|
16
16
|
const PROJECT_ROOT = process.cwd();
|
|
17
17
|
|
|
18
18
|
// Bulletproof W3C Private Network Access (PNA) and Dynamic Origin CORS Headers
|
|
19
19
|
function getCorsHeaders(req) {
|
|
20
20
|
const origin = req?.headers?.origin || '*';
|
|
21
|
+
const requestedHeaders = req?.headers?.['access-control-request-headers'] || '*';
|
|
21
22
|
return {
|
|
22
23
|
'Access-Control-Allow-Origin': origin,
|
|
23
|
-
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS, PUT, DELETE, HEAD',
|
|
24
|
-
'Access-Control-Allow-Headers':
|
|
24
|
+
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS, PUT, DELETE, HEAD, PATCH',
|
|
25
|
+
'Access-Control-Allow-Headers': requestedHeaders === '*' ? 'Content-Type, Authorization, Access-Control-Request-Private-Network, X-Requested-With, Accept, Origin, *' : requestedHeaders,
|
|
25
26
|
'Access-Control-Allow-Private-Network': 'true',
|
|
27
|
+
'Access-Control-Allow-Credentials': 'true',
|
|
26
28
|
'Access-Control-Max-Age': '86400',
|
|
29
|
+
'Vary': 'Origin, Access-Control-Request-Headers, Access-Control-Request-Private-Network',
|
|
27
30
|
'Content-Type': 'application/json'
|
|
28
31
|
};
|
|
29
32
|
}
|
|
@@ -83,25 +86,41 @@ const server = http.createServer(async (req, res) => {
|
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
let pathname = '/';
|
|
90
|
+
let searchParams = new URLSearchParams();
|
|
91
|
+
try {
|
|
92
|
+
const parsedUrl = new URL(req.url, `http://${req.headers.host || '127.0.0.1:10420'}`);
|
|
93
|
+
pathname = parsedUrl.pathname.replace(/\/+$/, '') || '/';
|
|
94
|
+
searchParams = parsedUrl.searchParams;
|
|
95
|
+
} catch {
|
|
96
|
+
pathname = (req.url || '/').split('?')[0].replace(/\/+$/, '') || '/';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 2. Health & Root Info (fast ping endpoints)
|
|
100
|
+
if (req.method === 'GET' && (
|
|
101
|
+
pathname === '/' ||
|
|
102
|
+
pathname === '/health' ||
|
|
103
|
+
pathname === '/api/health' ||
|
|
104
|
+
pathname === '/ping' ||
|
|
105
|
+
pathname === '/api/ping'
|
|
106
|
+
)) {
|
|
88
107
|
res.writeHead(200, headers);
|
|
89
108
|
res.end(JSON.stringify({
|
|
90
109
|
status: 'healthy',
|
|
91
110
|
service: 'Yap2App-Localhost-Bridge',
|
|
92
|
-
version: '1.
|
|
111
|
+
version: '1.1.4',
|
|
93
112
|
port: PORT,
|
|
94
113
|
project_root: PROJECT_ROOT,
|
|
95
|
-
project_name: path.basename(PROJECT_ROOT)
|
|
114
|
+
project_name: path.basename(PROJECT_ROOT),
|
|
115
|
+
ready: true
|
|
96
116
|
}));
|
|
97
117
|
return;
|
|
98
118
|
}
|
|
99
119
|
|
|
100
120
|
// 3. GET /api/context (Shallow Codebase Scanner with Optional Prompt Query)
|
|
101
|
-
if (req.method === 'GET' &&
|
|
121
|
+
if (req.method === 'GET' && (pathname === '/api/context' || pathname === '/context')) {
|
|
102
122
|
try {
|
|
103
|
-
const
|
|
104
|
-
const promptQuery = parsedUrl.searchParams.get('q') || '';
|
|
123
|
+
const promptQuery = searchParams.get('q') || '';
|
|
105
124
|
console.log(`[Yap2App Bridge] 🔍 Scanning shallow codebase context in: ${PROJECT_ROOT}${promptQuery ? ` (ranking for query: "${promptQuery}")` : ''}`);
|
|
106
125
|
const context = await scanCodebase(PROJECT_ROOT, promptQuery);
|
|
107
126
|
res.writeHead(200, headers);
|
|
@@ -115,7 +134,7 @@ const server = http.createServer(async (req, res) => {
|
|
|
115
134
|
}
|
|
116
135
|
|
|
117
136
|
// 4. POST /api/diff (Enterprise Diff & Safety Gate Review)
|
|
118
|
-
if (req.method === 'POST' &&
|
|
137
|
+
if (req.method === 'POST' && (pathname === '/api/diff' || pathname === '/diff')) {
|
|
119
138
|
let body = '';
|
|
120
139
|
req.on('data', chunk => body += chunk.toString());
|
|
121
140
|
req.on('end', async () => {
|
|
@@ -159,7 +178,7 @@ const server = http.createServer(async (req, res) => {
|
|
|
159
178
|
}
|
|
160
179
|
|
|
161
180
|
// 5. POST /api/write (Approved Write to Disk)
|
|
162
|
-
if (req.method === 'POST' &&
|
|
181
|
+
if (req.method === 'POST' && (pathname === '/api/write' || pathname === '/write')) {
|
|
163
182
|
let body = '';
|
|
164
183
|
req.on('data', chunk => body += chunk.toString());
|
|
165
184
|
req.on('end', async () => {
|
|
@@ -199,11 +218,24 @@ const server = http.createServer(async (req, res) => {
|
|
|
199
218
|
|
|
200
219
|
// 404 Fallback
|
|
201
220
|
res.writeHead(404, headers);
|
|
202
|
-
res.end(JSON.stringify({ error: 'Endpoint Not Found' }));
|
|
221
|
+
res.end(JSON.stringify({ error: 'Endpoint Not Found', path: pathname }));
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// Gracefully handle EADDRINUSE without crashing
|
|
225
|
+
server.on('error', (err) => {
|
|
226
|
+
if (err && err.code === 'EADDRINUSE') {
|
|
227
|
+
console.log(`\n===============================================================`);
|
|
228
|
+
console.log(`📡 Yap2App Localhost Bridge is ALREADY active on port ${PORT}!`);
|
|
229
|
+
console.log(`📁 Active Workspace: ${PROJECT_ROOT}`);
|
|
230
|
+
console.log(`🌐 Ready for 1-click sync from Yap2App Web Studio UI...`);
|
|
231
|
+
console.log(`===============================================================\n`);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
console.error('[Yap2App Bridge Error]:', err);
|
|
203
235
|
});
|
|
204
236
|
|
|
205
237
|
export function startBridge(port = PORT) {
|
|
206
|
-
server.listen(port, () => {
|
|
238
|
+
server.listen(port, '0.0.0.0', () => {
|
|
207
239
|
console.log(`\n===============================================================`);
|
|
208
240
|
console.log(`🚀 Yap2App Localhost Bridge & Shallow Scanner is ACTIVE!`);
|
|
209
241
|
console.log(`📡 Listening on: http://127.0.0.1:${port}`);
|
|
@@ -219,3 +251,4 @@ const isDirectRun = Boolean(typeof process !== 'undefined' && process.argv && pr
|
|
|
219
251
|
if (isDirectRun) {
|
|
220
252
|
startBridge();
|
|
221
253
|
}
|
|
254
|
+
|
package/package.json
CHANGED
package/polyfills.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Universal Node.js Polyfills for Yap2App CLI
|
|
3
|
-
* Enables full backwards compatibility across all NVM Node versions (Node 10.x to 23.x+)
|
|
2
|
+
* Universal Node.js Polyfills & Warning Suppressors for Yap2App CLI
|
|
3
|
+
* Enables full backwards compatibility and clean startup across all NVM Node versions (Node 10.x to 23.x+)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
// 0. Suppress noisy Node 18 experimental warnings and punycode deprecation warnings (DEP0040)
|
|
7
|
+
if (typeof process !== 'undefined' && process.emitWarning) {
|
|
8
|
+
var _originalEmitWarning = process.emitWarning;
|
|
9
|
+
process.emitWarning = function (warning) {
|
|
10
|
+
if (typeof warning === 'string') {
|
|
11
|
+
if (warning.includes('punycode') || warning.includes('ExperimentalWarning') || warning.includes('DEP0040')) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
} else if (warning && typeof warning === 'object') {
|
|
15
|
+
if (warning.code === 'DEP0040' || warning.name === 'ExperimentalWarning') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (String(warning.message || '').includes('punycode')) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return _originalEmitWarning.apply(process, arguments);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
6
26
|
// 1. globalThis polyfill (Node <12)
|
|
7
27
|
if (typeof globalThis === 'undefined') {
|
|
8
28
|
if (typeof global !== 'undefined') {
|
|
@@ -19,8 +39,9 @@ if (typeof Object.fromEntries === 'undefined') {
|
|
|
19
39
|
Object.fromEntries = function (entries) {
|
|
20
40
|
if (!entries) return {};
|
|
21
41
|
var obj = {};
|
|
22
|
-
|
|
23
|
-
|
|
42
|
+
var arr = Array.isArray(entries) ? entries : Array.from(entries);
|
|
43
|
+
for (var i = 0; i < arr.length; i++) {
|
|
44
|
+
var pair = arr[i];
|
|
24
45
|
if (pair && pair.length >= 2) {
|
|
25
46
|
obj[pair[0]] = pair[1];
|
|
26
47
|
}
|
|
@@ -64,7 +85,28 @@ if (!String.prototype.replaceAll) {
|
|
|
64
85
|
};
|
|
65
86
|
}
|
|
66
87
|
|
|
67
|
-
// 6.
|
|
88
|
+
// 6. String.prototype.matchAll polyfill (Node <12.0)
|
|
89
|
+
if (!String.prototype.matchAll) {
|
|
90
|
+
String.prototype.matchAll = function (regexp) {
|
|
91
|
+
var flags = regexp.flags;
|
|
92
|
+
if (!flags.includes('g')) {
|
|
93
|
+
flags += 'g';
|
|
94
|
+
}
|
|
95
|
+
var rx = new RegExp(regexp.source, flags);
|
|
96
|
+
var str = String(this);
|
|
97
|
+
var matches = [];
|
|
98
|
+
var match;
|
|
99
|
+
while ((match = rx.exec(str)) !== null) {
|
|
100
|
+
matches.push(match);
|
|
101
|
+
if (match.index === rx.lastIndex) {
|
|
102
|
+
rx.lastIndex++;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return matches[Symbol.iterator] ? matches[Symbol.iterator]() : matches;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 7. Promise.allSettled polyfill (Node <12.9)
|
|
68
110
|
if (!Promise.allSettled) {
|
|
69
111
|
Promise.allSettled = function (promises) {
|
|
70
112
|
return Promise.all(
|
|
@@ -81,3 +123,4 @@ if (!Promise.allSettled) {
|
|
|
81
123
|
);
|
|
82
124
|
};
|
|
83
125
|
}
|
|
126
|
+
|